How to get a Lastname from a field that contains the Full Name? (RPG-ILE)

5 pts.
AS/400 development
AS/400 Query
Hi Guys, I need your suggestions.... I have to extract data from our AS400 box and convert it into text file. For a client's name we have 3 particular fields. 1. FirstName, 2. LastName and 3. FullName. The problem is there are records where First Name and LastName fields are empty. Thats why I have to look on the 3rd Field which is the Full Name, but the data on this field are not on same format. Here are the particular formats: ROD Y. JACKSON (there are names that have middle initial on it) MARK LESTER JOHNSON (there are names that have two names before the lastname) JUAN DELA CRUZ (there are two-string last names) RUDY ATKINS JR. (there are names that have JR. II, III, etc, on the last part of the string) ABC Company Inc. (There are names that had been named under a company) What would be tha best approach for these scenarios? Im using an RPG-ILE language Thanks in advance....

Answer Wiki

Thanks. We'll let you know when a new response is added.


This is probably going to get tricky whatever you do and is likely to need some manual intervention.

First take a backup copy of your file – always good practice.

I would suggest that you get something to pick out the last name only to start with by locating the last string in the field – you can ignore certain strings like JR and look for the string that precedes them. Use the string you found as the lastname field and remove this string from the fullname field.

You should now have a last name filled for all your records. Now you can create a list of records which still contain more than one string in the fullname field. These records will probably need manual intervention as it’s almost impossible to code for whether the person has two first names or two last names. The company names will most likely appear on the list as well.

I know this isn’t marvellous, but in this situation you can only code for so many combinations.


Martin Gilbert.

Discuss This Question: 2  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • philpl1jb
    Niel How many are in error?As Martin said this will be tricky and you'll never get it 100% right programmatically. It might be quicker to create an interactive RPG program and have a clerk fill in the missing fields. Phil
    54,090 pointsBadges:
  • Brenger
    If I were doing it, I would move it into an array. Set up a file of suffixes (jr sr, etc). start from the end, count backwards to the first blank. Check to see if that is a suffix. If not, move it into last name. Start from the first and count forward to first blank for the first name. etc, etc set up an error print or file of ones that are undeterminable. etc, etc hopefully, your file is not too big.
    170 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: