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

Record should be sorted as a group


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Thu Aug 06, 2015 2:38 pm
Reply with quote

Hi,

I couldn't find sorting similar to this.

I have input file as below

Code:
S:GQI0010_UO_CCD DB2D DB2M QRCAP0 QRAPP0
T:C NB.TPOLICY_DOCUMENTS NB.TPOLICY_DOCUMENTS_CCD
C:  DOC_ID DOC_ID
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               
S:AQI0005_UO_CCD DB2D DB2D QRCAP0 QRAPP0
T:C NT.TPOLICY_DOCUMENTS NT.TPOLICY_DOCUMENTS_CCD
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               
C:  LAST_UPDATED LAST_UPDATED
C:  STATUS STATUS
S:CQI0001_UO_CCD DB2D DB2D QRCAP0 QRAPP0
T:C NO.TPOLICY_DOCUMENTS NO.TPOLICY_DOCUMENTS_CCD
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               
S:BQI0002_UO_CCD DB2M DB2M QRCAP0 QRAPP1
T:A NQ.CUSTOMER_ACCOUNT NQ.CUSTOMER_ACCOUNT_CCD0
C:  CUSTOMER_NAME_KEY CUSTOMER_NAME_KEY                                 
C:  CUSTOMER_TYPE     CUSTOMER_TYPE                                     
C:  POLICY_ID         POLICY_ID                                           
C:  CUST_ADDR_STATUS  CUST_ADDR_STATUS                                 
S:GQI0011_UO_CCD DB2M DB2P QRCAP0 QRAPP0
T:C NB.TPOLICY_DOCUMENTS NB.TPOLICY_DOCUMENTS_CCD
C:  DOC_ID DOC_ID
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               


Where each set of records are of multiple lines, like below is record one,
Code:
S:GQI0010_UO_CCD DB2D DB2M QRCAP0 QRAPP0
T:C NB.TPOLICY_DOCUMENTS NB.TPOLICY_DOCUMENTS_CCD
C:  DOC_ID DOC_ID
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               

Each record will have Single occurance of S:, T:(char in position 1 & 2) and multiple occurances( >=1 ) of C:

I need to sort this file based on, first 3 characters of string 1(eg:- S:G) and string 2(DB2D)
Code:
S:GQI0010_UO_CCD DB2D DB2M QRCAP0 QRAPP0


Output should be like,
Code:
S:AQI0005_UO_CCD DB2D DB2D QRCAP0 QRAPP0
T:C NT.TPOLICY_DOCUMENTS NT.TPOLICY_DOCUMENTS_CCD
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               
C:  LAST_UPDATED LAST_UPDATED
C:  STATUS STATUS
S:BQI0002_UO_CCD DB2M DB2M QRCAP0 QRAPP1
T:A NQ.CUSTOMER_ACCOUNT NQ.CUSTOMER_ACCOUNT_CCD0
C:  CUSTOMER_NAME_KEY CUSTOMER_NAME_KEY                                 
C:  CUSTOMER_TYPE     CUSTOMER_TYPE                                     
C:  POLICY_ID         POLICY_ID                                           
C:  CUST_ADDR_STATUS  CUST_ADDR_STATUS                                 
S:CQI0001_UO_CCD DB2D DB2D QRCAP0 QRAPP0
T:C NO.TPOLICY_DOCUMENTS NO.TPOLICY_DOCUMENTS_CCD
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               
S:GQI0010_UO_CCD DB2D DB2M QRCAP0 QRAPP0
T:C NB.TPOLICY_DOCUMENTS NB.TPOLICY_DOCUMENTS_CCD
C:  DOC_ID DOC_ID
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               
S:GQI0011_UO_CCD DB2M DB2P QRCAP0 QRAPP0
T:C NB.TPOLICY_DOCUMENTS NB.TPOLICY_DOCUMENTS_CCD
C:  DOC_ID DOC_ID
C:  POLICY_DOCUMENT POLICY_DOCUMENT                               

When the sort happens related sub-records should also move.

Thanks,
Sushanth
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: Thu Aug 06, 2015 3:17 pm
Reply with quote

INREC operates before SORT. So any manipulation required to allow a specific SORT is done in INREC.

You will need to use WHEN=GROUP with BEGIN= for your C'S:' in 1,2. Then PUSH the information required for sequencing so that it appears, in the same place, on each record of the group.

Then you SORT on that new key, with OPTION EQUALS (or EQUALS on the SORT) to preserve the original order of records.

Then, with OUTREC or OUTFIL you use BUILD to return the records to their original size and content.

That's the general outline.

