Created
January 19, 2022 14:23
-
-
Save larshp/7178e319d3b699dbc30ee963c1a35219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONSTANTS lc_tabname TYPE c LENGTH 16 VALUE 'ZHVAM_CUST'. | |
DATA obj TYPE REF TO object. | |
DATA lr_ddfields TYPE REF TO data. | |
FIELD-SYMBOLS <any> TYPE any. | |
FIELD-SYMBOLS <fieldname> TYPE simple. | |
FIELD-SYMBOLS <ddfields> TYPE ANY TABLE. | |
DATA names TYPE STANDARD TABLE OF abap_compname WITH DEFAULT KEY. | |
TRY. | |
CALL METHOD ('XCO_CP_ABAP_DICTIONARY')=>('DATABASE_TABLE') | |
EXPORTING | |
iv_name = lc_tabname | |
RECEIVING | |
ro_database_table = obj. | |
ASSIGN obj->('IF_XCO_DATABASE_TABLE~FIELDS->IF_XCO_DBT_FIELDS_FACTORY~KEY') | |
TO <any>. | |
obj = <any>. | |
CALL METHOD obj->('IF_XCO_DBT_FIELDS~GET_NAMES') | |
RECEIVING | |
rt_names = names. | |
CATCH cx_sy_dyn_call_illegal_class. | |
DATA workaround TYPE string. | |
workaround = 'DDFIELDS'. | |
CREATE DATA lr_ddfields TYPE (workaround). | |
ASSIGN lr_ddfields->* TO <ddfields>. | |
<ddfields> = CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_name( | |
lc_tabname ) )->get_ddic_field_list( ). | |
LOOP AT <ddfields> ASSIGNING <any> WHERE ('KEYFLAG = abap_true'). | |
ASSIGN COMPONENT 'FIELDNAME' OF STRUCTURE <any> TO <fieldname>. | |
APPEND <fieldname> TO names. | |
ENDLOOP. | |
ENDTRY. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment