- 浏览: 780985 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (573)
- Java基础 (76)
- C++基础 (5)
- hibernate (5)
- struts (4)
- spring (1)
- webservice (7)
- AjaX基础 (0)
- JS脚本 (53)
- 正则表达式 (5)
- html脚本 (30)
- 数据库基础 (54)
- 工作相关 (49)
- 其他 (30)
- Linux (9)
- web服务器 (17)
- JSP (13)
- eclipse (6)
- 面试题相关 (20)
- XML (3)
- Apache common (2)
- 生活 (35)
- VMware (1)
- log4j (9)
- BeanUtils (2)
- 设计模式 (3)
- UML (1)
- UNIX (1)
- ibats (5)
- GT-Grid (17)
- ABAP学习 (17)
- ABAP (35)
- ABAP--ALV (11)
- ABAP--WEBDIMPRO (0)
- abap-sample (1)
- BEMS (2)
- flex (33)
- GIS技术 (3)
最新评论
BDC(batch data communication)是SAP常用的一种数据传输方法。用于一些数据量大,但是对速度又要求不高的数据传输。
在实施中,很多开发顾问都忽略了BDC的日志和出错管理。这给用户在使用中带来了很大的不便。比如:哪些数据是成功生成的,哪些是失败的?那些失败的,原因的是什么?程序问题还是数据问题?
我觉得,既然是要做一套程序,那就应该尽可能地为客户考虑,减少日后的维护量。对于BDC程序来讲,日志和出错管理应该是必备的。
下面讲一下,BDC的两种通用写法。
1. Call Transaction: 顾名思义,就是直接调用BDC进行数据批量导入。优点:方便快捷,程序处理方便。缺点:日志管理能力差,需自己建透明表来维护数据。我只是把它用作测试用途,不做正式使用。
2. BDC Insert:这是一种不直接运行,而是将BDC程序生成session,间接运行的一种方法。优点:通过T-code SM35可以进行运行管理及日志管理,方便查错。缺点:相对方法1来说实现起来比较繁琐。我主要是用这种方法来实现BDC功能。
下面主要来谈一下BDC Insert这种方法。
1. 需要在程序中调用 function 'BDC_INSERT'来把BDCDATA生成SESSION.
2. 程序RSBDCSUB是执行SESSION的专用程序,要建立相应的VARIANT,后续建立JOB中使用
3. 建立BATCH JOB来定期执行RSBDCSUB,从而实现,SESSION自动执行的目的
4. 当然,不使用程序RSBDCSUB和JOB,每次手工在SM35中执行SESSION也是可以的
下面是我写的一个实例:
*----------------------------------------------------------------------*
* Program Name: Z_KEVIN_ADV_BDC
* Project : N/A
* Author : Kevin.Zhang
* Date : 2007.1.1
* Module : N/A
* Description : Advanced BDC
*
*
*
* Special features: N/A
*
*
*----------------------------------------------------------------------*
* Modifications:
* Author Date Commented as Description
*----------- -------- ----------- ----------------------------------*
*
*----------------------------------------------------------------------*
REPORT Z_KEVIN_ADV_BDC.
*$*$----------------------------------------------------------------$*$*
*$*$ Global Types, Data Statements, Ranges, Constants $*$*
*$*$----------------------------------------------------------------$*$*
*-----------------------------------------------------------------------
* Tables
*-----------------------------------------------------------------------
TABLES: COAS, CEPC.
*-----------------------------------------------------------------------
* Internal Tables and Work Areas
*-----------------------------------------------------------------------
DATA: BEGIN OF GT_TABLE OCCURS 0, "internal order table
AUART LIKE AUFK-AUART, "order type
AUFNR LIKE AUFK-AUFNR, "order number
KTEXT LIKE AUFK-KTEXT, "description
BUKRS LIKE AUFK-BUKRS, "company code
GSBER LIKE AUFK-GSBER, "business area
PRCTR LIKE AUFK-PRCTR, "profit center
FUNCA LIKE AUFK-FUNC_AREA, "function area
END OF GT_TABLE.
DATA: BEGIN OF GT_EXISTS OCCURS 0. "existed IO
INCLUDE STRUCTURE GT_TABLE.
DATA: END OF GT_EXISTS.
DATA: BEGIN OF GT_PRFT_CNTR OCCURS 0."the profit center not existing IO
INCLUDE STRUCTURE GT_TABLE.
DATA: END OF GT_PRFT_CNTR.
DATA: BEGIN OF GT_SUBMIT OCCURS 0. "the submitted IO
INCLUDE STRUCTURE GT_TABLE.
DATA: END OF GT_SUBMIT.
DATA: BEGIN OF GT_BDCDATA OCCURS 0. "BDC DATA
INCLUDE STRUCTURE BDCDATA.
DATA: END OF GT_BDCDATA.
DATA: BEGIN OF GT_MESSTAB OCCURS 10. "message table
INCLUDE STRUCTURE BDCMSGCOLL.
DATA: END OF GT_MESSTAB.
DATA: GT_IMESG LIKE MESG OCCURS 0 WITH HEADER LINE.
*-----------------------------------------------------------------------
* Variables
*-----------------------------------------------------------------------
DATA: GV_GROUP(12) TYPE C VALUE 'INTERNAL_ORD', "BDC Name
GV_USER(12) TYPE C, "BDC User
GV_KEEP(1) TYPE C VALUE 'X', " ' '=Delete,'X'=keep after processing
GV_HOLDDATE LIKE SY-DATUM. "Date
DATA: GV_FLAG(1) TYPE C,
GV_LIN TYPE I. "number of orders
DATA: GV_C170(170),
GV_C_ULINE(50) VALUE '__________________________________________________'.
*$*$----------------------------------------------------------------$*$*
*$*$ Selection Screen $*$*
*$*$----------------------------------------------------------------$*$*
*-----------------------------------------------------------------------
* Selection Screen
*-----------------------------------------------------------------------
PARAMETERS: BDCTYPE(1) TYPE C DEFAULT 'B' NO-DISPLAY,
BDCMODE LIKE BDCRUN-BDC_AMODUS DEFAULT 'A' NO-DISPLAY.
SELECTION-SCREEN COMMENT 10(70) TEXT-001.
PARAMETERS: IN_FILE(128) DEFAULT 'C:\TEMP\*.txt'.
SELECTION-SCREEN SKIP 1.
*-----------------------------------------------------------------------
* At Selection Screen
*-----------------------------------------------------------------------
*--------- AT SELECTION-SCREEN ON VALUE-REQUEST ----------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR IN_FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = '*.txt'
DEF_PATH = 'C:\DATA'
MASK = ',All Files,*.*,Text Files,*.txt;*.doc.'
MODE = 'O'
TITLE = 'Please choose file to use '
IMPORTING
FILENAME = IN_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
*$*$----------------------------------------------------------------$*$*
*$*$ Main Program $*$*
*$*$----------------------------------------------------------------$*$*
*--------- START-OF-SELECTION ----------
START-OF-SELECTION.
REFRESH GT_TABLE.
* Uploading the data which will be inserted into the internal table
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = IN_FILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = GT_TABLE
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'Unable to upload input file '
IN_FILE '' ''.
ENDIF.
SORT GT_TABLE BY AUFNR GSBER DESCENDING.
DELETE ADJACENT DUPLICATES FROM GT_TABLE COMPARING AUFNR.
PERFORM OPEN_GROUP.
PERFORM FILL_BDC_DATA.
PERFORM BDC_CLOSE_GROUP.
PERFORM WRITE_REPORT.
*--------- END-OF-SELECTION ----------
*$*$----------------------------------------------------------------$*$*
*$*$ Subroutines $*$*
*$*$----------------------------------------------------------------$*$*
*&---------------------------------------------------------------------*
*& Form OPEN_GROUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM OPEN_GROUP.
GV_USER = SY-UNAME.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = GV_GROUP
HOLDDATE = GV_HOLDDATE
KEEP = GV_KEEP
USER = GV_USER.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " OPEN_GROUP
*&---------------------------------------------------------------------*
*& Form FILL_BDC_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_BDC_DATA.
CLEAR GT_TABLE.
LOOP AT GT_TABLE.
CLEAR GT_MESSTAB.
CLEAR GT_BDCDATA.
REFRESH GT_BDCDATA.
REFRESH GT_MESSTAB.
CLEAR GV_FLAG.
* Check if Profit Center exists.
SELECT SINGLE * FROM CEPC
WHERE PRCTR = GT_TABLE-PRCTR.
IF SY-SUBRC <> 0.
CLEAR GT_PRFT_CNTR.
MOVE-CORRESPONDING GT_TABLE TO GT_PRFT_CNTR.
APPEND GT_PRFT_CNTR.
GV_FLAG = 'X'.
ENDIF.
* check if Internal Order has already been created.
SELECT SINGLE * FROM COAS
WHERE AUFNR = GT_TABLE-AUFNR.
IF SY-SUBRC = 0.
CLEAR GT_EXISTS.
MOVE-CORRESPONDING GT_TABLE TO GT_EXISTS.
APPEND GT_EXISTS.
GV_FLAG = 'X'.
ENDIF.
IF GV_FLAG <> 'X'.
PERFORM BDCDATA USING: 'X' 'SAPMKAUF' '0100', "order type
' ' 'COAS-AUART' GT_TABLE-AUART,
' ' 'BDC_OKCODE' '=KOKR'.
PERFORM BDCDATA USING: 'X' 'SAPLSPO4' '0300', "control area
' ' 'SVALD-VALUE(01)' '1000',
' ' 'BDC_OKCODE' '=FURT'.
PERFORM BDCDATA USING: 'X' 'SAPMKAUF' '0100', "ok code
' ' 'BDC_OKCODE' '/00'.
PERFORM BDCDATA USING: 'X' 'SAPMKAUF' '0600', "order master data
' ' 'COAS-AUFNR' GT_TABLE-AUFNR,
' ' 'COAS-KTEXT' GT_TABLE-KTEXT,
' ' 'COAS-BUKRS' GT_TABLE-BUKRS,
' ' 'COAS-GSBER' GT_TABLE-GSBER,
' ' 'COAS-PRCTR' GT_TABLE-PRCTR,
' ' 'COAS-FUNC_AREA' GT_TABLE-FUNCA,
' ' 'BDC_OKCODE' '=SICH'.
* PERFORM CALL_TRANSACTION. "for test purpose
PERFORM BDC_INSERT.
MOVE-CORRESPONDING GT_TABLE TO GT_SUBMIT.
APPEND GT_SUBMIT.
ENDIF.
ENDLOOP.
ENDFORM. " FILL_BDC_DATA
*&---------------------------------------------------------------------*
*& Form BDC_INSERT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_INSERT.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'KO01'
TABLES
DYNPROTAB = GT_BDCDATA.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " BDC_INSERT
*&---------------------------------------------------------------------*
*& Form BDC_CLOSE_GROUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_CLOSE_GROUP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " BDC_CLOSE_GROUP
*&---------------------------------------------------------------------*
*& Form CALL_TRANSACTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_TRANSACTION.
CALL TRANSACTION 'KO01' USING GT_BDCDATA
MODE BDCMODE
MESSAGES INTO GT_MESSTAB.
* IF SYST-SUBRC <> 0.
* CALL FUNCTION 'WRITE_MESSAGE'
* EXPORTING
* MSGID = SY-MSGID
* MSGNO = SY-MSGNO
* MSGTY = SY-MSGTY
* MSGV1 = SY-MSGV1
* MSGV2 = SY-MSGV2
* MSGV3 = SY-MSGV3
* MSGV4 = SY-MSGV4
* MSGV5 = ' '
* IMPORTING
* ERROR = ERROR
* MESSG = MESSG
* MSGLN = MSGLN.
ENDFORM. " CALL_TRANSACTION
*&---------------------------------------------------------------------*
*& Form BDCDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0310 text
* -->P_0311 text
*----------------------------------------------------------------------*
FORM BDCDATA USING P_BEGIN P_FIELD1 P_FIELD2.
CLEAR GT_BDCDATA.
CASE P_BEGIN.
WHEN 'X'.
GT_BDCDATA-PROGRAM = P_FIELD1.
GT_BDCDATA-DYNPRO = P_FIELD2.
GT_BDCDATA-DYNBEGIN = 'X'.
WHEN SPACE.
GT_BDCDATA-FNAM = P_FIELD1.
GT_BDCDATA-FVAL = P_FIELD2.
ENDCASE.
APPEND GT_BDCDATA.
ENDFORM. " BDCDATA
*&---------------------------------------------------------------------*
*& Form WRITE_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM WRITE_REPORT.
DESCRIBE TABLE GT_EXISTS LINES GV_LIN.
IF GV_LIN >= 1.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'The following Internal Orders already exist.' '' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
LOOP AT GT_EXISTS.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GT_EXISTS-AUFNR '' '' ''.
ENDLOOP.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
ENDIF.
DESCRIBE TABLE GT_PRFT_CNTR LINES GV_LIN.
IF GV_LIN >= 1.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'The following Profit centers do not exist.' '' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'Internal Order Profit Center.' '' '' ''.
LOOP AT GT_PRFT_CNTR.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GT_PRFT_CNTR-AUFNR
GT_PRFT_CNTR-PRCTR '' ''.
ENDLOOP.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
ENDIF.
DESCRIBE TABLE GT_SUBMIT LINES GV_LIN.
IF GV_LIN >= 1.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'BDC was created for the following Internal Orders.'
'' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
LOOP AT GT_SUBMIT.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GT_SUBMIT-AUFNR '' '' ''.
ENDLOOP.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
ENDIF.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'The following Internal Orders have no Business Area.'
'' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
DELETE GT_TABLE WHERE NOT GSBER = ' '.
LOOP AT GT_TABLE.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GT_TABLE-AUFNR '' '' ''.
ENDLOOP.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
ENDFORM. " WRITE_REPORT
*&---------------------------------------------------------------------*
*& Form COLLECT_MESSAGES
*&---------------------------------------------------------------------*
* Collects messgaes into rep tree table and writes them to
* screen for regular reporting
*----------------------------------------------------------------------*
* -->P_MSGID message id
* -->P_MSGTY messgae type
* -->P_MSGNR msg number
* -->P_MSG1 text 1
* -->P_MSG2 text 2
* -->P_MSG3 text 3
* -->P_MSG4 text 4
*----------------------------------------------------------------------*
FORM COLLECT_MESSAGES USING P_MSGID
P_MSGTY
P_MSGNR
P_MSGV1
P_MSGV2
P_MSGV3
P_MSGV4.
CLEAR GT_IMESG.
GT_IMESG-ARBGB = P_MSGID.
GT_IMESG-MSGTY = P_MSGTY.
GT_IMESG-TXTNR = P_MSGNR.
GT_IMESG-MSGV1+0(2) = '@ '.
GT_IMESG-MSGV1+2(48) = P_MSGV1.
GT_IMESG-MSGV2 = P_MSGV2.
GT_IMESG-MSGV3 = P_MSGV3.
GT_IMESG-MSGV4 = P_MSGV4.
APPEND GT_IMESG.
CONCATENATE P_MSGV1 P_MSGV2 P_MSGV3 P_MSGV4
INTO GV_C170 SEPARATED BY SPACE.
WRITE:/ GV_C170.
ENDFORM. " collect_messages
在实施中,很多开发顾问都忽略了BDC的日志和出错管理。这给用户在使用中带来了很大的不便。比如:哪些数据是成功生成的,哪些是失败的?那些失败的,原因的是什么?程序问题还是数据问题?
我觉得,既然是要做一套程序,那就应该尽可能地为客户考虑,减少日后的维护量。对于BDC程序来讲,日志和出错管理应该是必备的。
下面讲一下,BDC的两种通用写法。
1. Call Transaction: 顾名思义,就是直接调用BDC进行数据批量导入。优点:方便快捷,程序处理方便。缺点:日志管理能力差,需自己建透明表来维护数据。我只是把它用作测试用途,不做正式使用。
2. BDC Insert:这是一种不直接运行,而是将BDC程序生成session,间接运行的一种方法。优点:通过T-code SM35可以进行运行管理及日志管理,方便查错。缺点:相对方法1来说实现起来比较繁琐。我主要是用这种方法来实现BDC功能。
下面主要来谈一下BDC Insert这种方法。
1. 需要在程序中调用 function 'BDC_INSERT'来把BDCDATA生成SESSION.
2. 程序RSBDCSUB是执行SESSION的专用程序,要建立相应的VARIANT,后续建立JOB中使用
3. 建立BATCH JOB来定期执行RSBDCSUB,从而实现,SESSION自动执行的目的
4. 当然,不使用程序RSBDCSUB和JOB,每次手工在SM35中执行SESSION也是可以的
下面是我写的一个实例:
*----------------------------------------------------------------------*
* Program Name: Z_KEVIN_ADV_BDC
* Project : N/A
* Author : Kevin.Zhang
* Date : 2007.1.1
* Module : N/A
* Description : Advanced BDC
*
*
*
* Special features: N/A
*
*
*----------------------------------------------------------------------*
* Modifications:
* Author Date Commented as Description
*----------- -------- ----------- ----------------------------------*
*
*----------------------------------------------------------------------*
REPORT Z_KEVIN_ADV_BDC.
*$*$----------------------------------------------------------------$*$*
*$*$ Global Types, Data Statements, Ranges, Constants $*$*
*$*$----------------------------------------------------------------$*$*
*-----------------------------------------------------------------------
* Tables
*-----------------------------------------------------------------------
TABLES: COAS, CEPC.
*-----------------------------------------------------------------------
* Internal Tables and Work Areas
*-----------------------------------------------------------------------
DATA: BEGIN OF GT_TABLE OCCURS 0, "internal order table
AUART LIKE AUFK-AUART, "order type
AUFNR LIKE AUFK-AUFNR, "order number
KTEXT LIKE AUFK-KTEXT, "description
BUKRS LIKE AUFK-BUKRS, "company code
GSBER LIKE AUFK-GSBER, "business area
PRCTR LIKE AUFK-PRCTR, "profit center
FUNCA LIKE AUFK-FUNC_AREA, "function area
END OF GT_TABLE.
DATA: BEGIN OF GT_EXISTS OCCURS 0. "existed IO
INCLUDE STRUCTURE GT_TABLE.
DATA: END OF GT_EXISTS.
DATA: BEGIN OF GT_PRFT_CNTR OCCURS 0."the profit center not existing IO
INCLUDE STRUCTURE GT_TABLE.
DATA: END OF GT_PRFT_CNTR.
DATA: BEGIN OF GT_SUBMIT OCCURS 0. "the submitted IO
INCLUDE STRUCTURE GT_TABLE.
DATA: END OF GT_SUBMIT.
DATA: BEGIN OF GT_BDCDATA OCCURS 0. "BDC DATA
INCLUDE STRUCTURE BDCDATA.
DATA: END OF GT_BDCDATA.
DATA: BEGIN OF GT_MESSTAB OCCURS 10. "message table
INCLUDE STRUCTURE BDCMSGCOLL.
DATA: END OF GT_MESSTAB.
DATA: GT_IMESG LIKE MESG OCCURS 0 WITH HEADER LINE.
*-----------------------------------------------------------------------
* Variables
*-----------------------------------------------------------------------
DATA: GV_GROUP(12) TYPE C VALUE 'INTERNAL_ORD', "BDC Name
GV_USER(12) TYPE C, "BDC User
GV_KEEP(1) TYPE C VALUE 'X', " ' '=Delete,'X'=keep after processing
GV_HOLDDATE LIKE SY-DATUM. "Date
DATA: GV_FLAG(1) TYPE C,
GV_LIN TYPE I. "number of orders
DATA: GV_C170(170),
GV_C_ULINE(50) VALUE '__________________________________________________'.
*$*$----------------------------------------------------------------$*$*
*$*$ Selection Screen $*$*
*$*$----------------------------------------------------------------$*$*
*-----------------------------------------------------------------------
* Selection Screen
*-----------------------------------------------------------------------
PARAMETERS: BDCTYPE(1) TYPE C DEFAULT 'B' NO-DISPLAY,
BDCMODE LIKE BDCRUN-BDC_AMODUS DEFAULT 'A' NO-DISPLAY.
SELECTION-SCREEN COMMENT 10(70) TEXT-001.
PARAMETERS: IN_FILE(128) DEFAULT 'C:\TEMP\*.txt'.
SELECTION-SCREEN SKIP 1.
*-----------------------------------------------------------------------
* At Selection Screen
*-----------------------------------------------------------------------
*--------- AT SELECTION-SCREEN ON VALUE-REQUEST ----------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR IN_FILE.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = '*.txt'
DEF_PATH = 'C:\DATA'
MASK = ',All Files,*.*,Text Files,*.txt;*.doc.'
MODE = 'O'
TITLE = 'Please choose file to use '
IMPORTING
FILENAME = IN_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
*$*$----------------------------------------------------------------$*$*
*$*$ Main Program $*$*
*$*$----------------------------------------------------------------$*$*
*--------- START-OF-SELECTION ----------
START-OF-SELECTION.
REFRESH GT_TABLE.
* Uploading the data which will be inserted into the internal table
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = IN_FILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = GT_TABLE
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5
NO_BATCH = 6
UNKNOWN_ERROR = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'Unable to upload input file '
IN_FILE '' ''.
ENDIF.
SORT GT_TABLE BY AUFNR GSBER DESCENDING.
DELETE ADJACENT DUPLICATES FROM GT_TABLE COMPARING AUFNR.
PERFORM OPEN_GROUP.
PERFORM FILL_BDC_DATA.
PERFORM BDC_CLOSE_GROUP.
PERFORM WRITE_REPORT.
*--------- END-OF-SELECTION ----------
*$*$----------------------------------------------------------------$*$*
*$*$ Subroutines $*$*
*$*$----------------------------------------------------------------$*$*
*&---------------------------------------------------------------------*
*& Form OPEN_GROUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM OPEN_GROUP.
GV_USER = SY-UNAME.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = GV_GROUP
HOLDDATE = GV_HOLDDATE
KEEP = GV_KEEP
USER = GV_USER.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " OPEN_GROUP
*&---------------------------------------------------------------------*
*& Form FILL_BDC_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FILL_BDC_DATA.
CLEAR GT_TABLE.
LOOP AT GT_TABLE.
CLEAR GT_MESSTAB.
CLEAR GT_BDCDATA.
REFRESH GT_BDCDATA.
REFRESH GT_MESSTAB.
CLEAR GV_FLAG.
* Check if Profit Center exists.
SELECT SINGLE * FROM CEPC
WHERE PRCTR = GT_TABLE-PRCTR.
IF SY-SUBRC <> 0.
CLEAR GT_PRFT_CNTR.
MOVE-CORRESPONDING GT_TABLE TO GT_PRFT_CNTR.
APPEND GT_PRFT_CNTR.
GV_FLAG = 'X'.
ENDIF.
* check if Internal Order has already been created.
SELECT SINGLE * FROM COAS
WHERE AUFNR = GT_TABLE-AUFNR.
IF SY-SUBRC = 0.
CLEAR GT_EXISTS.
MOVE-CORRESPONDING GT_TABLE TO GT_EXISTS.
APPEND GT_EXISTS.
GV_FLAG = 'X'.
ENDIF.
IF GV_FLAG <> 'X'.
PERFORM BDCDATA USING: 'X' 'SAPMKAUF' '0100', "order type
' ' 'COAS-AUART' GT_TABLE-AUART,
' ' 'BDC_OKCODE' '=KOKR'.
PERFORM BDCDATA USING: 'X' 'SAPLSPO4' '0300', "control area
' ' 'SVALD-VALUE(01)' '1000',
' ' 'BDC_OKCODE' '=FURT'.
PERFORM BDCDATA USING: 'X' 'SAPMKAUF' '0100', "ok code
' ' 'BDC_OKCODE' '/00'.
PERFORM BDCDATA USING: 'X' 'SAPMKAUF' '0600', "order master data
' ' 'COAS-AUFNR' GT_TABLE-AUFNR,
' ' 'COAS-KTEXT' GT_TABLE-KTEXT,
' ' 'COAS-BUKRS' GT_TABLE-BUKRS,
' ' 'COAS-GSBER' GT_TABLE-GSBER,
' ' 'COAS-PRCTR' GT_TABLE-PRCTR,
' ' 'COAS-FUNC_AREA' GT_TABLE-FUNCA,
' ' 'BDC_OKCODE' '=SICH'.
* PERFORM CALL_TRANSACTION. "for test purpose
PERFORM BDC_INSERT.
MOVE-CORRESPONDING GT_TABLE TO GT_SUBMIT.
APPEND GT_SUBMIT.
ENDIF.
ENDLOOP.
ENDFORM. " FILL_BDC_DATA
*&---------------------------------------------------------------------*
*& Form BDC_INSERT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_INSERT.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'KO01'
TABLES
DYNPROTAB = GT_BDCDATA.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " BDC_INSERT
*&---------------------------------------------------------------------*
*& Form BDC_CLOSE_GROUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM BDC_CLOSE_GROUP.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " BDC_CLOSE_GROUP
*&---------------------------------------------------------------------*
*& Form CALL_TRANSACTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_TRANSACTION.
CALL TRANSACTION 'KO01' USING GT_BDCDATA
MODE BDCMODE
MESSAGES INTO GT_MESSTAB.
* IF SYST-SUBRC <> 0.
* CALL FUNCTION 'WRITE_MESSAGE'
* EXPORTING
* MSGID = SY-MSGID
* MSGNO = SY-MSGNO
* MSGTY = SY-MSGTY
* MSGV1 = SY-MSGV1
* MSGV2 = SY-MSGV2
* MSGV3 = SY-MSGV3
* MSGV4 = SY-MSGV4
* MSGV5 = ' '
* IMPORTING
* ERROR = ERROR
* MESSG = MESSG
* MSGLN = MSGLN.
ENDFORM. " CALL_TRANSACTION
*&---------------------------------------------------------------------*
*& Form BDCDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0310 text
* -->P_0311 text
*----------------------------------------------------------------------*
FORM BDCDATA USING P_BEGIN P_FIELD1 P_FIELD2.
CLEAR GT_BDCDATA.
CASE P_BEGIN.
WHEN 'X'.
GT_BDCDATA-PROGRAM = P_FIELD1.
GT_BDCDATA-DYNPRO = P_FIELD2.
GT_BDCDATA-DYNBEGIN = 'X'.
WHEN SPACE.
GT_BDCDATA-FNAM = P_FIELD1.
GT_BDCDATA-FVAL = P_FIELD2.
ENDCASE.
APPEND GT_BDCDATA.
ENDFORM. " BDCDATA
*&---------------------------------------------------------------------*
*& Form WRITE_REPORT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM WRITE_REPORT.
DESCRIBE TABLE GT_EXISTS LINES GV_LIN.
IF GV_LIN >= 1.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'The following Internal Orders already exist.' '' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
LOOP AT GT_EXISTS.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GT_EXISTS-AUFNR '' '' ''.
ENDLOOP.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
ENDIF.
DESCRIBE TABLE GT_PRFT_CNTR LINES GV_LIN.
IF GV_LIN >= 1.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'The following Profit centers do not exist.' '' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'Internal Order Profit Center.' '' '' ''.
LOOP AT GT_PRFT_CNTR.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GT_PRFT_CNTR-AUFNR
GT_PRFT_CNTR-PRCTR '' ''.
ENDLOOP.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
ENDIF.
DESCRIBE TABLE GT_SUBMIT LINES GV_LIN.
IF GV_LIN >= 1.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'BDC was created for the following Internal Orders.'
'' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
LOOP AT GT_SUBMIT.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GT_SUBMIT-AUFNR '' '' ''.
ENDLOOP.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
ENDIF.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
'The following Internal Orders have no Business Area.'
'' '' ''.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
DELETE GT_TABLE WHERE NOT GSBER = ' '.
LOOP AT GT_TABLE.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GT_TABLE-AUFNR '' '' ''.
ENDLOOP.
PERFORM COLLECT_MESSAGES USING 'Z3' 'I' '000'
GV_C_ULINE '' '' ''.
ENDFORM. " WRITE_REPORT
*&---------------------------------------------------------------------*
*& Form COLLECT_MESSAGES
*&---------------------------------------------------------------------*
* Collects messgaes into rep tree table and writes them to
* screen for regular reporting
*----------------------------------------------------------------------*
* -->P_MSGID message id
* -->P_MSGTY messgae type
* -->P_MSGNR msg number
* -->P_MSG1 text 1
* -->P_MSG2 text 2
* -->P_MSG3 text 3
* -->P_MSG4 text 4
*----------------------------------------------------------------------*
FORM COLLECT_MESSAGES USING P_MSGID
P_MSGTY
P_MSGNR
P_MSGV1
P_MSGV2
P_MSGV3
P_MSGV4.
CLEAR GT_IMESG.
GT_IMESG-ARBGB = P_MSGID.
GT_IMESG-MSGTY = P_MSGTY.
GT_IMESG-TXTNR = P_MSGNR.
GT_IMESG-MSGV1+0(2) = '@ '.
GT_IMESG-MSGV1+2(48) = P_MSGV1.
GT_IMESG-MSGV2 = P_MSGV2.
GT_IMESG-MSGV3 = P_MSGV3.
GT_IMESG-MSGV4 = P_MSGV4.
APPEND GT_IMESG.
CONCATENATE P_MSGV1 P_MSGV2 P_MSGV3 P_MSGV4
INTO GV_C170 SEPARATED BY SPACE.
WRITE:/ GV_C170.
ENDFORM. " collect_messages
发表评论
-
SAP ABAP 点滴记录
2010-04-30 14:56 2315SAP ABAP 点滴记录 Post By:2009-6- ... -
SAP数据库表
2010-04-30 14:51 1592SAP数据库表 SAP词典包含了4种类型的表(或结构): ... -
ABAP常用fuction
2010-04-30 14:49 1203ABAP常用fuction Post By:2009-7- ... -
sap 增强
2010-04-30 14:37 1650sap的用户出口总共有三代: 1、第一代 sap提供 ... -
ABAP简介
2010-04-30 10:31 1266一:什么是ABAP。 定义 ... -
ABAP中去掉前导零问题
2010-04-30 10:03 1825ABAP中去掉前导零问题 1.可以调用CONVERSION_ ... -
常用的字符串处理函数
2010-04-30 09:36 15121. 在字符串前補0. (如果p_input的位數未滿,則會於 ... -
ABAP日期格式轉換
2010-04-30 09:32 2364ABAP日期格式轉換 =================== ... -
常用的字符串操作
2010-04-30 09:23 1049CONCATENATE 连接字符串 [SEPARATED BY ... -
设置SAP GUI Status的按钮为灰色
2010-04-29 14:16 2184设置SAP GUI Status的按钮为灰色 一,首先设置 ... -
ABAP常用字符串操作
2010-04-29 13:19 1628ABAP常用字符串操作 字符串首字符索引为 0; Ch ... -
ABAP 筑基宝典
2010-04-29 12:50 1554ABAP 筑基宝典(5) -- 关于使用READ TABLE语 ... -
内部表行数de三种统计方法
2010-04-29 09:48 922内部表行数统计方法: 1.LOOP AT itab. ... -
ABAP开发语言
2010-04-29 09:38 22342.第二部分 ABAP开发语言 ... -
ABAP学习笔记--处理字符串
2010-04-27 17:01 1986一、移动字段内容 1、按给定位置数移动字符串 语法:SH ... -
3.1 FIELD-SYMBOLS
2010-04-13 19:32 1371FIELD-SYMBOLS是字段符号,类似于FOXPRO的宏, ...
相关推荐
#### 知识点二:ABAP BDC 导入的例子详解 本例中展示的是一个名为 `ZTFPPDCI0001` 的ABAP程序,该程序主要用于周计划的批量导入。 ##### 1. 程序基本信息 - **Program ID** (程序ID): PP0018 - **Program Name** ...
- **ABAP Workbench**:ABAP的主要开发环境,提供了完整的工具集来支持ABAP程序的开发、调试和部署。 - **ABAP Dictionary**:ABAP Dictionary是SAP系统中存储所有数据元素和表定义的地方,是开发ABAP程序的基础。 ...
- **特点**: ABAP不仅是一种编程语言,还包含了完整的客户端/服务器开发环境。该环境提供了丰富的API和工具,支持开发者进行高效开发。 ##### 2. ABAP开发环境的建立 - **安装**: 需要在SAP系统中安装相应的开发...
- **BDC (BATCH INPUT)**:通过ABAP代码实现数据导入。 - **LSMW**:适用于大规模数据录入,步骤详尽,确保数据完整性。 综上所述,ABAP不仅是一门语言,更是集成了多种开发工具和技术的生态系统,覆盖了从简单报表...
#### 二、ABAP开发总体介绍 ABAP开发主要包括以下方面: 1. **报表开发**: - 技术要点:数据库读取、ALV(SAP List Viewer)、LIST等技术。 - **应用场景**:用于生成报告和数据列表。 2. **单据打印**: - ...
ABAP代码通常包括`CALL TRANSACTION`语句来调用SAP事务,`BDC_OPEN`、`BDC_INSERT`等函数来处理数据导入,以及`BDC_CLOSE`来结束会话。 6. **运行BDC程序**: 完成程序编写后,可以将其上传到SAP系统并在后台运行...
BDC的核心在于通过SHDB事务码来记录用户的一次完整业务操作流程,包括事务代码输入、屏幕字段的光标位置、输入的值以及执行的按钮。这一过程被记录为一个模板,后续通过编程调用,可以按照这个模板重复执行相同的...
3. **编写程序**:在SE38中编写调用BDC脚本的ABAP程序。 4. **执行程序**:运行ABAP程序执行批量操作。 ##### 第二节 SHDB 录制屏幕 1. **启动事务代码**:使用`SHDB`启动屏幕录制工具。 2. **指定录制类型**:...