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
 

 

Appending previous record SEQNUM value to current record

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 16
Location: Coimbatore

PostPosted: Fri Oct 16, 2015 2:09 pm    Post subject: Appending previous record SEQNUM value to current record
Reply with quote

Hi all,

I want to append the SEQNUM value of previous record to current record.
Corresponding position of current record will have value as Spaces.

How to achieve using SORT?. Any clue would be better.

Sample Input :

ABC ID1 2001-08-25 XXXXX 0000001
ABC ID1 2005-04-30 YYYYYY 0000002
ABC ID2 1987-08-25 123456 0000003
ABC ID2 2003-04-25 123456
ABC ID2 2011-09-21 123789 0000004
ABC ID3 2005-04-30 FFFFFFF 0000005
DEF ID3 2005-04-30 FFFFFFF

Sample Output required:
ABC ID1 2001-08-25 XXXXX 0000001
ABC ID1 2005-04-30 YYYYYY 0000002
ABC ID2 1987-08-25 123456 0000003
ABC ID2 2003-04-25 123456 0000003
ABC ID2 2011-09-21 123789 0000004
ABC ID3 2005-04-30 FFFFFFF 0000005
DEF ID3 2005-04-30 FFFFFFF 0000005

Thanks.
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Fri Oct 16, 2015 2:48 pm    Post subject: Reply to: Appending previous record SEQNUM value to current record
Reply with quote

