Page 1 of 2

How to write privious record in current position

PostPosted: Mon Oct 15, 2012 3:52 pm
by Mayank[123]
Hi,

I have 1 input file as

Sno  Subject     roll-Number   Name
1     English     100      ABC
2     Maths     100       ABC
3     Science     100           ABC
4     Computer    100           ABC 
5     English     200      DEF
6     English     300      GHI
7     Maths     300       GHI
8     Science     400           JKL
9     Computer    500           MNO 
10    English     500      MNO


sorted roll-number wise

now i just to print data as

Sno  Subject     roll-Number   Name    Privious Roll-number
1     English     100      ABC   ___(Space)   
2     Maths     100       ABC     100
3     Science     100           ABC     100
4     Computer    100           ABC     100
5     English     200      DEF     100
6     English     300      GHI     200
7     Maths     300       GHI     300
8     Science     400           JKL     300
9     Computer    500           MNO     400
10    English     500      MNO     500


how I can do this using DFSort.

Code'd - de-mangling not attempted

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 4:45 pm
by BillyBoyo
When presenting information, please use the Code tags to preserve spacing, and the Preview button to ensure that you post looks how you want.

Is this an exercise, or a business requirement? Can you show the ICE201I message from any sort step that you have?

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 4:52 pm
by Mayank[123]
Yes it's a business requirement and i can see ICE201I MSG

ICE201I H RECORD TYPE IS F - DATA STARTS IN POSITION 1

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 5:12 pm
by BillyBoyo
OK, you're pretty up-to-date. Have a look at the manual for WHEN=GROUP and PUSH. PUSH is the way to get data from a record which defines the start of a GROUP to the following records that are part of the group. For your case, define your GROUP with RECORDS=2.

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 5:15 pm
by Mayank[123]
Hi,

I have 1 input file as
Sno    Subject     roll-Number        Name
1       English        100            ABC
2       Maths          100            ABC
3       Science        100            ABC
4       Computer       100            ABC 
5       English        200            DEF
6       English        300            GHI
7       Maths          300            GHI
8       Science        400            JKL
9       Computer       500            MNO 
10      English        500            MNO


sorted roll-number wise
now i just wanna print data as

Sno  Subject     roll-Number   Name    Privious Roll-number
1     English         100      ABC     ___(Space)   
2     Maths           100      ABC     100
3     Science         100      ABC     100
4     Computer        100      ABC     100
5     English         200      DEF     100
6     English         300      GHI     200
7     Maths           300      GHI     300
8     Science         400      JKL     300
9     Computer        500      MNO     400
10    English         500      MNO     500

how I can do this using DFSort.

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 5:16 pm
by Mayank[123]
ok i will try...

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 5:41 pm
by BillyBoyo
If you get stuck, show us what you've done, someone will be able to help.

If you get your results, show us what you've done, as it may help someone with a similar requirement.

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 5:47 pm
by Mayank[123]
//SYSOUT   DD  SYSOUT=*
//SORTOUT  DD  SYSOUT=*
//SORTIN   DD  *
1ENGLISH 100ABC
2MATHS   100ABC
3SCIENCE 100ABC
4COMPUTER100ABC
5ENGLISH 200DEF
6ENGLISH 300GHI
7MATHS   300GHI
8SCIENCE 400JKL
9COMPUTER500MNO
//SYSIN    DD  *
    SORT FIELDS=COPY
    OUTREC IFTHEN=(WHEN=GROUP,
              RECORDS=2,
              PUSH=(16:10,3))
//*


and output come like --> (incorrect)

1ENGLISH 100ABC100
2MATHS   100ABC100
3SCIENCE 100ABC100
4COMPUTER100ABC100
5ENGLISH 200DEF200
6ENGLISH 300GHI200
7MATHS   300GHI300
8SCIENCE 400JKL300
9COMPUTER500MNO500


I think, there should be any other condition also...

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 9:24 pm
by BillyBoyo
Yes, you need something else. I was trying to get you to think a bit more.

Sort solutions are not like other program solutions, because the only "storage" you have for "saving" things you need later is on the record, and only PUSH can, within one file, get data from one record to another.

There is another way to look at your problem. If records are "grouped" by Roll Number, you want the previous roll number for the change of group, for "non-change-of-group" records, the roll number is equal to the previous anyway.

If you have a look at the two solutions from our sister site, here:

http://ibmmainframes.com/about58064.html#291631

You'll maybe get some ideas.

It is a non-trivial thing you are after. I want you to understand what you end up with.

Re: How to write privious record in current position

PostPosted: Mon Oct 15, 2012 10:05 pm
by skolusu
Mayank[123] ,

Use the following DFSORT JCL which will give you the desired results
//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTOUT  DD  SYSOUT=*                                               
//SORTIN   DD  *                                                     
1ENGLISH 100ABC                                                       
2MATHS   100ABC                                                       
3SCIENCE 100ABC                                                       
4COMPUTER100ABC                                                       
5ENGLISH 200DEF                                                       
6ENGLISH 300GHI                                                       
7MATHS   300GHI                                                       
8SCIENCE 400JKL                                                       
9COMPUTER500MNO                                                       
//SYSIN    DD  *                                                     
  SORT FIELDS=COPY                                                   
  OUTREC IFOUTLEN=80,                                                 
  IFTHEN=(WHEN=GROUP,RECORDS=2,PUSH=(81:SEQ=1)),                     
  IFTHEN=(WHEN=GROUP,BEGIN=(81,1,ZD,EQ,1),PUSH=(82:10,3),RECORDS=2), 
  IFTHEN=(WHEN=GROUP,BEGIN=(81,1,ZD,EQ,2),PUSH=(85:10,3),RECORDS=2), 
  IFTHEN=(WHEN=(81,1,ZD,EQ,1),OVERLAY=(16:85,3)),                     
  IFTHEN=(WHEN=(81,1,ZD,EQ,2),OVERLAY=(16:82,3))                     
//*


The output from this job is
1ENGLISH 100ABC     
2MATHS   100ABC100 
3SCIENCE 100ABC100 
4COMPUTER100ABC100 
5ENGLISH 200DEF100 
6ENGLISH 300GHI200 
7MATHS   300GHI300 
8SCIENCE 400JKL300 
9COMPUTER500MNO400