码迷,mamicode.com
首页 > 其他好文 > 详细

由订单创建收款凭证

时间:2014-10-16 18:07:53      阅读:477      评论:0      收藏:0      [点我收藏+]

标签:des   io   os   使用   ar   for   sp   文件   数据   

*&---------------------------------------------------------------------*
*& Report ZFI_DOCU_IMPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZFIA04 NO STANDARD PAGE HEADING MESSAGE-ID 00.
TYPE-POOLS: SLIS,TRUXS,ICON.
TABLES: VBAK, T001,BKPF,TBSL,SSCRFIELDS.
DATA FUNCTXT TYPE SMP_DYNTXT.
*---------------------------------------------------------------------*
*ALV 使用到的类库
*---------------------------------------------------------------------*
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA: IT_SUBFIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: GT_TKB9G LIKE TABLE OF TKB9G WITH HEADER LINE.
DATA: BEGIN OF IEXCEL OCCURS 0. "excel上载内表
INCLUDE STRUCTURE ZALSMEX_TABLINE.
DATA: END OF IEXCEL.

DATA: BEGIN OF IT_DOC OCCURS 0,
ZBOX TYPE C,
* CBOX TYPE C,
ICONID LIKE ICON-ID,
DOC_NO LIKE BKPF-BELNR, "凭证序号
BELNR LIKE BKPF-BELNR,
XBLNR LIKE BKPF-XBLNR, "参照
BLDAT LIKE BKPF-BLDAT, "凭证日期
BUDAT LIKE BKPF-BUDAT, "过帐日期
PERIOD LIKE BKPF-MONAT, "期间
BLART LIKE BKPF-BLART, "凭证类型
BUKRS LIKE BKPF-BUKRS, "公司代码
WAERS LIKE BKPF-WAERS, "币别
KURSF LIKE BKPF-KURSF, "汇率
BKTXT LIKE BKPF-BKTXT, "抬头文本
BRNCH LIKE BKPF-BRNCH,"分支号
BSCHL LIKE BSEG-BSCHL, "记帐代码
HKONT LIKE BSEG-HKONT, "科目
UMSKZ LIKE BSEG-UMSKZ, "特别总账标志
ANBWA LIKE BSEG-ANBWA, "事务类型
WRBTR LIKE BSEG-WRBTR, "凭证金额
DMBTR LIKE BSEG-DMBTR, "本位币金额
GSBER LIKE BSEG-GSBER, "业务范围
RSTGR LIKE BSEG-RSTGR, "原因代码
ZUONR LIKE BSEG-ZUONR, "分配号
SGTXT LIKE BSEG-SGTXT, "行项目文本
ZFBDT LIKE BSEG-ZFBDT, "基准日期
ZTERM LIKE BSEG-ZTERM, "付款条件
KOSTL LIKE BSEG-KOSTL, "成本中心
PRCTR LIKE BSEG-PRCTR, "利润中心
AUFNR LIKE BSEG-AUFNR, "订单号
EBELN LIKE BSEG-EBELN, "采购凭证号
EBELP LIKE BSEG-EBELP, "采购凭证的项目编号
ZEKKN LIKE BSEG-ZEKKN, "帐户分配的序列号
MWSKZ LIKE BSEG-MWSKZ, "税码
KUNNR LIKE CE16666-KUNNR,
KDGRP LIKE CE16666-KDGRP,
VKORG LIKE CE16666-VKORG,
VTWEG LIKE CE16666-VTWEG,
KMVKBU LIKE CE16666-KMVKBU,
WWZZS LIKE CE16666-WWZZS,
BRSCH LIKE CE16666-BRSCH,
SPART LIKE CE16666-SPART,
KMVTNR LIKE CE16666-KMVTNR,
WERKS LIKE CE16666-WERKS,
MATNR LIKE CE16666-MATNR,
EXTWG LIKE CE16666-EXTWG,
PRODH LIKE CE16666-PRODH,
KMMAKL LIKE CE16666-KMMAKL,
WW01 LIKE CE16666-WW01,
RESULT TYPE STRING, "运行结果: 成功 失败
RETURN LIKE TABLE OF BAPIRET2 , "BAPI MESSAGE
WAERSB TYPE T001-WAERS,
XCPDK TYPE KNA1-XCPDK,"一次性标记
NAME LIKE BAPIACPA09-NAME,
CITY LIKE BAPIACPA09-CITY,
COUNTRY LIKE BAPIACPA09-COUNTRY,
XVBELN TYPE VBELN,
* BANK_ACCT LIKE BAPIACPA09-BANK_ACCT,
* BANK_CTRY LIKE BAPIACPA09-BANK_CTRY,
END OF IT_DOC.
*---------------------------------------------------------------------*
* 选择屏幕
*---------------------------------------------------------------------*
SELECTION-SCREEN:BEGIN OF BLOCK BK3 WITH FRAME TITLE TEXT-030.
*PARAMETERS:
* P_FILE LIKE RLGRAP-FILENAME OBLIGATORY DEFAULT ‘C:\‘ ."文件目录
SELECT-OPTIONS: S_DATE FOR BKPF-BLDAT.
SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
SELECT-OPTIONS: S_VKORG FOR VBAK-VKORG DEFAULT ‘6003‘.
SELECT-OPTIONS: S_VTWEG FOR VBAK-VTWEG DEFAULT ‘11‘.


SELECTION-SCREEN:END OF BLOCK BK3.

*SELECTION-SCREEN: FUNCTION KEY 1.
*&--------------------------------------------------------------------*
*& I N I T I A L I A T I O N
*&--------------------------------------------------------------------*
*INITIALIZATION.
* FUNCTXT-ICON_ID = ICON_EXPORT.
* FUNCTXT-QUICKINFO = ‘模版下载‘.
* FUNCTXT-ICON_TEXT = ‘模版下载‘.
* SSCRFIELDS-FUNCTXT_01 = FUNCTXT.

*-----------------------------------------------------------------------
* At Selection Screen
*-----------------------------------------------------------------------
*AT SELECTION-SCREEN.
* IF SSCRFIELDS-UCOMM = ‘FC01‘.
* PERFORM TEMP_EXCEL_GET USING ‘ZFI_DOCU_IMPORT‘.
* ELSE.
* IF P_FILE IS INITIAL.
* MESSAGE E001(00) WITH ‘请选择导入模版!‘.
* ENDIF.
* ENDIF.
*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
* PERFORM GET_FILENAME.
*---------------------------------------------------------------------*
* S T A R T - O F - S E L E C T I O N
*---------------------------------------------------------------------*
START-OF-SELECTION.


PERFORM READ_DATA.
PERFORM CHECKVALID."检查数据
PERFORM SHOW_DOC.

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& FORM BUILD_LAYOUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM BUILD_LAYOUT .
GS_LAYOUT-BOX_FIELDNAME = ‘ZBOX‘.
GS_LAYOUT-ZEBRA = ‘X‘.
GS_LAYOUT-DETAIL_POPUP = ‘X‘.
GS_LAYOUT-COLWIDTH_OPTIMIZE = ‘X‘.
ENDFORM. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& FORM WRITE_DATA_ALV
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM WRITE_DATA_ALV .
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY‘
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
I_CALLBACK_PF_STATUS_SET = ‘SET_PF_STATUS‘
I_CALLBACK_USER_COMMAND = ‘USER_COMMAND‘
I_DEFAULT = ‘X‘
I_SAVE = ‘A‘
TABLES
T_OUTTAB = IT_DOC
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE S398 WITH ‘Error when output data in ALV format.‘.
ENDIF.

