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 -
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.