ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Moving

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Moving

    Hi, The following is my program:
    PHP Code:
    D A S 10S 0 INZ(-6)
    D B S 10S 0 INZ(3)
    D C S 10S 0
    D D S 10A
    EVAL 100 * (A/B)
    C C DSPLY
    C MOVE C D
    C D DSPLY
    C SETON LR 
    In this above program the calculated value for C = -200,But when am moving this value to character field D, the value 000000020} is getting assigned. I need the value 0000000200 to be get assigned.
    Can you please help me.
    Thank you.
    Last edited by jamief; August 19, 2019, 01:57 PM.

  • #2
    Re: Moving

    It looks like the negative sign is getting encoded into te character field. If you do not need to represent the number as negative. just test it and make it positive.
    Goodbye

    Comment


    • #3
      Re: Moving

      Originally posted by vinod kumar View Post
      Hi, The following is my program:

      D A S 10S 0 INZ(-6)
      D B S 10S 0 INZ(3)
      D C S 10S 0
      D D S 10A
      C EVAL C = 100 * (A/B)
      C C DSPLY
      C MOVE C D
      C D DSPLY
      C SETON LR

      In this above program the calculated value for C = -200,But when am moving this value to character field D, the value 000000020} is getting assigned. I need the value 0000000200 to be get assigned.
      Can you please help me.
      Thank you.
      A negative number contains characters in the low order to denite a negative number. You are displaying it without edtting it on the screen.

      change the move line:
      eval d = %Editc(C : 'L')
      now when it displays you will see 200-
      obviusly you don't care about nagtive numbers (but your bank does)
      eval d = %editc(C : 'X')
      you will then see 0000000200
      or make it a positve number then display it
      eval c = c *-1

      then display d
      Million ways to get their
      Bill
      Bill
      "A good friend will bail you out of jail,
      A true friend would be sitting beside you saying,
      'Wow, that was fun.'"

      Comment


      • #4
        Re: Moving

        or, use eval d = %editc(C : 'Z') and any negative sign gets ignored. If you don't like the blanks that the edit code leaves, go one step further
        eval d = %trim(%editc(C : 'Z'))

        Comment


        • #5
          A dated thread, but for anyone else encountering this (as I am, 13 years later): You need to test for negativity. In free-format:
          Code:
          C = 100 * (A/B); 
          IF C >= *ZERO;
            D = %CHAR(C);         // or D =       %EDITC(  C:'X');
          ELSE;
            D = '-' + %CHAR(- C); // or D = '-' + %EDITC(- C:'X');
          ENDIF;
          %EDITC(C:'X') returns a string of the same length as C, if you don't want the potentially-left-truncated result of %CHAR.

          Comment


          • #6
            This would work also -- added indicator to tell you if negative if required down the code:

            PHP Code:
            d Answer          s             10s 0                                    
            d Character10     s             10                                       
            d Negative        s               n   inz
            ('0')                           
            d Number1         s              6s 0 inz(-6)                            
            d Number2         s              6s 0 inz(3)                             

                   *
            inlr = *on;                                                      

                   
            Answer = (100 * (Number1/Number2));                               
                   if 
            Answer <> %abs(Answer);                                        
                    
            Negative = *on;                                                  
                   endif;                                                            
                   
            Character10 = %editc(%abs(Answer):'X'); 

            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment

            Working...
            X