Page 1 of 1

alphanumeric to numeric value padding with ZEROS in COBOL

Posted: Fri Mar 27, 2009 1:22 pm
by rohan
Hello friends,

I need to have a PIC clause value padded with '0'.

The problem is like, I have a PIC 9(7) clause and want to get a user input value stored into that. If supplied value is less than 7 char, then the value should be padded with '0' to occupy all 7 digits.

Example-

User Supplied Value :- 1234
Padded Value:- 0001234

Please help out on this issue. I need a solution urgently.

Thanks in advance.

Posted: Fri Mar 27, 2009 1:39 pm
by dbzTHEdinosauer
*sigh*

1. if you want to store negative signs, you need a pic S9(7).

2. what is your source? x-type? if x-type, use NUMVAL.

3. any reason you need to use display instead of a real numeric like PACKED-DECIMAL?

Posted: Fri Mar 27, 2009 2:02 pm
by rohan
dbzTHEdinosauer wrote:*sigh*

1. if you want to store negative signs, you need a pic S9(7).

2. what is your source? x-type? if x-type, use NUMVAL.

3. any reason you need to use display instead of a real numeric like PACKED-DECIMAL?
Thanks for the reply.

What I need that is just for a "Customer Number" field. So I don't need to perform any calculation or sign.

and it just needs to be padded.

Posted: Fri Mar 27, 2009 4:06 pm
by Natarajan
Let us know , if you are still facing the issue.

Posted: Fri Mar 27, 2009 4:23 pm
by rohan
Yes, I'm still facing this issue. Kindly let me know.
Thanks.

Posted: Fri Mar 27, 2009 4:31 pm
by dbzTHEdinosauer
what code are you using that does not work?

data layout, code.....

Posted: Fri Mar 27, 2009 5:02 pm
by rohan
dbzTHEdinosauer wrote:what code are you using that does not work?

data layout, code.....
i am in the initial stage of development.
All I have done is declared a variable

WS-CUST-NUM PIC 9(7).

The program ACCEPT the input value given on the CICS designed screen and stores it in this variable.
This input has to be then padded with 0's

if input is 1234, I want it to be changed into 0001234.
this is only used as an ID number. No arithmetic operation is to be performed.

Posted: Fri Mar 27, 2009 5:24 pm
by dbzTHEdinosauer
suggest you try ACCEPTing to an x-type field and then use NUMVAL to move the data to the display-numeric (WS-CUST-NUM) field.

the NUMVAL function will correctly justify the numeric portion of the x-type field (the accept destination) and zero fill to the left.

display-numeric fields are not really 'numeric'.

ACCEPT from CICS? normally RECEIVE is used to import a map (or any data) from a terminal.

COBOL FUNCTION NUMVAL INSPECT REPLACING

Posted: Fri Mar 27, 2009 9:10 pm
by Natarajan
Method 1) In cics-bms programs
In cics programs.. you can do this by coding appropriate picture clause in BMS maps ( PICOUT attribute ) ,
if your work is to display the numeric data with padding zeros.


Method 2) applies to any COBOL program

Here is the basic solution for this.

Code: Select all


MOVE  '  345   ' TO WS-ALPHANUMERIC.                 

COMPUTE WS-NUMERIC = FUNCTION NUMVAL(WS-ALPHANUMERIC)  

MOVE WS-NUMERIC  TO  WS-ALPHANUMERIC.                  

INSPECT WS-ALPHANUMERIC REPLACING ALL SPACES BY '0'. 

In above code...
WS-NUMERIC defined with 9(7)
WS-ALPHANUMERIC defined with X(7)

the number padded with ZEROES will be in WS-ALPHANUMERIC.

Topic deleted by Admin

Posted: Wed Jan 27, 2016 8:21 pm
by academyindia4
<< Content deleted By Admin >>

Topic deleted by Admin

Posted: Sat Jan 30, 2016 11:41 pm
by academyindia4
<< Content deleted By Admin >>

Topic deleted by Admin

Posted: Mon Feb 01, 2016 10:08 pm
by academyindia4
<< Content deleted By Admin >>