Convert decimal number into Comp-3
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Utilities

#1: Convert decimal number into Comp-3 Author: jathampyLocation: UK PostPosted: Wed Jul 27, 2022 12:16 pm
    —
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.

It would be great if I can get help on this.

Sample input file
Quote:
11.11
121
1311.1234
14141.1
18911.6456

#2:  Author: kolusuLocation: San Jose PostPosted: Thu Jul 28, 2022 12:03 am
    —
jathampy,

You have been a member of site for nearly 15 years and yet you don't follow the simple rule of "search before posting"

If you did a search for Decimal in the Utilities forum, you would have found the answer in a topic that you started

https://www.mvsforums.com/helpboards/viewtopic.php?t=12976&highlight=decimal

Hope you can improvise the solution to handle trailing zeros for decimals.

#3:  Author: jathampyLocation: UK PostPosted: Thu Jul 28, 2022 7:21 am
    —
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

Code:
OPTION COPY
INREC IFTHEN=(WHEN=(1,10,SS,NE,C'.'),OVERLAY=(10:C'.'))           
OUTREC IFTHEN=(WHEN=INIT,PARSE=(%1=(ABSPOS=1,ENDBEFR=C'.',FIXLEN=5),
              %2=(ENDBEFR=C'|',FIXLEN=4)),                         
       BUILD=(%1,UFF,M11,LENGTH=5,C'.',%2,ZD,M11,LENGTH=4)),       
       IFTHEN=(WHEN=INIT,BUILD=(1,10,SFF,TO=PD,LENGTH=5))

#4:  Author: kolusuLocation: San Jose PostPosted: Thu Jul 28, 2022 3:13 pm
    —
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.

Code:

//SYSIN    DD *                               
  OPTION COPY                                 
  ALTSEQ CODE=(40F0)                         
  INREC IFTHEN=(WHEN=INIT,                   
         BUILD=(01,10)),                     
        IFTHEN=(WHEN=INIT,                   
         PARSE=(%01=(ENDBEFR=C'.',FIXLEN=5), 
                %02=(FIXLEN=4)),             
         BUILD=(%01,UFF,M11,LENGTH=5,         
                %02,TRAN=ALTSEQ)),           
        IFTHEN=(WHEN=INIT,                   
         BUILD=(01,09,UFF,PD,LENGTH=5))       
/*



MVSFORUMS.com -> Utilities


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group