Moving variable 
Author Message
 Moving variable

Hi,

I want to move an alphanumeric variable X(6) which read
from a seauential file to a non-integer numeric field 9(4)V99.
The alphanumeric variable is checked before moved, but it
doesn't work.

Would you help me to solve this problem? Thanks!

Regards
--
=================================
            Kwok-ho

=================================



Sun, 14 Nov 1999 03:00:00 GMT  
 Moving variable

Hi,

I want to move an alphanumeric variable X(6) which read
from a seauential file to a non-integer numeric field 9(4)V99.
The alphanumeric variable is checked before moved, but it
doesn't work.

Would you help me to solve this problem? Thanks!

Regards
--
=================================
            Kwok-ho

=================================



Sun, 14 Nov 1999 03:00:00 GMT  
 Moving variable

Quote:

>I want to move an alphanumeric variable X(6) which read
>from a seauential file to a non-integer numeric field 9(4)V99.
>The alphanumeric variable is checked before moved, but it
>doesn't work.

In Wang COBOL this would be done with one of their nifty
language extentions...

   MOVE WITH CONVERSION alpha-var TO numeric-var.

In your case you would probably have to do it thru a REDEFINES

     01  alpha-var     PIC X(6).
     01  numeric-var   REDEFINES alpha-var
                       PIC 9(04)V99.

         MOVE alpha-var  TO numeric-var.



Sun, 14 Nov 1999 03:00:00 GMT  
 Moving variable


Quote:

>>I want to move an alphanumeric variable X(6) which read
>>from a seauential file to a non-integer numeric field 9(4)V99.
>>The alphanumeric variable is checked before moved, but it
>>doesn't work.

>In Wang COBOL this would be done with one of their nifty
>language extentions...

>   MOVE WITH CONVERSION alpha-var TO numeric-var.

>In your case you would probably have to do it thru a REDEFINES

>     01  alpha-var     PIC X(6).
>     01  numeric-var   REDEFINES alpha-var
>                       PIC 9(04)V99.

>         MOVE alpha-var  TO numeric-var.

A redefines simply gives to different definitions to the same storage location. In your example the move statement would produce wierd results, the move statement would be moving an integer to a decimal field so that the results would be in effect multiplied by 100. The fact that your sending and receiving fields are the same could possibly result in changing the sending field as the move progressed.

The redefines gives you the ability to access data in either of two formats. If the field coming in from the sequential file contains a decimal point you would have to write a routine to parse the field. If the decimal place simply implied then a redefines is all that is necessary.



Sun, 14 Nov 1999 03:00:00 GMT  
 Moving variable



Quote:
>Hi,

>I want to move an alphanumeric variable X(6) which read
>from a seauential file to a non-integer numeric field 9(4)V99.
>The alphanumeric variable is checked before moved, but it
>doesn't work.

move x(6) to 9(6)
move 9(6) to 9999v99, but beware of overrun.
perhaps move 9(6) to 9(6)v99 and divide by 100?

If there is a decimal point in your x(6) string, it gets more
complicated.

H



Mon, 15 Nov 1999 03:00:00 GMT  
 Moving variable


Quote:

> I want to move an alphanumeric variable X(6) which read
> from a seauential file to a non-integer numeric field 9(4)V99.
> The alphanumeric variable is checked before moved, but it
> doesn't work.

MicroFocus has supported de-editing moves for decades.

      01  Source-Edited          PIC --9.99.
      01  Destination-Numeric    PIC S9(4)V99.

      MOVE Source-Edited  TO Destination-Numeric

You may need to use a $SET DE-EDIT"1" compiler option.



Mon, 15 Nov 1999 03:00:00 GMT  
 Moving variable

Quote:

> Hi,

> I want to move an alphanumeric variable X(6) which read
> from a seauential file to a non-integer numeric field 9(4)V99.
> The alphanumeric variable is checked before moved, but it
> doesn't work.

  01  IN-FIELD  PIC X(6).

  01  OUT-FIELD.
      05  OUT-NUMERIC PIC 9(4)V99.

  MOVE IN-FIELD TO OUT-FIELD.

        This tells the compiler to move the six bytes.  You then refer to
OUT-NUMERIC to treat the result as a numeric field.

Charlie Goodman



Mon, 15 Nov 1999 03:00:00 GMT  
 Moving variable



Quote:
> Hi,

> I want to move an alphanumeric variable X(6) which read
> from a seauential file to a non-integer numeric field 9(4)V99.
> The alphanumeric variable is checked before moved, but it
> doesn't work.

> Would you help me to solve this problem? Thanks!

> Regards
> --
> =================================
>             Kwok-ho

> =================================

Try the following .....

01  ALPHA-SOURCE.  
      05  NUMERIC-SOURCE  PIC 9(4)V99.

