Page 1 of 2

Issue with Numeric edited field in cobol

PostPosted: Thu Apr 21, 2011 10:16 pm
by MSURESH309
Hi,

I am facing an issue when creating report from cobol program..

I have input fields like

125.5
150
135.75
1450.5
(means character '0' in cents field is always supressed)

I want to be display them as (forma

$125.50
$150.00
$135.75
$1,450.50

input field declared as X(18). Can you help me how to do it in cobol..Please let me know if you need more details..

Thanks,
Suresh.

Re: Issue with Numeric edited field in cobol

PostPosted: Fri Apr 22, 2011 12:30 am
by NicC
Suggest you read the COBOL Language Reference manual paying particular regard to the section on PICTURE CLAUSE

Re: Issue with Numeric edited field in cobol

PostPosted: Fri Apr 22, 2011 1:50 am
by MSURESH309
I coded my program as below..

I redfined input field as

WS-HOLD-AMT PIC X(18). - ---- i/p
WS-HOLD-AMT-R REDEFINES WS-HOLD-AMT PIC 9(16)V99.

I declared print field as

exp-amt pic PIC $$$,$$$,$$9.99. - display field - o/p

in procedure division I am moving like this..

Move WS-HOLD-AMT-R to exp-amt..

But this logic giving abend ..Please help me.Thanks!

Re: Issue with Numeric edited field in cobol

PostPosted: Fri Apr 22, 2011 2:04 am
by prino
MSURESH309 wrote:I coded my program as below..

I redfined input field as

WS-HOLD-AMT PIC X(18). - ---- i/p
WS-HOLD-AMT-R REDEFINES WS-HOLD-AMT PIC 9(16)V99.

I declared print field as

exp-amt pic PIC $$$,$$$,$$9.99. - display field - o/p

in procedure division I am moving like this..

Move WS-HOLD-AMT-R to exp-amt..

But this logic giving abend ..Please help me.Thanks!


And you think that redefining a field from character to numeric just magically makes its contents shift in the correct position?

Better think again!

Re: Issue with Numeric edited field in cobol

PostPosted: Fri Apr 22, 2011 2:46 am
by BillyBoyo
First, if you want to use Cobol's numeric-edited pictures, you have to get your data "right justified".

Then you'll need to turn the decimal point into an implied decimal point (ie such that it does not really exist, but the last two characters represent the decimal part). Remember that you currently have 0, 1 and 2 decimal places and you will need to make them all have two decimal places without messing up the data.

You'll have to then, for a reasonable amount of characters, turn the leading spaces into zeros.

Look up STRING/UNSTRING, INSPECT and justification.

You will then have a field containg numerics which you can redefine so that it has two (implied) decimal places.

Then you can move that to your edited field.

Then, for some reason, you want them lined-up flat along the currency. You should be able to get to that from what you've already read and understood in the manual.

Re: Issue with Numeric edited field in cobol

PostPosted: Sat Apr 23, 2011 7:11 am
by Robert Sample
You might also check the intrinsic function NUMVAL.

Re: Issue with Numeric edited field in cobol

PostPosted: Sat Apr 23, 2011 1:07 pm
by BillyBoyo
Yes, Robert's solution will be significantly easier to follow, which is almost always good when writing code.

To stick it back (unless there is another function, which I can't see :-) ), you could also consider the method in "Example: arithmetic expressions as reference modifiers" in the Programmer's Guide.

Re: Issue with Numeric edited field in cobol

PostPosted: Sun Apr 24, 2011 9:47 pm
by MSURESH309
Thanks for your suggestionss..Your answers worked for me..This is what I coded in my program..I got results as required..

WS-HOLD-AMT PIC X(18) JUST RIGHT.
WS-HOLD-AMT-NUM PIC 9(16)V99.
TOT-EXP-AMT PIC $$$,$$$,$$9.99 - display field - o/p

MOVE input-amount TO WS-HOLD-AMT
COMPUTE WS-HOLD-AMT-NUM = FUNCTION NUMVAL(WS-HOLD-AMT)
MOVE WS-HOLD-AMT-NUM TO TOT-EXP-AMT

Thanks,
Suresh.

Re: Issue with Numeric edited field in cobol

PostPosted: Mon Apr 25, 2011 3:46 am
by BillyBoyo
MSURESH309 wrote:Thanks for your suggestionss..Your answers worked for me..This is what I coded in my program..I got results as required..

WS-HOLD-AMT PIC X(18) JUST RIGHT.
WS-HOLD-AMT-NUM PIC 9(16)V99.
TOT-EXP-AMT PIC $$$,$$$,$$9.99 - display field - o/p

MOVE input-amount TO WS-HOLD-AMT
COMPUTE WS-HOLD-AMT-NUM = FUNCTION NUMVAL(WS-HOLD-AMT)
MOVE WS-HOLD-AMT-NUM TO TOT-EXP-AMT

Thanks,
Suresh.


Glad you have it working.

If your input-amount is the 18-character field, you don't need to move it to ws-hold-amt. If the fields are the same length, the JUST RIGHT makes no difference. NUMVAL can handle it being on the left. Also check in the manual, I have a feeling that you might be near the size limit for NUMVAL.

Re: Issue with Numeric edited field in cobol

PostPosted: Tue Jun 21, 2011 9:01 am
by mrngorickets
Hi,

I agreed with you. Any way, your points of view make me thinking about some thing for my project.

Pls try to keep posting. Tks and best regards

Advertising deleted

Best rgs