Variable length records in COBOL LE

Any IBM i topic that does not fit in another forum
Post Reply
chrispickles
Posts: 4
Joined: Tue May 30, 2023 12:59 pm

Variable length records in COBOL LE

Post 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 :)
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Variable length records in COBOL LE

Post by jonboy49 »

Kinda difficult to know what might be wrong without you having posted the File specifications and record layouts etc.
Scott Klement
Site Admin
Posts: 653
Joined: Sun Jul 04, 2021 5:12 am

Re: Variable length records in COBOL LE

Post 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?
chrispickles
Posts: 4
Joined: Tue May 30, 2023 12:59 pm

Re: Variable length records in COBOL LE

Post 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.
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Variable length records in COBOL LE

Post 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.
Post Reply