ENDFORM. " WRITE_DATA_ALV
*&--------------------------------------------------------------------*
*& FORM SET_PF_STATUS
*&--------------------------------------------------------------------*
* TEXT
*---------------------------------------------------------------------*
FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
REFRESH: RT_EXTAB.
SET PF-STATUS ‘ZSTATUS‘ EXCLUDING RT_EXTAB.
ENDFORM. "set_pf_status
*&--------------------------------------------------------------------*
*& FORM USER_COMMAND
*&--------------------------------------------------------------------*
* TEXT
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN ‘CHECK‘.
PERFORM PROCESS_DATA USING ‘X‘.
WHEN ‘SAVE‘.
PERFORM PROCESS_DATA USING ‘‘.
WHEN ‘LOG‘.
READ TABLE IT_DOC INDEX RS_SELFIELD-TABINDEX.
IF SY-SUBRC = 0.
IF IT_SUBFIELDCAT[] IS INITIAL.
PERFORM INITIALIZE_SUBFIELDCAT.
ENDIF.
PERFORM WRITE_BAPILOG_ALV USING IT_DOC-RETURN.
ENDIF.
WHEN ‘&IC1‘.
IF RS_SELFIELD-FIELDNAME = ‘RESULT‘.
READ TABLE IT_DOC INDEX RS_SELFIELD-TABINDEX.
IF IT_DOC-RESULT = ‘失败‘.
IF IT_SUBFIELDCAT[] IS INITIAL.
PERFORM INITIALIZE_SUBFIELDCAT.
ENDIF.
PERFORM WRITE_BAPILOG_ALV USING IT_DOC-RETURN.
ENDIF.
ENDIF.
IF RS_SELFIELD-FIELDNAME = ‘BELNR‘.
READ TABLE IT_DOC INDEX RS_SELFIELD-TABINDEX.
IF IT_DOC-BELNR <> ‘‘.
SET PARAMETER ID ‘BLN‘ FIELD IT_DOC-BELNR.
SET PARAMETER ID ‘BUK‘ FIELD IT_DOC-BUKRS.
SET PARAMETER ID ‘GJR‘ FIELD IT_DOC-BUDAT+0(4).
CALL TRANSACTION ‘FB03‘ AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
WHEN OTHERS.
ENDCASE.
RS_SELFIELD-REFRESH = ‘X‘.
RS_SELFIELD-COL_STABLE = ‘X‘.
RS_SELFIELD-ROW_STABLE = ‘X‘.
ENDFORM. "user_command
*&---------------------------------------------------------------------*
*& FORM INITIALIZE_SUBFIELDCAT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM INITIALIZE_SUBFIELDCAT .
*获取数据字典中各个字段的属性
CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE‘
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_STRUCTURE_NAME = ‘BAPIRET2‘
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = IT_SUBFIELDCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2.
ENDFORM. " INITIALIZE_SUBFIELDCAT
*&---------------------------------------------------------------------*
*& FORM WRITE_BAPILOG_ALV
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->P_IT_DOC_RETURN TEXT
*----------------------------------------------------------------------*
FORM WRITE_BAPILOG_ALV USING PT_RETURN LIKE IT_DOC-RETURN.
DATA LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
LS_LAYOUT-ZEBRA = ‘X‘.
LS_LAYOUT-DETAIL_POPUP = ‘X‘.
LS_LAYOUT-COLWIDTH_OPTIMIZE = ‘X‘.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY‘
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = LS_LAYOUT
IT_FIELDCAT = IT_SUBFIELDCAT
* I_CALLBACK_PF_STATUS_SET = ‘SET_PF_STATUS‘
* I_CALLBACK_USER_COMMAND = ‘USER_COMMAND‘
I_DEFAULT = ‘X‘
I_SAVE = ‘A‘
TABLES
T_OUTTAB = PT_RETURN
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE S398 WITH ‘Error when output data in ALV format.‘.
ENDIF.
ENDFORM. " WRITE_BAPILOG_ALV


*&---------------------------------------------------------------------*
*& FORM READ_DATA
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM READ_DATA .
DATA: BEGIN OF ITS OCCURS 0,
VBELN TYPE VBELN,
VKORG TYPE VKORG,
KZWI4 TYPE KZWI4,
BUKRS TYPE VBRK-BUKRS,
BSTNK_VF LIKE VBRK-BSTNK_VF,
VGBEL LIKE VBRP-VGBEL,
NRZAS LIKE VBRK-NRZAS,
ERDAT TYPE ERDAT,
END OF ITS.

 

 

SELECT R~VBELN
VKORG
NETWR AS KZWI4
KKBER AS BUKRS
BSTNK AS BSTNK_VF
VBELN AS VGBEL
VSNMR_V AS NRZAS
ERDAT
INTO TABLE ITS
FROM VBAK AS R
* JOIN VBaP AS P ON R~VBELN = P~VBELN
WHERE R~ERDAT IN S_DATE
AND R~VBELN IN S_VBELN
AND R~VKORG IN S_VKORG
AND R~VTWEG IN S_VTWEG
AND KUNNR = ‘0000000001‘.

 

* SELECT R~VBELN
* VKORG
* KZWI4
* BUKRS
* BSTNK_VF
* VGBEL
* NRZAS
* INTO TABLE ITS
* FROM VBRK AS R
* JOIN VBRP AS P ON R~VBELN = P~VBELN
* WHERE P~ERDAT IN S_DATE
* AND KUNAG = ‘0000000001‘.


*抬头文本 = 科目号.工号-姓名.DRP订单号

LOOP AT ITS WHERE NRZAS = ‘‘.
IT_DOC-BELNR = ITS-NRZAS.
* IT_DOC-DOC_NO = ITS-VBELN."凭证序号
MOVE ITS-ERDAT TO IT_DOC-DOC_NO .
CONCATENATE IT_DOC-DOC_NO ITS-BUKRS INTO IT_DOC-DOC_NO.

IT_DOC-XVBELN = ITS-VBELN.

IT_DOC-BLDAT = SY-DATUM."凭证日期
IT_DOC-BUDAT = SY-DATUM. "过帐日期
IT_DOC-PERIOD = IT_DOC-BUDAT+4(2).
IT_DOC-BLART = ‘DA‘. "凭证类型
IT_DOC-BUKRS = ITS-BUKRS."公司代码
IT_DOC-WAERS = ‘CNY‘. "币别
IT_DOC-BKTXT = ‘员工入帐‘.

IT_DOC-BSCHL = ‘15‘. "记帐代码
IT_DOC-HKONT = ‘0000000001‘ . "科目

* IT_DOC-WRBTR = ITS-KZWI4 * ‘1.17‘.
* IT_DOC-DMBTR = ITS-KZWI4 * ‘1.17‘.
IT_DOC-GSBER = ITS-VKORG.
IT_DOC-PRCTR = ITS-VKORG.

