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
 

 

Handling Priority Using DFSORT

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

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Sun Feb 17, 2013 5:30 pm    Post subject: Handling Priority Using DFSORT
Reply with quote

Hi,
I have 2 files (File 1 and File 2).
I want to prepare File 3, based on the priority from File 1.

File1 - Priority File
Code:
----+----1
03
04
02
01

File2 - Details File
Code:
----+----1
ASDNASL01
ASDNASL02
ASDNASL03
ASDNASL04
KDVNLKN02
KDVNLKN04

In this case
I want to extract the row with the order of highest Priority
File3 - ExtractedDetails File
Code:
----+----1
ASDNASL03
KDVNLKN04

How to achieve this
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Sun Feb 17, 2013 6:03 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

when asking question it would be better to use a <neuter> terminology...
it makes easier for the people answering to interpret correctly Your question
since we take time to understand Your problem and providing a solution
the minimum You should do it is to spare us the time to translate Your organization jargon ....

how many records in file 1 ???
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Sun Feb 17, 2013 6:24 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

Will do so going forward.
Thanks for the advice.

File 1 contains max of 4 records (4 unique values).
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Sun Feb 17, 2013 8:35 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

Is file2 in sequence on the first nine bytes?
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Sun Feb 17, 2013 10:32 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

Yes, 7 (field 1) + 2 (field 2)
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Mon Feb 18, 2013 1:39 am    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

OK, the first step just takes file 1 and turns it into a symbol/SYMNAME for the later INCLUDE.

Produces:
Code:
REQUIRED-PRIORITY,C'01'
REQUIRED-PRIORITY,C'01,04'
REQUIRED-PRIORITY,C'01,04,03'
REQUIRED-PRIORITY,C'01,04,03,02'


Depending on the number of records on file 1 (the order does not matter, although you could "optimise" the order if you know which priority occurs the most to least on file 2).

The generated symbols from SORTOUT (temporary dataset) go into the SYMNAMES DD in the second step. SYMNOUT in that step will list the particular values used.

ICETOOL's SELECT operator is used to chose the LAST record of the key, The CTL1 contains the INCLUDE using the symbol generated, and uses COPY so the data does not get sorted by default.

Code:
//STEP0050 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD DSN=&&SYMNM,DISP=(,PASS),UNIT=SYSDA,SPACE=(TRK,1)
//SYSIN    DD *
  OPTION COPY,STOPAFT=4
                                                                   
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(20:SEQNUM,2,ZD,C'''',C',',80:X)),
        IFTHEN=(WHEN=GROUP,BEGIN=(20,2,CH,EQ,C'01'),
            PUSH=(3:1,2,22,1)),
        IFTHEN=(WHEN=GROUP,BEGIN=(20,2,CH,EQ,C'02'),
            PUSH=(5:23,1,1,2,22,1)),
        IFTHEN=(WHEN=GROUP,BEGIN=(20,2,CH,EQ,C'03'),
            PUSH=(8:23,1,1,2,22,1)),
        IFTHEN=(WHEN=GROUP,BEGIN=(20,2,CH,EQ,C'04'),
            PUSH=(11:23,1,1,2,22,1))
  OUTFIL REMOVECC,NODETAIL,
         TRAILER1=(C'REQUIRED-PRIORITY,C''',3,12)
//SORTIN   DD *
01
04
03
//STEP0100 EXEC PGM=ICETOOL
//IN       DD *
ASDNASL01
ASDNASL02
ASDNASL03
ASDNASL04
KDVNLKN02
KDVNLKN04
XYZAAAA01
XYZAAAA02
//OUT      DD SYSOUT=*
//TOOLMSG  DD   SYSOUT=*
//DFSMSG   DD   SYSOUT=*
//SYMNOUT  DD   SYSOUT=*
//SYMNAMES DD DSN=&&SYMNM,DISP=(OLD,DELETE)
//TOOLIN   DD *
SELECT FROM(IN) TO(OUT) ON(1,7,CH) LAST USING(CTL1)
//CTL1CNTL DD *
  SORT FIELDS=COPY
  INCLUDE COND=(8,2,SS,EQ,REQUIRED-PRIORITY)


The output from the above is

Code:
ASDNASL04
KDVNLKN04
XYZAAAA01


Note that for XYZAAAA 01 and 02 exist, but 02 was not a selected "priority" so 01 is extracted (the 02 got ignored by the INCLUDE).

