Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

String Formatting

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Wed Dec 16, 2009 11:03 pm    Post subject: String Formatting
Reply with quote

Hi all,

My requirement is to replace the words when it omes in text string
If the text string has the following, it should be replaced as mentioned.
AVENUE should be AVE
ROAD should be RD
LANE should be LN
DRIVE should be DR
NORTH should be N
SOUTH should be S
1 should be 1st
2 should be 2nd
..like wise lot many rules are there.

Eg: 50 NORTH VALLEY LAKE DRIVE should be => 50 N VALLEY LAKE DR
3415 FEDERAL AVENUE should be => 3415 FEDERAL AVE
1 MISSISSIPPI ROAD should be => 1st MISSISSIPPI RD

I think we can't use INSPECT REPLACING since the source/target char length is dfferent. Or whether I need to load the above values in COBOL internal tables and reference that. Can anybody throw some light in the better approach.

Thanks
Vinu
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Dec 16, 2009 11:15 pm    Post subject:
Reply with quote

Hello,

Quote:
Or whether I need to load the above values in COBOL internal tables and reference that
At least. . .

Suggest you need to break the input string into as many fields as necessary, convert each of these fields to their replavement value (if any), and then re-string the converted values back into a single string. There will probably be several pit-falls along the way. . .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7932
Location: Bellevue, IA

PostPosted: Wed Dec 16, 2009 11:42 pm    Post subject:
Reply with quote

An additional complication: you don't want to change Broadway to Brdway so you're going to need to look for full words, not just the exact phrases you list.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Thu Dec 17, 2009 12:31 am    Post subject: Reply to: String Formatting - Replacing
Reply with quote

Hi,

Yes Robert. I have some set of words which are to be looked upon.

As Dick has suggested, I will try to Unstring the words (the complication is that if I am delimiting by SPACE and unstring it, how will I know the number of variables I should keep or whether I should blindly keep 5 variables), and then do search for those listed words

Thanks
Vinu
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Thu Dec 17, 2009 12:38 am    Post subject: Reply to: String Formatting
Reply with quote

assuming that the address have a <fixed> pattern...

blank out the 5(N) work variables
unstring into the work variables and then

the first variable will hold the number ==> transform accordingly
start checking from the last variable backwards
the first non blank(backwards) variable will hold the <road> denomination ==> transform accordingly
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Dec 17, 2009 12:55 am    Post subject:
Reply with quote

Hello,

If you use the TALLING IN phrase, you can get the number of fields.

Instead, i'd define more than enough fields, set them to spaces before the unstring, UNSTRING, and then process from the last to the first skipping the blank fields (as mentioned by Enrico).

Depending on the actual data, delimiting by a single space may not be sufficient. . . Also, sometimes a 1 (one) might be converted to 1st, but other times it maybe should not (i.e. MAIL STOP 1, or SUITE 1, ETC).
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Thu Dec 17, 2009 2:27 am    Post subject:
Reply with quote

Thanks Dick and Enrico for the suggestion.
One complication I found is the number of bytes to be defined in UNSTRING variables. The source address field contains 35 bytes.

Code:
01  WS-ADDRESS   PIC X(35).
01  WS-ADDR-OUT.
      05 WS-ADDR1     PIC X(10).
      05 WS-ADDR2     PIC X(10).
      05 WS-ADDR3     PIC X(10).
      05 WS-ADDR4     PIC X(10).
      05 WS-ADDR5     PIC X(10).
01  WS-SRCH-ADDR  PIC X(10).

01  WS-TABLE-DESC.
      05 FILLER PIC X(14) VALUE 'STREET    ST  '.
      05 FILLER PIC X(14) VALUE 'ROAD      RD  '.
      05 FILLER PIC X(14) VALUE 'BOULEVARD BLVD'.

01 WS-TRANSFORM-TBL REDEFINES WS-TABLE-DESC.
     05 WS-TRN-ITEM OCCURS 2 TIMES INDEXED BY NUM.
          10 WS-TRAN-SRCE    PIC X(10).
          10 WS-TRAN-DEST    PIC X(4).

Read the file
Unstring WS-ADDRESS DELIMITED BY SPACE INTO
   WS-ADDR1 WS-ADDR2 WS-ADDR3 WS-ADDR4 WS-ADDR5

MOVE WS-ADDR5 to WS-SRCH-ADDR
Perform Searching with table to find matching table entry and move the WS-TRAN-DEST to output field.


Similarly do for WS-ADDR4 WS-ADDR3 WS-ADDR2 WS-ADDR1

The problem here is that WS-ADDR1...5 consitutes 50 bytes and actual movement is for 35 bytes(source) and destination

Also when I am moving WS-TRAN-DEST to output address field and then STRING back all the WS-ADDR1...5 fields, spaces will be populated Eg: For 61 North American Lane , will written as 61 N American LN

I am stuck up here in both this parts.

Thanks
Vinu
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Thu Dec 17, 2009 2:46 am    Post subject: Reply to: String Formatting
Reply with quote

just a few points...

the ws-addr should be 35 bytes each ( to be on the safe side )

rough pseudo code
Code:
unstring ....
transform ws-addr1
if ws-addr5 <not_eq> blanks
  transform ws-addr5
  goto done
if ws-addr4 <not_eq> blanks
  transform ws-addr4
  goto done
transform ws-addr3
done:
rebuild the 35 char thing


I am no cobol expert, You mean that when You string things together
the blanks will be left where they are not needed

if that is so You should use reference modification

with a running index for the destination
restarting from one for each subfield

and stopping when a ws-addr thing is blanks
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Dec 17, 2009 3:37 am    Post subject:
Reply with quote

you can STRING multiple variables and delimit each by space:
Code:

MOVE SPACES TO ACTUAL-ADDR-FIELD
STRING WS-ADDR1 DELIMITED BY SPACE
       ' ' DELIMITED BY SIZE
       WS-ADDR2 DELIMITED BY SPACE
       ' ' DELIMITED BY SIZE
       WS-ADDR3 DELIMITED BY SPACE
       ' ' DELIMITED BY SIZE
       WS-ADDR4 DELIMITED BY SPACE
       ' ' DELIMITED BY SIZE
       WS-ADDR5 DELIMITED BY SPACE
INTO ACTUAL-ADDR-FIELD
END-UNSTRING

in your STRING add the intervening space between the addr1,2,3,4 &5
if WS-ADDR2, 3, 4, or 5 are spaces, no problem.

you may need to use ' ' (two spaces) as a delimiter for both the UNSTRING and the STRING
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 129
Location: India

PostPosted: Thu Dec 17, 2009 9:59 pm    Post subject:
Reply with quote

Thanks everyone. That worked fine.

I have declared all the WS-ADDR1..5 as 35 bytes and have the logic mentioend by Dick to STRING it back delimited by spaces.

Thanks
Vinu
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Which function does the Ampersand (&a... Andi1982 PL/I & Assembler 3 Wed Aug 24, 2016 2:05 pm
No new posts Need a help how to replace a string i... gurunath82 CLIST & REXX 12 Tue Jul 26, 2016 11:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us