Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how to loop bdc_insert for fb60 posting

Former Member
0 Likes
904

for those who has play fb60/fb65 before, sure know that a user can insert more than 1 item(gl account)

1) therefore in bdc_insert where am i going to loop?

2) where r the item (gl account) store in ( i mean the name of the table) ^^

any tips to share^^

thankyou


PERFORM FILL_BDC_TAB.

CALL FUNCTION 'BDC_INSERT'
 EXPORTING
   TCODE                  = 'FB60'
*   POST_LOCAL             = NOVBLOCAL
*   PRINTING               = NOPRINT
*   SIMUBATCH              = ' '
*   CTUPARAMS              = ' '
  TABLES
    DYNPROTAB              = BDC_ITAB
 EXCEPTIONS
   INTERNAL_ERROR         = 1
   NOT_OPEN               = 2
   QUEUE_ERROR            = 3
   TCODE_INVALID          = 4
   PRINTING_INVALID       = 5
   POSTING_INVALID        = 6
   OTHERS                 = 7
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'BDC_CLOSE_GROUP'
 EXCEPTIONS
   NOT_OPEN          = 1
   QUEUE_ERROR       = 2
   OTHERS            = 3
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

    IF SY-SUBRC = 0.
      OUT_RESULT = 'SUCCESS'.
*      MESSAGE s000(ZDBMSG).
    ELSE.
      OUT_RESULT = 'FAIL'.
*      MESSAGE e001(ZDBMSG).
    ENDIF.

ENDFUNCTION.

FORM FILL_BDC_TAB.
  REFRESH BDC_ITAB.

    PERFORM POPULATE_BDC_TAB USING: 'X' 'SAPMF05A' '1100' ,
                                    ' ' 'RF05A-BUSCS' BUSCS ,
                                    ' ' 'INVFO-ACCNT' ACCNT ,
                                    ' ' 'INVFO-BLDAT' BLDAT ,
                                    ' ' 'INVFO-BUDAT' BUDAT ,
                                    ' ' 'INVFO-WRBTR' WRBTR ,
                                    ' ' 'INVFO-WAERS' WAERS ,
                                    ' ' 'ACGL_ITEM-HKONT(01)' HKONT_01 ,
                                    ' ' 'ACGL_ITEM-WRBTR(01)' WRBTR_01 ,
                                    ' ' 'BDC_OKCODE' '=BU'.


ENDFORM.

the code ' ' 'ACGL_ITEM-HKONT(01)' HKONT_01 , <--- the item G/L account

' ' 'ACGL_ITEM-WRBTR(01)' WRBTR_01 <---- amount of the item

this 2 things are at the same row ( row 1)

if i have more the 1 row? and everytime has different number rows.......

what can i do to make it loop?

PLEASE help me PLEASE PLEASE

Edited by: guanwei su on Mar 14, 2008 1:25 AM

Edited by: guanwei su on Mar 14, 2008 1:33 AM

Edited by: guanwei su on Mar 14, 2008 1:34 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
715

Hi,

write code like below

  • Total number of lines in AccountGL segment

DESCRIBE TABLE p_accountgl LINES l_lines.

LOOP AT p_accountgl.

l_row = sy-tabix.

CLEAR: l_tmp_amt, l_wrbtr.

READ TABLE p_currencyamount INDEX l_row.

l_tmp_amt = p_currencyamount-amt_doccur.

l_row1 = 01.

PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

IF l_tmp_amt < 0.

l_tmp_amt = l_tmp_amt * -1.

CONCATENATE 'ACGL_ITEM-SHKZG(' l_row1 ')' INTO l_shkzg.

PERFORM bdc_field USING l_shkzg

'H' .

ELSE.

CONCATENATE 'ACGL_ITEM-SHKZG(' l_row1 ')' INTO l_shkzg.

PERFORM bdc_field USING l_shkzg

'S' .

ENDIF.

WRITE: l_tmp_amt TO l_wrbtr.

CONCATENATE 'ACGL_ITEM-HKONT(' l_row1 ')' INTO l_hkont.

PERFORM bdc_field USING l_hkont

p_accountgl-gl_account .

CONCATENATE 'ACGL_ITEM-WRBTR(' l_row1 ')' INTO l_item_wrbtr.

PERFORM bdc_field USING l_item_wrbtr

l_wrbtr .

IF p_accountgl-costcenter IS NOT INITIAL.

CONCATENATE 'ACGL_ITEM-KOSTL(' l_row1 ')' INTO l_kostl.

PERFORM bdc_field USING l_kostl

p_accountgl-costcenter.

ENDIF.

IF p_accountgl-profit_ctr IS NOT INITIAL.

CONCATENATE 'ACGL_ITEM-PRCTR(' l_row1 ')' INTO l_prctr.

PERFORM bdc_field USING l_prctr

p_accountgl-profit_ctr.

ENDIF.

IF l_lines > l_row.

PERFORM bdc_field USING 'ACGL_ITEM-MARKSP(01)'

'X'.

PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=0005'.

ENDIF.

ENDLOOP.

Thanks

Sekhar

3 REPLIES 3
Read only

Former Member
0 Likes
716

Hi,

write code like below

  • Total number of lines in AccountGL segment

DESCRIBE TABLE p_accountgl LINES l_lines.

LOOP AT p_accountgl.

l_row = sy-tabix.

CLEAR: l_tmp_amt, l_wrbtr.

READ TABLE p_currencyamount INDEX l_row.

