2012 Oct 25 11:06 AM
Hi Experts,
I am working on a program at the moment where BAPI_ACC_DOCUMENT_POST is used to post gl items to a screen.
However i have been asked to create 1 summary line for all minus gl items instead of the current method of 1 line per minus gl item.
Any help appreciated.
2012 Oct 25 11:46 AM
Hi Michael,
The reconcilation GL for all the minus GL line items will be only 1. You need to collect the GL amount into that line. In addition collect all the minus amount into one work area of type currency, separate for the document currency, local currency or any other currency type.
At the end of the program, before posting, append the reconcilation account to GL Line item. Append the summary currency to the currency line and also the balancing entry. This needs to be done for each type of currency. Once coded, just check if the currency total is 0 for that line items. If this is done, the program will put the summary GL line for all the line items and automatically calculate the amounts.
Regards,
Hardik Mehta
2012 Oct 25 11:29 AM
Hi
I suppose you need to collect the minus gl item into a new one and you transfer it to the BAPI
Max
2012 Oct 25 11:41 AM
Hi Max,
i already hav trieed creating a new gl_item which contains the total value for the minus values.
however this will not work as i need to place a corresponding positive value for the program to work i.e. if the total minus value is a -1000 than hav to add a new anoother item which contains 1000.
Please see screenshot below
The total value of minus products is -1504.94.
However in order for the program to work i am having to add an extra line of a positive 1504.94.this is obviously wrong.
2012 Oct 25 11:31 AM
Hi Michael,
Try using the BAPI - BAPI_ACC_GL_POSTING_POST.
I have used this BAPI for GL Account Doc Posting and did not encounter such problem.
Regards...
Sultana
2012 Oct 25 11:46 AM
Hi Michael,
The reconcilation GL for all the minus GL line items will be only 1. You need to collect the GL amount into that line. In addition collect all the minus amount into one work area of type currency, separate for the document currency, local currency or any other currency type.
At the end of the program, before posting, append the reconcilation account to GL Line item. Append the summary currency to the currency line and also the balancing entry. This needs to be done for each type of currency. Once coded, just check if the currency total is 0 for that line items. If this is done, the program will put the summary GL line for all the line items and automatically calculate the amounts.
Regards,
Hardik Mehta
2012 Oct 25 11:52 AM
Hi Hardik,
Thanks for the response,i really appreciate it.
I have never worked on bapi's before so im not 100% clear on what you mean by your response above.
Could you take a look at my present code and maybe point out where i need to make a change?
METHOD create_ap_journal.
FIELD-SYMBOLS: <order> TYPE /chcie/orders_order.
TYPES: BEGIN OF calc_type,
ITEMNO_ACC TYPE POSNR_ACC,
AMT_DOCCUR type BAPIWRBTR,
GL_ACCOUNT type HKONT,
PROFIT_CTR type PRCTR,
END OF calc_type.
DATA: ls_dochead TYPE bapiache09,
ls_ap TYPE bapiacap09,
lt_ap TYPE bapiacap09_tab,
ls_curamt TYPE bapiaccr09,
lt_curamt TYPE bapiaccr09_tab,
lt_accountgl TYPE bapiacgl09_tab,
LT_ACCOUNTGL_sort type bapiacgl09_tab,
ls_accountgl TYPE bapiacgl09,
ls_accountgl_sort type bapiacgl09,
lv_calc type calc_type,
lv_calc_tab type table of calc_type,
lv_change type calc_type,
lv_change_tab type TABLE OF calc_type,
lv_test type calc_type,
lt_test type TABLE OF calc_type,
AMT_D_COLLECT TYPE BAPIWRBTR,
ls_return TYPE bapiret2,
lt_return TYPE bapiret2_tt,
lv_error TYPE sybatch,
lv_item TYPE posnr_va,
* lv_item2 type POSNR_VA,
lv_msg TYPE symsgv,
lv_itemno TYPE kdpos,
ls_succ_post TYPE /chcie/orders_posted.
IF gv_document = ' '.
CLEAR ls_return.
ls_return-type = 'E'.
ls_return-id = '/CHCIE/SD_01'.
ls_return-number = '000'.
ls_return-message_v1 = '---> Journal NOT created following error'.
ls_return-message_v2 = 'creating one or more SD documents'.
APPEND ls_return TO gt_errors.
ENDIF.
CHECK gv_document NE ' '. "Check the creation of the SD doc was successful
*---> Initialize variables
CLEAR: ls_dochead, lv_error.
*---> Set up Header data
ls_dochead-bus_act = 'RFBU'.
ls_dochead-username = sy-uname.
ls_dochead-comp_code = /chcie/cl_bc_constants=>c_cbi_sales_org. "4200.
ls_dochead-doc_date = sy-datum.
ls_dochead-pstng_date = sy-datum.
ls_dochead-ref_doc_no = gv_lifnr. "Supplier code
ls_dochead-header_txt = gv_lifnr.
ls_dochead-doc_type = /chcie/cl_bc_constants=>c_cbi_fi_doc_type. "'S2'.
LOOP AT gt_orders ASSIGNING <order>.
AT NEW type.
CLEAR: lt_return, ls_curamt, lt_curamt, ls_accountgl, lt_accountgl.
lv_item = '000001'.
*---> Set info for Application Log entry
CLEAR ls_return.
ls_return-type = 'S'.
ls_return-id = '/CHCIE/SD_01'.
ls_return-number = '000'.
CONCATENATE '>' <order>-type 'Supplier' <order>-suppcode INTO ls_return-message_v1 SEPARATED BY space.
APPEND ls_return TO gt_errors.
CLEAR lv_itemno.
ENDAT.
ls_curamt-itemno_acc = lv_item.
ls_curamt-currency = 'EUR'.
ls_curamt-amt_doccur = ( <order>-costprice * <order>-qty ) * -1.
move ls_curamt-itemno_acc to lv_test-itemno_acc.
move ls_curamt-amt_doccur to lv_test-amt_doccur.
append lv_test to lt_test.
APPEND ls_curamt TO lt_curamt.
ls_curamt-itemno_acc = ls_curamt-itemno_acc + 1.
ls_curamt-currency = 'EUR'.
ls_curamt-amt_doccur = ( <order>-costprice * <order>-qty ).
move ls_curamt-itemno_acc to lv_test-itemno_acc.
move ls_curamt-amt_doccur to lv_test-amt_doccur.
append lv_test to lt_test.
APPEND ls_curamt TO lt_curamt.
ls_accountgl-itemno_acc = lv_item.
IF <order>-type = 'INV'.
ls_accountgl-gl_account = /chcie/cl_bc_constants=>c_cbi_cr_accnt. "'0036990010'.
lv_change-gl_account = ls_accountgl-gl_account.
* lv_change-GL_ACCOUNT = ls_accountgl-GL_ACCOUNT.
* lv_change-PROFIT_CTR = ls_accountgl-PROFIT_CTR.
* modify lt_test index sy-tabix from lv_change
* TRANSPORTING gl_account profit_ctr.
* append lv_test to lt_test.
ELSE.
ls_accountgl-gl_account = /chcie/cl_bc_constants=>c_cbi_dr_accnt.
lv_change-gl_account = ls_accountgl-gl_account.
* lv_change-GL_ACCOUNT = ls_accountgl-GL_ACCOUNT.
* lv_change-PROFIT_CTR = ls_accountgl-PROFIT_CTR.
* modify lt_test index sy-tabix from lv_change
* TRANSPORTING gl_account profit_ctr.
* append lv_test to lt_test.
ENDIF.
ls_accountgl-item_text = <order>-proddetails.
ls_accountgl-pstng_date = sy-datum.
ls_accountgl-doc_type = /chcie/cl_bc_constants=>c_cbi_fi_doc_type. "S2.
*new bit
SELECT SINGLE lifnr FROM lfm1 INTO gv_lifnr WHERE eikto = <order>-suppcode.
* select single inpnr from EDPAR into gv_inpnr where
* kunnr = gv_lifnr and
* parvw = 'AG' and "AG
* expnr = <order>-acccode.
SELECT SINGLE kunnr FROM knb1 INTO gv_inpnr WHERE
bukrs = '4200' AND
zsabe = <order>-acccode.
SELECT SINGLE vkbur INTO gv_vkbur FROM knvv WHERE
kunnr = gv_inpnr AND
vkorg = /chcie/cl_bc_constants=>c_cbi_sales_org AND
vtweg = /chcie/cl_bc_constants=>c_cbi_distr_chan.
*end new bit
CONCATENATE '11' gv_vkbur '0001' INTO ls_accountgl-profit_ctr. "eg. '1142010001'.
lv_change-profit_ctr = ls_accountgl-profit_ctr.
ls_accountgl-alloc_nmbr = gv_lifnr. "Assignment
* For PL Posting only
IF ls_accountgl-gl_account = /chcie/cl_bc_constants=>c_cbi_dr_accnt.
* Add the Sales Order and item no. to posting
LOOP AT gt_succ_post INTO ls_succ_post
WHERE acccode = <order>-acccode.
ls_accountgl-sales_ord = ls_succ_post-vbeln.
lv_itemno = lv_itemno + 10.
ls_accountgl-s_ord_item = lv_itemno.
ENDLOOP.
ENDIF.
APPEND ls_accountgl TO lt_accountgl.
CLEAR: ls_accountgl-sales_ord, ls_accountgl-s_ord_item.
ls_accountgl-itemno_acc = ls_accountgl-itemno_acc + 1.
IF <order>-type = 'INV'.
ls_accountgl-gl_account = /chcie/cl_bc_constants=>c_cbi_dr_accnt. " '0051101100'.
ELSE.
ls_accountgl-gl_account = /chcie/cl_bc_constants=>c_cbi_cr_accnt. "'0036990010'.
ENDIF.
ls_accountgl-item_text = <order>-proddetails.
ls_accountgl-pstng_date = sy-datum.
ls_accountgl-doc_type = /chcie/cl_bc_constants=>c_cbi_fi_doc_type. "'S2'.
CONCATENATE '11' gv_vkbur '0001' INTO ls_accountgl-profit_ctr. "eg. '1142010001'.
ls_accountgl-alloc_nmbr = gv_lifnr.
* For PL Posting only
IF ls_accountgl-gl_account = /chcie/cl_bc_constants=>c_cbi_dr_accnt.
* Add the Sales Order and item no. to posting
LOOP AT gt_succ_post INTO ls_succ_post
WHERE acccode = <order>-acccode.
ls_accountgl-sales_ord = ls_succ_post-vbeln.
lv_itemno = lv_itemno + 10.
ls_accountgl-s_ord_item = lv_itemno.
ENDLOOP.
ENDIF.
APPEND ls_accountgl TO lt_accountgl.
append lv_change to lv_change_tab.
CLEAR: ls_accountgl-sales_ord, ls_accountgl-s_ord_item.
lv_item = lv_item + 2.
* Clear the Sales Item line no.
AT END OF acccode.
CLEAR lv_itemno.
ENDAT.
if sy-tabix NE '2'.
*ls_accountgl-ITEMNO_ACC = '0000000005'.
*ls_accountgl-GL_ACCOUNT = '0036990010'.
*ls_accountgl-item_text = 'Foster Grant Sunglasses'.
*append ls_accountgl to lt_accountgl.
*ls_accountgl-ITEMNO_ACC = '0000000006'.
*ls_accountgl-GL_ACCOUNT = '0041810302'.
*ls_accountgl-item_text = 'Foster Grant Sunglasses'.
*append ls_accountgl to lt_accountgl.
*ls_curamt-ITEMNO_ACC = '0000000005'.
*ls_curamt-AMT_DOCCUR = '800.00'.
*ls_curamt-CURRENCY = 'EUR'.
*append ls_curamt to lt_curamt.
*ls_curamt-ITEMNO_ACC = '0000000006'.
*ls_curamt-AMT_DOCCUR = '800.00-'.
*ls_curamt-CURRENCY = 'EUR'.
*append ls_curamt to lt_curamt.
*
*move ls_curamt-itemno_acc to lv_test-itemno_acc.
endif.
if sy-tabix eq '2'.
loop at lt_accountgl into ls_accountgl.
clear lv_change.
lv_change-GL_ACCOUNT = ls_accountgl-GL_ACCOUNT.
lv_change-PROFIT_CTR = ls_accountgl-PROFIT_CTR.
MODIFY lt_test INDEX sy-tabix FROM lv_change
TRANSPORTING GL_ACCOUNT PROFIT_CTR.
* LOOP at lt_test into lv_test where GL_ACCOUNT = '0036990010' and PROFIT_CTR = lv_change-PROFIT_CTR .
endloop.
LOOP at lt_test into lv_test where GL_ACCOUNT = '0036990010'.
AMT_D_COLLECT = AMT_D_COLLECT + LV_TEST-AMT_DOCCUR.
ENDLOOP.
* ******************
clear ls_curamt.
clear ls_accountgl.
ls_curamt-ITEMNO_ACC = lv_item .
ls_curamt-AMT_DOCCUR = AMT_D_COLLECT.
ls_curamt-CURRENCY = 'EUR'.
ls_accountgl-ITEMNO_ACC = lv_item .
ls_accountgl-GL_ACCOUNT = '0036990010'.
append ls_curamt to lt_curamt.
append ls_accountgl to lt_accountgl.
********************
endif.
*ls_accountgl-ITEMNO_ACC = '0000000005'.
*ls_accountgl-GL_ACCOUNT = '0036990010'.
*ls_accountgl-item_text = 'Foster Grant Sunglasses'.
*append ls_accountgl to lt_accountgl.
*ls_accountgl-ITEMNO_ACC = '0000000006'.
*ls_accountgl-GL_ACCOUNT = '0041810302'.
*ls_accountgl-item_text = 'Foster Grant Sunglasses'.
*append ls_accountgl to lt_accountgl.
*ls_curamt-ITEMNO_ACC = '0000000005'.
*ls_curamt-AMT_DOCCUR = '800.00'.
*ls_curamt-CURRENCY = 'EUR'.
*append ls_curamt to lt_curamt.
*ls_curamt-ITEMNO_ACC = '0000000006'.
*ls_curamt-AMT_DOCCUR = '800.00-'.
*ls_curamt-CURRENCY = 'EUR'.
*append ls_curamt to lt_curamt.
*
AT END OF type.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = ls_dochead
TABLES
accountgl = lt_accountgl
currencyamount = lt_curamt
return = lt_return.
LOOP AT lt_return INTO ls_return WHERE type = 'E'.
lv_error = 'X'.
ENDLOOP.
IF lv_error NE 'X'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CLEAR ls_return.
LOOP AT lt_return INTO ls_return.
ENDLOOP.
lv_msg = ls_return-message_v2.
CLEAR ls_return.
ls_return-type = 'S'.
ls_return-id = '/CHCIE/SD_01'.
ls_return-number = '000'.
CONCATENATE '---> Journal' lv_msg(10) 'created' INTO ls_return-message_v1 SEPARATED BY space.
APPEND ls_return TO gt_errors.
ENDIF.
LOOP AT lt_return INTO ls_return WHERE type = 'E'.
CONCATENATE '--->' ls_return-message_v1 INTO ls_return-message_v1 SEPARATED BY space.
APPEND ls_return TO gt_errors.
ENDLOOP.
ENDAT.
ENDLOOP.
ENDMETHOD.
2012 Oct 25 12:30 PM
Hi Michael,
I have gone through your program code and would like to have the following suggestion:
Data: wa_gl type bapiscgl09_tab
wa_curr type bapiaccr09_tab.
Loop at ....
AT NEW...
CLEAR: wa_gl, wa_curr.
<rest is ok>
ENDAT
*if GL is Minus, I think it is when <order>-type NE 'INV'
*First transfer to work area for summary account
wa_gl-account = <reconcilation account, Functional can provide this account>
.... Other GL values to be added, keep line item as blank.
*then collect all the currency amounts
wa_curr-amount = <gl-amount>..
(it is same as you have appended the currency amount. Line item should be blank. This should be for all currency types)
COLLECT WA_CURR into currency table.
....
..
AT END OF
wa_gl-line item = line item + 1.
Append wa_gl to GL table.
Read currency table where line item is blank. Modify the line item to the gl line item for all currency types.
then call BAPI_ACC_DOCUMENT_POST.
ENDAT
Endloop.
This is the general structure of the program which needs to be developed. Its only some code fixing for the summary lines.
Regards,
Hardik Mehta