×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Pulling Addresses From Free Text Fields

Pulling Addresses From Free Text Fields

Pulling Addresses From Free Text Fields

(OP)
I have 5 name lines, each pic x(36).  There are no edits on these fields, so there is not a consistent delimiter.  I have to feed city state and zip separately into a piece of software that standardizes addresses.  I can start on name 5 and work backwards looking for a name field not spaces.  At that point, I know I have the city state zip portion of the address.  Now the problem becomes how do you extract that?  Here are some examples of how the data looks.  Keep in mind, some citys have more than one name and in most cases, the state is abbreviated correctly.

city state zip
city  state              zip
city/state/zip
city ,state,zip
city, state             zip
city            state zip

RE: Pulling Addresses From Free Text Fields

You will need to work backwards in the field. As soon as you have any data in a zip work area, then any subsequent space, comma, or slash should trigger movement of characters into the state work area. Again, any space, comma, or slash will trigger movement of characters into a city work area. Then pass each field to a routine to trim leading spaces. At the end, check and see if you have data in each of the three fields. If not, report the record as rejected. Sorry, I dont
have time to code this.

RE: Pulling Addresses From Free Text Fields

I don't quite know your requirements for validation, but UNSTRING and INSPECT will generally get the job done in most problems like that.

CODE

 IDENTIFICATION DIVISION.
 PROGRAM-ID. TEST2.
 ENVIRONMENT DIVISION.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  INPUT-VAR                  PIC X(36).
 01  PROC-VARS.
     05  OUT-CITY                   PIC X(36).
     05  OUT-STATE                  PIC X(36).
     05  OUT-ZIP                    PIC X(36).
   PROCEDURE DIVISION.
     PERFORM UNTIL INPUT-VAR = "QUIT"
       DISPLAY "ENTER VALUE: "
       ACCEPT INPUT-VAR FROM CONSOLE
       MOVE SPACES TO PROC-VARS
       INSPECT INPUT-VAR REPLACING ALL ',' BY SPACES
       INSPECT INPUT-VAR REPLACING ALL '/' BY SPACES
       UNSTRING INPUT-VAR
         DELIMITED BY ALL SPACES
            INTO OUT-CITY OUT-STATE OUT-ZIP
       END-UNSTRING
       DISPLAY " CITY: " OUT-CITY
       DISPLAY "STATE: " OUT-STATE
       DISPLAY "  ZIP: " OUT-ZIP
     END-PERFORM.
     GOBACK.

Add the TALLYING option to unstring if it can be useful for validation purposes.

RE: Pulling Addresses From Free Text Fields

I recommended working backwards primarily due to city
names with imbedded spaces.

RE: Pulling Addresses From Free Text Fields

(OP)
Glen, your solution is perfect if we did not have cities with more than one name...


 CITY: ELM   
STATE: CITY  
  ZIP: NC    

 CITY: WILSON        
STATE: NC            
  ZIP: 27893-9226    

RE: Pulling Addresses From Free Text Fields

Quote:


Glen, your solution is perfect if we did not have cities with more than one name...

Then unstring to 4 parts and check the tallying value for 4 parts and string back the first and second.

CODE

       UNSTRING INPUT-VAR
         DELIMITED BY ALL SPACES
            INTO OUT-TABLE (1) OUT-TABLE (2)
                 OUT-TABLE (3) OUT-TABLE (4)
         TALLYING PART-COUNT
       END-UNSTRING
       IF PART-COUNT = 4
         STRING OUT-TABLE (1) DELIMITED BY SPACES
                SPACE DELIMITED BY SIZE
                OUT-TABLE (2) DELIMITED BY SPACES
           INTO OUT-CITY
         END-STRING
         MOVE OUT-TABLE (3) TO OUT-STATE
         MOVE OUT-TABLE (4) TO OUT-ZIP
       ELSE
         MOVE OUT-TABLE (1) TO OUT-CITY
         MOVE OUT-TABLE (2) TO OUT-STATE
         MOVE OUT-TABLE (3) TO OUT-ZIP
       END-IF

RE: Pulling Addresses From Free Text Fields

Glenn you may have handled the possibility of 2 names in the city but now you have places like Fond du Lac, WI.  Now you have to add code to handle the possibility of 3 names - and maybe there are some with four.

I agree that working backwards is the best approach.  You can assume first string is zip, second is state, and anything remaining is city.  Of course if you have Fond du Lac WI with no zip code, you have a problem.  If you can't rely on always having these three pieces, you'll need some extensive editing to verify the address.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close