Issue with Numeric edited field in cobol



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Issue with Numeric edited field in cobol

Postby MSURESH309 » Thu Apr 21, 2011 10:16 pm

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.
MSURESH309
 
Posts: 17
Joined: Thu Apr 21, 2011 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Issue with Numeric edited field in cobol

Postby NicC » Fri Apr 22, 2011 12:30 am

Suggest you read the COBOL Language Reference manual paying particular regard to the section on PICTURE CLAUSE
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Issue with Numeric edited field in cobol

Postby MSURESH309 » Fri Apr 22, 2011 1:50 am

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!
MSURESH309
 
Posts: 17
Joined: Thu Apr 21, 2011 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Issue with Numeric edited field in cobol

Postby prino » Fri Apr 22, 2011 2:04 am

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!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 641
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 29 times

Re: Issue with Numeric edited field in cobol

Postby BillyBoyo » Fri Apr 22, 2011 2:46 am

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Issue with Numeric edited field in cobol

Postby Robert Sample » Sat Apr 23, 2011 7:11 am

You might also check the intrinsic function NUMVAL.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Issue with Numeric edited field in cobol

Postby BillyBoyo » Sat Apr 23, 2011 1:07 pm

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Issue with Numeric edited field in cobol

Postby MSURESH309 » Sun Apr 24, 2011 9:47 pm

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.
MSURESH309
 
Posts: 17
Joined: Thu Apr 21, 2011 10:04 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Issue with Numeric edited field in cobol

Postby BillyBoyo » Mon Apr 25, 2011 3:46 am

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.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Issue with Numeric edited field in cobol

Postby mrngorickets » Tue Jun 21, 2011 9:01 am

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
mrngorickets
 
Posts: 1
Joined: Sat Mar 19, 2011 6:54 am
Has thanked: 0 time
Been thanked: 0 time

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post