Domanda

The goal of this exercise is to read and store an input file into a table then validate certain fields within the input and output any error records. I need to read and store each policy group so that there are just 5 records stored in the table at a time instead of the entire file.

So I need to read in a policy group which is 5 records, do the processing, then read the next 5 records, etc until the end of the file..

This is the input file.
10A 011111          2005062520060625                                    
20A 011111000861038                                                     
32A 011111                            79372                             
60A 0111112020                                             6          4 
94A 011111     080 1                                                    
10A 02222          2005082520060825                                    
20A 022221000187062                                                     
32A 022221                            05038                             
60A 0222212003                                             6          4 
94A 022221     090 1                                                    
....

I was able to load the first 5 records into a table by having my table OCCUR 5 TIMES but I don't know how I would continue that. My code is below. (I wrote it just to see if it was working correctly, but it prints the header line with the first 4 records, instead of just the first 5) 01 TABLES.

05  T1-RECORD-TABLE.                                
    10  T1-ENTRY                OCCURS 5 TIMES      
                                INDEXED BY T1-INDEX.

        15  RECORD-TYPE-10      PIC X(80).          
        15  RECORD-TYPE-20      PIC X(80).          
        15  RECORD-TYPE-32      PIC X(80).          
        15  RECORD-TYPE-60      PIC X(80).          
        15  RECORD-TYPE-94      PIC X(80).          

 copy trnrec10.
 COPY TRNREC20.
 COPY TRNREC32.
 COPY TRNREC60.
 COPY TRNREC94.
.....

Z200-READ-FILES.                               
    READ DISK-IN INTO T1-ENTRY(T1-INDEX)       
        AT END MOVE 'YES' TO END-OF-FILE-SW.   

    WRITE PRINT-RECORD FROM T1-ENTRY(T1-INDEX).

I don't want a step by step for this (though that'd be nice :P) bc I know WHAT I need to do I just don't know HOW to do it bc my textbook and course note are useless to me. I've been stuck on this for a while and nothing I try works.

È stato utile?

Soluzione 2

You have textbook, course notes, a manual, an editor, JCL and a computer.

All of those are going to be of use to you, but you've also got to get yourself thinking like your should program.

Your task is to read a file, load five records into a table, do something with them, then write them out.

You will have many tasks where you read a file, do something, and write a file.

So how about getting the file processing down pat first?

Define your files using FILE STATUS

PERFORM OPEN-INPUT-POLICY-MASTER
PERFORM OPEN-OUTPUT-NEW-POLICY-MASTER

In those paragraphs (or SECTIONs, depending on your site standards) OPEN the files, check the file status, abend if not "00".

