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

How to swap records using Syscsort?


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Sat Apr 21, 2012 7:53 pm
Reply with quote

I have a requirement as to swap a record.

Input file:
Code:

Header                                     
Act Num:123456789
Off:xyz.com
Emp Name:XXX
Manager:YYY
Pos:AAA
End

Header                                     
Act Num:58697423
Off:asd.com
Emp Name:qqq
Manager:yyy
Pos:cc
contant subjected to feed
.
.
end


Header                                     
Act Num:001234566
Off:abc.com
Emp Name:zzz
Manager:xxx
Pos:bbb
contant subjected to feed
.
.
End

i have to shift the record which starts with <Off> after <Pos> each time whn it occurs. I have a starting tag as <Header> and ending as <END>
Input and output LRECL is 80 FB.

Output required:

Code:
Header                                     
Act Num:123456789
Emp Name:XXX
Manager:YYY
Pos:AAA
Off:xyz.com
End

Header                                     
Act Num:58697423
Emp Name:qqq
Manager:yyy
Pos:cc
Off:asd.com
contant subjected to feed
.
.

end


Header                                     
Act Num:001234566
Emp Name:zzz
Manager:xxx
Pos:bbb
Off:abc.com
contant subjected to feed
.
.

End


Can you help how to acheive this using syncort/Icetool?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Apr 21, 2012 8:03 pm
Reply with quote

Quote:
How to swap records using Syscsort?

if You know that You are using syncsort why in h*** are You posting in the DFSORT section ?

topic moved icon_evil.gif

do You have problems with the logic or the coding ?

are the records in a group ALWAYS in the same order ?

You might for example

use the when group to push a group identifier on each each record

insert a sequence number according to the order of tags

before
Code:
001 Header                                     
002 Act Num:123456789
003 Off:xyz.com
004 Emp Name:XXX
005 Manager:YYY
006 Pos:AAA
007 End


after
Code:

001 Header                                     
002 Act Num:123456789
006 Off:xyz.com
003 Emp Name:XXX
004 Manager:YYY
005 Pos:AAA
007 End


sort on group id and record sequence number

rebuild the output records dropping the group id and the sequence number

quite a few example around on how to do it

when building the output record just drop the group id and the record sequence number

with all the suggestions You were given in Your previous questions
it would be nice on You side to demonstrate some ingenuity
showing that <we> have not wasted our time by spoon feeding You!

how to assign a record sequence number
Code:
IFTHEN=(WHEN=(1,6,CH,EQ,C'Header'),OVERLAY=(90:c'001')),
...
IFTHEN=(WHEN=(1,3,CH,EQ,C'Off'),OVERLAY=(90:c'006'))
IFTHEN=(WHEN=(1,3,CH,EQ,C'Pos'),OVERLAY=(90:c'005'))
...



how to push a group id
Code:
INREC IFTHEN=(WHEN=GROUP,                                         
              BEGIN=(1,8,CH,EQ,C'xxxxxxxxxxx'),                     
              END=(1,6,CH,EQ,C'yyyyyyyy'),                         
              PUSH=(81:ID=5))


change appropriately for the current positions, lengths, values

do things in stages without cleaning up the record to understand the logic

stage 1 add the group id
stage 2 add the record sequence
stage 3 combine the two things
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Sat Apr 21, 2012 10:27 pm
Reply with quote

Quote:
are the records in a group ALWAYS in the same order ?


Yes, The group will be in the same order, Starting with
Header,Act Num,Off,Emp Name,Manager,Pos, <some data undetermined length> and End tag.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Apr 21, 2012 11:28 pm
Reply with quote

Hello,

What have you tried so far?

What hppened?
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: Sun Apr 22, 2012 3:17 am
Reply with quote

This is by far the simplest of your recent requirements, and in the solutions so far provided you have more than enough to do the task.

Despite your subject, you are not "swapping" records that I can see, but just moving one record after a particular other record,

You need to save the record you want to move, in such a way that it can be accessed when another record is present. That'll be PUSH. PUSH only works with something else, so you'll need that. The original record you no longer need, so you need to get rid of it, so an OMIT somewhere along the way. When you identify the record that the data should appear after, you'll need to be able to cause both records to be written, which'll be the / (slash operator).

That's about it.
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: Sun Apr 22, 2012 3:39 am
Reply with quote

An implementation of enrico's suggestion, but it can be done, differently, without the sort.

This introduces a "half" value to be sorted on. An ordinary sequence number is assinged, followed by a zero. On finding the "OFF:", three is added to the sequence number and the extra byte is set to "5". Then the SORT is on the sequence+extra-byte. Finally the sequence+extra-byte is stripped off to leave the final file.

If you do want to swap records, this method could be used, as long as you know the "distance" between the records all the time, and you wouldn't have to have the extra byte.

Code:
//MOVEREC  EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN DD *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,C'0')),
        IFTHEN=(WHEN=(1,4,CH,EQ,C'OFF:'),
                 OVERLAY=(81:81,8,ZD,ADD,+3,EDIT=(TTTTTTTT),
                 89:C'5'))
  SORT FIELDS=(81,9,CH,A)
  OUTREC BUILD=(1,80)
                                                           
//SORTIN DD *
HEADER
ACT NUM:123456789
OFF:XYZ.COM
EMP NAME:XXX
MANAGER:YYY
POS:AAA
END
                                                           
