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 get object type and object key from Bapi_acc_gl_posting_post

Former Member
0 Likes
6,473

Hi,

Currently iam implementing FB01 transaction thru Bapi_acc_gl_posting_post.

I got object key by including document no, fiscal year and Document data

I got object type from TTYP table. But iam not sure it is correct.

After implemeting the BAPI return code is giving successfull and i commited the process.

But at last data is not updating in BKPF table. There is no document number displayed at BKPF...Please go thru and do the needful its urgent.

Thanks in advance....

Regards,

Ganga

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,421

Hi

If you have run the BAPI for commit after running Bapi_acc_gl_posting_post it means you're transfering some wrong data.

U should post your code or indicate which object type you're using, in generally it should be RFBU.

Max

Hi,

Currently iam implementing FB01 transaction thru Bapi_acc_gl_posting_post.

I got object key by including document no, fiscal year and Document data

I got object type from TTYP table. But iam not sure it is correct.

After implemeting the BAPI return code is giving successfull and i commited the process.

But at last data is not updating in BKPF table. There is no document number displayed at BKPF...Please go thru and do the needful its urgent.

Thanks in advance....

Regards,

Ganga

10 REPLIES 10
Read only

Former Member
0 Likes
3,422

Hi

If you have run the BAPI for commit after running Bapi_acc_gl_posting_post it means you're transfering some wrong data.

U should post your code or indicate which object type you're using, in generally it should be RFBU.

Max

Read only

0 Likes
3,421

Hi,

Iam sending my code with this mail. and here if i give object type as RFBU its giving error at return code. Please go thru the test code i have given and tell the changes what i have to do for updating in BKPF tables.

Data: gv_belnr type belnr_d.

data:file_na type string.

data: lsys like tbdls-logsys.

data: v_objkey(20) type c.

data: error_occured.

data: documentheader like bapiache08.

data: obj_type like bapiache02-obj_type,

obj_key like bapiache02-obj_key,

obj_sys like bapiache02-obj_sys.

data: accountgl like bapiacgl08 occurs 0 with header line,

currencyamount like bapiaccr08 occurs 0 with header line,

return like bapiret2 occurs 0 with header line.

----


*START OF SELECTION

----


start-of-selection.

call function 'NUMBER_GET_NEXT'

exporting

nr_range_nr = '19'

object = 'RF_BELEG'

quantity = '1'

subobject = '7777'

toyear = '2007'

importing

number = gv_belnr .

call function 'OWN_LOGICAL_SYSTEM_GET'

importing

own_logical_system = lsys .

write: 'The document number is' ,

gv_belnr.

concatenate gv_belnr '7777' '2007' into v_objkey.

*Filling header

documentheader-obj_type = 'BKPFF' .

documentheader-obj_key = v_objkey.

documentheader-obj_sys = lsys.

documentheader-username = sy-uname.

documentheader-comp_code = '7777' .

documentheader-fisc_year = '2007'.

documentheader-doc_date = '20070720' .

documentheader-pstng_date = '20070723'.

documentheader-doc_type = 'KR'.

*Filling Item Data of accountGL

accountgl-itemno_acc = '0000000001'.

accountgl-gl_account = '102'.

accountgl-comp_code = '7777'.

accountgl-pstng_date = '20070724'.

accountgl-doc_type = '20070724' .

accountgl-fisc_year = '2007'.

accountgl-stat_con = 'S'.

append accountgl.

accountgl-itemno_acc = '0000000002'.

accountgl-gl_account = '400001'.

accountgl-comp_code = '7777'.

accountgl-pstng_date = '20070724'.

accountgl-doc_type = '20070724' .

accountgl-fisc_year = '2007'.

accountgl-stat_con = 'H'.

append accountgl.

*Filling Currency table

currencyamount-itemno_acc = '0000000001'.

currencyamount-currency_iso = 'INR'.

currencyamount-amt_doccur = '1000'.

append currencyamount.

currencyamount-itemno_acc = '0000000002'.

currencyamount-currency_iso = 'INR'.

currencyamount-amt_doccur = '100'.

append currencyamount.

call function 'BAPI_ACC_GL_POSTING_POST'

exporting

documentheader = documentheader

importing

obj_type = obj_type

obj_key = obj_key

obj_sys = obj_sys

tables

accountgl = accountgl

currencyamount = currencyamount

return = return

  • EXTENSION1 =

.

if sy-subrc = 0.

call function 'BAPI_TRANSACTION_COMMIT'

exporting

