Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Error in moving value to COMP variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Error in moving value to COMP variable
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: 2150
Location: At my coffee table

PostPosted: Tue Jul 06, 2010 6:44 pm    Post subject:
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    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Tue Jul 06, 2010 7:33 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Jul 07, 2010 12:28 am    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Jul 07, 2010 12:41 am    Post subject: Reply to: Error in moving value to COMP variable
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Need help with below DB2 error ashek15 DB2 3 Sat Mar 18, 2017 5:56 am
No new posts FINDREP Syntax Error seahawk789 DFSORT/ICETOOL 4 Thu Mar 09, 2017 10:11 pm
No new posts INVOKE WEBSERVICE error danik56 CICS 11 Thu Mar 09, 2017 11:52 am
No new posts Row not found Sql error GaganGarg DB2 7 Tue Mar 07, 2017 6:29 am
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us