Page 1 of 1

Variable length records in COBOL LE

Posted: Tue Aug 15, 2023 2:48 pm
by chrispickles
Hi, I have a system that copies a csv to a flat file on the iSeries. I read the file in a COBOL LE program. The record is defined as 500 characters. Let say a record may contain "ADD,ABC,20230815,12.34". After I process that record I want to add a return code to the end and write it back so it becomes "ADD,ABC,20230815,12.34,00000". I get a 44 on the rewrite. Any ideas would be appreciated :)

Re: Variable length records in COBOL LE

Posted: Tue Aug 15, 2023 5:52 pm
by jonboy49
Kinda difficult to know what might be wrong without you having posted the File specifications and record layouts etc.

Re: Variable length records in COBOL LE

Posted: Tue Aug 15, 2023 8:22 pm
by Scott Klement
How are you reading/processing the CSV file? Are you reading it as a flat file, and manually splitting the fields by looking for the commas in your code? Are you using a tool that converts the CSV file to a PF? Are you using CSV processing tools?

What problem are you having when you try to add the return code?

Re: Variable length records in COBOL LE

Posted: Wed Aug 16, 2023 7:05 am
by chrispickles
The csv arrives on the IFS and I do a CPYFRMIMPF to a flat file. When the file is read by I split the record unstringing on commas. When I then add a comma and return code to the end of the record and rewrite I get the 44 due to the record being written back not being the same length.

Re: Variable length records in COBOL LE

Posted: Wed Aug 16, 2023 3:39 pm
by jonboy49
I'll repeat my earlier request ... show us some code. There are such things as (pseudo) variable length records that can be used in COBOL - but I don't know if that is what you are using without seeing your code.

Also, why are you not simply using CPYFRMIMPF to split the CSV into its component fields? It doesn't seem to make much sense to write code to split it up yourself.