Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
I am working on one requirement where I need to check if trailer count is zero, if zero then i want to copy just header and trailer from the input record.
Code:
HEADER2020-06-20
COL1,COL2,COL3,COL4
TRAILER0000
Output should have below:
Code:
HEADER2020-06-20
TRAILER0000
I am just thinking to drop COL1,COL2,COL3,COL4 line from input file and retain HEADER, TRAILER record.
If you never have more than 3, or at least a small number of, records, then I would go with a REXX pgm. Otherwise I would start looking at SORT, though I cannot offhand say that it is possible with SORT.
REXX will be something like this:
Code:
"execio * diskr in (stem in.)"
if right(value('in.'in.0),4)=0 then do
queue in.1
queue value('in.'in.0)
"execio 2 diskw out (finis)"
end
else "execio" in.0 "diskw out (stem in. finis)"
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
I assume that if the trailer count is not 0 then there will be many data records i..e. more than 0. I assume, maybe wrongly, that the second record (COPY....) is not a data record so will be in an 'empty' dataset. If that is correct then surely you read 4 records (STOPAFT=4) assigning sequence numbers and if the highest sequence number is 4 then this is not an empty dataset so you STOP. If the highest sequence number is 3 then there are no data records so only output records with sequence numbers 1 and 3.
For a Rexx solution you only meed to read 4 records again and if RC=400 (I think 400 is EOF) then there were only 3 records so output records 1 and 3.
Joined: 15 Aug 2015 Posts: 1348 Location: Bamberg, Germany
@Nic: With STOPAFT=n you will not be able to print the existing trailer record if the number of data records exceeds n. TS request was to have HDR/TRL in any case.
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
Well, he needs to clarify with data examples. To me it looks like the data is in csv format and the record with col1, col2 etc is a column headings record that is written before it is found that there are zero records to output. He says he wants header and trailer records written when the dataset is empty i.e. no data records. I do not think that he is wanting to check for the trailer having a zero count when there are data records. Clarification needed.
********************************* TOP OF DATA **********************************
HDR1234
TRL0000
******************************** BOTTOM OF DATA ********************************
When TRL0001 << other than 0000 then
Code:
********************************* TOP OF DATA **********************************
HDR1234
DTLAAAA
TRL0001
******************************** BOTTOM OF DATA ********************************