From: Howard Brazee on
I've done a lot of address processing, and find reference modification
and perform loops works best.

Analyze and code, just like other work. But take time to design it
in such a way that you can change it easily and clearly.

--
"In no part of the constitution is more wisdom to be found,
than in the clause which confides the question of war or peace
to the legislature, and not to the executive department."

- James Madison
From: Tony Harding on
On 03/26/10 20:52, Pete Dashwood wrote:
> jmoore wrote:
>> I am not familiar with the funtion reverse command. Does it reverse 2
>> fields or just the field? ie.
>> SANDY = YDNAS. I am looking to change some addresses that come intro
>> the file as 123 Maint St and change them to Main St 123.
>
> If I were you, I wouldn't use function reversed for this.
>
> Consider the following:
>
> 01 address-array.
> 12 address-words occurs<whatever, lets say 5 for this
> example...>
> indexed by aw-x1.
> 15 aword pic x(30) *> adjust this to be whatever your data
> shows as a reaonable size for a street or town name. 30 works for NZ.
>
> ...
>
> unstring input-buffer
> delimited by space
> into
> aword (1)
> aword (2)
> aword (3)
> aword (4)
> aword (5)
> end-unstring
>
> Note that, while this seems pretty useful, it may result in a stochastic or
> sparse array. (There can be blank entries). If the input string had 2 (or
> more) spaces between '123' and 'Main', for example, aword (2) would be blank
> and so would each following aword for the number of spaces encountered in
> the input. (It is usual to avoid this by doing some preparation with removel
> of superfluous spaces from the input buffer before unstringing it.).
>
> Given that God's on your side (or you did some preparation) and the address
> words are separated by single spaces, you will get each word loaded into the
> array.
>
> In your example '123 Main st.', aword ( 1) through aword (3) will be
> "filled" and the rest empty, it isn't too hard to swap the words you want
> swapped...
>
> It is also useful to have a facility that moves everything up one entry (you
> can do this with a perform varying loop, or with a single refmodded
> statement - I prefer the refmodding because it is quicker and more elegant
> but I have met people who don't understand it and find it confusing, so the
> perform loop is a simpler option. Mind you, I have also worked on sites
> where they wouldn't allow perform..varying... because it was "too complex";
> some so-called "computer programmers" should really be doing something
> else...)
>
> Having loaded your words and manipulated them in the address array, you now
> need to put them back
>
> move spaces to out-buffer
> perform
> varying aw-x1
> from 1
> by 1
> until aw-x1> 5 *> if you are sure you have removed
> blank entries through manipulation you could control this by testing for a
> blank entry as being the end...
> if aword (aw-x1) NOT = space
> string
> out-buffer
> delimited by space
> space
> delimited by size
> aword (aw-x1)
> delimited by space
> into out-buffer
> end-string
> end-if
> end-perform
>
> The result in out-buffer will be:
>
> ' Main St. 123'... which isn't EXACTLY what you want... remove the leading
> space with...
>
> move out-buffer (2:<defined length of out-buffer, or function
> length if you have it> - 1) to out buffer
>
> NOW you have 'Main St. 123'
>
> There are pros and cons in everything and things can look strange if you
> haven't seen them before. I like manipulating words rather than characters,
> if I'm dealing with text like address formats. Obviously, not the ONLY way,
> but this is the way I prefer.
>
> If you want to see COBOL being used to process addresses, try this URL:
>
> http://primacomputing.co.nz/PRIMAWebSite/default.aspx ... and click on the
> little postman icon. Try cutting some of the examples and pasting them into
> the pane. These are "free format" addresses; no fixed street, town,
> postcode, or any other fields, separated by any number of spaces, and the
> COBOL engine sorts it all out, using heuristics and some smart programming.
> You will probably realize that the input to this engine is a free format
> buffer containing words that MIGHT constitute a valid NZ address, separated
> by any number of spaces. Guess how it sorts it out? :-)
>
> This is running as a Web Service on my web server in Florida. When you hit
> enter, the message travels from your desktop to Florida, gets parsed and
> analysed, accesses a number of tables on 3 relational databases, results are
> re-assembled for delivery and pushed back to your desktop. The first address
> you try may take a few seconds while things get initialized and buffers get
> loaded, after that... well, see for yourself :-).

Whoa, seeing the COBOL code brought me back to the reality that this is
a COBOL NG. I've been thinking of the challenge as something I'd
approach in REXX; very strong parsing ability, break down by words,
REVERSE function, a STRIP function which allows you to trim leading
and/or trailing blanks (or whatever else you specify), etc. IMHO REXX is
a much better choice of language for a string handling problem like
this. Free on all IBM platforms (from IBM) and available free for
practically any other platform.

If you've had any exposure, might be worth considering. Give me some
more data and I *might* fiddle with it a bit. :)

Good luck on your job.
From: HeyBub on
Pete Dashwood wrote:
> jmoore wrote:
>> I am not familiar with the funtion reverse command. Does it reverse 2
>> fields or just the field? ie.
>> SANDY = YDNAS. I am looking to change some addresses that come intro
>> the file as 123 Maint St and change them to Main St 123.
>
> If I were you, I wouldn't use function reversed for this.
>
> Consider the following:
>
> 01 address-array.
> 12 address-words occurs <whatever, lets say 5 for this
> example...>
> indexed by aw-x1.
> 15 aword pic x(30) *> adjust this to be whatever your
> data shows as a reaonable size for a street or town name. 30 works
> for NZ.
> ...
>
> unstring input-buffer
> delimited by space
> into
> aword (1)
> aword (2)
> aword (3)
> aword (4)
> aword (5)
> end-unstring
>
> Note that, while this seems pretty useful, it may result in a
> stochastic or sparse array. (There can be blank entries). If the
> input string had 2 (or more) spaces between '123' and 'Main', for
> example, aword (2) would be blank and so would each following aword
> for the number of spaces encountered in the input. (It is usual to
> avoid this by doing some preparation with removel of superfluous
> spaces from the input buffer before unstringing it.).

Everybody likes to improve simple code. Here's mine:


Move space to address-array
Perform varying I from 5 by -1 until I = 0
Unstring Input-buffer delimied all space into aword(I)
end-perform
Compute Field-length = Function Length(Address-array)
Call "Squeeze-out-spaces" using Field-length Address-array.

Where "Squeeze-out-spaces" removes leading spaces, converts multiple spaces
to a single space, then space-fills the field.