Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Literals in ABAP OpenSQL?

Tags:

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?

like image 807
Felix Avatar asked Dec 22 '17 09:12

Felix


People also ask

What are literals in ABAP?

Literals are unnamed data objects that you create within the source code of a program. They are fully defined by their value. You can't change the value of a literal. Constants are named data objects created statically by using declarative statements.

What are host variables in SAP ABAP?

Host variables are global or local variables (usually variables) declared in the ABAP program that are used in operand positions of Open SQL statements. Instead of the data object itself, a field symbol to which the data object is assigned can be specified. Dereferenced data reference variables can also be specified.

How do you declare a constant variable in SAP ABAP?

Constants declared in the declaration part of a class or an interface are static attributes of that class or interface. The naming conventions apply to the name const. The syntax of the additions options of the statement CONSTANTS statement for declaring constants matches the statement DATA for declaring variables.

Which character is used to escape host variables in the new Opensql syntax?

Specifies various host variables; the escape character @ is always used.


1 Answers

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.
like image 68
Haojie Avatar answered Nov 03 '22 04:11

Haojie