ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Array processing

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

  • Array processing

    Field Name
    PRIMNAME
    ---------------------
    DANA J TAYLOR
    DANA TAYLOR
    DANA TAYLOR JR


    I have a database that I need to parse out the first name and last name. What is the best way I can do this. I could fill the characters in an array and look for spaces but does anyone have a better suggestion?

    Thanks,

    DAC

  • #2
    Re: Array processing

    Hi dcutaia:

    I've used the "space" parser before. It works ok but beware of names that begin with Mc, Mac, De, Del, Von, Van, etc. Also as you eluded to in your post Jr, Sr, II, III, IV, etc. And I don't know where your list is coming from but Mr, Ms, Mrs, etc are also got-yas.

    An Alternate approach (not that it's any better), extract an ID and Name to excel and try parsing it out there (text to columns with space as the delimiter) See what it looks like then re-load......Just a thought


    Best of Luck
    GLS
    The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

    Comment


    • #3
      Re: Array processing

      i would just use a %scan in a for next loop.....
      something like this just replace the "|" with a blank and edit to your liking.

      Code:
            *                                                                         
           d datalength      s              3  0                                      
           d fnd             s              3  0                                      
           d lastline        s              3  0                                      
           d len             s              3  0                                      
           d mydata          s            256                                         
           d outdata         s             30                                         
           d Reply           s              1                                         
           d str             s              3  0                                      
           d string          c                   CONST(' ABCDEFGHIJKLMNOPQRSTUVWXYZ - 
           d                                            01234567890')                 
            *                                                                         
            * Program Info                                                            
            *                                                                         
            *                                                                         
            /free                                                                     
                 mydata = 'john|Smith|President|Illinois|likes Pizza';                
                 mydata = %trim(mydata) + '|';                                        
                 lastline = %checkr(string : mydata);                                 
                                                        
                 datalength = %len(%trim(mydata));      
                 str = 1;                               
                 fnd = %scan('|' : mydata: str);        
                 dow fnd <> *zeros;                     
                  len = (fnd - str);                    
                  outdata = %subst(mydata:str:len);     
                  dsply outdata ' ';                    
                  str = fnd+1;                          
                  fnd = %scan('|' : mydata: str);       
                 enddo;                                 
                                                        
                   *inlr = *on;                         
            /end-free
      i would also like to make a suggestion that once we help you solve an issue
      that you post the solution back on the site. This will help others as well as
      let the person or persons that helped you feel like a new bride for a few
      minutes.
      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: Array processing

        i did this once a loooong time ago, you may have to play with it some.
        Code:
        Ddata             s             30a                          
        Dlastname         s             30a                          
        Dfirstname        s             30a                          
        Dmiddlename       s             30a                          
        Dlen              s              3s 0                        
        Ddatalen          s              3s 0                        
        Dendpos           s              3s 0                        
        Dstrpos           s              3s 0                        
        C     *Entry        plist                                    
        C                   Parm                    Data             
        C                   Parm                    lastname         
        C                   Parm                    firstname        
        C                   Parm                    middlename       
         /free                                                       
                 if data <> *blanks;                                 
                 strpos=&#37;scan(',':Data);                             
                 LastName=%Subst(Data:1:strpos-1);                          
                 if %subst(Data:strpos+1:1)=*blanks;                        
                   strpos=strpos+1;                                         
                 endif;                                                     
                 endpos=%scan(' ':Data:strpos+1);                           
                 FirstName=%Subst(Data:strpos+1:(endpos-1)-strpos+1);       
                 MiddleName=%trim(%subst(Data:endpos+1:30-(endpos+1)))+' '; 
                 endif;                                                     
                 *INLR=*ON;                                                 
                 Return;     
         /end-free
        I'm not anti-social, I just don't like people -Tommy Holden

        Comment


        • #5
          Re: Array processing

          The field PRIMNAMEi = 'Joe D Dirt'

          Therefore I did a modificaiton to the program to produce this results:
          LastNAME = 'Dirt'
          FirstName = 'Joe'
          Middle Init = 'D'


          Code:
          d*                                            
          d Count           s              3  0 inz(0)  
           *                                                                          
          d datalength      s              3  0                                       
          d fnd             s              3  0                                       
          d lastline        s              3  0                                       
          d len             s              3  0                                       
          d mydata          s            256                                          
          d outdata         s             30                                          
          d Reply           s              1                                          
          d str             s              3  0                                       
          d string          c                   CONST(' ABCDEFGHIJKLMNOPQRSTUVWXYZ -  
          d                                            01234567890')                  
          
                   BegSr SplitName;                                               
                     Count = 1;                                                   
                     mydata = PRIMNAMEi;                                          
                     mydata = &#37;trim(mydata) + ' ';                                
                     lastline = %checkr(string : mydata);                         
                     datalength = %len(%trim(mydata));                            
                     str = 1;                                                     
                     fnd = %scan(' ' : mydata: str);                              
                     dow fnd <> *zeros;                                           
                      len = (fnd - str);                                          
                      outdata = %subst(mydata:str:len);                           
                      If Count > 2 and                          
                         Len = 1;                               
                         Leave;                                 
                      Endif;                                    
                      If Count = 1;                             
                         FirstName = outdata;                   
                      Else;                                     
                      If Count = 2 and                          
                         Len = 1;                               
                         MI = outdata;                          
                      Else;                                     
                      If Count = 2 and                          
                         Len > 1;                               
                         LastName = outdata;                    
                         Leave;                                 
                      Else;                                     
                      If Count = 3 and                          
                         Len > 1;                               
                         LastName = outdata;                    
                         Leave;                                 
                     Else;                                      
                     If Count = 3 and                           
                        Len > 1;                                
                        LastName = outdata;                     
                        Leave;                                  
                     Endif;                                     
                     Endif;                                     
                     Endif;                                     
                     Endif;                                     
                     Count = Count + 1;                         
                     str = fnd+1;                               
                     fnd = %scan(' ' : mydata: str);            
                    enddo;                                      
                 EndSr;
          Last edited by dcutaia; January 17, 2008, 03:31 PM.

          Comment

          Working...
          X