BDC:批处理
*&---------------------------------------------------------------------*
*& Report ZBSO_09_BDC
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZBSO_09_BDC.
********************************************************************************DATA**********************************************************
TABLES: SSCRFIELDS.
"FILE
DATA: GT_FILETAB TYPE FILETABLE,
GW_FILETAB LIKE LINE OF GT_FILETAB,
RC TYPE I
.
"FILE CONVERT TO INNER TABLE DATA
DATA: GW_ITAB TYPE ZSO_09_ALV_STRUCTURE,
GT_ITAB LIKE TABLE OF GW_ITAB.
"BDC DATA
DATA: GW_BDCDATA TYPE BDCDATA, " TY_BDCDATA,
GT_BDCDATA LIKE TABLE OF GW_BDCDATA.
DATA:L_OPT TYPE CTU_PARAMS.
DATA: MESSTAB TYPE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
"DIALOG TC DATA
DATA: BEGIN OF GS_TC_TAB,
CHEBOX TYPE C.
INCLUDE STRUCTURE ZSO_09_I.
DATA END OF GS_TC_TAB.
DATA GT_TC_TAB LIKE TABLE OF GS_TC_TAB.
DATA GW_TC_TAB LIKE GS_TC_TAB.
***************************************************************************SCREEN**************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-001. "BLOCK
SELECTION-SCREEN SKIP.
SELECTION-SCREEN ULINE.
PARAMETERS FILENAME LIKE RLGRAP-FILENAME MODIF ID P1.
SELECTION-SCREEN ULINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK B01.
**************************************************************************PROGRAM**************************************************************
*INITIALIZATION
INITIALIZATION.
"SCREEN FILE SELECT
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILENAME.
"FILE FILTER
DATA: FILTER TYPE STRING.
FILTER = 'Excel文件(*.CSV;*.xlsx;*.xls)|*.CSV;*.xlsx;*.xls|全部文件 (*.*)|*.*|'.
"选择文件对话框
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
FILE_FILTER = FILTER
CHANGING
FILE_TABLE = GT_FILETAB
RC = RC
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
NOT_SUPPORTED_BY_GUI = 4
OTHERS = 5.
READ TABLE GT_FILETAB INTO GW_FILETAB INDEX 1.
FILENAME = GW_FILETAB-FILENAME. "GET FILENAME
*START-OF-SELECTION
START-OF-SELECTION.
IF FILENAME IS NOT INITIAL.
MESSAGE '请选择导入的文件地址' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
PERFORM FORM_CONVERT_FILE. "UPLOAD FILE CONVERT TO SAP ITAB
*END-OF-SELECTION
END-OF-SELECTION.
PERFORM FORM_BDC. "IMPLEMENT BDC
************************************************************************************FORM*****************************************************
*&---------------------------------------------------------------------*
*& Form FORM_CONVERT_FILE
*&---------------------------------------------------------------------*
FORM FORM_CONVERT_FILE .
DATA:LV_RAW_DATA TYPE TRUXS_T_TEXT_DATA.
"FILE CONVERT TO ITAB
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = LV_RAW_DATA
I_FILENAME = FILENAME
TABLES
I_TAB_CONVERTED_DATA = GT_ITAB
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
MESSAGE S375(E0) WITH FILENAME.
STOP.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_BDC
*&---------------------------------------------------------------------*
FORM FORM_BDC .
DATA LV_INDEX LIKE SY-TABIX VALUE 1.
DATA LT_ITAB LIKE GT_ITAB.
DATA LW_ITAB LIKE LINE OF LT_ITAB.
L_OPT-DISMODE = 'A'. "A前台,N后台,E出错时弹出屏幕,P后台处理;可以调试
L_OPT-UPDMODE = 'S'.
L_OPT-CATTMODE = ''.
L_OPT-DEFSIZE = 'X'.
L_OPT-NOBINPT = 'X'.
"从DB表获取DIALOG上的GT_TC_IAB数据
SELECT
*
FROM ZSO_09_I
INTO CORRESPONDING FIELDS OF TABLE GT_TC_TAB
FOR ALL ENTRIES IN GT_ITAB
WHERE
ORDER_NUMBER = GT_ITAB-ORDER_NUMBER
.
SORT GT_TC_TAB BY ORDER_ITEM.
LT_ITAB = GT_ITAB.
DELETE ADJACENT DUPLICATES FROM LT_ITAB COMPARING ORDER_NUMBER. "删除相邻重复项
LOOP AT LT_ITAB INTO LW_ITAB.
REFRESH: GT_BDCDATA,
MESSTAB.
"屏幕1
PERFORM BDC_DYNPRO USING 'ZDSO_09_DIALOG' '0500'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'P1'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=CRET'.
PERFORM BDC_FIELD USING 'P1'
LW_ITAB-ORDER_NUMBER.
"屏幕2
PERFORM BDC_DYNPRO USING 'ZDSO_09_DIALOG' '9000'.
"台头表
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=UPDATE_00'.
PERFORM BDC_FIELD USING 'ZSO_09_H-ORDER_NUMBER'
LW_ITAB-ORDER_NUMBER.
PERFORM BDC_FIELD USING 'ZSO_09_H-CUSTOMER_NAME'
LW_ITAB-CUSTOMER_NAME.
PERFORM BDC_FIELD USING 'ZSO_09_H-COMPANY_NAME'
LW_ITAB-COMPANY_NAME.
* PERFORM BDC_FIELD USING 'ZSO_09_H-DELIVERY_DATE'
* LW_ITAB-DELIVERY_DATE.
PERFORM BDC_FIELD USING 'ZSO_09_H-SALES_ORG'
LW_ITAB-SALES_ORG.
PERFORM BDC_FIELD USING 'ZSO_09_H-SALES_GROUP'
LW_ITAB-SALES_GROUP.
PERFORM BDC_FIELD USING 'ZSO_09_H-SALES_MAN'
LW_ITAB-SALES_MAN.
PERFORM BDC_FIELD USING 'ZSO_09_H-PRODUCT_CATEG'
LW_ITAB-PRODUCT_CATEG.
PERFORM BDC_FIELD USING 'ZSO_09_H-PRODUCT_CLASS'
LW_ITAB-PRODUCT_CLASS.
PERFORM BDC_FIELD USING 'ZSO_09_H-MADE_BY'
LW_ITAB-MADE_BY.
* PERFORM BDC_FIELD USING 'ZSO_09_H-MADE_DATE'
* LW_ITAB-MADE_DATE.
* PERFORM BDC_FIELD USING 'ZSO_09_H-MADE_TIME'
* LW_ITAB-MADE_TIME.
"行项目表
LOOP AT GT_ITAB INTO GW_ITAB.
LV_INDEX = 1.
"修改行项目表
LOOP AT GT_TC_TAB INTO GW_TC_TAB.
IF GW_TC_TAB-ORDER_ITEM = GW_ITAB-ORDER_ITEM.
DATA LV_FNAM TYPE BDCDATA-FNAM.
LV_FNAM = 'GW_TC_TAB-CHEBOX(0' && LV_INDEX && ')'.
PERFORM BDC_FIELD USING LV_FNAM
'X'.
CLEAR LV_FNAM.
LV_FNAM = 'GW_TC_TAB-PRODUCT_NAME(0' && LV_INDEX && ')'.
PERFORM BDC_FIELD USING LV_FNAM
GW_ITAB-PRODUCT_NAME.
ENDIF.
LV_INDEX = LV_INDEX + 1.
ENDLOOP.
ENDLOOP.
"屏幕3
PERFORM BDC_DYNPRO USING 'ZDSO_09_DIALOG' '9000'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=EXIT_00'.
PERFORM BDC_FIELD USING 'ZSO_09_H-ORDER_NUMBER'
'10000001'.
PERFORM BDC_FIELD USING 'ZSO_09_H-CUSTOMER_NAME'
'客户1'.
PERFORM BDC_FIELD USING 'ZSO_09_H-COMPANY_NAME'
'1'.
PERFORM BDC_FIELD USING 'ZSO_09_H-DELIVERY_DATE'
'23.04.2021'.
PERFORM BDC_FIELD USING 'ZSO_09_H-SALES_ORG'
'1001'.
PERFORM BDC_FIELD USING 'ZSO_09_H-SALES_GROUP'
'组'.
PERFORM BDC_FIELD USING 'ZSO_09_H-SALES_MAN'
'销售人员'.
PERFORM BDC_FIELD USING 'ZSO_09_H-PRODUCT_CATEG'
'30'.
PERFORM BDC_FIELD USING 'ZSO_09_H-PRODUCT_CLASS'
'产品'.
PERFORM BDC_FIELD USING 'ZSO_09_H-MADE_BY'
'订单创建人'.
PERFORM BDC_FIELD USING 'ZSO_09_H-MADE_DATE'
'23.04.2021'.
PERFORM BDC_FIELD USING 'ZSO_09_H-MADE_TIME'
'03:22:11'.
"CALL TRANSACTION
CALL TRANSACTION 'ZDSO_09_DIALOG' USING GT_BDCDATA
OPTIONS FROM L_OPT
"MODE 'N'" 'N'
"UPDATE 'S'
MESSAGES INTO MESSTAB.
"EQ THE RETURN MESSAGE
LOOP AT MESSTAB WHERE MSGTYP CA 'AE'.
EXIT.
ENDLOOP.
IF SY-SUBRC NE 0.
"GW_ITAB-MSG = '修改成功'.
ELSE.
* MESSAGE ID MESSTAB-MSGID TYPE MESSTAB-MSGTYP NUMBER MESSTAB-MSGNR
* WITH MESSTAB-MSGV1 MESSTAB-MSGV2 MESSTAB-MSGV3 MESSTAB-MSGV4 INTO GW_ITAB-MSG.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
"SETTING DYNPRO
CLEAR GW_BDCDATA.
GW_BDCDATA-PROGRAM = PROGRAM. "程序名称
GW_BDCDATA-DYNPRO = DYNPRO. "屏幕号码
GW_BDCDATA-DYNBEGIN = 'X'. "屏幕启动
APPEND GW_BDCDATA TO GT_BDCDATA.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
"SETTING BDC FIELD
CLEAR GW_BDCDATA.
GW_BDCDATA-FNAM = FNAM. "字段名
GW_BDCDATA-FVAL = FVAL. "字段值
APPEND GW_BDCDATA TO GT_BDCDATA.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BDC_FIELD_1
*&---------------------------------------------------------------------*
FORM BDC_FIELD_1 USING P_LV_FNAM
P_GW_ITAB_PRICE TYPE ZSO_09_ALV_STRUCTURE-PRICE.
"SETTING BDC FIELD
CLEAR GW_BDCDATA.
GW_BDCDATA-FNAM = P_LV_FNAM. "字段名
GW_BDCDATA-FVAL = P_GW_ITAB_PRICE."字段值
APPEND GW_BDCDATA TO GT_BDCDATA.
ENDFORM.
INCLUDE STRUCTURE
选择本地文件,获取文件名
本地EXCEL文件转换为内表
BDC设置前台显示
BDC调用屏幕程序,结合另一文章一起看