Q
Problem solve Get help with specific problems with your technologies, process and projects.

Searching fields for values

In AS/400, if you need to find database fields that contain a specific value, in ILE RBG the field to use is D1FIND. The trick is that you have to add code to turn all search terms into uppercase, or the program won't recognize the search term if it's in lowercase.

How do I test a field to see if it contains a certain value? For example my field could have the value of 'Truck contains combo loads' or it could contain: 'Combo loads on truck' I need to determine if the word combo is in the text field in order to do certain things in the program.
In ILE RPG, the code would look like this:

C If D1FIND <> *Blank and

C %Scan(%Subst(D1FIND:1:%Len(%TrimR(D1FIND)))

C :%Xlate(L_Case:U_Case:D#SFLN)) = *Zero

C Eval RecFound = *Off

C EndIf

...where the field to be searched is D#SFLN, and may contain both upper and lower case text. The field containing the word to search for is D1FIND, which can only contain upper case text. The code will turn OFF the indicator field RecFound if the search word is NOT found in the field to be searched.

So, if your address line contains 'Combo loads on truck' and your search field contains 'COMBO', this scan will convert the D#SFLN data to all upper case, then conduct the scan, and will find the search term in the string.

This was last published in April 2008

Dig Deeper on iSeries ILE programming

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close