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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling Addresses From Free Text Fields 1

Status
Not open for further replies.

ugaisnumberone

Programmer
Dec 21, 2007
2
US
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
 
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.
 
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.
 
I recommended working backwards primarily due to city
names with imbedded spaces.
 
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
 
I recommended working backwards
You may unstring a reverse buffer.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top