## Hexadecimal to decimal conversion - SORT JCL INREC OUTREC

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

jathampy
Member
Posts: 22
Joined: Sat Sep 26, 2009 4:02 pm
Location: software engineer

### Hexadecimal to decimal conversion - SORT JCL INREC OUTREC

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)
//*

MrSpock
Active Member
Posts: 273
Joined: Wed Jun 27, 2007 5:37 pm
Hm. I get 12512 for my output.

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

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

dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm
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!
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:
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=&#40;WHEN=INIT,
OVERLAY=&#40;81&#58;C'0',1,1,C'0',2,1,C'0',3,1,C'0',4,1&#41;&#41;,
IFTHEN=&#40;WHEN=INIT,FINDREP=&#40;STARTPOS=81,
INOUT=&#40;C'0A',C'10',C'0B',C'11',C'0C',C'12',
C'0D',C'13',C'0E',C'14',C'0F',C'15'&#41;&#41;&#41;,
IFTHEN=&#40;WHEN=INIT,
/*
``````
SORTOUT will have:

Code: Select all

``````12512
04660
22136
39612
57072
``````
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

jathampy
Member
Posts: 22
Joined: Sat Sep 26, 2009 4:02 pm
Location: software engineer
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

Frank Yaeger
Moderator
Posts: 812
Joined: Sat Feb 18, 2006 5:45 am
Location: San Jose, CA
Contact:
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=&#40;1,4,TRAN=UNHEX&#41;
OUTREC BUILD=&#40;1,2,BI,TO=ZD&#41;
/*
``````
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
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India
Good One Frank...
Regards,
Anuj

bharath.gct
Member
Posts: 7
Joined: Sat Mar 31, 2012 8:16 am

### HEX to CHAR Representation

Hi Frank,

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

Bharath

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa
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.
Have a good one

Anuj Dhawan
Moderator
Posts: 1625
Joined: Sat Aug 09, 2008 9:02 am
Location: Mumbai, India
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?
Regards,
Anuj

bharath.gct
Member
Posts: 7
Joined: Sat Mar 31, 2012 8:16 am
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

bharath.gct
Member
Posts: 7
Joined: Sat Mar 31, 2012 8:16 am
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 &#58;
OPTION COPY
INREC IFTHEN=&#40;WHEN=INIT,
OVERLAY=&#40;81&#58;C'0',1,1,C'0',2,1,C'0',3,1,C'0',4,1&#41;&#41;,
IFTHEN=&#40;WHEN=INIT,FINDREP=&#40;STARTPOS=81,
*
INOUT=&#40;C'0A',C'10',C'0B',C'11',C'0C',C'12',
C'0D',C'13',C'0E',C'14',C'0F',C'15'&#41;&#41;&#41;,
IFTHEN=&#40;WHEN=INIT,
WER268A  INREC STATEMENT   &#58; SYNTAX ERROR``````
Thanks
Bharath

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa
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.
Have a good one

sskum
Member
Posts: 1
Joined: Sun Aug 17, 2014 12:38 pm
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=&#40;WHEN=INIT,
OVERLAY=&#40;81&#58;C'0',1,1,C'0',2,1,C'0',3,1,C'0',4,1&#41;&#41;,
IFTHEN=&#40;WHEN=INIT,FINDREP=&#40;STARTPOS=81,
INOUT=&#40;C'0A',C'10',C'0B',C'11',C'0C',C'12',
C'0D',C'13',C'0E',C'14',C'0F',C'15'&#41;&#41;&#41;,
IFTHEN=&#40;WHEN=INIT,
/*
``````
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.

NicC
Active Member
Posts: 650
Joined: Sun Jul 24, 2011 5:27 pm
Location: Down on the pig farm
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.
Regards
Nic

# FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
• JCL Tutorial
Covers all important JCL concepts.
• Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3.
• DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming.
• SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples
• CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions

Other References
Mainframe Tools and others