Page 1 of 2

Hexadecimal to decimal conversion - SORT JCL INREC OUTREC

Posted: Fri Jan 15, 2010 6:25 pm
by jathampy
Need a help in converting hexadecimal to decimal using SORT.
e.g 30E0 should be converted to 12512

I tried the following jcl but I am getting the output 4092642800 instead of 12512.

//STEP020 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
30E0
//*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
OUTREC FIELDS=(1,4,BI,ZDF)
//*

Posted: Fri Jan 15, 2010 7:06 pm
by MrSpock
Hm. I get 12512 for my output.

'30E0'X is only two-bytes long, so I used

OUTREC FIELDS=(1,2,BI,ZDF)

Posted: Fri Jan 15, 2010 7:34 pm
by dbzTHEdinosauer
jathampy,

//SORTIN DD *
30E0


would be treated as F3F0C5F0

you have to hex on your JOB JCL (since you have instream data) and as MrSpock said,
enter the 30E0 in two bytes.

Good Catch MrSpock!

Posted: Fri Jan 15, 2010 9:26 pm
by Frank Yaeger
jathampy,

As Dick says, C'30E0' is X'F3F0C5F0', so you can't use BI,TO=ZDF to convert it. You have to do an actual conversion of the binary equivalent of the EBCDIC value.
Here's one way to do what you asked for with DFSORT:

Code: Select all

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
30E0
1234
5678
9ABC
DEF0
//*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=INIT,
    OVERLAY=(81:C'0',1,1,C'0',2,1,C'0',3,1,C'0',4,1)),
   IFTHEN=(WHEN=INIT,FINDREP=(STARTPOS=81,
    INOUT=(C'0A',C'10',C'0B',C'11',C'0C',C'12',
           C'0D',C'13',C'0E',C'14',C'0F',C'15'))),
   IFTHEN=(WHEN=INIT,
     BUILD=((81,2,ZD,MUL,+4096),ADD,
        (83,2,ZD,MUL,+256),ADD,
        (85,2,ZD,MUL,+16),ADD,(87,2,ZD),TO=ZDF,LENGTH=5))