You have an issue, because it looks like the second part of your key may be variably-located.

This means you have to use IFTHEN=(WHEN=INIT in INREC to first prepare the key, with PARSE to get the second element of the key.

The first element of the key is fixed-position and fixed-length, so you use OVERLAY on another INIT to extend the record to include the fixed-position value and the variable-position value (you're going to have to decide on a maximum length, the logical maximum of that content).

Then with the GROUP mentioned earlier, you PUSH the two elements to themselves, thus marking each record in the group with the same key.

Where to extend depends on whether fixed-length or variable-length records. Fixed-length, at the end of the record, variable-length at the beginning (like BUILD=(1,4,15X,5) to temporarily extend, BUILD=(1,4,20) to return to original size).
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Thu Aug 06, 2015 7:49 pm
Reply with quote

Assuming 80 FB, see if below works...

Code:
//SYSIN DD *                                           
   INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'S:'),   
                 PUSH=(81:1,3,18,4))                   
   SORT FIELDS=(81,7,CH,A)                             
   OUTFIL BUILD=(1,80)                                 
/*                                                     


Thanks,
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: Thu Aug 06, 2015 8:35 pm
Reply with quote

With the EQUALS needed somewhere.

Otherwise fine as long as the second field always starts there. Simple enough for the variable-length version as well.

Long time no see. Nice to see you back.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Thu Aug 06, 2015 9:21 pm
Reply with quote

DFSort default ships with OPTIONS EQUALS and same is the case here at my site but otherwise I would agree, its needed.

Just coming back icon_smile.gif Thanks
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: Thu Aug 06, 2015 9:44 pm
Reply with quote

So the document says, EQUALS is the delivered defualt. I never realised that, having never seen a site with EQUALS=Y as the default :-)

There's a performance penalty, additional storage requirements and a minor reduction in the total size of keys.

Of course, if you have EQUALS=Y as the default don't just change it. It can/will change the order of output (for non-unique keys only). Use OPTION NOEQUALS or NOEQUALS on the SORT/MERGE statement instead.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Thu Aug 06, 2015 10:36 pm
Reply with quote

Thank You Very Much Bill for taking your time and elaborating step-by-step on what commands i should code in order, i am pretty much a beginner in SORT tools. When i finished the below part,
Code:
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'S:'),
      PUSH=(100:ID=6))                           

And started with the sort, the sequence of S:, T:, C: was getting interchanged within the ID. And i was wondering, should i add another sequence column and sort that, so that it will come in order. Still i was pretty much not going anywhere with that idea in the head as i didn't have a clue how to sort the entire block of records. Its a bit easy when a record is in single line, since my records were in multiple line. I was thinking, whether to combine multiple line record to single line --> sort it --> split to multiple lines back. But that would be very inefficent(possibility of data hitting record limit per line).

Just about then when i saw the result from sqlcode1, icon_biggrin.gif . (Then i knew, i was thinkin too much ).

Thank You Very Much sqlcode1


Regards,
Sushanth
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 Aug 10, 2015 9:17 pm
Reply with quote

I've been doing some poking about.

Firstly, I misread the Customisation and Installation Guide. Penalty for looking positively, rather than negatively.

Secondly, here is what happens.

The IBM-supplied default value for the EQUALS installation option is VBLKSET.

This means that operations which use the BLOCKSET technique (recommended to use where possible) would use EQUALS=Y for variable-length records.

Operations which enforce the use of EQUALS (JOINKEYS, ICETOOL operators) do so irrespective of installation default.

Assuming that the options are listed per run, look at the SYSOUT for SORT steps. If it says EQUALS=Y, confirm that this is required, and consider the use of NOEQUALS for the step if EQUALS is not required.

What does EQUALS do?

It makes a new low-order key-field for SORT/MERGE, a sequence number. This requires more storage for the key. The sequence number is four bytes long. So an existing four-byte key will be doubled in size. CPU time is increased also, to process the new part of the key.

When is EQUALS useful?

When you can have duplicate keys. No other time. If keys are unique, then using EQUALS is wasteful. If keys are not unique, but the order of the output (including SUMming) is not relevant, then EQUALS is wastefull. If keys are not unique, and the order of the input needs to be preserved through to the output, then use EQUALS.

In technical terms, EQUALS produces a "stable sort" when there are duplicate keys. With unique keys, a sort is always stable.

Why do JOINKEYS and various ICETOOL operators force the use of EQUALS?

To ensure they work as described.
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts FINDREP - Only first record from give... DFSORT/ICETOOL 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
Search our Forums:

Back to Top