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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to move numeric non integer data item to alphanumeric data item? 3

Status
Not open for further replies.

yuriyking

Programmer
Jan 29, 2004
26
0
0
DE
Hi all.
Sorry, if the question is stupid, but I am totally new to COBOL.

I have two data items:

01 NNI PIC 9(05)V9(02) USAGE IS DISPLAY.
01 AN PIC X(07).

When trying to move:

MOVE NNI TO AN


I have the following error:

1561 IGYPA3005-S "NNI (NUMERIC NON-INTEGER)" AND "AN (ALPHANUMERIC)" DID NOT FOLLOW THE "MOVE" STATEMENT
COMPATIBILITY RULES. THE STATEMENT WAS DISCARDED.

It is OS/390, IBM COBOL FOR MVS & VM 1.2.2.

My question: can I somehow move value from NNI (without comma) to AN without using REDEFINES.

Thans a lot.
 
Hi yuriyking,

Guess it depends what you mean by redefines. Something like this should work, but it is an implicit redefinition.

Code:
    1   NNI.
     2      PIC 9(05)V9(02) USAGE IS DISPLAY.
        :
        :
        MOVE NNI TO AN

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Hi, Tony.
As I understood, redefining is normal practice in COBOL.
My native languages are C and C++, that's why I had some doubts whether redefining is a good style.
If in COBOL it is good style - OK.
I will do it this way.
Thank You.
 
Hi yuriyking,

C and COBOL are different animals, and variable typing works completely dfferently (in as much as it can be said to work at all with Cobol). In C there is, in effect, a layer between you and the memory. In Cobol you are more or less mapping portions of memory with your storage definitions and implicit and explicit redefinitions are routine.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
If USAGE is DISPLAY, try this:

MOVE NNI(1:7) TO AN(1:7)

Dimandja
 
Dimandja -

For the kind of MOVE you're proposing, I prefer
Code:
MOVE NNI(1:) TO AN
This approach allows you a little flexibility to change the definitions (i.e. length) of NNI and AN without always "breaking" the code.

Regards.

Glenn
 
Glenn,

That would be fine, except my manual used to (or still does) say that when moving data between numeric and alpha, the size needs to be explicit.

I believe the reason is justification of data, or something along those lines.

Also, when NNI is NUMERIC, "NNI(1:)" may fail to size up correctly.

Dimandja
 
Dimandja,

Can you not, in that case, use LENGTH OF NNI for the length? Then you have it explicit, and you have the flexibility.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Of course, Tony. That's a more elegant solution. Notice that the size needs to be specified on the destination field as well, as in:

MOVE NNI(1:LENGTH OF NNI) TO AN(1:LENGTH OF NNI)

Dimandja
 
It is not neccessary to specify reference modification on both the source and the target. Specifying it on either converts the move to a "group" move, which is treated as a move from one alphameric item to another.
 
Dimandja:

You wrote:
Code:
MOVE NNI(1:LENGTH OF NNI)
Code:
 TO AN(1:LENGTH OF NNI)

But there is danger in this in the general case.
Code:
LENGTH OF NNI
may exceed the actual length on AN, which will most likely cause some problems.

Tom Morrison
 
Of course.

Before the MOVE one should make sure that 'LENGTH OF AN' is equal or greater than 'LENGTH OF NNI'. Seeing that my COBOL, at least, lacks dynamic allocation capabilities...

Dimandja
 
webrabbit: ...Specifying it on either converts the move to a "group" move, which is treated as a move from one alphameric item to another.

That's exactly the intended effect, especially when dealing with mismatched data types.

Dimandja
 
webrabbit, I meant to emphasize that my COBOL insists on using size on both operands to avoid nasty results.
 
Dimandja, if your COBOL does as you say, it is non-standard and defective. One should never[/] have to explicitly specify the length of the target as long as it is internal to the program.
 
This debate is pointless without testing the theories. I have no access to a COBOL compiler at this moment. Maybe you do, webrabbit?

Dimandja
 
In the meantime, a quick call to a colleague produced this:

"The MOVE between alpha and numeric fields needs to be implied as 'group to group', otherwise if an operand is treated as elementary, the COBOL auto-conversion will kick in and the data may not be interpreted correctly: use size on both operands".

I am waiting for a rigorous test or formal documentation.

Dimandja

 
FYI.

MOVE NNI(1:) TO AN

is accepted by IBM COBOL FOR MVS & VM 1.2.2

And I tend to agree with webrabbit that

"It is not neccessary to specify reference modification on both the source and the target. Specifying it on either converts the move to a "group" move, which is treated as a move from one alphameric item to another."

Although I did not find any explicit confirmation of it in IBM documentation, but, to argue with logic, it should be so.
IMHO.
 
There are three situations to consider

1. The target is shorter than the source:

- if reference modification is specified a modern compiler should throw it out; if not there is a chance of overwriting storage
- if reference modification is NOT specified the source should be truncated

2. The two are of equal length - all fine and dandy

3. The target is longer than the source:

- if reference modification is specified the specified number of characters should be moved
- if reference modification is NOT specified the target should be space filled on the right

The question, surely, is what do you want to happen - in particular do you want the receiving field to be space-filled.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
The question, surely, is what do you want to happen - in particular do you want the receiving field to be space-filled.

I agree. Consider this:

01 AN PIX(4)
01 NNI PI 9(10).

MOVE AN(1:4) TO NNI.

Dimandja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top