Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert alpha to packed decimal - Mainframe cobol

Status
Not open for further replies.

Mercykam

Programmer
Mar 26, 2009
3
How do i convert PIC X(11) to SPIC 9(7)v99 COMP-3? This is mainframe cobol programming. Any help is greatly apprciated.
 
IF yourPicX11 IS NUMERIC
MOVE yourPicX11 TO yourPIC9COMP3
END-IF

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you all.
Due to plan change, Actually what i am trying to do now is
Online display Screen field definition is PIC X(11).
We have to capture 9 bytes of the value into copybook field
PIC 9(7)V99 comp-3.
Whatever they key in on the screen is what we have to capture in the copybook field.
Ex: 123456 or 123456789 or 12345

Is the following procedure ok?
redefine copybook field PIC 9(7)v99 COMP-3 to PIC X(9)
then capture 9 bytes of screen field X(11) into copybook field X(9).

 
What if they key in 123 456? I.e. what do you do with an embedded space?
 
Is the following procedure ok?
redefine copybook field PIC 9(7)v99 COMP-3 to PIC X(9)
No - for multiple reasons.


The fields are not the same length.

PIC X and comp-3 fields should not redefine each other.

Once the data is entered by the user, the code must validate the data for proper length and content.
 
The process I've always used for this sort of thing is to do the conversion by writing code to parse the input string following whatever rules are appropriate for your input (leading or trailing sign, implied or actual decimal point provided, maximum value allowed, embedded separators (commas?)). The code is a bit tedious and you have to careful. Once written, however it can easily be reused as needed.

I think many non-mainframe compilers offer a simple way to ACCEPT a value like this.

Regards,

Glenn
 
You may also consider the NUMVAL intrinsic function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ask your colleagues in the office. As we are talking Mainframe Cobol, there will almost definitely already be a sub-routine at your installation to do this.

 
You may also consider the NUMVAL intrinsic function.
NUMVAL and NUMVAL-C work well and can save some rather tedious coding but only when the data is known to be valid.

Data entered from some user is not going to be valid all of the time and invalid entries can cause abends at runtime.

If you want to try NUMVAL/-C, suggest you do some comprehensive testing with various invalid entries (such as no digits, multiple decimal points, letters and numbers combined, etc).
 
I have always used reference modification, scanning the input right to left, and moving numeric bytes into a target numeric field initialized to zeroes. Any combination of rules can be applied. The code is relatively compact and should be quite efficient on an IBM mainframe which has reference modification in the microcode.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top