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
 

 

COBOL String Handling for various cases

 
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: 151
Location: India

PostPosted: Fri Nov 20, 2009 10:46 pm    Post subject: COBOL String Handling for various cases
Reply with quote

Hi,

My reqt is as follows:
In the Description field, if the state code or state name comes, change the wordings as RESIDING STATE =<state code>
Eg: If Desc field has values like
RESIDING IN MISSOURI
RESIDING: LOS ANGELES, CA
RESIDING IN NORTH DAKOTA
RESIDING: KANSAS CITY
RESIDENT FLORIDA, FL
RESIDENT OF TAMPA

I need to have the formatted output field as
RESIDING STATE=MO
RESIDING STATE=CA
RESIDING STATE=ND
RESIDING STATE=KS
RESIDING STATE=FL
RESIDENT OF TAMPA (No formatting necessary since State code or state name is not there)

My Logic:
1. With INSPECT, I will find any occurance of 'RESID' and if YES, then extract that value to be formatted.
2. I had COBOL internal table which has State ID and State Name stored
3. UNSTRING Desc field delimitted by ' ,' and then compare the extracted field after ' ,' with COBOL internal table which will handle case (2) and (5).

However I am not sure how to handle Case(3) and Case (4). Because if I am using UNSTRING delimited by 'RESIDING IN', it will do good for NORTH DAKOTA but can't handle KANSAS

Is there any other better approach for this requirement or this is the only way that can be modified?

Appreciate your help
Vinu
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Nov 20, 2009 11:02 pm    Post subject:
Reply with quote

how about changing your delimiter to:

delimited by 'RESIDING IN ' or 'RESIDING: '

delimitted by ' ,' doesnot make a lot of sense, since that literal appears nowhere in you examples.

and this makes no sense:
Quote:

RESIDENT FLORIDA, FL
RESIDENT OF TAMPA

RESIDING STATE=FL
RESIDENT OF TAMPA (No formatting necessary since State code or state name is not there)

based on the rules that you have given us.

also RESIDENT seems to imply different rules.

once you can describe all the rules to us, we may offer better advice.

you have learned one thing from my post, delimited by can have multiples.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 151
Location: India

PostPosted: Fri Nov 20, 2009 11:15 pm    Post subject:
Reply with quote

Thanks Dick for the reply.
Sorry.I mean DELIMITED BY ', ' to handle Case (2) and (5).
The State Code or State Name can come in any way
Eg: RESIDENT OF WA
RESIDING IN WA
RESIDING: WA
RESIDENT OF NEW YORK IN LOC
RESIDING IN LOC# 234 IN NJ

The DELIMITED BY 'RESIDING IN' or 'RESIDING:' will handle some cases.
Thanks for that.

The other way that I thought is like puting INSPECT for all the 50 states in US (around searching for occurance of State ID or State name for each INSPECT and if Count is greater than 0, will hardcode
RESIDING STATE=<corresponding State ID>
So 50 INSPECT will come...sounds bad logic, right.

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8117
Location: East Dubuque, Illinois, USA

PostPosted: Sat Nov 21, 2009 12:01 am    Post subject:
Reply with quote

I would use EVALUATE with reference modification to do something like
Code:
EVALUATE TRUE
WHEN (WS-LINE (01 : 11) = 'RESIDING IN')
     DISPLAY 'CASE 1 ' WS-LINE
WHEN (WS-LINE (01 : 09) = 'RESIDING:')
     DISPLAY 'CASE 2 ' WS-LINE
WHEN (WS-LINE (01 : 11) = 'RESIDENT OF')
     DISPLAY 'CASE 3 ' WS-LINE
WHEN (WS-LINE (01 : 08) = 'RESIDENT')
     DISPLAY 'CASE 4 ' WS-LINE
WHEN OTHER
     DISPLAY 'CASE 0 ' WS-LINE
END-EVALUATE
but I think your real problem will be distinguishing states and cities -- how to tell where Virginia City, NV is, for example.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Sat Nov 21, 2009 12:21 am    Post subject:
Reply with quote

INSPECT is one of those really powerful instructions/commands,
but it comes at a price - performance.

If I was doing this I would start by:
Code:

EVALUATE TRUE
       WHEN DESCRIPTIONFIELD(1:11) = 'RESIDING IN'
                 PERFORM D100-RESIDING-IN-PARSE
       WHEN DESCRIPTIONFIELD(1:11) = 'RESIDENT OF'
                 PERFORM D200-RESIDENT-OF-PARSE
       WHEN DESCRIPTIONFIELD(1:09) = 'RESIDING:'
                 PERFORM D300-RESIDING-COLON-PARSE
       WHEN OTHER
                 PERFORM D400-HAVE-NOT-FIGURED-IT-OUT
END-EVALUATE


generic routines have less code,
but burn up a lot of cycles schlepping thru finding things.

using the evaluate, each performed paragraph knows exactly where things are (position, length) and can parse exactly what you need.
obviously, paragraph D400-HAVE-NOT-FIGURED-IT-OUT is where
you could code your UNSTRINGS, etc..
If enough of your expected input is handled by one of the earlier performs, then D400 handles exceptions.

should improve your thru-put.

if you get caught in a situation where you need to determine
if your 'state' variable is 'translatable', I would use a LEVEL 88,
unless your table is setup for a Binary Search.

reference modification with variables [field(var1:var2)] is slow,
compiler generates code to substitute, convert, etc..
reference modification with literal values [field(1:8)] is fast as lighting,
compiler generates a direct instruction as if you had assigned a field in working-storage.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Sat Nov 21, 2009 12:23 am    Post subject:
Reply with quote

I see I have been 'Samply fast fingered, again.

Robert, I think his input is State, then City. If not, you have, as usual, a very valid point.
Back to top
View user's profile Send private message
vinu78

Active User


Joined: 02 Oct 2008
Posts: 151
Location: India

PostPosted: Sat Nov 21, 2009 12:31 am    Post subject:
Reply with quote

Hi Robert,

If I am able to extract the State ID or State name from the line regardless of where it is occuring, I can compare that with the hardcoded COBOL internal table (having State ID mapped with State name).
If it is matching, I will write RESIDING STATE=<State ID>.

The above example that you have posted tells me whether the line starts with RESIDING IN or RESIDENT: or ... and what you had told is the real problem for me (extracting the State ID or State name).

I am thinking around this
Code:
INSPECT WS-DESC TALLYING Z-COUNT FOR ALL 'NEW YORK' OR 'NY'
IF Z-COUNT > 0
   MOVE 'RESIDING STATE='   TO WS-DESC(1:15)
   MOVE 'NY'                           TO WS-DESC(16:2)
END-IF.

The problem here is that it is NOT a generalized code for all states. If this can be generalized for all states, I dont have to worry about the position of State ID or State name.
Any thoughts?

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
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm


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