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

Insert a tag-field when field changes


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

New User


Joined: 14 Aug 2007
Posts: 14
Location: Chennai

PostPosted: Thu Aug 30, 2012 9:06 pm
Reply with quote

Hi

I got a requirement which is explained below

File1: My input file looks like this

Code:
XX000100.10
XX000500.34
XX000678.23
XX000099.42
YY000578.98
YY000728.00
ZZ000356.89
ZZ178728.90



Requirement:

When the first two byte code breaks(i.e. changes from XX to YY) a tag 'EC' need to be inserted on the last XX record.

after the logic my file should look like

Code:
XX000100.10
XX000500.34
XX000678.23
XX000099.42EC
YY000578.98
YY000728.00EC
ZZ000356.89
ZZ178728.90EC


Is there a way to do this in DFSORT?

Your help is appreciated.

Code'd
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Thu Aug 30, 2012 10:26 pm
Reply with quote

sthirumalai,

Use the following DFSORT JCL which will give you the desired results. The trick here is to use the same file twice and match on the seqnum.

I assumed that your input is RECFM=FB and LRECL=80

Code:

//STEP0100 EXEC PGM=SORT                               
//SYSOUT   DD SYSOUT=*                                 
//INA      DD *                                       
XX000100.10                                           
XX000500.34                                           
XX000678.23                                           
XX000099.42                                           
YY000578.98                                           
YY000728.00                                           
ZZ000356.89                                           
ZZ178728.90                                           
//INB      DD *                                       
XX000100.10                                           
XX000500.34                                           
XX000678.23                                           
XX000099.42                                           
YY000578.98                                           
YY000728.00                                           
ZZ000356.89                                           
ZZ178728.90                                           
//SORTOUT  DD SYSOUT=*                                 
//SYSIN    DD *                                       
  OPTION COPY                                         
  JOINKEYS F1=INA,FIELDS=(81,8,A),SORTED,NOSEQCK       
  JOINKEYS F2=INB,FIELDS=(81,8,A),SORTED,NOSEQCK       
  JOIN UNPAIRED,F1                                     

  REFORMAT FIELDS=(F1:1,80,F2:1,2,?)                                 
  INREC IFOUTLEN=80,                                                 
  IFTHEN=(WHEN=(1,2,CH,NE,81,2,CH,OR,83,1,ZD,EQ,1),OVERLAY=(12:C'EC'))

//*                                                   
//JNF1CNTL DD *                                       
  INREC OVERLAY=(81:SEQNUM,8,ZD)                       
//*                                                   
//JNF2CNTL DD *                                       
  INREC OVERLAY=(81:SEQNUM,8,ZD,START=0)               
//*


The output from this is
Code:

XX000100.10   
XX000500.34   
XX000678.23   
XX000099.42EC
YY000578.98   
YY000728.00EC
ZZ000356.89   
ZZ178728.90EC
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 Aug 30, 2012 10:47 pm
Reply with quote

This is worth fully understanding, rather than just poking it into production cos it works.

It took me some time to get it, so here's what I came to. Hope I got it all :-)

Don't be confused by all the 81s. There are two different sets of them.

The two JNFnCNTL files add a sequence number to each record, but the sequence number is "off by one" between the two files. The main file (F1) has the larger sequence number (default start for sequence number is one), and that is important.

The JOINKEYS matches on the sequence number.

After that point, forget the sequence number, it is irrelevant.

The REFORMAT takes the whole F1 record and the first two bytes of the F2 record, the key.
These two bytes on the REFORMAT record start at position 81.

Now the single REFORMAT record contains "current" record and "next" record key. When "current" and "next" keys are different, the "current" is the last of that key.

Everything goes smoothly until the last record on F1, which doesn't match to a sequence number on F2. No problem, that is what the UNPAIRED,F1 is for. The ? match marker will have a value of "1", which will indicate end of group, and indeed end-of-file if that is required.

Thanks Kolusu, that is useful, not only in itself, but also for thinking about how to do other things.
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: Fri Aug 31, 2012 6:51 am
Reply with quote

Partly so that interested parties get to see the edits, I'll add that the technique has also been used to keep running-totals for records by key and a somewhat esoteric "delete duplicates without sorting" (which can be done with ICETOOL anyway).

For anything which requires the presence of data/keys at the same time from consecutive records, this technique can be considered.
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Identify Program Insert DB2 7
Search our Forums:

Back to Top