Convert ZD field to Negative Binary



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Convert ZD field to Negative Binary

Postby ianc » Sat Jan 25, 2025 2:56 am

I have a dataset with a small number of records with a 'sign' character, follow by a 10 character ZD number. If the 'sign' is - then I need to convert it to the binary negative equivalent, if it's + then I need to convert it to the binary equivalent. For example, I created a simple test with the following

//SORTIN DD *
+0000000011
-0000000011
/*


Using this data I need to just convert the number in the first record to binary and the number in the second record to the negatie binary value (ie The first character is driving the positive/negative conversion)

I'm using the following SORT statements

SORT FIELDS=COPY
OUTREC IFTHEN=(WHEN=INIT,BUILD(1,1,2,10,ZD,TO=BI)),
  IFTHEN=(WHEN=(1,1,CH,EQ,C'-'),OVERLAY(2:2,4,ZD,TO=FS,LENGTH=4)


The job runs to CC=0.

However, when I look at the generated records, the first positive number is correct, however the second number has had the leading zeros replaced with spaces x'40'.

Record 1 - 4E000000 0B000000
Record 2 - 60404040 FB000000

Red indicates the spaces where I expected zeros.

I looked in the DFSORT OPTIONS to see if there was something to control this but couldn't see anything.

Any thoughts appreciated!
ianc
 
Posts: 2
Joined: Wed Jan 31, 2018 8:56 am
Has thanked: 0 time
Been thanked: 0 time

Re: Convert ZD field to Negative Binary

Postby sergeyken » Sun Jan 26, 2025 2:50 am

After conversion to BI your field (2,4) is neither ZD format, nor can be converted to FS. It just makes no sense.

In order to change the sign of your binary field, you must multiply its content by -1, in binary format, but not ZD or FS.
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 453
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 8 times
Been thanked: 40 times

Re: Convert ZD field to Negative Binary

Postby sergeyken » Sun Jan 26, 2025 3:07 am

FYI:

In binary format, the value -11 is stored in memory as X’FFFFFFF5’
While the value +11 is X’0000000B’
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 453
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 8 times
Been thanked: 40 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post