‎2014 Feb 18 10:56 AM
Hi,
I want to generate accounting document through J1IJ transaction.
Client want to add functionality of generating accounting document when J1IJ is saved.
I have checked this User Exit J_1I7_USEREXIT_DEPOT_BEF_SAVE
In this UE I want to write a logic for generating accounting document.
Please help me with the programming code or function module which can generate accounting entries for Depot Excise Invoice.
‎2014 Feb 25 10:01 AM
*Populating tables for BAPI
str_rec_l_doch-obj_type = cc_g_objty.
str_rec_l_doch-obj_key(10) = rg23d-vbeln.
str_rec_l_doch-obj_key+10(4) = cc_g_bukrs.
str_rec_l_doch-obj_key+14(4) = sy-datum(4).
str_rec_l_doch-obj_sys = sy-sysid.
str_rec_l_doch-bus_act = cc_g_busact.
str_rec_l_doch-username = sy-uname.
str_rec_l_doch-doc_date = sy-datum.
str_rec_l_doch-pstng_date = sy-datum.
str_rec_l_doch-doc_type = cc_g_docty.
str_rec_l_doch-comp_code = cc_g_bukrs.
LOOP AT rg23d.
IF rg23d-exbed IS NOT INITIAL.
str_rec_l_accgl-itemno_acc = r_oth_g_zsched_line.
str_rec_l_accgl-gl_account = cc_g_acbed.
str_rec_l_accgl-comp_code = cc_g_bukrs.
str_rec_l_accgl-pstng_date = sy-datum.
str_rec_l_accgl-doc_type = cc_g_docty.
str_rec_l_accgl-po_number = str_rec_l_ekbe-ebeln.
str_rec_l_accgl-po_item = str_rec_l_ekbe-ebelp.
str_rec_l_accgl-item_text = cc_g_bedtxt.
str_rec_l_accgl-material = rg23d-matnr.
APPEND str_rec_l_accgl TO itab_g_accgl.
str_rec_l_curamt-itemno_acc = r_oth_g_zsched_line.
str_rec_l_curamt-currency = cc_g_curr.
str_rec_l_curamt-amt_doccur = rg23d-exbed * -1 .
APPEND str_rec_l_curamt TO itab_g_curamt.
r_oth_g_zsched_line = r_oth_g_zsched_line + 1.
ENDIF.
IF rg23d-ecs IS NOT INITIAL.
str_rec_l_accgl-itemno_acc = r_oth_g_zsched_line.
str_rec_l_accgl-gl_account = cc_g_acecs.
str_rec_l_accgl-comp_code = cc_g_bukrs.
str_rec_l_accgl-pstng_date = sy-datum.
str_rec_l_accgl-doc_type = cc_g_docty.
str_rec_l_accgl-po_number = str_rec_l_ekbe-ebeln.
str_rec_l_accgl-po_item = str_rec_l_ekbe-ebelp.
str_rec_l_accgl-item_text = cc_g_ecstxt.
str_rec_l_accgl-material = rg23d-matnr.
APPEND str_rec_l_accgl TO itab_g_accgl.
str_rec_l_curamt-itemno_acc = r_oth_g_zsched_line.
str_rec_l_curamt-currency = cc_g_curr.
str_rec_l_curamt-amt_doccur = rg23d-ecs * -1 .
APPEND str_rec_l_curamt TO itab_g_curamt.
r_oth_g_zsched_line = r_oth_g_zsched_line + 1.
ENDIF.
Endloop.
* Calling BAPI to create Accounting Document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = str_rec_l_doch
IMPORTING
obj_key = r_oth_g_awkey
TABLES
accountgl = itab_g_accgl
currencyamount = itab_g_curamt
return = itab_g_return
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE i999(re) WITH 'Problem occured in creating Accounting document'.
ELSE.
r_oth_g_zsched_line = 1.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = r_oth_g_wait
IMPORTING
return = r_oth_g_return.
‎2014 Feb 25 10:01 AM
*Populating tables for BAPI
str_rec_l_doch-obj_type = cc_g_objty.
str_rec_l_doch-obj_key(10) = rg23d-vbeln.
str_rec_l_doch-obj_key+10(4) = cc_g_bukrs.
str_rec_l_doch-obj_key+14(4) = sy-datum(4).
str_rec_l_doch-obj_sys = sy-sysid.
str_rec_l_doch-bus_act = cc_g_busact.
str_rec_l_doch-username = sy-uname.
str_rec_l_doch-doc_date = sy-datum.
str_rec_l_doch-pstng_date = sy-datum.
str_rec_l_doch-doc_type = cc_g_docty.
str_rec_l_doch-comp_code = cc_g_bukrs.
LOOP AT rg23d.
IF rg23d-exbed IS NOT INITIAL.
str_rec_l_accgl-itemno_acc = r_oth_g_zsched_line.
str_rec_l_accgl-gl_account = cc_g_acbed.
str_rec_l_accgl-comp_code = cc_g_bukrs.
str_rec_l_accgl-pstng_date = sy-datum.
str_rec_l_accgl-doc_type = cc_g_docty.
str_rec_l_accgl-po_number = str_rec_l_ekbe-ebeln.
str_rec_l_accgl-po_item = str_rec_l_ekbe-ebelp.
str_rec_l_accgl-item_text = cc_g_bedtxt.
str_rec_l_accgl-material = rg23d-matnr.
APPEND str_rec_l_accgl TO itab_g_accgl.
str_rec_l_curamt-itemno_acc = r_oth_g_zsched_line.
str_rec_l_curamt-currency = cc_g_curr.
str_rec_l_curamt-amt_doccur = rg23d-exbed * -1 .
APPEND str_rec_l_curamt TO itab_g_curamt.
r_oth_g_zsched_line = r_oth_g_zsched_line + 1.
ENDIF.
IF rg23d-ecs IS NOT INITIAL.
str_rec_l_accgl-itemno_acc = r_oth_g_zsched_line.
str_rec_l_accgl-gl_account = cc_g_acecs.
str_rec_l_accgl-comp_code = cc_g_bukrs.
str_rec_l_accgl-pstng_date = sy-datum.
str_rec_l_accgl-doc_type = cc_g_docty.
str_rec_l_accgl-po_number = str_rec_l_ekbe-ebeln.
str_rec_l_accgl-po_item = str_rec_l_ekbe-ebelp.
str_rec_l_accgl-item_text = cc_g_ecstxt.
str_rec_l_accgl-material = rg23d-matnr.
APPEND str_rec_l_accgl TO itab_g_accgl.
str_rec_l_curamt-itemno_acc = r_oth_g_zsched_line.
str_rec_l_curamt-currency = cc_g_curr.
str_rec_l_curamt-amt_doccur = rg23d-ecs * -1 .
APPEND str_rec_l_curamt TO itab_g_curamt.
r_oth_g_zsched_line = r_oth_g_zsched_line + 1.
ENDIF.
Endloop.
* Calling BAPI to create Accounting Document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = str_rec_l_doch
IMPORTING
obj_key = r_oth_g_awkey
TABLES
accountgl = itab_g_accgl
currencyamount = itab_g_curamt
return = itab_g_return
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE i999(re) WITH 'Problem occured in creating Accounting document'.
ELSE.
r_oth_g_zsched_line = 1.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = r_oth_g_wait
IMPORTING
return = r_oth_g_return.