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.
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.
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:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.