l_tmp_amt = p_currencyamount-amt_doccur.

l_row1 = 01.

PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

IF l_tmp_amt < 0.

l_tmp_amt = l_tmp_amt * -1.

CONCATENATE 'ACGL_ITEM-SHKZG(' l_row1 ')' INTO l_shkzg.

PERFORM bdc_field USING l_shkzg

'H' .

ELSE.

CONCATENATE 'ACGL_ITEM-SHKZG(' l_row1 ')' INTO l_shkzg.

PERFORM bdc_field USING l_shkzg

'S' .

ENDIF.

WRITE: l_tmp_amt TO l_wrbtr.

CONCATENATE 'ACGL_ITEM-HKONT(' l_row1 ')' INTO l_hkont.

PERFORM bdc_field USING l_hkont

p_accountgl-gl_account .

CONCATENATE 'ACGL_ITEM-WRBTR(' l_row1 ')' INTO l_item_wrbtr.

PERFORM bdc_field USING l_item_wrbtr

l_wrbtr .

IF p_accountgl-costcenter IS NOT INITIAL.

CONCATENATE 'ACGL_ITEM-KOSTL(' l_row1 ')' INTO l_kostl.

PERFORM bdc_field USING l_kostl

p_accountgl-costcenter.

ENDIF.

IF p_accountgl-profit_ctr IS NOT INITIAL.

CONCATENATE 'ACGL_ITEM-PRCTR(' l_row1 ')' INTO l_prctr.

PERFORM bdc_field USING l_prctr

p_accountgl-profit_ctr.

ENDIF.

IF l_lines > l_row.

PERFORM bdc_field USING 'ACGL_ITEM-MARKSP(01)'

'X'.

PERFORM bdc_dynpro USING 'SAPMF05A' '1100'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=0005'.

ENDIF.

ENDLOOP.

Thanks

Sekhar

Read only

0 Likes
715

HI,

thanks for the code but i still not too understand about some part ^^

p_accountgl and p_currencyamount

this 2 is internal table? and what is the type for this table?

haha sry i try my best still cannot find.

can i have a full sample code? because i scare that later i solve this problem and another problem come and find me T_T.

Thanks,

guanwei

Read only

0 Likes
715

See the following ex: code for handling table control.

Put the header data in one internal table & Line item data in second internal table.

LOOP AT I_TAB1.

REFRESH I_BDCDATA.

CLEAR: I_BDCDATA, G_FL, L_SUBRC.

SET PARAMETER ID 'BUK' FIELD I_TAB1-BUKRS.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'RM08M-VORGANG'

'1'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'INVFO-BLDAT'.

PERFORM BDC_FIELD USING 'INVFO-BLDAT'

I_TAB1-BLDAT.

PERFORM BDC_FIELD USING 'INVFO-XBLNR'

I_TAB1-XBLNR.

PERFORM BDC_FIELD USING 'INVFO-WRBTR'

I_TAB1-AMOUNT.

PERFORM BDC_FIELD USING 'INVFO-WAERS'

I_TAB1-CURR.

PERFORM BDC_FIELD USING 'INVFO-BUPLA'

'BTDS'.

PERFORM BDC_FIELD USING 'INVFO-SECCO'

'BTDS'.

PERFORM BDC_FIELD USING 'INVFO-XMWST'

'X'.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=DUMMY'.

PERFORM BDC_FIELD USING 'INVFO-MWSKZ'

'Z0'.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=HEADER_FI'.

PERFORM BDC_FIELD USING 'RM08M-ITEM_LIST_VERSION'

'7_6310'.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'RM08M-VORGANG'

'1'.

PERFORM BDC_FIELD USING 'INVFO-BKTXT'

I_TAB1-BKTXT.

PERFORM BDC_FIELD USING 'INVFO-GSBER'

I_TAB-BUSAREA.

PERFORM BDC_FIELD USING 'INVFO-LIFRE'

I_TAB1-LIFNR.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'RM08M-XWARE_BNK'.

PERFORM BDC_FIELD USING 'RM08M-EBELN'

I_TAB1-EBELN.

PERFORM BDC_FIELD USING 'RM08M-XWARE_BNK'

'2'.

PERFORM BDC_FIELD USING 'RM08M-ITEM_LIST_VERSION'

'7_6310'.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'HEADER_FI'.

CLEAR: CNT, L_PGD, L_FLG.

***Here you are handling the table control.

LOOP AT I_TAB2 WHERE EBELN = I_TAB1-EBELN.

L_PGD = L_PGD + 1.

CNT = CNT + 1.

REPLACE C WITH CNT INTO QTY.

REPLACE C WITH CNT INTO AMT.

REPLACE C WITH CNT INTO TAX.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

AMT.

PERFORM BDC_FIELD USING QTY

I_TAB2-DMBTR.

PERFORM BDC_FIELD USING AMT

I_TAB2-MENGE.

PERFORM BDC_FIELD USING TAX

'Z0'.

QTY = 'DRSEG-WRBTR(&1)'.

AMT = 'DRSEG-MENGE(&1)'.

TAX = 'DRSEG-MWSKZ(&1)'.

**Page down.

IF L_PGD = 6.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=P+'.

CLEAR L_PGD.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'HEADER_FI'.

CLEAR CNT.

ENDIF.

ENDLOOP.

CLEAR : L_FLG, L_PGD.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_DYNPRO USING 'SAPLMR1M' '6000'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=PARK'.

ENDLOOP.