View previous topic :: View next topic
|
Author |
Message |
sasikumar1984
Active User
Joined: 02 Jul 2007 Posts: 109 Location: Chennai - India
|
|
|
|
Hi,
i am facing a problem in cobol when moving data from a varaible with picture caluse V9999 to a variable with picture clause V999 comp-3 and the problme is as below.
WS-VAR1 pic 99v99 values 10.25
WS-VAR2 pic v999 comp-3.
WS-VAR3 pic v9999 values .0000
now i am computing WS-VAR3 = WS-VAR1 * 0.01 = 10.25*0.01 = .1025
Then i am moving WS-VAR3 to WS-VAR2.
now WS-VAR2 is displaying '.025'. I dont know on what basis '.025' is moving to WS-VAR2 instead of '.102'. Can someone help me what is causing the issue here? Please note that i cannt change the picture clause of WS-VAR2 since it is a variable used in the program in so many places.
Regards,
Sasikumar.K |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
now i am computing WS-VAR3 = WS-VAR1 * 0.01 = 10.25*0.01 = .1025
Then i am moving WS-VAR3 to WS-VAR2. |
don't believe you,
cut and paste the exact data definitions and
the code in the module. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
You are obviously NOT pasting the precise code used since VALUES gives a syntax error. When I copied what you said you were doing and tried it out:
Code: |
77 WS-VAR1 PIC 99V99 VALUE 10.25 .
77 WS-VAR2 PIC V999 COMP-3.
77 WS-VAR3 PIC V9999 VALUE .0000 .
PROCEDURE DIVISION.
COMPUTE WS-VAR3 = WS-VAR1 * .01 .
MOVE WS-VAR3 TO WS-VAR2.
DISPLAY 'WS-VAR1 ' WS-VAR1.
DISPLAY 'WS-VAR2 ' WS-VAR2.
DISPLAY 'WS-VAR3 ' WS-VAR3. |
gives me results of
Code: |
WS-VAR1 1025
WS-VAR2 102
WS-VAR3 1025 |
exactly as expected.
So you are either not doing what you told us you are doing, or your changes from the actual code to pasting here added another factor. |
|
Back to top |
|
|
sasikumar1984
Active User
Joined: 02 Jul 2007 Posts: 109 Location: Chennai - India
|
|
|
|
Hi,
Thanks for looking into my problem.
i verified the variable WS-VAR2, its picture clause is pic VP999 comp-3. Its a packed decimal value. I am getting 0.025 in this instead of 0.102. Can you please let me know what is causing problem here.?
regards,
Sasikumar.K |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
NOW you tell us the picture is VP999, not V999. Do you know what the P symbol does? If not, look up the P symbol in the COBOL Language Reference manual and you will find that 0.025 is the expected result in a VP999 field instead of 0.102 in a V999 field.
As I said earlier, you need to post the exact code you are using or the answers you get will not reflect your problem -- just as what happened when you didn't post the exact code above. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
i am facing a problem in cobol when moving data from a varaible with picture caluse V9999 to a variable with picture clause V999 comp-3 and the problme is as below. |
Quote: |
i verified the variable WS-VAR2, its picture clause is pic VP999 comp-3. |
How did the VP999 get into the code? If you did not code this, there must have been a reason. . .
Suggest you talk with your seniors and determine the "rules" for this process. That PICTURE is quite rare, so either you simply made a mistake when coding/typing this or someone else had a reason for this definition. |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
CICS Guy wrote: |
It seems that the VP is the same a V, what am I missing? |
Further on in the manual it says:
"In certain operations that reference a data item whose PICTURE character-string contains the symbol P, the algebraic value of the data item is used rather than the actual character representation of the data item. This algebraic value assumes the decimal point in the prescribed location and zero in place of the digit position specified by the symbol P. The size of the value is the number of digit positions represented by the PICTURE character-string. These operations are any of the following:
* Any operation that requires a numeric sending operand
* A MOVE statement where the sending operand is numeric and its PICTURE character-string contains the symbol P " |
|
Back to top |
|
|
sasikumar1984
Active User
Joined: 02 Jul 2007 Posts: 109 Location: Chennai - India
|
|
|
|
I am sorry if i have confused u guys....
Actually i didnt introduce the field WS-VAR2 in the programs. its an existing variable. I am just computing the value and moving the value to WS-VAR2.
The variable is declared as below.
05 WS-VAR2 pic v999 comp-3.
05 WS-VARA redefines WS-VAR1 pic vp999 comp-3.
After computation i am moving my value to WS-VAR2 only. That is the reason i said the picture clause is V999 in my first post. Later i have seen the redefines picture clause and i have informed the same in my second post.
I thought WS-VAR2 will hold .102 (actually i am moving .1025) and that should be displayed when i check in FILEAID. but in fileaid it shows .025
but my senior says it is .1025 only because of the redefines picture clause VP999 it will store the actual value. I really dont understand how come this happens?
Regards,
Sasikumar.K |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
sasikumar1984 wrote: |
I thought WS-VAR2 will hold .102 (actually i am moving .1025) and that should be displayed when i check in FILEAID. but in fileaid it shows .025
but my senior says it is .1025 only because of the redefines picture clause VP999 it will store the actual value. I really dont understand how come this happens? |
Robert, since you seem to have the big box available, how about a slightly modified test of your last proof?
Inquiring minds want to know....grin....
Code: |
77 WS-VAR1 PIC 99V99 VALUE 10.25 .
77 WS-VAR2 PIC V999 COMP-3.
77 WS-VAR2A PIC VP999 COMP-3.
77 WS-VAR3 PIC V9999 VALUE .0000 .
77 WS-EDIT PIC +9(4).9(4).
PROCEDURE DIVISION.
COMPUTE WS-VAR3 = WS-VAR1 * .01 .
MOVE WS-VAR3 TO WS-VAR2.
MOVE WS-VAR1 TO WS-EDIT.
DISPLAY 'WS-VAR1 ' WS-EDIT.
MOVE WS-VAR2 TO WS-EDIT.
DISPLAY 'WS-VAR2 ' WS-EDIT.
MOVE WS-VAR3 TO WS-EDIT.
DISPLAY 'WS-VAR3 ' WS-EDIT.
COMPUTE WS-VAR3 = WS-VAR1 * .01 .
MOVE WS-VAR3 TO WS-VAR2A.
MOVE WS-VAR1 TO WS-EDIT.
DISPLAY 'WS-VAR1 ' WS-EDIT.
MOVE WS-VAR2A TO WS-EDIT.
DISPLAY 'WS-VAR2 ' WS-EDIT.
MOVE WS-VAR3 TO WS-EDIT.
DISPLAY 'WS-VAR3 ' WS-EDIT. |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
I cut and pasted your code, compiled and ran -- ask and you receive :
Code: |
WS-VAR1 +0010.2500
WS-VAR2 +0000.1020
WS-VAR3 +0000.1025
WS-VAR1 +0010.2500
WS-VAR2 +0000.0025
WS-VAR3 +0000.1025 |
I think COBOL is using the P to generate the intermediate results, although I have not (yet) gone into the manuals to confirm this. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Thanks, the manual is somewhat confusing with regard to the abnormal use of the P symbol. A couple hours comparing the results of your test and the text of the manual might clear up my condusion.
Dang, to be back in the saddle again....grumble.... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Let's see ... 3 hours of meetings Tuesday, 6 hours Wednesday, 3 hours Thursday, 2 hours today -- while the normal work load continues to pile up. I think I've got saddle sores -- wanna trade?
Not to mention more meetings on Monday and Tuesday ... sigh
Anyway, as far as the P goes, from section 5.3.12.1.1 of the COBOL Language Reference manual:
Quote: |
In certain operations that reference a data item whose PICTURE character-string contains the symbol P, the algebraic value of the data item is used rather than the actual character representation of the data item. This algebraic value assumes the decimal point in the prescribed location and zero in place of the digit position specified by the symbol P. The size of the value is the number of digit positions represented by the PICTURE character-string. |
and 5.3.18.1.1:
Quote: |
With some exceptions, numeric literals in a VALUE clause must have a value within the range of values indicated by the PICTURE clause for the item. For example, for PICTURE 99PPP, the literal must be zero or within the range 1000 through 99000. For PICTURE PPP99, the literal must be within the range 0.00000 through 0.00099. |
So the VP999 will have values between 0.0000 and 0.0999 as the P must be a zero. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Bill,
Here ya go . . .
WS-VAR1 +0010.2500
WS-VAR2 +0000.1020
WS-VAR3 +0000.1025
WS-VAR1 +0010.2500
WS-VAR2 +0000.0025
WS-VAR3 +0000.1025
d |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Oops.. . .
Was interrupted longer than i realized - should have refreshed before sending the reply
At least we got the same results. . .
d |
|
Back to top |
|
|
|