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

Problem Using BAPI_ACC_DOCUMENT_POST

Former Member
0 Likes
1,501

Hi All:

I've been trying to use the bapi BAPI_ACC_DOCUMENT_POST to post the G/L accounts. It works fine for posting one document number. But in the file I have multiple documents with a numbric sequence.

How do I make the Bapi read and post based on this indicator?

For example

If we have a file like

TNO Doc Date doctype ... .... . . ...

1 01012008 SA

1 01012008 SA

1 01012008 SA

1 01012008 SA

2 01012008 SA

2 01012008 SA

3 01012008 SA

3 01012008 SA

3 01012008 SA

3 01012008 SA

How do I split the file for each document based on TNO? If the TNO is 1 this is one document, if it is 2 then this is another document and so on ...

Any help is greatly appreciated.

Thanks

Venkat

10 REPLIES 10
Read only

former_member189629
Active Contributor
0 Likes
1,247

Hey,

The data you show is redundant (I don't see a sequence - linhe 1-4 are same) . Try deleing adjacent duplicates from the internal table and post.

OR

If each line is unique, club all records for ex. of TNO1 into one line

Edited by: NW on Aug 6, 2008 1:29 PM

Edited by: NW on Aug 6, 2008 1:30 PM

Read only

0 Likes
1,247

It's just that the data for TNO = 1 is one document with multiple line items as Credit or Debit.

We want to do the posting individually by document.

Thanks

Venkata

Read only

0 Likes
1,247

Oh, excuse me. You will have to split the header and item data and populate items into whichever of the below is relevant for your items in the TABLES section of the BAPI call

ACCOUNTGL G/L account item

ACCOUNTRECEIVABLE Customer Item

ACCOUNTPAYABLE Vendor Item

ACCOUNTTAX Tax item

CURRENCYAMOUNT Currency Items

Read only

0 Likes
1,247

That works fine but the problem is I'm not able to split the file into different documents.

Thanks

Venkat

Read only

0 Likes
1,247

please paste a few full lines from ur utab...

Read only

0 Likes
1,247

LOOP AT ITAB_INDATA.

*Skip the first line item.

IF SY-TABIX = 1.

CONTINUE.

ENDIF.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

DATE_EXTERNAL = ITAB_INDATA-PDATE

IMPORTING

DATE_INTERNAL = ITAB_INDATA-PDATE

EXCEPTIONS

DATE_EXTERNAL_IS_INVALID = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

RETURN.

ENDIF.

  • Fill Document Header

DOC_HEADER-USERNAME = SY-UNAME.

DOC_HEADER-COMP_CODE = 'BP01'.

DOC_HEADER-HEADER_TXT = ITAB_INDATA-BKTXT.

DOC_HEADER-REF_DOC_NO = ITAB_INDATA-XBLNR.

DOC_HEADER-DOC_DATE = ITAB_INDATA-DDATE.

DOC_HEADER-PSTNG_DATE = ITAB_INDATA-PDATE.

DOC_HEADER-DOC_TYPE = ITAB_INDATA-BLART.

ADD 1 TO COUNT.

MOVE COUNT TO DOC_ITEM-ITEMNO_ACC.

MOVE COUNT TO VENDOR-ITEMNO_ACC.

MOVE COUNT TO DOC_VALUES-ITEMNO_ACC.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

DATE_EXTERNAL = DOC_HEADER-DOC_DATE

IMPORTING

DATE_INTERNAL = DOC_HEADER-DOC_DATE

EXCEPTIONS

DATE_EXTERNAL_IS_INVALID = 1

OTHERS = 2.

IF SY-SUBRC <> 0.

RETURN.

ENDIF.

IF ITAB_INDATA-ACTYP ='S'.

    • Fill Line 1 of Document Item

    • DOC_ITEM-ITEMNO_ACC = ITAB_INDATA-NEWBS.

DOC_ITEM-GL_ACCOUNT = ITAB_INDATA-GLACC.

DOC_ITEM-PSTNG_DATE = ITAB_INDATA-PDATE.

DOC_ITEM-DOC_TYPE = ITAB_INDATA-BLART.

DOC_ITEM-PROFIT_CTR = ITAB_INDATA-PC.

DOC_ITEM-ALLOC_NMBR = ITAB_INDATA-ASSGN.

DOC_ITEM-ITEM_TEXT = ITAB_INDATA-TEXT.

DOC_ITEM-COSTCENTER = ITAB_INDATA-CC.

DOC_ITEM-ACCT_TYPE = ITAB_INDATA-ACTYP.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = DOC_ITEM-GL_ACCOUNT

IMPORTING

OUTPUT = DOC_ITEM-GL_ACCOUNT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = DOC_ITEM-VENDOR_NO

IMPORTING

OUTPUT = DOC_ITEM-VENDOR_NO.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = DOC_ITEM-COSTCENTER

IMPORTING

OUTPUT = DOC_ITEM-COSTCENTER.

APPEND DOC_ITEM.

CLEAR DOC_ITEM.

ELSEIF ITAB_INDATA-ACTYP = 'K'.

  • VENDOR-PROFIT_CTR = ITAB_INDATA-PC.

VENDOR-VENDOR_NO = ITAB_INDATA-GLACC.

VENDOR-ALLOC_NMBR = ITAB_INDATA-ASSGN.

VENDOR-ITEM_TEXT = ITAB_INDATA-TEXT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = VENDOR-VENDOR_NO

IMPORTING

OUTPUT = VENDOR-VENDOR_NO.

APPEND VENDOR.

CLEAR VENDOR.

ELSEIF ITAB_INDATA-ACTYP = 'D'.

CUSTOMER-CUSTOMER = ITAB_INDATA-GLACC.

CUSTOMER-ALLOC_NMBR = ITAB_INDATA-ASSGN.

CUSTOMER-ITEM_TEXT = ITAB_INDATA-TEXT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = CUSTOMER-CUSTOMER

IMPORTING

OUTPUT = CUSTOMER-CUSTOMER.

APPEND CUSTOMER.

CLEAR CUSTOMER.

ENDIF.

APPEND ITAB_INDATA.

DOC_VALUES-CURRENCY_ISO = 'USD'.

IF ITAB_INDATA-CRAMT IS NOT INITIAL AND ITAB_INDATA-DRAMT IS INITIAL.

DOC_VALUES-AMT_DOCCUR = ITAB_INDATA-CRAMT.

ENDIF.

IF ITAB_INDATA-CRAMT IS INITIAL AND ITAB_INDATA-DRAMT IS NOT INITIAL.

ITAB_INDATA-DRAMT = ( -1 * ITAB_INDATA-DRAMT ).

DOC_VALUES-AMT_DOCCUR = ITAB_INDATA-DRAMT.

ENDIF.

APPEND DOC_VALUES.

CLEAR DOC_VALUES.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

DOCUMENTHEADER = DOC_HEADER

TABLES

ACCOUNTGL = DOC_ITEM

ACCOUNTRECEIVABLE = CUSTOMER

ACCOUNTPAYABLE = VENDOR

  • ACCOUNTTAX =

CURRENCYAMOUNT = DOC_VALUES

  • CRITERIA =

  • VALUEFIELD =

  • EXTENSION1 =

RETURN = RETURN.

Read only

0 Likes
1,247

hey,

sorry i meant please paste a few full lines from ur itab...

from your code i understand that you are identifying items ITAB_INDATA-ACTYP.

Now split this iformation for ITAB_INDATA-ACTYP ='S' and 'K' to separate internal tables for Doc item, customer and Vendor items and assign individually

loop at itab_header

  • populate header data

read itab_item with key XYZ = itab_header-XYZ

  • populate item data

read itab_cust with key XYZ = itab_header-XYZ

  • populate customer data

read itab_vend with key XYZ = itab_header-XYZ

  • populate vendor data

endloop

OR

have all items in 1 itab

loop at itab_header

  • populate header data

loop at it_item where key = itab_header-key

case it_item-ACTYP.

when 'S'.

  • populate item data

when ... and so on

endcase.

endloop.

endloop

Edited by: NW on Aug 6, 2008 3:42 PM

Read only

0 Likes
1,247

But my file format doesn't have multiple headers. This is the file format.

Trx # Document Dt Posting Dt Document Type Reference Doc Hdr Text Posting key Account Type Account Dr Amount Cr Amount Cost Ctr Profit Ctr Assignment Text

1 08012008 08012008 KR 31 K 300015 1000

1 08012008 08012008 KR 40 S 654000 500 1101

1 08012008 08012008 KR 40 S 654000 500 1101

2 08012008 08012008 KR 31 K 300015 1000

2 08012008 08012008 KR 40 S 654000 500 1101

2 08012008 08012008 KR 40 S 654000

500 1101

Thanks

Venkat

Read only

0 Likes
1,247

Well i din mean multiple headers either. Anyways, try using a CASE in your existing loop on ITAB_INDATA-ACTYP and populate accordingly

Read only

0 Likes
1,247

My code work fine, the only problem there is is that it appends all the records into one document.

It has to post seperate documnents based on the first field.

If it is 1 for the first 3 records, then all these will be posted in one document.

If it is 2 for the next 4 records, then all these will be posted in one document. and so on...

This is the problem I'm having.

Thanks

Venkat