[ABAP] OpenSQL: Zusammenführen von Tabelleninhalten mit SELECT UNION

Variante 1 (UNION == UNION DISTINCT – einfaches Auftreten der Datensätze)

DATA: lv_devclass TYPE string VALUE 'ZABAP2XLSX'.

SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'PROG' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'CLAS' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'FUGR' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'DEVC' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'DOMA' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'DTEL' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'INTF' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'MSAG' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'TABL' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'TTYP' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'WDYA' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'XSLT' AND devclass = @lv_devclass
UNION DISTINCT
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'WDYN' AND devclass = @lv_devclass
 ORDER BY obj_name
 INTO TABLE @DATA(it_prog_range).

DATA(lv_lines) = lines( it_prog_range ).
cl_demo_output=>write_data( lv_lines ).
cl_demo_output=>write_data( it_prog_range ).
cl_demo_output=>display( ).

Variante 2 (UNION ALL – mehrfach auftretende Datensätze)

DATA: lv_devclass TYPE string VALUE 'ZABAP2XLSX'.

SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'PROG' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'CLAS' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'FUGR' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'DEVC' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'DOMA' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'DTEL' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'INTF' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'MSAG' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'TABL' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'TTYP' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'WDYA' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'XSLT' AND devclass = @lv_devclass
UNION ALL
SELECT obj_name
  FROM tadir
  WHERE pgmid = 'R3TR' AND object = 'WDYN' AND devclass = @lv_devclass
 ORDER BY obj_name
 INTO TABLE @DATA(it_prog_range).

DATA(lv_lines) = lines( it_prog_range ).
cl_demo_output=>write_data( lv_lines ).
cl_demo_output=>write_data( it_prog_range ).
cl_demo_output=>display( ).

Links