Literals in ABAP OpenSQL?
Asked Answered
G

2

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?

Germanous answered 22/12, 2017 at 9:40 Comment(0)
A
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.
Appomattox answered 22/12, 2017 at 13:20 Comment(3)
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.Patriapatriarch
@Patriapatriarch you are right. I just tried. It is working as well. I will update my answer. Thank you!Appomattox
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.Germanous
A
-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.

Adsorb answered 22/12, 2017 at 12:56 Comment(2)
This is not even close to answering the question.Renita
Agreed. Understood the query in a complete different manner and came up with this answer.Adsorb

© 2022 - 2024 — McMap. All rights reserved.