View previous topic :: View next topic
|
Author |
Message |
mahausa21
New User
Joined: 14 Aug 2022 Posts: 6 Location: India
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2131 Location: USA
|
|
|
|
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 |
|
|
mahausa21
New User
Joined: 14 Aug 2022 Posts: 6 Location: India
|
|
|
|
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 |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
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 |
|
|
mahausa21
New User
Joined: 14 Aug 2022 Posts: 6 Location: India
|
|
|
|
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 |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Since you are using Db2 in this program , why use cobol logic , it’s pretty easier to use Db2 LOCATE function. |
|
Back to top |
|
|
mahausa21
New User
Joined: 14 Aug 2022 Posts: 6 Location: India
|
|
|
|
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 |
|
|
mahausa21
New User
Joined: 14 Aug 2022 Posts: 6 Location: India
|
|
|
|
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 |
|
|
mahausa21
New User
Joined: 14 Aug 2022 Posts: 6 Location: India
|
|
|
|
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 |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Welcome! |
|
Back to top |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2131 Location: USA
|
|
|
|
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 |
|
|
|