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

Truncation issue while moving COMP-3 value to CHAR


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Dec 02, 2008 4:24 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Dec 02, 2008 5:22 pm
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
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
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: 6966
Location: porcelain throne

PostPosted: Tue Dec 02, 2008 9:42 pm
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
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: 6966
Location: porcelain throne

PostPosted: Tue Dec 02, 2008 10:05 pm
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: 6966
Location: porcelain throne

PostPosted: Tue Dec 02, 2008 10:08 pm
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: 6966
Location: porcelain throne

PostPosted: Wed Dec 03, 2008 3:16 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
Search our Forums:

Back to Top