0
Former Member
Jul 23, 2007 at 02:45 PM

Getting the total amount n creating extra profit center

32 Views

hello folks,

I am uploading the data for open AR items, in this process..

I am looping through the AR items internal table and for each one AR item i am taking multiple GL items looping through the GL item internal table internally.

So here I have to do one more extra thing. I have to take the balance amount of the one AR item BSEG-WRBTR and compare with the sum of the GL items amounts for that particular AR line item and if there is any difference in the amount then with that difference amount i have to create one more extra line GL line item.

here is the example : let us take the AR item balance amount is 100\$ and the for that particular AR item if u have 3 GL line items each one with 30\$ balance amounts. Then compare 100 = 303030 and the difference is 10\$. With that 10\$ amount i have to create the one more GL line item how to do it can anyone guide me plzzzzzzzzzzzz

here is my code.......

FORM FORM_MAIN_LOGIC.

DATA:BEGIN OF KUNNR1,

KUNNR TYPE KUNNR,

ALTKN TYPE ALTKN,

BUKRS TYPE BUKRS,

END OF KUNNR1.

DATA: BEGIN OF IT_EXTENSION OCCURS 0,

P_EXTENSION TYPE C,

END OF IT_EXTENSION.

DATA : LV_WRBTR TYPE WRBTR.

DATA: BEGIN OF I_PRCTR,

PRCTR TYPE PRCTR,

END OF I_PRCTR.

LOOP AT I_ARITEM.

SELECT SINGLE KUNNR FROM KNB1 INTO KUNNR1-KUNNR WHERE ALTKN = I_ARITEM-P_KUNNR and BUKRS = 'U001' .

IF SY-SUBRC <> 0.

WA_ERROR-E_KUNNR = I_ARITEM-P_KUNNR.

WA_ERROR-E_XBLNR = I_ARITEM-P_XBLNR.

WA_ERROR-E_ERROR = ' CORRESPONDING SAP CUSTOMER NOT FOUND'.

APPEND WA_ERROR TO IT_ERROR .

MOVE KUNNR1-KUNNR TO I_ARITEM-P_KUNNR.

MODIFY I_ARITEM.

ENDIF.

CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

IMPORTING

• fill AR (line 1)

IT_ACCOUNTRECEIVABLE-ITEMNO_ACC = '1'.

IT_ACCOUNTRECEIVABLE-CUSTOMER = I_ARITEM-P_KUNNR.

IT_ACCOUNTRECEIVABLE-REF_KEY_1 = I_ARITEM-P_XREF1.

IT_ACCOUNTRECEIVABLE-REF_KEY_2 = I_ARITEM-P_XREF2.

IT_ACCOUNTRECEIVABLE-REF_KEY_3 = I_ARITEM-P_XREF3.

IT_ACCOUNTRECEIVABLE-PMNTTRMS = I_ARITEM-P_ZTERM.

IT_ACCOUNTRECEIVABLE-ALLOC_NMBR = I_ARITEM-P_ZUONR.

IT_ACCOUNTRECEIVABLE-ITEM_TEXT = I_ARITEM-P_SGTXT.

APPEND IT_ACCOUNTRECEIVABLE.

• fill extension segments.

it_EXTENSION1-field1+3 = 1.

it_EXTENSION1-field1+3(18) = I_ARITEM-P_RSTGR.

it_EXTENSION1-field1+3(10) = I_ARITEM-P_WSKTO.

append IT_EXTENSION1.

IT_CURRENCYAMOUNT-ITEMNO_ACC = 1.

IT_CURRENCYAMOUNT-CURR_TYPE = '00'.

IT_CURRENCYAMOUNT-CURRENCY = 'USD'.

IT_CURRENCYAMOUNT-AMT_DOCCUR = I_ARITEM-P_WRBTR.

APPEND IT_CURRENCYAMOUNT.

LOOP AT I_GLITEM.

*******GET THE PROFIT CENTER AND UPDATE THE BAPI STRUCTURE************

*SELECT SIGLE PRCTR FROM YOCTD_C009_MKDPR INTO I_PRCTR-PRCTR WHERE LEG_MRKT_DIV = I_GLITEM-P_MRDIV AND

• LEG_SBU = I_GLITEM-P_MRSBU.

IF SY-SUBRC = 0.

MOVE I_PRCTR TO I_GLITEM-P_PRCTR.

MODIFY I_GLITEM.

ENDIF.

*IF PROFIT CENTER IS NOT FOUND THEN CREATE A NEW PROFIT CENTER.

IF SY-SUBRC <> 0.

I_GLITEM-P_PRCTR = 'P1331193'.

MODIFY I_GLITEM.

ENDIF.

*******CHECK THE ROLL UP GL LINE ITEM AMOUNT WITH AR LINE ITEM AMOUNT.

• GET PROFIT CENTER FOR THE CORRESPONDING MARK DIV AND SBU.

*SELECT SINGLE PRCTR FROM YOTCD_C009_MKDPR INTO I_GLITEM-PRCRT WHERE LEG_MRKT_DIV = I_GLITEM-MARDIV AND LEG_SBU = I_GLITEM-MRSUB.

IT_ACCOUNTGL-ITEMNO_ACC = 2.

IT_ACCOUNTGL-GL_ACCOUNT = P_HKONT.

IT_ACCOUNTGL-ITEM_TEXT = 'CONVERSION ACCOUNT'.

IT_ACCOUNTGL-COSTCENTER = P_KOSTL.

IT_ACCOUNTGL-PROFIT_CTR = P_PRCTR.

APPEND IT_ACCOUNTGL.

IT_CURRENCYAMOUNT-ITEMNO_ACC = 2.

IT_CURRENCYAMOUNT-CURR_TYPE = '00'.

IT_CURRENCYAMOUNT-CURRENCY = P_WAERS.

IT_CURRENCYAMOUNT-AMT_DOCCUR = I_GLITEM-P_SAMNT * -1.

APPEND IT_CURRENCYAMOUNT.

ENDLOOP.

PERFORM FORM_CHECK_DATA.

PERFORM FORM_POST_DATA.

PERFORM FORM_COMMIT_WORK.

PERFORM FORM_LONG_TEXT.

ENDLOOP.

Please its bit urgent can anyone guide me...........

SRI