wait = ' '.

.

Read only

0 Likes
3,421

Hi Sun

Try this modifications:

If it's an internal range you haven't to get the number:

<b>*CALL FUNCTION 'NUMBER_GET_NEXT'

  • EXPORTING

  • NR_RANGE_NR = '19'

  • OBJECT = 'RF_BELEG'

  • QUANTITY = '1'

  • SUBOBJECT = '7777'

  • TOYEAR = '2007'

  • IMPORTING

  • NUMBER = GV_BELNR.

*

*

*CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

  • IMPORTING

  • OWN_LOGICAL_SYSTEM = LSYS.

*

*

*WRITE: 'The document number is' ,

*GV_BELNR.

*

*CONCATENATE GV_BELNR '7777' '2007' INTO V_OBJKEY.</b>

*Filling header

DOCUMENTHEADER-OBJ_TYPE = 'RFBU'.

<b>*DOCUMENTHEADER-OBJ_KEY = V_OBJKEY. <--

*DOCUMENTHEADER-OBJ_SYS = LSYS. <--</b>

DOCUMENTHEADER-USERNAME = SY-UNAME.

DOCUMENTHEADER-COMP_CODE = '7777' .

<b>*DOCUMENTHEADER-FISC_YEAR = '2007'. <--</b>

DOCUMENTHEADER-DOC_DATE = '20070720' .

DOCUMENTHEADER-PSTNG_DATE = '20070723'.

DOCUMENTHEADER-DOC_TYPE = 'KR'.

*Filling Item Data of accountGL

ACCOUNTGL-ITEMNO_ACC = '0000000001'.

I suppose your account is 0000000102 and not 102

<b>ACCOUNTGL-GL_ACCOUNT = '0000000102'. <----</b>

ACCOUNTGL-COMP_CODE = '7777'.

ACCOUNTGL-PSTNG_DATE = '20070724'.

ACCOUNTGL-DOC_TYPE = '20070724' .

ACCOUNTGL-FISC_YEAR = '2007'.

The code is setted by the BAPI in order of the sign of the amount, the field STAT_CON is for the statistic and not for the sign

<b>*ACCOUNTGL-STAT_CON = 'S'. <---</b>

APPEND ACCOUNTGL.

ACCOUNTGL-ITEMNO_ACC = '0000000002'.

<b>ACCOUNTGL-GL_ACCOUNT = '0000400001'. <---</b>

ACCOUNTGL-COMP_CODE = '7777'.

ACCOUNTGL-PSTNG_DATE = '20070724'.

ACCOUNTGL-DOC_TYPE = '20070724' .

*ACCOUNTGL-FISC_YEAR = '2007'.

<b>*ACCOUNTGL-STAT_CON = 'H'. <---</b>

APPEND ACCOUNTGL.

*Filling Currency table

<b>The total of the amount has to be ZERO</b>

CURRENCYAMOUNT-ITEMNO_ACC = '0000000001'.

CURRENCYAMOUNT-CURRENCY_ISO = 'INR'.

<b>*CURRENCYAMOUNT-AMT_DOCCUR = '1000'. <------</b>

MOVE 1000 TO CURRENCYAMOUNT-AMT_DOCCUR.

APPEND CURRENCYAMOUNT.

CURRENCYAMOUNT-ITEMNO_ACC = '0000000002'.

CURRENCYAMOUNT-CURRENCY_ISO = 'INR'.

<b>*CURRENCYAMOUNT-AMT_DOCCUR = '100'. <----</b>

MOVE '1000-' TO CURRENCYAMOUNT-AMT_DOCCUR.

APPEND CURRENCYAMOUNT.

Max

Read only

0 Likes
3,421

Thank you very much Max,

I implemented corrected code what u have sent. After execution it is asking for OBJ_KEY and OBJ_SYS.

E |RW |602 |Required field OBJ_KEY was not transferre

E |RW |602 |Required field OBJ_SYS was not transferre

Read only

0 Likes
3,421

Hi

U don't need to transfer the OBJ_TYPE, try this code it works fine for me:

TABLES: BAPIACHE08, BAPIACHE02.

DATA: ACCOUNTGL      LIKE STANDARD TABLE OF BAPIACGL08 WITH HEADER LINE,
      CURRENCYAMOUNT LIKE STANDARD TABLE OF BAPIACCR08 WITH HEADER LINE,
      RETURN         LIKE STANDARD TABLE OF BAPIRET2   WITH HEADER LINE.



