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 

Left justified alphanumeric to right justified numeric

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


Joined: 18 Jun 2015
Posts: 3
Topics: 2

PostPosted: Fri Dec 18, 2015 5:56 am    Post subject: Left justified alphanumeric to right justified numeric Reply with quote

I need to convert Numbers stored as Text datatype(left aligned) ranging from 2 to 4 digits to Numeric format(Right aligned) padded with zeros in COBOL.

For eg,
Code:

Field1(Text left aligned)         Field2(Numeric Right aligned)
------------------------------    -------------------------------
1000                              001000           
11                                000011     
-200                              -00200


I tried with below options but my Cobol compiler is not supporting all.

NUMVAL
JUSTIFIED RIGHT
INSPECT with TRAILING SPACES

I appreciate any help on this.
Back to top
View user's profile Send private message
William Collins
Supermod


Joined: 03 Jun 2012
Posts: 437
Topics: 0

PostPosted: Fri Dec 18, 2015 6:28 am    Post subject: Reply with quote

Well, I know of no Mainframe compiler which doesn't support JUST RIGHT.

INSPECT with TRAILING is non-Standard, and not an IBM Extension, so that won't work. I assume INSPECT itself does?

If you don't have FUNCTION NUMVAL you must have a very old COBOL compiler, like OS/VS COBOL. Or did you just miss out the word FUNCTION, or try to use it incorrectly?

You state 2-4 digits, but since you show a sign, do you mean maximum source size is five characters? And in what format do you want the output, actual leading zeros and a leading sign?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Dec 18, 2015 11:14 am    Post subject: Reply with quote

SathishKrishna,

I am not sure as to why you are complicating a simple requirement. You are inconsistent with your zero padding for positive and negative numbers. Your final output size is 6 bytes of edited numeric data. For positive numbers you want a zero instead of the + sign and for the negative numbers you want the negative sign.

So use this

Code:

WORKING-STORAGE SECTION.                                 
01  INP-VAL    PIC X(4).                                 
01  OUT-VAL    PIC -99999.                               
PROCEDURE DIVISION.                                     
                                                         
     MOVE '1000' TO INP-VAL                             
     IF INP-VAL > ' '                                   
        COMPUTE OUT-VAL = FUNCTION NUMVAL(INP-VAL)       
     ELSE                                               
        MOVE +0   TO  OUT-VAL                           
     END-IF                                             
     DISPLAY 'NUMERIC VALUE OF INP-VAL BEFORE : ' OUT-VAL


This will produce
Code:

 01000
 00011
-00200


The first byte is a space for the positive numbers. If you insist on having a zero for that then use this
Code:

INSPECT OUT-VAL REPLACING LEADING ' ' BY '0'         
DISPLAY 'NUMERIC VALUE OF INP-VAL AFTER  : ' OUT-VAL 


And this will give you the desired results

Code:

001000
000011
-00200

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

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 -> 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