View previous topic :: View next topic
|
Author |
Message |
spradeepece
New User
Joined: 25 Jun 2008 Posts: 19 Location: Chennai
|
|
|
|
Hi,
Is is possible to carry over values from previous record to current record, using Sort? For example, I have a condition where based on a field value, another field in previous record should be copied to the current record.
For instance, if column 5 in the input file reads 'R', data in column 1 to 3 should be carried over to the next line.
Input File (FB/5)
Code: |
AAA
123 R
R
BBB
CCC
DDD
EEE R
R |
Output File (FB/5)
Code: |
AAA
AAA R
AAA R
BBB
CCC
DDD
DDD R
DDD R |
|
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Just a bit of confusion....
for first case ...AAA is carried over and not 123
But in second case...DDD(char associated with R) is carried over |
|
Back to top |
|
|
spradeepece
New User
Joined: 25 Jun 2008 Posts: 19 Location: Chennai
|
|
|
|
Yes.
For 123, the previous record - AAA is carried over. For the third record (spaces) AAA will 'NOW' be the previous record. Hence AAA is carried over.
DDD in input file is not associated with R. Here again, 'EEE' and 'Spaces' were 'Overlayed' with the 'DDD'.
In other words.. Until the next occurence of non-R character (here Space) in Column 5, the data (with a non-R character in Column 5) should be repeated.
Thanks.. |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Sorry.. I think, I confused you.. .
Here is DFSORT sortstep will give you desired result
Code: |
//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
AAA
123 R
R
BBB
CCC
DDD
EEE R
R
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(5,1,CH,EQ,C' '),PUSH=(6:1,3))
OUTFIL BUILD=(6,3,4,2)
|
Output will be
Code: |
AAA
AAA R
AAA R
BBB
CCC
DDD
DDD R
DDD R
|
|
|
Back to top |
|
|
spradeepece
New User
Joined: 25 Jun 2008 Posts: 19 Location: Chennai
|
|
|
|
Thanks a lot Sambhaji,
This was perfect.. |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
spradeepece wrote: |
Thanks a lot Sambhaji,
This was perfect.. |
Am glad it helped.. |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
sambhaji,
Just curious - why did you use both INREC and OUTFIL when you could just use INREC?
Code: |
OPTION COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(5,1,CH,EQ,C' '),PUSH=(6:1,3)),
IFTHEN=(WHEN=INIT,BUILD=(6,3,4,2))
|
|
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Frank Yaeger wrote: |
sambhaji,
Just curious - why did you use both INREC and OUTFIL when you could just use INREC?
|
Hmmm... Actually yeah... |
|
Back to top |
|
|
|