Code: Alles auswählen.
CONSTANTS : lc_bus_act(4) TYPE c VALUE 'RFBU',
lc_doc_type(2) TYPE c VALUE 'SA'.
DATA :
lt_acc_glitem TYPE TABLE OF bapiacgl09,
ls_acc_glitem TYPE bapiacgl09,
lt_acc_curr_amnt TYPE TABLE OF bapiaccr09,
ls_acc_curr_amnt TYPE bapiaccr09,
g_obj_type TYPE bapiache09-obj_type, "#EC NEEDED
g_obj_key TYPE bapiache09-obj_key, "#EC NEEDED
g_obj_sys TYPE bapiache09-obj_sys, "#EC NEEDED
ls_acc_header TYPE bapiache09,
lt_return TYPE TABLE OF bapiret2,
ls_return TYPE bapiret2.
data: gv_acc_document_num(10) type c.
data: gv_error_flag type xfeld.
* Prepare accounting header
CLEAR ls_acc_header.
ls_acc_header-bus_act = lc_bus_act.
ls_acc_header-username = sy-uname.
ls_acc_header-comp_code = '0001' .
ls_acc_header-doc_date = sy-datum.
ls_acc_header-pstng_date = sy-datum.
ls_acc_header-fisc_year = sy-datum+0(4).
ls_acc_header-header_txt = 'Unit Test'.
ls_acc_header-obj_type = 'BKPFF'.
ls_acc_header-ac_doc_no = '$'.
ls_acc_header-doc_type = lc_doc_type.
ls_acc_header-fisc_year = sy-datum+0(4).
ls_acc_header-fis_period = sy-datum+4(2).
* Fill Line 1 of Document Item
ls_acc_glitem-itemno_acc = '1'.
ls_acc_glitem-stat_con = 'S'. "Debit
ls_acc_glitem-gl_account = '10010000'.
ls_acc_glitem-item_text = 'Unit Test'.
ls_acc_glitem-doc_type = lc_doc_type.
ls_acc_glitem-ac_doc_no = '$'.
ls_acc_glitem-comp_code = '0001'.
APPEND ls_acc_glitem TO lt_acc_glitem.
CLEAR ls_acc_glitem.
* Fill Line 2 of Document Item
ls_acc_glitem-itemno_acc = '2'.
ls_acc_glitem-stat_con = 'H'.
ls_acc_glitem-gl_account = '10010000'.
ls_acc_glitem-item_text = 'Unit Test'.
ls_acc_glitem-doc_type = lc_doc_type.
ls_acc_glitem-ac_doc_no = '$'.
ls_acc_glitem-comp_code = '0001' .
APPEND ls_acc_glitem TO lt_acc_glitem.
CLEAR ls_acc_glitem.
* Fill Line 1 of Document Value.
ls_acc_curr_amnt-itemno_acc = '1'.
ls_acc_curr_amnt-currency = 'CNY'.
ls_acc_curr_amnt-amt_doccur_long = '100'. "AFLE
ls_acc_curr_amnt-curr_type = '00'.
APPEND ls_acc_curr_amnt TO lt_acc_curr_amnt.
CLEAR ls_acc_curr_amnt.
* Fill Line 2 of Document Value.
ls_acc_curr_amnt-itemno_acc = '2'.
ls_acc_curr_amnt-currency = 'CNY'.
ls_acc_curr_amnt-amt_doccur_long = '-100'. "AFLE
ls_acc_curr_amnt-curr_type = '00'.
APPEND ls_acc_curr_amnt TO lt_acc_curr_amnt.
CLEAR ls_acc_curr_amnt.
* Check the Document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = ls_acc_header
TABLES
accountgl = lt_acc_glitem
currencyamount = lt_acc_curr_amnt
return = lt_return.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = ls_acc_header
IMPORTING
obj_type = g_obj_type
obj_key = g_obj_key
obj_sys = g_obj_sys
TABLES
accountgl = lt_acc_glitem
currencyamount = lt_acc_curr_amnt
return = lt_return.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ELSE.
gv_error_flag = 'X'.
ENDIF.
Code: Alles auswählen.
REPORT.
DATA:lv_objectkey TYPE objnum,
lt_allocvaluesnum TYPE STANDARD TABLE OF bapi1003_alloc_values_num,
lt_allocvalueschar TYPE STANDARD TABLE OF bapi1003_alloc_values_char,
lt_allocvaluescurr TYPE STANDARD TABLE OF bapi1003_alloc_values_curr,
lt_return TYPE STANDARD TABLE OF bapiret2.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = lv_objectkey
objecttable = 'EQUI'
classnum = 'OBJECTINFO'
classtype = '002'
TABLES
allocvaluesnum = lt_allocvaluesnum
allocvalueschar = lt_allocvalueschar
allocvaluescurr = lt_allocvaluescurr
return = lt_return.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL' "#EC CI_USAGE_OK[2438131] No material number in used part of interface
EXPORTING
objectkey = lv_objectkey
objecttable = 'EQUI'
classnum = 'OBJECTINFO'
classtype = '002'
TABLES
allocvaluesnum = lt_allocvaluesnum
allocvalueschar = lt_allocvalueschar
allocvaluescurr = lt_allocvaluescurr
return = lt_return.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag:
PeterPaletti
Code: Alles auswählen.
* Check the Document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK' "#EC CI_USAGE_OK[2628704] Longfield is used
"#EC CI_USAGE_OK[2438131] Material is not used
EXPORTING
documentheader = ls_acc_header
TABLES
accountgl = lt_acc_glitem
currencyamount = lt_acc_curr_amnt
return = lt_return.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST' "#EC CI_USAGE_OK[2438131] Material is not used
"#EC CI_USAGE_OK[2628704] Longfield is used
EXPORTING
documentheader = ls_acc_header
IMPORTING
obj_type = g_obj_type
obj_key = g_obj_key
obj_sys = g_obj_sys
TABLES
accountgl = lt_acc_glitem
currencyamount = lt_acc_curr_amnt
return = lt_return.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
Folgende Benutzer bedankten sich beim Autor PeterPaletti für den Beitrag:
Romaniac