[SAP ABAP] APPEND INITIAL LINE 追加空行
语法格式
APPEND INITIAL LINE TO itab.
示例1
输出结果:
示例2
我们可以使用下面的语法进行内表分配指针,追加空行并赋值的操作
APPEND INITIAL LINE TO lt_tab ASSIGNING FIELD-SYMBOL(<lfs_val>).
REPORT z437_test_2025.
* 自定义数据类型
TYPES: BEGIN OF ty_item,
id(2) TYPE n, " 编号ID
name(10) TYPE c, " 姓名
age TYPE i, " 年龄
END OF ty_item.
TYPES: BEGIN OF ty_info,
id(2) TYPE n, " 编号ID
name(10) TYPE c, " 姓名
shcool(10) TYPE c, " 学校
END OF ty_info.
DATA: ls_item TYPE ty_item, " 结构体变量
lt_item TYPE STANDARD TABLE OF ty_item, " 内表
lt_info TYPE STANDARD TABLE OF ty_info. " 内表
* lt_item内表添加数据
lt_item = VALUE #( ( id = '10' name = 'A10' age = 10 )
( id = '20' name = 'A20' age = 20 ) ).
LOOP AT lt_item INTO ls_item.
APPEND INITIAL LINE TO lt_info ASSIGNING FIELD-SYMBOL(<lfs_info>).
<lfs_info>-id = ls_item-id.
<lfs_info>-name = ls_item-name.
ENDLOOP.
* 数据呈现
cl_demo_output=>display( lt_info ).
输出结果: