Question

I need to make a table out of the data structure below because I am not certain how many records that are each one line long will be in my input file. If I can make a table then I will be able to loop through them at a later time which is what I need to be able to do.

**Question: How to make a table out of the data structure before? Part B: An array in Cobol is an OCCURS 100 TIMES

01 PRECORD.                             
    05 JE.                              
       10 NE          PIC X(6)  VALUE SPACES.
       10 NM          PIC X(2)  VALUE SPACES.
    05 FILL1          PIC X(16) VALUE SPACES.
    05 TM             PIC X(7)  VALUE SPACES.
    05 FILL2          PIC X(6)  VALUE SPACES.
    05 TT             PIC X(7)  VALUE SPACES.
    05 FILL3          PIC X(13) VALUE SPACES.
    05 TTY            PIC X(10) VALUE SPACES.
    05 FILL4          PIC X(13) VALUE SPACES.
01 PRECORD. 
  02 table-counter  <-- this is used to hold the number of records                            
  02 tTable occurs 300 times. <-- creates a table with three hundred occurences
    05 JE.                              
       10 NE          PIC X(6)  VALUE SPACES.
       10 NM          PIC X(2)  VALUE SPACES.
    05 FILL1          PIC X(16) VALUE SPACES.
    05 TM             PIC X(7)  VALUE SPACES.
    05 FILL2          PIC X(6)  VALUE SPACES.
    05 TT             PIC X(7)  VALUE SPACES.
    05 FILL3          PIC X(13) VALUE SPACES.
    05 TTY            PIC X(10) VALUE SPACES.
    05 FILL4          PIC X(13) VALUE SPACES.

The code above is update with how I think that table should look. The table has to have a counter at the top and then under than it will have to have a occur and how many times the table should occur.

The question that I was asking was how do you make a table like above actually a table I did not know that you had to create an Occurs and then put everything below that level of the occurs.

  01 mytable.
     02 counter...
     02 tablevar occures 200 times.
        05 var...
        05 var2..

I just was not sure of the structure of a Cobol table. My question is what was the format of a Cobol data structure?

Was it helpful?

Solution 2

Personally, I'd declare table-counter as a 77-level with a PIC 9(03). And you really should remove the VALUE clauses. Of course, this would need to be a WORKING-STORAGE entry, not an FD since the table isn't on the file. Other than that, what you've dome appears valid - but it's difficult to see what question you are asking.

OTHER TIPS

Your table-counter will need a PICture.

What PICture? Opinions vary.

There are three numeric formats which are useful for this, binary, packed-decimal, and display-numeric.

nn table-counter COMP/COMP-4/BINARY/COMP-5 PIC 9(4).
nn table-counter COMP-3/PACKED-DECIMAL PIC 9(3).
nn table-counter  PIC 9(3).

The most efficient definition will be a binary one. If you use packed-decimal, the compiler will generate code to convert it to binary when used in comparison with anything you use for subscripting (except literals). When using display-numeric, the compiler will generate code to first convert to packed-decimal, then to binary.

Do these things matter with the speed of machines these days? Well, if they don't matter, may as well be efficient, but opinions do vary.

What size for the PICture? 9(4) for binary allows up to 9999 as a maximum value. You can code 999, but it does not give you much advantage (can't limit it to 300), so I go for optimal for the size (for a packed-decimal (COMP-3) it would be 999, as you don't get a fourth digit for nothing). Same if using display-numeric. Again, opinions vary.

If those are records, as Magoo has pointed out, you can't just add the count to the beginning of the record. You can't keep your table in the FILE SECTION under and FD. It will need to go into the WORKING-STORAGE SECTION.

Then there is the problem of keeping two structures "in step" for where they should match each other.

You probably have a copybook for the record-layout. The best is if you can parameterise the names in the copybook, so that you can use REPLACING on the COPY statement, allowing you to use the same copybook for the two different purposes. It would then be important that the copybook does not contain an 01-level. Again opinions vary on the inclusion of 01s in copybooks, but you may get lucky.

Which, given all the opinion, gets us to "well, what do I do?". What you do is the way they do it at your site. There should be documentation of local standards. This may not cover everything, you may have to seek the opinions of colleagues. If you all code in about the same way, it makes the code easier to understand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top