Felix
Felix

Reputation: 88

Literals in ABAP OpenSQL?

in SQL it is usually possible to use literals in a select statement, e.g. like this

SELECT 'I', 'EQ', table.alev_uuid
  FROM table

Is there any chance to do this in an ABAP SQL query?

what I tried so far is this:

DATA lt_aldf TYPE RANGE OF cam_pw_stat-alev_uuid .

DATA lv_i type string value 'I'.
DATA lv_eq type string value 'EQ'.


    SELECT lv_i lv_eq alev~alev_uuid
      FROM cam_tool AS tool INNER JOIN
           cam_alev AS alev ON tool~tool_uuid = alev~tool_uuid
      INTO TABLE lt_aldf
      WHERE tool_access = /a1sspc/if_cam_tool=>gc_tool_definition-hdb-class AND
            tool~active = abap_true AND
            alev~active = abap_true.

But it does not work like in the usual SQL standard. Does anyone have any advice?

Upvotes: 6

Views: 3343

Answers (2)

In ABAP SQL one can make use of string literals in SELECT query in the following way.

DATA : li_t001w TYPE STANDARD TABLE OF t001w.
DATA : lv_name TYPE name1 VALUE 'ST%'.

SELECT *
FROM t001w
INTO TABLE li_t001w
WHERE  name1 like lv_name.

Above example would return the table entries from T001w where the name1 field value starts with ST.

Upvotes: -3

Haojie
Haojie

Reputation: 5713

starting from ABAP 7.5*, you can use Host Variables to achieve your requirements.

Please define lv_i and lv_eq as Char type.

data lv_i type char1 value 'I'.
data lv_eq type char2 value 'EQ'.

I tried with my own by selecting from T001. It is working perfect.

data:
  lr_t_bukrs type range of bukrs.

select @lv_i, @lv_eq, bukrs from t001 into table @lr_t_bukrs up to 10 rows.

Update from @Jagger,

you can also use constants in the OPEN SQL directly.

select 'I', 'EQ', bukrs from t001 into table @lr_t_bukrs up to 10 rows.

Upvotes: 6

Related Questions