HEADER
ACT NUM:58697423
OFF:ASD.COM
EMP NAME:QQQ
MANAGER:YYY
POS:CC
CONTANT SUBJECTED TO FEED
.
.
END
                                                           
                                                           
HEADER
ACT NUM:001234566
OFF:ABC.COM
EMP NAME:ZZZ
MANAGER:XXX
POS:BBB
CONTANT SUBJECTED TO FEED
.
.
END


Gives:

Code:
HEADER                   
ACT NUM:123456789       
EMP NAME:XXX             
MANAGER:YYY             
POS:AAA                 
OFF:XYZ.COM             
END                     
                         
HEADER                   
ACT NUM:58697423         
EMP NAME:QQQ             
MANAGER:YYY             
POS:CC                   
OFF:ASD.COM             
CONTANT SUBJECTED TO FEED
.                       
.                       
END                     
                         
                         
HEADER                   
ACT NUM:001234566       
EMP NAME:ZZZ             
MANAGER:XXX             
POS:BBB                 
OFF:ABC.COM             
CONTANT SUBJECTED TO FEED
.                       
.                       
END   
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Sun Apr 22, 2012 9:20 pm
Reply with quote

Many thanks Bill.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sun Apr 22, 2012 9:48 pm
Reply with quote

once again somebody on the forum did the job for which the TS is getting paid for icon_evil.gif
Back to top
View user's profile Send private message
sabarikanth

New User


Joined: 07 Jun 2010
Posts: 59
Location: coimbatore

PostPosted: Sun Apr 22, 2012 9:54 pm
Reply with quote

Enrico,
I'm at a beginner level at Syncsort/Icetool. But I was even trying for a resolution which you have advised. Thanks for your guidance too. Still many things is there in my requirement I'm trying with solution which has been posted. Thanks again for this forum..!!!
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sun Apr 22, 2012 10:27 pm
Reply with quote

I am a beginner is the standard excuse
for just sitting lazily waiting for somebody to the job on your behalf,

this is a help forum , not a do my job one...

it means post what You have tried an we will help
You to fix the errors,
make your solution work
and mybe help You on how to find a better one

You just failed in giving evidence of Your attempts
icon_evil.gif
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: Mon Apr 23, 2012 3:06 am
Reply with quote

Sab,

I didn't provide the last intending that you use it. It was an implementation of enrico's solution with a sort, which would also allow you a swap if you actually needed it (which you don't seem to).

You can achieve your current requirement without sorting the file, so without using unnecessary resources.

If you need the swap, it can again be done without sorting the file, but will be more complicated. If your files are small, use the sort. If you files are big, do the swap in one pass. If your files are intermediate in size, make a reasoned decision yourself/at your site.

With another proposed solution to one of your other questions you had multiple passes of a file. The less you read/write, generally, the less it costs, to your organisation.

Look at what I wrote:

Quote:
You need to save the record you want to move, in such a way that it can be accessed when another record is present. That'll be PUSH. PUSH only works with something else, so you'll need that. The original record you no longer need, so you need to get rid of it, so an OMIT somewhere along the way. When you identify the record that the data should appear after, you'll need to be able to cause both records to be written, which'll be the / (slash operator).


Look at what enrico wrote:

Quote:
do things in stages without cleaning up the record to understand the logic


Look at what Dick wrote:

Quote:
What have you tried so far?

What happened?


So, please try to get the non-sorting solution. Here's a leg-up.

This is broken down, as enrico suggested, so you can see how it works.

First, HEADER defines the start of a group, so make that a GROUP.

Code:
//SWAP01   EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=GROUP,
                  BEGIN=(1,9,CH,EQ,C'HEADER '),
                  PUSH=(73:ID=4,SEQ=4,81:1,80))
                                               
//SORTIN DD DSN=&&COPY1,DISP=(OLD,PASS)


Doesn't give you much. The HEADER data is copied to the subsequent records, but that is not the data you want. You'll see it on the SYSOUT if you use PF11.

So, start the group for the data that you do want instead (there is nothing that says a GROUP can only be used on a complete group).

Code:
//SWAP02   EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=GROUP,
                  BEGIN=(1,9,CH,EQ,C'OFF:'),
                  PUSH=(73:ID=4,SEQ=4,81:1,80))


Better, there is the OFF: data alongside the POS: data. The OFF: in the old position you don't need, so loose it...

Code:
//SORTIN DD DSN=&&COPY1,DISP=(OLD,PASS)
//SWAP03   EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=GROUP,
                  BEGIN=(1,4,CH,EQ,C'OFF:'),
                  PUSH=(73:ID=4,SEQ=4,81:1,80))
                                               
  OUTFIL OMIT=(1,4,CH,EQ,C'OFF:')
//SORTIN DD DSN=&&COPY1,DISP=(OLD,PASS)



Now, the final part, where you are on your own, is to output two records, in the order you want and the position you want.

Then, after the final bit, to put all of that together into one step (they all go one after another, in the order shown with your bit on the end).

You'll end up with a non-sorting solution that you should fully understand.

If you don't fully understand the solutions for your other questions, go back and break them down, and "play" with them until you do. You'll learn a bundle that way, rather than just taking in what is provided to you.

Sharpen up on your testing as well, please.
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 0
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
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 Join multiple records using splice DFSORT/ICETOOL 5
Search our Forums:

Back to Top