IF IT_DOC-PRCTR+0(1) = ‘8‘.
IT_DOC-PRCTR = ‘6001‘.
IT_DOC-GSBER = ‘6001‘.
ENDIF.

DATA: S(100),T(100),V(100),P(100).
* CLEAR: S,T.
* SPLIT ITS-BSTNK_VF AT ‘.‘ INTO S T V .
* CONCATENATE S ITS-VGBEL INTO IT_DOC-SGTXT .

 

 

* IT_DOC-SGTXT = ITS-VGBEL.
IF ITS-VKORG = ‘6001‘.
IT_DOC-ZUONR = ‘2‘.
ELSEIF ITS-VKORG = ‘6003‘.
IT_DOC-ZUONR = ‘6‘.
ELSE.
IT_DOC-ZUONR = ‘1‘.
ENDIF.
IT_DOC-NAME = ‘一次性客户‘.

IT_DOC-CITY = ‘弗吉尼亚‘.

* APPEND IT_DOC.


DATA: NAME LIKE THEAD-TDNAME,
ITAB_HTXT LIKE TLINE OCCURS 0 WITH HEADER LINE.
CLEAR : NAME, S,T,ITAB_HTXT , ITAB_HTXT[].
MOVE ITS-VBELN TO NAME.
CALL FUNCTION ‘READ_TEXT‘
EXPORTING
ID = ‘0001‘
LANGUAGE = ‘1‘
NAME = NAME
OBJECT = ‘VBBK‘
TABLES
LINES = ITAB_HTXT
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.

READ TABLE ITAB_HTXT INDEX 1.
IF SY-SUBRC = 0.
SPLIT ITAB_HTXT-TDLINE AT ‘_‘ INTO S T V P .
MOVE V TO IT_DOC-WRBTR .
MOVE V TO IT_DOC-DMBTR .
CONCATENATE T ‘/‘ V ‘/‘ ITS-VGBEL INTO IT_DOC-SGTXT .
APPEND IT_DOC.


IT_DOC-HKONT = S . "科目
else.
move ITS-VGBEL TO IT_DOC-SGTXT .
ENDIF.
IT_DOC-RSTGR = ‘A01‘.
IT_DOC-BSCHL = ‘40‘. "记帐代码
APPEND IT_DOC.

CLEAR ITS.
CLEAR IT_DOC.
ENDLOOP.


ENDFORM. " READ_DATA

*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TEST text
*----------------------------------------------------------------------*
FORM PROCESS_DATA USING P_TEST TYPE C.
DATA:
WA_DOCUMENTHEADER TYPE BAPIACHE09 ,
WA_CUST TYPE BAPIACPA09,
IT_ACCOUNTGL TYPE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
IT_CURRENCYAMOUNT TYPE BAPIACCR09 OCCURS 0 WITH HEADER LINE,
IT_ACCOUNTRECEIVABLE TYPE BAPIACAR09 OCCURS 0 WITH HEADER LINE,
IT_RETURN TYPE BAPIRET2 OCCURS 0 WITH HEADER LINE,
IT_EXT2 TYPE BAPIPAREX OCCURS 0 WITH HEADER LINE,
IT_ACCOUNTPAYABLE TYPE BAPIACAP09 OCCURS 0 WITH HEADER LINE,
IT_ACCOUNTTAX LIKE TABLE OF BAPIACTX09 WITH HEADER LINE,
LT_ACKEC LIKE TABLE OF BAPIACKEC9 WITH HEADER LINE,
LT_ACKEV LIKE TABLE OF BAPIACKEV9 WITH HEADER LINE.
DATA:
ISNEW_DOC TYPE I,
ITEMNO TYPE I VALUE 0. "当前行项目编号
DATA: L_KEY LIKE WA_DOCUMENTHEADER-OBJ_KEY.
DATA: LV_KOKRS TYPE TKA02-KOKRS,
LV_ERZUO TYPE TKB9G-ERZUO.

LOOP AT IT_DOC WHERE BELNR = ‘‘.
AT NEW DOC_NO.
CLEAR: WA_DOCUMENTHEADER,IT_ACCOUNTGL[],IT_ACCOUNTPAYABLE[],
IT_ACCOUNTRECEIVABLE[],IT_EXT2[],
IT_RETURN[],IT_CURRENCYAMOUNT[],IT_ACCOUNTTAX[].
ISNEW_DOC = 1.
ITEMNO = 0.
ENDAT.

IF ISNEW_DOC = 1."新凭证
ISNEW_DOC = 0.
PERFORM FILL_HEADER USING IT_DOC
CHANGING WA_DOCUMENTHEADER
WA_CUST."输入凭证抬头
ENDIF.

ITEMNO = ITEMNO + 1.
SELECT SINGLE * FROM TBSL WHERE BSCHL = IT_DOC-BSCHL."记帐代码
CASE TBSL-KOART."记帐代码
"客户相关统驭科目
WHEN ‘D‘.
PERFORM FILL_AR TABLES IT_ACCOUNTRECEIVABLE
USING ITEMNO
IT_DOC.
"供应商相关统驭科目
WHEN ‘K‘.
PERFORM FILL_AP TABLES IT_ACCOUNTPAYABLE
USING ITEMNO
IT_DOC.
WHEN OTHERS.
PERFORM FILL_GL TABLES IT_ACCOUNTGL
USING ITEMNO
IT_DOC.
ENDCASE.

IF IT_DOC-MWSKZ <> ‘‘.
PERFORM FILL_IT_ACCOUNTTAX TABLES IT_CURRENCYAMOUNT
IT_ACCOUNTTAX
USING ITEMNO
CHANGING IT_DOC.
ENDIF.
*"货币项目
PERFORM FILL_CURRAMOUNT TABLES IT_CURRENCYAMOUNT
USING ITEMNO
IT_DOC
TBSL.
*COPA字段

SELECT SINGLE KOKRS FROM TKA02
INTO LV_KOKRS
WHERE BUKRS = IT_DOC-BUKRS.