You use IFTHEN=(WHEN=GROUP with your sequence not being blank and RECORDS=2, PUSH your sequence to an extension of the record.

Then use IFTHEN=(WHEN=(logicalexpression) to identify spaces in the seqnum, and use OVERLAY to put the extended sequence number in place of the spaces.

Return the record to it's original size. If you get that working, post the code please.
Back to top
View user's profile Send private message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 16
Location: Coimbatore

PostPosted: Fri Oct 16, 2015 4:04 pm    Post subject: Reply to: Appending previous record SEQNUM value to current record
Reply with quote

Thanks Bill.

I got the desired output.

ABC ID1 2001-08-25 XXXXX 0000001
ABC ID1 2005-04-30 YYYYYY 0000002
ABC ID2 1987-08-25 123456 0000003
ABC ID2 2003-04-25 123456 0000003
ABC ID2 2011-09-21 123789 0000004
ABC ID3 2005-04-30 FFFFFFF 0000005
DEF ID3 2005-04-30 FFFFFFF 0000005

Below is the corresponding sort card used.

//SYSIN DD *
OPTION COPY
OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(38,7,CH,NE,C' '),
PUSH=(81:38,7,SEQ=1)),
IFTHEN=(WHEN=(38,7,CH,EQ,C' '),OVERLAY=(38:81,7))
//*

Bill,

I am achieving this output using three sort steps.

On first step, I am generating Seqnum based on Key values and used RESTART to start the Sequencing, if key value changes.
On second step, I am re-sequencing and moving spaces.
On final step, I am appending the previous record sequence num.

Can this be written in a single sort step?.

Code:
//SORTIN DD *
ABC ID1 2001-08-25 XXXXX
ABC ID1 2005-04-30 YYYYYY
ABC ID2 1987-08-25 123456
ABC ID2 2011-09-21 123789
ABC ID2 2003-04-25 123456
ABC ID3 2005-04-30 FFFFFFF
DEF ID3 2005-04-30 FFFFFFF
/*
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,7,CH,A,9,10,CH,A)
OUTREC OVERLAY=(1:1,30,50,7,SEQNUM,7,ZD,START=1,INCR=1,RESTART=(20,7))
/*
//*
//STEP0002 EXEC PGM=SORT
//SORTIN DD *
ABC ID1 2001-08-25 XXXXX 0000001
ABC ID1 2005-04-30 YYYYYY 0000001
ABC ID2 1987-08-25 123456 0000001
ABC ID2 2003-04-25 123456 0000002
ABC ID2 2011-09-21 123789 0000001
ABC ID3 2005-04-30 FFFFFFF 0000001
DEF ID3 2005-04-30 FFFFFFF 0000002
/*
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTREC IFTHEN=(WHEN=(38,7,CH,EQ,C'0000001'),
OVERLAY=(38:SEQNUM,7,ZD,START=1,INCR=1)),
IFTHEN=(WHEN=(38,7,CH,NE,C'0000001'),
OVERLAY=(38:C' '))
/*
//STEP0003 EXEC PGM=SORT
//SORTIN DD *
ABC ID1 2001-08-25 XXXXX 0000001
ABC ID1 2005-04-30 YYYYYY 0000002
ABC ID2 1987-08-25 123456 0000003
ABC ID2 2003-04-25 123456
ABC ID2 2011-09-21 123789 0000004
ABC ID3 2005-04-30 FFFFFFF 0000005
DEF ID3 2005-04-30 FFFFFFF
/*
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(38,7,CH,NE,C' '),
PUSH=(81:38,7,SEQ=1)),
IFTHEN=(WHEN=(38,7,CH,EQ,C' '),OVERLAY=(38:81,7))
//*
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Fri Oct 16, 2015 4:26 pm    Post subject: Reply to: Appending previous record SEQNUM value to current record
Reply with quote

Just quickly, the entire thing can be done in one step using IFTHEN=(WHEN=GROUP and PUSH an ID= for the length of your field. ID is a sequence number across groups, SEQ is a sequence number within a group.

You have to decide what your key is. You are SORTing on one key, but only using the low-order part of the key. This gives you a potential for "false hits" were two different high-order keys are different but consecutive, and the low-order keys are equal.
Back to top
View user's profile Send private message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 16
Location: Coimbatore

PostPosted: Mon Oct 19, 2015 4:01 pm    Post subject: Reply to: Appending previous record SEQNUM value to current record
Reply with quote

Bill,

I can able to generate Sequence number, if i explicitly mention the keyvalue in the SORT Card. But my keyvalue can be anything, other than Spaces.

Code:
//SYSIN DD *
SORT FIELDS=(1,7,CH,A,9,10,CH,A,20,7,CH,A)
OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(20,7,CH,EQ,C'FFFFFFF'),
PUSH=(81:ID=7)),
IFTHEN=(WHEN=(40,7,CH,EQ,C' '),OVERLAY=(40:81,7))
/*

Output:

ABC ID1 2001-08-25 XXXXX
ABC ID1 2005-04-30 YYYYYY
ABC ID2 1987-08-25 123456
ABC ID2 2003-04-25 123456
ABC ID2 2011-09-21 123789
ABC ID3 2005-04-30 FFFFFFF 0000001
DEF ID3 2005-04-30 FFFFFFF 0000002

Since we don't have DFSORT installed, I couldn't able to use KEYBEGIN keyword.
Back to top
View user's profile Send private message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 16
Location: Coimbatore

PostPosted: Mon Oct 19, 2015 4:15 pm    Post subject:
Reply with quote

Bill,

I checked the below post and i tried using it. It worked perfectly.

http://ibmmainframes.com/about60165.html

Code:

Code:
 SORT FIELDS=(1,7,CH,A,9,10,CH,A,20,7,CH,A)
 INREC  IFOUTLEN=80,
       IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,7,ZD,RESTART=(20,7))),
       IFTHEN=(WHEN=GROUP,BEGIN(81,7,ZD,EQ,1),PUSH=(30:ID=7))
 OUTFIL BUILD=(1,80)


Output:

Code:
ABC ID1 2001-08-25 XXXXX     0000001
ABC ID1 2005-04-30 YYYYYY    0000002
ABC ID2 1987-08-25 123456    0000003
ABC ID2 2003-04-25 123456    0000003
ABC ID2 2011-09-21 123789    0000004
ABC ID3 2005-04-30 FFFFFFF   0000005
DEF ID3 2005-04-30 FFFFFFF   0000005


Thanks.

Code'd and link de-mangled
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Mon Oct 19, 2015 5:47 pm    Post subject: Reply to: Appending previous record SEQNUM value to current record
Reply with quote

The IFOUTLEN will have already set the record-length to 80, so when INREC is complete only the original 80 bytes are present, and you don't need the OUTFIL with BUILD.
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 How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
This topic is locked: you cannot edit posts or make replies. How to pass the previous month date i... Suganya87 DFSORT/ICETOOL 5 Mon Oct 31, 2016 4:13 pm
No new posts How to get previous month in SYMNAMES Suganya87 SYNCSORT 9 Fri Oct 28, 2016 1:37 pm
This topic is locked: you cannot edit posts or make replies. Get correct date and time when curren... balaji81_k DB2 24 Fri Oct 14, 2016 10:40 pm
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am


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