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
 

 

Truncation issue while moving COMP-3 value to CHAR

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rajupillai

New User


Joined: 24 Nov 2008
Posts: 2
Location: india

PostPosted: Tue Dec 02, 2008 3:53 pm    Post subject: Truncation issue while moving COMP-3 value to CHAR
Reply with quote

Hi All,

Am facing the following truncation issue:

03 num1 pic 9(3)
.
.
03 num2 pic s9(03) comp-3.
.
.
07 char1 pic x(51).

The field char1 has been redefined several times to support all kinds of values.

The statement in the source are

MOVE NUM1 TO NUM2.
MOVE NUM2 TO CHAR1.

If the value in NUM1 is 211, the final value in CHAR1 is coming as 21.

Any help on why this truncation is happening will be appreciated.

Thanks,
Raju.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Tue Dec 02, 2008 4:24 pm    Post subject:
Reply with quote

It's not truncating, but I'm not sure what is happening -- could you post a display of the hex value in CHAR1 after the MOVE statement?
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: Tue Dec 02, 2008 5:22 pm    Post subject: Re: Truncation issue while moving COMP-3 value to CHAR
Reply with quote

I recall years ago (in COBOL2 Release 4 or COBOL/370), moving a COMP-3 field directly to a CHAR (PIC X) field, would cause the compiler to generate an MVC, instead of an UNPK of the COMP-3 field into the first 3-Bytes.

In any case, you really should be moving a display-numeric (unpacked) field directly into the PIC X field using reference modification (instead of COMP-3/PACKED-DECIMAL), as this is the safest and cleanest method.

EG:

Code:

MOVE NUM2      TO NUM1.
MOVE NUM1 (1:) TO CHAR1 (1:).

Give this a try and let us know how it works out.

HTH....

Regards,

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

New User


Joined: 24 Nov 2008
Posts: 2
Location: india

PostPosted: Tue Dec 02, 2008 9:08 pm    Post subject: Re: Truncation issue while moving COMP-3 value to CHAR
Reply with quote

Bill, it did not work by the solution you suggested.

Do you think there could be any problem due to the field level? i tried using the same PIC clause and logic but a different level 01 for all the 3 fields. that worked fine.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue Dec 02, 2008 9:41 pm    Post subject:
Reply with quote

As long as your 3 fields do not overlap (share storage), the level numbers should not make a difference. I find it hard to believe that Bill's suggestion did not work. Can you paste your exact field definitions and code?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Dec 02, 2008 9:42 pm    Post subject:
Reply with quote

not sure what Rajupillai is doing, but the following code has the same results both with COBOL II and Enterprise COBOL:


WORKING-STORAGE:
Code:

/
 WORKING-STORAGE                 SECTION.
*---------------                 --------
 01  SOURCE-GROUP.
     05  WS-DISPLAY-FIELD        PIC S9(4).
     05  WS-BINARY               PIC S9(4).
     05  WS-PACKED-DECIMAL       PIC S9(4).
     05  WS-CHAR-FIELD           PIC X(21) VALUE SPACES.

PROCEDURE DIV:
Code:

MOVE 211                       TO WS-DISPLAY-FIELD
                                  WS-BINARY
                                  WS-PACKED-DECIMAL
MOVE WS-DISPLAY-FIELD          TO WS-CHAR-FIELD
DISPLAY WS-CHAR-FIELD

MOVE SPACES                    TO WS-CHAR-FIELD
MOVE WS-PACKED-DECIMAL         TO WS-CHAR-FIELD
DISPLAY WS-CHAR-FIELD

MOVE SPACES                    TO WS-CHAR-FIELD
MOVE WS-BINARY                 TO WS-CHAR-FIELD
DISPLAY WS-CHAR-FIELD

MOVE SPACES                    TO WS-CHAR-FIELD
MOVE WS-DISPLAY-FIELD(1:4)     TO WS-CHAR-FIELD(1:4)
DISPLAY WS-CHAR-FIELD

MOVE SPACES                    TO WS-CHAR-FIELD
MOVE WS-DISPLAY-FIELD(1:)      TO WS-CHAR-FIELD(1:)
DISPLAY WS-CHAR-FIELD

MOVE SPACES                    TO WS-CHAR-FIELD
MOVE WS-PACKED-DECIMAL         TO WS-CHAR-FIELD
DISPLAY WS-CHAR-FIELD


Results:
Code:

0211
0211
0211
021A
021A
0211



Rajupillai,

why do you think using a 01-level for all fields has an affect?
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue Dec 02, 2008 9:44 pm    Post subject:
Reply with quote

Dick,
Where are your USAGE clauses? icon_smile.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Dec 02, 2008 10:05 pm    Post subject:
Reply with quote

it is late, the machine is running on really cold oil, and I am an idiot.

will update and repost tomorrow.

thx for the tip, terry.

will attempt to keep my eyes open.

dbz
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Dec 02, 2008 10:08 pm    Post subject:
Reply with quote

Terry,

the clauses are in the same place my head is in - UMA.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Dec 03, 2008 3:16 pm    Post subject:
Reply with quote

Hi guys,

This morning adding the clauses (BINARY & PACKED-DECIMAL) and recompiled both COBOL II and Enterprise, results are the same.

Both COBOL II and Enterprise COBOL will unpack the PD and convert the Binary on a move to x-type.
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 Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am
No new posts Execessive parameter issue Sumeendar JCL & VSAM 5 Mon Dec 19, 2016 4:35 pm
No new posts DFHRESPONSE returns issue divated CICS 3 Wed Nov 02, 2016 6:32 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


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