代码示例:
1.系统数据中存在的表或结构;
DATA: lv_tabnam TYPE ddobjname VALUE 'ZSDS006', |
lt_dfies TYPE STANDARD TABLE OF dfies, |
ls_dfies LIKE LINE OF lt_dfies. |
FIELD-SYMBOLS: <fv_value> TYPE any, |
<fv_mvalu> TYPE any. |
CALL FUNCTION 'DDIF_NAMETAB_GET' |
EXPORTING |
tabname = lv_tabnam |
TABLES |
dfies_tab = lt_dfies |
EXCEPTIONS |
not_found = 1 |
OTHERS = 2. |
IF sy-subrc <> 0. |
ENDIF. |
LOOP AT lt_dfies INTO ls_dfies. |
UNASSIGN: <fv_value>, <fv_mvalu>. |
ASSIGN COMPONENT ls_dfies-fieldname OF STRUCTURE zsds006 TO <fv_value>. |
CHECK <fv_value> IS ASSIGNED. |
ASSIGN COMPONENT ls_dfies-fieldname OF STRUCTURE es_vbap TO <fv_mvalu>. |
CHECK <fv_mvalu> IS ASSIGNED. |
MOVE <fv_value> TO <fv_mvalu>. |
ENDLOOP. |
2.内表或临时定义的结构
DATA:cl_descr TYPE REF TO cl_abap_structdescr. |
FIELD-SYMBOLS:<fs_comp> TYPE abap_compdescr. |
FIELD-SYMBOLS: <fv_value> TYPE any. |
LOOP AT gt_itab WHERE type = ''. |
CLEAR:gt_zmmt014[]. |
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_zmmt014 FROM zmmt014 WHERE mtart = gt_itab-mtart |
AND werks = gt_itab-werks. |
IF gt_zmmt014[] IS NOT INITIAL. |
LOOP AT gt_zmmt014. |
SPLIT gt_zmmt014-zfield AT '-' INTO gt_zmmt014-ztable gt_zmmt014-zfname. |
MODIFY gt_zmmt014. |
ENDLOOP. |
cl_descr ?= cl_abap_typedescr=>describe_by_data( gt_itab ). |
LOOP AT cl_descr->components ASSIGNING <fs_comp>. |
UNASSIGN <fv_value>. |
ASSIGN COMPONENT <fs_comp>-name OF STRUCTURE gt_itab TO <fv_value>. |
READ TABLE gt_zmmt014 WITH KEY zfname = <fs_comp>-name. |
IF sy-subrc = 0. |
<fv_value> = gt_zmmt014-zvalue. |
ENDIF. |
ENDLOOP. |
ENDIF. |
ENDLOOP. |