Hi,
I am using scan function in rpgle for scan string my problem is that when i scan a string with one space like 'Invalid Customer' then my program not given positive result or no result
Software/Hardware used:
ASKED:
May 2, 2012 11:38 AM
UPDATED:
May 11, 2012 10:41 AM
IF YOU USE SCANF TO READ A STRING U MUST REMEMBER THAT WHEN U PRESS SPACE,TAB, ENTER THE SCANF FUNCTION TERMINATE . TO OVERCOME THIS PROBLEM USE PUTS() FUNCTION.
Can you show us your RPG code
Check out the %scan built-in function. That may take care of the problem.
Without seeing how it is coded, we can’t tell what is going wrong. Please show the instructions. It might also be necessary to see the field definitions for everything referenced in that part of the code.
Generally, an embedded space should not be a problem. But it might be part of the problem if lengths and padding could interfere.
Tom
%scan built-in function is more indicated.
Pay attention to Uppercase and Lowercase too
I use this fairly routinely:
If %scan(%xlate(lo: up: %trim(field_1)): %trim(%xlate(lo: up: field_2))) > *zero;hi i am using scan function like that:
if %scan(%trim(#strng):istrng)<>0 where #strng=ite
now scan function scan in istring if istrng has “item” then result came
like item no exist
but i want it search only “ite“.
Can some one guide me …how to find a exact word or string using “Scan” not a part of some other string.
say if i need 321 it should not give me 3210 nor 1321 it should only give me line containing string 321
scan for ‘ 321 ‘ instead of ’321′
but it given same result like i search ‘ITE’ and it given ITEM also…..
If your search pattern is ‘ite’ – a subset of ‘item’ – it will return a valid result, wanted or no. If you follow BigKat’s suggestion and prepend and append a blank to the search pattern – giving you ‘ ite ‘ – a valid result will occur only if that pattern is found.
but it given same result like i search ‘ITE’ and it given ITEM also…..
That’s what it’s supposed to do. “ITEM” contains “ITE”, so it is a correct result.
ITERATE
CITE
WHITE
ARBITER
All of those contain “ITE”, so the scan functions will find “ITE” in all of them. Further, they can all be at the beginning, at the end or in the middle of a string or might be the entire string. There might be no blanks before or after the word. There might even be special characters instead of blanks:
(ARBITER)
WHITE–
And how about “Item”?
If you want to discard those results, then you need to program around it. There are a number of possible combinations. We have no idea what circumstances you might run into.
Tom
Below i mention my example code here i want search only ‘ITE’ string
DiSTRNG s 50 varying inz
D#strng s 50 inz(‘ITE’)
D#num s 2 0
c
“c eval istrng=’Blank Descriptions,ITEM Invalid’”
c if %scan(%trim(#strng):istrng)<>0
c iSTRNG dsply
c endif
11/3/2007
c* eval #num=%check((istrng):(#strng))
c eval #num=%check(%trim(#strng):%trim(istrng))
c if #num>0
c* if %check(%trim(#strng):%trim(istrng))<>0
c iSTRNG dsply
c endif
c eval *inlr=*on
“c eval istrng=’Blank Descriptions,ITEM Invalid’”
It’s not clear what that statement is supposed to do. The program won’t compile unless the outer quotes are removed.
Then, it’s not clear what your problem is. If the above source line is corrected, the program works.
here i want search only ‘ITE’ string
That is what the program does. In both tests, it scans for ‘ITE’ and finds it both times. The DSPLY executes for both tests.
The program seems to work exactly as you say you want it to work. What is the problem?
Tom
but i dont want which contain only string ‘ITE’
sorry contain only ITE