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

Problem with movind 99v99 to v999 field


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

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Wed Apr 14, 2010 8:56 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Apr 14, 2010 11:43 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Apr 14, 2010 5:06 pm
Reply with quote

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
View user's profile Send private message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Fri Apr 16, 2010 6:58 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Apr 16, 2010 7:41 am
Reply with quote

Quote:
its picture clause is pic VP999 comp-3
That's a new one on me.....
The symbol P can be specified only as a continuous string of Ps in the leftmost or rightmost digit positions within a PICTURE character-string
Is there a reason for the 'P'?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Apr 16, 2010 8:07 am
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Fri Apr 16, 2010 8:39 am
Reply with quote

Robert Sample wrote:
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.
I just didn't see that:
The symbol P specifies a scaling position and implies an assumed decimal point (to the left of the Ps if the Ps are leftmost PICTURE characters; to the right of the Ps if the Ps are rightmost PICTURE characters). The assumed decimal point symbol V is redundant as either the leftmost or rightmost character within such a PICTURE description.
It seems that the VP is the same a V, what am I missing?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Apr 16, 2010 8:56 am
Reply with quote

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
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Fri Apr 16, 2010 6:03 pm
Reply with quote

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
View user's profile Send private message
sasikumar1984

Active User


Joined: 02 Jul 2007
Posts: 109
Location: Chennai - India

PostPosted: Sat Apr 17, 2010 7:02 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sat Apr 17, 2010 7:23 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Apr 17, 2010 7:50 am
Reply with quote

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. icon_smile.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sat Apr 17, 2010 7:57 am
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Sat Apr 17, 2010 8:09 am
Reply with quote

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? icon_biggrin.gif

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Apr 17, 2010 8:10 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Apr 17, 2010 8:13 am
Reply with quote

Oops.. . .

Was interrupted longer than i realized - should have refreshed before sending the reply icon_redface.gif

At least we got the same results. . .

d
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
Search our Forums:

Back to Top