View previous topic :: View next topic
|
Author |
Message |
rajupillai
New User
Joined: 24 Nov 2008 Posts: 2 Location: india
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
rajupillai
New User
Joined: 24 Nov 2008 Posts: 2 Location: india
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Dick,
Where are your USAGE clauses? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Terry,
the clauses are in the same place my head is in - UMA. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|