ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Array processing

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

  • Array processing

    Array = 6210056-0014-ZZZZ

    In my Array the two fields are separated by the character.

    I am trying to separate both fields in my RPG program and when I review the character it doesn't allow me to separate them. Does anyone know what I check for that

    Right now the code is set up like this but it doesn't seem to work.
    Code:
    C     GET$$         BEGSR                              
    C*                                                     
    C                   MOVE      *BLANKS       OFF1       
    C                   MOVE      *BLANKS       D14A       
    C                   Z-ADD     01            X          
    C                   Z-ADD     01            Y          
    C                   DO        200                      
    C     W14(X)        Ifne      ''                      
    C                   MOVE      W14(X)        D14A(Y)    
    C                   Add       1             Y          
    C                   Add       1             X          
    C                   ELSE                               
    C                   leave
    C                   end
    Any suggestions?

    Thanks,

    DAC

  • #2
    Re: Array processing

    separated by what character? at should the end result look like? and why use 2 fields for positioning to a specific array element when they will always contain the same value? for the sake of sanity...don't use generic END...use ENDIF, ENDDO, etc. eval works for move and z-add as well...

    you also don't have to z-add 01 you can just z-add 1...
    cleaned up a bit
    Code:
    C     GET$$         BEGSR                          
    C*                                                 
    C                   MOVE      ' '           OFF1   
    C                   MOVE      ' '           D14A   
    C                   Z-ADD     1             X      
    C                   DO        200                  
    C     W14(X)        Ifne      ''                   
    C                   MOVE      W14(X)        D14A(x)
    C                   Add       1             X      
    C                   ELSE                           
    C                   leave                          
    C                   endif
    all your code will do is move all NON-BLANK characters into the 2nd array...which is what you had going into this loop...

    same thing with some minor changes
    Code:
    C     GET$$         BEGSR                        
    C*                                               
    c                   eval      Off1 = ' '         
    c                   eval      D14A = ' '         
    c                   eval      x = 1              
    C                   DO        200                
    C     W14(X)        Ifne      ''                 
    c                   eval      D14A(x) = W14(x)   
    c                   eval      x += 1             
    c*  same as eval x = x + 1                       
    C                   ELSE                         
    C                   leave                        
    C                   endif                        
    C                   enddo                        
    C                   endsr
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Re: Array processing

      Based upon your code snippet, the only way you drop out of the do loop is when you find a blank character in your field. In your example, the first blank character comes after the 4 Z's. So your field would likely look exactly like your array.

      Another coding tip is to not use the DO opcode, since it is not supported in free format. Use a DOW X is less than or equal to 200. ( or even better, get rid of the 200 and replace it with %elem( W14 )

      In free format, it would look like this:

      Code:
      dow x <= %elem( W14 );
      Michael Catalani
      IS Director, eCommerce & Web Development
      Acceptance Insurance Corporation
      www.AcceptanceInsurance.com
      www.ProvatoSys.com

      Comment


      • #4
        Re: Array processing

        or
        Code:
        for x = 1 to %elem(W14);
        for loops rulz
        I'm not anti-social, I just don't like people -Tommy Holden

        Comment


        • #5
          Re: Array processing

          The for loop would work, but I was also going to add more to the do loop to get rid of his leave op code, which I left out:

          Code:
          dow x <= %elem( W14 )  AND W14( x ) <> '' ;
          That would get rid of the if and leave section in the loop.
          Michael Catalani
          IS Director, eCommerce & Web Development
          Acceptance Insurance Corporation
          www.AcceptanceInsurance.com
          www.ProvatoSys.com

          Comment


          • #6
            Re: Array processing

            example using %SUBARR (V5R3 +)
            Code:
                  /FREE
                   X = %LOOKUP(' ':D14);
                   IF X > 0;
                     %SUBARR(D14:1:X) = %SUBARR(W14:1:X);
                   ENDIF;
                   // or if you need to track the start position.
                   START = X+1;
                   IF START <= %ELEM(W14);
                     X = %LOOKUP(' ':W14:START);
                     IF X > 0;
                       %SUBARR(D14:1 :(X-START+1)) = %SUBARR(W14:START:(X-START+1) );
                     ENDIF;
                   ENDIF;   
                  /END-FREE

            Comment

            Working...
            X