Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

USING ARRAY AS VARIABLE

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have a conversion program from Fortran to Cobol. In fortran they have used array as a variable and have passed it to functions with arry as paramater. Can it be done in cobol ?. If so how ?
 
CV,
Assuming that the functions are COBOL functions, or are system functions that allow an interface to COBOL, I have successfully accompilshed this in 3 compilers. (UNISYS A-SERIES/NX/LX, Fujitsu 5.0, MicroFocus 5.0). The syntax is similar to
Code:
CALL <function> OF <code-file> USING <variable(s)>

Any 01 level variable in COBOL IS an Array by nature.

Hope this is helpful, if not, let us know, and I'm sure someone else will have a better answer, but may require some more information.
Regards,
Codeslug
 
Call me stupid, but as far as i know the verb ARRAY isn't used anywhere in the COBOL standards i've seen sofar. If indeed it isn't i would recommend NOT using this term anymore to avoid confusion. I've seen people use it for tables, character identifiers, etc.
I'm not familiar with functions in COBOL, but i guess you can pass either tables or character id's to one.

Regards,
Ronald.
 
In COBOL a table is an array.

An array is just a bunch of data elements that repeat X number of times, (CALL THAT TABLE-MAX) so if you have a total and say it occurs 5 times it is an array.

You can copy an array with a field used to point to the array element like CNTR. This is called sub-scripting.

......
move 1 to CNTR.
PERFORM COPY-TABLE TABLE-MAX times.
COPY-TABLE.
COPY TABLE-ONE (CNTR) TO TABLE-TWO (CNTR).
ADD 1 TO CNTR.
......

I dont use varying much but that is an option.

Normally in my compiler variables are all global, so you only have to know the CNTR location of the TABLE (array), to use it as a subscript. Since it is all global, there is no reason to pass a table(array).

There may be object oriented compilers that use local variables like C++ or Java. They don't normally pass the array, but a reference location in memory for the array from what I can remember. Some languages may do both.

If you have two arrays you can copy them in one line.
If each array has a discription like:

01 TABLE-ONE.
05 TABLE-ONE-TOTAL OCCURS 5 TIMES PIC 9999.

01 TABLE-TWO.
05 TABLE-TWO-TOTAL OCCURS 5 TIMES PIC 9999.

Then you could use

MOVE TABLE-ONE TO TABLE-TWO.

BECAUSE IT IS A GROUP MOVE.

If you do not like my post feel free to point out your opinion or my errors.
 
NO, NO, NO!!!

It is NOT an array, it is a TABLE! Pleeeease use the lingo we've all agreed on describing COBOL thingies with.

Regards,
Ronald.
 
Ronald,
Please don't take this the wrong way, I am not trying to be difficult, or obnoxious. What or where can I find the 'official COBOL' lingo? I understand how specific words can be very confusing to anyone who codes in more than 1 language, or who reads any Microsoft technical documentation. :)
TIA for your help.
CodeSlug
 
My two scents,

Ron, I feel your pain but, in these days of new fangled languages and the cross-talk that they present, it's worth knowing the analogous terms for any of the COBOL features.

CS, I feel your pain too. Not knowing the language of currency, whether it be COBOL or English can be a handicap. You can try and find IBM's latest COBOL Language Reference or Application Pgmmer's Guide. The index of these s/b some help. I think there may even be a Glossary in them.

Regards, Jack.
 
In COBOL you can not pass an Array, even though it is called a table. Stern & Stern sometimes uses the term array.

In COBOL variables are global. This means no variables can be hidden and all variables are accessable from everywhere in the porgram. This also means no variable names can be reused. Therefore, there is no reason to pass a table.
COBOL has some intrinsic functions which are built into the compiler, but you can not make them up by using a compiler.
Instead we break code up into paragraphs.

paragraph-one.
do this.
do that.
perform paragraph-two.
.....

Control passes back to the paragraph-one after paragraph-two is performed.


You use an integer variable form 1 to the maximum table elements to access the table elements.

move first-table (1) to second-table (1).

I recommend a cheap book like learn COBOL in 24 hours.

When you ask the next question you may want to add
Compiler you are using.
OS you are using.
What you want to do.

Do you want to pass data from one program to another?
Do you simply want to change data?
Are you sorting the table/array?
Is the program self contained?
Be specific because they can't read your mind. If you do not like my post feel free to point out your opinion or my errors.
 
All,

COBOL is about the only computer language around that is officially laid down in a world wide, acknowledged standard. Although i'm am very aware various compiler manufacturers, of which IBM - which i use professionally daily - is no exeption, tend to define their own version, the COBOL standard should be the guideline to anyone using it.
I'm very well aware of the fact that some, or in fact many, languages call a structured collection of similar elements an array; COBOL however doesn't, and this is a COBOL forum, so let's stick to the standard, shall we?
Well ,that's about all the intelligent comment a can produce; i'm tired, i'm pissed, so i'm going to hit the sack. See you all in about two days (got a training coming monday and tuesday, that's why).

Regards,
Ronald.
 
Ronald B wrote:

NO, NO, NO!!!

It is NOT an array, it is a TABLE! Pleeeease use the lingo we've all agreed on describing COBOL thingies with.

I always was taught back in my COBOL classes, and also in training given at work, that in COBOL, a &quot;table&quot; is just another name for an &quot;array.&quot;

Usually I use &quot;table&quot; when describing a specific set of values i.e. a specific array such as &quot;a table of social security numbers.&quot; And I use &quot;array&quot; for more abstract analytical considerations, such as &quot;I'm going to design a 2-dimensional array for this application.&quot; But I think that this is simply my own little quirk; either term can be used interchangeably.

Nina Too

 
All fine and dandy, but reading back through this thread i've witnessed at least three different uses of the term &quot;array&quot;. Stating, for instance, that every COBOL 01 level is an array does not in any way resemble what i like to call a table; that looks more like they PASCAL construction for a string, being an &quot;array of char&quot;. I fail to see, however, the table, array, or even string, in the next definition:

01 SOME-NUM-FIELD 9(08)V99.

I've attended business meetings where attendants of several different disciplines were all talking appearently about the same things, using similar terminology, only to find out after a while thay they were talking completely at cross-purposes.
That is why i advocate using the same &quot;language&quot; to avoid these mixups.

But, i'll back off now.
Regards,
Ronald.
 
The COBOL language comes in modules. To qualify as a COBOL compiler at some specific level, you must pass tests which determine whether you have implemented the module at the low or high level. The module which handles multiply occurring data items is called the Table Handling Module - don't recall ever seeing a test for an Array Handling Module, and I used to be in COBOL compiler development / implementation, although somehow I've managed to become an application programmer again. Betty Scherber
Brainbench MVP for COBOL II
 
Taken from the &quot;COBOL for OS/390 & VM V2R2 Programming Guide&quot; - SC26-9049-05 TOC:

1.2.5 Using tables (arrays) and pointers

If IBM is equating arrays w/tables, why are we arguing? It seems like a silly argument, anyway. After all, when someone sats &quot;array&quot; we know the poor unannointed fool is referring to a &quot;table&quot;. :)

Jack
 
If IBM is equating arrays w/tables, why are we arguing?

Because we're COBOL programmers. And arguing is a lot of fun. :) :-D

Nina Too
 
If IBM is equating arrays w/tables, why are we arguing?

For the same reason that we argue with things said by that big company in Redmond. Just because you have more money doesn't make you right. Betty Scherber
Brainbench MVP for COBOL II
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top