IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

[Solved]Need to find a specific STRING


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
mahausa21

New User


Joined: 14 Aug 2022
Posts: 6
Location: India

PostPosted: Sun Aug 14, 2022 4:26 am
Reply with quote

Hello Friends,

Need your help.
Input string Length - 10 character
Host Variable (Retrieved from a table) - Max of 25 Characters (It may be 16, 20 or 25 - we were not sure exactly)

I would like to compare an input string (10 char) with a host variable (20 or 25), if match found (if continues 10 characters matched) then i need to do a specific function. Can you help which is the best option to achieve this goal?

Ex: Input string - 1234567898
HOST variable - 00001234567898000 or 00000123567898 or 000123456789800000000

Note: the characters should match continuously.

Thanks for your help.

Regards,
maha
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2018
Location: USA

PostPosted: Sun Aug 14, 2022 5:53 am
Reply with quote

1) What the "host variable" stands for in this context?
- a COBOL variable? What is "host" in that case?
- a JCL variable? What is COBOL in that case?
- something else?

2) What the "table" stands for in this context?
- DB2 table?
- ISPF table?
- Oracle table?
- Teradata table?
- Excel table?
- Access table?
- An array of multi-field rows in memory?
- something else?
Back to top
View user's profile Send private message
mahausa21

New User


Joined: 14 Aug 2022
Posts: 6
Location: India

PostPosted: Sun Aug 14, 2022 6:13 am
Reply with quote

Am retrieving a field from a DB2 table an comparing with input field
The DB2 is a varianbe length ( It may be 25 or 20 or less than 10) where as input data is a fixed length (10 char).
How can i find a match? What is the best way to compare?
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Sun Aug 14, 2022 8:07 am
Reply with quote

One way to do this

UNSTRING db2 field DELIMITED BY input string INTO …..etc

If input string is not found the INTO fields will be empty.
Back to top
View user's profile Send private message
mahausa21

New User


Joined: 14 Aug 2022
Posts: 6
Location: India

PostPosted: Sun Aug 14, 2022 8:19 am
Reply with quote

Thank You don.leahy.
Let me try this and let everyone know if this works.

UNSTRING DISC-NBR DELIMITED BY WS-DISC-NBR
INTO OUT-DISC-NBR
END-UNSTRING.

IF WS-DISC-NBR = OUT-DISC-NBR
CONTINUR THE PTOCESS
ELSE
DISPLAY 'No match found"
End-if
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Sun Aug 14, 2022 9:12 pm
Reply with quote

Since you are using Db2 in this program , why use cobol logic , it’s pretty easier to use Db2 LOCATE function.
Back to top
View user's profile Send private message
mahausa21

New User


Joined: 14 Aug 2022
Posts: 6
Location: India

PostPosted: Mon Aug 15, 2022 10:31 pm
Reply with quote

don.leahy wrote:
One way to do this

UNSTRING db2 field DELIMITED BY input string INTO …..etc

If input string is not found the INTO fields will be empty.



UNSTRING DB2-DISC-NBR DELIMITED BY INP-DISC-NBR
INTO OUT-DISC-NBR
END-UNSTRING

DB2 DISC NBR - 0000000123456789
INP-DISC-NBR - 0123456789

But am still getting OUT-DISC-NBR as 0000000123456789. It supposed to be 0123456789.

Can you please help on this? thank you
Back to top
View user's profile Send private message
mahausa21

New User


Joined: 14 Aug 2022
Posts: 6
Location: India

PostPosted: Mon Aug 15, 2022 11:56 pm
Reply with quote

Rohit Umarjikar wrote:
Since you are using Db2 in this program , why use cobol logic , it’s pretty easier to use Db2 LOCATE function.


Thank you Rohit, I never used DB2 LOCATE before. Am searching manual to get some good example. If you possible can you please let me know how to use this command for my scenario?
Back to top
View user's profile Send private message
mahausa21

New User


Joined: 14 Aug 2022
Posts: 6
Location: India

PostPosted: Tue Aug 16, 2022 1:35 am
Reply with quote

mahausa21 wrote:
Rohit Umarjikar wrote:
Since you are using Db2 in this program , why use cobol logic , it’s pretty easier to use Db2 LOCATE function.


Thank you Rohit, I never used DB2 LOCATE before. Am searching manual to get some good example. If you possible can you please let me know how to use this command for my scenario?


Hi Rohit,

DB2 LOCATE is working fine. Thank you so much👍
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Tue Aug 16, 2022 9:01 pm
Reply with quote

Welcome!
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Fri Aug 19, 2022 7:29 am
Reply with quote

mahausa21 wrote:
don.leahy wrote:
One way to do this

UNSTRING db2 field DELIMITED BY input string INTO …..etc

If input string is not found the INTO fields will be empty.



UNSTRING DB2-DISC-NBR DELIMITED BY INP-DISC-NBR
INTO OUT-DISC-NBR
END-UNSTRING

DB2 DISC NBR - 0000000123456789
INP-DISC-NBR - 0123456789

But am still getting OUT-DISC-NBR as 0000000123456789. It supposed to be 0123456789.

Can you please help on this? thank you
I am going to do you a favour by NOT giving you the code. Check the syntax diagram of the UNSTRING statement in the Enterprise COBOL reference manual and it will all become clear.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2018
Location: USA

PostPosted: Fri Aug 19, 2022 8:33 pm
Reply with quote

mahausa21 wrote:



Code:
UNSTRING DB2-DISC-NBR  DELIMITED BY INP-DISC-NBR
      INTO OUT-DISC-NBR                       
END-UNSTRING                                 

Code:
DB2 DISC NBR - 0000000123456789
INP-DISC-NBR - 0123456789

But am still getting OUT-DISC-NBR as 0000000123456789. It supposed to be 0123456789.


Please explain: why do you think so?

Did you ever RTFM with examples, like COBOL - Unstring Statement, or one of 100500 other explanations?

Please learn: how to use the Code button at the top of your answering window!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
Search our Forums:

Back to Top