IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Edited numeric variable cannot be used in arithmatic


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sameet83

New User


Joined: 05 Jul 2006
Posts: 2

PostPosted: Thu Dec 07, 2006 2:28 pm
Reply with quote

Hi,
I have a variable WS-PERCENT PIC 9.99. It can have a value of .89 . I want to convert this data to 89.00. I tried multiplying WS-PERCENT by 100 but got a compilation error saying edited numeric variable cannot be used in arithmatic statement.

Could anyone please let me know as to how can I convert this data.

Thanks
Sameet
Back to top
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Thu Dec 07, 2006 3:13 pm
Reply with quote

Sameet,

Please try this...

77 WS-VAR1 PIC 9.99.
77 WS-VAR2 PIC 99.99.
77 WS-VAR3 PIC 99V99.
77 WS-VAR4 PIC 9V99.

MOVE .89 TO WS-VAR4
MOVE WS-VAR4 TO WS-VAR1
MOVE WS-VAR1 TO WS-VAR3
COMPUTE WS-VAR3 = WS-VAR3 * 100
MOVE WS-VAR3 TO WS-VAR2
DISPLAY WS-VAR2

Dinesh
Back to top
View user's profile Send private message
sameet83

New User


Joined: 05 Jul 2006
Posts: 2

PostPosted: Thu Dec 07, 2006 4:44 pm
Reply with quote

Hi Dinesh,
The above code works if the input is 0.89. i get a S0C7 error for
MOVE .89 TO WS-VAR4 .

Currently I have changed my i/p data format to 0.89 and the above code works fine.

Thanks a lot Dinesh.


Thanks
Sameet
Back to top
View user's profile Send private message
cobolunni

Active User


Joined: 07 Aug 2006
Posts: 127
Location: kerala,india

PostPosted: Thu Dec 07, 2006 6:07 pm
Reply with quote

hello sameet

you are getting the compilation error because you are using a edited pic item
you can declare another variable
Code:
01 WS-PERCENT-C PIC 9V99.
01 WS-PERCENT PIC 99.99.
01 RESULT PIC 99V99.

Now use WS-PERCENT for display purpose (ie move value of WS-PERCENT-C
to WS-PERCENT and display WS-PERCENT)
use WS-PERCENT-C for arithmetic operation (ie
Code:
COMPUTE RESULT = WS-PERCENT-C * 10000
)

Code:
01 WS-PERCENT-C PIC 99V99.
01 WS-PERCENT PIC 99.99.
01 RESULT PIC 99V99.


Code:
MOVE 0.89 TO WS-PERCENT-C.
COMPUTE RESULT = WS-PERCENT-C * 10000.
MOVE WS-PERCENT-C TO WS-PERCENT.
DISPLAY WS-PERCENT.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Dec 10, 2006 5:02 am
Reply with quote

Hi Sameet,

Try this:
Code:

01  WS-PERCENT        PIC 99.99
01  WS-PERCENT-NUM    PIC 99V99

MOVE WS-PERCENT    TO WS-PERCENT-NUM
COMPUTE WS-PERCENT  = WS-PERCENT-NUM * 100

Note that I changed the PIC of WS-PERCENT to 99.99 to make it large enough to contain 89.00 after the COMPUTE.
Back to top
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Mon Dec 11, 2006 12:51 pm
Reply with quote

hi Sameet,

The code works fine for other nos. also. It doesn't depends on 0.89.

I think you are trying to do computation on numeric edited field. If you could paste the code which is giving error then it will be easier to understand the problem.

Dinesh
Back to top
View user's profile Send private message
cynderilla

New User


Joined: 07 Dec 2006
Posts: 5
Location: chennai

PostPosted: Mon Dec 11, 2006 5:57 pm
Reply with quote

Hi sammet,

U got that error because we cannot do arthimatic operation's
on numeric edited variables.

instead of that we can use general varibles for the arthmatic operation's
n after that we can move it to edited variables.

n the ouput depend's upon the edited variable if it's shorter than the output,it will be truncated.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Dec 12, 2006 2:22 am
Reply with quote

HI ALL,

A num/ed var can be used as the receiving var in a compute, ex.:

COMPUTE WS-NUM-ED = 2 * 2
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
No new posts Convert HEX to Numeric DB2 3
Search our Forums:

Back to Top