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

Error in moving value to COMP variable


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

New User


Joined: 26 Feb 2008
Posts: 4
Location: INDIA

PostPosted: Tue Jul 06, 2010 5:59 pm
Reply with quote

I am having problem in moving a PIC X value to PIC s9 COMP varaible .
The value is a date in CCYY-MM-DD format and I need to move it to CCYYMMDD format in COMP . I use below code .

The code I have tried to use :

Code:
 03 WS-DUEDATE-NUM-N.                             
    05 WS-CCYY-N                  PIC X(4).       
    05 FILLER                     PIC X.           
    05 WS-MM-N                    PIC X(2).       
    05 FILLER                     PIC X.           
    05 WS-DD-N                    PIC X(2).       
    05 FILLER                     PIC X(9).       
 03 WS-HOST-DUEDATE               PIC S9(9)  COMP.
 03 WS-DUEDATE-NUM.                     -----------------> I have tried changing this to PIC 9 . Still its not working                         
    05 FILLER                     PIC X.           .
    05 WS-CCYY-NUM                PIC X(4).         
    05 WS-MM-NUM                  PIC X(2).       
    05 WS-DD-NUM                  PIC X(2).       


 MOVE DEM-DUE-DATE                 TO WS-DUEDATE-NUM-N. 
  MOVE WS-CCYY-N                    TO WS-CCYY-NUM.
  MOVE WS-MM-N                      TO WS-MM-NUM.
  MOVE WS-DD-N                      TO WS-DD-NUM.
 MOVE WS-DUEDATE-NUM               TO WS-HOST-DUEDATE

Error message I am getting :

WS-DUEDATE-NUM-N :2010-07-31
WS-CCYY-NUM :2010
WS-MM-NUM :07
WS-DD-NUM :31
WS-DUEDATE-NUM : 20100731
DEM-DUE-DATE: 2010-07-31
WS-HOST-DUEDATE 15921393 ---> I was moving WS-DUEDATE-NUM to WS-HOST-DUEDATE ( PIC S9(9) comp ) . Although WS-DUEDATE-NUM is getting populated correctly
DEM-WORKS-ORDER(1:2): 48 the WS-HOST-DUEDATE value is coming junk.
WS-WKPLANRO: 48

Guys please help .

Thanks,
Sandeep
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: Tue Jul 06, 2010 6:44 pm
Reply with quote

15921393 is X'F2F0F1'

A group move is treated as though it were an alphanumeric-to-alphanumeric elementary move, except that there is no conversion of data from one form of internal representation to another.

Try:
Code:
 03 WS-DUEDATE-NUM PIC 9(8).
 03 FILLER REDEFINES WS-DUEDATE-NUM.
    05 WS-CCYY-NUM                PIC X(4).         
    05 WS-MM-NUM                  PIC X(2).       
    05 WS-DD-NUM                  PIC X(2).       
Back to top
View user's profile Send private message
SANDEEPAN DEY

New User


Joined: 26 Feb 2008
Posts: 4
Location: INDIA

PostPosted: Tue Jul 06, 2010 7:19 pm
Reply with quote

ok I will try that out . Do u want me to keep the MOVE statements as it is . Any why it is giving that particular value :

15921393 is X'F2F0F1'


Thanks,
Sandeep
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: Tue Jul 06, 2010 7:33 pm
Reply with quote

Since S9(9) is a four byte field and 15921393 is actually X'00F2F0F1' and the from field is a nine byte field containing '20100731', truncation occurred.
I can only assume the the leading FILLER contained low values.....
Back to top
View user's profile Send private message
SANDEEPAN DEY

New User


Joined: 26 Feb 2008
Posts: 4
Location: INDIA

PostPosted: Wed Jul 07, 2010 12:18 am
Reply with quote

It worked ! Thanks a lot .

However I am still confused what was wrong in my initial code . Was it because of the additional filler ? Can you tell me how should I populate a comp variable from a PIC X variable . Do I need to move it through a PIC 9 variable always ? What measures should I take regard to size ?

Sandeep
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: Wed Jul 07, 2010 12:28 am
Reply with quote

Hello,

Quote:
However I am still confused what was wrong in my initial code .


Code:
WS-DUEDATE-NUM-N :2010-07-31
is not a numeric value. . .
It is a group alphanumeric. To move part of the content (which is what you wanted to do) create a valid elementary numeric field from the numbers in the "input" field.

Then move this valid number to the comp variable.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Jul 07, 2010 12:41 am
Reply with quote

COBOL will move data as-is, if it's defined explicitly or implicitly as PIC X. So, if you have a field which contains only numerics and you need to populate a COMP-3 or COMP field, the sending field must be defined as PIC 9.

Moving PIC 9 to COMP-3, involves 2-3 instructions, which PACKS and then ensures a packed-decimal "C" or "D" sign-nibble or an "F" neutral-nibble.

However, moving PIC 9 to COMP adds several more instructions after the PACK, such as a CVB (Convert To Binary) and a ST (Store).

IMHO, understanding the underlying Assembler instructions would benefit you in the long run.

Compiling your program using the LIST,NOOFFSET compile options and the associated Assembler instructions will be generated.

Bill
Back to top
View user's profile Send private message
SANDEEPAN DEY

New User


Joined: 26 Feb 2008
Posts: 4
Location: INDIA

PostPosted: Wed Jul 07, 2010 11:41 am
Reply with quote

Thanks Guys ! Especially CICS GUY and BIll for your valuable insights.
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 Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Error when install DB2 DB2 2
No new posts CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top