You will need a READ paragraph. READ in there, check the file status, being aware that "10" is valid and that it indicates end-of-file (so you don't need AT END and END-READ). Count all records read (file status "00").

You will need a WRITE paragraph. Check the file status. Only "00" is valid. Count the records written.

PERFORM PRIMING-READ-OF-POLICY-MASTER

All that paragraph needs to do is PERFORM the READ paragraph. Putting it in a paragraph of its own is a way of documenting what it does. Telling the next person along.

What does it do? Reads, or attempts to read, the first record. If the file is empty, you will get file status "10". If the file should not be empty, abend. You've now dealt with an empty file without affecting your processing logic.

PERFORM PROCESS-POLICY-MASTER UNTIL END-OF-POLICY-MASTER

or

PERFORM UNTIL END-OF-POLICY-MASTER
    ....
END-PERFORM

I prefer the first, to avoid the main logic "spreading", but it's fine to start with the second if you prefer/it fits in with your course.

The last thing in the paragraph or before the END-PERFORM is a PERFORM of your READ.

You can then PERFORM CLOSE-INPUT-POLICY-MASTER, and similar for the output file.

Then check that the counts are equal. If not, abend. This is trivial in this example, but as your logic gets more complicated, things can go wrong.

Always provide counts to reconcile your input to output, count additions, deletions. Count updates separately for information. Get your program to check what it can. If you have more updates than input records, identify that and abend. Have your program do as much verification as possible.

You will now have a simple program which reads a file, writes a file, checks as much as it can, and is just lacking processing logic.

You can use that program as a base for all your tasks reading one file and writing another.

All that stuff will work in your new program, without you having to do anything.

The logic you need for now is to store data in a table.

OK, as Gilbert has rightly shown, storing in a table doesn't make sense in your actual case. But, it is the requirement. You need to get good at tables as well.

Your table is not defined correctly. Try this:

01  T1-RECORD-TABLE.                                
    05  T1-ENTRY                OCCURS 5 TIMES      
                                INDEXED BY T1-INDEX.

        10  POLICY-RECORD.
            15  POLICY-RECORD-TYPE PIC XX.
            15  POLICY-RECORD-DATA PIC X(78).

Put an 88 underneath POLICY-RECORD-TYPE for each of your record-types. Make the 88 descriptive of the business function, don't just say "RECORD-IS-TYPE-10".

You are using an index to reference items in the table. Before putting the first entry in the table you have to SET the index to 1. To access the next entry, you have to SET the index UP BY 1.

Once you have stored your items in the table, you need to get at them again. SET the index to 1 again and you can reference the first entry. SET the index UP BY 1 serially to access the other entries.

SET index TO 1 before you start the processing. MOVE zero to a count of table entries. Get into your file processing loop.

There, count what you store, every time that your count of table entries reaches five, PERFORM a paragraph to output your records and SET your index to 1. If the count is not five, SET your index UP BY 1.

In your paragraph to output the records, use PERFORM VARYING your index FROM 1 BY 1 UNTIL GREATER THAN 5. In the PERFORM, PERFORM your WRITE paragraph with the current table entry as the source for the record.

You will now have two programs, both of which read an input file and produce an identical output file.

Then you can do your verification logic.

If you break everything down, keep things separate, keep things simple, name them well, you'll start to write COBOL programs that are the same except for the specific business logic. All the standard stuff, all the boring stuff, if you like, all the basic structure stays the same. The new code you write is just the specifics of the next task.

Yes, you'll get to read more files, either as reference files, or as multiple inputs. You'll have multiple outputs. But you can build the basics of all those in exactly the same manner. Then you'll have more examples to base your future programs on.

Once you've got the basic stuff, you never need to code it again. You just copy and apply.

With good names, your programs will tell what they are doing.

The code that you actually write will be the "interesting" stuff, not the stuff you do "every time".

I've just "designed" this for you. It is not the only workable design. It is how I do it, and have done for some time. You should also design every part of your processing. You should know what it is doing before you write the code.

As an example, take a simple loop. Imagine how you will test it. With zero entries in the table, what happens? With one? With an intermediate number? One less than the maximum? The maximum? One more than the maximum? 10 more than the maximum? Then write the code knowing that you need to know how to deal with those cases.

In time, not too long, you'll think about the low-level design while you code. In more time, you'll do the high-level design that way as well. In enough time you'll only design things you've not had to deal with before, the rest you'll already know.

You have textbook, course notes, a manual, an editor, JCL and a computer. I've given you some ideas. How about seeing if taken all together they are useful to you. I think you have some frustrations now. Write some basic programs, then apply them to your tasks.

Altri suggerimenti

I'm assuming that every policy group has exactly 5 records with the 5 record types.

You can set up your working storage like this.

05  T1-RECORD.
    10  T1-RECORD-TYPE               PIC XX.
    10  FILLER                       PIC X(78).      

 COPY TRNREC10.
 COPY TRNREC20.
 COPY TRNREC32.
 COPY TRNREC60.
 COPY TRNREC94.

Then your read paragraph would look like this. I assumed that TRNREC10-RECORD was the 01 level of the TRNREC10 copybook. if not, substitute the actual 01 levels in the following code.

2200-READ-FILE.                               
    READ DISK-IN INTO T1-RECORD      
        AT END MOVE 'YES' TO END-OF-FILE-SW.  

    IF END-OF-FILE-SW = 'NO'
        IF T1-RECORD-TYPE = '10'
            MOVE T1-RECORD TO TRNREC10-RECORD
        END-IF
        IF T1-RECORD-TYPE = '20'
            MOVE T1-RECORD TO TRNREC20-RECORD
        END-IF
        ...
    END-IF.

Your write paragraph would look like this

2400-WRITE-FILE.
    WRITE PRINT-RECORD FROM TRNREC10-RECORD
    WRITE PRINT-RECORD FROM TRNREC20-RECORD
    ...

Your processing paragraphs would access the data in the copybook records.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top