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 

Reading and writing the decimal in a file.

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


Joined: 02 Aug 2005
Posts: 75
Topics: 27

PostPosted: Tue Aug 24, 2010 3:59 am    Post subject: Reading and writing the decimal in a file. Reply with quote

Hi,
I have a requirement to read one input file and format it little bit before writing it to a new file..Here is more details about the input file..

Input file layout
==========
Code:

-------120 bytes -------| -----15 bytes ----- |
xxxxxxxxxxxxxxxxxxx                    10.89
xxxxxxxxxxxxxxxxxxx                   110.67
xxxxxxxxxxxxxxxxxxx                   78.394
xxxxxxxxxxxxxxxxxxx               7288.86345


The last 15 byte field is a right aligned field and you can also notice the digits after decimal point is also not same.

The requirement is to write this file to the output file by only converting the last 15 byte field to COMP-3 field of S9(8)V9(5) COMP-3


Is it possible by using SORT utility ?

I was trying to do it by using COBOL inspect, but got a syntax error..
Code:
 
INSPECT INPUT-PRICE TALLYING WS-TALLY-COUNT FOR "."
REPLACING ALL SPACES BY ZEROES                       
.
.
.
other codes goes here ...


could anyone please let me know how can I get the required output ?

Thank you..
batu544
_________________
Regards,
batu
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Aug 24, 2010 7:25 am    Post subject: Reply with quote

why did you not use the intrinsic function NUMVAL?
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Aug 24, 2010 10:41 am    Post subject: Reply with quote

batu544,


There are ways to do it in cobol but it depends on how you want interpret the data.

Remember that comp-3 fields doesn't have an exclusive decimal point. So using numval function you can convert 10.89 to PD format it will be like this

Code:

0001009
000008C


Now if you read that into a field defined as S9(8)V9(5) COMP-3 you will read it as 00000000.01089 which is wrong. You need to adjust the number of decimals before you convert it into PD.

You can parse and then convert it into PD format using Sort utility using the following control cards.

Code:

//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                             
  INREC IFTHEN=(WHEN=(121,15,SS,NE,C'.'),                       
  OVERLAY=(121:121,15,SFF,ZD,LENGTH=15)),                       
  IFTHEN=(WHEN=(121,15,SS,EQ,C'.'),                             
  PARSE=(%00=(ABSPOS=121,ENDBEFR=C'.',FIXLEN=15),               
         %01=(FIXLEN=5)),                                       
  BUILD=(1,120,%00,SFF,ZD,LENGTH=10,                           
         %01,UFF,M11,LENGTH=5),HIT=NEXT),                       
  IFTHEN=(WHEN=(121,10,ZD,LT,0),                               
  OVERLAY=(121:121,10,ZD,M11,LENGTH=10,                         
           131:+0,SUB,131,5,ZD,ZD,LENGTH=5))                   
                                                               
  OUTREC IFTHEN=(WHEN=INIT,BUILD=(1,120,121,15,ZD,PD,LENGTH=7))
//*


This will create a 127 byte output file. However there is a chance that you might truncate the values . for example if you have a 15 digit value without any decimal , then you would truncate the left most digits.

Code:

123456789012345


would be truncated to
Code:
3456789012345

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
batu544
Beginner


Joined: 02 Aug 2005
Posts: 75
Topics: 27

PostPosted: Fri Oct 08, 2010 7:26 am    Post subject: Reply with quote

well.. sorry guys.. its really a late reply.. but just want to say thanks.. I used function NUMVAL to resolve this issue.. and everything working fine...


Thanks you ..
_________________
Regards,
batu
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming 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