MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Convert decimal number into Comp-3

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
jathampy
Beginner


Joined: 21 Dec 2007
Posts: 18
Topics: 7
Location: UK

PostPosted: Wed Jul 27, 2022 12:16 pm    Post subject: Convert decimal number into Comp-3 Reply with quote

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
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Jul 28, 2022 12:03 am    Post subject: Reply with quote

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.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jathampy
Beginner


Joined: 21 Dec 2007
Posts: 18
Topics: 7
Location: UK

PostPosted: Thu Jul 28, 2022 7:21 am    Post subject: Reply with quote

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))
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Jul 28, 2022 3:13 pm    Post subject: Reply with quote

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

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group