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!

reading variable length record file with two ODO arrays. 1

Status
Not open for further replies.

mattyp75

Programmer
Aug 28, 2002
16
GB
I am looking for some help with a COBOL problem:

the problem is basically verifying an variable length input file is a valid record and if not change the input file definition to correct for this.

The code as is stands is:
03 FILE1-RECORD.
04 FILE1-INFO1 PIC X(90).
04 FILE1-NUMBER1 PIC 9(8).
04 FILE1-INFO2 PIC X(248).
04 FILE1-NUMBER2 PIC 9(8).
04 FILE1-TABLE-INFO1 OCCURS 1 TO 100
DEPENDING ON FILE1-NUMBER1.
05 FILE1-INFO3 PIC X(267).
04 FILE1-TABLE-INFO2 OCCURS 1 TO 100
DEPENDING ON FILE1-NUMBER2.
05 FILE1-INFO4 PIC 9(2).

03 WS-NUMBER1 PIC 9(8) VALUE 100.
03 WS-NUMBER2 PIC 9(8) VALUE 100.
03 WS-RECORD.
04 WS-INFO1 PIC X(90).
04 WS-N1 PIC 9(8).
04 WS-INFO2 PIC X(248).
04 WS-N2 PIC 9(8).
04 WS-CARDHOLDERS-INFO OCCURS 1 TO 100
DEPENDING ON WS-NUMBER1.
05 WS-INFO3 PIC X(267).
04 WS-TRANSACTION-INFO OCCURS 1 TO 100
DEPENDING ON WS-NUMBER2.
05 WS-INFO4 PIC 9(2).

The data is first moved from the file1 record structure to the working storage.
I want to verify that FILE1-NUMBER1 is correct (I can do this as if it reads past the end of this table it will hit numeric data rather than alpha-numeric data) and thus be able to read the second array correctly.

The main problem is referencing the second array if the first arrays ODO variable is incorrect, even though I have found a way to find the correct value in the program I cannot seem to make the input structure dynamic enough to update the input file structure so that for example say if originally file1-number1 is 4 and after checking this I find it to be 3, the program does not seem able to change where it is looking for the second array. The maximum size of the array is 100 for both arrays. I set the initial values of WS-NUMBER1 to 100 so to take the whole record if either FILE1-NUMBER1 or FILE1-NUMBER2 are less than the extents of the tables they are meant to refer to.

When I run my code perfroming functions on the second array it abends due to it not reading from the correct place.

If anyone has any advice or code it would help greatly.

Matt

p.s. I am using COBOL 2 on an MVS mainframe.
 
Hi Matt,

You said:
"...for example say if originally file1-number1 is 4 and after checking this I find it to be 3..."

Why would the field contain an incorrect value?


You said:
"...it will hit numeric data rather than alpha-numeric data..."

Do you mean alphbetic data? A/N data can contain numerals, which could give a false reading of the lengths.

If you CAN predict the length of the first table, you may want to consider not using ODO to define the record, but use it in the FD record contains clause. Then use a ref-mod move loop into the WS tables (subscript the WS receiving fields) adding 1 to the ws-numberx field before each move (init them to zero, not 100). Use the FD ODO field to regulate the loop.

It might work.

HTH, Jack
 
Thanks for your advice, I have now rectified the problem.
You were right in thinking i meant alphabetic rather than alpha-numeric data.

I did use a similar approach to what you mentioned. As to why the field should contain an incorrect value, I don't expect this to occur. I just needed to code so that the code was robust enough to withstand all invalid data that was passed into it. Isn't that good programming practice? In the real world assuming the data is coming to you in the exact format you want it is not the best assumption to make.
Testing should take into account anything that can go wrong.

Many thanks for your advice. I will post the code I used later so that anyone who has a similar problem like this can in future use this as reference.

Matt
 
Hi Matt,

I've dealt w/my share of ODO data and I havn't come across anyone checking the arrays. But there was one case where "foreign" data was to contain a 6 element array but only 4 or 5 were filled, causing all sorts of problems.

It would be interesting to hear of other experiences from the rest of the group. What's your take?

P.S.

I wrote the following, had trouble sending it, then forgot about it. I know you said you had a solution, but FWIW, here it is:

In the FD code:
Code:
FD FILE1
   RECORD CONTAINS 623 TO 27254 CHARACTERS
          DEPENDING ON WS-REC-LEN.
01  FILE1-RECORD.
    03  FILLER OCCURS 623 TO 27254 TIMES
               DEPENDING ON WS-REC-LEN
                     PIC  X(001).
  
01  FILE1-REDEF.
03  FIXED-PART. 
    04 INFO1         PIC  X(90).          
    04 NUMBER1       PIC  9(8).           
    04 INFO2         PIC  X(248).         
    04 NUMBER2       PIC  9(8).
03  VAR-PART         PIC  X(26900).

In WS, as you describe it:
 
03 WS-NUMBER1        PIC 9(8) VALUE 0.
03 WS-NUMBER2        PIC 9(8) VALUE 0.
03 WS-RECORD.
   04 WS-INFO1       PIC X(90).          
   04 WS-N1          PIC 9(8).           
   04 WS-INFO2       PIC X(248).         
   04 WS-N2          PIC 9(8).           
   04 WS-CARDHOLDERS-INFO OCCURS 1 TO 100
      DEPENDING ON WS-NUMBER1.       
      05 WS-INFO3    PIC X(267).         
   04 WS-TRANSACTION-INFO OCCURS 1 TO 100
      DEPENDING ON WS-NUMBER2.         
      05 WS-INFO4    PIC 9(2).           

Some work fields: 

01  WS-WRK-FLDS.
05  SEG-PTR     PIC S9(004) COMP VALUE +1.
05  SUB         PIC S9(004) COMP VALUE +1.
05  WS-REC-LEN  PIC S9(004) COMP. 



After you read a record, its length is in WS-REC-LEN if you need it.
When you determine the value of NUMBER1 and NUMBER2 move them to their WS counter-parts. 
Now start the move loops:

PERFORM WS-NUMBER1 TIMES
   MOVE VAR-PART(SEG-PTR:267) TO WS-INFO3(SUB)
   ADD +1   TO SUB
   ADD +267 TO SEG-PTR
END-PERFORM
MOVE +1 TO SUB
PERFORM WS-NUMBER2 TIMES
   MOVE VAR-PART(SEG-PTR:002) TO WS-INFO4(SUB)
   ADD +1   TO SUB
   ADD +2   TO SEG-PTR
END-PERFORM
You may want to use WS-REC-LEN to verify that you picked up all, and only all the data you needed. With any kind of luck, this should work.

HTH, Jack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top