ABAP 动态内表创建/赋值
DATA:it_structure TYPE lvc_t_fcat,
dy_line TYPE REF TO data,
dy_table TYPE REF TO data.
FIELD-SYMBOLS: <dyn_wa> TYPE ANY,
<dyn_table> TYPE table.
"根据动态内表结构,创建动态内表
FORM create_dy_table USING p_structure.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = p_structure "USING it_structure
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
ENDFORM.
"给动态内表赋值
FORM get_data.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
LOOP AT gt_itab INTO gs_itab.
MOVE-CORRESPONDING gs_itab TO <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.
ENDLOOP.
ENDFORM.
ASSIGN 分配
FIELD-SYMBOLS:<fs>.
DATA:str(20) TYPE c VALUE 'Output String',
name(20) TYPE c VALUE 'STR'.
"静态分配:编译时就知道要分配的对象名
ASSIGN name TO <fs>."结果是<fs>与name变量等同
"通过变量名动态访问变量
ASSIGN (name) TO <fs>."结果是是<fs>的值为str变量值
"通过索引分配
LOOP AT <dyn_table> ASSIGNING <dyn_wa> .
ASSIGN COMPONENT col OF STRUCTURE <dyn_wa> TO <fs3>.
endloop.
"通过字段名动态的访问结构成员
ASSIGN COMPONENT <f2>OF STRUCTURE <f1> TO <f3>.