*& 两个内表不同名称字段赋值的方法
*& 方法1:使用Loop循环手动赋值
*& 方法2:维护一个映射表,返回一个执行器,调用其execute方法
*& 方法3:CORRESPONDING #( )
TYPES :BEGIN OF developer, "内表1 name TYPE string, focus_language TYPE string, salary TYPE i, END OF developer, BEGIN OF presale, "内表2 name TYPE string, focus_area TYPE string, salary_plus_bouns TYPE i, END OF presale. DATA: developer_list TYPE TABLE OF developer WITH EMPTY KEY, presale_list1 TYPE TABLE OF presale WITH EMPTY KEY, presale_list2 TYPE TABLE OF presale WITH EMPTY KEY, presale_list3 TYPE TABLE OF presale WITH EMPTY KEY. developer_list = VALUE #( ( name = 'AAA' focus_language = 'ZH' salary = 1 ) ( name = 'BBB' focus_language = 'EN' salary = 2 ) ). "方法一:使用Loop循环手动赋值 LOOP AT developer_list ASSIGNING FIELD-SYMBOL(<temp1>). APPEND INITIAL LINE TO presale_list1 ASSIGNING FIELD-SYMBOL(<temp2>). <temp2>-name = <temp1>-name. <temp2>-focus_area = <temp1>-focus_language. <temp2>-salary_plus_bouns = <temp1>-salary. ENDLOOP. "方法2:维护一个映射表,返回一个执行器,调用其execute方法 *DATA(it_mapping) = VALUE cl_abap_corresponding=>mapping_table( ( level = 0 kind = 1 srcname = 'name' dstname = 'name' ) ). DATA(lo_mapping_executor) = cl_abap_corresponding=>create( source = developer_list destination = presale_list2 mapping = VALUE cl_abap_corresponding=>mapping_table( ( level = 0 kind = 1 srcname = 'name' dstname = 'name' ) ( level = 0 kind = 1 srcname = 'focus_language' dstname = 'focus_area' ) ( level = 0 kind = 1 srcname = 'salary' dstname = 'salary_plus_bouns' ) ) ). lo_mapping_executor->execute( EXPORTING source = developer_list CHANGING destination = presale_list2 ). "方法3:CORRESPONDING #( ) presale_list3 = CORRESPONDING #( developer_list MAPPING name = name focus_area = focus_language salary_plus_bouns = salary ).
推荐方法三,动态的话就用方法二。