I fyou want to select all fields of one table and just few fields of another (joined) table, you have to specify all required fields manually. It is NOT possible to write SELECT TAB_1~* TAB_2~FIELD_1 TAB_2~FIELD_2…. In this article I’ll show how to make this thing easier 🙂
The selection of all fields (SELECT tabname.*) will be done with the following helper method/form:
TYPES: tt_fields TYPE TABLE OF char300.
FORM add_tabfields_for_selection USING iv_tabname
CHANGING ct_fields TYPE tt_fields.
DATA:
lt_dfies TYPE dfies_tab,
lv_tabname TYPE ddobjname.
lv_tabname = iv_tabname.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = lv_tabname
TABLES
dfies_tab = lt_dfies.
* Append each field as line of TABNAME~FIELDNAME of the itab
LOOP AT lt_dfies ASSIGNING FIELD-SYMBOL(<ls_dfies>).
APPEND |{ <ls_dfies>-tabname }~{ <ls_dfies>-fieldname }| TO ct_fields.
ENDLOOP.
ENDFORM.
The real usage of this form might be as in the following code snippet:
TYPES:
BEGIN OF ts_data.
INCLUDE TYPE mara.
TYPES:
maktx TYPE maktx,
END OF ts_data,
tt_data TYPE TABLE OF ts_data.
DATA:
lt_fields TYPE tt_fields,
lt_data TYPE tt_data.
* Add all fields of selected DB table to the SQL selection
PERFORM add_tabfields_for_selection USING 'MARA'
CHANGING lt_fields.
* Add subset of fields from MAKT (mat. description)
APPEND 'MAKT~MAKTX' TO lt_fields.
* ...another fields
SELECT (lt_fields)
INTO CORRESPONDING FIELDS OF TABLE lt_data
FROM mara
INNER JOIN makt ON mara~matnr = makt~matnr
UP TO 5000 ROWS
WHERE makt~spras = sy-langu.
Hello,
this is an interesting approach for the older releases for sure.
I would like to point to the new feature released as part of ABAP 740/SP08 which does allow the maratab~* to specifiy all the fields :
Refer the link:
http://help.sap.com/abapdocu_740/en/abennews-740_sp08-open_sql.htm#!ABAP_MODIFICATION_1@1@
Regards
Kesari
Hi,
thanks a lot for this information – Our company does not currently have this version and service pack installed, therefore I was not able to use this form of the SELECT command – but anyway, it’s good to know there’s finally this feature in SAP 🙂