/*
SORTOUT will have:

Code: Select all

12512   
04660   
22136   
39612   
57072   

Posted: Fri Jan 15, 2010 10:32 pm
by jathampy
I tried the JCL provided by Frank and is working as per my expectation.

Thanks Frank for your timely help.

Also my special thanks to Mrspock and Dick

Posted: Tue Oct 26, 2010 2:45 am
by Frank Yaeger
With z/OS DFSORT V1R10 PTF UK90025 or z/OS DFSORT V1R12 PTF UK90026 (Oct,2010), you can use DFSORT's new TRAN=UNHEX function to do this more easily like this:

Code: Select all

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
30E0
1234
5678
9ABC
DEF0
//*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  INREC BUILD=(1,4,TRAN=UNHEX)
  OUTREC BUILD=(1,2,BI,TO=ZD)
/*
For complete details on the new functions for DFSORT and DFSORT's ICETOOL available with the Oct, 2010 PTF, see:

http://www.ibm.com/support/docview.wss? ... g3T7000242

Posted: Tue Oct 26, 2010 1:28 pm
by Anuj Dhawan
Good One Frank...:)

HEX to CHAR Representation

Posted: Sat Mar 31, 2012 8:22 am
by bharath.gct
Hi Frank,

I only have SYNCSORT installed. Can we do this (TRAN=UNHEX) using ICETOOL?

Bharath

Posted: Sun Apr 01, 2012 3:27 am
by DikDude
Frank is a DFSORT developer and does not support Syncsort.

Suggest you refer to the Syncsort documentation for your release of the product.

You might also open an issue with Syncsort support as they will be able to quickly tell you if your release supports this or if there is a workaround.

Posted: Sun Apr 01, 2012 1:36 pm
by Anuj Dhawan
SyncSort does not support UNHEX, at least till 1.3 release of it. However, you can use the sort-solution shown by Frank using IFTHEN with that release of SyncSort.

By the way, what release of SyncSort you are at?

Posted: Mon Apr 02, 2012 5:57 am
by bharath.gct
Hi,

I did open this issue seperately in SyncSort Support Area. http://www.mainframegurukul.com/ibmmain ... ght=#15557

I am using Syncsort V 1.3.02R. I guess mine did not support UNHEX. I tried running a example and it gave me a syntax error.

More details on i/p o/p can be found in the above link.

Thanks
Bharath

Posted: Mon Apr 02, 2012 6:07 am
by bharath.gct
I did try Frank's IFTHEN solution using my SyncSort. Below is what I got:

Code: Select all

SYNCSORT FOR Z/OS  1.3.0.2R

SYSIN :                                                    
  OPTION COPY                                              
  INREC IFTHEN=(WHEN=INIT,                                 
    OVERLAY=(81:C'0',1,1,C'0',2,1,C'0',3,1,C'0',4,1)),     
   IFTHEN=(WHEN=INIT,FINDREP=(STARTPOS=81,                 
                     *                                     
    INOUT=(C'0A',C'10',C'0B',C'11',C'0C',C'12',            
           C'0D',C'13',C'0E',C'14',C'0F',C'15'))),         
   IFTHEN=(WHEN=INIT,                                      
     BUILD=((81,2,ZD,MUL,+4096),ADD,                       
        (83,2,ZD,MUL,+256),ADD,                            
        (85,2,ZD,MUL,+16),ADD,(87,2,ZD),TO=ZDF,LENGTH=5))  
WER268A  INREC STATEMENT   : SYNTAX ERROR

Posted: Mon Apr 02, 2012 9:15 pm
by DikDude
FINDREP is available with Syncsort 1.3.

There may be some examples of INREC / FINDREP in a previous topic. Make sure the topic is for Syncsort. . .

Suggest you look at the examples in the documentation for proper syntax and/or open an issue with Syncsort support.

Posted: Sun Aug 17, 2014 12:45 pm
by sskum
Frank Yaeger wrote:jathampy,

As Dick says, C'30E0' is X'F3F0C5F0', so you can't use BI,TO=ZDF to convert it. You have to do an actual conversion of the binary equivalent of the EBCDIC value.
Here's one way to do what you asked for with DFSORT:

Code: Select all

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
30E0
1234
5678
9ABC

DEF0
//*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=INIT,
    OVERLAY=(81:C'0',1,1,C'0',2,1,C'0',3,1,C'0',4,1)),
   IFTHEN=(WHEN=INIT,FINDREP=(STARTPOS=81,
    INOUT=(C'0A',C'10',C'0B',C'11',C'0C',C'12',
           C'0D',C'13',C'0E',C'14',C'0F',C'15'))),
   IFTHEN=(WHEN=INIT,
     BUILD=((81,2,ZD,MUL,+4096),ADD,
        (83,2,ZD,MUL,+256),ADD,
        (85,2,ZD,MUL,+16),ADD,(87,2,ZD),TO=ZDF,LENGTH=5))
/*
SORTOUT will have:

Code: Select all

12512   
04660   
22136   
39612   
57072   

Hi Frank,

I tried your conversion and it worked very good.

The question is my input file has record till 35th position and in that 1-4 is hexadecimal that I need to convert. when I used the above sort card, 1-4 got converted and sortout has the decimal values in 1-4. but last 31 byte i.e., 05-35 is not appearing in output. the file is having 999 million records so I could nt download into excel and merge. Please let me know what should I use in the above sort card to copy 05-35 bytes as is.

Posted: Sun Aug 17, 2014 2:07 pm
by NicC
If you want to wait for Frank to reply then so be it - you will wait a very long time as he retired some time ago. Lesson to be learnt? Do not address posts to particular people.
Also, you should really have started a new topic as this one is old. You can link to this one or cut and paste the relevant bit.