Page 1 of 2

Please help with syntax

PostPosted: Tue Nov 22, 2011 4:49 am
by minhthy76
I'm writing a quick code to examine the address line so that if it starts with C/O or CO, I will move those info into Attention line, The address line should starts with any characters like PO, P.O. or with numeric.

So, I have this following suedo code:

Address line begins with C/O or CO
Search for PO, P.O, or P.O.
----Set subscripts to 1
----Do unitl subscripts is 30 - :x where x = 3, 4,5
----if address (sub:3) = 'PO ' success
----if address (sub:4) = 'P O ' or 'P.O.' success
----if address (sub:5) = 'P.O. ' success
If not found, search for first numeric digit
----if address (sub:1) numeric
Move Address (1:sub - 1) to Attention
Move Address (sub:30) to Address line.

Please help me translate these into COBOL, I'm learning about index and subcribe....Thank you.

Re: Please help with syntax

PostPosted: Tue Nov 22, 2011 5:56 am
by BillyBoyo
I'm a little unclear about what you mean.

Do you have something like:

C/O SOME TEXT P.O. BOX 1731


and you want to remove the C/O SOME TEXT and leave the rest in the address?

If not, can you give some examples of what you start with and how you'd like to see it afterwards?

Re: Please help with syntax

PostPosted: Tue Nov 22, 2011 6:01 am
by minhthy76
Yes, my input can be C/O SOME TEXT PO Box 123
or C/O SOME TEXT 123 Y Street

and I want to take the part of C/O SOME TEXT to move it to Attention line and keep PO Box 123 or 123 Y Street on Street Line.

Re: Please help with syntax

PostPosted: Tue Nov 22, 2011 8:16 pm
by Ronald Burr
What if your input was, e.g.,

C/O MS. POLLY POINDEXTER PO BOX 123?

Re: Please help with syntax

PostPosted: Tue Nov 22, 2011 8:40 pm
by Robert Sample
Having done considerable work with U.S. addresses over the past couple of years, I think you've got -- maybe -- half a specification there. The addresses I deal with are entered by the recipients themselves ( no third-party entry), and I've seen things like
po box
p o box
p  o  box
P o Box
POBOX
P  O  Box
POB
Box
and many other variations. Unless you are sure that your addresses have been standardized already, preferably through a CASS-certified program, you have a real character matching nightmare on your hands.

Re: Please help with syntax

PostPosted: Tue Nov 22, 2011 9:32 pm
by BillyBoyo
As Robert has pointed out, a lot will be to do with the quality of the addresses. You already have CO and C/O. You can probably add to those, in the same way as Robert has shown for the PO.

Your starting point has to be analysing the data. The wildest mistakes you may be able to get corrected, but it will leave you with a number of "valid" combinations.

You might also find C/O on line 1 of the address, or line 2 (in my experience).

I think you first need to see what you have with your data. Your pseudo-code won't change much, just the values being searched for. Implementing the pseudo-code in Cobol is not too tricky.

Now you'll want to know how to analyse the data?

Re: Please help with syntax

PostPosted: Tue Nov 22, 2011 10:32 pm
by minhthy76
Thanks all for input...my data is little stable/standardized since it went thru normalization process before it gets to me.

What I have trouble is translate/implement the above pseudo-code into COBOL, I'm not success with it :-( especially the perform until statement.

Re: Please help with syntax

PostPosted: Tue Nov 22, 2011 10:46 pm
by BillyBoyo
minhthy76 wrote:I'm writing a quick code to examine the address line so that if it starts with C/O or CO, I will move those info into Attention line, The address line should starts with any characters like PO, P.O. or with numeric.

So, I have this following suedo code:

Address line begins with C/O or CO
Search for PO, P.O, or P.O.
----Set subscripts to 1
----Do unitl subscripts is 30 - :x where x = 3, 4,5
----if address (sub:3) = 'PO ' success
----if address (sub:4) = 'P O ' or 'P.O.' success
----if address (sub:5) = 'P.O. ' success
If not found, search for first numeric digit
----if address (sub:1) numeric
Move Address (1:sub - 1) to Attention
Move Address (sub:30) to Address line.

Please help me translate these into COBOL, I'm learning about index and subcribe....Thank you.


OK then. If you look in the manuals you'll find PERFORM with VARYING. Combined with TEST BEFORE (default if not specified) and TEST AFTER you can have a DO UNTIL or a DO WHILE.

Also look up "REFERENCE MODIFICATION". You may already know this, or it may be coincidence that your code above is pretty close to that usage.

You have a little note to watch out for the different lenths of comparisons, so you have to remember to code for that.

Your VARYING can be an index or a subscript. Your site standards may dictate which you choose. Subscripts are considered more straightforward, indexes are not a big problem so you could tackle it that way as well.

You need one performing loop (for me a paragraph or section is preferable, but you can do it "inline") which works for the length of the line. "Protect" your tests by only doing them if your have not already run out of space (line-current-position + test length of data <= length of line).

Your pseudo-code is quite close to how you can do it in Cobol. Give it a bash, and come back if you get stuck. Let us know how it goes anyway.

Re: Please help with syntax

PostPosted: Tue Nov 22, 2011 11:30 pm
by minhthy76
Thanks, I'm working on it right now.

Re: Please help with syntax

PostPosted: Wed Nov 23, 2011 12:08 pm
by dick scherrer
Good luck - someone is most often "here" 8-)

d