01  NUMERIC-TARGET      PIC 9(4)V9(2).

       IF ALPHA-SOURCE IS NUMERIC
           MOVE NUMERIC-SOURCE TO NUMERIC-TARGET
       ELSE
           < something appropriate >
       ENDIF.

Some compilers will attempt to permit the move (IBM for instance) of the
"X" pictured field to the numeric pictured filed.  As long as the source
field is truly numeric, no problem, if not then and error will occur (IBM
)C& for instance).  Redefining the alpha definition as a numeric will
permit the move to work.      



Mon, 15 Nov 1999 03:00:00 GMT  
 Moving variable

Quote:


> > I want to move an alphanumeric variable X(6) which read
> > from a seauential file to a non-integer numeric field 9(4)V99.
> > The alphanumeric variable is checked before moved, but it
> > doesn't work.

> MicroFocus has supported de-editing moves for decades.

>       01  Source-Edited          PIC --9.99.
>       01  Destination-Numeric    PIC S9(4)V99.

>       MOVE Source-Edited  TO Destination-Numeric

> You may need to use a $SET DE-EDIT"1" compiler option.

A de-edited MOVE was made part of the standard in 1985 (maybe not
decades, but at least one decade).  There is no need for any compiler
options and it works on almost every compiler there is.  However, I
don't think his input corresponds quite to what you stated.  Perhaps
he has random decimal points and whatnot in his sender.  Or, it might
be something like PIC -----9.  That is, no decimal.  The safest way is
to use the NUMVAL function (like COMPUTE destination-numeric =
FUNCTION NUMVAL (source-field)).  I did a COMPUTE instead of a MOVE
because of the dumb rule in the standard that you can use a numeric
function only in an arithmetic expression (that rule is gone from the
next standard, whatever number it will be).

--
Don Nelson
COBOL Development, Tandem Computers, Inc.
Member, ANSI X3J4 and ISO/IEC JTC1/SC22 WG4 COBOL Committees

No clever quotes here



Mon, 15 Nov 1999 03:00:00 GMT  
 Moving variable


Quote:

> >       01  Source-Edited          PIC --9.99.
> >       01  Destination-Numeric    PIC S9(4)V99.

> >       MOVE Source-Edited  TO Destination-Numeric

> > You may need to use a $SET DE-EDIT"1" compiler option.

> A de-edited MOVE was made part of the standard in 1985 (maybe not
> decades, but at least one decade).  There is no need for any compiler
> options and it works on almost every compiler there is.  However, I
> don't think his input corresponds quite to what you stated.  Perhaps
> he has random decimal points and whatnot in his sender.  Or, it might
> be something like PIC -----9.  That is, no decimal.  The safest way is

The De-Edit"1" option on MF allows the source field to be processed
regardless of the actual PICTURE.  So it will process and correctly
extract the values:   1.0___  ____9  99.99_  -1____ (_=space) etc

The ANSI85 standard will only de-edit based on the picture so the
'.' must be aligned, the minus must be correctly leading or trailing.

Quote:
> to use the NUMVAL function (like COMPUTE destination-numeric =
> FUNCTION NUMVAL (source-field)).  I did a COMPUTE instead of a MOVE
> because of the dumb rule in the standard that you can use a numeric
> function only in an arithmetic expression (that rule is gone from the
> next standard, whatever number it will be).

Yes, NUMVAL function would be best with a modern compiler.


Mon, 15 Nov 1999 03:00:00 GMT  
 Moving variable

Quote:

> Some compilers will attempt to permit the move (IBM for instance) of the
> "X" pictured field to the numeric pictured filed.  As long as the source
> field is truly numeric, no problem, if not then and error will occur (IBM
> )C& for instance).  Redefining the alpha definition as a numeric will
> permit the move to work.

All compilers allow you to move alphanumeric to an integer numeric.  
The alphanumeric item is treated as an integer.  This is part of the
standard.  Of course the contents must be all numeric - no decimal
point and no sign and such.  What is not allowed in the standard is
moving such an item to a non-integer numeric.  Some do as an extension
and some don't because they conform to the standard.

--
Don Nelson
COBOL Development, Tandem Computers, Inc.
Member, ANSI X3J4 and ISO/IEC JTC1/SC22 WG4 COBOL Committees

No clever quotes here



Tue, 16 Nov 1999 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Moving APL functions and variables

2. Need help moving string field using data variable at runtime

3. I need a variable updated when cursor moves

4. Moving data from registers to variables...

5. how to move a raw address to a pointer variable

6. TIP #44: Move Tk's Private Commands and Variables into ::tk Namespace

7. Q: moving obj with variable as -tag name

8. Move up/Move down buttons

9. Group level move vs sub-group level move.

10. moving icons when mouse moves, virus?

11. Class variables / global variables / Init variables

12. J and variable variables

 

 
Powered by phpBB® Forum Software