SELECT SINGLE ERZUO
FROM TKB9G
INTO LV_ERZUO
WHERE ERSCH = ‘FI‘
AND KOKRS = LV_KOKRS
AND VALMIN = IT_DOC-HKONT.
IF SY-SUBRC = 0.
PERFORM FILL_COPA TABLES LT_ACKEC
LT_ACKEV
USING ITEMNO
IT_DOC.
ENDIF.
*原因代码
PERFORM FILL_EXT2 TABLES IT_EXT2
USING ITEMNO
IT_DOC.
AT END OF DOC_NO.
IF P_TEST = ‘‘. "执行
CALL FUNCTION ‘BAPI_ACC_DOCUMENT_POST‘
EXPORTING
DOCUMENTHEADER = WA_DOCUMENTHEADER
CUSTOMERCPD = WA_CUST
IMPORTING
OBJ_KEY = L_KEY
TABLES
ACCOUNTGL = IT_ACCOUNTGL
ACCOUNTRECEIVABLE = IT_ACCOUNTRECEIVABLE
ACCOUNTPAYABLE = IT_ACCOUNTPAYABLE
EXTENSION2 = IT_EXT2
CURRENCYAMOUNT = IT_CURRENCYAMOUNT
ACCOUNTTAX = IT_ACCOUNTTAX
CRITERIA = LT_ACKEC
VALUEFIELD = LT_ACKEV
RETURN = IT_RETURN.
ELSEIF P_TEST = ‘X‘. "测试
CALL FUNCTION ‘BAPI_ACC_DOCUMENT_CHECK‘
EXPORTING
DOCUMENTHEADER = WA_DOCUMENTHEADER
CUSTOMERCPD = WA_CUST
TABLES
ACCOUNTGL = IT_ACCOUNTGL
ACCOUNTRECEIVABLE = IT_ACCOUNTRECEIVABLE
ACCOUNTPAYABLE = IT_ACCOUNTPAYABLE
EXTENSION2 = IT_EXT2
CURRENCYAMOUNT = IT_CURRENCYAMOUNT
ACCOUNTTAX = IT_ACCOUNTTAX
CRITERIA = LT_ACKEC
VALUEFIELD = LT_ACKEV
RETURN = IT_RETURN.
ENDIF.

READ TABLE IT_RETURN WITH KEY TYPE = ‘E‘.
IF SY-SUBRC <> 0. "找不到错误
IT_DOC-ICONID = ICON_LED_GREEN.
IF P_TEST = ‘X‘.
IT_DOC-BELNR = ‘‘.
IT_DOC-RESULT = ‘检查OK‘.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘
EXPORTING
WAIT = ‘X‘.
CONCATENATE ‘过账成功!凭证号为‘ L_KEY(10) INTO
IT_DOC-RESULT.
IT_DOC-BELNR = L_KEY(10).
ENDIF.

 

ELSE.
IT_DOC-RESULT = ‘失败‘.
IT_DOC-ICONID = ICON_LED_RED.
ENDIF.
LOOP AT IT_RETURN.
APPEND IT_RETURN TO IT_DOC-RETURN.
ENDLOOP.
MODIFY IT_DOC FROM IT_DOC
TRANSPORTING RESULT ICONID BELNR RETURN
WHERE DOC_NO = IT_DOC-DOC_NO.
CLEAR: WA_DOCUMENTHEADER,IT_ACCOUNTGL[],IT_ACCOUNTPAYABLE[],
IT_ACCOUNTRECEIVABLE[],IT_EXT2[],IT_RETURN[],
IT_CURRENCYAMOUNT[],IT_ACCOUNTTAX[].
ENDAT.

 

ENDLOOP.

DATA: SV LIKE VBRK-VBELN.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN TYPE VBELN,
BELNR LIKE IT_DOC-BELNR,
END OF ITAB.

LOOP AT IT_DOC WHERE ICONID = ICON_LED_GREEN.
MOVE IT_DOC-XVBELN TO ITAB-VBELN.
MOVE IT_DOC-BELNR TO ITAB-BELNR.
COLLECT ITAB.
* MOVE IT_DOC-DOC_NO TO SV.
ENDLOOP.

LOOP AT ITAB.

MOVE ITAB-VBELN TO SV.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = SV
IMPORTING
OUTPUT = SV.

UPDATE VBAK SET VSNMR_V = ITAB-BELNR
WHERE VBELN = SV .

ENDLOOP.


ENDFORM. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& FORM FILL_HEADER
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM FILL_HEADER USING PS_DOCLINE LIKE IT_DOC
CHANGING DOC_HEADER TYPE BAPIACHE09
C_CUST TYPE BAPIACPA09.
DOC_HEADER-USERNAME = SY-UNAME.
DOC_HEADER-FISC_YEAR = PS_DOCLINE-BUDAT+0(4).
DOC_HEADER-REF_DOC_NO = PS_DOCLINE-XBLNR.
DOC_HEADER-DOC_DATE = PS_DOCLINE-BLDAT. "凭证日期
DOC_HEADER-PSTNG_DATE = PS_DOCLINE-BUDAT. "过账日期
DOC_HEADER-DOC_TYPE = PS_DOCLINE-BLART. "凭证类型
DOC_HEADER-COMP_CODE = PS_DOCLINE-BUKRS. "公司代码
DOC_HEADER-HEADER_TXT = PS_DOCLINE-BKTXT. "抬头文本
DOC_HEADER-FIS_PERIOD = PS_DOCLINE-PERIOD. "期间
DOC_HEADER-BUS_ACT = ‘RFBU‘.
IF PS_DOCLINE-XCPDK = ‘X‘.
C_CUST-NAME = PS_DOCLINE-NAME.
C_CUST-CITY = PS_DOCLINE-CITY.
C_CUST-COUNTRY = PS_DOCLINE-COUNTRY.
* C_CUST-BANK_ACCT = PS_DOCLINE-BANK_ACCT.
* C_CUST-BANK_CTRY = PS_DOCLINE-BANK_CTRY.
ENDIF.
ENDFORM. " FILL_HEADER
*&---------------------------------------------------------------------*
*& FORM FILL_GL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM FILL_GL TABLES PT_ACCOUNTGL STRUCTURE BAPIACGL09
USING P_ITEMNO TYPE I
DOCLINE LIKE IT_DOC.
DATA:TKTOGR LIKE ANLA-KTOGR.
DATA:TANLN1 LIKE ANLA-ANLN1 .

CLEAR PT_ACCOUNTGL.
PT_ACCOUNTGL-ITEMNO_ACC = P_ITEMNO.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = DOCLINE-HKONT "科目
IMPORTING
OUTPUT = PT_ACCOUNTGL-GL_ACCOUNT.

PT_ACCOUNTGL-COMP_CODE = DOCLINE-BUKRS. "公司代码
PT_ACCOUNTGL-ALLOC_NMBR = DOCLINE-ZUONR . "分配号
PT_ACCOUNTGL-ITEM_TEXT = DOCLINE-SGTXT . "行项目文本
* PT_ACCOUNTGL-WBS_ELEMENT = <FS_DOCLINE>-PROJK . "WBS元素
* PT_ACCOUNTGL-MATERIAL = <FS_DOCLINE>-MATNR. "物料号
* PT_ACCOUNTGL-QUANTITY = <FS_DOCLINE>-MENGE. "数量
* PT_ACCOUNTGL-BASE_UOM = <FS_DOCLINE>-MEINS."基本计量单位

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘"成本中心
EXPORTING
INPUT = DOCLINE-KOSTL
IMPORTING
OUTPUT = PT_ACCOUNTGL-COSTCENTER.

CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘ "内部订单号
EXPORTING
INPUT = DOCLINE-AUFNR
IMPORTING
OUTPUT = PT_ACCOUNTGL-ORDERID.
* PT_ACCOUNTGL-FUNC_AREA = <FS_DOCLINE>-FKBER. "功能范围
PT_ACCOUNTGL-PO_NUMBER = DOCLINE-EBELN. "采购凭证号
PT_ACCOUNTGL-PO_ITEM = DOCLINE-EBELP.
* PT_ACCOUNTGL-REF_KEY_1 = <FS_DOCLINE>-XREF1. "参考代码1
* PT_ACCOUNTGL-REF_KEY_2 = <FS_DOCLINE>-XREF2. "参考代码2
* PT_ACCOUNTGL-REF_KEY_3 = <FS_DOCLINE>-XREF3. "参考代码3
PT_ACCOUNTGL-TAX_CODE = DOCLINE-MWSKZ.
* CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
* EXPORTING
* INPUT = <FS_DOCLINE>-VBUND
* IMPORTING
* OUTPUT = PT_ACCOUNTGL-TRADE_ID. "贸易伙伴
* PT_ACCOUNTGL-CS_TRANS_T = <FS_DOCLINE>-BEWAR. "事物类型
PT_ACCOUNTGL-PROFIT_CTR = DOCLINE-PRCTR."利润中心

* IF <FS_DOCLINE>-BSCHL = ‘70‘ OR <FS_DOCLINE>-BSCHL = ‘75‘.
* PT_ACCOUNTGL-ACCT_TYPE = ‘A‘.
* CLEAR:TKTOGR.
* CLEAR:TANLN1 .
* TANLN1 = PT_ACCOUNTGL-GL_ACCOUNT.
* CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
* EXPORTING
* INPUT = TANLN1
* IMPORTING
* OUTPUT = TANLN1.
* SELECT SINGLE KTOGR INTO TKTOGR
* FROM ANLA
* WHERE BUKRS = DOCLINE-BUKRS
* AND ANLN1 = TANLN1.
* PT_ACCOUNTGL-ASSET_NO = TANLN1.
* PT_ACCOUNTGL-SUB_NUMBER = ‘0000‘.
*
* SELECT SINGLE * FROM T001
* WHERE BUKRS = DOCLINE-BUKRS.
* IF SY-SUBRC = 0.
* SELECT SINGLE KTANSW
* INTO PT_ACCOUNTGL-GL_ACCOUNT
* FROM T095
* WHERE KTOGR = TKTOGR
* AND KTOPL = T001-KTOPL.
* ENDIF.
* ENDIF.

APPEND PT_ACCOUNTGL.
CLEAR PT_ACCOUNTGL.
ENDFORM. " FILL_GL


*&---------------------------------------------------------------------*
*& FORM FILL_CURRAMOUNT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM FILL_CURRAMOUNT TABLES PT_CURRENCYAMOUNT STRUCTURE BAPIACCR09
USING P_ITEMNO TYPE I
DOCLINE LIKE IT_DOC
LS_TBSL TYPE TBSL.
CLEAR PT_CURRENCYAMOUNT.
PT_CURRENCYAMOUNT-ITEMNO_ACC = P_ITEMNO.
PT_CURRENCYAMOUNT-CURR_TYPE = ‘00‘.
PT_CURRENCYAMOUNT-CURRENCY = DOCLINE-WAERS."币别
CASE LS_TBSL-SHKZG."记帐代码对应的借贷标识
WHEN ‘H‘. "贷方DM
PT_CURRENCYAMOUNT-AMT_DOCCUR = 0 - DOCLINE-WRBTR.
WHEN OTHERS.
PT_CURRENCYAMOUNT-AMT_DOCCUR = DOCLINE-WRBTR. "金额
ENDCASE.
IF DOCLINE-KURSF <> 0."直接指定汇率
PT_CURRENCYAMOUNT-EXCH_RATE = DOCLINE-KURSF.
ENDIF.
APPEND PT_CURRENCYAMOUNT.

IF DOCLINE-WAERS <> DOCLINE-WAERSB."外币
IF DOCLINE-DMBTR <> 0 AND DOCLINE-KURSF = 0.
PT_CURRENCYAMOUNT-ITEMNO_ACC = P_ITEMNO.
PT_CURRENCYAMOUNT-CURR_TYPE = ‘10‘.
PT_CURRENCYAMOUNT-CURRENCY = DOCLINE-WAERSB."币别
CASE LS_TBSL-SHKZG."记帐代码对应的借贷标识
WHEN ‘H‘. "贷方DM
PT_CURRENCYAMOUNT-AMT_DOCCUR = 0 - DOCLINE-DMBTR.
WHEN OTHERS.
PT_CURRENCYAMOUNT-AMT_DOCCUR = DOCLINE-DMBTR."本位金额
ENDCASE.
APPEND PT_CURRENCYAMOUNT.
ENDIF.

ENDIF.

CLEAR PT_CURRENCYAMOUNT.
ENDFORM. " FILL_CURRAMOUNT
*&---------------------------------------------------------------------*
*& FORM FILL_AR
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM FILL_AR TABLES PT_ACCOUNTRECEIVABLE STRUCTURE BAPIACAR09
USING P_ITEMNO TYPE I
DOCLINE LIKE IT_DOC.
CLEAR PT_ACCOUNTRECEIVABLE.
PT_ACCOUNTRECEIVABLE-ITEMNO_ACC = P_ITEMNO.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = DOCLINE-HKONT
IMPORTING
OUTPUT = PT_ACCOUNTRECEIVABLE-CUSTOMER. "客户

SELECT SINGLE ZTERM FROM KNB1
INTO PT_ACCOUNTRECEIVABLE-PMNTTRMS "付款条件
WHERE KUNNR = PT_ACCOUNTRECEIVABLE-CUSTOMER
AND BUKRS = DOCLINE-BUKRS.

