View previous topic :: View next topic
|
Author |
Message |
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
Hi,
I need to Blank out P.O. BOX <num/alphabet> wherever it comes in the Address field.
Eg: P.O. BOX 68 300 S. MAIN ST should be 300 S. MAIN ST
P.O. BOX M, 12 FEDERAL DR should be 12 FEDERAL DR
The logic I have in mind is
Code: |
INSPECT WS-DESC-CHK TALLYING Z-COUNT FOR ALL 'P.O. BOX'
IF Z-COUNT > 0
UNSTRING WS-ADDRESS-POST DELIMITED BY 'P.0. BOX '
INTO WS-ADDR-PART1 WS-ADDR-PART2
UNSTRING WS-ADDR-PART2 DELIMITED BY SPACES
INTO WS-ADDR-PART3 WS-ADDR-PART4
MOVE SPACES TO WS-ADDR-PART3 |
I was trying to do the below mentioned logic but lost in the coding part.
- To find if the address field contains 'P.O. BOX'
- If yes, find the numeral or alphabet attached to P.O. BOX and space it
out.
- Then blank out the P.O. BOX
- Write the remaining charcters to Output address field
Thanks
Vinu |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Will the literal always be first in the string and always spelled as shown? What about PO BOX or P O BOX? |
|
Back to top |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
Hi Dick,
The literal will always be the same - P.O. BOX <any number/alphabet>
Only the number. alphabet following the P.O. BOX differs.
Mostly it comes as first in the string but can come in midway too.
Thanks
Vinu |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Mostly it comes as first in the string but can come in midway too. |
One approach might be to parse the entire field (using reference modification) looking for the literal as a single value 'P.O. BOX'.
If it doesn't exist, the string is ok as is.
If it does exist, change it to '$$$FOUND'. Then do the unstring as you did in the eariler requirement. When re-building the string to remove the po box, skip the field with the $$$FOUND and the field after it (using reference modified MOVEs rather than STRING). |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you already have a table containing
values in text - replacement value
add a new field to your item - special handling.
before = UNSTRUNG TEXT
after = replacement text
special handling=routine to do something
so your table would be:
Code: |
before after spec handling
==== ===== =======
P.O.BOX (contains spaces) space out next UNSTRUNG field
AVENUE AVE NONE
1 1st NONE
|
since you can delimit your STRING with space, you would not have any extra spaces. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
I believe there is a space in the input between P.O. and BOX. . . |
|
Back to top |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
Yes there is a space between P.O. and BOX
Here the concern is that I need to SPACE out P.O. BOX and also the number/alphabet coming along with it. So just spacing out P.O. BOX will leave the number alone in the output address field
For finding the P.O. BOX, I have used
Code: |
INSPECT WS-DESC-CHK TALLYING Z-COUNT FOR ALL 'P.O. BOX'
If Z-COUNT > 0
The string contains P.O. BOX |
Now I need to find the number/alphabet following the P.O. BOX and space out that too.
Thanks
Vinu |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Dick,
you are correct and your solution is probably better for this situation.
Vinu,
Quote: |
Now I need to find the number/alphabet following the P.O. BOX and space out that too. |
well, maaayyyybeee you are on the wrong track.
go back and read Dick's suggestion.
He already provided you with a solution.
If you don't understand what he said, say: please explain in more detail
instead of repeating your request and repeating your flawed logic. |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Your original post indicated both an alphabetic O and the numeral 0. Be careful when coding the abbreviation for Office. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
To repeat with a bit of emphasis:
Quote: |
. . .When re-building the string to remove the po box, skip the field with the $$$FOUND and the field after it . . . |
Whatever is in the "field after" can be skipped - alpha or numberic or both. . . |
|
Back to top |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
Sorry Dick Brenholtz. I am trying to understand Dick Scherrer's logic.
Thanks a lot Dick for providing the logic.
As per my understanding, this is what I need to do
- Find for 'P.O. BOX' occurance in the string and replace it as $$$FOUND
- Unstring the above string having $$$FOUND delimited by spaces
- When rebuilding the string back, skip the field containing $$$FOUND
and the immediate next field.
In the Reference modification to check for 'P.O. BOX', can you please help me how to check for the whole literal 'P.O. BOX'.
I tried searching in this forum but was not able to find it out. Can anyone please give me pointers in that.
Thanks
Vinu |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Vinu,
Pseudo code:
Code: |
Define a numeric "displacement" field (ws-d) in ws.
Move 1 to it.
Loop thru the input string
If input-string(ws-d : 7) = 'p.o. box'
- you need to replace the literal with $$$FOUND (ws-d points there)
and leave this loop.
Increment ws-d.
If ws-d < 28 - continue the loop
otherwise - the literal is not in this string. |
|
|
Back to top |
|
|
Lijo
New User
Joined: 24 Aug 2008 Posts: 41 Location: Cochin
|
|
|
|
Probably Dick's method will be more efficient, but I am just posting another way:
Code: |
INSPECT WS-DESC-CHK REPLACING ALL 'P.O. BOX' BY '$$$FOUND'
UNSTRING WS-DESC-CHK DELIMITED BY SPACES
INTO WS-ADDR-PART1 WS-ADDR-PART2
STRING WS-ADDR-PART1 DELIMITED BY SPACES
' ' DELIMITED BY SIZE
WS-ADDR-PART2 DELIMITED BY SPACES
INTO WS-ADDR-PART4
INSPECT WS-DESC-CHK REPLACING ALL WS-ADDR-PART4 BY SPACES |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Lijo,
Good catch - i should have been using $$$FOUND (rather than the $$FOUND typo i got stuck on - i've hopefully corrected the previous replies)
Will the code you posted handle the P.O. BOX if it is not in the beginning of the string? |
|
Back to top |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
Thanks Dick and Lijo for the pseudo code.
I will try the logics posted by you and will let you know the result.
Dick - Thanks for the reference modification logic.
Lijo - Your code works great when 'P.O. BOX' comes in the starting of the string. Or is there any way to UNSTRING from $$$FOUND word.
Thanks
Vinu |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
$$FOUND starts in position 11 of the text.
UNSTRING text(17:)
into ..... |
|
Back to top |
|
|
Lijo
New User
Joined: 24 Aug 2008 Posts: 41 Location: Cochin
|
|
|
|
Sorry Guys. I didn't consider the occurrence of 'P.O. Box' in the middle of the string in my earlier post. If you've not got a solution yet, you can try this out:
Code: |
INSPECT WS-DESC-CHK TALLYING Z-COUNT FOR CHARACTERS
BEFORE INITIAL 'P.O. BOX' (assuming that P.O. Box will come only once as per your example)
ADD 10 TO Z-COUNT GIVING WS-START (8bytes for P.O. BOX and one space after that as shown in your example, so the next character is likely to be start at 10th position)
SUBTRACT WS-START FROM 28 GIVING WS-LENGTH(assuming total length of the straing as 28)
UNSTRING WS-DESC-CHK(WS-START:WS-LENGTH) DELIMITED BY SPACES
INTO WS-ADDR-PART1 WS-ADDR-PART2
STRING 'P.O. BOX ' DELIMITED BY SIZE
WS-ADDR-PART1 DELIMITED BY SPACES
INTO WS-ADDR-PART4
INSPECT WS-DESC-CHK REPLACING ALL WS-ADDR-PART4 BY SPACES |
First INSPECT is the same thing which Dick showed using loop constraints. May be I am too lazy to follow loop constarints;)... |
|
Back to top |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
Thanks a lot Lijo for the code.
I tried testing this code and found that WS-ADDR-PART4 contains the literal 'P.O. BOX <number/alphabet till spaces> which is exactly that I wanted. However on executing the last line
INSPECT WS-DESC-CHK REPLACING ALL WS-ADDR-PART4 BY SPACES
I have found the following concerns.
- If the WS-DESC-CHK contains 'P.O. BOX <num/alphabet> at the beginning of text, the code is not replacing.
Eg: P.O. BOX 68; 300 S MAIN STREET
- If the WS-DESC-CHK contains 'P.O. BOX <num/alphabet> at the end of text, it is erased and the code works FINE.
Eg: 148 STAUFFER ROAD; P.O. BOX 267
- If the WS-DESC-CHK contains 'P.O. BOX <num/alphabt> as the only string, it is erased and the code works FINE.
Eg: P.O. BOX 460
So for the first case, whether the problem is because of WS-ADDR-PART4 contains spaces at the end.
Please help.
Thanks
Vinu |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
One reason i use "loop constraints" is that at any given point in the execution, i am in control of the process. When a function is invoked, it will run to completion or fail with little opportunity in between.
Another is "scope creep" - the realization that there is more to the requirement than was identified originally (or is discovered later).
From within one loop, another loop might be performed which could modify the operation of the original loop. From within a function, nothing else can happen until the function completes - successful or otherwise. |
|
Back to top |
|
|
Lijo
New User
Joined: 24 Aug 2008 Posts: 41 Location: Cochin
|
|
|
|
Vinu,
Yes. Problem is because of the spaces only. You need to decide up on the size of WS-ADDR-PART4. Especially size of "<number/alphabet till spaces>". You should find out how many bytes can this info occur. (I think this info is needed even if you use any other method to extract 'P.O. Box and <number/alphabet till spaces>'). Then allocate only that much storage and use replace option. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
You need to decide up on the size of WS-ADDR-PART4. Especially size of "<number/alphabet till spaces>". |
I believe not. . .
The code needs to be more flexible. It is not a good idea to dictate to the users what the "real" data will be. We (as developers) need to meet their need. . . We implement the business rules, not define them. . .
imho |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Quote: |
We implement the business rules, not define them. . . |
Depends upon how heavily armed you are, Dick. |
|
Back to top |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
Lijo,
That is the problem. The P.O. BOX can come as following:
P.O. BOX A
P.O. BOX 234
P.O. BOX 11050
P.O. BOX 12
So I need to allocate WS-ADDR-PART4 atleast 20 bytes. We are declaring the WS variable not dynamically, right. So I am confused how we can decide upon the WS variable PIC size based on the data.
Can you please explain in detail. Sorry for that.
Thanks
Vinu |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Can there be more than 1 space between "P.O." and "BOX"? |
|
Back to top |
|
|
vinu78
Active User
Joined: 02 Oct 2008 Posts: 179 Location: India
|
|
|
|
Hi all,
I think the below code did the trick
Before the last line of code posted by Lijo, I have added this line of code to find the data length of P.O. BOX <num/alphabet>
i.e., after getting the P.O. BOX <num/alphabet> in WS-ADDRESS-POST4
Code: |
INITIALIZE K
PERFORM VARYING K FROM 35 BY -1
UNTIL WS-ADDRESS-POST4(K:1) NOT = SPACES
CONTINUE
END-PERFORM
INSPECT WS-DESC-CHK REPLACING ALL
WS-ADDRESS-POST4(1:K) BY SPACES |
I have tested and this works fine.
Thanks Lijo, Dick for your great amount of time and support.
Thanks
Vinu |
|
Back to top |
|
|
|