×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

convert alpha to packed decimal - Mainframe cobol

convert alpha to packed decimal - Mainframe cobol

(OP)
How do i convert PIC X(11) to SPIC 9(7)v99 COMP-3? This is mainframe cobol programming. Any help is greatly apprciated.
Replies continue below

RE: convert alpha to packed decimal - Mainframe cobol

IF yourPicX11 IS NUMERIC
MOVE yourPicX11 TO yourPIC9COMP3
END-IF

RE: convert alpha to packed decimal - Mainframe cobol

Pic S9(9) should be a Redfinition of your S9(7)v99.

RE: convert alpha to packed decimal - Mainframe cobol

(OP)
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).

RE: convert alpha to packed decimal - Mainframe cobol

What if they key in 123 456? I.e. what do you do with an embedded space?

RE: convert alpha to packed decimal - Mainframe cobol

Quote:

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.

RE: convert alpha to packed decimal - Mainframe cobol

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

RE: convert alpha to packed decimal - Mainframe cobol

You may also consider the NUMVAL intrinsic function.

RE: convert alpha to packed decimal - Mainframe cobol

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.

RE: convert alpha to packed decimal - Mainframe cobol

Quote:

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

RE: convert alpha to packed decimal - Mainframe cobol

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!