Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

11/8/2019 ABAP - Using of generic data elements (sample) - Code Gallery - SCN Wiki

Getting Started Store

Community WIKI SAP Community Welcome, Guest Login Register Search the Community

Code Gallery

ABAP - Using of generic data elements (sample)


Created by Waldemar Schakiel, last modified on Apr 05, 2016

Author: Waldemar Schakiel


Submitted: 5th April 2016

Description

Here is a sample for using generic data elements. This example displays the content of any table that was given as Parameter.

REPORT zgeneric_elements.
PARAMETERS:
p_tabnam TYPE tabname.

DATA:
lr_table TYPE REF TO data,
lx_error TYPE REF TO cx_root.

FIELD-SYMBOLS:
<lt_table> TYPE ANY TABLE.

TRY.
CREATE DATA lr_table TYPE TABLE OF (p_tabnam).
ASSIGN lr_table->* TO <lt_table>.

SELECT * FROM (p_tabnam) INTO TABLE <lt_table>.

LOOP AT <lt_table> ASSIGNING FIELD-SYMBOL(<ls_table>).


DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO FIELD-SYMBOL(<lv_field>).

IF sy-subrc = 0.
WRITE: <lv_field>.
ELSE.
WRITE: /. " New line
EXIT.
ENDIF.
ENDDO.
ENDLOOP.

CATCH cx_sy_create_data_error cx_sy_dynamic_osql_semantics INTO lx_error.


WRITE: / 'Exception:', lx_error->get_text( ).
ENDTRY.

No labels

Contact Us SAP Help Portal


Privacy Terms of Use Legal Disclosure Copyright Cookie Preferences Follow SCN

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=491920119 1/1

You might also like