IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Extracting records between a header and trailer


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Indrajit_57
Warnings : 1

New User


Joined: 27 Jun 2006
Posts: 60

PostPosted: Thu Sep 22, 2011 6:33 pm
Reply with quote

I have an variable length input file of length 1040 bytes. The format of the file is

HDRRec VersionNbr1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec
HDRRec VersionNbr2
Detial Rec 1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec
HDRRec VersionNbr1
Detial Rec 1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec

My requirement is, if the VersionNbr in HDRRec is 1, then all detail records (including Header and Trailer) under that Header Record needs to be extracted and written into a new file. So in this case the output will be

HDRRec VersionNbr1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec
HDRRec VersionNbr1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec




The Header record is identified by the keyword HDR which starts at position 1 and trailer record is identified by the keyword TRL which starts at position 1. The version number will be starting at position 41 and will be 8 bytes in length.

Can this be achieved using DFSORT?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 6:44 pm
Reply with quote

Yes, I'm pretty sure it can.

If you look through the forum you'll get some good hints as to how, even.
Back to top
View user's profile Send private message
Indrajit_57
Warnings : 1

New User


Joined: 27 Jun 2006
Posts: 60

PostPosted: Thu Sep 22, 2011 6:54 pm
Reply with quote

I had searched the forum and written the following sort card

OPTION COPY
INREC IFTHEN=(WHEN=INIT,OVERLAY=(1040:C'N')),
IFTHEN=(WHEN=(1,3,CH,EQ,C'HDR',AND,41,8,ZD,EQ,0001),
OVERLAY=(1041:C'0'),HIT=NEXT),
IFTHEN=(WHEN=(1,3,CH,EQ,C'TRL'),
OVERLAY=(1041:C'9'),HIT=NEXT)

The problem I am facing is that the detail records are always getting marked with 'N' even if the header record is satisfying the conditions.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Thu Sep 22, 2011 7:42 pm
Reply with quote

Code:

HDRRec VersionNbr1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec
HDRRec VersionNbr2
Detial Rec 1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec
HDRRec VersionNbr1
Detial Rec 1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec

For your shown input I am really wondering what rules you want to apply to get below output(Shown by you)
Code:

HDRRec VersionNbr1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec
HDRRec VersionNbr1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec


Why below is not output?

Code:

HDRRec VersionNbr1
Detial Rec 1
Detail Rec 1
Detail Rec 2
Detail Rec 3
TRLRec
Back to top
View user's profile Send private message
elango_K

New User


Joined: 18 Aug 2011
Posts: 44
Location: India

PostPosted: Thu Sep 22, 2011 8:22 pm
Reply with quote

Code:

INREC IFTHEN=(WHEN=INIT,OVERLAY=(1040:C'N')),
IFTHEN=(WHEN=(1,3,CH,EQ,C'HDR',AND,41,8,ZD,EQ,0001),
OVERLAY=(1041:C'0'),HIT=NEXT),
IFTHEN=(WHEN=(1,3,CH,EQ,C'TRL'),
OVERLAY=(1041:C'9'),HIT=NEXT)


You are using a VB file, your header will not satisfy this condition.
Start from position 5 .
Back to top
View user's profile Send private message
elango_K

New User


Joined: 18 Aug 2011
Posts: 44
Location: India

PostPosted: Thu Sep 22, 2011 8:34 pm
Reply with quote

Try this:

Code:

//SYSIN    DD *                                         
  OPTION COPY                                           
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(5,3,CH,EQ,C'HDR',AND,
  41,8,ZD,EQ,1),END=(5,3,CH,EQ,C'TRL'),PUSH=(1041:ID=8))
  OUTFIL OMIT=(1041,1,CH,NE,C'0'),BUILD=(1,1040)       
 
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Sep 22, 2011 10:03 pm
Reply with quote

Indrajit_57,
If you pad the group-id indicator at the end of a VB file you will ruin the very concept of VB files and make them all fixed block.

I assumed that your HDR value starts in pos 5 ( first 4 byte of RDW) and the number 1 starts in position 22. In order to retain the original lengths of the VB file, we pad a 1 byte space right after the RDW and use that for pushing the Group-id indicator. since we padded the space before the actual record , now your positions are incremented by 1. So the HDR is now at position 6 and the number is at position 23. While writing out we remove that field, there by retaining the original VB file lengths for each record.


Use the following DFSORT JCL.

Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD DSN=Your Input VB 1040 Lrecl file,DISP=SHR
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                               
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,X,5)),                     
  IFTHEN=(WHEN=GROUP,BEGIN=(6,3,CH,EQ,C'HDR',AND,23,1,ZD,EQ,1), 
  END=(6,3,CH,EQ,C'TRL'),PUSH=(5:ID=1))                         
  OUTFIL OMIT=(5,1,CH,EQ,C' '),BUILD=(1,4,6)                     
//*
Back to top
View user's profile Send private message
Indrajit_57
Warnings : 1

New User


Joined: 27 Jun 2006
Posts: 60

PostPosted: Fri Sep 23, 2011 5:55 pm
Reply with quote

Thanks Skolusu. It is working fine for me.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Help in extracting data between doubl... DFSORT/ICETOOL 5
No new posts Join multiple records using splice DFSORT/ICETOOL 5
Search our Forums:

Back to Top