简体   繁体   中英

Searching entire record for specific string - RPGFREE IBM i Series

I'm trying to correct a specific customer type in our database from a character customer type of "05" to a character customer type of "09". I need to iterate through the database and find a customer name of ex."Gas Station 123" and then change the customer type to a '09' for each record found. The problem I keep having is how to find a partial string in the customer name for each record. Any help would be appreciated.

`

Dcl-F CUSTMST Keyed Usage(*INPUT:*OUTPUT:*UPDATE);

Dcl-S CUSTNM Uns(10);

SETLL 80000 Custmst;

READ CUSTMST;

DoW not %EoF(CUSTMST);
  If CUSTNM = %CHECK('GAS STATION 123':BL2LN1);
    CSTYP = %REPLACE('09':'05');
  ENDIF;
  UPDATE CUSTREC;
  READ CUSTMST;
ENDDO;
Return;

`

I've tried %scan and %check but get "Operands are not compatible with the type of operator." I can assign an uns variable to the function which gets rid of the error but then doesn't find anything. I've looked for any kind of wildcard function that would allow partial string searches but haven't had any success.

The function to search for partial string is %scan

%SCAN(search argument : source string {: start position {: length}})

In your code:

If %scan('GAS STATION 123':BL2LN1) > 0;

Note:Your use of %replace is strange, why don't you assign directly CSTYP = '09'?

With SQL, you even have more options for pattern matching. Make sure that International Components for Unicode is installed, that is a free operating system option, it is option 39. Then you can include regular expressions in your SQL code. This is documented in the DB2 SQL reference manual .

select * 
from custmst
where regexp_like(custnm, 'gas station [0-9]{3}', 1, 'i')

This would grab any customer name that includes 'gas station' followed by a blank and 3 numeric digits. The 'i' is a flag that indicates case insensitive search.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM