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

BDC Session method to upload FB01 transaction

Former Member
0 Likes
2,041

Hi Gurus,

I have to write a BDC Session method program for FB01 Transaction through a tab limited file.

The file format consist of Header and Items. The first field is an indicator. H for Header and L1 for Debit Entry line item, L2 for Credit Entry line item.

If Debit is equal to Credit document should be posted.

Please send me the code,its very urgent.

Thanks,

Ramdeep

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,584

Hi,

Before writing a BDC for FB01 please explore other possibilites such as BAPI.

As this transaction checks for lot many parameter and it is the all in one transaction of FI , it is better not to write a BDC as you may end up with writing a very big code with lots of validations.

Regards,

Atish

Hi Gurus,

I have to write a BDC Session method program for FB01 Transaction through a tab limited file.

The file format consist of Header and Items. The first field is an indicator. H for Header and L1 for Debit Entry line item, L2 for Credit Entry line item.

If Debit is equal to Credit document should be posted.

Please send me the code,its very urgent.

Thanks,

Ramdeep

5 REPLIES 5
Read only

Former Member
0 Likes
1,584

Hi,

Create the BDC data using the transaction SHDB and use that in your program..

OR

Call the BAPI BAPI_ACC_DOCUMENT_POST by passing the values to the parameters...

Thanks,

Naren

Read only

Former Member
0 Likes
1,584

Hai,

Here is the code for FB01. This code will automatically identifies the Credit memo as well as invoice. Make some changes according to your logic. Its working perfectly fine and moved to live also.

<b>*

*

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' w_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.

*populating the UOM

IF NOT tbl_items-meins IS INITIAL.

PERFORM populate_bdc_tab USING:

'X' 'SAPMF05A' '0300',

' ' 'BSEG-MEINS' tbl_items-meins.

ENDIF.

  • ' ' '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.

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.

Reward if helpful.

Read only

Former Member
0 Likes
1,585

Hi,

Before writing a BDC for FB01 please explore other possibilites such as BAPI.

As this transaction checks for lot many parameter and it is the all in one transaction of FI , it is better not to write a BDC as you may end up with writing a very big code with lots of validations.

Regards,

Atish

Read only

Former Member
0 Likes
1,584

Use standard batch-input program RFBIBL00.

Read only

Former Member
0 Likes
1,584

SOLVED MY MYSELF