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

Move COMP variable to Alphanumeric variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Tue Jul 21, 2009 6:57 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Jul 21, 2009 7:03 pm
Reply with quote

RTFM
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 Jul 21, 2009 7:05 pm
Reply with quote

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
View user's profile Send private message
knn9413

New User


Joined: 23 Jul 2009
Posts: 17
Location: US

PostPosted: Thu Jul 23, 2009 4:43 pm
Reply with quote

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
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Thu Jul 23, 2009 4:58 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 23, 2009 5:02 pm
Reply with quote

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
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Thu Jul 23, 2009 5:09 pm
Reply with quote

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 icon_rolleyes.gif

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 icon_biggrin.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jul 23, 2009 5:21 pm
Reply with quote

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
View user's profile Send private message
knn9413

New User


Joined: 23 Jul 2009
Posts: 17
Location: US

PostPosted: Thu Jul 23, 2009 7:20 pm
Reply with quote

You guys are brutal. Thanks for the nice welcome !! icon_biggrin.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Jul 23, 2009 8:00 pm
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Jul 23, 2009 8:32 pm
Reply with quote

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! icon_smile.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 23, 2009 8:49 pm
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Jul 27, 2009 7:54 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Mon Jul 27, 2009 8:14 pm
Reply with quote

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
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 REXX/CMS How to place command console... CLIST & REXX 4
No new posts CA7 count with DATE variable CA Products 0
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
Search our Forums:

Back to Top