Scan a string

1355 pts.
Tags:
AS400 RPGLE
RPGLE Program
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

Answer Wiki

Thanks. We'll let you know when a new response is added.

Below i mention my example code here i want search only ‘ITE’ string

<pre>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</pre>

Discuss This Question: 16  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • HIMANGSHU
    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.
    10 pointsBadges:
    report
  • CharlieBrowne
    Can you show us your RPG code
    41,380 pointsBadges:
    report
  • WoodEngineer
    Check out the %scan built-in function. That may take care of the problem.
    6,725 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • nuccio
    %scan built-in function is more indicated. Pay attention to Uppercase and Lowercase too
    290 pointsBadges:
    report
  • Splat
    I use this fairly routinely:
    If %scan(%xlate(lo: up: %trim(field_1)):          
             %trim(%xlate(lo: up: field_2))) > *zero;
    7,455 pointsBadges:
    report
  • 9783444184
    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".
    1,355 pointsBadges:
    report
  • 9783444184
    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
    1,355 pointsBadges:
    report
  • BigKat
    scan for ' 321 ' instead of '321'
    8,330 pointsBadges:
    report
  • 9783444184
    but it given same result like i search 'ITE' and it given ITEM also.....
    1,355 pointsBadges:
    report
  • Splat
    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.
    7,455 pointsBadges:
    report
  • TomLiotta
    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
    125,585 pointsBadges:
    report
  • 9783444184
    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
    1,355 pointsBadges:
    report
  • TomLiotta
    “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
    125,585 pointsBadges:
    report
  • 9783444184
    but i dont want which contain only string 'ITE'
    1,355 pointsBadges:
    report
  • 9783444184
    sorry contain only ITE
    1,355 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following