*----------------------------------------------------------------------*
* Program name : ZSD_BDC_ORDERHEAD Date written: 07-11-10 *
* Author's name: HouZhiYu Last update : *
* Program title: 销售订单表头批量创建 *
*----------------------------------------------------------------------*
REPORT ZSD_BDC_ORDERHEAD_01_HZY MESSAGE-ID ZB.
TABLES: VBAK. "销售凭证:抬头数据
**--------传入HEAD数据----------------
DATA: BEGIN OF L_VBAK OCCURS 0,
AUART LIKE VBAK-AUART,"订单类型
VKORG LIKE VBAK-VKORG,"销售组织
VTWEG LIKE VBAK-VTWEG,"分销渠道
SPART LIKE VBAK-SPART,"部门
VKBUR LIKE VBAK-VKBUR,"销售办事处
VKGRP LIKE VBAK-VKGRP,"销售组
AGV_KUNNR LIKE KUAGV-KUNNR,"售达方
WEV_KUNNR LIKE KUWEV-KUNNR,"送达方
BSTKD LIKE VBKD-BSTKD,"采购订单编号
BSTDK LIKE VBKD-BSTDK,"采购订单日期
KETDAT LIKE RV45A-KETDAT,"请求交货日期
* DWERK LIKE RV45A-DWERK,"交货工厂
WAERK LIKE VBAK-WAERK,"凭证货币
VSBED LIKE VBAK-VSBED,"装运条件
ZTERM LIKE VBKD-ZTERM,"付款条款
INCO1 LIKE VBKD-INCO1,"国际贸易条款(部分1)
INCO2 LIKE VBKD-INCO2,"国际贸易条款(部分2)
MSCHL LIKE VBKD-MSCHL,"催款代码
AUGRU LIKE VBAK-AUGRU,"订单原因
ABRVW LIKE VBAK-ABRVW,"用途
C_PARTNER LIKE SDPARTNERLIST-PARTNER,"出具发票方
F_PARTNER LIKE SDPARTNERLIST-PARTNER,"付款方
BSARK LIKE VBKD-BSARK,"采购订单类型
AP_PARTNER LIKE SDPARTNERLIST-PARTNER,"AP 联系人
EK_PARTNER LIKE SDPARTNERLIST-PARTNER,"EK 最终用户
ROHS(20) TYPE C,"RoHS(头文本)
END OF L_VBAK.
*--BDC专用变量定义-----------
DATA:T_BDC LIKE STANDARD TABLE OF BDCDATA INITIAL SIZE 0
WITH HEADER LINE. "STANDARD BDC TABLE
REFRESH T_BDC.
*--BDC执行方式
DATA: MODE TYPE C.
* INTERNALE TABLE FOR MESSAGE.
DATA: ITAB_MESSAGE LIKE STANDARD TABLE OF BDCMSGCOLL WITH HEADER LINE.
*输出错误信息内表---
DATA: BEGIN OF MESSTAB OCCURS 0.
INCLUDE STRUCTURE L_VBAK.
DATA: FLAG(10)."错误标记
DATA: MESSAGE(100)."信息
DATA: VBELN TYPE VBAK-VBELN."订单号码
DATA: END OF MESSTAB.
*--输出日志专用----
DATA TMP_CANCEL.
*----------alv所需变量定义----------------------------------------------
TYPE-POOLS: SLIS.
DATA:
V_REPID LIKE SY-REPID,
I_PERIOD TYPE STRING.
DATA:
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
"ALV 字段
V_ALV_LAYOUT TYPE SLIS_LAYOUT_ALV. "ALV 样式
DATA GIT_LISTHEADER TYPE SLIS_T_LISTHEADER.
DATA GIT_EVENTS TYPE SLIS_T_EVENT.
*--输出屏幕-------
*****************************************************************
* SELECTION-SCREEN
*****************************************************************
SELECTION-SCREEN BEGIN OF BLOCK BLOCK1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: R1 TYPE C
RADIOBUTTON GROUP MOD.
SELECTION-SCREEN COMMENT 3(20) TEXT-005 FOR FIELD R1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: R2 TYPE C
RADIOBUTTON GROUP MOD.
SELECTION-SCREEN COMMENT 3(20) TEXT-006 FOR FIELD R2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: R3 TYPE C
RADIOBUTTON GROUP MOD DEFAULT 'X'.
SELECTION-SCREEN COMMENT 3(20) TEXT-007 FOR FIELD R3.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BLOCK1.
*&-------------------------------------------------------------------*
* AT SELECTION-SCREEN
*&-------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM GET_FILENAME USING P_FILE.
*&-------------------------------------------------------------------*
* START-OF-SELECTION
*&-------------------------------------------------------------------*
START-OF-SELECTION.
IF R1 = 'X'.
MODE = 'A'.
ENDIF.
IF R2 = 'X'.
MODE = 'E'.
ENDIF.
IF R3 = 'X'.
MODE = 'N'.
ENDIF.
*----------------
*---加载文件------
PERFORM UPOLOAD_FILE.
*--执行BDC操作----
PERFORM RUN_BDC.
*--输出日志信息----
PERFORM OUTPUT_LOG.
*---------------------------------------------------------------------*
* FORM UPOLOAD_FILE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM UPOLOAD_FILE.
CALL FUNCTION 'UPLOAD'
EXPORTING
CODEPAGE = '8400'
* FILENAME = SOURCEFILE
FILENAME = P_FILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = L_VBAK
EXCEPTIONS
OTHERS = 7.
ENDFORM. " upoload_file
*---------------------------------------------------------------------*
* FORM GET_FILENAME *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> P_P_FILE *
*---------------------------------------------------------------------*
FORM GET_FILENAME USING P_P_FILE.
"出现打开文件的对话框
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',*.*,*.*.'
MODE = 'O'
IMPORTING
FILENAME = P_P_FILE
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDFORM. " get_filename
*&---------------------------------------------------------------------*
*& Form RUN_BDC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM RUN_BDC.
LOOP AT L_VBAK.
REFRESH T_BDC.
PERFORM FRM_ADD_BDC_TAB_RECORD USING:
'1' 'SAPMV45A' '0101',
' ' 'BDC_CURSOR' 'VBAK-AUART',
' '