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

How to sort using COMP-3 variable


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

New User


Joined: 31 Mar 2008
Posts: 8
Location: india

PostPosted: Tue Feb 10, 2009 1:22 pm
Reply with quote

Hi,

I have a 12 byte COMP-3 field from byte 230-235 as shown below. i need to sort the records based on the 5-7 bytes of the field, ie with the value 302, in the given record. The input file is of 403 byte length.

[img]C:\Documents and Settings\169685\Desktop\record[/img]

Thanks in advance.[/img]
Back to top
View user's profile Send private message
vinodkumarrs

New User


Joined: 31 Mar 2008
Posts: 8
Location: india

PostPosted: Tue Feb 10, 2009 1:36 pm
Reply with quote

vinodkumarrs wrote:
Hi,

I have a 12 byte COMP-3 field from byte 230-235 as shown below. i need to sort the records based on the 5-7 bytes of the field, ie with the value 302, in the given record. The input file is of 403 byte length.

[img]C:\Documents and Settings\169685\Desktop\record[/img]

Thanks in advance.[/img]
Back to top
View user's profile Send private message
Girish Firke

New User


Joined: 04 Feb 2009
Posts: 5
Location: Mumbai

PostPosted: Tue Feb 10, 2009 3:36 pm
Reply with quote

Hi Vinod,

Sort control card syntax for packed decimal values will be
SORT FIELDS=(Starting Position, Length, PD,A)

By looking at your question I am getting that you want to sort the 3 bytes from 5 character of a comp-3 field. If that is the case then please try below control card and let me know whether it works fine or not.


In your case

SORT FIELDS=(232,02,PD,A)
Back to top
View user's profile Send private message
vinodkumarrs

New User


Joined: 31 Mar 2008
Posts: 8
Location: india

PostPosted: Tue Feb 10, 2009 3:41 pm
Reply with quote

Hi Girish,

The SORT FIELDS=(232,02,PD,A), will take 4 bytes to check. In my case it will take the value '3021' for sorting, I need only upto '302'.

Thanks,
Vinod
Back to top
View user's profile Send private message
Girish Firke

New User


Joined: 04 Feb 2009
Posts: 5
Location: Mumbai

PostPosted: Tue Feb 10, 2009 4:16 pm
Reply with quote

Hi,

Your screenshot shows the hexa-decimal value of the record.

The hex-decimal value X'30' represent one ascii character and X'21' represents another ascii character.

I am not sure whether we can sort those as per your requirement.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Tue Feb 10, 2009 4:23 pm
Reply with quote

Also, since you are not checking the entire packed field, specifying PD for the sort is invalid.

You could try INREC processing to expand the COMP-3 field into an appended work field and sort based on the expanded 3 characters in that field. Then use OUTREC processing to drop the work field.

Garry.
Back to top
View user's profile Send private message
vinodkumarrs

New User


Joined: 31 Mar 2008
Posts: 8
Location: india

PostPosted: Tue Feb 10, 2009 6:13 pm
Reply with quote

I tried the above mentioned logic and it worked. thanks
Code:
//STEP01   EXEC  PGM=SORT                                         
//SYSOUT   DD  SYSOUT=*                                           
//SORTIN   DD DSN=------
//*                                                               
//SORTOUT  DD DSN=------               
//SYSIN    DD    *                                               
  OPTION EQUALS                                                   
  INREC OVERLAY=(404:230,6,PD,TO=ZD,LENGTH=11)                   
  SORT FIELDS=(408,3,ZD,A)                                       
  OUTREC BUILD=(1,403)                                           
/*                                                               
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Tue Feb 10, 2009 6:20 pm
Reply with quote

Thanks for letting us know, Vinod.

Glad to have been able to help.

Garry.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Feb 10, 2009 10:09 pm
Reply with quote

Here's a much easier way to do this using DFSORT's bit notation for the length:

Code:

//S2  EXEC  PGM=SORT
//SYSOUT   DD  SYSOUT=*
//SORTIN   DD DSN=...  input file
//SORTOUT  DD DSN=...  output file
//SYSIN    DD    *
  OPTION EQUALS
  SORT FIELDS=(232,1.4,BI,A)
/*


For example, if the value at 232-233 is X'3021', this tells DFSORT to sort on 1 byte and 4 bits, e.g. on 302.
Back to top
View user's profile Send private message
vinodkumarrs

New User


Joined: 31 Mar 2008
Posts: 8
Location: india

PostPosted: Wed Feb 11, 2009 10:56 am
Reply with quote

This also works fine.
Since I need 3 bytes to compare I modified as below.
Code:
//STEP01   EXEC  PGM=SORT                                         
//SYSOUT   DD  SYSOUT=*                                           
//SORTIN   DD DSN=------
//*                                                               
//SORTOUT  DD DSN=------               
//SYSIN    DD    *                                               
  OPTION EQUALS                                                   
  SORT FIELDS=(232,1.3,BI,A)                                 
/*


Thank you very much for the help.

Regards,
Vinod
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Feb 11, 2009 9:47 pm
Reply with quote

Huh? You are dealing with 2 bytes (232-233), not 3 bytes.

1.4 for the length means 1 byte and 4 bits. 1.3 for the length means 1 byte and 3 bits. 1.4 for the length would give the correct results for all cases whereas 1.3 for the length wouldn't.

As an example, if 232-233 had records with these hex values:

3010
3000
3030
3020

Using 232,1.4 you would correctly get these output records:

3000
3010
3020
3030

Using 232,1.3, you would incorrectly get these output records:

3010
3000
3030
3020

As you can see, that fourth bit does matter.
Back to top
View user's profile Send private message
vinodkumarrs

New User


Joined: 31 Mar 2008
Posts: 8
Location: india

PostPosted: Thu Feb 12, 2009 9:51 am
Reply with quote

Hi,

I got the same results when I tried with 232,1.3 as well as 232,1.4 bytes.
Anyway I got the point that Frank mentioned above. Hence I will follow with the 232,1.4 option. Thanks for the clear explanation.

Regards,
Vinod
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Feb 12, 2009 10:10 am
Reply with quote

Hello,

Quote:
I got the same results when I tried with 232,1.3 as well as 232,1.4 bytes.
That was due to fortune rather than proper code. . .

At some point the output would have not been the same and that could be an ugly surprise icon_confused.gif

Using the nnn,1.4 will ensure the proper bits are used for sorting.

Thanks for the update icon_smile.gif
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 Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
Search our Forums:

Back to Top