Joined: 21 Dec 2007 Posts: 18 Topics: 7 Location: UK
Posted: Wed Jul 27, 2022 12:16 pm Post subject: Convert decimal number into Comp-3
I am having an input file with 10 amount fields that contain decimal numbers but decimal point is not always guaranteed. I need to convert each of these amount fields into COMP-3 of length 5. The maximum number of digits before decimal point is 5 and 4 digits after decimal point.
I tried using
1,10,SFF,PD,LENGTH=5 in INREC statement
and then checked the output file using the Cobol copybook field PIC S9(5)V9(4) COMP-3. The values are coming correctly only for the records that contain 4 digits after decimal point .(e.g 1311.1234). The first record is coming incorrectly as 0.1111 instead of 11.11
I think if I maintain 4 decimals for every record then it should work. But challenge is to convert the amount field into 5 digits before decimal point and 4 digits after decimal point.
Joined: 21 Dec 2007 Posts: 18 Topics: 7 Location: UK
Posted: Thu Jul 28, 2022 7:21 am Post subject:
Thanks Kolusu. The one mentioned in the link previously work only for two fixed decimal digits.As per the new requirement the number of digits after decimal places can vary between 0 and 4. It worked with the below sort card. I just set a decimal point at the last position of the number field, if the number doesn't contain any decimal point. After that use PARSE to split the numbers before and after decimal point and then add leading zeros to the integer part and trailing zeros to the fractional part
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Thu Jul 28, 2022 3:13 pm Post subject:
jathampy wrote:
Thanks Kolusu. The one mentioned in the link previously work only for two fixed decimal digits.As per the new requirement the number of digits after decimal places can vary between 0 and 4.
Jathampy,
I mentioned that you need to improvise on the solution to handle 4 decimals
jathampy wrote:
It worked with the below sort card. I just set a decimal point at the last position of the number field, if the number doesn't contain any decimal point.
why bother about adding a decimal point? UFF will any ignore it.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum