Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COBOL to RPG IV conversion 1

Status
Not open for further replies.

Athena32

Programmer
Nov 20, 2003
8
US
I decided to tackle the task of converting a COBOL pgm to RPG IV (Free format). I am trying to break unstrung variable into strung variables. For example: 'Susan E Gantner MD' is being returned as 'Susan E Gantner'. I just want 'Susan'.

Code:
  BegSr UnstringPrvdr;                                             
    len = %LEN(%trimr fullname));                                  
    start = 1;                                                     
    For i = 1 to len;                                              
      If %Subst(Fullname:i:1) = ' ' or %Subst(Fullname:i:1) = '';  
        Firstname = %subst(Fullname:1:i);                          
        start = i + 1;                                             
      Endif;                                                       
    Endfor;                                                        
  EndSr;
 

FirstName = %subst(%trimL(FullName):1:%scan(' ':%trimL(FullName))-1);

 
Thanks Mercury2! I am very new at this and appreciate your help. It work perfect.
 
I don't think I am understanding the substring function. I want to place the first name, middle initial, last name, and designation in a separate bucket. Your code helped me place the first name in a buckets. I tried to use your example to place the middle initial in other bucket.

Code:
 BegSr UnstringPrvdr;
          len = %LEN(%trimr(fullname));
          start = 1;
          For i = 1 to len;
            If %Subst(Fullname:i:1) = ' ' or %Subst(Fullname:i:1) = '';
          Firstname = %subst(%triml(Fullname):1:%scan(' ':%triml(Fullname))-1);
          MInitial= %subst(%triml(Fullname):i:%scan(' ':%triml(fullname))+i);
              start = i + 1;
            Endif;
          Endfor;
        EndSr;

I don't think I can use the starting position of one. I am feeling really dumb.
 
Don't worry Athena32, I gonna help you out as much as I can.
First of all, don't try to retrieve character by character and use again the %subtring function instead else you make the same mistake as in your first post.
Code:
d FullName        s             50a   inz('Susan E Gantner MD')
d String          s                   like(FullName)           
d i               s              5u 0                    
d Name            s             10a   dim(4)             
                                                         
 /free                                                   
                                                         
    String = FullName;    // Workarea                               
                                                         
    For i = 1 to 4;                                      
     Name(i) = %subst( %trimL( String ): 1 :             
                   %scan( ' ' :%trimL( String ) ) - 1 ); 
     Dsply Name(i);                                      
     String = %replace( ' ': %trimL( String ) : 1 :      
             %scan(' ' : %trimL( String ) ) );      // Replace just extracted string by blanks     
    Endfor;  

 /end-free
When i = 1 --> firstname, i = 2 --> middleinitial, i = 3 --> lastname and i = 4 --> designation
Fell free to post again if necessary.
 
So create an array to extract the first name, middle initial, etc? Just making sure I understand.
 
Actually you don't really need an array since you can replace the array by named fields if you want, i.e.
...
For i = 1 to 4;
if i = 1;
FirstName = %subst( %trimL( String ): 1 :
%scan( ' ' :%trimL( String ) ) - 1 );
if i = 2;
MInitial = %subst( %trimL( String ): 1 :
%scan( ' ' :%trimL( String ) ) - 1 );
etc...
String = %replace( ' ': %trimL( String ) : 1 :
%scan(' ' : %trimL( String ) ) );
Endfor;
 
Thank you Mercury2 for all your help. I am close to being done with my first conversion and it has been quite an experience to say the least.[hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top