Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
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
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!
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
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).
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
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.
Joined: 07 Jun 2010 Posts: 59 Location: coimbatore
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..!!!
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
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.
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).
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.