首先, 解释BDC这三个英文的意思, 普遍都认同是(
Batch Data Communication ). 然后下面是一些相关的术语解释:
Batch Input : 批输入, 用于大批量, 非实时性( 对速度要求比较低) 的数据传输 使用BDC_OPEN_GROUP, BDC_INSERT_GROUP, BDC_CLOSE_GROUP这几个function实现批输入会话的操作. 然后通过批输入会话将数据传输到SAP.
Call Transaction : 调用事务, 与批输入的差异主要是在于数据传输过程不生成批输入会话, 数据在程序运行过程中直接通过调用CALL TRANSACTION USING BDC表传输至SAP.
Direct Input : 直接输入, 其主要优点是速度最快, 不生成会话, 数据被直接输入至SAP. 不存在事务屏幕处理过程(批输入和调用事务中均包含该过程), 直接输入的效率较高, 系统负载较小. 使用TCODE BMV0.
但是我们不该把BDC技术只局限于录屏幕, 批输入和调用事务上, 其实以下技术都可以实现BDC, 比如BAPI, IDOC.
BAPI : 业务应用程序接口, SAP作为一个完善的系统, 每个应用中都有包含标准的数据传输接口.
IDOC : 中间文档, ALE和EDI属于系统间数据传输的接口, IDOC中包含数据结构的定义和数据的处理逻辑, 是传输的介质.
这个图参照了黄佳写的<<SAP业务数据传输指南>>. 下面我来详细举例一下其中几种技术.
一, 调用事务, 主要使用该语句
CALL TRANSACTION '事务代码' USING bdc表 MODE m UPDATE 'S' MESSAGES INTO mssg.
bdc表是参考bdcdata结构定义的内表, 主要存储屏幕处理所需要的关键数据, 其结构如下:
字段名 类型 长度 小数 描述 PROGRAM CHAR 40 0 BDC module pool DYNPRO NUMC 4 0 BDC Screen number DYNBEGIN CHAR 1 0 BDC screen start FNAM CHAR 132 0 Field name FVAL CHAR 132 0 BDC field value
MODE m 是指Processing Mode, 共有4种处理模式:
模式 英文描述 A Display all screens E Display errors N Background processing P Background processing; debugging possible
UPDATE 'S' 是指更新模式, 共有3种更新模式,一般使用'S'模式:
MESSAGES INTO mssg 的意思是将处理信息导入到一个参考bdcmsgcoll结构的内表, 方便查错.
下面是一个上传物料中文描述的简单例子:
view plaincopy to clipboardprint?
*&---------------------------------------------------------------------* *& Report ZBDC_TEST1 *& 调用事务 *&---------------------------------------------------------------------* *& Author: Jun *& *&---------------------------------------------------------------------* REPORT zbdc_test1. ************************************************************************ * D A T A ************************************************************************ CONSTANTS: c_def_path LIKE rlgrap-filename VALUE 'c:\file.txt' . DATA: BEGIN OF mssg OCCURS 0. INCLUDE STRUCTURE bdcmsgcoll. DATA: END OF mssg. DATA: BEGIN OF zitab_bdc OCCURS 0. INCLUDE STRUCTURE bdcdata. DATA: END OF zitab_bdc. DATA: BEGIN OF t_main OCCURS 0, matnr(18), maktx(40), END OF t_main. DEFINE dynpro. CLEAR zitab_bdc. IF &1 = 'X' . MOVE: 'X' TO zitab_bdc-dynbegin, &2 TO zitab_bdc-program, &3 TO zitab_bdc-dynpro. ELSE. MOVE: &2 TO zitab_bdc-fnam, &3 TO zitab_bdc-fval. ENDIF. APPEND zitab_bdc. END-OF-DEFINITION. SELECTION-SCREEN BEGIN OF BLOCK sc1 WITH FRAME TITLE text-s01. PARAMETER: f_cap TYPE rlgrap-filename OBLIGATORY DEFAULT c_def_path. PARAMETER: m TYPE ctu_mode DEFAULT 'N' . SELECTION-SCREEN END OF BLOCK sc1. ************************************************************************ * S T A R T O F S E L E C T I O N ************************************************************************ START-OF-SELECTION. WRITE : / 'Start creation of BDC session' ,sy-mandt,sy-uname,sy-uzeit. PERFORM get_codepage. PERFORM call_upload TABLES t_main USING f_cap. PERFORM update_data. WRITE: / 'Finished!' . ************************************************************************ * F O R M S ************************************************************************ *&---------------------------------------------------------------------* *& *& Form GET_CODEPAGE *&---------------------------------------------------------------------* FORM get_codepage. DATA: cncoden TYPE abap_encod, cncode type CPCODEPAGE. CALL FUNCTION 'NLS_GET_FRONTEND_CP' EXPORTING langu = '1' IMPORTING frontend_codepage = cncode EXCEPTIONS illegal_syst_codepage = 21 no_frontend_cp_found = 23 internal_or_db_error = 25. MOVE: cncode TO cncoden. ENDFORM. *&---------------------------------------------------------------------* *& *& Form CALL_UPLOAD *&---------------------------------------------------------------------* FORM call_upload TABLES p_tab USING p_fname. DATA: tmp_filename TYPE string . tmp_filename = p_fname. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = tmp_filename write_field_separator = 'X' codepage = cncoden CHANGING data_tab = p_tab EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 OTHERS = 24. 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. "call_upload *&---------------------------------------------------------------------* *& Form update_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM update_data. REFRESH zitab_bdc. LOOP AT t_main. PERFORM call_transaction. ENDLOOP. ENDFORM. "update_data *&---------------------------------------------------------------------* *& Form call_transaction *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM call_transaction. dynpro: 'X' 'SAPLMGMM' '0060' , ' ' 'RMMG1-MATNR' t_main-matnr, ' ' 'BDC_OKCODE' '/00' . dynpro: 'X' 'SAPLMGMM' '0070' , ' ' 'MSICHTAUSW-KZSEL(01)' 'X' , ' ' 'BDC_OKCODE' '=ENTR' . dynpro: 'X' 'SAPLMGMM' '4004' , ' ' 'BDC_OKCODE' '=ZU01' . dynpro: 'X' 'SAPLMGMM' '4300' , ' ' 'SKTEXT-SPRAS(02)' 'ZH' , ' ' 'SKTEXT-MAKTX(02)' t_main-maktx, ' ' 'BDC_OKCODE' '=BU' . CALL TRANSACTION 'MM02' USING zitab_bdc MODE m UPDATE 'S' MESSAGES INTO mssg. IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. REFRESH: zitab_bdc,mssg. ENDFORM. " CALL_TRANSACTION *&---------------------------------------------------------------------* *& Report ZBDC_TEST1 *& 调用事务 *&---------------------------------------------------------------------* *& Author: Jun *& *&---------------------------------------------------------------------* REPORT zbdc_test1. ************************************************************************ * D A T A ************************************************************************ CONSTANTS: c_def_path LIKE rlgrap-filename VALUE 'c:\file.txt'. DATA: BEGIN OF mssg OCCURS 0. INCLUDE STRUCTURE bdcmsgcoll. DATA: END OF mssg. DATA: BEGIN OF zitab_bdc OCCURS 0. INCLUDE STRUCTURE bdcdata. DATA: END OF zitab_bdc. DATA: BEGIN OF t_main OCCURS 0, matnr(18), maktx(40), END OF t_main. DEFINE dynpro. CLEAR zitab_bdc. IF &1 = 'X'. MOVE: 'X' TO zitab_bdc-dynbegin, &2 TO zitab_bdc-program, &3 TO zitab_bdc-dynpro. ELSE. MOVE: &2 TO zitab_bdc-fnam, &3 TO zitab_bdc-fval. ENDIF. APPEND zitab_bdc. END-OF-DEFINITION. SELECTION-SCREEN BEGIN OF BLOCK sc1 WITH FRAME TITLE text-s01. PARAMETER: f_cap TYPE rlgrap-filename OBLIGATORY DEFAULT c_def_path. PARAMETER: m TYPE ctu_mode DEFAULT 'N'. SELECTION-SCREEN END OF BLOCK sc1. ************************************************************************ * S T A R T O F S E L E C T I O N ************************************************************************ START-OF-SELECTION. WRITE : / 'Start creation of BDC session',sy-mandt,sy-uname,sy-uzeit. PERFORM get_codepage. PERFORM call_upload TABLES t_main USING f_cap. PERFORM update_data. WRITE: / 'Finished!'. ************************************************************************ * F O R M S ************************************************************************ *&---------------------------------------------------------------------* *& *& Form GET_CODEPAGE *&---------------------------------------------------------------------* FORM get_codepage. DATA: cncoden TYPE abap_encod, cncode type CPCODEPAGE. CALL FUNCTION 'NLS_GET_FRONTEND_CP' EXPORTING langu = '1' IMPORTING frontend_codepage = cncode EXCEPTIONS illegal_syst_codepage = 21 no_frontend_cp_found = 23 internal_or_db_error = 25. MOVE: cncode TO cncoden. ENDFORM. *&---------------------------------------------------------------------* *& *& Form CALL_UPLOAD *&---------------------------------------------------------------------* FORM call_upload TABLES p_tab USING p_fname. DATA: tmp_filename TYPE string. tmp_filename = p_fname. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = tmp_filename write_field_separator = 'X' codepage = cncoden CHANGING data_tab = p_tab EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 OTHERS = 24. 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. "call_upload *&---------------------------------------------------------------------* *& Form update_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM update_data. REFRESH zitab_bdc. LOOP AT t_main. PERFORM call_transaction. ENDLOOP. ENDFORM. "update_data *&---------------------------------------------------------------------* *& Form call_transaction *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM call_transaction. dynpro: 'X' 'SAPLMGMM' '0060', ' ' 'RMMG1-MATNR' t_main-matnr, ' ' 'BDC_OKCODE' '/00'. dynpro: 'X' 'SAPLMGMM' '0070', ' ' 'MSICHTAUSW-KZSEL(01)' 'X', ' ' 'BDC_OKCODE' '=ENTR'. dynpro: 'X' 'SAPLMGMM' '4004', ' ' 'BDC_OKCODE' '=ZU01'. dynpro: 'X' 'SAPLMGMM' '4300', ' ' 'SKTEXT-SPRAS(02)' 'ZH', ' ' 'SKTEXT-MAKTX(02)' t_main-maktx, ' ' 'BDC_OKCODE' '=BU'. CALL TRANSACTION 'MM02' USING zitab_bdc MODE m UPDATE 'S' MESSAGES INTO mssg. IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. REFRESH: zitab_bdc,mssg. ENDFORM. " CALL_TRANSACTION
二, 批输入, 主要使用BDC_OPEN_GROUP, BDC_INSERT_GROUP, BDC_CLOSE_GROUP这几个function实现批输入会话的操作. 然后通过批输入会话将数据传输到SAP.
以下是Batch Input的例子, 是把前面的程序改了一下完成的, 注意红色的地方就是不同处:
view plaincopy to clipboardprint?
*&---------------------------------------------------------------------* *& Report ZBDC_TEST2 *& 批输入 *&---------------------------------------------------------------------* *& Author: Jun *& *&---------------------------------------------------------------------* REPORT zbdc_test2. ************************************************************************ * D A T A ************************************************************************ CONSTANTS: c_def_path LIKE rlgrap-filename VALUE 'c:\file.txt' . DATA: BEGIN OF zitab_bdc OCCURS 0. INCLUDE STRUCTURE bdcdata. DATA: END OF zitab_bdc. DATA: BEGIN OF t_main OCCURS 0, matnr(18), maktx(40), END OF t_main. DEFINE dynpro. CLEAR zitab_bdc. IF &1 = 'X' . MOVE: 'X' TO zitab_bdc-dynbegin, &2 TO zitab_bdc-program, &3 TO zitab_bdc-dynpro. ELSE. MOVE: &2 TO zitab_bdc-fnam, &3 TO zitab_bdc-fval. ENDIF. APPEND zitab_bdc. END-OF-DEFINITION. SELECTION-SCREEN BEGIN OF BLOCK sc1 WITH FRAME TITLE text-s01. PARAMETER: f_cap TYPE rlgrap-filename OBLIGATORY DEFAULT c_def_path. SELECTION-SCREEN END OF BLOCK sc1. ************************************************************************ * S T A R T O F S E L E C T I O N ************************************************************************ START-OF-SELECTION. WRITE : / 'Start creation of BDC session' ,sy-mandt,sy-uname,sy-uzeit. PERFORM get_codepage. PERFORM call_upload TABLES t_main USING f_cap. PERFORM update_data. WRITE: / 'Finished!' . ************************************************************************ * F O R M S ************************************************************************ *&---------------------------------------------------------------------* *& *& Form GET_CODEPAGE *&---------------------------------------------------------------------* FORM get_codepage. DATA: cncoden TYPE abap_encod, cncode type CPCODEPAGE. CALL FUNCTION 'NLS_GET_FRONTEND_CP' EXPORTING langu = '1' IMPORTING frontend_codepage = cncode EXCEPTIONS illegal_syst_codepage = 21 no_frontend_cp_found = 23 internal_or_db_error = 25. MOVE: cncode TO cncoden. ENDFORM. *&---------------------------------------------------------------------* *& *& Form CALL_UPLOAD *&---------------------------------------------------------------------* FORM call_upload TABLES p_tab USING p_fname. DATA: tmp_filename TYPE string . tmp_filename = p_fname. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = tmp_filename write_field_separator = 'X' codepage = cncoden CHANGING data_tab = p_tab EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 OTHERS = 24. 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. "call_upload *&---------------------------------------------------------------------* *& Form update_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM update_data. <font color="#ff0000" > CALL FUNCTION 'BDC_OPEN_GROUP' EXPORTING CLIENT = SY-MANDT GROUP = P_S_NAME KEEP = 'X' USER = SY-UNAME EXCEPTIONS CLIENT_INVALID = 1 DESTINATION_INVALID = 2 GROUP_INVALID = 3 GROUP_IS_LOCKED = 4 HOLDDATE_INVALID = 5 INTERNAL_ERROR = 6 QUEUE_ERROR = 7 RUNNING = 8 SYSTEM_LOCK_ERROR = 9 USER_INVALID = 10 OTHERS = 11.</font> *&---------------------------------------------------------------------* *& Report ZBDC_TEST2 *& 批输入 *&---------------------------------------------------------------------* *& Author: Jun *& *&---------------------------------------------------------------------* REPORT zbdc_test2. ************************************************************************ * D A T A ************************************************************************ CONSTANTS: c_def_path LIKE rlgrap-filename VALUE 'c:\file.txt'. DATA: BEGIN OF zitab_bdc OCCURS 0. INCLUDE STRUCTURE bdcdata. DATA: END OF zitab_bdc. DATA: BEGIN OF t_main OCCURS 0, matnr(18), maktx(40), END OF t_main. DEFINE dynpro. CLEAR zitab_bdc. IF &1 = 'X'. MOVE: 'X' TO zitab_bdc-dynbegin, &2 TO zitab_bdc-program, &3 TO zitab_bdc-dynpro. ELSE. MOVE: &2 TO zitab_bdc-fnam, &3 TO zitab_bdc-fval. ENDIF. APPEND zitab_bdc. END-OF-DEFINITION. SELECTION-SCREEN BEGIN OF BLOCK sc1 WITH FRAME TITLE text-s01. PARAMETER: f_cap TYPE rlgrap-filename OBLIGATORY DEFAULT c_def_path. SELECTION-SCREEN END OF BLOCK sc1. ************************************************************************ * S T A R T O F S E L E C T I O N ************************************************************************ START-OF-SELECTION. WRITE : / 'Start creation of BDC session',sy-mandt,sy-uname,sy-uzeit. PERFORM get_codepage. PERFORM call_upload TABLES t_main USING f_cap. PERFORM update_data. WRITE: / 'Finished!'. ************************************************************************ * F O R M S ************************************************************************ *&---------------------------------------------------------------------* *& *& Form GET_CODEPAGE *&---------------------------------------------------------------------* FORM get_codepage. DATA: cncoden TYPE abap_encod, cncode type CPCODEPAGE. CALL FUNCTION 'NLS_GET_FRONTEND_CP' EXPORTING langu = '1' IMPORTING frontend_codepage = cncode EXCEPTIONS illegal_syst_codepage = 21 no_frontend_cp_found = 23 internal_or_db_error = 25. MOVE: cncode TO cncoden. ENDFORM. *&---------------------------------------------------------------------* *& *& Form CALL_UPLOAD *&---------------------------------------------------------------------* FORM call_upload TABLES p_tab USING p_fname. DATA: tmp_filename TYPE string. tmp_filename = p_fname. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING filename = tmp_filename write_field_separator = 'X' codepage = cncoden CHANGING data_tab = p_tab EXCEPTIONS file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 OTHERS = 24. 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. "call_upload *&---------------------------------------------------------------------* *& Form update_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM update_data. view plaincopy to clipboardprint?
<font color="#ff0000" > IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. </font> REFRESH zitab_bdc. LOOP AT t_main. PERFORM batch_input. ENDLOOP. <font color="#ff0000" > CALL FUNCTION 'BDC_CLOSE_GROUP' EXCEPTIONS NOT_OPEN = 1 QUEUE_ERROR = 2 OTHERS = 3. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. </font> ENDFORM. "update_data *&---------------------------------------------------------------------* *& Form batch_input *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM batch_input. dynpro: 'X' 'SAPLMGMM' '0060' , ' ' 'RMMG1-MATNR' t_main-matnr, ' ' 'BDC_OKCODE' '/00' . dynpro: 'X' 'SAPLMGMM' '0070' , ' ' 'MSICHTAUSW-KZSEL(01)' 'X' , ' ' 'BDC_OKCODE' '=ENTR' . dynpro: 'X' 'SAPLMGMM' '4004' , ' ' 'BDC_OKCODE' '=ZU01' . dynpro: 'X' 'SAPLMGMM' '4300' , ' ' 'SKTEXT-SPRAS(02)' 'ZH' , ' ' 'SKTEXT-MAKTX(02)' t_main-maktx, ' ' 'BDC_OKCODE' '=BU' . <font color="#ff0000" > CALL FUNCTION 'BDC_INSERT' EXPORTING TCODE = 'MM02' TABLES DYNPROTAB = zitab_bdc EXCEPTIONS INTERNAL_ERROR = 1 NOT_OPEN = 2 QUEUE_ERROR = 3 TCODE_INVALID = 4 PRINTING_INVALID = 5 POSTING_INVALID = 6 OTHERS = 7. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.</font> REFRESH: zitab_bdc. ENDFORM. REFRESH zitab_bdc. LOOP AT t_main. PERFORM batch_input. ENDLOOP. ENDFORM. "update_data *&---------------------------------------------------------------------* *& Form batch_input *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM batch_input. dynpro: 'X' 'SAPLMGMM' '0060', ' ' 'RMMG1-MATNR' t_main-matnr, ' ' 'BDC_OKCODE' '/00'. dynpro: 'X' 'SAPLMGMM' '0070', ' ' 'MSICHTAUSW-KZSEL(01)' 'X', ' ' 'BDC_OKCODE' '=ENTR'. dynpro: 'X' 'SAPLMGMM' '4004', ' ' 'BDC_OKCODE' '=ZU01'. dynpro: 'X' 'SAPLMGMM' '4300', ' ' 'SKTEXT-SPRAS(02)' 'ZH', ' ' 'SKTEXT-MAKTX(02)' t_main-maktx, ' ' 'BDC_OKCODE' '=BU'. REFRESH: zitab_bdc. ENDFORM. 三, BAPI是SAP标准的API, 在多系统的环境下,我们可以通过ALE/EDI技术使用RFC和BAPI实现数据传输工作. 但是也可以自己编写程序实现本地执行传输工作. 下面是一个使用BAPI传输PO的例子: view plaincopy to clipboardprint?
<pre class ="csharp" name="code" >*&---------------------------------------------------------------------* *& Report ZCON0026 *& *&---------------------------------------------------------------------* *& Author: Jun *& *&---------------------------------------------------------------------* REPORT ZCON0026. FIELD-SYMBOLS : <fs></fs>. <font color="#ff0000" >DATA:wa_pohead TYPE bapimepoheader. DATA:wa_poheadx TYPE bapimepoheaderx. DATA:wa_poaddrvendor TYPE bapimepoaddrvendor. DATA:wa_testrun TYPE bapiflag-bapiflag.</font> DATA:g_ebeln TYPE ekko-ebeln. "Purchasing Document Header DATA:g_mtart TYPE mtart. <font color="#ff0000" >DATA:it_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE. DATA:it_msg TYPE bapiret2 OCCURS 0 WITH HEADER LINE.</font> DATA:BEGIN OF it_msg1 OCCURS 0, ebeln LIKE ekpo-ebeln, type like bapiret2-type, message LIKE bapiret2-message, old_po like ekpo-ebeln, END OF it_msg1. <font color="#ff0000" >DATA:it_poitem TYPE bapimepoitem OCCURS 0 WITH HEADER LINE. DATA:it_poitemx TYPE bapimepoitemx OCCURS 0 WITH HEADER LINE. DATA:it_pocondh TYPE bapimepocondheader OCCURS 0 WITH HEADER LINE. DATA:it_pocondhx TYPE bapimepocondheaderx OCCURS 0 WITH HEADER LINE. DATA:it_pocond TYPE bapimepocond OCCURS 0 WITH HEADER LINE. DATA:it_pocondx TYPE bapimepocondx OCCURS 0 WITH HEADER LINE. DATA:it_potexth TYPE bapimepotextheader OCCURS 0 WITH HEADER LINE. DATA:it_potexti TYPE bapimepotext OCCURS 0 WITH HEADER LINE. DATA:it_popartner TYPE bapiekkop OCCURS 0 WITH HEADER LINE. DATA:it_extens TYPE bapiparex OCCURS 0 WITH HEADER LINE. "Customer's Own Fields DATA:it_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE. DATA:it_poaccountx TYPE bapimepoaccountx OCCURS 0 WITH HEADER LINE. DATA:it_poche TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE. DATA:it_pochex TYPE bapimeposchedulx OCCURS 0 WITH HEADER LINE. DATA:purchseorder TYPE BAPIMEPOHEADER-PO_NUMBER.</font> DATA:g_poitem TYPE ebelp. "Item Number of Purchasing Document DATA:g_meng LIKE ekpo-menge. "Purchase Order Quantity DATA:l_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE. DATA:len_str TYPE i, l_index TYPE i. DATA:BEGIN OF it_data OCCURS 0, * doc_type(004), </pre> <pre class ="csharp" name="code" > po(010), "PO NO material(018), vendor(010), invoice_no(15), "Invoice Number(Header text) pmnttrms(004), "Paymentterms quantity(017), doc_date(008), gr_to_date(008), "Delivery date shippingin(10), "Ship Date(Header Text) eta_hk(10), "Date of ETA HK(Header Text) trsp_metd(10), "Transportion Method(Header Text) container_no(20), "COntainer Number(Header Text) lc_number(20), "LC Number(Header Text) load_date(10), "Load Date(Header Text) arr_hk(10), "Date of Arr. Date(Header Text) remark(20), "Header remark(Header Text) currency(005), cond_pb00(038), "Net price cond_p_unt(5), "Price Unit END OF it_data. DATA:BEGIN OF it_head OCCURS 0, comp_code(4), "Company Code doc_type(004), "###### po_number(010), po(010), vendor(010), "###### doc_date(008), "#### purch_org(004), "#### pur_group(003), "#### pmnttrms(004), "#### incoterms1(003), "###### incoterms2(028), "###### currency(005), "#### exch_rate(014), "## text_pohzs(132), "Header Remark shippingin(132), "SHIPPING INSTRUCTION prppayment(132), "PAYMENT TERM FOR PRP delivery(132), "DELIVERY attention(132), "ATTENTION name_2(040), "#####2 name_3(040), "#####3 name_4(040), "#####4 street(040), "## str_suppl2(040), "##4 location(040), "##5 postl_cod1(010), "###### country(003), "#### tel1_numbr(030), "## fax_number(030), "## billty(002), "######## billpo(010), "###### purcty(002), "######## purcpo(010), "##### patety(002), "######## patepo(010), "###### shipty(002), "######## shippo(010), "###### COLLECT_NO(010), "Collective Number END OF it_head. DATA:BEGIN OF it_item OCCURS 0, po_number(010), " po(010), acctasscat(001), "###### item_cat(001), "#### material(018), "###### short_text(040), "#### quantity(017), "###### po_unit(003), "#### gr_to_date(008), "#### cond_pb00(038), "Net Price cond_p_unt(005), "######## cond_za00(038), "UNZ#UTE###### matl_group(009), "#### plant(004), "## over_dlv_tol(005),"######## tax_code(002), "##/###### costcenter(010), "#### poit_text(132), "PO#### pobz_text(132), "PO#### valuepart1(240), "Exfact Date valuepart2(240), "Arr.HK Date END OF it_item. DATA:g_menge LIKE ekpo-netpr. ****************************************************************** * PARAMETERS & SELECTION-OPTIONS ****************************************************************** SELECTION-SCREEN BEGIN OF BLOCK sel WITH FRAME TITLE text-001. PARAMETERS:p_upload RADIOBUTTON GROUP radi, p_uptemp RADIOBUTTON GROUP radi. PARAMETERS:p_flag AS CHECKBOX . SELECTION-SCREEN END OF BLOCK sel. SELECTION-SCREEN BEGIN OF BLOCK mod WITH FRAME TITLE text-002. PARAMETERS:p_file LIKE rlgrap-filename DEFAULT 'c:\podata' , p_log LIKE rlgrap-filename DEFAULT 'c:\polog.xls' . SELECTION-SCREEN END OF BLOCK mod. START-OF-SELECTION. IF p_upload = 'X' . PERFORM upload_file. PERFORM upload_data. ENDIF. *&--------------------------------------------------------------------* *& Form upload_file *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM upload_file. TRANSLATE p_file TO UPPER CASE. len_str = STRLEN( p_file ). len_str = len_str - 4. IF p_file+len_str(4) <> '.XLS' . CONCATENATE p_file '.XLS' INTO p_file. ENDIF. CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT' EXPORTING filename = p_file i_begin_col = 1 i_begin_row = 2 i_end_col = 256 i_end_row = 65535 TABLES intern = l_intern EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. SORT l_intern BY row col. LOOP AT l_intern. MOVE l_intern-col TO l_index. ASSIGN COMPONENT l_index OF STRUCTURE it_data TO <fs></fs>. MOVE l_intern-value TO <fs></fs>. AT END OF row. APPEND it_data. CLEAR it_data. ENDAT. ENDLOOP. ENDFORM. "UPLOAD_FILE *&---------------------------------------------------------------------* *& Form UPLOAD_DATA *&---------------------------------------------------------------------* FORM upload_data . CLEAR:it_head,it_item. LOOP AT it_data. MOVE-CORRESPONDING it_data TO it_head. it_head-COLLECT_NO = it_data-po. COLLECT it_head. MOVE-CORRESPONDING it_data TO it_item. APPEND it_item. ENDLOOP. REFRESH it_msg. LOOP AT it_head. CLEAR: it_potexth,wa_pohead,wa_poheadx,wa_poaddrvendor. REFRESH:it_potexth,it_popartner. *Document Type wa_pohead-doc_type = 'NB' . wa_poheadx-doc_type = 'X' . *Vendor Number CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = it_head-vendor IMPORTING output = it_head-vendor. wa_pohead-vendor = it_head-vendor. wa_poheadx-vendor = 'X' . *Document Date wa_pohead-doc_date = it_head-doc_date. wa_poheadx-doc_date = 'X' . *Collective Number wa_pohead-COLLECT_NO = it_head-COLLECT_NO. wa_poheadx-COLLECT_NO = 'X' . *Company Code wa_pohead-comp_code = '8200' . wa_poheadx-comp_code = 'X' . *Purchase Organise wa_pohead-purch_org = '8200' . *Purchase Group wa_pohead-pur_group = '003' . wa_poheadx-pur_group = 'X' . *Payment term wa_pohead-pmnttrms = it_head-pmnttrms. wa_poheadx-pmnttrms = 'X' . *Currency wa_pohead-currency = it_head-currency. wa_poheadx-currency = 'X' . *Purchase Order Header Text it_potexth-text_line = it_data-remark. "Header Remark(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F01' . APPEND it_potexth. CLEAR it_potexth. *SHIPPING INSTRUCTION it_potexth-text_line = it_head-shippingin. "Ship Date(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F02' . APPEND it_potexth. CLEAR it_potexth. *PAYMENT TERM FOR PRP it_potexth-text_line = it_data-load_date. "Load Date(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F03' . APPEND it_potexth. CLEAR it_potexth. *Date of ETA HK it_potexth-text_line = it_data-eta_hk. "Date of ETA HK it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F04' . APPEND it_potexth. CLEAR it_potexth. *Date of Arr HK it_potexth-text_line = it_data-arr_hk. "Date of Arr HK it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F05' . APPEND it_potexth. CLEAR it_potexth. *Transpotion Method it_potexth-text_line = it_data-trsp_metd. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F06' . APPEND it_potexth. CLEAR it_potexth. *Container Number it_potexth-text_line = it_data-container_no. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F07' . APPEND it_potexth. CLEAR it_potexth. *LC Number it_potexth-text_line = it_data-lc_number. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F08' . APPEND it_potexth. CLEAR it_potexth. *Invoice Number it_potexth-text_line = it_data-invoice_no. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F09' . APPEND it_potexth. CLEAR it_potexth. *Purchase Order Item Information CLEAR g_poitem. REFRESH: it_poitemx,it_poitem,it_pocond,it_pocondx, it_poche,it_pochex . LOOP AT it_item. IF it_item-po EQ it_head-po. CLEAR:it_poitem, it_poitemx. g_poitem = g_poitem + 10. it_poitem-po_item = g_poitem. it_poitemx-po_item = g_poitem. it_poitem-item_cat = it_item-item_cat. it_poitemx-item_cat = 'X' . it_poitemx-po_itemx = 'X' . CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = it_item-material IMPORTING output = it_item-material. it_poitem-material = it_item-material. it_poitemx-material = 'X' . IF it_item-short_text IS NOT INITIAL. it_poitem-short_text = it_item-short_text. it_poitemx-short_text = 'X' . ENDIF. CLEAR g_meng. g_meng = it_item-quantity. it_poitem-quantity = g_meng. it_poitemx-quantity = 'X' . it_poitem-po_unit = it_item-po_unit. it_poitemx-po_unit = 'X' . CLEAR g_mtart. SELECT SINGLE mtart INTO g_mtart FROM mara WHERE matnr EQ it_item-material. IF g_mtart EQ 'ZNON' . it_poitem-acctasscat = 'Z' . it_poitemx-acctasscat = 'X' . ENDIF. CLEAR: it_poche,it_pochex. it_poche-po_item = g_poitem. it_pochex-po_item = g_poitem. it_poche-sched_line = g_poitem. it_pochex-sched_line = g_poitem. it_poche-delivery_date = it_item-gr_to_date. it_pochex-delivery_date = 'X' . it_poche-quantity = g_meng. it_pochex-quantity = 'X' . it_pochex-po_itemx = 'X' . it_pochex-sched_linex = 'X' . APPEND: it_poche,it_pochex. it_poitem-plant = '8200' . it_poitemx-plant = 'X' . IF it_item-matl_group IS NOT INITIAL. it_poitem-matl_group = it_item-matl_group. it_poitemx-matl_group = 'X' . ENDIF. it_poitem-over_dlv_tol = it_item-over_dlv_tol. it_poitemx-over_dlv_tol = 'X' . it_poitem-tax_code = it_item-tax_code. it_poitemx-tax_code = 'X' . g_menge = it_item-cond_pb00. IF g_menge EQ 0. it_poitem-free_item = 'X' . it_poitemx-free_item = 'X' . ELSE. it_poitem-free_item = '' . it_poitemx-free_item = 'X' . ENDIF. it_poitem-matl_group = it_item-matl_group. it_poitemx-matl_group = 'X' . IT_POITEM-NET_PRICE = IT_ITEM-COND_PB00. IT_POITEMX-NET_PRICE = 'X' . it_poitem-price_unit = it_item-cond_p_unt. it_poitemx-price_unit = 'X' . APPEND:it_poitemx,it_poitem. *ConditionS CLEAR it_pocond. it_pocond-cond_type = 'PB00' . it_pocond-itm_number = it_poitem-po_item. it_pocond-cond_value = IT_ITEM-COND_PB00. it_pocond-cond_p_unt = it_item-cond_p_unt. it_pocond-currency = it_head-currency. it_pocond-change_id = 'U' . APPEND it_pocond. CLEAR it_pocondx. it_pocondx-cond_type = 'X' . it_pocondx-itm_number = it_poitem-po_item. it_pocondx-cond_value = 'X' . it_pocondx-cond_p_unt = 'X' . it_pocondx-currency = 'X' . it_pocondx-change_id = 'X' . APPEND it_pocondx. ENDIF. ENDLOOP. wa_testrun = p_flag. DELETE it_item WHERE po EQ it_head-po. SELECT SINGLE ebeln INTO g_ebeln FROM ekko WHERE ebeln EQ wa_pohead-po_number. IF sy-subrc NE 0. <font color="#ff0000" > CALL FUNCTION 'BAPI_PO_CREATE1' EXPORTING poheader = wa_pohead poheaderx = wa_poheadx poaddrvendor = wa_poaddrvendor testrun = wa_testrun IMPORTING EXPPURCHASEORDER = purchseorder TABLES return = it_return poitem = it_poitem poitemx = it_poitemx poschedule = it_poche poschedulex = it_pochex pocond = it_pocond pocondx = it_pocondx potextheader = it_potexth potextitem = it_potexti popartner = it_popartner.</font> <font color="#ff0000" >CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' . WAIT UP TO 1 SECONDS.</font> REFRESH: it_poitem,it_poitemx,it_poche,it_pochex, it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner. CLEAR:it_return,it_poitem,it_poitemx,it_poche,it_pochex, it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner. DELETE it_item WHERE po EQ it_head-po. DELETE it_head WHERE po EQ it_head-po. * LOOP AT it_return WHERE type EQ 'E' . LOOP AT it_return. MOVE-CORRESPONDING it_return TO it_msg1. * it_msg1-ebeln = wa_pohead-po_number. it_msg1-ebeln = purchseorder. it_msg1-old_po = it_head-po. APPEND it_msg1. clear it_msg1. ENDLOOP. ENDIF. ENDLOOP. CALL FUNCTION 'WS_DOWNLOAD' EXPORTING filename = p_log filetype = 'DAT' mode = 'O' TABLES data_tab = it_msg1 EXCEPTIONS invalid_filesize = 1 invalid_table_width = 2 invalid_type = 3 no_batch = 4 unknown_error = 5 gui_refuse_filetransfer = 6 OTHERS = 7. 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. " UPLOAD_DATA </pre> view plaincopy to clipboardprint?
*&---------------------------------------------------------------------* *& Report ZCON0026 *& *&---------------------------------------------------------------------* *& Author: Jun *& *&---------------------------------------------------------------------* REPORT ZCON0026. FIELD-SYMBOLS : <fs></fs>. <font color="#ff0000" >DATA:wa_pohead TYPE bapimepoheader. DATA:wa_poheadx TYPE bapimepoheaderx. DATA:wa_poaddrvendor TYPE bapimepoaddrvendor. DATA:wa_testrun TYPE bapiflag-bapiflag.</font> DATA:g_ebeln TYPE ekko-ebeln. "Purchasing Document Header DATA:g_mtart TYPE mtart. <font color="#ff0000" >DATA:it_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE. DATA:it_msg TYPE bapiret2 OCCURS 0 WITH HEADER LINE.</font> DATA:BEGIN OF it_msg1 OCCURS 0, ebeln LIKE ekpo-ebeln, type like bapiret2-type, message LIKE bapiret2-message, old_po like ekpo-ebeln, END OF it_msg1. <font color="#ff0000" >DATA:it_poitem TYPE bapimepoitem OCCURS 0 WITH HEADER LINE. DATA:it_poitemx TYPE bapimepoitemx OCCURS 0 WITH HEADER LINE. DATA:it_pocondh TYPE bapimepocondheader OCCURS 0 WITH HEADER LINE. DATA:it_pocondhx TYPE bapimepocondheaderx OCCURS 0 WITH HEADER LINE. DATA:it_pocond TYPE bapimepocond OCCURS 0 WITH HEADER LINE. DATA:it_pocondx TYPE bapimepocondx OCCURS 0 WITH HEADER LINE. DATA:it_potexth TYPE bapimepotextheader OCCURS 0 WITH HEADER LINE. DATA:it_potexti TYPE bapimepotext OCCURS 0 WITH HEADER LINE. DATA:it_popartner TYPE bapiekkop OCCURS 0 WITH HEADER LINE. DATA:it_extens TYPE bapiparex OCCURS 0 WITH HEADER LINE. "Customer's Own Fields DATA:it_poaccount TYPE bapimepoaccount OCCURS 0 WITH HEADER LINE. DATA:it_poaccountx TYPE bapimepoaccountx OCCURS 0 WITH HEADER LINE. DATA:it_poche TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE. DATA:it_pochex TYPE bapimeposchedulx OCCURS 0 WITH HEADER LINE. DATA:purchseorder TYPE BAPIMEPOHEADER-PO_NUMBER.</font> DATA:g_poitem TYPE ebelp. "Item Number of Purchasing Document DATA:g_meng LIKE ekpo-menge. "Purchase Order Quantity DATA:l_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE. DATA:len_str TYPE i, l_index TYPE i. DATA:BEGIN OF it_data OCCURS 0, * doc_type(004), *&---------------------------------------------------------------------* *& Report ZCON0026 *& *&---------------------------------------------------------------------* *& Author: Jun *& *&---------------------------------------------------------------------* REPORT ZCON0026. FIELD-SYMBOLS : . DATA:g_ebeln TYPE ekko-ebeln. "Purchasing Document Header DATA:g_mtart TYPE mtart. DATA:BEGIN OF it_msg1 OCCURS 0, ebeln LIKE ekpo-ebeln, type like bapiret2-type, message LIKE bapiret2-message, old_po like ekpo-ebeln, END OF it_msg1. DATA:g_poitem TYPE ebelp. "Item Number of Purchasing Document DATA:g_meng LIKE ekpo-menge. "Purchase Order Quantity DATA:l_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE. DATA:len_str TYPE i, l_index TYPE i. DATA:BEGIN OF it_data OCCURS 0, * doc_type(004), view plaincopy to clipboardprint?
po(010), "PO NO material(018), vendor(010), invoice_no(15), "Invoice Number(Header text) pmnttrms(004), "Paymentterms quantity(017), doc_date(008), gr_to_date(008), "Delivery date shippingin(10), "Ship Date(Header Text) eta_hk(10), "Date of ETA HK(Header Text) trsp_metd(10), "Transportion Method(Header Text) container_no(20), "COntainer Number(Header Text) lc_number(20), "LC Number(Header Text) load_date(10), "Load Date(Header Text) arr_hk(10), "Date of Arr. Date(Header Text) remark(20), "Header remark(Header Text) currency(005), cond_pb00(038), "Net price cond_p_unt(5), "Price Unit END OF it_data. DATA:BEGIN OF it_head OCCURS 0, comp_code(4), "Company Code doc_type(004), "###### po_number(010), po(010), vendor(010), "###### doc_date(008), "#### purch_org(004), "#### pur_group(003), "#### pmnttrms(004), "#### incoterms1(003), "###### incoterms2(028), "###### currency(005), "#### exch_rate(014), "## text_pohzs(132), "Header Remark shippingin(132), "SHIPPING INSTRUCTION prppayment(132), "PAYMENT TERM FOR PRP delivery(132), "DELIVERY attention(132), "ATTENTION name_2(040), "#####2 name_3(040), "#####3 name_4(040), "#####4 street(040), "## str_suppl2(040), "##4 location(040), "##5 postl_cod1(010), "###### country(003), "#### tel1_numbr(030), "## fax_number(030), "## billty(002), "######## billpo(010), "###### purcty(002), "######## purcpo(010), "##### patety(002), "######## patepo(010), "###### shipty(002), "######## shippo(010), "###### COLLECT_NO(010), "Collective Number END OF it_head. DATA:BEGIN OF it_item OCCURS 0, po_number(010), " po(010), acctasscat(001), "###### item_cat(001), "#### material(018), "###### short_text(040), "#### quantity(017), "###### po_unit(003), "#### gr_to_date(008), "#### cond_pb00(038), "Net Price cond_p_unt(005), "######## cond_za00(038), "UNZ#UTE###### matl_group(009), "#### plant(004), "## over_dlv_tol(005),"######## tax_code(002), "##/###### costcenter(010), "#### poit_text(132), "PO#### pobz_text(132), "PO#### valuepart1(240), "Exfact Date valuepart2(240), "Arr.HK Date END OF it_item. DATA:g_menge LIKE ekpo-netpr. ****************************************************************** * PARAMETERS & SELECTION-OPTIONS ****************************************************************** SELECTION-SCREEN BEGIN OF BLOCK sel WITH FRAME TITLE text-001. PARAMETERS:p_upload RADIOBUTTON GROUP radi, p_uptemp RADIOBUTTON GROUP radi. PARAMETERS:p_flag AS CHECKBOX . SELECTION-SCREEN END OF BLOCK sel. SELECTION-SCREEN BEGIN OF BLOCK mod WITH FRAME TITLE text-002. PARAMETERS:p_file LIKE rlgrap-filename DEFAULT 'c:\podata' , p_log LIKE rlgrap-filename DEFAULT 'c:\polog.xls' . SELECTION-SCREEN END OF BLOCK mod. START-OF-SELECTION. IF p_upload = 'X' . PERFORM upload_file. PERFORM upload_data. ENDIF. *&--------------------------------------------------------------------* *& Form upload_file *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM upload_file. TRANSLATE p_file TO UPPER CASE. len_str = STRLEN( p_file ). len_str = len_str - 4. IF p_file+len_str(4) <> '.XLS' . CONCATENATE p_file '.XLS' INTO p_file. ENDIF. CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT' EXPORTING filename = p_file i_begin_col = 1 i_begin_row = 2 i_end_col = 256 i_end_row = 65535 TABLES intern = l_intern EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. SORT l_intern BY row col. LOOP AT l_intern. MOVE l_intern-col TO l_index. ASSIGN COMPONENT l_index OF STRUCTURE it_data TO <fs></fs>. MOVE l_intern-value TO <fs></fs>. AT END OF row. APPEND it_data. CLEAR it_data. ENDAT. ENDLOOP. ENDFORM. "UPLOAD_FILE *&---------------------------------------------------------------------* *& Form UPLOAD_DATA *&---------------------------------------------------------------------* FORM upload_data . CLEAR:it_head,it_item. LOOP AT it_data. MOVE-CORRESPONDING it_data TO it_head. it_head-COLLECT_NO = it_data-po. COLLECT it_head. MOVE-CORRESPONDING it_data TO it_item. APPEND it_item. ENDLOOP. REFRESH it_msg. LOOP AT it_head. CLEAR: it_potexth,wa_pohead,wa_poheadx,wa_poaddrvendor. REFRESH:it_potexth,it_popartner. *Document Type wa_pohead-doc_type = 'NB' . wa_poheadx-doc_type = 'X' . *Vendor Number CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = it_head-vendor IMPORTING output = it_head-vendor. wa_pohead-vendor = it_head-vendor. wa_poheadx-vendor = 'X' . *Document Date wa_pohead-doc_date = it_head-doc_date. wa_poheadx-doc_date = 'X' . *Collective Number wa_pohead-COLLECT_NO = it_head-COLLECT_NO. wa_poheadx-COLLECT_NO = 'X' . *Company Code wa_pohead-comp_code = '8200' . wa_poheadx-comp_code = 'X' . *Purchase Organise wa_pohead-purch_org = '8200' . *Purchase Group wa_pohead-pur_group = '003' . wa_poheadx-pur_group = 'X' . *Payment term wa_pohead-pmnttrms = it_head-pmnttrms. wa_poheadx-pmnttrms = 'X' . *Currency wa_pohead-currency = it_head-currency. wa_poheadx-currency = 'X' . *Purchase Order Header Text it_potexth-text_line = it_data-remark. "Header Remark(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F01' . APPEND it_potexth. CLEAR it_potexth. *SHIPPING INSTRUCTION it_potexth-text_line = it_head-shippingin. "Ship Date(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F02' . APPEND it_potexth. CLEAR it_potexth. *PAYMENT TERM FOR PRP it_potexth-text_line = it_data-load_date. "Load Date(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F03' . APPEND it_potexth. CLEAR it_potexth. *Date of ETA HK it_potexth-text_line = it_data-eta_hk. "Date of ETA HK it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F04' . APPEND it_potexth. CLEAR it_potexth. *Date of Arr HK it_potexth-text_line = it_data-arr_hk. "Date of Arr HK it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F05' . APPEND it_potexth. CLEAR it_potexth. *Transpotion Method it_potexth-text_line = it_data-trsp_metd. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F06' . APPEND it_potexth. CLEAR it_potexth. *Container Number it_potexth-text_line = it_data-container_no. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F07' . APPEND it_potexth. CLEAR it_potexth. *LC Number it_potexth-text_line = it_data-lc_number. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F08' . APPEND it_potexth. CLEAR it_potexth. *Invoice Number it_potexth-text_line = it_data-invoice_no. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F09' . APPEND it_potexth. CLEAR it_potexth. *Purchase Order Item Information CLEAR g_poitem. REFRESH: it_poitemx,it_poitem,it_pocond,it_pocondx, it_poche,it_pochex . LOOP AT it_item. IF it_item-po EQ it_head-po. CLEAR:it_poitem, it_poitemx. g_poitem = g_poitem + 10. it_poitem-po_item = g_poitem. it_poitemx-po_item = g_poitem. it_poitem-item_cat = it_item-item_cat. it_poitemx-item_cat = 'X' . it_poitemx-po_itemx = 'X' . CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = it_item-material IMPORTING output = it_item-material. it_poitem-material = it_item-material. it_poitemx-material = 'X' . IF it_item-short_text IS NOT INITIAL. it_poitem-short_text = it_item-short_text. it_poitemx-short_text = 'X' . ENDIF. CLEAR g_meng. g_meng = it_item-quantity. it_poitem-quantity = g_meng. it_poitemx-quantity = 'X' . it_poitem-po_unit = it_item-po_unit. it_poitemx-po_unit = 'X' . CLEAR g_mtart. SELECT SINGLE mtart INTO g_mtart FROM mara WHERE matnr EQ it_item-material. IF g_mtart EQ 'ZNON' . it_poitem-acctasscat = 'Z' . it_poitemx-acctasscat = 'X' . ENDIF. CLEAR: it_poche,it_pochex. it_poche-po_item = g_poitem. it_pochex-po_item = g_poitem. it_poche-sched_line = g_poitem. it_pochex-sched_line = g_poitem. it_poche-delivery_date = it_item-gr_to_date. it_pochex-delivery_date = 'X' . it_poche-quantity = g_meng. it_pochex-quantity = 'X' . it_pochex-po_itemx = 'X' . it_pochex-sched_linex = 'X' . APPEND: it_poche,it_pochex. it_poitem-plant = '8200' . it_poitemx-plant = 'X' . IF it_item-matl_group IS NOT INITIAL. it_poitem-matl_group = it_item-matl_group. it_poitemx-matl_group = 'X' . ENDIF. it_poitem-over_dlv_tol = it_item-over_dlv_tol. it_poitemx-over_dlv_tol = 'X' . it_poitem-tax_code = it_item-tax_code. it_poitemx-tax_code = 'X' . g_menge = it_item-cond_pb00. IF g_menge EQ 0. it_poitem-free_item = 'X' . it_poitemx-free_item = 'X' . ELSE. it_poitem-free_item = '' . it_poitemx-free_item = 'X' . ENDIF. it_poitem-matl_group = it_item-matl_group. it_poitemx-matl_group = 'X' . IT_POITEM-NET_PRICE = IT_ITEM-COND_PB00. IT_POITEMX-NET_PRICE = 'X' . it_poitem-price_unit = it_item-cond_p_unt. it_poitemx-price_unit = 'X' . APPEND:it_poitemx,it_poitem. *ConditionS CLEAR it_pocond. it_pocond-cond_type = 'PB00' . it_pocond-itm_number = it_poitem-po_item. it_pocond-cond_value = IT_ITEM-COND_PB00. it_pocond-cond_p_unt = it_item-cond_p_unt. it_pocond-currency = it_head-currency. it_pocond-change_id = 'U' . APPEND it_pocond. CLEAR it_pocondx. it_pocondx-cond_type = 'X' . it_pocondx-itm_number = it_poitem-po_item. it_pocondx-cond_value = 'X' . it_pocondx-cond_p_unt = 'X' . it_pocondx-currency = 'X' . it_pocondx-change_id = 'X' . APPEND it_pocondx. ENDIF. ENDLOOP. wa_testrun = p_flag. DELETE it_item WHERE po EQ it_head-po. SELECT SINGLE ebeln INTO g_ebeln FROM ekko WHERE ebeln EQ wa_pohead-po_number. IF sy-subrc NE 0. <font color="#ff0000" > CALL FUNCTION 'BAPI_PO_CREATE1' EXPORTING poheader = wa_pohead poheaderx = wa_poheadx poaddrvendor = wa_poaddrvendor testrun = wa_testrun IMPORTING EXPPURCHASEORDER = purchseorder TABLES return = it_return poitem = it_poitem poitemx = it_poitemx poschedule = it_poche poschedulex = it_pochex pocond = it_pocond pocondx = it_pocondx potextheader = it_potexth potextitem = it_potexti popartner = it_popartner.</font> <font color="#ff0000" >CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' . WAIT UP TO 1 SECONDS.</font> REFRESH: it_poitem,it_poitemx,it_poche,it_pochex, it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner. CLEAR:it_return,it_poitem,it_poitemx,it_poche,it_pochex, it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner. DELETE it_item WHERE po EQ it_head-po. DELETE it_head WHERE po EQ it_head-po. * LOOP AT it_return WHERE type EQ 'E' . LOOP AT it_return. MOVE-CORRESPONDING it_return TO it_msg1. * it_msg1-ebeln = wa_pohead-po_number. it_msg1-ebeln = purchseorder. it_msg1-old_po = it_head-po. APPEND it_msg1. clear it_msg1. ENDLOOP. ENDIF. ENDLOOP. CALL FUNCTION 'WS_DOWNLOAD' EXPORTING filename = p_log filetype = 'DAT' mode = 'O' TABLES data_tab = it_msg1 EXCEPTIONS invalid_filesize = 1 invalid_table_width = 2 invalid_type = 3 no_batch = 4 unknown_error = 5 gui_refuse_filetransfer = 6 OTHERS = 7. 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. " UPLOAD_DATA po(010), "PO NO material(018), vendor(010), invoice_no(15), "Invoice Number(Header text) pmnttrms(004), "Paymentterms quantity(017), doc_date(008), gr_to_date(008), "Delivery date shippingin(10), "Ship Date(Header Text) eta_hk(10), "Date of ETA HK(Header Text) trsp_metd(10), "Transportion Method(Header Text) container_no(20), "COntainer Number(Header Text) lc_number(20), "LC Number(Header Text) load_date(10), "Load Date(Header Text) arr_hk(10), "Date of Arr. Date(Header Text) remark(20), "Header remark(Header Text) currency(005), cond_pb00(038), "Net price cond_p_unt(5), "Price Unit END OF it_data. DATA:BEGIN OF it_head OCCURS 0, comp_code(4), "Company Code doc_type(004), "###### po_number(010), po(010), vendor(010), "###### doc_date(008), "#### purch_org(004), "#### pur_group(003), "#### pmnttrms(004), "#### incoterms1(003), "###### incoterms2(028), "###### currency(005), "#### exch_rate(014), "## text_pohzs(132), "Header Remark shippingin(132), "SHIPPING INSTRUCTION prppayment(132), "PAYMENT TERM FOR PRP delivery(132), "DELIVERY attention(132), "ATTENTION name_2(040), "#####2 name_3(040), "#####3 name_4(040), "#####4 street(040), "## str_suppl2(040), "##4 location(040), "##5 postl_cod1(010), "###### country(003), "#### tel1_numbr(030), "## fax_number(030), "## billty(002), "######## billpo(010), "###### purcty(002), "######## purcpo(010), "##### patety(002), "######## patepo(010), "###### shipty(002), "######## shippo(010), "###### COLLECT_NO(010), "Collective Number END OF it_head. DATA:BEGIN OF it_item OCCURS 0, po_number(010), " po(010), acctasscat(001), "###### item_cat(001), "#### material(018), "###### short_text(040), "#### quantity(017), "###### po_unit(003), "#### gr_to_date(008), "#### cond_pb00(038), "Net Price cond_p_unt(005), "######## cond_za00(038), "UNZ#UTE###### matl_group(009), "#### plant(004), "## over_dlv_tol(005),"######## tax_code(002), "##/###### costcenter(010), "#### poit_text(132), "PO#### pobz_text(132), "PO#### valuepart1(240), "Exfact Date valuepart2(240), "Arr.HK Date END OF it_item. DATA:g_menge LIKE ekpo-netpr. ****************************************************************** * PARAMETERS & SELECTION-OPTIONS ****************************************************************** SELECTION-SCREEN BEGIN OF BLOCK sel WITH FRAME TITLE text-001. PARAMETERS:p_upload RADIOBUTTON GROUP radi, p_uptemp RADIOBUTTON GROUP radi. PARAMETERS:p_flag AS CHECKBOX . SELECTION-SCREEN END OF BLOCK sel. SELECTION-SCREEN BEGIN OF BLOCK mod WITH FRAME TITLE text-002. PARAMETERS:p_file LIKE rlgrap-filename DEFAULT 'c:\podata', p_log LIKE rlgrap-filename DEFAULT 'c:\polog.xls'. SELECTION-SCREEN END OF BLOCK mod. START-OF-SELECTION. IF p_upload = 'X'. PERFORM upload_file. PERFORM upload_data. ENDIF. *&--------------------------------------------------------------------* *& Form upload_file *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* FORM upload_file. TRANSLATE p_file TO UPPER CASE. len_str = STRLEN( p_file ). len_str = len_str - 4. IF p_file+len_str(4) <> '.XLS'. CONCATENATE p_file '.XLS' INTO p_file. ENDIF. CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT' EXPORTING filename = p_file i_begin_col = 1 i_begin_row = 2 i_end_col = 256 i_end_row = 65535 TABLES intern = l_intern EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. ENDIF. SORT l_intern BY row col. LOOP AT l_intern. MOVE l_intern-col TO l_index. ASSIGN COMPONENT l_index OF STRUCTURE it_data TO . MOVE l_intern-value TO . AT END OF row. APPEND it_data. CLEAR it_data. ENDAT. ENDLOOP. ENDFORM. "UPLOAD_FILE *&---------------------------------------------------------------------* *& Form UPLOAD_DATA *&---------------------------------------------------------------------* FORM upload_data . CLEAR:it_head,it_item. LOOP AT it_data. MOVE-CORRESPONDING it_data TO it_head. it_head-COLLECT_NO = it_data-po. COLLECT it_head. MOVE-CORRESPONDING it_data TO it_item. APPEND it_item. ENDLOOP. REFRESH it_msg. LOOP AT it_head. CLEAR: it_potexth,wa_pohead,wa_poheadx,wa_poaddrvendor. REFRESH:it_potexth,it_popartner. *Document Type wa_pohead-doc_type = 'NB'. wa_poheadx-doc_type = 'X'. *Vendor Number CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = it_head-vendor IMPORTING output = it_head-vendor. wa_pohead-vendor = it_head-vendor. wa_poheadx-vendor = 'X'. *Document Date wa_pohead-doc_date = it_head-doc_date. wa_poheadx-doc_date = 'X'. *Collective Number wa_pohead-COLLECT_NO = it_head-COLLECT_NO. wa_poheadx-COLLECT_NO = 'X'. *Company Code wa_pohead-comp_code = '8200'. wa_poheadx-comp_code = 'X'. *Purchase Organise wa_pohead-purch_org = '8200'. *Purchase Group wa_pohead-pur_group = '003'. wa_poheadx-pur_group = 'X'. *Payment term wa_pohead-pmnttrms = it_head-pmnttrms. wa_poheadx-pmnttrms = 'X'. *Currency wa_pohead-currency = it_head-currency. wa_poheadx-currency = 'X'. *Purchase Order Header Text it_potexth-text_line = it_data-remark. "Header Remark(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F01'. APPEND it_potexth. CLEAR it_potexth. *SHIPPING INSTRUCTION it_potexth-text_line = it_head-shippingin. "Ship Date(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F02'. APPEND it_potexth. CLEAR it_potexth. *PAYMENT TERM FOR PRP it_potexth-text_line = it_data-load_date. "Load Date(Header Text) it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F03'. APPEND it_potexth. CLEAR it_potexth. *Date of ETA HK it_potexth-text_line = it_data-eta_hk. "Date of ETA HK it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F04'. APPEND it_potexth. CLEAR it_potexth. *Date of Arr HK it_potexth-text_line = it_data-arr_hk. "Date of Arr HK it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F05'. APPEND it_potexth. CLEAR it_potexth. *Transpotion Method it_potexth-text_line = it_data-trsp_metd. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F06'. APPEND it_potexth. CLEAR it_potexth. *Container Number it_potexth-text_line = it_data-container_no. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F07'. APPEND it_potexth. CLEAR it_potexth. *LC Number it_potexth-text_line = it_data-lc_number. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F08'. APPEND it_potexth. CLEAR it_potexth. *Invoice Number it_potexth-text_line = it_data-invoice_no. it_potexth-po_number = it_head-po_number. it_potexth-text_id = 'F09'. APPEND it_potexth. CLEAR it_potexth. *Purchase Order Item Information CLEAR g_poitem. REFRESH: it_poitemx,it_poitem,it_pocond,it_pocondx, it_poche,it_pochex . LOOP AT it_item. IF it_item-po EQ it_head-po. CLEAR:it_poitem, it_poitemx. g_poitem = g_poitem + 10. it_poitem-po_item = g_poitem. it_poitemx-po_item = g_poitem. it_poitem-item_cat = it_item-item_cat. it_poitemx-item_cat = 'X'. it_poitemx-po_itemx = 'X'. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = it_item-material IMPORTING output = it_item-material. it_poitem-material = it_item-material. it_poitemx-material = 'X'. IF it_item-short_text IS NOT INITIAL. it_poitem-short_text = it_item-short_text. it_poitemx-short_text = 'X'. ENDIF. CLEAR g_meng. g_meng = it_item-quantity. it_poitem-quantity = g_meng. it_poitemx-quantity = 'X'. it_poitem-po_unit = it_item-po_unit. it_poitemx-po_unit = 'X'. CLEAR g_mtart. SELECT SINGLE mtart INTO g_mtart FROM mara WHERE matnr EQ it_item-material. IF g_mtart EQ 'ZNON'. it_poitem-acctasscat = 'Z'. it_poitemx-acctasscat = 'X'. ENDIF. CLEAR: it_poche,it_pochex. it_poche-po_item = g_poitem. it_pochex-po_item = g_poitem. it_poche-sched_line = g_poitem. it_pochex-sched_line = g_poitem. it_poche-delivery_date = it_item-gr_to_date. it_pochex-delivery_date = 'X'. it_poche-quantity = g_meng. it_pochex-quantity = 'X'. it_pochex-po_itemx = 'X'. it_pochex-sched_linex = 'X'. APPEND: it_poche,it_pochex. it_poitem-plant = '8200'. it_poitemx-plant = 'X'. IF it_item-matl_group IS NOT INITIAL. it_poitem-matl_group = it_item-matl_group. it_poitemx-matl_group = 'X'. ENDIF. it_poitem-over_dlv_tol = it_item-over_dlv_tol. it_poitemx-over_dlv_tol = 'X'. it_poitem-tax_code = it_item-tax_code. it_poitemx-tax_code = 'X'. g_menge = it_item-cond_pb00. IF g_menge EQ 0. it_poitem-free_item = 'X'. it_poitemx-free_item = 'X'. ELSE. it_poitem-free_item = ''. it_poitemx-free_item = 'X'. ENDIF. it_poitem-matl_group = it_item-matl_group. it_poitemx-matl_group = 'X'. IT_POITEM-NET_PRICE = IT_ITEM-COND_PB00. IT_POITEMX-NET_PRICE = 'X'. it_poitem-price_unit = it_item-cond_p_unt. it_poitemx-price_unit = 'X'. APPEND:it_poitemx,it_poitem. *ConditionS CLEAR it_pocond. it_pocond-cond_type = 'PB00'. it_pocond-itm_number = it_poitem-po_item. it_pocond-cond_value = IT_ITEM-COND_PB00. it_pocond-cond_p_unt = it_item-cond_p_unt. it_pocond-currency = it_head-currency. it_pocond-change_id = 'U'. APPEND it_pocond. CLEAR it_pocondx. it_pocondx-cond_type = 'X'. it_pocondx-itm_number = it_poitem-po_item. it_pocondx-cond_value = 'X'. it_pocondx-cond_p_unt = 'X'. it_pocondx-currency = 'X'. it_pocondx-change_id = 'X'. APPEND it_pocondx. ENDIF. ENDLOOP. wa_testrun = p_flag. DELETE it_item WHERE po EQ it_head-po. SELECT SINGLE ebeln INTO g_ebeln FROM ekko WHERE ebeln EQ wa_pohead-po_number. IF sy-subrc NE 0. REFRESH: it_poitem,it_poitemx,it_poche,it_pochex, it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner. CLEAR:it_return,it_poitem,it_poitemx,it_poche,it_pochex, it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner. DELETE it_item WHERE po EQ it_head-po. DELETE it_head WHERE po EQ it_head-po. * LOOP AT it_return WHERE type EQ 'E'. LOOP AT it_return. MOVE-CORRESPONDING it_return TO it_msg1. * it_msg1-ebeln = wa_pohead-po_number. it_msg1-ebeln = purchseorder. it_msg1-old_po = it_head-po. APPEND it_msg1. clear it_msg1. ENDLOOP. ENDIF. ENDLOOP. CALL FUNCTION 'WS_DOWNLOAD' EXPORTING filename = p_log filetype = 'DAT' mode = 'O' TABLES data_tab = it_msg1 EXCEPTIONS invalid_filesize = 1 invalid_table_width = 2 invalid_type = 3 no_batch = 4 unknown_error = 5 gui_refuse_filetransfer = 6 OTHERS = 7. 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. " UPLOAD_DATA
四, 最后说的是使用ALE技术, 利用IDOC和BAPI实现数据传输功能。我在这里提供一个链接,这是郭裕老师的在线课程录像下载, 主要讲述的是ALE技术和MASTER DATA DISTRIBUTION技术:http://www.itpub.net/494989,1.html
转载于:https://www.cnblogs.com/levin/archive/2009/08/10/1543179.html
总结
以上是生活随笔 为你收集整理的SAP BDC 技术的分类(转) 的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得生活随笔 网站内容还不错,欢迎将生活随笔 推荐给好友。