由订单创建收款凭证

*&---------------------------------------------------------------------*
*& 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

时间: 2024-10-08 20:32:19

由订单创建收款凭证的相关文章

[问题解决]开启了adsubcon调用BAPI_GOODSMVT_CREATE创建物料凭证时第一行批次错误

1,问题描述 项目里使用了ADSUBCON,在调用BAPI_GOODSMVT_CREATE创建带subcontractor行项目的物料移动凭证时,发现主行项目中的批次赋值错误. 错误截图: 看到第一行,也就是物料移动类型是101的行项目上的批次是1208221560,实际调用bapi时的输入批次是另外一个1906050181,但是创建出来的物料凭证却不同,而且bapi返回消息中也没有提示任何信息. &lt;img class="alignnone size-medium wp-image

Super超级ERP系统---(8)订单管理--订单创建

订单管理是ERP系统中一个重要模块,客户下订单,ERP通过订单来为客户进行配送.订单模块主要包括订单创建,订单修改,订单审核,订单取消,订单分配,订单打印,订单拣货,订单出库.在随后的几节里我们看看这些每个模块是怎么设计运行的.    1.订单创建 订单创建主要功能是下单,下单的时候输入收货人信息,包括姓名,电话,邮箱,收货地址.录入需要的商品名称,数量等信息.如下图 2.订单审核 订单审核主要负责对创建的订单进行审核,对无效的订单进行取消.只用审核通过的订单,才能进行下一个环节进行操作.  3

Magento代码之订单创建流程

Magento代码之订单创建流程         直接看代码吧.下面的代码是如何通过程序创建一个完美订单.        <?php        require_once 'app/Mage.php';                 Mage::app('default');//初始化程序,设置当前店铺                 $store = Mage::app()->getStore('default');        //通过电子邮件获取用户,当然也可以不获取,创建gues

SAP MM 可以不用创建盘点凭证直接录入盘点结果?

SAP MM 可以不用创建盘点凭证直接录入盘点结果? 可以.SAP标准功能就支持这么做. 事务代码 MI09 (Enter Count w/o Reference to Document), 输入plant和storage location字段值, 输入各个物料批次的实际盘点库存结果值,保存, 系统自动创建了盘点凭证100104266,并完成了结果录入. 后续可以MI20去看difference list, MI07去clear difference了.比如MI07, SAP功能强大而灵活,能支

为什么S/4HANA的销售订单创建会触发生产订单的创建

调用S/4HANA销售订单创建函数SD_SALES_DOCU_MAINTAIN创建一个销售订单时,会触发生产订单的创建. 销售订单的每个行项目对应一个独立的生产订单,SD_SALES_DOCU_MAINTAIN相当于CRM里的CRM_ORDER_MAINTAIN,在LOOP里处理每一个行项目: 观察这个函数内部的调用栈,发现一个subroutine EIGENFERTIGUNG_BEARBEITEN.: EIGENFERTIGUNG的意思是Own production: BEARBEITEN的意

订单创建失败

最近修复的一个bug, 在prod上发生,但是在qa上没有发生. 在prod上也是偶现. 至少解决了 第一: 修复了订单创建失败,需要通知优惠券中台,“请将该优惠券释放” 第二: 我因为再去研究下为什么会下单失败,根据接口报的错是“优惠券已经被使用”,猜测是优惠券缓存不一致. 一台server优惠券显示的是可用,另一个server是不可用. 下单的时候,判断了两次优惠券??先看了其一server显示优惠券可用,正式下单又显示优惠券不可用??难道是这样 原文地址:https://www.cnblo

根据采购/销售订单创建STO/SO

FUNCTION Z_SD_CREATE_DN. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(IM_SHIP_TYPE) TYPE LIKP-VSART DEFAULT '01' *" VALUE(IM_DUE_DATE) TYPE DATUM DEFAULT '99991231'

为什么S/4HANA的生产订单创建后会自动release

在S/4HANA系统里我们观察到通过函数CO_61_ORDER_EDIT创建的生产订单会自动释放Release: 通过第86行的IF语句的条件检测不难找到原因. 变量PROFILE_TMP的类型为TCO43: 这个scheduling profile的配置在路径Production->Shop Floor Control->Master Data->Define Production Scheduling Profile里: 如下图所示:Automatic Actions标签页里的On

SAP 参照sto订单创建外向交货BAPI

DATA: VSTEL LIKE TVST-VSTEL, "装运点/接收点 NUM_DELIVERIES TYPE VBNUM, STOCK_TRANS_ITEMS LIKE BAPIDLVREFTOSTO OCCURS 0 WITH HEADER LINE. SHIP_POINT = '1000'. "装运点 STOCK_TRANS_ITEMS-REF_DOC = '4500000000'. "参考凭证 APPEND STOCK_TRANS_ITEMS. REFRESH L