ER problem: find string in string

hharald

Member
Hello List,

writing some ER for a report i have the following problem:
I need to find a string in another string.

Example:

i need to find 'cpg' in 'bkhbhjabdsf cpg jasbdhasd'

i even don't need the position, only if the string is included...

Looking in the KG i found nothing, BSFN B96701 is not working as expected.
Has anyone a idea how to do it?
Any help would be appreciated!

Thank you,
hharald
 
hharald,

B96701 is a LOCAL execution only BSFN...are you running it on the server? Reference the following SARs for more information: 5418119, 5296550, and 4944525.

For server use, you'd need to write your own BSFN...probably not preferred.

ER manipulation could work by truncating your original string one position to the left (within a loop), and retest for the desired value in positions 1 + n. If your string search argument is variable in length, you could use multiple custom sections based on a pre-determined argument test in the mainline, which would call the appropriate custom section.

Hope this helps...good luck.

Regards, SDW
 
I created a BSFN for finding string position in string. (I could not find any thing in JDE)
I am attaching .C, .H and data structure document. With the help of attached docs you should be able to create a "C" BSFN your self.

I hope this might help !!!!!!!!
 

Attachments

  • 53155-FindStr.zip
    78.9 KB · Views: 149
Thank you for the C-File!! I think i will give it a try the next days...

Kind Regards,

hharald
 
This can be accomplished by NER, no need for C++.
1-Get length of string.
loop to end of substring.
begin
substring one charater at a time
if first charcter found raise flag yes or count 1
substring next charcter , if second char found flag yes or count 2
..... etc to third.
if seond not found, restart counters or flags.
end loop

Good luck.
 
This can be one in statement using C. No need for C++. Command is strstr
Late
 
Re: ER problem: find string in string (Here is the NER Solution)

By the way (i have found my own message while i was searching for somethin else....)

