Loading

Moving Numeric values between variables in Easytrieve

When you want to move a value from one Numeric/Packed/Binary variable to another Numeric/Packed (COMP-3) /Binary (COMP) variable, never use the MOVE verb. Just use the assignment statement using “=” (equal) symbol.

This is because, MOVE will work fine, if the hexadecimally stored values are compatible. (ie, Numeric to Numeric, Packed to Packed, or Binary to Binary). Other cases, you will see unwanted values.

Instead of facing such issues, just use the simple assignment statements.

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
 LIST ON
 FILE INFILE
 WS-NUERIC W 9 N VALUE 5
 WS-BINARY W 4 B
 WS-PACKED W 5 P 0
*
 JOB INPUT NULL
* PRINT 5
 DISPLAY WS-NUMERIC
* ASSIGN IT TO WS-BINARY
 WS-BINARY = WS-NUMERIC
 DISPLAY WS-BINARY
* ASSIGN IT TO WS-PACKED
 WS-PACKED = WS-BINARY
 DISPLAY WS-PACKED
 STOP.
Numeric to Packed, Binary WS-BINARY = WS-NUMERIC

WS-PACKED = WS-NUMERIC

Binary to Numeric, Packed WS-NUMERIC = WS-BINARY

WS-PACKED = WS-BINARY

Packed to Binary, Numeric WS-NUMERIC = WS-PACKED

WS-BINARY = WS-PACKED

If you want to move a value from Packed to Alpha,
first move the packed to a Numeric variable, then move the Numeric variable to an Alpha variable.
i.e,

 WS-NUMERIC = WS-PACKED
 MOVE WS-NUMERIC TO WS-ALPHA

Similarly, if you want to move from Binary to Alpha,

 WS-NUMERIC = WS-BINARY
 MOVE WS-NUMERIC TO WS-ALPHA

Learn more about Easytrieve variable declaration.

Related Posts




blog comments powered by Disqus

There's 2 Comments So Far

  •   pavan
    February 7th, 2012 at 5:34 am

    very helpful…

  •   Karthik
    February 7th, 2012 at 2:58 pm

    Thanks Pavan!

Share your thoughts, leave a comment!