PT_ACCOUNTRECEIVABLE-COMP_CODE = DOCLINE-BUKRS. "公司代码
PT_ACCOUNTRECEIVABLE-ITEM_TEXT = DOCLINE-SGTXT . "行项目文本
PT_ACCOUNTRECEIVABLE-ALLOC_NMBR = DOCLINE-ZUONR.
PT_ACCOUNTRECEIVABLE-BLINE_DATE = DOCLINE-ZFBDT. "到期日
* PT_ACCOUNTRECEIVABLE-REF_KEY_1 = DOCLINE-XREF1."参考代码1
* PT_ACCOUNTRECEIVABLE-REF_KEY_2 = DOCLINE-XREF2."参考代码2
* PT_ACCOUNTRECEIVABLE-REF_KEY_3 = DOCLINE-XREF3."参考代码3
* PT_ACCOUNTRECEIVABLE-PARTNER_BK = DOCLINE-BVTYP.
"合作银行类型
PT_ACCOUNTRECEIVABLE-BLINE_DATE = DOCLINE-ZFBDT.
"到日期/付款基准日
PT_ACCOUNTRECEIVABLE-SP_GL_IND = DOCLINE-UMSKZ.
"特殊总分类帐标志
PT_ACCOUNTRECEIVABLE-BUS_AREA = DOCLINE-GSBER."业务范围
* PT_ACCOUNTRECEIVABLE-DSCT_PCT1 = 0. "折扣百分比
PT_ACCOUNTRECEIVABLE-TAX_CODE = DOCLINE-MWSKZ.
* PT_ACCOUNTRECEIVABLE-sp_gl_ind = ‘V‘.
APPEND PT_ACCOUNTRECEIVABLE.
CLEAR PT_ACCOUNTRECEIVABLE.
ENDFORM. " FILL_AR
*&---------------------------------------------------------------------*
*& FORM FILL_AP
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM FILL_AP TABLES PT_ACCOUNTPAYABLE STRUCTURE BAPIACAP09
USING P_ITEMNO TYPE I
DOCLINE LIKE IT_DOC.
CLEAR PT_ACCOUNTPAYABLE.
PT_ACCOUNTPAYABLE-ITEMNO_ACC = P_ITEMNO.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = DOCLINE-HKONT
IMPORTING
OUTPUT = PT_ACCOUNTPAYABLE-VENDOR_NO. "供应商
* PT_ACCOUNTPAYABLE-GL_ACCOUNT = PT_ACCOUNTPAYABLE-VENDOR_NO.
IF DOCLINE-ZTERM = ‘‘.
SELECT SINGLE ZTERM FROM LFB1
INTO PT_ACCOUNTPAYABLE-PMNTTRMS
WHERE LIFNR = PT_ACCOUNTPAYABLE-VENDOR_NO
AND BUKRS = DOCLINE-BUKRS.
ELSE.
PT_ACCOUNTPAYABLE-PMNTTRMS = DOCLINE-ZTERM. "付款条件
ENDIF.
PT_ACCOUNTPAYABLE-COMP_CODE = DOCLINE-BUKRS. "公司代码
PT_ACCOUNTPAYABLE-ITEM_TEXT = DOCLINE-SGTXT .
"行项目文本
PT_ACCOUNTPAYABLE-ALLOC_NMBR = DOCLINE-ZUONR.
PT_ACCOUNTPAYABLE-BLINE_DATE = DOCLINE-ZFBDT. "到期日
PT_ACCOUNTPAYABLE-BUS_AREA = DOCLINE-GSBER."业务范围
PT_ACCOUNTPAYABLE-BLINE_DATE = DOCLINE-ZFBDT.
"到日期/付款基准日
PT_ACCOUNTPAYABLE-TAX_CODE = DOCLINE-MWSKZ.
APPEND PT_ACCOUNTPAYABLE.
CLEAR PT_ACCOUNTPAYABLE.
ENDFORM. " FILL_AP

*&---------------------------------------------------------------------*
*& FORM FILL_EXT2
*&---------------------------------------------------------------------*
* EXTENSION2 扩展字段增强部分
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*---------------------------------------------------------------------
FORM FILL_EXT2 TABLES PT_EXT2 STRUCTURE BAPIPAREX
USING P_ITEMNO TYPE I
DOCLINE LIKE IT_DOC.
DATA: WA_ZEXTEN LIKE ZRSTRG.
CLEAR:WA_ZEXTEN.
WA_ZEXTEN-POSNR = P_ITEMNO.
WA_ZEXTEN-RSTGR = DOCLINE-RSTGR. "原因代码
WA_ZEXTEN-BSCHL = DOCLINE-BSCHL. "记账代码
WA_ZEXTEN-UMSKZ = DOCLINE-UMSKZ. "特殊总账标志
WA_ZEXTEN-BRNCH = DOCLINE-BRNCH.
PT_EXT2-STRUCTURE = ‘ZRSTRG‘.
PT_EXT2-VALUEPART1 = WA_ZEXTEN.
APPEND PT_EXT2.
CLEAR PT_EXT2.
ENDFORM. " FILL_EXT2
*&---------------------------------------------------------------------*
*& FORM SHOW_DOC
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM SHOW_DOC .
PERFORM GET_FIELDCATALOG.
PERFORM BUILD_LAYOUT.
PERFORM WRITE_DATA_ALV.
ENDFORM. " SHOW_DOC
*&---------------------------------------------------------------------*
*& Form GET_FIELDCATALOG
*&---------------------------------------------------------------------*
* 设置各个字段的属性
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_FIELDCATALOG .
*获取数据字典中各个字段的属性
CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE‘
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = ‘IT_DOC‘
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = GT_FIELDCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2.
*修改字段属性
READ TABLE GT_FIELDCAT INTO WA_FIELDCAT WITH KEY FIELDNAME = ‘DOC_NO‘.
IF SY-SUBRC = 0.
WA_FIELDCAT-SELTEXT_S = ‘凭证序号‘.
WA_FIELDCAT-SELTEXT_M = WA_FIELDCAT-SELTEXT_S.
WA_FIELDCAT-SELTEXT_L = WA_FIELDCAT-SELTEXT_S.
WA_FIELDCAT-DDICTXT = ‘M‘.
MODIFY GT_FIELDCAT FROM WA_FIELDCAT INDEX SY-TABIX.
ENDIF.
READ TABLE GT_FIELDCAT INTO WA_FIELDCAT WITH KEY FIELDNAME = ‘RESULT‘.
IF SY-SUBRC = 0.
WA_FIELDCAT-SELTEXT_S = ‘返回消息‘.
WA_FIELDCAT-SELTEXT_M = WA_FIELDCAT-SELTEXT_S.
WA_FIELDCAT-SELTEXT_L = WA_FIELDCAT-SELTEXT_S.
WA_FIELDCAT-DDICTXT = ‘M‘.
MODIFY GT_FIELDCAT FROM WA_FIELDCAT INDEX SY-TABIX.
ENDIF.

* READ TABLE GT_FIELDCAT INTO WA_FIELDCAT WITH KEY FIELDNAME = ‘ZBOX‘.
* IF SY-SUBRC = 0.
* WA_FIELDCAT-checkbox = ‘X‘.
* WA_FIELDCAT-SELTEXT_S = ‘测试信息‘.
* WA_FIELDCAT-SELTEXT_M = WA_FIELDCAT-SELTEXT_S.
* WA_FIELDCAT-SELTEXT_L = WA_FIELDCAT-SELTEXT_S.
* WA_FIELDCAT-DDICTXT = ‘M‘.
* MODIFY GT_FIELDCAT FROM WA_FIELDCAT INDEX SY-TABIX.
* ENDIF.

ENDFORM. " GET_FIELDCATALOG

*&---------------------------------------------------------------------*
*& FORM CHECKVALID
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM CHECKVALID .
FIELD-SYMBOLS: <FS_DOC> LIKE LINE OF IT_DOC.
DATA: LS_KNA1 TYPE KNA1,
LS_LFA1 TYPE LFA1.
DATA RSTGR LIKE BSEG-RSTGR.
DATA MSG LIKE BAPIRET2.

