ZDOCUMENT_BILL_EXCHANG_POST
施超
2023-12-01
FUNCTION ZDOCUMENT_BILL_EXCHANG_POST
.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(I_HEADER) LIKE BKPF STRUCTURE BKPF
*" EXPORTING
*" VALUE(E_BELNR) TYPE BKPF-BELNR
*" VALUE(E_GJAHR) TYPE BKPF-GJAHR
*" TABLES
*" IT_ITEM STRUCTURE ZFS_BSED
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
DATA
:LV_ZFBDT
(
10
)
TYPE
C
,
LV_WDATE
(
10
)
TYPE
C
,
LV_VALUT
(
10
)
TYPE
C
.
CLEAR
:E_BELNR
,E_GJAHR
.
REFRESH
: IT_BLNTAB
,IT_FTCLEAR
,IT_FTPOST
,
RETURN
.
IF I_HEADER
-BUDAT
IS
INITIAL
.
WRITE SY
-DATUM
TO LV_DATUM
.
ELSE
.
WRITE I_HEADER
-BUDAT
TO LV_DATUM
.
ENDIF
.
IF I_HEADER
-BLDAT
IS
INITIAL
.
WRITE SY
-DATUM
TO LV_BLDAT
.
ELSE
.
WRITE I_HEADER
-BLDAT
TO LV_BLDAT
.
ENDIF
.
CALL
FUNCTION
'POSTING_INTERFACE_START'
EXPORTING
I_FUNCTION
=
'C'
I_KEEP
=
'X'
I_MODE
=
MODE
I_UPDATE
=
'A'
EXCEPTIONS
CLIENT_INCORRECT
=
1
FUNCTION_INVALID
=
2
GROUP_NAME_MISSING
=
3
MODE_INVALID
=
4
UPDATE_INVALID
=
5
OTHERS
=
6
.
POPULATE_FTPOST
:
'K'
1
'BKPF-BUKRS' I_HEADER
-BUKRS
,
"Company code
'K'
1
'BKPF-BLART' I_HEADER
-BLART
,
'K'
1
'BKPF-BLDAT' LV_BLDAT
,
'K'
1
'BKPF-BUDAT' LV_DATUM
,
'K'
1
'BKPF-MONAT' I_HEADER
-MONAT
,
'K'
1
'BKPF-WAERS' I_HEADER
-WAERS
,
'K'
1
'BK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EM
-WLZBP
,
'P' IT_ITEM
-BUZEI
'BSED-WBANK' IT_ITEM
-WBANK
,
'P' IT_ITEM
-BUZEI
'BSEG-ZFBDT' LV_ZFBDT
.
ELSE
.
POPULATE_FTPOST
:
'P' IT_ITEM
-BUZEI
'RF05A-NEWUM' IT_ITEM
-UMSKZ
.
POPULATE_FTPOST
:
'P' IT_ITEM
-BUZEI
'COBL-PRCTR' IT_ITEM
-PRCTR
.
ENDIF
.
POPULATE_FTPOST
:
'P' IT_ITEM
-BUZEI
'BSEG-SGTXT' IT_ITEM
-SGTXT
,
'P' IT_ITEM
-BUZEI
'BSEG-ZUONR' IT_ITEM
-ZUONR
,
'P' IT_ITEM
-BUZEI
'BSEG-WRBTR' LV_DMBTR
.
IF IT_ITEM
-SKFBT <>
0
.
POPULATE_FTPOST
:
'P' IT_ITEM
-BUZEI
'BSEG-SKFBT' LV_SKFBT
.
ENDIF
.
IF IT_ITEM
-XNEGP
=
'X'
.
POPULATE_FTPOST
:
'P' IT_ITEM
-BUZEI
'BSEG-XNEGP' IT_ITEM
-XNEGP
.
ENDIF
.
ENDLOOP
.
CALL
FUNCTION
'POSTING_INTERFACE_DOCUMENT'
EXPORTING
I_TCODE
=
'FB01'
* I_SGFUNCT = ' '
* I_NO_AUTH = ' '
IMPORTING
E_MSGID
=
RETURN
-
ID
E_MSGNO
=
RETURN
-
NUMBER
E_MSGTY
=
RETURN
-
TYPE
E_MSGV1
=
RETURN
-MESSAGE_V1
E_MSGV2
=
RETURN
-MESSAGE_V2
E_MSGV3
=
RETURN
-MESSAGE_V3
E_MSGV4
=
RETURN
-MESSAGE_V4
* E_SUBRC =
TABLES
T_BLNTAB
= IT_BLNTAB
T_FTPOST
= IT_FTPOST
T_FTTAX
= IT_FTTAX
EXCEPTIONS
ACCOUNT_MISSING
=
1
COMPANY_CODE_MISSING
=
2
POSTING_KEY_INVALID
=
3
POSTING_KEY_MISSING
=
4
RECORD_TYPE_INVALID
=
5
TRANSACTION_CODE_INVALID
=
6
AMOUNT_FORMAT_ERROR
=
7
TOO_MANY_LINE_ITEMS
=
8
COMPANY_CODE_INVALID
=
9
SCREEN_NOT_FOUND
=
10
NO_AUTHORIZATION
=
11
OTHERS
=
12
.
IF SY
-SUBRC
=
0
AND IT_BLNTAB[]
IS
NOT
INITIAL
AND
RETURN
-
TYPE <>
'E'
.
READ
TABLE IT_BLNTAB
INDEX
1
.
IF SY
-SUBRC
=
0
.
E_BELNR
= IT_BLNTAB
-BELNR
.
E_GJAHR
= IT_BLNTAB
-GJAHR
.
ENDIF
.
ENDIF
.
CALL
FUNCTION
'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID
=
RETURN
-
ID
MSGNR
=
RETURN
-
NUMBER
MSGV1
=
RETURN
-MESSAGE_V1
MSGV2
=
RETURN
-MESSAGE_V2
MSGV3
=
RETURN
-MESSAGE_V3
MSGV4
=
RETURN
-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT
=
RETURN
-
MESSAGE
.
APPEND
RETURN
.
CALL
FUNCTION
'POSTING_INTERFACE_END'
EXCEPTIONS
SESSION_NOT_PROCESSABLE
=
1
OTHERS
=
2
.
ENDFUNCTION
.