ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

some %replace stuff

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

  • some %replace stuff

    Example of string manipulation


    This procedure takes a string (address)
    and converts it. This could be used to
    compare free format address lines across
    multiple files.

    for example this: 1722 CANdleWick Dr NW.
    converts to : 1722 Candlewick Drive North West

    (remember its just an example)

    The copybook (used to make it easier to add procedure to programs)

    PHP Code:

          
    FMTADR Format address string as title

         d fmtadr          pr           256
         d Instring                     256    value 


    to compile :
    PHP Code:
    CRTRPGMOD MODULE(JAMIELIB/FMTADRSRCFILE(JAMIELIB/SOURCE
    The procedure FMTADR

    PHP Code:
         H NOMAIN EXPROPTS(*RESDECPOS)

          * 
    PROGRAM fmtadr
          
    PURPOSE Subprocedure to format text string as a address
          
    WRITTEN 
          * 
    AUTHOR  


          * 
    Parameters
          
    *       Instring              Char 256   both

          
    Indicator Usage
          
    *   None

          
    *   The FMTADR_CP copy member should be used by programs that call this subprocedure
          
    *   to obtain the procedure prototype fields.

          /
    copy source,fmtadr_cp

         d AfterString     s            256
         d BeforeString    s            256
         d Count           s              4  0
         d CurrentOne      s              1
         d LastCharacter   s              1
          
    *
         
    d Up              c                   CONST('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
         
    d Lo              c                   CONST('abcdefghijklmnopqrstuvwxyz')
          *

          * 
    Begin Procedure
         P fmtadr          B                   export

          
    Procedure Interface
         
    d fmtadr          pi           256
         d instring                     256    value

          
    /free

              
    //
              //  Upper case the entire string to start process
              //

             
    clear  AfterString;
             
    beforestring = %Xlate(lo:up:Instring);
             
    exsr $FormatAddress;

              
    //
              // Now lower case and only UPPER case the first letter in each group of
              // letters seperated by spaces
              //

             
    beforestring = %Xlate(up:lo:beforestring);

             for 
    count 1 to %len(%trim(beforestring));
              if 
    lastcharacter = *blanks or count 1;
                %
    subst(beforestring:count:1) =
                 %
    xlate(lo:up: %subst(beforestring:count:1));
              endif;
              
    lastcharacter = %subst(beforestring:count:1);
             endfor;

             
    Afterstring Beforestring;

             return 
    AfterString;

            
    //--------------------------------------------------------
            // $FormatAddress - format the address
            //--------------------------------------------------------
                 
    begsr $FormatAddress;


              
    // fix the address replace stuff with other stuff

                  
    if %scan (' S.W. ':beforestring ) > *zeros;

                   
    beforestring  =
                   %
    replace (' SOUTH WEST '            :
                              
    beforestring                    :
                              %
    scan (' S.W. 'beforestring ) :
                              
    6
                                                       
    );
                  endif;

                  if %
    scan ('S.W. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH WEST '            :
                              
    beforestring                    :
                              %
    scan ('S.W. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' SW 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH WEST '            :
                              
    beforestring                    :
                              %
    scan (' SW 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' SW. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH WEST '            :
                              
    beforestring                    :
                              %
    scan (' SW. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' S.E. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH EAST '            :
                               
    beforestring                   :
                               %
    scan (' S.E. 'beforestring ):
                               
    6
                                                       
    );
                  endif;

                  if %
    scan ('S.E. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH EAST '            :
                              
    beforestring                    :
                              %
    scan ('S.E. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' SE 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH EAST '            :
                              
    beforestring                    :
                              %
    scan (' SE 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' SE. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH EAST '            :
                             
    beforestring                     :
                             %
    scan (' SE. 'beforestring )   :
                             
    5
                                                       
    );

                  endif;

                  if %
    scan (' N.W. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH WEST '            :
                              
    beforestring                    :
                              %
    scan (' N.W. 'beforestring ) :
                              
    6
                                                       
    );
                  endif;

                  if %
    scan ('N.W. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH WEST '            :
                              
    beforestring                    :
                              %
    scan ('N.W. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' NW 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH WEST '            :
                              
    beforestring                    :
                              %
    scan (' NW 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' NW. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH WEST '            :
                              
    beforestring                    :
                              %
    scan (' NW. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' N.E. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH EAST '            :
                              
    beforestring                    :
                              %
    scan (' N.E. 'beforestring ) :
                              
    6
                                                       
    );
                  endif;

                  if %
    scan ('N.E. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH EAST '            :
                              
    beforestring                    :
                              %
    scan ('N.E. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' NE 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH EAST '            :
                              
    beforestring                    :
                              %
    scan (' NE 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' NE. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH EAST '            :
                              
    beforestring                    :
                              %
    scan (' NE. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;


              
    //AVE  = Avenue
                  
    if %scan (' AVE 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' AVENUE '                :
                              
    beforestring                    :
                              %
    scan (' AVE 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' AVE. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' AVENUE '                :
                              
    beforestring                    :
                              %
    scan (' AVE. 'beforestring ) :
                              
    6
                                                       
    );
                  endif;

                  if %
    scan (' AV. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' AVENUE '                :
                              
    beforestring                    :
                              %
    scan (' AV. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' AV 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' AVENUE '                :
                             
    beforestring                     :
                             %
    scan (' AV 'beforestring )    :
                             
    4
                                                       
    );
                  endif;

              
    //BLVD = Boulevard
                  
    if %scan (' BLVD. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' BOULEVARD '             :
                              
    beforestring                    :
                              %
    scan (' BLVD. ':beforestring ) :
                              
    7
                                                       
    );
                  endif;

                  if %
    scan (' BLVD 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' BOULEVARD '             :
                              
    beforestring                    :
                              %
    scan (' BLVD ' beforestring ):
                              
    6
                                                       
    );
                  endif;

                  if %
    scan (' BLD 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' BOULEVARD '             :
                              
    beforestring                    :
                              %
    scan (' BLD ' beforestring ) :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' BOULV. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' BOULEVARD '             :
                              
    beforestring                    :
                              %
    scan (' BOULV. ':beforestring ):
                              
    8
                                                       
    );
                  endif;

              
    //CT = Court
                  
    if %scan (' CT 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' DRIVE '                 :
                              
    beforestring                    :
                              %
    scan (' CT ' beforestring )  :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' CT. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' COURT '                        :
                             
    beforestring                     :
                             %
    scan (' CT. ' beforestring )  :
                             
    5
                                                       
    );
                  endif;

              
    //DR  = drive
                  
    if %scan (' DR 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' DRIVE '                 :
                              
    beforestring                    :
                              %
    scan (' DR 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' DR. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' DRIVE '                 :
                             
    beforestring                     :
                             %
    scan (' DR. 'beforestring )   :
                             
    5
                                                       
    );
                  endif;

                  if %
    scan (' DRI 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' DRIVE '                 :
                             
    beforestring                     :
                             %
    scan (' DRI ' beforestring )  :
                             
    5
                                                       
    );
                  endif;


              
    //HWY  = Highway
                  
    if %scan (' HWY 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' HIGHWAY '               :
                              
    beforestring                    :
                              %
    scan (' HWY ' beforestring ) :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' HWY. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' HIGHWAY '               :
                              
    beforestring                    :
                              %
    scan (' HWY. ' beforestring ):
                              
    6
                                                       
    );
                  endif;

              
    //LN  = lane
                  
    if %scan (' LN. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' LANE '                  :
                              
    beforestring                    :
                              %
    scan (' LN. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' LN 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' LANE '                  :
                             
    beforestring                     :
                             %
    scan (' LN 'beforestring )    :
                             
    4
                                                       
    );
                  endif;


              
    //PKY = Parkway
                  
    if %scan (' PKY 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' PARKWAY '               :
                              
    beforestring                    :
                              %
    scan (' PKY 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' PKWAY 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' PARKWAY '               :
                              
    beforestring                    :
                              %
    scan (' PKWAY 'beforestring ):
                              
    7
                                                       
    );
                  endif;

              
    //PL  = Place
                  
    if %scan (' PL 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' PLACE '                 :
                              
    beforestring                    :
                              %
    scan (' PL 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

              
    //RD  = road
                  
    if %scan (' RD. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' ROAD '                  :
                              
    beforestring                    :
                              %
    scan (' RD. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' RD 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' ROAD '                  :
                              
    beforestring                    :
                              %
    scan (' RD 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

              
    //ST  = street
                  
    if %scan (' ST 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' STREET '                :
                              
    beforestring                    :
                              %
    scan (' ST 'beforestring )   :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' ST. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' STREET '                :
                              
    beforestring                    :
                              %
    scan (' ST. 'beforestring )  :
                              
    6
                                                       
    );
                  endif;

                  if %
    scan (' ST, 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' STREET '                :
                              
    beforestring                    :
                              %
    scan (' ST, 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan (' STR. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' STREET '                :
                              
    beforestring                    :
                              %
    scan (' STR. 'beforestring ) :
                              
    6
                                                       
    );
                  endif;

              
    //PO
                  
    if %scan ('PO. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace ('PO '                     :
                             
    beforestring                     :
                             %
    scan ('PO. 'beforestring )    :
                             
    4
                                                       
    );
                  endif;

                  if %
    scan ('P.O. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace ('PO '                     :
                              
    beforestring                    :
                              %
    scan ('P.O. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan ('P. O. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace ('PO '                     :
                              
    beforestring                    :
                              %
    scan ('P. O. 'beforestring ) :
                              
    6
                                                       
    );
                  endif;

                  if %
    scan ('P.O.BOX 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace ('PO BOX '                 :
                              
    beforestring                    :
                              %
    scan('P.O.BOX ':beforestring ) :
                              
    8
                                                        
    );
                  endif;

              
    //company
                  
    if %scan (' CO. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' COMPANY '               :
                              
    beforestring                    :
                              %
    scan (' CO. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

              
    //Department
                  
    if %scan (' DEPT 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' DEPARTMENT '            :
                              
    beforestring                    :
                              %
    scan (' DEPT 'beforestring ) :
                              
    6
                                                       
    );
                  endif;

              
    //Division
                  
    if %scan (' DIV 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' DIVISION '              :
                              
    beforestring                    :
                              %
    scan (' DIV 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

                  if %
    scan ('DIV.'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' DIVISION '              :
                              
    beforestring                    :
                              %
    scan ('DIV.'beforestring )   : 4);
                  endif;

              
    //Building
                  
    if %scan (' BLDG 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' BUILDING '              :
                              
    beforestring                    :
                              %
    scan (' BLDG 'beforestring ) :
                              
    6
                                                        
    );

                  endif;

                  if %
    scan (' E 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' EAST '                  :
                              
    beforestring                    :
                              %
    scan (' E 'beforestring )    :
                              
    3
                                                       
    );

                  endif;

                  if %
    scan (' E. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' EAST '                  :
                             
    beforestring                     :
                             %
    scan (' E. 'beforestring )    :
                             
    4
                                                       
    );
                  endif;

                  if %
    scan (' E.'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' EAST '                  :
                             
    beforestring                     :
                             %
    scan (' E.'beforestring )     :
                             
    3
                                                       
    );
                  endif;

                  if %
    scan (' W 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' WEST '                  :
                              
    beforestring                    :
                              %
    scan (' W 'beforestring )    :
                              
    3
                                                       
    );
                  endif;

                  if %
    scan (' W. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' WEST '                  :
                              
    beforestring                    :
                              %
    scan (' W. 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' W.'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' WEST '                  :
                              
    beforestring                    :
                              %
    scan (' W.'beforestring )    :
                              
    3
                                                       
    );
                  endif;

                  if %
    scan (' S 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH '                 :
                              
    beforestring                    :
                              %
    scan (' S 'beforestring )    :
                              
    3
                                                       
    );
                  endif;

                  if %
    scan (' S. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH '                 :
                              
    beforestring                    :
                              %
    scan (' S. 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' S.'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' SOUTH '                 :
                              
    beforestring                    :
                              %
    scan (' S.'beforestring )    :
                              
    3
                                                       
    );
                  endif;


                  if %
    scan (' N 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH '                 :
                              
    beforestring                    :
                              %
    scan (' N 'beforestring )    :
                              
    3
                                                       
    );
                  endif;

                  if %
    scan (' N. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH '                 :
                              
    beforestring                    :
                              %
    scan (' N. 'beforestring )   :
                              
    4
                                                       
    );
                  endif;

                  if %
    scan (' N.'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH '                 :
                              
    beforestring                    :
                              %
    scan (' N.'beforestring )    :
                              
    3
                                                       
    );
                  endif;

                  if %
    scan (' NO. 'beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' NORTH '                 :
                              
    beforestring                    :
                              %
    scan (' NO. 'beforestring )  :
                              
    5
                                                       
    );
                  endif;

            
    // Remove the "-"
                  
    if %scan (' - '  beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' '                       :
                             
    beforestring                     :
                             %
    scan (' - '  beforestring )   :
                             
    3
                                                       
    );
                  endif;

                  if %
    scan (' -'  beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' '                       :
                             
    beforestring                     :
                             %
    scan (' -'  beforestring )    :
                             
    2
                                                       
    );
                  endif;

                  if %
    scan ('- '  beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' '                       :
                             
    beforestring                     :
                             %
    scan ('- '  beforestring )    :
                             
    2
                                                       
    );
                  endif;

                  if %
    scan ('-'  beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' '                       :
                             
    beforestring                     :
                             %
    scan ('-'  beforestring )     :
                             
    1
                                                       
    );
                  endif;

            
    // Remove the ","
                  
    if %scan (' , '  beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' '                       :
                              
    beforestring                    :
                              %
    scan (' , '  beforestring )  :
                              
    3
                                                       
    );
                  endif;

                  if %
    scan (' ,'  beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' '                       :
                             
    beforestring                     :
                             %
    scan (' ,'  beforestring )    :
                             
    2
                                                       
    );
                  endif;

                  if %
    scan (', '  beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' '                       :
                              
    beforestring                    :
                              %
    scan (', '  beforestring )   :
                              
    2
                                                       
    );
                  endif;

                  if %
    scan (','  beforestring ) > *zeros;
                   
    beforestring  =
                   %
    replace (' '                       :
                             
    beforestring                     :
                             %
    scan (','  beforestring )     :
                             
    1
                                                       
    );
                  endif;

                 
    endsr;

            
    //--------------------------------------------------------


          
    /end-free

         p fmtadr          E 
    The program used to test....

    fmtadrtest

    compile: (fix the libraries)
    PHP Code:
    CRTRPGMOD MODULE(JAMIELIB/FMTADRTESTSRCFILE(JAMIELIB/SOURCE

    (
    then)

    crtpgm jamielib/fmtadrtest module(fmtadrtest fmtadr
    the code
    PHP Code:
         d myfield         s            256

          
    /copy source,FMTADR_CP

          
    * ================================================
          * 
    M A I N   L I N E
          
    * ================================================
          *
         
    c                   eval      myfield '1722 CANdleWick Dr NW.'
         
    c                   eval      myfield  FMTADR(Myfield)
          *
         
    c                   eval      *INLR = *On 
    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

  • #2
    Re: some %replace stuff

    is it possible to build a table with all the cases you wish to represent? aka... a table with 'SW', 'S.W.', ' SW ', etc....

    Then just loop through the possibilities and putting that variable in the scan statement....something like this....

    if %scan (shorhand: beforestring ) > *zeros;
    beforestring =
    %replace (longhand :
    beforestring :
    %scan ('shorthand' : beforestring ) :
    5
    );

    shorthand would be the symbolic reference and longhand would be the full name.

    any thoughts?
    or am i way off?

    I just think it would really clean up the code...you could just add the case to a table instead of totally building a new statement....
    Your future President
    Bryce

    ---------------------------------------------
    http://www.bravobryce.com

    Comment


    • #3
      Re: some %replace stuff

      the spaces before and after would be important here.

      "_" = *blank

      so you would need to know this '_TEST_' is not this 'TEST_' or this '_TEST'

      other than that yes you could.

      so the table would hold the string... its length, # of spaces before , #of spaces after......etc
      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


      • #4
        Re: some %replace stuff

        and the beat goes on


        would you consider that a better way to do it? would it be faster or would it just be cleaner?
        Your future President
        Bryce

        ---------------------------------------------
        http://www.bravobryce.com

        Comment


        • #5
          Re: some %replace stuff

          it would be and easier to modify.....
          now to add a new search you must recreate the program.

          if there were a file it would simply be adding new records.

          but For the example I didnt want to create a table cause
          then you have to create a program to add/modify records.
          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


          • #6
            Re: some %replace stuff

            true, but it would be a program that tintin could write.
            Your future President
            Bryce

            ---------------------------------------------
            http://www.bravobryce.com

            Comment


            • #7
              Re: some %replace stuff

              Jamie:

              Nice program. You might want to change some of this code though.


              Code:
                        //CT = Court 
                            if %scan (' CT ': beforestring ) > *zeros; 
                             beforestring  = 
                             %replace (' DRIVE '                 : 
                                        beforestring                    : 
                                        %scan (' CT ' : beforestring )  : 
                                        4 
                                                                 ); 
                            endif;
              Best of Luck
              GLS
              The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

              Comment


              • #8
                Re: some %replace stuff

                that is why you need to put it in a table. Then you can just look down through it with some kind of query and make sure things make sense
                Your future President
                Bryce

                ---------------------------------------------
                http://www.bravobryce.com

                Comment


                • #9
                  Re: some %replace stuff

                  this might work

                  the table
                  PHP Code:
                  ************ Beginning of data ***************
                               
                  R FMTADRR                        
                                 STRING        50               
                                 TOSTRING      50               
                  *************** End of data ****************** 
                  the new procedure:
                  Code:
                       H NOMAIN EXPROPTS(*RESDECPOS)
                  
                        * PROGRAM - fmtadr
                        * PURPOSE - Subprocedure to format text string as a address
                        * WRITTEN -
                        * AUTHOR  -
                  
                  
                        * Parameters
                        *       Instring              Char 256   both
                  
                        * Indicator Usage
                        *   None
                  
                        *   The FMTADR_CP copy member should be used by programs that call this subprocedure
                        *   to obtain the procedure prototype fields.
                  
                       ffmtadrp   if   e             disk        usropn
                  
                        /copy source,fmtadr_cp
                  
                  
                       d AfterString     s            256    varying
                       d BeforeString    s            256    varying
                       d Count           s              4  0
                       d CurrentOne      s              1
                       d LastCharacter   s              1
                       d workstring      s            256    varying
                       d thereplace      s            256    varying
                       d thesearch       s            256    varying
                        *
                       d Up              c                   CONST('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
                       d Lo              c                   CONST('abcdefghijklmnopqrstuvwxyz')
                        *
                  
                        * Begin Procedure
                       P fmtadr          B                   export
                  
                        * Procedure Interface
                       d fmtadr          pi           256
                       d instring                     256    value
                  
                        /free
                  
                            if not%open(fmtadrp);
                             open fmtadrp;
                            endif;
                  
                            //
                            //  Upper case the entire string to start process
                            //
                  
                           clear  AfterString;
                           beforestring = %Xlate(lo:up:Instring);
                           exsr $FormatAddress;
                  
                            //
                            // Now lower case and only UPPER case the first letter in each group of
                            // letters seperated by spaces
                            //
                  
                           beforestring = %Xlate(up:lo:beforestring);
                  
                           for count = 1 to %len(%trim(beforestring));
                            if lastcharacter = *blanks or count = 1;
                              %subst(beforestring:count:1) =
                               %xlate(lo:up: %subst(beforestring:count:1));
                            endif;
                            lastcharacter = %subst(beforestring:count:1);
                           endfor;
                  
                           Afterstring = Beforestring;
                  
                            if %open(fmtadrp);
                             close fmtadrp;
                            endif;
                  
                           return AfterString;
                  
                          //--------------------------------------------------------
                          // $FormatAddress - format the address
                          //--------------------------------------------------------
                               begsr $FormatAddress;
                  
                  
                            // fix the address replace stuff with other stuff
                                setll *start fmtadrp;
                                read fmtadrp;
                                dow not%eof(fmtadrp);
                  
                                  thesearch  = %trim(%xlate('''':' ': string));
                                  thereplace = ' ' + %trim(%xlate('''':' ': tostring));
                  
                                  if %scan (%trim(thesearch) + ' ' :beforestring)
                                           > *zeros;
                  
                  
                                  // overlay the existing characters with the new ones
                  
                                   beforestring = %trim(
                                   %replace ( %trim(thereplace)                               :
                                              beforestring                                    :
                                              %scan(%trim(thesearch) + ' ' :beforestring)     :
                                                    %len(%trim(thereplace))-3  ) );
                  
                                  endif;
                                 read fmtadrp;
                                enddo;
                  
                  
                               endsr;
                  
                          //--------------------------------------------------------
                  
                  
                        /end-free
                  
                       p fmtadr          E


                  see image for data layout
                  Attached Files
                  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