There are a couple of other ways of finding the "last" record for a key. If you file 2 is large, you might want to try all three to see which is the most effective for your data.
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon Feb 18, 2013 2:42 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

Thanks Bill

But the precedence should be given to
ASDNASL03 over ASDNASL04 as in my first example.
Whereas in your logic, only the last record is being extracted as ASDNASL04
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Mon Feb 18, 2013 3:09 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

Perhaps you didn't explain it so well.

Are you saying, "if 03 exists, give me that, else if 04 exists, give me that, else if 02 exists, give me that, else if 01 exists, give me that"?

File one is not "priorities", but shows the priority that you want the values to be applied in?
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon Feb 18, 2013 3:41 pm    Post subject:
Reply with quote

Exactly, as you mentioned.
The precedence is as follows.

For
ASDNASL01
ASDNASL02
ASDNASL03
ASDNASL04

ASDNASL03 should be extracted

For
ASDNASL01
ASDNASL02
ASDNASL04

ASDNASL04 should be extracted
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Mon Feb 18, 2013 3:55 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

Will there always be four records on file 1? You say both a "max" of four and "four unique values"?
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon Feb 18, 2013 4:29 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

Yes, max 4 and 4 unique values.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Mon Feb 18, 2013 4:45 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

HameedAli,

Please don't just repeat what has already confused me.

A "maximum" implies that there is a "minimum".

Do you have four records on file 1, no more, no less?

You stress uniqueness, is that to be tested for? Otherwise not relevant.
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon Feb 18, 2013 5:18 pm    Post subject:
Reply with quote

Sorry to test your patience.

Quote:
Do you have four records on file 1, no more, no less?
yes
Quote:
You stress uniqueness, is that to be tested for? Otherwise not relevant.
Please ignore this
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue Feb 19, 2013 12:33 am    Post subject:
Reply with quote

Use the following DFSORT JCL which will give you the desired results. I assumed that your extract file 1 has RECFM=FB and LRECL=80

Code:

//STEP0100 EXEC PGM=SORT                 
//SYSOUT   DD SYSOUT=*                   
//INA      DD *                         
----+----1----+----2----+----3----+----4-
ASDNASL01                               
ASDNASL02                               
ASDNASL03                               
ASDNASL04                               
KDVNLKN02                               
KDVNLKN04                               
//INB      DD *                         
03                                       
04                                       
02                                       
01                                       
//SORTOUT  DD SYSOUT=*                   
//SYSIN    DD *                         
  JOINKEYS F1=INA,FIELDS=(8,2,A)         
  JOINKEYS F2=INB,FIELDS=(1,2,A)         
  REFORMAT FIELDS=(F1:1,80,F2:3,1)       
  SORT FIELDS=(1,7,CH,A,81,1,CH,A)       
  OUTFIL REMOVECC,NODETAIL,BUILD=(80X), 
  SECTIONS=(1,7,HEADER3=(1,80))         
//*                                     
//JNF2CNTL DD *                         
  OPTION STOPAFT=4                       
  INREC OVERLAY=(3:SEQNUM,1,ZD)           
//*
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon Mar 04, 2013 11:44 am    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

Skolusu,
Thanks a lot, it is working as expected.

Would you please explain how this works.
I am not able to understand the File2 manipulation.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7241

PostPosted: Mon Mar 04, 2013 1:45 pm    Post subject: Reply to: Handling Priority Using DFSORT
Reply with quote

It is very simple to try

Code:

  JOINKEYS F1=INA,FIELDS=(8,2,A)         
  JOINKEYS F2=INB,FIELDS=(1,2,A)         
  REFORMAT FIELDS=(F1:1,80,F2:3,1,1,2)       


If you run this, you will be able to see what has been "added" to the F2 record. Note that I've added the final '1,2' just so you can see which record gets which addition.
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 get the remainder and quotient... vnktrrd DFSORT/ICETOOL 2 Mon Oct 31, 2016 10:59 am
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts DFSORT sorting only specific records akodakka DFSORT/ICETOOL 4 Thu Aug 04, 2016 11:24 am
No new posts Symbolic Parameters in SYSIN DD state... madishpa DFSORT/ICETOOL 3 Mon Jun 27, 2016 6:23 pm
No new posts DFSORT to match two files and write John F Dutcher DFSORT/ICETOOL 6 Thu May 12, 2016 5:17 pm


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