View previous topic :: View next topic
|
Author |
Message |
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi,
I am trying to move S9(8) COMP field to X(16) field. But after movement first two bytes of numeric field gets truncated.
I will be thankful if anyone let me know the reason behind this
Sample Code:
Working-Storage
01 TEST-REC.
05 A PIC S9(8) COMP.
05 B PIC X(16) VALUE SPACES.
Procedure Division.
MOVE 1234512345 TO A.
MOVE A TO B.
DISPLAY 'VALUE OF A ==> ' A.
DISPLAY 'VALUE OF C ==> ' B.
STOP RUN.
Final display:
VALUE OF A ==> 1234512345
VALUE OF C ==> 34512345
Thanks in advance
Regards,
Chandan |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
RTFM |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
To ensure that there isn't high-order truncation on the COMP field (which is what is happening), you need to compile your program using the TRUNC(BIN) compile option. Most likely, you're current TRUNC option is OPT.
However, if your compiler supports COMP-5 (Native Binary), which was introduced with OS/390 COBOL 2.2 some 10-12 years ago, then there's no need to change your TRUNC option (COMP-5 ignores the TRUNC option) and define field A as COMP-5 instead of COMP and you'll be good to go.
Eventually, when all shops have migrated off older compilers and utilize compilers which support COMP-5 and make the necessary adjustments to their source-code, then this problem will go way. |
|
Back to top |
|
|
knn9413
New User
Joined: 23 Jul 2009 Posts: 17 Location: US
|
|
|
|
Craq Giegerich wrote: |
RTFM |
That is totally unwarranted. If you can answer, reply if not just shut up and move on. I have seen a lot of guys who do not know that this could be causing it, even some of the experienced COBOL programmers. |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
Kkn,
Quote: |
If you can answer, reply if not just shut up and move on |
If you can answer, reply if not just shut up and move on. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Kkn: actually, RTFM is a perfectly valid reply. Craq is stating that the information being asked about is in the manual. If the poster cannot find the data in the manual, that's a different issue and should be addressed with another post. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
knn9413 wrote: |
Craq Giegerich wrote: |
RTFM |
That is totally unwarranted. If you can answer, reply if not just shut up and move on. I have seen a lot of guys who do not know that this could be causing it, even some of the experienced COBOL programmers. |
Not bad for a first post
May I suggest that you read THIS document to get a little insight into how most forums work, and the rules that generally apply before spouting off
Oh, and welcome to the forum |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
even some of the experienced COBOL programmers |
big difference between someone who has held a job for a while
and someone who is experienced. |
|
Back to top |
|
|
knn9413
New User
Joined: 23 Jul 2009 Posts: 17 Location: US
|
|
|
|
You guys are brutal. Thanks for the nice welcome !! |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
You guys are brutal. |
what is brutal is some of the questions.
about once a week, a theme is discussed at some level above blind, no-experience, no-desire-to-learn.
otherwise, most threads are like this one. too lazy to look-it-up, to lazy to think, expect others to just hand the stuff to you. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Here are my 2 cents:
I did RTFM and very easily found the Elementary move rules.
Quote: |
If the sending item is a national decimal integer item, the sending data is converted to usage DISPLAY and treated as though it were moved to a temporary data item of category alphanumeric with the same number of character positions as the sending item. The resulting alphanumeric data item is treated as the sending item |
In other words, the program behaves as if there was:
Code: |
01 TEMP-AREA PIC X(8).
MOVE A TO TEMP-AREA.
MOVE TEMP-AREA TO B. |
instead of "MOVE A TO B".
The TEMP-AREA is 8 characters in length, because A's picture is 8, regardless of the TRUNC option.
(The TRUNC influences the "MOVE nnn TO A" statement).
knn9413, welcome to the forum! |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Marso, I don't see in the original post anything about using national characters -- there's no PIC N variables nor any GROUP-USAGE NATIONAL clauses. Other than that, I agree with your analysis -- A has the full value because of the TRUNC option setting while B is truncated due to move rules for conversion (which use picture sizes for moves). |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Quote: |
If the sending item is a national decimal integer item, the sending data is converted to usage DISPLAY and treated as though it were moved to a temporary data item of category alphanumeric with the same number of character positions as the sending item. The resulting alphanumeric data item is treated as the sending item |
Yes, this part of the documentation is a bit strange. I'm not even sure what is meant by "national decimal integer item".
(I always thought a number is decimal OR integer)
Anyway, as there is no "ELSE" in this "IF" sentence, I more or less assumed this is what happens to all numeric items... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
National data is UTF-1600, which is 16-bit ASCII. This code:
Code: |
WORKING-STORAGE SECTION.
01 WS-VARS.
10 WS-A PIC 9(10) USAGE DISPLAY.
10 WS-B PIC 9(10) USAGE NATIONAL.
10 WS-C PIC N(10).
10 WS-D PIC S9(10) COMP.
/
PROCEDURE DIVISION.
S1000-MAIN SECTION.
MOVE 1 TO WS-A
WS-B
WS-C
WS-D.
DISPLAY 'WS-A ' WS-A.
DISPLAY 'WS-B ' WS-B.
DISPLAY 'WS-C ' WS-C.
DISPLAY 'WS-D ' WS-D. |
produces output of
Code: |
WS-A 0000000001
4EE6C4FFFFFFFFFF
0620100000000001
------------------------------------------------------------------------------
WS-B ....................
4EE6C403030303030303030303
06202000000000000000000001
------------------------------------------------------------------------------
WS-C ....................
4EE6C403020202020202020202
06203001000000000000000000
------------------------------------------------------------------------------
WS-D 0000000000000000001
4EE6C4FFFFFFFFFFFFFFFFFFF
0620400000000000000000001 |
x'0031' for WS-B, for example, represents the 1. |
|
Back to top |
|
|
|