View previous topic :: View next topic
|
Author |
Message |
k.pavankumar
New User
Joined: 22 May 2006 Posts: 8
|
|
|
|
Hi
Is it possible to use the Alphanumeric declared variable as a target for the Compute statement.
Advance Thanks. Please Reply |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Pavan,
I dont think so. |
|
Back to top |
|
|
vijayamadhuri
Active User
Joined: 06 Apr 2005 Posts: 180
|
|
|
|
It should be elementary numeric item(s) or elementary numeric-edited
items. |
|
Back to top |
|
|
Bharanidharan
New User
Joined: 20 Jun 2005 Posts: 86 Location: Chennai, India
|
|
|
|
I believe you can use numeric data to be stored in alpha variable, because logically target is nothing but a storage; you will face bomb only when you try to access that storage.
Since the very purpose of declaring an alpha is for non-computational purposes, I don't think this usage would be commonplace. |
|
Back to top |
|
|
humpty Warnings : 1 New User
Joined: 01 May 2005 Posts: 23
|
|
|
|
hi pavan,
let me inform you that Alphanumeric type can contain alphabetic as well as numeric values.
but the limitation for the compute verb is that it is restricted only for numeric data items. so if you cannot target alphanumeric element compute verb.
thanks |
|
Back to top |
|
|
humpty Warnings : 1 New User
Joined: 01 May 2005 Posts: 23
|
|
|
|
hi pavan,
The COMPUTE statement assigns the value of an arithmetic expression to one or more data items. With the COMPUTE statement, arithmetic operations can be combined without the restrictions on receiving data items imposed by the rules for the ADD, SUBTRACT, MULTIPLY, and DIVIDE statements. When arithmetic operations are combined, the COMPUTE statement may be more efficient than the separate arithmetic statements written in a series. |
|
Back to top |
|
|
gskulkarni
New User
Joined: 01 Mar 2006 Posts: 70
|
|
|
|
I don't think humpty's reply is in line with the original question.
It was a simple query of whether or not one can do this:
Code: |
01 WS-AMOUNT pic x(05) value '34560'
COMPUTE WS-RESULT = WS-AMOUNT * 5. |
The answer is NO.
You will get error at compilation time as follows:
Code: |
IGYPA3074-S "WS-AMT-1 (ALPHANUMERIC)" was not numeric, but was a sender in an arithmetic expression. The statement was discarded. |
|
|
Back to top |
|
|
manisha-s Warnings : 1 New User
Joined: 22 May 2006 Posts: 13
|
|
|
|
compute w=u
is valid statement bcoz it is similar to move u to w.
n we can move anything to alphanumeric variable .
so i think it is possible to target an alphanumeric variable in a compute statement. |
|
Back to top |
|
|
gskulkarni
New User
Joined: 01 Mar 2006 Posts: 70
|
|
|
|
manisha-s wrote: |
so i think it is possible to target an alphanumeric variable in a compute statement. |
Apparently not in all of the 'compute's.
See my post above. |
|
Back to top |
|
|
manisha-s Warnings : 1 New User
Joined: 22 May 2006 Posts: 13
|
|
|
|
hi gskulkarni
i suppose the question is
"Is it possible to use the Alphanumeric declared variable as a target for the Compute statement. "
what u did ? u tried to make computations over the alphanumeric values thats not possible .
but still u can target anything to alphanumeric value .
u plz try this thing .
a pic x(3) value "234".
b pic x(3).
compute b=a. |
|
Back to top |
|
|
humpty Warnings : 1 New User
Joined: 01 May 2005 Posts: 23
|
|
|
|
hi gskulkarni,
i fully agree with manisha-s.
bottom line answer is that you cannot manipulate any alphanumeric
data item with COMPUTE verb, instead you can do the same with numeric data types only.
thanks. |
|
Back to top |
|
|
gskulkarni
New User
Joined: 01 Mar 2006 Posts: 70
|
|
|
|
Although your statement compute c=u will work i believe that it is more of a "MOVE" statement equivalent rather than arithmetic operation.
I stand corrected here.
manisha's reply comput c=u may be insuffiencient in the context where question is if alphanumeric could be target for computational statement.
Code: |
01 WS-AMT-1 PIC 9(05). - This is the field to be used for arithmetic
01 WS-RESULT-AMT PIC X(05). - this is the target field after arithmetic on above variable |
I have executed below code:
Code: |
MOVE 34560 TO WS-AMT-1.
DISPLAY 'WS-AMT-1 = ' WS-AMT-1.
COMPUTE WS-RESULT-AMT = WS-AMT-1 * 2.
DISPLAY 'WS-RESULT-AMT = ' WS-RESULT-AMT |
And it has given following response.
Code: |
IGYPA3146-S Receiving operand "WS-RESULT-AMT (ALPHANUMERIC)" of an arithmetic statement was neither numeric nor numeric-edited. The statement was discarded. |
|
|
Back to top |
|
|
manisha-s Warnings : 1 New User
Joined: 22 May 2006 Posts: 13
|
|
|
|
Mr. kulkarni
Kindly read urs n my answers carefully . u will get ur answer .
n one thing more that u r again doing the samething that u applied arithmetic operations on alphanumeric variable . that shudn't b done . |
|
Back to top |
|
|
humpty Warnings : 1 New User
Joined: 01 May 2005 Posts: 23
|
|
|
|
Mr. Kulkarni,
the thing what u r trying to do is called data mismatch and simply
gives SOC7 error.
................. |
|
Back to top |
|
|
gskulkarni
New User
Joined: 01 Mar 2006 Posts: 70
|
|
|
|
Humpty, it will not give soc7 because the pgm itself won't get compiled as i have showed in my post.
manisha and humpty,
i am not saying what you guys are pointing out is wrong.
I accept that the alphanumeric data item can be used as target in compute statement given by manisha.
Now holoding the above sentence true, i am going ahead and saying that it is true only for one single compute statement that she has given - that is with '=' operator. And it is allowed mainly because the = operator is as good as a 'MOVE' statement. There is no other COMPUTE statement where an alphanumeric variable can be used as target. |
|
Back to top |
|
|
OldSystemProgrammer
New User
Joined: 12 May 2006 Posts: 7
|
|
|
|
Hi gskulkarni!
In a numeric operation the type of operation field must be numeric. In your COMPUTE satement the type of result field is alfanumeric. |
|
Back to top |
|
|
|