Page 1 of 1

Writing the file with layout

PostPosted: Thu Jan 06, 2011 2:59 pm
by Suganya.Shanmugam
I have the requirement like below:
Two input files. one will have the file layout and the other will have values for that layout.
I need to read the layout and pull the values and have to write it in the output file.
for eg:
Layout of the file is
05 abc 9(5)
05 def9(8)
05 sdhf x(5)

File2 will have val for the layout mentioned above as 111112222222233333

what i need in output is in the below format
abc 11111
def 22222222
sdhf 33333
please help in coding this requirement.

Re: Writing the file with layout

PostPosted: Thu Jan 06, 2011 5:36 pm
by Akatsukami
I recommend that you read and process the first data set, creating and filling stems of field tag, field type, starting position, and length (although in the sample data that you present the fields are contiguous and presumably start in position 1, this may not always be the case). Then process the second data set; for each input record iterate through the stems and use the SUBSTR function and concatenation operator to create an output record.

Aside from the obvious return code checks, there are at least two potential error conditions that you have to handle:

  1. What if the data record is of a different length than the layout?
  2. What if the data are different from the field definition (i.e., the field is defined as 9(6), but the data are "ABCXYZ")?
There are likely others, but I'm not moved to do a thorough job of analysis just now.