LOOP AT IT_DOC ASSIGNING <FS_DOC>.
IF <FS_DOC>-BUKRS = ‘‘.
MSG-TYPE = ‘E‘.
<FS_DOC>-ICONID = ICON_LED_RED.
MSG-MESSAGE = ‘公司代码不能为空!‘.
APPEND MSG TO <FS_DOC>-RETURN.
CONCATENATE <FS_DOC>-RESULT MSG-MESSAGE
INTO <FS_DOC>-RESULT.
ELSE.
SELECT SINGLE WAERS FROM T001
INTO <FS_DOC>-WAERSB
WHERE BUKRS = <FS_DOC>-BUKRS.
ENDIF.
IF <FS_DOC>-WAERS = ‘‘.
MSG-TYPE = ‘E‘.
<FS_DOC>-ICONID = ICON_LED_RED.
MSG-MESSAGE = ‘币别不能为空!‘.
APPEND MSG TO <FS_DOC>-RETURN.
CONCATENATE <FS_DOC>-RESULT MSG-MESSAGE
INTO <FS_DOC>-RESULT.
ENDIF.
IF <FS_DOC>-WAERS <> <FS_DOC>-WAERSB."外币
IF <FS_DOC>-DMBTR = 0 AND <FS_DOC>-KURSF = 0.
MSG-TYPE = ‘E‘.
<FS_DOC>-ICONID = ICON_LED_RED.
MSG-MESSAGE = ‘外币凭证必须填写汇率或本位币!‘.
APPEND MSG TO <FS_DOC>-RETURN.
CONCATENATE <FS_DOC>-RESULT MSG-MESSAGE
INTO <FS_DOC>-RESULT.
ENDIF.
ENDIF.
IF <FS_DOC>-HKONT = ‘‘.
MSG-TYPE = ‘E‘.
<FS_DOC>-ICONID = ICON_LED_RED.
MSG-MESSAGE = ‘科目不能为空!‘.
APPEND MSG TO <FS_DOC>-RETURN.
CONCATENATE <FS_DOC>-RESULT MSG-MESSAGE
INTO <FS_DOC>-RESULT.
ENDIF.
"原因代码校验
IF <FS_DOC>-RSTGR <> SPACE.
SELECT SINGLE RSTGR FROM T053R
INTO RSTGR
WHERE BUKRS = <FS_DOC>-BUKRS
AND RSTGR = <FS_DOC>-RSTGR.
IF SY-SUBRC <> 0.
MSG-TYPE = ‘E‘.
<FS_DOC>-ICONID = ICON_LED_RED.
CONCATENATE ‘原因代码 ‘ <FS_DOC>-RSTGR ‘ 在公司 ‘
<FS_DOC>-BUKRS ‘不存在!‘ INTO MSG-MESSAGE.
APPEND MSG TO <FS_DOC>-RETURN.
ENDIF.
ENDIF.
IF <FS_DOC>-HKONT <> ‘‘.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = <FS_DOC>-HKONT
IMPORTING
OUTPUT = <FS_DOC>-HKONT.
ENDIF.
IF <FS_DOC>-PRCTR <> ‘‘.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = <FS_DOC>-PRCTR
IMPORTING
OUTPUT = <FS_DOC>-PRCTR.
ENDIF.
IF <FS_DOC>-AUFNR <> ‘‘.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = <FS_DOC>-AUFNR
IMPORTING
OUTPUT = <FS_DOC>-AUFNR.
ENDIF.
IF <FS_DOC>-EBELN <> ‘‘.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = <FS_DOC>-EBELN
IMPORTING
OUTPUT = <FS_DOC>-EBELN.
ENDIF.
"记帐代码检查
SELECT SINGLE * FROM TBSL
WHERE BSCHL = <FS_DOC>-BSCHL."记帐代码
IF SY-SUBRC = 0.
CASE TBSL-KOART."记帐代码
WHEN ‘K‘.
SELECT SINGLE * FROM LFA1 INTO LS_LFA1
WHERE LIFNR = <FS_DOC>-HKONT.
IF SY-SUBRC = 0.
<FS_DOC>-COUNTRY = LS_LFA1-LAND1.
<FS_DOC>-XCPDK = LS_LFA1-XCPDK.
ELSE.
MSG-TYPE = ‘E‘.
<FS_DOC>-ICONID = ICON_LED_RED.
CONCATENATE ‘供应商代码‘ <FS_DOC>-HKONT ‘不存在!‘
INTO MSG-MESSAGE.
APPEND MSG TO <FS_DOC>-RETURN.
ENDIF.
WHEN ‘D‘."客户相关统驭科目
SELECT SINGLE * FROM KNA1 INTO LS_KNA1
WHERE KUNNR = <FS_DOC>-HKONT.
IF SY-SUBRC = 0.
<FS_DOC>-COUNTRY = LS_KNA1-LAND1.
<FS_DOC>-XCPDK = LS_KNA1-XCPDK.
ELSE.
MSG-TYPE = ‘E‘.
<FS_DOC>-ICONID = ICON_LED_RED.
CONCATENATE ‘客户代码‘ <FS_DOC>-HKONT ‘不存在!‘
INTO MSG-MESSAGE.
APPEND MSG TO <FS_DOC>-RETURN.
ENDIF.
ENDCASE.
ELSE.
MSG-TYPE = ‘E‘.
<FS_DOC>-ICONID = ICON_LED_RED.
CONCATENATE ‘记帐代码‘ <FS_DOC>-BSCHL ‘不存在!‘
INTO MSG-MESSAGE.
APPEND MSG TO <FS_DOC>-RETURN.
ENDIF.
IF <FS_DOC>-PERIOD = ‘‘."过账期间
<FS_DOC>-PERIOD = <FS_DOC>-BUDAT+4(2).
ENDIF.
ENDLOOP.
ENDFORM. " CHECKVALID
*&---------------------------------------------------------------------*
*& FORM FILL_IT_ACCOUNTTAX
*&---------------------------------------------------------------------
*
* TEXT
*----------------------------------------------------------------------
*
* --> P1 TEXT
* <-- P2 TEXT
*---------------------------------------------------------------------*
FORM FILL_IT_ACCOUNTTAX TABLES PT_CURRENCYAMOUNT STRUCTURE BAPIACCR09
PT_ACCOUNTTAX STRUCTURE BAPIACTX09
USING P_ITEMNO TYPE I
CHANGING DOCLINE LIKE IT_DOC.
DATA: LT_TAX LIKE TABLE OF RTAX1U15 WITH HEADER LINE.

CALL FUNCTION ‘CALCULATE_TAX_FROM_GROSSAMOUNT‘
EXPORTING
I_BUKRS = DOCLINE-BUKRS "公司代码
I_MWSKZ = DOCLINE-MWSKZ "税码
I_WAERS = DOCLINE-WAERS "币种
I_WRBTR = DOCLINE-WRBTR "金额
TABLES
T_MWDAT = LT_TAX.
LOOP AT LT_TAX.
CLEAR PT_ACCOUNTTAX.
PT_ACCOUNTTAX-ITEMNO_ACC = P_ITEMNO + 1.
PT_ACCOUNTTAX-TAX_CODE = DOCLINE-MWSKZ.
PT_ACCOUNTTAX-ACCT_KEY = LT_TAX-KTOSL.
PT_ACCOUNTTAX-COND_KEY = LT_TAX-KSCHL.
PT_ACCOUNTTAX-TAXJURCODE = LT_TAX-TXJCD.
PT_ACCOUNTTAX-TAXJURCODE_DEEP = LT_TAX-TXJCD_DEEP.
PT_ACCOUNTTAX-TAXJURCODE_LEVEL = LT_TAX-TXJLV.
APPEND PT_ACCOUNTTAX.
CLEAR PT_CURRENCYAMOUNT.
PT_CURRENCYAMOUNT-ITEMNO_ACC = PT_ACCOUNTTAX-ITEMNO_ACC.
PT_CURRENCYAMOUNT-CURR_TYPE = ‘00‘.
PT_CURRENCYAMOUNT-CURRENCY = DOCLINE-WAERS.
PT_CURRENCYAMOUNT-AMT_DOCCUR = LT_TAX-WMWST.
PT_CURRENCYAMOUNT-AMT_BASE = 100."DOCLINE-WRBTR.
APPEND PT_CURRENCYAMOUNT.

