Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Where + Like and a variable

Former Member
0 Likes
830

Hi everybody,

I am using a RFC and sending it some values to the imported variables.

In the code I want to use some select statement and a "where" condition that is followed by "like". In the value that I insert to the "like " I wish to use the value that was sent to the imported variable + the "%" sign (results should be all records that their relevant field starts with the value that I send to the imported variable).

For example:

SELECT * FROM <table_name> INTO table <my_table> WHERE <some_field> LIKE <my_imported_variable>%

This syntax fails. Can someone explain why and what is the right way?

Thanks,

Roy

4 REPLIES 4
Read only

suresh_datti
Active Contributor
0 Likes
809

Declare another variable; concatenate the '%' to the imported variable & then store it in this variable; use this new variable in your WHERE clause.

~Suresh

Read only

0 Likes
809

Thanks Suresh,

Can you give an example - how do I concatenate the variable with the char "%"?

Read only

0 Likes
809

Hi Roy check this code to create dynamic where clause.. like you wanted..


PARAMETERS: carr_id TYPE spfli-carrid,
            conn_id TYPE spfli-connid.
 
DATA:       where_clause TYPE  STRING,
            and(4),
            wa_spfli TYPE spfli.
 
IF carr_id IS NOT INITIAL.
  CONCATENATE 'CARRID = ''' carr_id '''' INTO where_clause.
  and = ' AND'.
ENDIF.
IF conn_id IS NOT INITIAL.
  CONCATENATE where_clause and ' CONNID = ''' conn_id ''''
    INTO where_clause.
ENDIF.
SELECT * FROM spfli INTO wa_spfli WHERE (where_clause).
  WRITE: / wa_spfli-carrid, wa_spfli-connid, wa_spfli-cityfrom,
           wa_spfli-cityto, wa_spfli-deptime.
ENDSELECT. 

Read only

Former Member
0 Likes
809

Hi Roy,

Please try this logic.

This logic i have used for getting purchase orders from EKKO where Purchase order number starts only with '46'.

SELECT ebeln

ekorg

lifnr

INTO TABLE it_ekko

FROM ekko

WHERE EBELN like '46%'.

regards

Avi....