2007 May 17 11:25 AM
Hi,
I'm using RFBIBL00 for posting documents FB01.
How many source files should i need to have. My header values will be constannts always. And there will be 10 line items in each document.so i will have only one source file for 10 line items .
Now how do I get all 10 line items under one document. Actaully my program creates seaparate doc for each line item.
How to link BBKPF and BBSEG structure . Is there any common field which i can use.?
Pls help
Thanks
2007 May 17 2:25 PM
Hi,
Please look into this code, it may be helpful for you. Iam also, having one header and several line items with one invoice posting.
<b>FORM post_inv.
*
*
DATA: w_amount LIKE bsik-wrbtr.
REFRESH tbl_bdcdata.
CLEAR: tbl_bdcdata, w_dat1, w_dat2, w_amt1.
*
Get the header dates in the required format
WRITE: st_header-bldat TO w_dat1,
st_header-budat TO w_dat2.
*
Populate the document header information
PERFORM populate_bdc_tab USING:
'X' 'SAPMF05A' '0100',
' ' 'BKPF-BLDAT' w_dat1,
' ' 'BKPF-BLART' 'K2',
' ' 'BKPF-BUKRS' st_accxref-bukrs,
' ' 'BKPF-BUDAT' w_dat2,
' ' 'BKPF-MONAT' st_header-monat,
' ' 'BKPF-WAERS' st_header-waers,
' ' 'BKPF-XBLNR' st_header-xblnr,
' ' 'BKPF-BKTXT' st_header-bktxt,
' ' 'FS006-DOCID' '*'.
Populate the vendor line
Checking whether it is credit memo or Invoice
CLEAR: w_amt1, w_amount.
IF w_invamt > 0.
MOVE c_31 TO w_bschl1.
ELSE.
MOVE c_21 TO w_bschl1.
ENDIF.
w_amount = abs( w_invamt ).
MOVE w_amount TO w_amt1.
PERFORM populate_bdc_tab USING:
' ' 'RF05A-NEWBS' w_bschl1,
' ' 'RF05A-NEWKO' w_lifnr,
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF05A' '0302',
' ' 'BSEG-WRBTR' w_amt1,
' ' 'BSEG-SGTXT' w_duns,
' ' 'BSEG-ZLSPR' 'A'.
*Loop the table for line item data.
LOOP AT tbl_items.
Get the account X-Reference Information
MOVE sy-tabix TO w_tabix.
CLEAR: tbl_accxref.
READ TABLE tbl_accxref WITH KEY subacct = tbl_items-accno
BINARY SEARCH.
IF sy-subrc NE 0.
MOVE: w_saknr TO tbl_accxref-saknr,
w_bukrs TO tbl_accxref-bukrs,
w_prctr TO tbl_accxref-prctr.
CLEAR: sy-subrc.
ENDIF.
Checking for the posting key to be populated
Checking whether it is credit entry or Debit entry
IF tbl_items-wrbtr > 0.
MOVE c_40 TO w_bschl2.
ELSE.
MOVE c_50 TO w_bschl2.
ENDIF.
*Populating the posting for line item
PERFORM populate_bdc_tab USING:
' ' 'RF05A-NEWBS' w_bschl2,
' ' 'RF05A-NEWKO' tbl_accxref-saknr,
' ' 'RF05A-NEWBK' tbl_accxref-bukrs,
' ' 'BDC_OKCODE' '/00'.
WHILE ( sy-subrc = 0 ).
Fill the individual line items
CLEAR: w_amt1, w_amount.
w_amount = abs( tbl_items-wrbtr ).
MOVE w_amount TO w_amt1.
*
PERFORM populate_bdc_tab USING:
'X' 'SAPMF05A' '0300',
' ' 'BSEG-WRBTR' w_amt1,
' ' 'BSEG-SGTXT' tbl_items-ftext,
' ' 'BSEG-ZUONR' tbl_items-zuonr,
' ' 'BSEG-MEINS' tbl_items-meins.
*populating the Quantity field
IF NOT tbl_items-menge IS INITIAL.
PERFORM populate_bdc_tab USING:
'X' 'SAPMF05A' '0300',
' ' 'BSEG-MENGE' tbl_items-menge.
ENDIF.
Check whether tax codes needs to be populated
SELECT SINGLE mwskz INTO skb1-mwskz FROM skb1
WHERE saknr = tbl_accxref-saknr
AND bukrs = tbl_accxref-bukrs.
IF ( sy-subrc = 0 ) AND NOT ( skb1-mwskz IS INITIAL ).
PERFORM populate_bdc_tab USING:
' ' 'BSEG-MWSKZ' 'U0'.
CLEAR: skb1-mwskz.
ENDIF.
CLEAR: sy-subrc.
Check whether the order number is required
IF NOT ( tbl_accxref-aufnr IS INITIAL ).
PERFORM populate_bdc_tab USING:
' ' 'BDC_OKCODE' '=ZK',
'X' 'SAPLKACB' '0002',
' ' 'COBL-AUFNR' tbl_accxref-aufnr,
' ' 'BDC_OKCODE' '=ENTE',
'X' 'SAPMF05A' '0330'.
Check whether the cost center is required
ELSEIF NOT ( tbl_accxref-kostl IS INITIAL ).
PERFORM populate_bdc_tab USING:
' ' 'BDC_OKCODE' '=ZK',
'X' 'SAPLKACB' '0002',
' ' 'COBL-KOSTL' tbl_accxref-kostl,
' ' 'BDC_OKCODE' '=ENTE',
'X' 'SAPMF05A' '0330'.
Check whether the Profit center is required
ELSEIF NOT ( tbl_accxref-prctr IS INITIAL ).
PERFORM populate_bdc_tab USING:
' ' 'BDC_OKCODE' '=ZK',
'X' 'SAPLKACB' '0002',
' ' 'COBL-PRCTR' tbl_accxref-prctr,
' ' 'BDC_OKCODE' '=ENTE',
'X' 'SAPMF05A' '0330'.
ENDIF.
ADD 1 TO w_tabix.
CLEAR: tbl_items, tbl_accxref. "v_xref1.
READ TABLE tbl_items INDEX w_tabix.
IF sy-subrc = 0.
Get the account X-Reference Information
CLEAR: tbl_accxref.
READ TABLE tbl_accxref WITH KEY subacct = tbl_items-accno
BINARY SEARCH.
IF sy-subrc NE 0.
MOVE: w_saknr TO tbl_accxref-saknr,
w_bukrs TO tbl_accxref-bukrs,
w_prctr TO tbl_accxref-prctr.
CLEAR: sy-subrc.
ENDIF.
*
IF sy-subrc = 0.
*Checking for the posting key to be populated
IF tbl_items-wrbtr > 0.
MOVE c_40 TO w_bschl2.
ELSE.
MOVE c_50 TO w_bschl2.
ENDIF.
*Populating the posting for line item
PERFORM populate_bdc_tab USING:
' ' 'RF05A-NEWBS' w_bschl2,
' ' 'RF05A-NEWKO' tbl_accxref-saknr,
' ' 'RF05A-NEWBK' tbl_accxref-bukrs,
' ' 'BDC_OKCODE' '/00'.
ENDIF.
ENDIF.
ENDWHILE.
EXIT.
ENDLOOP.
Save the document
PERFORM populate_bdc_tab USING:
' ' 'BDC_OKCODE' '=BU'.
Performing the call transaction to post the invoice in the background
and collect the errors, if any while posting.
CALL TRANSACTION 'FB01' USING tbl_bdcdata
MODE 'N'
UPDATE 'S'
MESSAGES INTO tbl_bdc_msg.
IF sy-subrc NE 0.
MOVE sy-subrc TO w_subrc.
ENDIF.
*Moving the error message into a table.
LOOP AT tbl_bdc_msg.
READ TABLE tbl_bdc_msg with key msgtyp = 'E'.
IF tbl_bdc_msg-msgtyp = 'E'.
PERFORM get_text_message.
MOVE tbl_string-w_mstring TO tbl_bdc_error-w_bdc_error.
MOVE tbl_bdc_msg-msgid TO tbl_bdc_error-msgid.
MOVE tbl_bdc_msg-msgnr TO tbl_bdc_error-msgnr.
APPEND tbl_bdc_error.
CLEAR tbl_bdc_error.
ENDIF.
ENDLOOP.
ENDFORM. " post_inv
&----
*& Form populate_bdc_tab
&----
text
----
--> Z_11 *
--> Z_12 *
--> Z_13 *
----
FORM populate_bdc_tab USING z_11
z_12
z_13.
IF z_11 = 'X'.
tbl_bdcdata-program = z_12.
tbl_bdcdata-dynpro = z_13.
tbl_bdcdata-dynbegin = z_11.
ELSE.
tbl_bdcdata-fnam = z_12.
tbl_bdcdata-fval = z_13.
ENDIF.
APPEND tbl_bdcdata.
CLEAR: tbl_bdcdata.
ENDFORM. " populate_bdc_tab
</b>
Thanks
Manju.