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_ACC_GL_POSTING_POST set Posting Key

Former Member
0 Kudos
6,147

dear all

i am new to this,

i want to create a document using tCode: F-02

i used this BAPI: BAPI_ACC_GL_POSTING_POST

now i want to set the "Posting Key" for every line in the document.

people on the internet are saying, use: "EXTENSION1".

but i don't know what the fields mean.

so please i need an example to set the "posting Key"

thanks,

1 ACCEPTED SOLUTION
Read only

sunil_mani
Active Participant
0 Kudos
3,624

Hi Ramzy,

     Please write the following code.

Step 1: Populate structure extension as below in your program.

Field1 in extension should POSNR ( Line item number ), Field2 should be field name, in your case, it will be BSCHL, Field3 should posting key.

           lst_extension1-field1 l_item_no.
           lst_extension1-field2 =  'BSCHL'
           lst_extension1-field3 =  '40'.
           APPEND lst_extension1 TO li_extension1.


Step2: Go inside your BAPI  BAPI_ACC_GL_POSTING_POST, you will find a user exit as below screenshot.

       


Go inside this perform you will find function exit EXIT_SAPLACC4_001. Create a project from CMOD and write following inside the z include.

LOOP AT extension.
* Determine line item
   READ TABLE t_accit WITH KEY posnr = extension-field1.
   IF sy-subrc IS INITIAL.
* Determine posting key
     IF extension-field3 IS NOT INITIAL AND
        extension-field2 = 'BSCHL'.       
*     Update the line item with posting key
       t_accit-bschl = '40'.
       MODIFY t_accit INDEX sy-tabix.
     ENDIF.


Hope this helps for you.

15 REPLIES 15
Read only

Former Member
0 Kudos
3,624

Hi,

Posting key can be passed by passing -Ve  value (for debit posting key), +ve value (for credit posting key ) to the field   CURRENCYAMOUNT-AMT_DOCCUR.

Regards

Read only

0 Kudos
3,624

thanks for your reply, but i want to set specific "Posting key".

thanks,

Read only

0 Kudos
3,624

Hi,

I hope you wanted to pass either debit posting key or credit posting key for each line item.

In that case, for a line item if you want to set debit posting key multiply the value of  AMT_DOCCUR with -1 other wise pass the value with out multiplying with -1.


Regards,

Read only

0 Kudos
3,624

how can i change the Posting Key ?

Read only

RaymondGiuseppi
Active Contributor
0 Kudos
3,624

That is not possible (AFAIK) with this GL BAPI (40/50 only determined from sign of amount) without playing with EXTENSION parameters and BAdI implementation.

So try using BAPI_ACC_DOCUMENT_POST.

Regards,

Raymond

Read only

0 Kudos
3,624

if i use "BAPI_ACC_DOCUMENT_POST" ? then i can change the Posting Key?

what about "Extension1" in BAPI_ACC_GL_POSTING_POST ?

Read only

0 Kudos
3,624

Read the parameter documentation, you will have to implement enhancement SMOD ACBAPI01 thru CMOD transaction. (Use search tool for samples)

Regards,

Raymond

PS: I removed the BAdI ACC_DOCUMENT, seems only called by BAPI_ACC_DOCUMENT_POST and not by old BAPI_ACC_GL_POSTING_POST.

Read only

sunil_mani
Active Participant
0 Kudos
3,625

Hi Ramzy,

     Please write the following code.

Step 1: Populate structure extension as below in your program.

Field1 in extension should POSNR ( Line item number ), Field2 should be field name, in your case, it will be BSCHL, Field3 should posting key.

           lst_extension1-field1 l_item_no.
           lst_extension1-field2 =  'BSCHL'
           lst_extension1-field3 =  '40'.
           APPEND lst_extension1 TO li_extension1.


Step2: Go inside your BAPI  BAPI_ACC_GL_POSTING_POST, you will find a user exit as below screenshot.

       


Go inside this perform you will find function exit EXIT_SAPLACC4_001. Create a project from CMOD and write following inside the z include.

LOOP AT extension.
* Determine line item
   READ TABLE t_accit WITH KEY posnr = extension-field1.
   IF sy-subrc IS INITIAL.
* Determine posting key
     IF extension-field3 IS NOT INITIAL AND
        extension-field2 = 'BSCHL'.       
*     Update the line item with posting key
       t_accit-bschl = '40'.
       MODIFY t_accit INDEX sy-tabix.
     ENDIF.


Hope this helps for you.

Read only

0 Kudos
3,624

i want to thank you for your reply, but when i try to edit the function  "EXIT_SAPLACC4_001"

it asks me for Access key, i already have one but it is not working ?

do you have any idea ?

thanks ,

Read only

0 Kudos
3,624

HI Ramzy,

The below thread might help how to write the code in the include. Please do follow the steps and let me know if you need further assitance.

Thanks

Read only

0 Kudos
3,624

HI Ramzy,

The below thread might help how to write the code in the include. Please do follow the steps and let me know if you need further assitance.

User exit asking for access key in CMOD

Thanks

Read only

0 Kudos
2,287

thank you ..its helpful ..

Read only

atul_mohanty
Active Contributor
0 Kudos
3,624

Hi Ramzy -

Please check the below link, details are avaialble using BAPI_ACC_DOCUMENT_POST and the extension and the BADI ACC_DOCUMENT ( method - Change)

http://scn.sap.com/message/14643146#14643146

Let us know in case any further help

Regards,

Atul Mohanty

Read only

0 Kudos
3,624

thanks

but i am creating this document for customer.

so it gives me this error: "Account 1250701 in company code 2000 cannot be directly posted to"

and i didnt pass the GL account it give me error you musr set the GL Account.

FYI, i didit by my hand from the screen F-02 and it is working very good.

here is the sample of my code:

                                     ("ITEMNO_ACC", "1");

                table.SetValue("CUSTOMER", "241");

                table.SetValue("GL_ACCOUNT", "0001250701");

Read only

0 Kudos
3,624

Please close the thread if you got the answer.