Search code examples
abapopensql

Asterisk in variable not considered like % in SQL


I created these three radio buttons to define values to the variable TEST.

The first two work just fine: if I click in p_r1 it assigns B and if I click p_r2 it assigns A.

I wanted the third to assign * to get all status i.e A, B, C.

Why doesn't it work? Isn't * a special character that means all like % in SQL?

DATA: TEST TYPE C.

PARAMETERS:
  P_R1 RADIOBUTTON GROUP GRP1 DEFAULT 'X',
  P_R2 RADIOBUTTON GROUP GRP1,
  P_R3 RADIOBUTTON GROUP GRP1.

IF P_R1 = 'X'.
  TEST = 'B'.

ELSEIF P_R2 = 'X'.
  TEST = 'A'.

ELSEIF P_R3 = 'X'.
  TEST = '*'.

ENDIF.

SELECT  VBELN,GBSTK
  FROM LIKP
  WHERE GBSTK = @TEST
  INTO TABLE @DATA(IT_FINAL).


CL_DEMO_OUTPUT=>DISPLAY( IT_FINAL ).

Solution

  • A few things to keep in mind to make your requirement work:

    1. An = or EQ in the where condition does not allow for wildcards. I.e. when test equals '*' in your example it will only find entries in the database table where GBSTK equals '*', most probably zero entries
    2. To use wildcards you need to use LIKE instead of = or EQ
    3. The general wild card to mach any string is '%' and not '*'

    For more details check the SAP help for SELECT - WHERE for your specific version. Here is the one for 752: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapwhere.htm?file=abapwhere.htm