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 Mike Lewis 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 KSDS file

Status
Not open for further replies.

lakekids

Programmer
Apr 20, 2007
2
US
How do I set my program up to read a variable length KSDS file? I am using Enterprise COBOL for z/os.I want to read a variable length KSDS sequentially. My program reads the first 3 records successfully and then gets a file status of 04 - wrong length record. The longest record can be 1018 bytes.I have the following code :
Code:
       SELECT CUSTMSTR-FILE                         
       ASSIGN TO  CUSTMSTR                   
       ACCESS MODE  IS SEQUENTIAL            
       ORGANIZATION IS INDEXED               
       RECORD KEY   IS CUSTMSTR-REC-KEY      
       FILE STATUS  IS CUSTMSTR-STATUS       
                       CUSTMSTR-VSAM-STATUS.  

 FILE SECTION.                                         
 FD  CUSTMSTR-FILE                                     
     RECORD IS VARYING                                 
     DEPENDING ON WS-CUSTMSTR-LENGTH.                  
 01  CUSTMSTR-RECORD.                                  
     03  CUSTMSTR-REC-KEY   PIC X(66).                
     03  CUSTMSTR-DATA      PIC X(952).      


 WORKING-STORAGE SECTION.                             
 01  WS-CUSTMSTR-LENGTH   PIC 9(04) COMP.   
.....
                                                
 READ CUSTMSTR-FILE                             
 AT END                                         
      SET END-OF-FILE TO TRUE                   
 END-READ.                                      
                                                
 IF END-OF-FILE                                 
    CONTINUE                                    
 ELSE                                           
    EVALUATE CUSTMSTR-STATUS                    
    WHEN '00'                                   
       INITIALIZE CIRMISC                       
       MOVE CUSTMSTR-REC-KEY  TO CIRMISC-REC-KEY
      PERFORM C010-WRITE-CIKMISC                
    WHEN '10'                                   
       CONTINUE                                 
    WHEN OTHER                                  
       MOVE CUSTMSTR-VSAM-STATUS TO VSAM-STATUS 
       PERFORM VSAM-CODE-DISPLAY                
    END-EVALUATE                                
  end-if.
 
A file status of 04 - Wrongh Length Record indicates that a record longer than the longest specified record (1018) has been read. This is a non-critical error. The fact that you were able to open the file with this FD indicates that the system thinks that the longest record should be 1018. That there actually exists a record longer than that is an anomoly that should be brought to the attention of the DBA or whomever is in charge or the fiel integrety.

However, I generally ignore any file status less that 10. The program should be able to continue processing without any significant problems. In other words, the WHEN 00 should be changed to WHEN < 10
 
The file status code 04 will also be returned if the value of WS-CUSTMSTR-LENGTH doesn't correspond to the record you have just read. From your code it is not possible to see where you are setting the value of this field. My suggestion is to display the value of WS-CUSTMSTR-LENGTH and check this against the record each time an 04 status code is returned.
 
Hi Kids,

If you're still out there, try changing the RECORD IS VARYING line to:

RECORD IS VARYING FROM 1 TO the len of the largest expected rec

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Per COBOL standard, WS-CUSTMSTR-LENGTH should be set by the READ statement. Perhaps slade's suggestion will make this work properly.
 
My take would be that without the
Code:
RECORD IS VARYING FROM 1 TO ...
clause in the FD, as pointed out by Slade,

the system is giving you a file status of 04 because the length of the record that was read did not match the length of the record that was defined in the FD (953 characters long).

Code what you mean,
and mean what you code!
But by all means post your code!

Razalas
 
Sorry, Razals, the record length coded in the FD is 1018 as lakekids said. Note that 04 is a non-critical error (first digit zero). As I said earlier, I generally ignore any file status with a first digit of zero.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top