field values - IBM AS400

This is a discussion on field values - IBM AS400 ; Hello, I am trying to move a numeric field to a character field in free format and keep the leading zeros. I have tried multiple edit codes and cannot get the leading zero on the field. Any ideas?...

+ Reply to Thread
Results 1 to 5 of 5

Thread: field values

  1. field values

    Hello,

    I am trying to move a numeric field to a character field in free
    format and keep the leading zeros. I have tried multiple edit codes
    and cannot get the leading zero on the field. Any ideas?


  2. Re: field values

    Hi,

    try the following:
    /Free
    MyCharField = %EditC(MyNumField: 'X');
    /End-Free

    Birgitta

    On 5 Sep., 23:49, Alida wrote:
    > Hello,
    >
    > I am trying to move a numeric field to a character field in free
    > format and keep the leading zeros. I have tried multiple edit codes
    > and cannot get the leading zero on the field. Any ideas?




  3. Re: field values

    On Sep 5, 5:49 pm, Alida wrote:
    > Hello,
    >
    > I am trying to move a numeric field to a character field in free
    > format and keep the leading zeros. I have tried multiple edit codes
    > and cannot get the leading zero on the field. Any ideas?


    You can use a zero suppression character in editw to force a specific
    number of leading zeros

    I will use dots to represent spaces because you couldn't count the
    space if I used spaces, so I'll use dots.

    If Num is 4 numeric with value 5

    data = %editw(Num: '0....'); data would equal " 0005"
    data = %editw(Num: '0...'); data would equal " 005"
    data = %editw(Num: '.0..'); data would equal " 05"

    Anyway you can force a specific number of leading zeros by adjusting
    where you put the zero suppession character in the edit word.

    The result can can have leading space where the zero suppression
    character was specified. You may have to use trim_left to remove the
    leading space.

    data = %trimL(%editw(Num: '0....'))


  4. Re: field values

    I am pretty sure the masking rules return a length of four for the
    edit word ('0 ') such that a TrimL should be unnecessary. This is a
    /special case/ whereby the digit zero [stop zero suppression character]
    acts as an uncounted position. The special case is an exception to the
    original rule counting all blanks plus the stop zero suppress character
    as the length required to match the number of digits for the numeric
    field. Now when the first character is a stop zero suppress character
    [there is both zero and asterisk], the number of blanks in the remainder
    of the edit word can match the number of digits for the numeric field;
    rather than one less.

    Regards, Chuck
    --
    All comments provided "as is" with no warranties of any kind
    whatsoever and may not represent positions, strategies, nor views of my
    employer

    eb wrote:
    >
    > You can use a zero suppression character in editw to force a specific
    > number of leading zeros
    >
    > I will use dots to represent spaces because you couldn't count the
    > space if I used spaces, so I'll use dots.
    >
    > If Num is 4 numeric with value 5
    >
    > data = %editw(Num: '0....'); data would equal " 0005"
    > data = %editw(Num: '0...'); data would equal " 005"
    > data = %editw(Num: '.0..'); data would equal " 05"
    >
    > Anyway you can force a specific number of leading zeros by adjusting
    > where you put the zero suppression character in the edit word.
    >
    > The result can can have leading space where the zero suppression
    > character was specified. You may have to use trim_left to remove the
    > leading space.
    >
    > data = %trimL(%editw(Num: '0....'))


  5. Re: field values

    Why fool around with %editw when %editC does it all without worrying
    about how many columns ? Use Birgitta's solution.


+ Reply to Thread