Moving Numeric to COmp 3



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

Moving Numeric to COmp 3

Postby nm992 » Fri Nov 19, 2010 1:12 pm

I have 9(9)V9(2) .I need to move to S9(9)V((2) Comp 3.How do i move that?
nm992
 
Posts: 43
Joined: Sun Jul 11, 2010 11:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Moving Numeric to COmp 3

 

Re: Moving Numeric to COmp 3

Postby Akatsukami » Sat Nov 20, 2010 12:41 am

Whilst I have not programmed in COBOL in many years, IIRC the statement is:
 MOVE DISPLAY-VAR TO COMP-3-VAR.


You are aware that a COBOL COMP-3 variable is numeric, in fact packed decimal, yes?
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Moving Numeric to COmp 3

Postby nm992 » Tue Nov 23, 2010 3:11 pm

hi..


As per my knowlwedge..We cant move directly to comp-3 variable.

Can anyone suggest?
nm992
 
Posts: 43
Joined: Sun Jul 11, 2010 11:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Moving Numeric to COmp 3

Postby Robert Sample » Tue Nov 23, 2010 5:57 pm

As per my knowlwedge..We cant move directly to comp-3 variable.

Can anyone suggest?
Your knowledge is WRONG. Any numeric variable (USAGE DISPLAY, COMP, COMP-1, COMP-2, COMP-3, COMP-4, or COMP-5) can be moved to a COMP-3 variable with only truncation and overflow issues possible, depending upon the PICTURE clauses involved. You generally cannot move PIC X variables to a COMP-3 variable, but in some special cases even that can work.

Please find the COBOL Language Reference manual and spend a while reading the elementary move rules -- you will learn much that you do not know.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times

Re: Moving Numeric to COmp 3

Postby dick scherrer » Wed Nov 24, 2010 3:12 am

Hello,

As per my knowlwedge..We cant move directly to comp-3 variable.

Can anyone suggest?
Suggest you never use the source of that "knowledge" again. . .

If it came from some documentation we may be able to clarify if you post this bit from the material.

If it came from some person, be very careful to never ask for any more technical information from that person. There is no way to know how many other "things" they don't know. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Moving Numeric to COmp 3

Postby nm992 » Wed Nov 24, 2010 11:46 am

Thanks RObert and Dick..

How about if I have to move Pic X to COmp-3 variable?
nm992
 
Posts: 43
Joined: Sun Jul 11, 2010 11:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Moving Numeric to COmp 3

Postby Robert Sample » Wed Nov 24, 2010 4:08 pm

If the PIC X variable does not have purely numeric data, moving it to ANY numeric variable can cause a S0C7 abend.

Assuming that the PIC X variable does have nothing but numeric digits, your best bet is a two-step move: move the PIC X to USAGE DISPLAY variable, then move the USAGE DISPLAY variable to the COMP-3 variable. This will allow COBOL to handle the conversion between the PIC X internal storage format and the COMP-3 internal storage format. Moving a PIC X variable directly to a COMP-3 variable pretty much guarantees an abend as the internal formats are very different.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 222 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post