FORM frm_get_cols_fields TABLES pt_comp TYPE abap_compdescr_tab
USING ps_cols.
DATA: lcl_ref_descr TYPE REF TO cl_abap_structdescr,
ls_comp TYPE abap_compdescr.
CLEAR: pt_comp,pt_comp[].
"获取工作区字段信息
lcl_ref_descr ?= cl_abap_typedescr=>describe_by_data( ps_cols ).
pt_comp[] = lcl_ref_descr->components.
ENDFORM.
程序调用
REPORT zwldemo036.
DATA:BEGIN OF ls_cols,
note001 TYPE string VALUE '1',
note002 TYPE string VALUE '2',
END OF ls_cols.
DATA: lt_comp TYPE abap_compdescr_tab,
ls_comp TYPE abap_compdescr.
"获取工作区字段信息
PERFORM frm_get_cols_fields TABLES lt_comp
USING ls_cols.
CHECK lt_comp IS NOT INITIAL.
"输出工作区值
ASSIGN ls_cols TO FIELD-SYMBOL(<fs_cols>).
LOOP AT lt_comp INTO ls_comp.
ASSIGN COMPONENT ls_comp-name OF STRUCTURE <fs_cols> TO FIELD-SYMBOL(<fd_col>).
CHECK <fd_col> IS ASSIGNED.
WRITE: / ls_comp-name, ' = ', <fd_col>.
UNASSIGN <fd_col>.
ENDLOOP.
输出结果
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/17909.html