|
View previous topic :: View next topic
|
| Author |
Message |
rohanthengal
Active User
.jpg)
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. |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1442 Location: Bamberg, Germany
|
|
|
|
| And the question is, what have you tried so far to achieve this? |
|
| Back to top |
|
 |
rohanthengal
Active User
.jpg)
Joined: 19 Mar 2009 Posts: 206 Location: Globe, India
|
|
|
|
I am thinking about solution either of sortcard, rexx to do that.
Whichever is best, could do that.
I am not much familiar with SORT cards to do these so thought to check here. |
|
| Back to top |
|
 |
Willy Jensen
Active Member

Joined: 01 Sep 2015 Posts: 774 Location: Denmark
|
|
|
|
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)" |
|
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1442 Location: Bamberg, Germany
|
|
|
|
Note DD:F1 and DD:F2 have to be exactly the same input.
| Code: |
//TRLCHECK EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//F1 DD *
HEADER2020-06-20
COL1,COL2,COL3,COL4
TRAILER0000
/*
//F2 DD *
HEADER2020-06-20
COL1,COL2,COL3,COL4
TRAILER0000
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=F1,FIELDS=(41,1,A)
JOINKEYS F2=F2,FIELDS=(41,1,A)
REFORMAT FIELDS=(F1:1,40,F1:42,1,F2:43,4)
OUTFIL FNAMES=(SORTOUT),
OMIT=(41,1,CH,EQ,C'D',AND,42,4,ZD,EQ,+0),
REMOVECC,
BUILD=(1,40)
/*
//JNF1CNTL DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(41:C'XD',4X)),
IFTHEN=(WHEN=(1,6,CH,EQ,C'HEADER'),OVERLAY=(42:C'H')),
IFTHEN=(WHEN=(1,7,CH,EQ,C'TRAILER'),OVERLAY=(42:C'T'))
END
/*
//JNF2CNTL DD *
INCLUDE COND=(1,7,CH,EQ,C'TRAILER')
INREC BUILD=(41:C'X',X,8,4)
END
/* |
Output for TRAILER0000:
| Code: |
****** *****************
000001 HEADER2020-06-20
000002 TRAILER0000
****** ***************** |
Output for TRAILER0008:
| Code: |
****** ********************
000001 HEADER2020-06-20
000002 COL1,COL2,COL3,COL4
000003 TRAILER0008
****** ******************** |
|
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
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. |
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1442 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. |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
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. |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
Moot point as OP has not come back but
| Quote: |
| if zero then i want to copy just header and trailer from the input record. |
Note he wants output if trailer is 0 - not any other number. |
|
| Back to top |
|
 |
Rohit Umarjikar
Global Moderator

Joined: 21 Sep 2010 Posts: 3109 Location: NYC,USA
|
|
|
|
This is one another way, You can change the offsets as per your record offset and good to go. You can also do 3 pass to 2 and 2 to 1 if you want.
| Code: |
//STEP01 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
HDR1234
DTLAAAA
TRL0000
//TMP1 DD DISP=(NEW,PASS),
// UNIT=SYSDA,SPACE=(TRK,(10,10),RLSE),
// DSN=&&MASTER
//TMP2 DD DISP=(NEW,PASS),
// UNIT=SYSDA,SPACE=(TRK,(10,10),RLSE),
// DSN=&&MASTER
//OUT DD SYSOUT=*
//TOOLIN DD *
RESIZE FROM(IN) TO(TMP1) TOLEN(80) USING(CTL1)
COPY FROM(TMP1) TO(TMP2) USING(CTL2)
COPY FROM(TMP2) TO(OUT) USING(CTL3)
//CTL1CNTL DD *
INREC BUILD=(1,10)
OUTFIL BUILD=(1,80)
//CTL2CNTL DD *
INREC IFTHEN=(WHEN=(21,7,CH,EQ,C'TRL0000'),
OVERLAY=(81:1,10,10X,21,10)),
IFTHEN=(WHEN=(21,7,CH,NE,C'TRL0000'),
OVERLAY=(81:1,10,11,10,21,10))
OUTFIL BUILD=(81,10,/,91,10,/,101,10)
//CTL3CNTL DD *
OMIT COND=(1,1,CH,EQ,C' ') |
Output-
| Code: |
********************************* TOP OF DATA **********************************
HDR1234
TRL0000
******************************** BOTTOM OF DATA ******************************** |
When TRL0001 << other than 0000 then
| Code: |
********************************* TOP OF DATA **********************************
HDR1234
DTLAAAA
TRL0001
******************************** BOTTOM OF DATA ******************************** |
|
|
| Back to top |
|
 |
Joerg.Findeisen
Senior Member

Joined: 15 Aug 2015 Posts: 1442 Location: Bamberg, Germany
|
|
|
|
And one more:
| Code: |
//A EXEC PGM=ICEMAN
//SORTIN DD *
HEADER2020-06-20
COL1,COL2,COL3,COL4
TRAILER0000
/*
//SYSOUT DD SYSOUT=*
//SORTOUT DD DISP=(NEW,PASS),UNIT=SYSALLDA,
// SPACE=(CYL,(2,1),RLSE),
// DSORG=PS,RECFM=FB,LRECL=80,BLKSIZE=0
//SYSIN DD *
INREC IFTHEN=(WHEN=INIT,OVERLAY=(41:SEQNUM,8,ZD))
SORT FIELDS=(41,8,ZD,D)
OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(1,7,CH,EQ,C'TRAILER'),PUSH=(49:8,4))
END
/*
//B EXEC PGM=ICEMAN
//SORTIN DD DISP=(OLD,PASS),DSN=*.A.SORTOUT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INCLUDE COND=(1,6,CH,EQ,C'HEADER',OR,1,7,CH,EQ,C'TRAILER',OR,
49,4,ZD,NE,+0)
SORT FIELDS=(41,8,ZD,A)
OUTFIL BUILD=(1,40)
END
/* |
|
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|