表数据修改
DATA: lt_dntab TYPE TABLE OF dntab, ls_config TYPE zabapt_enh_conf. DATA gv_tabnam TYPE tabname. DATA: dyn_table TYPE REF TO data, dyn_wa TYPE REF TO data. DATA cursor TYPE cursor. DELETE FROM (gt_config-yl4). * 创建动态内表结构 CREATE DATA dyn_table TYPE TABLE OF (gv_tabnam). * 创建动态内表 ASSIGN dyn_table->* TO <dyn_table>. * 创建动态工作区结构 CREATE DATA dyn_wa LIKE LINE OF <dyn_table>. * 创建动态工作区 ASSIGN dyn_wa->* TO <dyn_wa>. * 获取表对应的字段 CALL FUNCTION 'NAMETAB_GET' EXPORTING langu = sy-langu tabname = gv_tabnam TABLES nametab = lt_dntab EXCEPTIONS internal_error = 1 table_has_no_fields = 2 table_not_activ = 3 no_texts_found = 4 OTHERS = 5. * 从表里获取数据 OPEN CURSOR WITH HOLD cursor FOR SELECT * FROM (gv_tabnam). DO. FETCH NEXT CURSOR cursor INTO TABLE <dyn_table> PACKAGE SIZE gv_package. IF sy-subrc = 0. "数据分包处理 IF gv_backup = 'X'. PERFORM frm_backup_data TABLES lt_dntab."备份原表数据 ELSE. PERFORM frm_process_data TABLES lt_dntab."替换数据 ENDIF. ELSE. CLOSE CURSOR cursor. EXIT. ENDIF. ENDDO. *&---------------------------------------------------------------------* *& Form frm_backup_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->LT_DNTAB text *----------------------------------------------------------------------* FORM frm_backup_data TABLES lt_dntab STRUCTURE dntab. DATA: ls_config TYPE zabapt_enh_conf. * 备份原表数据 READ TABLE gt_config INTO ls_config WITH KEY yl1 = gv_tabnam. IF sy-subrc = 0 . IF gv_backup = 'X' AND ls_config-yl4 IS NOT INITIAL . MODIFY (ls_config-yl4) FROM TABLE <dyn_table>. IF sy-subrc = 0. EXEC SQL. COMMIT ENDEXEC. ENDIF. ENDIF. ENDIF. ENDFORM. " FRM_BACKUP_DATA *&---------------------------------------------------------------------* *& Form frm_process_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->LT_DNTAB text *----------------------------------------------------------------------* FORM frm_process_data TABLES lt_dntab STRUCTURE dntab. FIELD-SYMBOLS:<ambigous> TYPE ANY. FIELD-SYMBOLS:<1j> TYPE ANY. DATA: ls_config TYPE zabapt_enh_conf, ls_dntab TYPE dntab, lv_mark TYPE c. * 渠道字段为主健的时候,需要先删除原数据 READ TABLE gt_config INTO ls_config WITH KEY yl1 = gv_tabnam. IF sy-subrc = 0. READ TABLE lt_dntab INTO ls_dntab WITH KEY fieldname = ls_config-yl2. IF sy-subrc = 0. IF ls_dntab-keyflag = 'X'. DELETE (gv_tabnam) FROM TABLE <dyn_table>. ENDIF. ENDIF. ENDIF. * 对配置表中的需要处理的字段进行备份和替换 LOOP AT <dyn_table> ASSIGNING <dyn_wa>. READ TABLE gt_config INTO ls_config WITH KEY yl1 = gv_tabnam. CHECK sy-subrc = 0. ASSIGN COMPONENT ls_config-yl3 OF STRUCTURE <dyn_wa> TO <1j>."2级 IF sy-subrc = 0 . <1j> = <ambigous>+0(1). ENDIF. ENDIF. ENDLOOP. IF <dyn_table>[] IS NOT INITIAL AND gv_test IS INITIAL. MODIFY (gv_tabnam) FROM TABLE <dyn_table>. IF sy-subrc = 0. EXEC SQL. COMMIT ENDEXEC. ENDIF. ENDIF. ENDFORM. " FRM_PROCESS_DATA