*BAPIACHE08-OBJ_TYPE   = 'RFBU'.
BAPIACHE08-HEADER_TXT = 'BAPI'.
BAPIACHE08-COMP_CODE  = 'MAAB'.
BAPIACHE08-DOC_DATE   = SY-DATUM.
BAPIACHE08-PSTNG_DATE = SY-DATUM.
BAPIACHE08-USERNAME   = SY-UNAME.
BAPIACHE08-DOC_TYPE   = 'ZL'.

ACCOUNTGL-ITEMNO_ACC  = '0000000001'.
ACCOUNTGL-GL_ACCOUNT  = '0013250001'.
ACCOUNTGL-BUS_AREA    = 'MA40'.
APPEND ACCOUNTGL.

ACCOUNTGL-ITEMNO_ACC  = '0000000002'.
ACCOUNTGL-GL_ACCOUNT  = '0099999997'.
ACCOUNTGL-BUS_AREA    = 'MA40'.
APPEND ACCOUNTGL.


CURRENCYAMOUNT-ITEMNO_ACC = '0000000001'.
CURRENCYAMOUNT-CURR_TYPE  = '00'.
CURRENCYAMOUNT-CURRENCY   = 'EUR'.
CURRENCYAMOUNT-AMT_DOCCUR = 100.
APPEND CURRENCYAMOUNT.

CURRENCYAMOUNT-ITEMNO_ACC = '0000000002'.
CURRENCYAMOUNT-CURR_TYPE  = '00'.
CURRENCYAMOUNT-CURRENCY   = 'EUR'.
CURRENCYAMOUNT-AMT_DOCCUR = - 100.
APPEND CURRENCYAMOUNT.


CALL FUNCTION 'BAPI_ACC_GL_POSTING_CHECK'
     EXPORTING
          DOCUMENTHEADER = BAPIACHE08
     TABLES
          ACCOUNTGL      = ACCOUNTGL
          CURRENCYAMOUNT = CURRENCYAMOUNT
          RETURN         = RETURN.

LOOP AT RETURN WHERE TYPE = 'E' OR
                     TYPE = 'A'.
  EXIT.
ENDLOOP.
IF SY-SUBRC <> 0.

  CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
       EXPORTING
            DOCUMENTHEADER = BAPIACHE08
       IMPORTING
            OBJ_TYPE       = BAPIACHE02-OBJ_TYPE
            OBJ_KEY        = BAPIACHE02-OBJ_KEY
            OBJ_SYS        = BAPIACHE02-OBJ_SYS
       TABLES
            ACCOUNTGL      = ACCOUNTGL
            CURRENCYAMOUNT = CURRENCYAMOUNT
            RETURN         = RETURN.


  LOOP AT RETURN WHERE TYPE = 'E' OR
                       TYPE = 'A'.
    EXIT.
  ENDLOOP.
  IF SY-SUBRC <> 0.

    WRITE: / 'Object:', BAPIACHE02-OBJ_TYPE,
           / 'Company code:', BAPIACHE02-OBJ_KEY+10(4),
           / 'Doc. nr.:':   , BAPIACHE02-OBJ_KEY(10),
           / 'Fyscal year:' , BAPIACHE02-OBJ_KEY+14(4).


    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
         EXPORTING
              WAIT = ' '.
  ENDIF.
ENDIF.

Max

Read only

0 Likes
3,421

Hi Max,

I have executed it and it is working only for GL posting but i need to make this for different accounting types like vendors, customers, material customers etc.

I found BAPI_ACC_DOCUMENT_POST. when i executed it is giving error as 'Line entered several Times'.

I following is my code. If time permits please go thru my code and do the need ful..

Thanks in advance.

REPORT zk_fi_fb01 .

Data: v_objkey(20) type c.

Data: Docheader type BAPIACHE09.

Data: ACCOUNTGL LIKE BAPIACGL09 occurs 0 with header line,

  • ACCOUNTRECEIVABLE like BAPIACAR09,

ACCOUNTPAYABLE like BAPIACAP09 occurs 0 with header line,

CURRENCYAMOUNT like BAPIACCR09 occurs 0 with header line,

RETURN like BAPIRET2 occurs 0.

Data: obj_typ like BAPIACHE09-OBJ_TYPE,

OBJ_KEY like BAPIACHE09-OBJ_KEY,

OBJ_SYS like BAPIACHE09-OBJ_SYS.

*Data: gv_belnr type belnr_d.

*Data:file_Na type String.

Data: lsys like TBDLS-LOGSYS.

