Page 1 of 1
Convert two PD fields to Numeric using Sort
Posted:
Wed Nov 04, 2015 4:09 am
by Kitz
Hi there,
I have two packed decimal fields in a file of record length 80
Field1 1-4 (S9(7) COMP-3)
Field2 5-9 (S9(9) COMP-3)
I tried to do with the below, but the results are not as expected.
INREC BUILD=(1,9,PD,TO=ZD,LENGTH=16
Could you please advise how do I convert the data to numeric using SORT?
Re: Convert two PD fields to Numeric using Sort
Posted:
Wed Nov 04, 2015 4:38 am
by Robert Sample
Treat them as separate fields. Your INREC is attempting to use the first field's sign bits as data, which will give erroneous results at best.
Re: Convert two PD fields to Numeric using Sort
Posted:
Wed Nov 04, 2015 5:26 am
by BillyBoyo
As Robert says, something like this;
INREC BUILD=(1,4,PD,TO=ZD,LENGTH=7,5,5,TO=ZD,LENGTH=9)
Re: Convert two PD fields to Numeric using Sort
Posted:
Thu Nov 05, 2015 3:35 am
by Kitz
Thanks a lot Billy Boya. I am able to convert the file to numeric now.
For some reasons, these fields are coming with a prefix '0' to each field.
1.Could you please advise how to I get rid of '0' to these fields?
2. Also, pls let me know how to I get a space in between these two fields in the output file.
Current file:
0111111011111111
0222222022222222
0121212014345678
Expected output:
111111 11111111
222222 22222222
121212 14345678
Re: Convert two PD fields to Numeric using Sort
Posted:
Thu Nov 05, 2015 4:51 am
by BillyBoyo
Change both the LENGTH=s. Use X between the fields to insert one blank (2X to insert two blanks).
Re: Convert two PD fields to Numeric using Sort
Posted:
Thu Nov 05, 2015 8:02 pm
by Terry Heinze
Kitz,
In the future, please use code tags to indicate spacing:
Current file:
0111111011111111
0222222022222222
0121212014345678
Expected output:
111111 11111111
222222 22222222
121212 14345678