6

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?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Felix
  • 78
  • 4
  • 15

2 Answers2

6

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.
Haojie
  • 5,665
  • 1
  • 15
  • 14
  • You don't need the variables in the newest versions of Open SQL. You can write `I` and `EQ` directly as constants in the query. – Jagger Dec 22 '17 at 13:29
  • @Jagger you are right. I just tried. It is working as well. I will update my answer. Thank you! – Haojie Dec 22 '17 at 13:30
  • Thanks for the answer. Unfortunately we are using NGAP(netweaver 8.x, the standard for ByD systems) which not too many people will know. As this is actually a dead codeline (allthough its version number is higher than the current standard) and is not developed anymore, it is probably not possible to use it in this version.Nevertheless, thank you for your answers. – Felix Dec 23 '17 at 11:13
-3

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.