SAP BDC 技术的分类(转)

首先, 解释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结构定义的内表, 主要存储屏幕处理所需要的关键数据, 其结构如下:

字段名类型长度小数描述
PROGRAMCHAR400BDC module pool
DYNPRONUMC40BDC Screen number
DYNBEGINCHAR10BDC screen start
FNAMCHAR1320Field name
FVALCHAR1320BDC field value

MODE m 是指Processing Mode, 共有4种处理模式:

模式英文描述
ADisplay all screens
EDisplay errors
NBackground processing
PBackground processing; debugging possible

UPDATE 'S'  是指更新模式, 共有3种更新模式,一般使用'S'模式:

模式描述
A异步
S同步
L本地

MESSAGES INTO mssg 的意思是将处理信息导入到一个参考bdcmsgcoll结构的内表, 方便查错.

下面是一个上传物料中文描述的简单例子:

  1. *&---------------------------------------------------------------------*  
  2. *& Report  ZBDC_TEST1  
  3. *& 调用事务  
  4. *&---------------------------------------------------------------------*  
  5. *&  Author: Jun  
  6. *&  
  7. *&---------------------------------------------------------------------*  
  8.   
  9. REPORT  zbdc_test1.  
  10.   
  11. ************************************************************************  
  12. * D A T A  
  13. ************************************************************************  
  14.   
  15. CONSTANTS: c_def_path LIKE rlgrap-filename VALUE 'c:\file.txt'.  
  16. DATA: BEGIN OF mssg OCCURS 0.  
  17.         INCLUDE STRUCTURE bdcmsgcoll.  
  18. DATA: END OF mssg.  
  19.   
  20.   
  21. DATA: BEGIN OF zitab_bdc OCCURS 0.  
  22.         INCLUDE STRUCTURE bdcdata.  
  23. DATA: END OF zitab_bdc.  
  24.   
  25. DATA: BEGIN OF t_main OCCURS 0,  
  26.       matnr(18),  
  27.       maktx(40),  
  28.       END OF t_main.  
  29.   
  30. DEFINE dynpro.  
  31.   
  32.   CLEAR zitab_bdc.  
  33.   IF &1 = 'X'.  
  34.   
  35.     MOVE: 'X' TO zitab_bdc-dynbegin,  
  36.                 &2  TO zitab_bdc-program,  
  37.                 &3 TO zitab_bdc-dynpro.  
  38.   
  39.   ELSE.  
  40.   
  41.     MOVE: &2 TO zitab_bdc-fnam,  
  42.                 &3 TO zitab_bdc-fval.  
  43.   
  44.   ENDIF.  
  45.   
  46.   APPEND zitab_bdc.  
  47.   
  48. END-OF-DEFINITION.  
  49.   
  50. SELECTION-SCREEN BEGIN OF BLOCK sc1 WITH FRAME TITLE text-s01.  
  51. PARAMETER: f_cap TYPE rlgrap-filename OBLIGATORY DEFAULT c_def_path.  
  52. PARAMETER: m TYPE ctu_mode DEFAULT 'N'.  
  53. SELECTION-SCREEN END OF BLOCK sc1.  
  54.   
  55.   
  56. ************************************************************************  
  57. * S T A R T O F S E L E C T I O N  
  58. ************************************************************************  
  59. START-OF-SELECTION.  
  60.   WRITE : / 'Start creation of BDC session',sy-mandt,sy-uname,sy-uzeit.  
  61.   PERFORM get_codepage.  
  62.   PERFORM call_upload TABLES t_main USING f_cap.  
  63.   PERFORM update_data.  
  64.   
  65.   WRITE: / 'Finished!'.  
  66.   
  67.   
  68. ************************************************************************  
  69. * F O R M S  
  70. ************************************************************************  
  71. *&---------------------------------------------------------------------*  
  72. *&  
  73. *&      Form  GET_CODEPAGE  
  74. *&---------------------------------------------------------------------*  
  75. FORM get_codepage.  
  76.   
  77.   DATA: cncoden TYPE abap_encod,  
  78.         cncode type  CPCODEPAGE.  
  79.   
  80.   CALL FUNCTION 'NLS_GET_FRONTEND_CP'  
  81.     EXPORTING  
  82.       langu                 = '1'  
  83.     IMPORTING  
  84.       frontend_codepage     = cncode  
  85.     EXCEPTIONS  
  86.       illegal_syst_codepage = 21  
  87.       no_frontend_cp_found  = 23  
  88.       internal_or_db_error  = 25.  
  89.   MOVE: cncode TO cncoden.  
  90. ENDFORM.  
  91.   
  92. *&---------------------------------------------------------------------*  
  93. *&  
  94. *&      Form  CALL_UPLOAD  
  95. *&---------------------------------------------------------------------*  
  96.   
  97. FORM call_upload TABLES p_tab USING p_fname.  
  98.   
  99.   DATA: tmp_filename TYPE string.  
  100.   
  101.   tmp_filename = p_fname.  
  102.   
  103.   
  104.     CALL METHOD cl_gui_frontend_services=>gui_download  
  105.       EXPORTING  
  106.         filename                = tmp_filename  
  107.         write_field_separator     = 'X'  
  108.         codepage                = cncoden  
  109.       CHANGING  
  110.         data_tab                = p_tab  
  111.       EXCEPTIONS  
  112.         file_write_error        = 1  
  113.         no_batch                = 2  
  114.         gui_refuse_filetransfer = 3  
  115.         invalid_type            = 4  
  116.         no_authority            = 5  
  117.         unknown_error           = 6  
  118.         header_not_allowed      = 7  
  119.         separator_not_allowed   = 8  
  120.         filesize_not_allowed    = 9  
  121.         header_too_long         = 10  
  122.         dp_error_create         = 11  
  123.         dp_error_send           = 12  
  124.         dp_error_write          = 13  
  125.         unknown_dp_error        = 14  
  126.         access_denied           = 15  
  127.         dp_out_of_memory        = 16  
  128.         disk_full               = 17  
  129.         dp_timeout              = 18  
  130.         file_not_found          = 19  
  131.         dataprovider_exception  = 20  
  132.         control_flush_error     = 21  
  133.         not_supported_by_gui    = 22  
  134.         error_no_gui            = 23  
  135.         OTHERS                  = 24.  
  136.   
  137. if sy-subrc <> 0.  
  138. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO  
  139. *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.  
  140. endif.  
  141.   
  142. ENDFORM.                    "call_upload  
  143. *&---------------------------------------------------------------------*  
  144. *&      Form  update_data  
  145. *&---------------------------------------------------------------------*  
  146. *       text  
  147. *----------------------------------------------------------------------*  
  148. FORM update_data.  
  149.   
  150.   REFRESH zitab_bdc.  
  151.   
  152.   LOOP AT t_main.  
  153.     PERFORM call_transaction.  
  154.   ENDLOOP.  
  155. ENDFORM.                    "update_data  
  156.   
  157. *&---------------------------------------------------------------------*  
  158. *&      Form  call_transaction  
  159. *&---------------------------------------------------------------------*  
  160. *       text  
  161. *----------------------------------------------------------------------*  
  162. FORM call_transaction.  
  163.   
  164. dynpro: 'X'   'SAPLMGMM'  '0060',  
  165.              ' '   'RMMG1-MATNR'   t_main-matnr,  
  166.              ' '   'BDC_OKCODE'    '/00'.  
  167.   
  168. dynpro: 'X'   'SAPLMGMM'   '0070',  
  169.              ' '   'MSICHTAUSW-KZSEL(01)'  'X',  
  170.              ' '   'BDC_OKCODE'  '=ENTR'.  
  171.   
  172. dynpro: 'X'   'SAPLMGMM'    '4004',  
  173.              ' '   'BDC_OKCODE'  '=ZU01'.  
  174.   
  175. dynpro:  'X'   'SAPLMGMM'    '4300',  
  176.               ' '   'SKTEXT-SPRAS(02)'  'ZH',  
  177.               ' '   'SKTEXT-MAKTX(02)'  t_main-maktx,  
  178.               ' '   'BDC_OKCODE'    '=BU'.  
  179.   
  180.   
  181.   CALL TRANSACTION 'MM02' USING zitab_bdc MODE m UPDATE 'S' MESSAGES INTO mssg.  
  182.   
  183.   IF sy-subrc NE 0.  
  184.     MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno  
  185.             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.  
  186.   ENDIF.  
  187.   REFRESH: zitab_bdc,mssg.  
  188.   
  189. 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的例子, 是把前面的程序改了一下完成的, 注意红色的地方就是不同处:

  1. *&---------------------------------------------------------------------*  
  2. *& Report  ZBDC_TEST2  
  3. *&  批输入  
  4. *&---------------------------------------------------------------------*  
  5. *&  Author: Jun  
  6. *&  
  7. *&---------------------------------------------------------------------*  
  8.   
  9. REPORT  zbdc_test2.  
  10.   
  11. ************************************************************************  
  12. * D A T A  
  13. ************************************************************************  
  14.   
  15. CONSTANTS: c_def_path LIKE rlgrap-filename VALUE 'c:\file.txt'.  
  16.   
  17. DATA: BEGIN OF zitab_bdc OCCURS 0.  
  18.         INCLUDE STRUCTURE bdcdata.  
  19. DATA: END OF zitab_bdc.  
  20.   
  21. DATA: BEGIN OF t_main OCCURS 0,  
  22.       matnr(18),  
  23.       maktx(40),  
  24.       END OF t_main.  
  25.   
  26. DEFINE dynpro.  
  27.   
  28.   CLEAR zitab_bdc.  
  29.   IF &1 = 'X'.  
  30.   
  31.     MOVE: 'X' TO zitab_bdc-dynbegin,  
  32.         &2  TO zitab_bdc-program,  
  33.         &3 TO zitab_bdc-dynpro.  
  34.   
  35.   ELSE.  
  36.   
  37.     MOVE: &2 TO zitab_bdc-fnam,  
  38.  &3 TO zitab_bdc-fval.  
  39.   
  40.   ENDIF.  
  41.   
  42.   APPEND zitab_bdc.  
  43.   
  44. END-OF-DEFINITION.  
  45.   
  46. SELECTION-SCREEN BEGIN OF BLOCK sc1 WITH FRAME TITLE text-s01.  
  47. PARAMETER: f_cap TYPE rlgrap-filename OBLIGATORY DEFAULT c_def_path.  
  48. SELECTION-SCREEN END OF BLOCK sc1.  
  49.   
  50.   
  51. ************************************************************************  
  52. * S T A R T O F S E L E C T I O N  
  53. ************************************************************************  
  54. START-OF-SELECTION.  
  55.   WRITE : / 'Start creation of BDC session',sy-mandt,sy-uname,sy-uzeit.  
  56.   PERFORM get_codepage.  
  57.   PERFORM call_upload TABLES t_main USING f_cap.  
  58.   PERFORM update_data.  
  59.   
  60.   WRITE: / 'Finished!'.  
  61.   
  62.   
  63. ************************************************************************  
  64. * F O R M S  
  65. ************************************************************************  
  66. *&---------------------------------------------------------------------*  
  67. *&  
  68. *&      Form  GET_CODEPAGE  
  69. *&---------------------------------------------------------------------*  
  70. FORM get_codepage.  
  71.   
  72.   DATA: cncoden TYPE abap_encod,  
  73.         cncode type  CPCODEPAGE.  
  74.   
  75.   CALL FUNCTION 'NLS_GET_FRONTEND_CP'  
  76.     EXPORTING  
  77.       langu                 = '1'  
  78.     IMPORTING  
  79.       frontend_codepage     = cncode  
  80.     EXCEPTIONS  
  81.       illegal_syst_codepage = 21  
  82.       no_frontend_cp_found  = 23  
  83.       internal_or_db_error  = 25.  
  84.   MOVE: cncode TO cncoden.  
  85. ENDFORM.  
  86.   
  87. *&---------------------------------------------------------------------*  
  88. *&  
  89. *&      Form  CALL_UPLOAD  
  90. *&---------------------------------------------------------------------*  
  91.   
  92. FORM call_upload TABLES p_tab USING p_fname.  
  93.   
  94.   DATA: tmp_filename TYPE string.  
  95.   
  96.   tmp_filename = p_fname.  
  97.   
  98.   
  99.     CALL METHOD cl_gui_frontend_services=>gui_download  
  100.       EXPORTING  
  101.         filename                = tmp_filename  
  102.  write_field_separator     = 'X'  
  103.         codepage                = cncoden  
  104.       CHANGING  
  105.         data_tab                = p_tab  
  106.       EXCEPTIONS  
  107.         file_write_error        = 1  
  108.         no_batch                = 2  
  109.         gui_refuse_filetransfer = 3  
  110.         invalid_type            = 4  
  111.         no_authority            = 5  
  112.         unknown_error           = 6  
  113.         header_not_allowed      = 7  
  114.         separator_not_allowed   = 8  
  115.         filesize_not_allowed    = 9  
  116.         header_too_long         = 10  
  117.         dp_error_create         = 11  
  118.         dp_error_send           = 12  
  119.         dp_error_write          = 13  
  120.         unknown_dp_error        = 14  
  121.         access_denied           = 15  
  122.         dp_out_of_memory        = 16  
  123.         disk_full               = 17  
  124.         dp_timeout              = 18  
  125.         file_not_found          = 19  
  126.         dataprovider_exception  = 20  
  127.         control_flush_error     = 21  
  128.         not_supported_by_gui    = 22  
  129.         error_no_gui            = 23  
  130.         OTHERS                  = 24.  
  131.   
  132. if sy-subrc <> 0.  
  133. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO  
  134. *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.  
  135. endif.  
  136.   
  137. ENDFORM.                    "call_upload  
  138. *&---------------------------------------------------------------------*  
  139. *&      Form  update_data  
  140. *&---------------------------------------------------------------------*  
  141. *       text  
  142. *----------------------------------------------------------------------*  
  143. FORM update_data.  
  144.   
  145. <font color="#ff0000">    CALL FUNCTION 'BDC_OPEN_GROUP'  
  146.       EXPORTING  
  147.         CLIENT              = SY-MANDT  
  148.         GROUP               = P_S_NAME  
  149.         KEEP                = 'X'  
  150.         USER                = SY-UNAME  
  151.       EXCEPTIONS  
  152.         CLIENT_INVALID      = 1  
  153.         DESTINATION_INVALID = 2  
  154.         GROUP_INVALID       = 3  
  155.         GROUP_IS_LOCKED     = 4  
  156.         HOLDDATE_INVALID    = 5  
  157.         INTERNAL_ERROR      = 6  
  158.         QUEUE_ERROR         = 7  
  159.         RUNNING             = 8  
  160.         SYSTEM_LOCK_ERROR   = 9  
  161.         USER_INVALID        = 10  
  162.         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.  
  1. <font color="#ff0000">    IF SY-SUBRC <> 0.  
  2.       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO  
  3.               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.  
  4.     ENDIF.  
  5. </font>  
  6.   
  7.   REFRESH zitab_bdc.  
  8.   
  9.   LOOP AT t_main.  
  10.     PERFORM  batch_input.  
  11.   
  12.   ENDLOOP.  
  13.   
  14. <font color="#ff0000">    CALL FUNCTION 'BDC_CLOSE_GROUP'  
  15.     EXCEPTIONS  
  16.       NOT_OPEN    = 1  
  17.       QUEUE_ERROR = 2  
  18.       OTHERS      = 3.  
  19.   
  20.     IF SY-SUBRC <> 0.  
  21.       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO  
  22.               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.  
  23.     ENDIF.  
  24. </font>  
  25. ENDFORM.                    "update_data  
  26.   
  27. *&---------------------------------------------------------------------*  
  28. *&      Form  batch_input  
  29.   
  30. *&---------------------------------------------------------------------*  
  31. *       text  
  32. *----------------------------------------------------------------------*  
  33. FORM batch_input.  
  34.   
  35. dynpro:  
  36.   'X'   'SAPLMGMM'  '0060',  
  37.   ' '   'RMMG1-MATNR'   t_main-matnr,  
  38.   ' '   'BDC_OKCODE'    '/00'.  
  39.   
  40.   dynpro:  
  41.   'X'   'SAPLMGMM'   '0070',  
  42.   ' '   'MSICHTAUSW-KZSEL(01)'  'X',  
  43.   ' '   'BDC_OKCODE'  '=ENTR'.  
  44.   
  45. dynpro:  
  46.   'X'   'SAPLMGMM'    '4004',  
  47.   ' '   'BDC_OKCODE'  '=ZU01'.  
  48.   
  49. dynpro:  
  50.   'X'   'SAPLMGMM'    '4300',  
  51.   ' '   'SKTEXT-SPRAS(02)'  'ZH',  
  52.   ' '   'SKTEXT-MAKTX(02)'  t_main-maktx,  
  53.   ' '   'BDC_OKCODE'    '=BU'.  
  54.   
  55. <font color="#ff0000">    CALL FUNCTION 'BDC_INSERT'  
  56.       EXPORTING  
  57.         TCODE            = 'MM02'  
  58.       TABLES  
  59.         DYNPROTAB        = zitab_bdc  
  60.       EXCEPTIONS  
  61.         INTERNAL_ERROR   = 1  
  62.         NOT_OPEN         = 2  
  63.         QUEUE_ERROR      = 3  
  64.         TCODE_INVALID    = 4  
  65.         PRINTING_INVALID = 5  
  66.         POSTING_INVALID  = 6  
  67.         OTHERS           = 7.  
  68.   
  69.   
  70.       IF SY-SUBRC <> 0.  
  71.         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO  
  72.                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.  
  73.       ENDIF.</font>  
  74.   
  75.   REFRESH: zitab_bdc.  
  76.   
  77. 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的例子:
  1. <pre class="csharp" name="code">*&---------------------------------------------------------------------*  
  2. *& Report  ZCON0026  
  3. *&  
  4. *&---------------------------------------------------------------------*  
  5. *&  Author: Jun  
  6. *&  
  7. *&---------------------------------------------------------------------*  
  8.   
  9. REPORT  ZCON0026.  
  10.   
  11. FIELD-SYMBOLS : <fs></fs>.  
  12. <font color="#ff0000">DATA:wa_pohead  TYPE bapimepoheader.  
  13. DATA:wa_poheadx TYPE bapimepoheaderx.  
  14. DATA:wa_poaddrvendor TYPE bapimepoaddrvendor.  
  15. DATA:wa_testrun TYPE bapiflag-bapiflag.</font>  
  16. DATA:g_ebeln TYPE ekko-ebeln.   "Purchasing Document Header  
  17. DATA:g_mtart TYPE mtart.  
  18.   
  19. <font color="#ff0000">DATA:it_return    TYPE bapiret2       OCCURS 0 WITH HEADER LINE.  
  20. DATA:it_msg       TYPE bapiret2       OCCURS 0 WITH HEADER LINE.</font>  
  21. DATA:BEGIN OF it_msg1 OCCURS 0,  
  22.           ebeln LIKE ekpo-ebeln,  
  23.           type like bapiret2-type,  
  24.           message LIKE bapiret2-message,  
  25.           old_po like ekpo-ebeln,  
  26.      END  OF it_msg1.  
  27. <font color="#ff0000">DATA:it_poitem    TYPE bapimepoitem   OCCURS 0 WITH HEADER LINE.  
  28. DATA:it_poitemx   TYPE bapimepoitemx  OCCURS 0 WITH HEADER LINE.  
  29. DATA:it_pocondh   TYPE bapimepocondheader OCCURS 0 WITH HEADER LINE.  
  30. DATA:it_pocondhx  TYPE bapimepocondheaderx OCCURS 0 WITH HEADER LINE.  
  31. DATA:it_pocond    TYPE bapimepocond   OCCURS 0 WITH HEADER LINE.  
  32. DATA:it_pocondx   TYPE bapimepocondx  OCCURS 0 WITH HEADER LINE.  
  33. DATA:it_potexth   TYPE bapimepotextheader  OCCURS 0 WITH HEADER LINE.  
  34. DATA:it_potexti   TYPE bapimepotext  OCCURS 0 WITH HEADER LINE.  
  35. DATA:it_popartner TYPE bapiekkop  OCCURS 0 WITH HEADER LINE.  
  36. DATA:it_extens    TYPE bapiparex  OCCURS 0 WITH HEADER LINE.    "Customer's Own Fields  
  37. DATA:it_poaccount TYPE bapimepoaccount  OCCURS 0 WITH HEADER LINE.  
  38. DATA:it_poaccountx TYPE bapimepoaccountx  OCCURS 0 WITH HEADER LINE.  
  39. DATA:it_poche      TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE.  
  40. DATA:it_pochex     TYPE bapimeposchedulx OCCURS 0 WITH HEADER LINE.  
  41. DATA:purchseorder TYPE BAPIMEPOHEADER-PO_NUMBER.</font>  
  42.   
  43. DATA:g_poitem TYPE ebelp.   "Item Number of Purchasing Document  
  44. DATA:g_meng LIKE ekpo-menge.    "Purchase Order Quantity  
  45. DATA:l_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE.  
  46. DATA:len_str TYPE i,  
  47.      l_index TYPE i.  
  48.   
  49. DATA:BEGIN OF it_data OCCURS 0,  
  50. *       doc_type(004),   </pre>  
  51. <pre class="csharp" name="code">       po(010),  "PO NO  
  52.        material(018),  
  53.        vendor(010),  
  54.        invoice_no(15),  "Invoice Number(Header text)  
  55.        pmnttrms(004),   "Paymentterms  
  56.        quantity(017),  
  57.        doc_date(008),  
  58.        gr_to_date(008), "Delivery date  
  59.        shippingin(10),  "Ship Date(Header Text)  
  60.        eta_hk(10),      "Date of ETA HK(Header Text)  
  61.        trsp_metd(10),   "Transportion Method(Header Text)  
  62.        container_no(20),  "COntainer Number(Header Text)  
  63.        lc_number(20),   "LC Number(Header Text)  
  64.        load_date(10),   "Load Date(Header Text)  
  65.        arr_hk(10),      "Date of Arr. Date(Header Text)  
  66.        remark(20),      "Header remark(Header Text)  
  67.        currency(005),  
  68.        cond_pb00(038),  "Net price  
  69.        cond_p_unt(5),    "Price Unit  
  70.   
  71. END OF it_data.  
  72. DATA:BEGIN OF it_head OCCURS 0,  
  73.        comp_code(4),    "Company Code  
  74.        doc_type(004),   "######  
  75.        po_number(010),  
  76.        po(010),  
  77.        vendor(010),     "######  
  78.        doc_date(008),   "####  
  79.        purch_org(004),  "####  
  80.        pur_group(003),  "####  
  81.        pmnttrms(004),   "####  
  82.        incoterms1(003), "######  
  83.        incoterms2(028), "######  
  84.        currency(005),   "####  
  85.        exch_rate(014),  "##  
  86.        text_pohzs(132), "Header Remark  
  87.        shippingin(132), "SHIPPING INSTRUCTION  
  88.        prppayment(132), "PAYMENT TERM FOR PRP  
  89.        delivery(132),   "DELIVERY  
  90.        attention(132),  "ATTENTION  
  91.        name_2(040),                                         "#####2  
  92.        name_3(040),                                         "#####3  
  93.        name_4(040),                                         "#####4  
  94.        street(040),     "##  
  95.        str_suppl2(040), "##4  
  96.        location(040),   "##5  
  97.        postl_cod1(010), "######  
  98.        country(003),    "####  
  99.        tel1_numbr(030), "##  
  100.        fax_number(030), "##  
  101.        billty(002),     "########  
  102.        billpo(010),     "######  
  103.        purcty(002),     "########  
  104.        purcpo(010),     "#####  
  105.        patety(002),     "########  
  106.        patepo(010),     "######  
  107.        shipty(002),     "########  
  108.        shippo(010),     "######  
  109.        COLLECT_NO(010),   "Collective Number  
  110.      END   OF it_head.  
  111. DATA:BEGIN OF it_item OCCURS 0,  
  112.        po_number(010),  "  
  113.        po(010),  
  114.        acctasscat(001), "######  
  115.        item_cat(001),   "####  
  116.        material(018),   "######  
  117.        short_text(040), "####  
  118.        quantity(017),   "######  
  119.        po_unit(003),    "####  
  120.        gr_to_date(008), "####  
  121.        cond_pb00(038),  "Net Price  
  122.        cond_p_unt(005), "########  
  123.        cond_za00(038),  "UNZ#UTE######  
  124.        matl_group(009), "####  
  125.        plant(004),      "##  
  126.        over_dlv_tol(005),"########  
  127.        tax_code(002),    "##/######  
  128.        costcenter(010),  "####  
  129.        poit_text(132),   "PO####  
  130.        pobz_text(132),   "PO####  
  131.        valuepart1(240),  "Exfact Date  
  132.        valuepart2(240),  "Arr.HK Date  
  133.      END OF it_item.  
  134. DATA:g_menge LIKE ekpo-netpr.  
  135. ******************************************************************  
  136. *   PARAMETERS & SELECTION-OPTIONS  
  137. ******************************************************************  
  138. SELECTION-SCREEN BEGIN OF BLOCK sel  WITH FRAME TITLE text-001.  
  139. PARAMETERS:p_upload RADIOBUTTON GROUP radi,  
  140.            p_uptemp RADIOBUTTON GROUP radi.  
  141. PARAMETERS:p_flag  AS CHECKBOX .  
  142. SELECTION-SCREEN END OF BLOCK sel.  
  143.   
  144. SELECTION-SCREEN BEGIN OF BLOCK mod  WITH FRAME TITLE text-002.  
  145. PARAMETERS:p_file LIKE  rlgrap-filename DEFAULT 'c:\podata',  
  146.            p_log  LIKE  rlgrap-filename DEFAULT 'c:\polog.xls'.  
  147. SELECTION-SCREEN END OF BLOCK mod.  
  148.   
  149. START-OF-SELECTION.  
  150.   IF p_upload = 'X'.  
  151.     PERFORM upload_file.  
  152.     PERFORM upload_data.  
  153.   ENDIF.  
  154.   
  155.   
  156. *&--------------------------------------------------------------------*  
  157. *&      Form  upload_file  
  158. *&--------------------------------------------------------------------*  
  159. *       text  
  160. *---------------------------------------------------------------------*  
  161. FORM upload_file.  
  162.   
  163.   TRANSLATE p_file TO UPPER CASE.  
  164.   len_str = STRLEN( p_file ).  
  165.   len_str = len_str - 4.  
  166.   IF p_file+len_str(4) <> '.XLS'.  
  167.     CONCATENATE p_file '.XLS' INTO p_file.  
  168.   ENDIF.  
  169.   CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'  
  170.     EXPORTING  
  171.       filename                = p_file  
  172.       i_begin_col             = 1  
  173.       i_begin_row             = 2  
  174.       i_end_col               = 256  
  175.       i_end_row               = 65535  
  176.     TABLES  
  177.       intern                  = l_intern  
  178.     EXCEPTIONS  
  179.       inconsistent_parameters = 1  
  180.       upload_ole              = 2  
  181.       OTHERS                  = 3.  
  182.   IF sy-subrc <> 0.  
  183.   ENDIF.  
  184.   
  185.   SORT l_intern BY row col.  
  186.   LOOP AT l_intern.  
  187.     MOVE l_intern-col TO l_index.  
  188.     ASSIGN COMPONENT l_index OF STRUCTURE it_data TO <fs></fs>.  
  189.     MOVE l_intern-value TO <fs></fs>.  
  190.     AT END OF row.  
  191.       APPEND it_data.  
  192.       CLEAR  it_data.  
  193.     ENDAT.  
  194.   ENDLOOP.  
  195.   
  196. ENDFORM.                    "UPLOAD_FILE  
  197. *&---------------------------------------------------------------------*  
  198. *&      Form  UPLOAD_DATA  
  199. *&---------------------------------------------------------------------*  
  200. FORM upload_data .  
  201.   CLEAR:it_head,it_item.  
  202.   LOOP AT it_data.  
  203.     MOVE-CORRESPONDING it_data TO it_head.  
  204.     it_head-COLLECT_NO = it_data-po.  
  205.     COLLECT it_head.  
  206.     MOVE-CORRESPONDING it_data TO it_item.  
  207.     APPEND  it_item.  
  208.   ENDLOOP.  
  209.   REFRESH it_msg.  
  210.   
  211.   
  212.   LOOP AT it_head.  
  213.     CLEAR: it_potexth,wa_pohead,wa_poheadx,wa_poaddrvendor.  
  214.     REFRESH:it_potexth,it_popartner.  
  215. *Document Type  
  216.     wa_pohead-doc_type = 'NB'.  
  217.     wa_poheadx-doc_type = 'X'.  
  218.   
  219. *Vendor Number  
  220.     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'  
  221.       EXPORTING  
  222.         input  = it_head-vendor  
  223.       IMPORTING  
  224.         output = it_head-vendor.  
  225.     wa_pohead-vendor = it_head-vendor.  
  226.     wa_poheadx-vendor = 'X'.  
  227. *Document Date  
  228.     wa_pohead-doc_date = it_head-doc_date.  
  229.     wa_poheadx-doc_date = 'X'.  
  230.   
  231. *Collective Number  
  232.     wa_pohead-COLLECT_NO = it_head-COLLECT_NO.  
  233.     wa_poheadx-COLLECT_NO = 'X'.  
  234.   
  235. *Company Code  
  236.       wa_pohead-comp_code = '8200'.  
  237.       wa_poheadx-comp_code = 'X'.  
  238.   
  239.   
  240. *Purchase Organise  
  241.       wa_pohead-purch_org = '8200'.  
  242.   
  243. *Purchase Group  
  244.       wa_pohead-pur_group = '003'.  
  245.       wa_poheadx-pur_group = 'X'.  
  246.   
  247. *Payment term  
  248.       wa_pohead-pmnttrms = it_head-pmnttrms.  
  249.       wa_poheadx-pmnttrms = 'X'.  
  250.   
  251. *Currency  
  252.     wa_pohead-currency = it_head-currency.  
  253.     wa_poheadx-currency = 'X'.  
  254.   
  255. *Purchase Order Header Text  
  256.       it_potexth-text_line = it_data-remark.    "Header Remark(Header Text)  
  257.       it_potexth-po_number = it_head-po_number.  
  258.       it_potexth-text_id   = 'F01'.  
  259.       APPEND it_potexth.  
  260.       CLEAR it_potexth.  
  261.   
  262. *SHIPPING INSTRUCTION  
  263.     it_potexth-text_line = it_head-shippingin.  "Ship Date(Header Text)  
  264.     it_potexth-po_number = it_head-po_number.  
  265.     it_potexth-text_id   = 'F02'.  
  266.     APPEND it_potexth.  
  267.     CLEAR it_potexth.  
  268. *PAYMENT TERM FOR PRP  
  269.     it_potexth-text_line = it_data-load_date.  "Load Date(Header Text)  
  270.     it_potexth-po_number = it_head-po_number.  
  271.     it_potexth-text_id   = 'F03'.  
  272.     APPEND it_potexth.  
  273.     CLEAR it_potexth.  
  274. *Date of ETA HK  
  275.     it_potexth-text_line = it_data-eta_hk.    "Date of ETA HK  
  276.     it_potexth-po_number = it_head-po_number.  
  277.     it_potexth-text_id   = 'F04'.  
  278.     APPEND it_potexth.  
  279.     CLEAR it_potexth.  
  280. *Date of Arr HK  
  281.     it_potexth-text_line = it_data-arr_hk.    "Date of Arr HK  
  282.     it_potexth-po_number = it_head-po_number.  
  283.     it_potexth-text_id   = 'F05'.  
  284.     APPEND it_potexth.  
  285.     CLEAR it_potexth.  
  286.   
  287. *Transpotion Method  
  288.     it_potexth-text_line = it_data-trsp_metd.  
  289.     it_potexth-po_number = it_head-po_number.  
  290.     it_potexth-text_id   = 'F06'.  
  291.     APPEND it_potexth.  
  292.     CLEAR it_potexth.  
  293.   
  294. *Container Number  
  295.     it_potexth-text_line = it_data-container_no.  
  296.     it_potexth-po_number = it_head-po_number.  
  297.     it_potexth-text_id   = 'F07'.  
  298.     APPEND it_potexth.  
  299.     CLEAR it_potexth.  
  300.   
  301. *LC Number  
  302.     it_potexth-text_line = it_data-lc_number.  
  303.     it_potexth-po_number = it_head-po_number.  
  304.     it_potexth-text_id   = 'F08'.  
  305.     APPEND it_potexth.  
  306.     CLEAR it_potexth.  
  307.   
  308. *Invoice Number  
  309.     it_potexth-text_line = it_data-invoice_no.  
  310.     it_potexth-po_number = it_head-po_number.  
  311.     it_potexth-text_id   = 'F09'.  
  312.     APPEND it_potexth.  
  313.     CLEAR it_potexth.  
  314.   
  315.   
  316. *Purchase Order Item Information  
  317.     CLEAR g_poitem.  
  318.     REFRESH: it_poitemx,it_poitem,it_pocond,it_pocondx,  
  319.              it_poche,it_pochex .  
  320.   
  321.     LOOP AT it_item.  
  322.       IF  it_item-po EQ it_head-po.  
  323.         CLEAR:it_poitem, it_poitemx.  
  324.         g_poitem = g_poitem + 10.  
  325.         it_poitem-po_item = g_poitem.  
  326.         it_poitemx-po_item = g_poitem.  
  327.         it_poitem-item_cat = it_item-item_cat.  
  328.         it_poitemx-item_cat = 'X'.  
  329.         it_poitemx-po_itemx = 'X'.  
  330.         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'  
  331.           EXPORTING  
  332.             input  = it_item-material  
  333.           IMPORTING  
  334.             output = it_item-material.  
  335.   
  336.         it_poitem-material = it_item-material.  
  337.         it_poitemx-material = 'X'.  
  338.         IF it_item-short_text IS NOT INITIAL.  
  339.           it_poitem-short_text = it_item-short_text.  
  340.           it_poitemx-short_text = 'X'.  
  341.   
  342.         ENDIF.  
  343.   
  344.         CLEAR g_meng.  
  345.         g_meng = it_item-quantity.  
  346.         it_poitem-quantity = g_meng.  
  347.         it_poitemx-quantity = 'X'.  
  348.         it_poitem-po_unit =  it_item-po_unit.  
  349.         it_poitemx-po_unit =  'X'.  
  350.   
  351.         CLEAR g_mtart.  
  352.         SELECT SINGLE mtart INTO g_mtart FROM mara  
  353.                 WHERE matnr EQ it_item-material.  
  354.         IF g_mtart EQ 'ZNON'.  
  355.           it_poitem-acctasscat = 'Z'.  
  356.           it_poitemx-acctasscat = 'X'.  
  357.         ENDIF.  
  358.   
  359.   
  360.         CLEAR:  it_poche,it_pochex.  
  361.         it_poche-po_item   = g_poitem.  
  362.         it_pochex-po_item  = g_poitem.  
  363.         it_poche-sched_line   = g_poitem.  
  364.         it_pochex-sched_line  = g_poitem.  
  365.         it_poche-delivery_date  = it_item-gr_to_date.  
  366.         it_pochex-delivery_date  = 'X'.  
  367.   
  368.         it_poche-quantity   = g_meng.  
  369.         it_pochex-quantity  = 'X'.  
  370.   
  371.         it_pochex-po_itemx = 'X'.  
  372.         it_pochex-sched_linex = 'X'.  
  373.   
  374.   
  375.         APPEND: it_poche,it_pochex.  
  376.   
  377.         it_poitem-plant = '8200'.  
  378.         it_poitemx-plant = 'X'.  
  379.         IF it_item-matl_group IS NOT INITIAL.  
  380.           it_poitem-matl_group = it_item-matl_group.  
  381.           it_poitemx-matl_group = 'X'.  
  382.         ENDIF.  
  383.         it_poitem-over_dlv_tol = it_item-over_dlv_tol.  
  384.         it_poitemx-over_dlv_tol = 'X'.  
  385.         it_poitem-tax_code = it_item-tax_code.  
  386.         it_poitemx-tax_code = 'X'.  
  387.         g_menge = it_item-cond_pb00.  
  388.   
  389.         IF g_menge EQ  0.  
  390.           it_poitem-free_item = 'X'.  
  391.           it_poitemx-free_item = 'X'.  
  392.         ELSE.  
  393.           it_poitem-free_item = ''.  
  394.           it_poitemx-free_item = 'X'.  
  395.         ENDIF.  
  396.   
  397.         it_poitem-matl_group = it_item-matl_group.  
  398.         it_poitemx-matl_group = 'X'.  
  399.   
  400.   
  401.         IT_POITEM-NET_PRICE = IT_ITEM-COND_PB00.  
  402.         IT_POITEMX-NET_PRICE = 'X'.  
  403.         it_poitem-price_unit = it_item-cond_p_unt.  
  404.         it_poitemx-price_unit = 'X'.  
  405.         APPEND:it_poitemx,it_poitem.  
  406.   
  407.   
  408. *ConditionS  
  409.         CLEAR it_pocond.  
  410.         it_pocond-cond_type = 'PB00'.  
  411.         it_pocond-itm_number = it_poitem-po_item.  
  412.         it_pocond-cond_value = IT_ITEM-COND_PB00.  
  413.         it_pocond-cond_p_unt  =  it_item-cond_p_unt.  
  414.         it_pocond-currency    = it_head-currency.  
  415.         it_pocond-change_id   = 'U'.  
  416.         APPEND it_pocond.  
  417.   
  418.         CLEAR it_pocondx.  
  419.         it_pocondx-cond_type = 'X'.  
  420.         it_pocondx-itm_number = it_poitem-po_item.  
  421.         it_pocondx-cond_value = 'X'.  
  422.         it_pocondx-cond_p_unt = 'X'.  
  423.         it_pocondx-currency    = 'X'.  
  424.         it_pocondx-change_id   = 'X'.  
  425.         APPEND it_pocondx.  
  426.   
  427.       ENDIF.  
  428.     ENDLOOP.  
  429.   
  430.     wa_testrun = p_flag.  
  431.     DELETE it_item WHERE  po EQ it_head-po.  
  432.     SELECT SINGLE ebeln INTO g_ebeln FROM ekko  
  433.         WHERE ebeln EQ wa_pohead-po_number.  
  434.     IF sy-subrc NE 0.  
  435. <font color="#ff0000">      CALL FUNCTION 'BAPI_PO_CREATE1'  
  436.         EXPORTING  
  437.           poheader     = wa_pohead  
  438.           poheaderx    = wa_poheadx  
  439.           poaddrvendor = wa_poaddrvendor  
  440.           testrun      = wa_testrun  
  441.         IMPORTING  
  442.           EXPPURCHASEORDER        = purchseorder  
  443.         TABLES  
  444.           return       = it_return  
  445.           poitem       = it_poitem  
  446.           poitemx      = it_poitemx  
  447.           poschedule   = it_poche  
  448.           poschedulex  = it_pochex  
  449.           pocond       = it_pocond  
  450.           pocondx      = it_pocondx  
  451.           potextheader = it_potexth  
  452.           potextitem   = it_potexti  
  453.           popartner    = it_popartner.</font>  
  454.   
  455. <font color="#ff0000">CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.  
  456.     WAIT UP TO 1 SECONDS.</font>  
  457.     REFRESH: it_poitem,it_poitemx,it_poche,it_pochex,  
  458.              it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner.  
  459.     CLEAR:it_return,it_poitem,it_poitemx,it_poche,it_pochex,  
  460.              it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner.  
  461.     DELETE it_item WHERE po EQ it_head-po.  
  462.     DELETE it_head WHERE po EQ it_head-po.  
  463. *    LOOP AT it_return WHERE type EQ 'E'.  
  464.     LOOP AT it_return.  
  465.       MOVE-CORRESPONDING it_return TO it_msg1.  
  466. *      it_msg1-ebeln = wa_pohead-po_number.  
  467.       it_msg1-ebeln = purchseorder.  
  468.       it_msg1-old_po = it_head-po.  
  469.       APPEND it_msg1.  
  470.       clear it_msg1.  
  471.     ENDLOOP.  
  472.     ENDIF.  
  473.   
  474.   ENDLOOP.  
  475.   
  476.   
  477.   CALL FUNCTION 'WS_DOWNLOAD'  
  478.     EXPORTING  
  479.       filename                = p_log  
  480.       filetype                = 'DAT'  
  481.       mode                    = 'O'  
  482.     TABLES  
  483.       data_tab                = it_msg1  
  484.     EXCEPTIONS  
  485.       invalid_filesize        = 1  
  486.       invalid_table_width     = 2  
  487.       invalid_type            = 3  
  488.       no_batch                = 4  
  489.       unknown_error           = 5  
  490.       gui_refuse_filetransfer = 6  
  491.       OTHERS                  = 7.  
  492.   IF sy-subrc <> 0.  
  493.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno  
  494.             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.  
  495.   ENDIF.  
  496.   
  497. ENDFORM.                    " UPLOAD_DATA  
  498. </pre>  
  1. *&---------------------------------------------------------------------*  
  2. *& Report  ZCON0026  
  3. *&  
  4. *&---------------------------------------------------------------------*  
  5. *&  Author: Jun  
  6. *&  
  7. *&---------------------------------------------------------------------*  
  8.   
  9. REPORT  ZCON0026.  
  10.   
  11. FIELD-SYMBOLS : <fs></fs>.  
  12. <font color="#ff0000">DATA:wa_pohead  TYPE bapimepoheader.  
  13. DATA:wa_poheadx TYPE bapimepoheaderx.  
  14. DATA:wa_poaddrvendor TYPE bapimepoaddrvendor.  
  15. DATA:wa_testrun TYPE bapiflag-bapiflag.</font>  
  16. DATA:g_ebeln TYPE ekko-ebeln.   "Purchasing Document Header  
  17. DATA:g_mtart TYPE mtart.  
  18.   
  19. <font color="#ff0000">DATA:it_return    TYPE bapiret2       OCCURS 0 WITH HEADER LINE.  
  20. DATA:it_msg       TYPE bapiret2       OCCURS 0 WITH HEADER LINE.</font>  
  21. DATA:BEGIN OF it_msg1 OCCURS 0,  
  22.           ebeln LIKE ekpo-ebeln,  
  23.           type like bapiret2-type,  
  24.           message LIKE bapiret2-message,  
  25.           old_po like ekpo-ebeln,  
  26.      END  OF it_msg1.  
  27. <font color="#ff0000">DATA:it_poitem    TYPE bapimepoitem   OCCURS 0 WITH HEADER LINE.  
  28. DATA:it_poitemx   TYPE bapimepoitemx  OCCURS 0 WITH HEADER LINE.  
  29. DATA:it_pocondh   TYPE bapimepocondheader OCCURS 0 WITH HEADER LINE.  
  30. DATA:it_pocondhx  TYPE bapimepocondheaderx OCCURS 0 WITH HEADER LINE.  
  31. DATA:it_pocond    TYPE bapimepocond   OCCURS 0 WITH HEADER LINE.  
  32. DATA:it_pocondx   TYPE bapimepocondx  OCCURS 0 WITH HEADER LINE.  
  33. DATA:it_potexth   TYPE bapimepotextheader  OCCURS 0 WITH HEADER LINE.  
  34. DATA:it_potexti   TYPE bapimepotext  OCCURS 0 WITH HEADER LINE.  
  35. DATA:it_popartner TYPE bapiekkop  OCCURS 0 WITH HEADER LINE.  
  36. DATA:it_extens    TYPE bapiparex  OCCURS 0 WITH HEADER LINE.    "Customer's Own Fields  
  37. DATA:it_poaccount TYPE bapimepoaccount  OCCURS 0 WITH HEADER LINE.  
  38. DATA:it_poaccountx TYPE bapimepoaccountx  OCCURS 0 WITH HEADER LINE.  
  39. DATA:it_poche      TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE.  
  40. DATA:it_pochex     TYPE bapimeposchedulx OCCURS 0 WITH HEADER LINE.  
  41. DATA:purchseorder TYPE BAPIMEPOHEADER-PO_NUMBER.</font>  
  42.   
  43. DATA:g_poitem TYPE ebelp.   "Item Number of Purchasing Document  
  44. DATA:g_meng LIKE ekpo-menge.    "Purchase Order Quantity  
  45. DATA:l_intern TYPE kcde_cells OCCURS 0 WITH HEADER LINE.  
  46. DATA:len_str TYPE i,  
  47.      l_index TYPE i.  
  48.   
  49. DATA:BEGIN OF it_data OCCURS 0,  
  50. *       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),   
  1.        po(010),  "PO NO  
  2.        material(018),  
  3.        vendor(010),  
  4.        invoice_no(15),  "Invoice Number(Header text)  
  5.        pmnttrms(004),   "Paymentterms  
  6.        quantity(017),  
  7.        doc_date(008),  
  8.        gr_to_date(008), "Delivery date  
  9.        shippingin(10),  "Ship Date(Header Text)  
  10.        eta_hk(10),      "Date of ETA HK(Header Text)  
  11.        trsp_metd(10),   "Transportion Method(Header Text)  
  12.        container_no(20),  "COntainer Number(Header Text)  
  13.        lc_number(20),   "LC Number(Header Text)  
  14.        load_date(10),   "Load Date(Header Text)  
  15.        arr_hk(10),      "Date of Arr. Date(Header Text)  
  16.        remark(20),      "Header remark(Header Text)  
  17.        currency(005),  
  18.        cond_pb00(038),  "Net price  
  19.        cond_p_unt(5),    "Price Unit  
  20.   
  21. END OF it_data.  
  22. DATA:BEGIN OF it_head OCCURS 0,  
  23.        comp_code(4),    "Company Code  
  24.        doc_type(004),   "######  
  25.        po_number(010),  
  26.        po(010),  
  27.        vendor(010),     "######  
  28.        doc_date(008),   "####  
  29.        purch_org(004),  "####  
  30.        pur_group(003),  "####  
  31.        pmnttrms(004),   "####  
  32.        incoterms1(003), "######  
  33.        incoterms2(028), "######  
  34.        currency(005),   "####  
  35.        exch_rate(014),  "##  
  36.        text_pohzs(132), "Header Remark  
  37.        shippingin(132), "SHIPPING INSTRUCTION  
  38.        prppayment(132), "PAYMENT TERM FOR PRP  
  39.        delivery(132),   "DELIVERY  
  40.        attention(132),  "ATTENTION  
  41.        name_2(040),                                         "#####2  
  42.        name_3(040),                                         "#####3  
  43.        name_4(040),                                         "#####4  
  44.        street(040),     "##  
  45.        str_suppl2(040), "##4  
  46.        location(040),   "##5  
  47.        postl_cod1(010), "######  
  48.        country(003),    "####  
  49.        tel1_numbr(030), "##  
  50.        fax_number(030), "##  
  51.        billty(002),     "########  
  52.        billpo(010),     "######  
  53.        purcty(002),     "########  
  54.        purcpo(010),     "#####  
  55.        patety(002),     "########  
  56.        patepo(010),     "######  
  57.        shipty(002),     "########  
  58.        shippo(010),     "######  
  59.        COLLECT_NO(010),   "Collective Number  
  60.      END   OF it_head.  
  61. DATA:BEGIN OF it_item OCCURS 0,  
  62.        po_number(010),  "  
  63.        po(010),  
  64.        acctasscat(001), "######  
  65.        item_cat(001),   "####  
  66.        material(018),   "######  
  67.        short_text(040), "####  
  68.        quantity(017),   "######  
  69.        po_unit(003),    "####  
  70.        gr_to_date(008), "####  
  71.        cond_pb00(038),  "Net Price  
  72.        cond_p_unt(005), "########  
  73.        cond_za00(038),  "UNZ#UTE######  
  74.        matl_group(009), "####  
  75.        plant(004),      "##  
  76.        over_dlv_tol(005),"########  
  77.        tax_code(002),    "##/######  
  78.        costcenter(010),  "####  
  79.        poit_text(132),   "PO####  
  80.        pobz_text(132),   "PO####  
  81.        valuepart1(240),  "Exfact Date  
  82.        valuepart2(240),  "Arr.HK Date  
  83.      END OF it_item.  
  84. DATA:g_menge LIKE ekpo-netpr.  
  85. ******************************************************************  
  86. *   PARAMETERS & SELECTION-OPTIONS  
  87. ******************************************************************  
  88. SELECTION-SCREEN BEGIN OF BLOCK sel  WITH FRAME TITLE text-001.  
  89. PARAMETERS:p_upload RADIOBUTTON GROUP radi,  
  90.            p_uptemp RADIOBUTTON GROUP radi.  
  91. PARAMETERS:p_flag  AS CHECKBOX .  
  92. SELECTION-SCREEN END OF BLOCK sel.  
  93.   
  94. SELECTION-SCREEN BEGIN OF BLOCK mod  WITH FRAME TITLE text-002.  
  95. PARAMETERS:p_file LIKE  rlgrap-filename DEFAULT 'c:\podata',  
  96.            p_log  LIKE  rlgrap-filename DEFAULT 'c:\polog.xls'.  
  97. SELECTION-SCREEN END OF BLOCK mod.  
  98.   
  99. START-OF-SELECTION.  
  100.   IF p_upload = 'X'.  
  101.     PERFORM upload_file.  
  102.     PERFORM upload_data.  
  103.   ENDIF.  
  104.   
  105.   
  106. *&--------------------------------------------------------------------*  
  107. *&      Form  upload_file  
  108. *&--------------------------------------------------------------------*  
  109. *       text  
  110. *---------------------------------------------------------------------*  
  111. FORM upload_file.  
  112.   
  113.   TRANSLATE p_file TO UPPER CASE.  
  114.   len_str = STRLEN( p_file ).  
  115.   len_str = len_str - 4.  
  116.   IF p_file+len_str(4) <> '.XLS'.  
  117.     CONCATENATE p_file '.XLS' INTO p_file.  
  118.   ENDIF.  
  119.   CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT'  
  120.     EXPORTING  
  121.       filename                = p_file  
  122.       i_begin_col             = 1  
  123.       i_begin_row             = 2  
  124.       i_end_col               = 256  
  125.       i_end_row               = 65535  
  126.     TABLES  
  127.       intern                  = l_intern  
  128.     EXCEPTIONS  
  129.       inconsistent_parameters = 1  
  130.       upload_ole              = 2  
  131.       OTHERS                  = 3.  
  132.   IF sy-subrc <> 0.  
  133.   ENDIF.  
  134.   
  135.   SORT l_intern BY row col.  
  136.   LOOP AT l_intern.  
  137.     MOVE l_intern-col TO l_index.  
  138.     ASSIGN COMPONENT l_index OF STRUCTURE it_data TO <fs></fs>.  
  139.     MOVE l_intern-value TO <fs></fs>.  
  140.     AT END OF row.  
  141.       APPEND it_data.  
  142.       CLEAR  it_data.  
  143.     ENDAT.  
  144.   ENDLOOP.  
  145.   
  146. ENDFORM.                    "UPLOAD_FILE  
  147. *&---------------------------------------------------------------------*  
  148. *&      Form  UPLOAD_DATA  
  149. *&---------------------------------------------------------------------*  
  150. FORM upload_data .  
  151.   CLEAR:it_head,it_item.  
  152.   LOOP AT it_data.  
  153.     MOVE-CORRESPONDING it_data TO it_head.  
  154.     it_head-COLLECT_NO = it_data-po.  
  155.     COLLECT it_head.  
  156.     MOVE-CORRESPONDING it_data TO it_item.  
  157.     APPEND  it_item.  
  158.   ENDLOOP.  
  159.   REFRESH it_msg.  
  160.   
  161.   
  162.   LOOP AT it_head.  
  163.     CLEAR: it_potexth,wa_pohead,wa_poheadx,wa_poaddrvendor.  
  164.     REFRESH:it_potexth,it_popartner.  
  165. *Document Type  
  166.     wa_pohead-doc_type = 'NB'.  
  167.     wa_poheadx-doc_type = 'X'.  
  168.   
  169. *Vendor Number  
  170.     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'  
  171.       EXPORTING  
  172.         input  = it_head-vendor  
  173.       IMPORTING  
  174.         output = it_head-vendor.  
  175.     wa_pohead-vendor = it_head-vendor.  
  176.     wa_poheadx-vendor = 'X'.  
  177. *Document Date  
  178.     wa_pohead-doc_date = it_head-doc_date.  
  179.     wa_poheadx-doc_date = 'X'.  
  180.   
  181. *Collective Number  
  182.     wa_pohead-COLLECT_NO = it_head-COLLECT_NO.  
  183.     wa_poheadx-COLLECT_NO = 'X'.  
  184.   
  185. *Company Code  
  186.       wa_pohead-comp_code = '8200'.  
  187.       wa_poheadx-comp_code = 'X'.  
  188.   
  189.   
  190. *Purchase Organise  
  191.       wa_pohead-purch_org = '8200'.  
  192.   
  193. *Purchase Group  
  194.       wa_pohead-pur_group = '003'.  
  195.       wa_poheadx-pur_group = 'X'.  
  196.   
  197. *Payment term  
  198.       wa_pohead-pmnttrms = it_head-pmnttrms.  
  199.       wa_poheadx-pmnttrms = 'X'.  
  200.   
  201. *Currency  
  202.     wa_pohead-currency = it_head-currency.  
  203.     wa_poheadx-currency = 'X'.  
  204.   
  205. *Purchase Order Header Text  
  206.       it_potexth-text_line = it_data-remark.    "Header Remark(Header Text)  
  207.       it_potexth-po_number = it_head-po_number.  
  208.       it_potexth-text_id   = 'F01'.  
  209.       APPEND it_potexth.  
  210.       CLEAR it_potexth.  
  211.   
  212. *SHIPPING INSTRUCTION  
  213.     it_potexth-text_line = it_head-shippingin.  "Ship Date(Header Text)  
  214.     it_potexth-po_number = it_head-po_number.  
  215.     it_potexth-text_id   = 'F02'.  
  216.     APPEND it_potexth.  
  217.     CLEAR it_potexth.  
  218. *PAYMENT TERM FOR PRP  
  219.     it_potexth-text_line = it_data-load_date.  "Load Date(Header Text)  
  220.     it_potexth-po_number = it_head-po_number.  
  221.     it_potexth-text_id   = 'F03'.  
  222.     APPEND it_potexth.  
  223.     CLEAR it_potexth.  
  224. *Date of ETA HK  
  225.     it_potexth-text_line = it_data-eta_hk.    "Date of ETA HK  
  226.     it_potexth-po_number = it_head-po_number.  
  227.     it_potexth-text_id   = 'F04'.  
  228.     APPEND it_potexth.  
  229.     CLEAR it_potexth.  
  230. *Date of Arr HK  
  231.     it_potexth-text_line = it_data-arr_hk.    "Date of Arr HK  
  232.     it_potexth-po_number = it_head-po_number.  
  233.     it_potexth-text_id   = 'F05'.  
  234.     APPEND it_potexth.  
  235.     CLEAR it_potexth.  
  236.   
  237. *Transpotion Method  
  238.     it_potexth-text_line = it_data-trsp_metd.  
  239.     it_potexth-po_number = it_head-po_number.  
  240.     it_potexth-text_id   = 'F06'.  
  241.     APPEND it_potexth.  
  242.     CLEAR it_potexth.  
  243.   
  244. *Container Number  
  245.     it_potexth-text_line = it_data-container_no.  
  246.     it_potexth-po_number = it_head-po_number.  
  247.     it_potexth-text_id   = 'F07'.  
  248.     APPEND it_potexth.  
  249.     CLEAR it_potexth.  
  250.   
  251. *LC Number  
  252.     it_potexth-text_line = it_data-lc_number.  
  253.     it_potexth-po_number = it_head-po_number.  
  254.     it_potexth-text_id   = 'F08'.  
  255.     APPEND it_potexth.  
  256.     CLEAR it_potexth.  
  257.   
  258. *Invoice Number  
  259.     it_potexth-text_line = it_data-invoice_no.  
  260.     it_potexth-po_number = it_head-po_number.  
  261.     it_potexth-text_id   = 'F09'.  
  262.     APPEND it_potexth.  
  263.     CLEAR it_potexth.  
  264.   
  265.   
  266. *Purchase Order Item Information  
  267.     CLEAR g_poitem.  
  268.     REFRESH: it_poitemx,it_poitem,it_pocond,it_pocondx,  
  269.              it_poche,it_pochex .  
  270.   
  271.     LOOP AT it_item.  
  272.       IF  it_item-po EQ it_head-po.  
  273.         CLEAR:it_poitem, it_poitemx.  
  274.         g_poitem = g_poitem + 10.  
  275.         it_poitem-po_item = g_poitem.  
  276.         it_poitemx-po_item = g_poitem.  
  277.         it_poitem-item_cat = it_item-item_cat.  
  278.         it_poitemx-item_cat = 'X'.  
  279.         it_poitemx-po_itemx = 'X'.  
  280.         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'  
  281.           EXPORTING  
  282.             input  = it_item-material  
  283.           IMPORTING  
  284.             output = it_item-material.  
  285.   
  286.         it_poitem-material = it_item-material.  
  287.         it_poitemx-material = 'X'.  
  288.         IF it_item-short_text IS NOT INITIAL.  
  289.           it_poitem-short_text = it_item-short_text.  
  290.           it_poitemx-short_text = 'X'.  
  291.   
  292.         ENDIF.  
  293.   
  294.         CLEAR g_meng.  
  295.         g_meng = it_item-quantity.  
  296.         it_poitem-quantity = g_meng.  
  297.         it_poitemx-quantity = 'X'.  
  298.         it_poitem-po_unit =  it_item-po_unit.  
  299.         it_poitemx-po_unit =  'X'.  
  300.   
  301.         CLEAR g_mtart.  
  302.         SELECT SINGLE mtart INTO g_mtart FROM mara  
  303.                 WHERE matnr EQ it_item-material.  
  304.         IF g_mtart EQ 'ZNON'.  
  305.           it_poitem-acctasscat = 'Z'.  
  306.           it_poitemx-acctasscat = 'X'.  
  307.         ENDIF.  
  308.   
  309.   
  310.         CLEAR:  it_poche,it_pochex.  
  311.         it_poche-po_item   = g_poitem.  
  312.         it_pochex-po_item  = g_poitem.  
  313.         it_poche-sched_line   = g_poitem.  
  314.         it_pochex-sched_line  = g_poitem.  
  315.         it_poche-delivery_date  = it_item-gr_to_date.  
  316.         it_pochex-delivery_date  = 'X'.  
  317.   
  318.         it_poche-quantity   = g_meng.  
  319.         it_pochex-quantity  = 'X'.  
  320.   
  321.         it_pochex-po_itemx = 'X'.  
  322.         it_pochex-sched_linex = 'X'.  
  323.   
  324.   
  325.         APPEND: it_poche,it_pochex.  
  326.   
  327.         it_poitem-plant = '8200'.  
  328.         it_poitemx-plant = 'X'.  
  329.         IF it_item-matl_group IS NOT INITIAL.  
  330.           it_poitem-matl_group = it_item-matl_group.  
  331.           it_poitemx-matl_group = 'X'.  
  332.         ENDIF.  
  333.         it_poitem-over_dlv_tol = it_item-over_dlv_tol.  
  334.         it_poitemx-over_dlv_tol = 'X'.  
  335.         it_poitem-tax_code = it_item-tax_code.  
  336.         it_poitemx-tax_code = 'X'.  
  337.         g_menge = it_item-cond_pb00.  
  338.   
  339.         IF g_menge EQ  0.  
  340.           it_poitem-free_item = 'X'.  
  341.           it_poitemx-free_item = 'X'.  
  342.         ELSE.  
  343.           it_poitem-free_item = ''.  
  344.           it_poitemx-free_item = 'X'.  
  345.         ENDIF.  
  346.   
  347.         it_poitem-matl_group = it_item-matl_group.  
  348.         it_poitemx-matl_group = 'X'.  
  349.   
  350.   
  351.         IT_POITEM-NET_PRICE = IT_ITEM-COND_PB00.  
  352.         IT_POITEMX-NET_PRICE = 'X'.  
  353.         it_poitem-price_unit = it_item-cond_p_unt.  
  354.         it_poitemx-price_unit = 'X'.  
  355.         APPEND:it_poitemx,it_poitem.  
  356.   
  357.   
  358. *ConditionS  
  359.         CLEAR it_pocond.  
  360.         it_pocond-cond_type = 'PB00'.  
  361.         it_pocond-itm_number = it_poitem-po_item.  
  362.         it_pocond-cond_value = IT_ITEM-COND_PB00.  
  363.         it_pocond-cond_p_unt  =  it_item-cond_p_unt.  
  364.         it_pocond-currency    = it_head-currency.  
  365.         it_pocond-change_id   = 'U'.  
  366.         APPEND it_pocond.  
  367.   
  368.         CLEAR it_pocondx.  
  369.         it_pocondx-cond_type = 'X'.  
  370.         it_pocondx-itm_number = it_poitem-po_item.  
  371.         it_pocondx-cond_value = 'X'.  
  372.         it_pocondx-cond_p_unt = 'X'.  
  373.         it_pocondx-currency    = 'X'.  
  374.         it_pocondx-change_id   = 'X'.  
  375.         APPEND it_pocondx.  
  376.   
  377.       ENDIF.  
  378.     ENDLOOP.  
  379.   
  380.     wa_testrun = p_flag.  
  381.     DELETE it_item WHERE  po EQ it_head-po.  
  382.     SELECT SINGLE ebeln INTO g_ebeln FROM ekko  
  383.         WHERE ebeln EQ wa_pohead-po_number.  
  384.     IF sy-subrc NE 0.  
  385. <font color="#ff0000">      CALL FUNCTION 'BAPI_PO_CREATE1'  
  386.         EXPORTING  
  387.           poheader     = wa_pohead  
  388.           poheaderx    = wa_poheadx  
  389.           poaddrvendor = wa_poaddrvendor  
  390.           testrun      = wa_testrun  
  391.         IMPORTING  
  392.           EXPPURCHASEORDER        = purchseorder  
  393.         TABLES  
  394.           return       = it_return  
  395.           poitem       = it_poitem  
  396.           poitemx      = it_poitemx  
  397.           poschedule   = it_poche  
  398.           poschedulex  = it_pochex  
  399.           pocond       = it_pocond  
  400.           pocondx      = it_pocondx  
  401.           potextheader = it_potexth  
  402.           potextitem   = it_potexti  
  403.           popartner    = it_popartner.</font>  
  404.   
  405. <font color="#ff0000">CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.  
  406.     WAIT UP TO 1 SECONDS.</font>  
  407.     REFRESH: it_poitem,it_poitemx,it_poche,it_pochex,  
  408.              it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner.  
  409.     CLEAR:it_return,it_poitem,it_poitemx,it_poche,it_pochex,  
  410.              it_pocond,it_pocondx,it_potexth,it_potexti,it_popartner.  
  411.     DELETE it_item WHERE po EQ it_head-po.  
  412.     DELETE it_head WHERE po EQ it_head-po.  
  413. *    LOOP AT it_return WHERE type EQ 'E'.  
  414.     LOOP AT it_return.  
  415.       MOVE-CORRESPONDING it_return TO it_msg1.  
  416. *      it_msg1-ebeln = wa_pohead-po_number.  
  417.       it_msg1-ebeln = purchseorder.  
  418.       it_msg1-old_po = it_head-po.  
  419.       APPEND it_msg1.  
  420.       clear it_msg1.  
  421.     ENDLOOP.  
  422.     ENDIF.  
  423.   
  424.   ENDLOOP.  
  425.   
  426.   
  427.   CALL FUNCTION 'WS_DOWNLOAD'  
  428.     EXPORTING  
  429.       filename                = p_log  
  430.       filetype                = 'DAT'  
  431.       mode                    = 'O'  
  432.     TABLES  
  433.       data_tab                = it_msg1  
  434.     EXCEPTIONS  
  435.       invalid_filesize        = 1  
  436.       invalid_table_width     = 2  
  437.       invalid_type            = 3  
  438.       no_batch                = 4  
  439.       unknown_error           = 5  
  440.       gui_refuse_filetransfer = 6  
  441.       OTHERS                  = 7.  
  442.   IF sy-subrc <> 0.  
  443.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno  
  444.             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.  
  445.   ENDIF.  
  446.   
  447. 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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值