----


*START OF SELECTION

----


START-OF-SELECTION.

*

*CALL FUNCTION 'NUMBER_GET_NEXT'

  • EXPORTING

  • nr_range_nr = '19'

  • object = 'RF_BELEG' "'FIAA-BELNR'

  • QUANTITY = '1'

  • SUBOBJECT = '7777'

  • TOYEAR = '2007'

    • IGNORE_BUFFER = ' '

  • IMPORTING

  • NUMBER = gv_belnr

    • QUANTITY =

    • RETURNCODE =

*.

*CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

  • IMPORTING

  • OWN_LOGICAL_SYSTEM = lsys

    • EXCEPTIONS

    • OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1

    • OTHERS = 2

  • .

*IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*ENDIF.

*

*concatenate gv_belnr '7777' '2007' into v_objkey.

*Filling Document Header Details

*

*Docheader-OBJ_TYPE = 'BEBD'.

*Docheader-OBJ_key = V_objkey.

*Docheader-OBJ_SYS = lsys.

docheader-BUS_ACT = 'RFBU'.

Docheader-USERNAME = sy-uname.

Docheader-COMP_CODE = '7777'.

Docheader-DOC_DATE = '20070724'.

Docheader-PSTNG_DATE = '20070725'.

Docheader-FISC_YEAR = '2007'.

Docheader-DOC_TYPE = 'KZ'.

*Item data for ACCOUNTGL

ACCOUNTGL-ITEMNO_ACC = '0000000001'.

ACCOUNTGL-GL_ACCOUNT = '0000000501'.

ACCOUNTGL-DOC_TYPE = 'KZ'.

ACCOUNTGL-COMP_CODE = '7777'.

ACCOUNTGL-FISC_YEAR = '2007'.

ACCOUNTGL-PSTNG_DATE = '20070725'.

*ACCOUNTGL-DE_CRE_IND = 'S'.

append ACCOUNTGL.

ACCOUNTGL-ITEMNO_ACC = '0000000002'.

ACCOUNTGL-GL_ACCOUNT = '0000400002'.

ACCOUNTGL-DOC_TYPE = 'KR'.

ACCOUNTGL-COMP_CODE = '7777'.

ACCOUNTGL-FISC_YEAR = '2007'.

ACCOUNTGL-PSTNG_DATE = '20070725'.

*ACCOUNTGL-DE_CRE_IND = 'H'.

append ACCOUNTGL.

*Account payable

ACCOUNTPAYABLE-ITEMNO_ACC = '0000000001'.

ACCOUNTPAYABLE-GL_ACCOUNT = '0000000102'.

ACCOUNTPAYABLE-COMP_CODE = '7777'.

append ACCOUNTPAYABLE.

ACCOUNTPAYABLE-ITEMNO_ACC = '0000000002'.

ACCOUNTPAYABLE-GL_ACCOUNT = '0000400002'.

ACCOUNTPAYABLE-COMP_CODE = '7777'.

append ACCOUNTPAYABLE.

*Currency Amount

CURRENCYAMOUNT-ITEMNO_ACC = '0000000001'.

CURRENCYAMOUNT-CURRENCY_ISO = 'INR'.

MOVE 1000 TO CURRENCYAMOUNT-AMT_DOCCUR.

Append CURRENCYAMOUNT.

CURRENCYAMOUNT-ITEMNO_ACC = '0000000002'.

CURRENCYAMOUNT-CURRENCY_ISO = 'INR'.

MOVE '1000-' to CURRENCYAMOUNT-AMT_DOCCUR.

Append CURRENCYAMOUNT.

clear CURRENCYAMOUNT.

clear ACCOUNTGL.

clear ACCOUNTPAYABLE.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = Docheader

  • CUSTOMERCPD =

  • CONTRACTHEADER =

IMPORTING

OBJ_TYPE = obj_typ

OBJ_KEY = obj_key

OBJ_SYS = obj_sys

tables

ACCOUNTGL = ACCOUNTGL[]

  • ACCOUNTRECEIVABLE =

ACCOUNTPAYABLE = ACCOUNTPAYABLE

  • ACCOUNTTAX =

currencyamount = CURRENCYAMOUNT

  • CRITERIA =

  • VALUEFIELD =

  • EXTENSION1 =

return = return.

.

if sy-subrc = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = ' '.

endif.

if sy-subrc = 0.

WRITE: / OBJ_KEY,

OBJ_TYP,

OBJ_SYS.

Read only

0 Likes
3,421

