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

Bapi to post two FI documents in MB1B.

former_member357236
Participant
0 Likes
1,347

Hi,

I'm trying to create a badi to post two FI documents. I'm using CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'. I'm getting following error in this.

Please help me to resolve this issue.

LOOP AT ZTABLE INTO WA_ZTABLE.

       documentheader-username = sy-uname.

       documentheader-header_txt = 'Test using BAPI'.

       documentheader-comp_code = 'M000'.

       documentheader-doc_date = wa_ztable-CPUDT_MKPF.

       documentheader-pstng_date = wa_ztable-BUDAT_MKPF.

       documentheader-doc_type = 'SA'.

       e_accountgl-itemno_acc = '1'.

*      e_accountgl-gl_account = '410003'.

       e_accountgl-gl_account = gl_account1.

       e_accountgl-comp_code = 'M000'.

       e_accountgl-pstng_date = wa_ztable-BUDAT_MKPF.

       e_accountgl-doc_type = 'SA'.

       e_accountgl-ITEM_TEXT = text1.

       e_accountgl-BUS_AREA = 'W***'.

       APPEND e_accountgl to accountgl.

       e_accountgl-itemno_acc = '2'.

       e_accountgl-gl_account = gl_account2.

       e_accountgl-comp_code = 'M000'.

       e_accountgl-pstng_date = wa_ztable-BUDAT_MKPF.

       e_accountgl-doc_type = 'SA'.

       e_accountgl-ITEM_TEXT = text1.

       e_accountgl-BUS_AREA = 'H000'.

       APPEND e_accountgl to accountgl.

       e_currencyamount-itemno_acc = '1'.

       e_currencyamount-currency = 'INR'.

       e_currencyamount-amt_doccur = amount.

       APPEND e_currencyamount to currencyamount.

       e_currencyamount-itemno_acc = '2'.

       e_currencyamount-currency = 'INR'.

       e_currencyamount-amt_doccur = - amount.

       APPEND e_currencyamount to currencyamount.

*      call BAPI-function in this system.

       CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'

         EXPORTING

           documentheader       = documentheader

*       IMPORTING

*         OBJ_TYPE             =

*         OBJ_KEY              =

*         OBJ_SYS              =

         tables

           accountgl            = accountgl

           currencyamount       = currencyamount

           RETURN               = return

          EXTENSION1            = extension1

                 .

           CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

            EXPORTING

              WAIT          = 'X'.

         IMPORTING

          RETURN        = return

                 .

       WRITE: /'BAPI cal worked'.

Hi,

I'm trying to create a badi to post two FI documents. I'm using CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'. I'm getting following error in this.

Please help me to resolve this issue.

LOOP AT ZTABLE INTO WA_ZTABLE.

       documentheader-username = sy-uname.

       documentheader-header_txt = 'Test using BAPI'.

       documentheader-comp_code = 'M000'.

       documentheader-doc_date = wa_ztable-CPUDT_MKPF.

       documentheader-pstng_date = wa_ztable-BUDAT_MKPF.

       documentheader-doc_type = 'SA'.

       e_accountgl-itemno_acc = '1'.

*      e_accountgl-gl_account = '410003'.

       e_accountgl-gl_account = gl_account1.

       e_accountgl-comp_code = 'M000'.

       e_accountgl-pstng_date = wa_ztable-BUDAT_MKPF.

       e_accountgl-doc_type = 'SA'.

       e_accountgl-ITEM_TEXT = text1.

       e_accountgl-BUS_AREA = 'W***'.

       APPEND e_accountgl to accountgl.

       e_accountgl-itemno_acc = '2'.

       e_accountgl-gl_account = gl_account2.

       e_accountgl-comp_code = 'M000'.

       e_accountgl-pstng_date = wa_ztable-BUDAT_MKPF.

       e_accountgl-doc_type = 'SA'.

       e_accountgl-ITEM_TEXT = text1.

       e_accountgl-BUS_AREA = 'H000'.

       APPEND e_accountgl to accountgl.

       e_currencyamount-itemno_acc = '1'.

       e_currencyamount-currency = 'INR'.

       e_currencyamount-amt_doccur = amount.

       APPEND e_currencyamount to currencyamount.

       e_currencyamount-itemno_acc = '2'.

       e_currencyamount-currency = 'INR'.

       e_currencyamount-amt_doccur = - amount.

       APPEND e_currencyamount to currencyamount.

*      call BAPI-function in this system.

       CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'

         EXPORTING

           documentheader       = documentheader

*       IMPORTING

*         OBJ_TYPE             =

*         OBJ_KEY              =

*         OBJ_SYS              =

         tables

           accountgl            = accountgl

           currencyamount       = currencyamount

           RETURN               = return

          EXTENSION1            = extension1

                 .

           CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

            EXPORTING

              WAIT          = 'X'.

         IMPORTING

          RETURN        = return

                 .

       WRITE: /'BAPI cal worked'.

7 REPLIES 7
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,304

Hi Gopi

Can you please explain in detail your issue. What exactly is the error you are getting and what you are trying to achieve

Nabheet

Read only

0 Likes
1,304

Hi Madan,

I'm trying to create a badi for t-code MB1B.... while doing a material to material transfer a document will be created. Using that document details, i need to post FI document. so i'm using the
FM-BAPI_ACC_GL_POSTING_POST. I'm getting the below error.

Read only

0 Likes
1,304

This is happening because you are using commit work inside BADI.... please comment commit work and check

Which BADI/exit are you using for the same

Nabheet

Read only

Former Member
0 Likes
1,304

Hi Gopi,

What Error are you getting?

-Sowmya

Read only

Former Member
0 Likes
1,304

Hi,

It seems you are trying to put commit work statement inside Update task. System throws a dump when you put commit work statement inside update function module. 

Remove the statement

   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

            EXPORTING

              WAIT          = 'X'.

         IMPORTING

          RETURN        = return

                 .

       WRITE: /'BAPI cal worked'.



You can separately add the FI document after the material document is created. By calling :


1) BAPI   CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'  in background task  in the exit.


2)  Or create a wrapper FM . Call that FM in starting new task. Use  while and wait statement to check whether document exists in the database (MKPF). If yes, call the BAPI 'BAPI_ACC_GL_POSTING_POST'. Disadvantage of this process is that , it  opens a new session. If number of open session is more than 6-7( maintained in profile parameter) update fails.



Regards,

DPM

Read only

Former Member
0 Likes
1,304

Hi Gopi,

The problem is with BAPI_TRANSACTION_COMMIT. You are not passing the import/export parameters properly.

Check Your code as you are using a period at Export statement.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

            EXPORTING

              WAIT          = 'X'. (Remove the dot)

         IMPORTING

          RETURN        = return.


Regards,

K.Srikanth Reddy.

Read only

eduardo_hinojosa
Active Contributor
0 Likes
1,304

Hi

Where are you calling the BAPI from? I believe you are using a BADI (maybe, MB_DOCUMENT_BADI?). See SAP Note 968812 - MM/FI Difference for material stocks and SAP Note 1315985 - FAQ: BAdI MB_DOCUMENT_BADI.

Maybe you can call the same program with option IN UPDATE TASK (encapsulate it in a function module) and inside it with a job (with the sequence JOB_OPEN, RS_CREATE_VARIANT, JOB_SUBMIT and JOB_CLOSE) some time after good movement.

I hope this helps you

Regards

Eduardo