Wednesday, December 3, 2014

ABAP: Dynamically generated WHERE conduction in SELECT

Sometimes ABAP programmers needs to do dynamical generation of WHERE conditions in SELECT statement. To do this the WHERE condition can be built by either CONCATENATE statement or by && string expression. Example in SAP documentation is provided here. Basically string variable is filled up with column name in which the lookup is performed and by lookup value:

cond_syntax = column &&  ` = value`. 

More over there are couple of function modules which can do this automatically. There are following FMs for that:


Last note to this topic is related to lookups of string values. Usually while we want to search in SAP (e.g. in matchcodes) we use asterisk (*) as wildcard which matches one or more characters. However in SQL language instead of the asterisk a percent sign (%) is used for the same. Therefore while the WHERE condition needs to be build up to look up matches one or more characters before and after EMAIL literal in column USRID it has to look like following:

USRID like '%EMAIL%'

No comments: