[ABAP] Rückgabedaten eines SELECTs in einzelne Variablen übergeben

DATA: lv_name_first TYPE ad_namefir.
DATA: lv_name_last TYPE ad_namelas.
DATA: lv_smtp_addr TYPE ad_smtpadr.

SELECT SINGLE p~name_first, p~name_last, a~smtp_addr
  FROM usr21 AS u
  INNER JOIN adrp AS p ON p~persnumber = u~persnumber
  INNER JOIN adr6 AS a ON a~addrnumber = u~addrnumber AND a~persnumber = u~persnumber
  INTO (@lv_name_first, @lv_name_last, @lv_smtp_addr)
  WHERE u~bname = @sy-uname.

IF sy-subrc = 0.
  ...
ENDIF.

[ABAP] OpenSQL: Felder im SELECT mit konstanten Werten füllen

* Variante 1 (Konstante)
CONSTANTS: co_empty TYPE char7 VALUE '<empty>'.
* Konstante über Alias maktx in das korrespondierende Feld MAKTX einfügen
SELECT matnr, @co_empty AS maktx FROM mara INTO TABLE @DATA(it_mara) UP TO 10 ROWS.

cl_demo_output=>display( it_mara ).

* Variante 2 (Variable)
DATA: lv_empty TYPE char7 VALUE '<empty>'.
* Konstante über Alias maktx in das korrespondierende Feld MAKTX einfügen
SELECT matnr, @lv_empty AS maktx FROM mara INTO TABLE @DATA(it_mara) UP TO 10 ROWS.

cl_demo_output=>display( it_mara ).

[ABAP] SELECT, GROUP BY, SUM, AS – Daten gruppieren und Elemente einer Gruppe aufsummieren

TYPES: BEGIN OF ty_sflight,
         carrid    TYPE sflight-carrid,
         connid    TYPE sflight-connid,
         sum_price TYPE sflight-price,
       END OF ty_sflight.

DATA: it_sflight TYPE STANDARD TABLE OF ty_sflight.
DATA: o_salv TYPE REF TO cl_salv_table.

* nach carrid und connid gruppieren und die Preise pro Gruppe summieren
SELECT carrid, connid, SUM( price ) AS sum_price FROM sflight
  INTO TABLE @it_sflight
  GROUP BY carrid, connid.

cl_salv_table=>factory( IMPORTING
                          r_salv_table   = o_salv
                        CHANGING
                          t_table        = it_sflight ).

o_salv->display( ).

[ABAP] SELECT mit Suchbereich / Mehrfachbedingungen

DATA: BEGIN OF s_stxh,
        tdname TYPE tdobname,
        tdid   TYPE tdid,
      END OF s_stxh.

DATA: it_stxh TYPE STANDARD TABLE OF s_stxh WITH DEFAULT KEY.

* Abfrage von zwei Spalten, Suchbereich in it_selection
* Ergebnismenge in it_stxh
SELECT tdname, tdid FROM stxh INTO CORRESPONDING FIELDS OF TABLE @it_stxh WHERE tdfdate IN @it_selection.