Midrange News for the IBM i Community


Posted by: John Dowling
Array Processing
has no ratings.
Published: 01 Mar 2013
Revised: 05 Mar 2013 - 4041 days ago
Last viewed on: 28 Mar 2024 (4951 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Array Processing Published by: John Dowling on 01 Mar 2013 view comments(4)

I have a field in a customer master that contains both City and state.  I want to move state to another field.  My thought process is to load the address into an array, read from the last postion untill I find the first no blank field, read one more then I have the state. here is the code

 

D                 ds                                  
D    address                    30    dim(1)          
D      cycyst                   30    overlay(Address)

 

                    x       =  30;                  
               dou  address(x)<> ' ';               
                    x       =  x-1;                 
               enddo;                               
                    x       =  x-1;                 
                                                    
                    field6  =  %subst(Cucyst:x:2);  

 

I am getting a subscript out of range on the second pass (when x=29)

any ideas ?

thanks

 

 

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Array Processing
Posted: 11 years 24 days 23 hours 17 minutes ago

X + 2 = 31, your field is "only" 30.

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Array Processing
Posted: 11 years 24 days 23 hours 8 minutes ago
Edited: Mon, 04 Mar, 2013 at 19:22:32 (4042 days ago)

 Here's a routine I wrote for you that should work fine. NOTE: The JOBLOG function from COZTOOLS is not necessary to make it work--its just there to allow you to see the results in the JOBLOG.

     H BNDDIR('COZTOOLS/RPGFREE') DFTACTGRP(*NO)             
      /include cozTools/qcpysrc,joblog                       
     D addr            s             30A   Inz('Chicago, IL')
     D state           s             30A                     
     D len             s             10I 0                   
     D x               s             10I 0                   
     C                   move      *ON           *INLR       
      /free                                                  
           len = %len(%trimR(addr));                         
           for x = len DOWNTO 1;                             
              if %subst(addr:x:1) = ' ' or                   
                 %subst(addr:x:1) = ',';                     
                 state = %trim(%subst(addr:x) : ', ');       
                 leave;                                      
              endif;                                         
           endfor;                                           
           if (state = '');  // Didn't find the state!       
              joblog('Sorry, no State in %s': addr);         
           else;
              joblog('STATE=%s': state);
           endif;                       
      /end-free                         

 

Posted by: neilrh
Premium member *
Jackson, MI
Comment on: Array Processing
Posted: 11 years 24 days 10 hours 52 minutes ago

Isn't the simplest solution something along the lines of:

EVALR State = %trimr(CityState);

Assuming that the CityState field ALWAYS contains the state as last two characters. Obviously this approach isn't foolproof, if the CityState content cannot be guaranteed.

Posted by: johnd01
Premium member *
Comment on: Array Processing
Posted: 11 years 24 days 8 hours 53 minutes ago

Thanks Bob that worked just great, Neil .... we just don't have states, there are countries, proviences ect

   thank guys