DOCLINE-WRBTR = LT_TAX-KAWRT.
EXIT.
ENDLOOP.
ENDFORM. " FILL_IT_ACCOUNTTAX


*&---------------------------------------------------------------------*
*& FORM TEMP_EXCEL_GET
*&---------------------------------------------------------------------*
* TCODE: SMW0 WEBRFC 的二进制数据
*----------------------------------------------------------------------*
* -->P_OBJID TYPE WWWDATA-OBJID
*---------------------------------------------------------------------*
FORM TEMP_EXCEL_GET USING P_OBJID TYPE WWWDATA-OBJID.
DATA:L_OBJDATA LIKE WWWDATATAB,
L_DESTINATION LIKE RLGRAP-FILENAME,
L_RC LIKE SY-SUBRC,
L_ERRTXT TYPE STRING.

DATA: L_FULLPATH TYPE STRING,
L_EXTENSION TYPE STRING,
L_FNAME LIKE RLGRAP-FILENAME,
" L_RC LIKE SY-SUBRC,
L_FORMKEY LIKE WWWDATATAB.

L_EXTENSION = P_OBJID.

PERFORM GET_FILE_NAME USING ‘.xls‘
‘Excel|*.xls‘
CHANGING L_FULLPATH.
IF L_FULLPATH = SPACE.
MESSAGE ‘请选择下载文件名‘ TYPE ‘E‘.
ELSE.
L_FNAME = L_FULLPATH.
SELECT SINGLE RELID OBJID
FROM WWWDATA
INTO CORRESPONDING FIELDS OF L_OBJDATA
WHERE RELID = ‘MI‘
AND OBJID = P_OBJID .

IF SY-SUBRC NE 0 OR L_OBJDATA-OBJID = SPACE.
MESSAGE E001(00) WITH ‘文件不存在!‘.
ELSE.
CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT‘
EXPORTING
KEY = L_OBJDATA
DESTINATION = L_FNAME
IMPORTING
RC = L_RC
CHANGING
TEMP = L_FNAME.
IF L_RC NE 0.
MESSAGE E001(00) WITH ‘文件下载失败!‘.
ENDIF.
ENDIF.
ENDIF.

ENDFORM. "TEMP_EXCEL_GET
*&---------------------------------------------------------------------*
*& FORM GET_FILE_NAME
*&--------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->P_EXTENSION TEXT
* -->P_FULLPATH TEXT
*----------------------------------------------------------------------*
FORM GET_FILE_NAME USING P_EXTENSION
P_FILE_FILTER
CHANGING P_FULLPATH.
DATA: L_FILENAME TYPE STRING,
L_PATH TYPE STRING,
L_FULLPATH TYPE STRING,
L_TITILE TYPE STRING,
L_INIT_DIR TYPE STRING.

CLEAR P_FULLPATH.

* L_TITILE = TEXT-T04.
* L_INIT_DIR = TEXT-T03.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = L_TITILE
DEFAULT_EXTENSION = ‘.xls‘
INITIAL_DIRECTORY = L_INIT_DIR
PROMPT_ON_OVERWRITE = ‘X‘
FILE_FILTER = P_FILE_FILTER
CHANGING
FILENAME = L_FILENAME
PATH = L_PATH
FULLPATH = L_FULLPATH
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

P_FULLPATH = L_FULLPATH.
ENDFORM. " GET_FILE_NAME
*&---------------------------------------------------------------------*
*& Form FILL_COPA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_ACKEC text
* -->P_LT_ACKEV text
* -->P_ITEMNO text
* -->P_<FS_DOCLINE> text
*----------------------------------------------------------------------*
FORM FILL_COPA TABLES PT_ACKEC STRUCTURE BAPIACKEC9
PT_ACKEV STRUCTURE BAPIACKEV9
USING P_ITEMNO TYPE I
DOCLINE LIKE IT_DOC.
*COPA特性字段赋值
IF DOCLINE-PRCTR <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘PRCTR‘.
PT_ACKEC-CHARACTER = DOCLINE-PRCTR.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-KUNNR <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘KUNNR‘.
PT_ACKEC-CHARACTER = DOCLINE-KUNNR.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-KDGRP <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘KDGRP‘.
PT_ACKEC-CHARACTER = DOCLINE-KDGRP.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-VKORG <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘VKORG‘.
PT_ACKEC-CHARACTER = DOCLINE-VKORG.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-VTWEG <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘VTWEG‘.
PT_ACKEC-CHARACTER = DOCLINE-VTWEG.
APPEND PT_ACKEC.
ENDIF.

IF DOCLINE-KMVKBU <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘KMVKBU‘.
PT_ACKEC-CHARACTER = DOCLINE-KMVKBU.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-WWZZS <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘WWZZS‘.
PT_ACKEC-CHARACTER = DOCLINE-WWZZS.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-BRSCH <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘BRSCH‘.
PT_ACKEC-CHARACTER = DOCLINE-BRSCH.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-SPART <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘SPART‘.
PT_ACKEC-CHARACTER = DOCLINE-SPART.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-KMVTNR <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘KMVTNR‘.
PT_ACKEC-CHARACTER = DOCLINE-KMVTNR.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-WERKS <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘WERKS‘.
PT_ACKEC-CHARACTER = DOCLINE-WERKS.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-MATNR <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘MATNR‘.
PT_ACKEC-CHARACTER = DOCLINE-MATNR.
APPEND PT_ACKEC.
SELECT SINGLE EXTWG MATKL FROM MARA
INTO (DOCLINE-EXTWG,DOCLINE-KMMAKL)
WHERE MATNR = DOCLINE-MATNR.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘EXTWG‘.
PT_ACKEC-CHARACTER = DOCLINE-EXTWG.
APPEND PT_ACKEC.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘KMMAKL‘.
PT_ACKEC-CHARACTER = DOCLINE-KMMAKL.
APPEND PT_ACKEC.
ENDIF.
IF DOCLINE-WW01 <> ‘‘.
PT_ACKEC-ITEMNO_ACC = P_ITEMNO.
PT_ACKEC-FIELDNAME = ‘WW01‘.
PT_ACKEC-CHARACTER = DOCLINE-WW01.
APPEND PT_ACKEC.
ENDIF.


*COPA值字段赋值
* PT_ACKEV-ITEMNO_ACC = 1.
* PT_ACKEV-FIELDNAME = ‘VV210‘.
* PT_ACKEV-CURRENCY = ‘CNY‘.
* PT_ACKEV-AMT_VALCOM = 100.
* APPEND PT_ACKEV.
ENDFORM. " FILL_COPA

由订单创建收款凭证

标签:des   io   os   使用   ar   for   sp   文件   数据   

原文地址:http://www.cnblogs.com/twttafku/p/4029139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!