Parameters p_belnr like bkpf-belnr
default '0100000236'.
*Get last SA type document posted to build document key
CALL FUNCTION
'NUMBER_GET_NEXT' EXPORTING
NR_RANGE_NR =
'01' OBJECT =
'RF_BELEG' QUANTITY =
'1' SUBOBJECT =
'4000' "company code TOYEAR =
'2005' IGNORE_BUFFER =
'2005' IMPORTING
NUMBER = docnum
QUANTITY =
RETURNCODE =
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8
.
IF SY-SUBRC 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
"Begin to populate docnument header. *obj_key contains
new document no.
CONCATENATE docnum
'4000' sy-datlo(4) INTO doc_header-obj_key.
doc_header-obj_type =
'BKPFF'.
*obj_key_r contains document no. needed to reverse
CONCATENATE p_belnr
'4000' sy-datlo(4) INTO doc_header-obj_key_r.
doc_header-obj_sys =
'A1DMD011'.
*doc_header-OBJ_KEY_R =
'AWREF_REV'.
*doc_header-AC_DOC_NO =
'8'.
*doc_header-header_txt =
'TEST BOC BAPI POSTING'.
doc_header-comp_code =
'4000'.
doc_header-REASON_REV =
'02'.
doc_header-pstng_date =
'20050517'.
doc_header-FIS_PERIOD =
'05'.
"All tables filled - now call BAPI. CALL FUNCTION
'BAPI_ACC_GL_POSTING_REV_POST' EXPORTING
REVERSAL = doc_header
IMPORTING
OBJ_TYPE = doc_header-obj_type
OBJ_KEY = doc_header-obj_key
OBJ_SYS = doc_header-obj_sys
TABLES
RETURN =
return .
LOOP AT
return WHERE type =
'E'.
EXIT.
ENDLOOP.
IF sy-subrc EQ 0.
WRITE: /
'BAPI call failed - debug and fix!'.
LOOP AT return.
WRITE: / .
WRITE:
return-TYPE,
'|',
return-ID,
'|',
return-NUMBER,
'|',
return-MESSAGE.
ENDLOOP.
ELSE.
LOOP AT return.
WRITE: / .
WRITE:
return-TYPE,
'|',
return-ID,
'|',
return-NUMBER,
'|',
return-MESSAGE.
ENDLOOP.
CLEAR return.
REFRESH return.
CALL FUNCTION
'BAPI_TRANSACTION_COMMIT' EXPORTING
WAIT =
'X' IMPORTING
return = return.
WRITE: /
'BAPI call worked!!'.
WRITE: / doc_header-obj_key,
' posted'.
----------------------------------------------------------------
另外一个代码:
call function 'OWN_LOGICAL_SYSTEM_GET'
importing
own_logical_system = reversal-obj_sys.
clear reversal[].
select single awtyp awkey awkey into
(reversal-obj_type, reversal-obj_key_r, reversal-obj_key)
from bkpf where belnr = wa_belnr
and bukrs = wa_bukrs
and gjahr = wa_gjahr.
reversal-obj_key(1) = 'R'.
reversal-pstng_date = p_budat.
reversal-fis_period = p_budat+4(2).
reversal-comp_code = wa_bukrs.
reversal-reason_rev = p_stgrd.
reversal-ac_doc_no = wa_belnr.
append reversal.
call function 'BAPI_ACC_DOCUMENT_REV_POST'
exporting
reversal = reversal
bus_act = 'RFBU'
importing
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
tables
return = p_return.
阅读(6264) | 评论(4) | 转发(0) |