Here is the solution i programmed back then (it's not optimized and for sure i have not build something very impressive or new, but it works):



This example searches for the upper-case 'CPG' in a given String and sets a flag if it is found (i had to use two flags, with only one it was not working....):


// ##############################################################
//
// START: Check if 'CPG' is included in the RV ChemicalName
//
//
// ##############################################################
// Make sure everything is in a defined state!
//
VA rpt_testFLAG1_DMFL = "0"
VA rpt_testFLAG2_DMFL = "0"
VA evt_Counter_MATH01 = 0
VA evt_ChemicalNameCopy_AASC = upper([RV ChemicalName])
VA evt_ChemicalNameLenght_Math01 = length([VA evt_ChemicalNameCopy_AASC])-2
//
//
While VA rpt_testFLAG2_DMFL is not equal to "1"
//
//
VA evt_testSTRING1_A301 = substr([VA evt_ChemicalNameCopy_AASC],[VA evt_Counter_MATH01],3)
//
If VA evt_testSTRING1_A301 is equal to "CPG"
VA rpt_testFLAG1_DMFL = "1"
VA rpt_testFLAG2_DMFL = "1"
End If
//
If VA evt_Counter_MATH01 is greater than VA evt_ChemicalNameLenght_Math01
VA rpt_testFLAG2_DMFL = "1"
End If
//
VA evt_Counter_MATH01 = [VA evt_Counter_MATH01]+1
//
End While
//
If VA rpt_testFLAG1_DMFL is equal to "1"
*********************i.E.: DO SOMETHING
Else
*********************i.E.: GO HOME
End If

Cheers, happy X-Mas and wonderful New-Years partys to you all,
HHarald
 
This solution is not correct ...
If the words will be in the diferents positions in the string the logic tell to us wich the strinf are find

Ex.:
I´m looking for string "CFG" in the string "XXXC XXF XXXG"
For your logic the string "CFG" will be in the string "XXXC XXF XXXG" but only the same words in the diferent positions was be presents.
 
I created a BSFN for finding string position in string. (I could not find any thing in JDE)
I am attaching .C, .H and data structure document. With the help of attached docs you should be able to create a "C" BSFN your self.

I hope this might help !!!!!!!!
jastips,

thanks so much for sharing this, it really helped me today.
I have further modified this to use MOTEXT of 30000 character length for my requirement by replacing the existing QUPATH in Datastructure and also replacing strstr api unicode api jdeStrstr api.

- Pranoy
 
Pranoy, there are several business functions that run on both client and server that can do this. One good example is B952334 "Find a String in a String", which can search a string up to 32000 characters in size. I hope you didn't bother to write your own function - that would be a risk of relying on old solutions found in an 18 year old thread!
 
Pranoy, there are several business functions that run on both client and server that can do this. One good example is B952334 "Find a String in a String", which can search a string up to 32000 characters in size. I hope you didn't bother to write your own function - that would be a risk of relying on old solutions found in an 18 year old thread!

Hi Kim,

I dont think it gives out the position of string, correct me if I'm wrong. Is there any std BSFN which gives out the position? I didnt find yet? but the code shared above works.

1635258644534.png

Currently I'm using B7900007 to replace the string with string.

1635258460286.png

Thanks,
Pranoy
 
Last edited:
Hi Pranoy

What exactly are you trying to do? Parse, replace, substring the text? There are lots out there (all on F9862 and ObjectBrowser to test to check) to do various things in isolation or alone.

Example: If the text is separated at all, you can use Parse String B98220D to split it up. In you case it looks like ' '

Do Section =-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Split out OBNM VERS etc
// Get OBJ VERS and extension from F986110.FUNDFU2
// FNDFUF2 is stored as a string made up of "OBJ_VERS_JOBNBR_PDF"
// =-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
//
BC Foundation - Future Use 2 (F986110.0) [FNDFUF2] = rtrim([BC Foundation - Future Use 2 (F986110.0) [FNDFUF2]], <Blank>)

ParseString(B98220D.ParseString)
BC Foundation - Future Use 2 (F986110.0) [FNDFUF2] -> szInputObjectID [OMWOBJID]
VA rpt_NameObjectOBNM [OBNM] <- szOutputObjectSegment [OMWOBJID]
"0" -> mnSegmentNumber [MATH01]
"_" -> cDelimiter [EV01]

ParseString(B98220D.ParseString)
BC Foundation - Future Use 2 (F986110.0) [FNDFUF2] -> szInputObjectID [OMWOBJID]
VA rpt_VersionVERS [VERS] <- szOutputObjectSegment [OMWOBJID]
"1.00" -> mnSegmentNumber [MATH01]
"_" -> cDelimiter [EV01]

ParseString(B98220D.ParseString)
BC Foundation - Future Use 2 (F986110.0) [FNDFUF2] -> szInputObjectID [OMWOBJID]
VA rpt_DocumentExtensionDCEX [DCEX] <- szOutputObjectSegment [OMWOBJID]
"3.00" -> mnSegmentNumber [MATH01]
"_" -> cDelimiter [EV01]


If you just want to know it's in the text at all, B952334 is perfect. Same if you just want to replace.

If you need to know the starting position of the text you are looking for, first check it's there using one of the above, then chop one off the start of the text and loop substringing out the length you're looking for
When you hit a match, there's your position

Looking for Egg in fishEggfish would be
Yes I found Egg
Now check fis = Egg (starting pos 0)
No so try ish = Egg (starting pos 1)
No so try shE = Egg (starting pos 2)
No so try hEg = Egg (starting pos 3)
No so try Egg = Egg Boom! There's your answer (starting pos 4)
 
Last edited:
Hi,

I have a requirement to parse the Processing option input = MH,OV,IV,IR (e.g Document Types )

Created NER

I have used Parse Delimited string

VA evt_mnMATH01 = '0'

PO DocTypes -> szInputObjectID [OMWOBJID]
VA evt_szDocType <- szOutputObjectSegment [OMWOBJID]
VA evt_mnMATH01 -> mnSegmentNumber [MATH01]
"," -> cDelimiter [EV01]

While VA evt_szDocType is not Blank or NULL

--> Do Logic with the VA evt_szDocType

VA evt_mnMATH01 = VA evt_mnMATH01+1
Parse Delimited string (as same as above)
End While

but this logic works as expected for first 4 times with the 4 values (MH,OV,IV,IR), but on the Fourth iteration still the value is getting as VA evt_szDocType = IR & it continues for all 5,6,7 & infinty having the last value

Could you please help resolve this?
 
Last edited:
Hi,

I have a requirement to parse the Processing option input = MH,OV,IV,IR (e.g Document Types )

Created NER

I have used Parse Delimited string

VA evt_mnMATH01 = '0'

PO DocTypes -> szInputObjectID [OMWOBJID]
VA evt_szDocType <- szOutputObjectSegment [OMWOBJID]
VA evt_mnMATH01 -> mnSegmentNumber [MATH01]
"," -> cDelimiter [EV01]

While VA evt_szDocType is not Blank or NULL

--> Do Logic with the VA evt_szDocType

VA evt_mnMATH01 = VA evt_mnMATH01+1
Parse Delimited string (as same as above)
End While

but this logic works as expected for first 4 times with the 4 values (MH,OV,IV,IR), but on the Fourth iteration still the value is getting as VA evt_szDocType = IR & it continues for all 5,6,7 & infinty having the last value

Could you please help resolve this?
That is pretty annoying, it seems that the BF uses the last found value no matter which position you're asking for. 2 ways to handle this I can think of:

1) If there's no problem with reprocessing the final value in the list a few times, I'd just add some hard stops for the while loop so that you won't ever go infinite. You should probably do this anyway.

Choose a # that is your max # of values (let's say 25) and add an AND statement to your while loop.
AND evt_mnMATH01 Less Than 25

2) Add a new variable let's say VA evt_szPrevDocType. It should be blank for your initial Parse Delimited String call. This is bad if there's a chance that your delimited list might have duplicates.

Before the Parse Delimited String call within your while loop, set VA evt_szPrevDocType to the value of VA evt_szDocType
Finally add an AND to your while loop saying AND VA evt_szPrevDocType NOT EQUAL VA evt_szDocType
 
B0500690 is String in Sting
Moderator, delete this message. Tnx
 
Last edited:
Back
Top