Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Insert a tag-field when field changes

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Insert a tag-field when field changes
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Thu Aug 30, 2012 10:47 pm    Post subject: Reply to: Insert a tag-field when field changes
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Fri Aug 31, 2012 6:51 am    Post subject: Reply to: Insert a tag-field when field changes
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts outrec field outside range Danielle.Filteau SYNCSORT 10 Sat Mar 04, 2017 2:37 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us