Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comp-3 1

Status
Not open for further replies.

claudeb

Programmer
Nov 23, 2000
140
CA
hi,
what happens if i do a move of a PIC S9(07) COMP-3 to a PIC S9(07) ?
i get strange results.
thanks
 
The result of this move is dependent on the COBOL you are using. Some COBOL's will reformat and do it correctly, others will not. I use a variety of different COBOL systems and the following technique works for me across the different COBOL systems.

01 FIELD-A PIC S9(07) COMP-3.
01 FIELD-B PIC S9(7).
...
ADD FIELD-A TO ZERO GIVING FIELD-B.

Hope this helps...
 
In my previous note I forgot to answer your question of "What happens..." Some COBOL systems fail to recognize the numeric characteristics of the source and target fields and the different formats of each. An example of this type of failure is as follows...
The PIC S9(7) COMP-3 source field of seven digits is stored in memory as a packed-decimal value that is 4 bytes. If the source field is a value of 0000123 then it is stored as X'0000123C'.
The PIC S9(9) target field of seven digits is stored in memory as 7 bytes. If the value prior to the move is zero then it is stored as X'F0F0F0F0F0F0F0'.
Some COBOL systems simply do a move and this could result in the target field stored as X'0000123CF0F0F0' or "strange result"...
I know the IBM Mainframe, Micro Focus (now MERANT) and Fujitsu handle this correctly... I would be curious to know what COBOL are you using since I have not seen this problem in a number of years?
Hope this answers your question...
 
Hi,
I have never seen any kind of a Cobol problem that occurs under the circumstances you describe unless your comp-3 field really has something completely different in it than you think it does (like control characters). Your s9(7) field could be zoned signed, leading sign, or trailing sign depending on your compiler defaults; but that shouldnt affect the move.
 
I have been asked a silmilar question. Once I looked at the programmer's code I found the following:

01 FIELD-A PIC S9(08) COMP-3.
01 FIELD-B.
05 FIELD-B-YY PIC 9(4).
05 FIELD-B-MM PIC 9(2).
05 FIELD-B-DD PIC 9(2).

...
MOVE FIELD-A TO FIELD-B.

This code resulted in an alpha-numeric move. The end results has packed data in a numeric display field (i.e., x'1234567C'). I had the programmer change the definition of FIELD-B as follows:

01 FIELD-B PIC 9(8).
01 FILLER REDEFINES FIELD-B.
05 FIELD-B-YY PIC 9(4).
05 FIELD-B-MM PIC 9(2).
05 FIELD-B-DD PIC 9(2).


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top