Search a variable and find for strings in cobol
The string size can varies
Fore.g
I have to set a switch when any of the below string are found in the variable
1)CAT
2)MOUSE
3)ELEPHANT
4)AEROPLANE
Please note that these strings varies with size.
And i want these strings defined in working storage area NOT inside procedure division(Coding standard, sine there might be a later enhancement to add in more strings
Search a variable and find for strings in cobol
Moderators: dbzTHEdinosauer, Moderator Group
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 pm
so, what have you in mind?
do you know how you want to define your working-storage?
do you know what COBOL Statements you are going to employ?
the COBOL manuals (Programming Guide and Reference) are found by the IBM MANUALS link at the top of the page.
Sorry,
we only help,
we don't do it for you.
do you know how you want to define your working-storage?
do you know what COBOL Statements you are going to employ?
the COBOL manuals (Programming Guide and Reference) are found by the IBM MANUALS link at the top of the page.
Sorry,
we only help,
we don't do it for you.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
Okay..
Here is the list of code which i tried..
1) Binary search
2) Linear search
Both search command works only if the string we are searching is of same length.. For e.g. If i have to search CAT and ELEPHANT in a variable, i have to declare a Temporary variable which stores those strings.. 'CAT ' CAT appended with spaces to match string length of elephant..
3) INSPECT command
NSPECT WSANIMAL-NAME
TALLYING NAME-1 FOR ALL 'CAT'
NAME-2 FOR ALL 'ELEPHANT'
This logic needs those strings to be hardcoded inside the procedure division..
But i do want these strings to be declared in working storage area..
Here is the list of code which i tried..
1) Binary search
2) Linear search
Both search command works only if the string we are searching is of same length.. For e.g. If i have to search CAT and ELEPHANT in a variable, i have to declare a Temporary variable which stores those strings.. 'CAT ' CAT appended with spaces to match string length of elephant..
3) INSPECT command
NSPECT WSANIMAL-NAME
TALLYING NAME-1 FOR ALL 'CAT'
NAME-2 FOR ALL 'ELEPHANT'
This logic needs those strings to be hardcoded inside the procedure division..
But i do want these strings to be declared in working storage area..
Keep in mind that COBOL doesn't have strings. . .
You haven't really posted anythng like the requested pseudo-code.
If the lenght of the data to be searched varies, you will need to have a way to specify the length for the current search. You will also need to identify the length of each of the values you want to look for.
One way to do what you want would be to use reference modification to compare the animal values against the "variable". If you have never done something like this, it will probably take a while to get the hang of it.
Basically, you would write code to "parse" the variable looking for the value(s) that would require setting "the switch".
You haven't really posted anythng like the requested pseudo-code.
If the lenght of the data to be searched varies, you will need to have a way to specify the length for the current search. You will also need to identify the length of each of the values you want to look for.
One way to do what you want would be to use reference modification to compare the animal values against the "variable". If you have never done something like this, it will probably take a while to get the hang of it.
Basically, you would write code to "parse" the variable looking for the value(s) that would require setting "the switch".
Have a good one
-
- Active Member
- Posts: 732
- Joined: Thu May 24, 2012 4:07 am
Set the "switch" . . .What do you want to do when you "find" the data?
I'd not fall on my sword for either alternative. . . I suppose i'd go with whatever the shop standards permit and look for someone in the organization who has done somethng similar.
In the "old days" the way we wrote things like this was in Assembler
Have a good one
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page