Hi

If you've solved your problem on Bapi_acc_gl_posting_post, you should close this post and open a new one for BAPI BAPI_ACC_DOCUMENT_POST.

Anyway the BAPI Bapi_acc_gl_posting_post posts documents with G/L items only, if you need to post a document for Vendor or Customer it can use the BAPI BAPI_ACC_DOCUMENT_POST.

The G/L Items have to be transfered by structure ACCOUNTGL, customer by ACCOUNTRECEIVABLE and vendor by ACCOUNTPAYABLE.

U need to consider the total of amount of every item has to be ZERO (just as for Bapi_acc_gl_posting_post).

Now I correct your code in order to create a document with one item of GL and one of vendor.

  DOCHEADER-BUS_ACT = 'RFBU'.
  DOCHEADER-USERNAME = SY-UNAME.
  DOCHEADER-COMP_CODE = '7777'.
  DOCHEADER-DOC_DATE = '20070724'.
  DOCHEADER-PSTNG_DATE = '20070725'.
  DOCHEADER-DOC_TYPE = 'KZ'.

*Item data for ACCOUNTGL
  ACCOUNTGL-ITEMNO_ACC = '0000000001'.
  ACCOUNTGL-GL_ACCOUNT = '0000000501'.
  APPEND ACCOUNTGL.

*Account payable
  ACCOUNTPAYABLE-ITEMNO_ACC = '0000000002'.
  ACCOUNTPAYABLE-VENDOR_NO  = '0000000102'. "<---- Vendor Code
  APPEND ACCOUNTPAYABLE.

*Currency Amount
  CURRENCYAMOUNT-ITEMNO_ACC = '0000000001'.
  CURRENCYAMOUNT-CURRENCY_ISO = 'INR'.
  MOVE 1000 TO CURRENCYAMOUNT-AMT_DOCCUR.
  APPEND CURRENCYAMOUNT.

  CURRENCYAMOUNT-ITEMNO_ACC = '0000000002'.
  CURRENCYAMOUNT-CURRENCY_ISO = 'INR'.
  MOVE '1000-' TO CURRENCYAMOUNT-AMT_DOCCUR.
  APPEND CURRENCYAMOUNT.

  CLEAR CURRENCYAMOUNT.
  CLEAR ACCOUNTGL.
  CLEAR ACCOUNTPAYABLE.

  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
       EXPORTING
            DOCUMENTHEADER = DOCHEADER
       IMPORTING
            OBJ_TYPE       = OBJ_TYP
            OBJ_KEY        = OBJ_KEY
            OBJ_SYS        = OBJ_SYS
       TABLES
            ACCOUNTGL      = ACCOUNTGL[]
            ACCOUNTPAYABLE = ACCOUNTPAYABLE
            CURRENCYAMOUNT = CURRENCYAMOUNT
            RETURN         = RETURN.
  .

  IF SY-SUBRC = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
         EXPORTING
              WAIT = ' '.
  ENDIF.

  IF SY-SUBRC = 0.
    WRITE: / OBJ_KEY,
    OBJ_TYP,
    OBJ_SYS.
  ENDIF.

As you can see in my code every time you insert a new item, you need to increase the counter ACCOUNTGL-ITEMNO_ACC and ACCOUNTPAYABLE-ITEMNO_ACC.

If you transfer items with the same counter you'll get the error: 'Line entered several Times'.

Max

Read only

Former Member
0 Likes
3,421

Hi,

When I have tested this BAPI Function Module, I was doing the same by populating OBJECT KEY, OBJECT TYPE and OBJECT SYS.

But when I was writting the code I have not provided OBJECT KEY, OBJECT TYPE and OBJECT SYS.

THIS WILL BE POPULATED BY THE SYSTEM.

Don't give any input to the export parameters of this BAPI Function Module, while writing it from SE38.

It will work fine.

Vijay.

Read only

0 Likes
3,421

Hi Vijayanand,

I tried with your answer with the same program but in the return table iam getting error like object key, type and system not specified. Please tell me about what r all the other inputs i have to give. If u have any sample program of urs please send me. It will be very helpful.

Thanks in advance,

Regards,

Sun.

Read only

mrahhaoui
Participant
0 Likes
3,421

HI I have the same problem but in my case I try to post 2 or 3 documents at the same time.

My question is how to increment automaticly the ITEMNO_ACC. I think that it checks the line item in FAGLGLEXA table and it checks if this line item for this account exist.

Anybody could help me please?

Regards,

Mohamed.