‎2006 Mar 30 7:21 AM
Hi,
I am looking 2 BAPI's for posting an accounting doc in GL.
BAPI_ACC_DOCUMENT_POST
BAPI_ACC_GL_POSTING_POST
But in the above mentioned BAPI's I dont find any posting key field.
Here my scenario is to use the posting keys 40 and 50 for posting's.
Can any body suggest me how to approach for this.
Thanks in Advance.
Message was edited by: KDeepak
Message was edited by: KDeepak
Message was edited by: KDeepak
‎2006 Mar 31 9:46 AM
Hi
The BAPI_ACC_DOCUMENT_POST allows to post whichever account document, BAPI_ACC_GL_POSTING_POST posts only in G/L accounting area.
Anyway both BAPIs set the posting key automatically, you can't decide which one to be used.
The value of posting key depends on the kind of the item and the sign of amount.
This the routine used to do that:
form fill_acct_key.
data: ld_bschh like accit-bschl,
ld_bschs like accit-bschl,
ld_umskz like accit-umskz.
if not gs_accit-ktosl is initial and
gs_accit-kstat is initial.
call function 'FI_GET_POSTING_KEY'
exporting
i_ktosl = gs_accit-ktosl
importing
e_bschs = ld_bschs
e_bschh = ld_bschh
e_umskz = ld_umskz
exceptions
error_message = 1.
if sy-subrc is initial.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = ld_bschs.
else.
gs_accit-bschl = ld_bschh.
endif.
SHB-Vorgänge HR-Travel mit Ktosl 'HRV'
IF NOT ld_umskz IS INITIAL.
gs_accit-umskz = ld_umskz.
keine Ableitung Zahlungsbedingung für SHB-Vorgänge
CLEAR gs_accit-zterm.
ENDIF.
else.
perform error_from_system
using gs_bapi_accit-parameter
gs_bapi_accit-tabix
'ACCT_KEY'.
endif.
endif.
if gs_accit-bschl is initial.
case gs_accit-koart.
when 'D' or 'V'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '01'.
else.
gs_accit-bschl = '11'.
endif.
when 'K'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '21'.
else.
gs_accit-bschl = '31'.
endif.
when 'S'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '40'.
else.
gs_accit-bschl = '50'.
endif.
when 'A'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '70'.
else.
gs_accit-bschl = '75'.
endif.
when 'M'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '40'.
else.
gs_accit-bschl = '50'.
endif.
endcase.
endif.
if not gs_accit-umskz is initial.
if gs_accit-bschl+1 = '1'.
gs_accit-bschl+1 = '9'.
endif.
endif.
endform. " FILL_ACCT_KEY
So usually:
- Customer Item (field KOART = D):
Posting key are 01 and 11
- Vendor Item (field KOART = K):
Posting key are 21 and 31
- G/L Item (field KOART = S):
Posting key are 40 and 50
So if you have to use only keys 40 and 50 It should means you have to post document only in G/L accounting.
Max
‎2006 Mar 31 9:46 AM
Hi
The BAPI_ACC_DOCUMENT_POST allows to post whichever account document, BAPI_ACC_GL_POSTING_POST posts only in G/L accounting area.
Anyway both BAPIs set the posting key automatically, you can't decide which one to be used.
The value of posting key depends on the kind of the item and the sign of amount.
This the routine used to do that:
form fill_acct_key.
data: ld_bschh like accit-bschl,
ld_bschs like accit-bschl,
ld_umskz like accit-umskz.
if not gs_accit-ktosl is initial and
gs_accit-kstat is initial.
call function 'FI_GET_POSTING_KEY'
exporting
i_ktosl = gs_accit-ktosl
importing
e_bschs = ld_bschs
e_bschh = ld_bschh
e_umskz = ld_umskz
exceptions
error_message = 1.
if sy-subrc is initial.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = ld_bschs.
else.
gs_accit-bschl = ld_bschh.
endif.
SHB-Vorgänge HR-Travel mit Ktosl 'HRV'
IF NOT ld_umskz IS INITIAL.
gs_accit-umskz = ld_umskz.
keine Ableitung Zahlungsbedingung für SHB-Vorgänge
CLEAR gs_accit-zterm.
ENDIF.
else.
perform error_from_system
using gs_bapi_accit-parameter
gs_bapi_accit-tabix
'ACCT_KEY'.
endif.
endif.
if gs_accit-bschl is initial.
case gs_accit-koart.
when 'D' or 'V'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '01'.
else.
gs_accit-bschl = '11'.
endif.
when 'K'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '21'.
else.
gs_accit-bschl = '31'.
endif.
when 'S'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '40'.
else.
gs_accit-bschl = '50'.
endif.
when 'A'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '70'.
else.
gs_accit-bschl = '75'.
endif.
when 'M'.
if gs_accit-shkzg = 'S'.
gs_accit-bschl = '40'.
else.
gs_accit-bschl = '50'.
endif.
endcase.
endif.
if not gs_accit-umskz is initial.
if gs_accit-bschl+1 = '1'.
gs_accit-bschl+1 = '9'.
endif.
endif.
endform. " FILL_ACCT_KEY
So usually:
- Customer Item (field KOART = D):
Posting key are 01 and 11
- Vendor Item (field KOART = K):
Posting key are 21 and 31
- G/L Item (field KOART = S):
Posting key are 40 and 50
So if you have to use only keys 40 and 50 It should means you have to post document only in G/L accounting.
Max
‎2006 Mar 31 9:58 AM
Hi Max,
Thank you once again for the reply.
Could you post the entire code regarding the BAPI.
I mean I want the INPUT fields and how to catch the DOCUMENT NO which was generated.
If possible please send the entire code for posting of Accounting Document in GL area.
Thanks in Advance.
‎2006 Mar 31 11:03 AM
Hi
Here there's a little example:
TABLES: bapiache09.
DATA: t_items LIKE STANDARD TABLE OF bapiacgl09 WITH HEADER LINE,
t_amount LIKE STANDARD TABLE OF bapiaccr09 WITH HEADER LINE,
t_result LIKE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
DATA: belnr TYPE belnr_d,
gjahr TYPE gjahr.
Header Data
bapiache09-comp_code = 'ZN01'.
bapiache09-doc_date = sy-datum.
bapiache09-pstng_date = sy-datum.
bapiache09-doc_type = 'PV'.
bapiache09-ref_doc_no = 'BAPI Test'.
bapiache09-username = sy-uname.
bapiache09-bus_act = 'RFBU'.
First Item
MOVE 1 TO t_items-itemno_acc.
Account number
t_items-gl_account = '0012440130'.
The posting key are 40/50 by default, if you need different keys, set
the transaction business code here: check hits of table T030B to see
the link between transaction and posting keys
*t_items-acct_key = 'ACC'. <----
APPEND t_items.
Second Item
MOVE 2 TO t_items-itemno_acc.
Account number
t_items-gl_account = '0012440140'.
The posting key are 40/50 by default, if you need different keys, set
the transaction business code here: check hits of table T030B to see
the link between transaction and posting keys
*t_items-acct_key = 'ACC'. <----
APPEND t_items.
Set amount
MOVE 1 TO t_amount-itemno_acc.
t_amount-currency = 'EUR'.
MOVE 1000 TO t_amount-amt_doccur.
APPEND t_amount.
MOVE 2 TO t_amount-itemno_acc.
t_amount-currency = 'EUR'.
MOVE 1000 TO t_amount-amt_doccur.
t_amount-amt_doccur = t_amount-amt_doccur * -1.
APPEND t_amount.
check posting
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = bapiache09
TABLES
accountgl = t_items
currencyamount = t_amount
return = t_result.
LOOP AT t_result WHERE ( type = 'E' OR
type = 'A' ).
EXIT.
ENDLOOP.
IF sy-subrc <> 0.
REFRESH t_result.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = bapiache09
TABLES
accountgl = t_items
currencyamount = t_amount
return = t_result.
*
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
Print Message
LOOP AT t_result.
WRITE: t_result-message.
Get Number
IF t_result-id = 'RW' AND
t_result-number = '605'.
belnr = t_result-message_v2(10).
gjahr = t_result-message_v2+14(4).
ENDIF.
ENDLOOP.
I wrote this code in order FI customizing of my system, of course, but I hope it's helpfull for you.
It's important: if you want to use different keys use the field acct_key of item structure (see the table T030B).
Max
‎2006 Mar 31 4:13 PM
Hi Max,
I executed your code it is working fine for me.
But what i found is I was giving some 5 docs at a time to post. The DOC# which is generated is ok. But the BKPF-AWKEY is getting same for all Doc's. But BSEG-ZUONR is getting diff for all.
Could you please tell me what to do to over come this.
In RETURN table I am getting only 1 message if it executed for 1 or MANY Doc's.
In that message only the AWKEY 3 will be there.
Could you suggest me some thing to handle this.
Thanks in advance.
‎2006 Mar 31 4:34 PM
Hi
I the field BKPF-AWKEY should have the key of the document you've created: BELNRBUKRSGJAHR.
The value of ZUONR depends on your FI customizing.
But you can create only one doc by this BAPI, so if you have to create severals docs you have to call it as many times as many docs to be created.
Max
‎2006 Mar 31 4:45 PM
Hi,
You mean if I put this BAPI in side the LOOP is it good in the performance point of view???
I think if I place this BAPI inside the loop then I think I will get giff AWKEY for for diff BELNR.
Now what I am getting is:
BELNR AWKEY
100000001 1000000001IE042006
100000002 1000000001IE042006<<<<<<-----
Like this I am getting.
But I want like this....
BELNR AWKEY
100000001 1000000001IE042006
100000002 1000000002IE042006<<<<<-----
Any suggestions please.
Thanks.
‎2006 Mar 31 5:16 PM
Hi
I changed my code to create three documents:
TABLES: bapiache09, mard.
DATA: t_items LIKE STANDARD TABLE OF bapiacgl09 WITH HEADER LINE,
t_amount LIKE STANDARD TABLE OF bapiaccr09 WITH HEADER LINE,
t_result LIKE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
DATA: belnr TYPE belnr_d,
gjahr TYPE gjahr.
DATA times TYPE n.
DO 3 TIMES.
Header Data
bapiache09-comp_code = 'ZN01'.
bapiache09-doc_date = sy-datum.
bapiache09-pstng_date = sy-datum.
bapiache09-doc_type = 'PV'.
bapiache09-ref_doc_no = 'BAPI Test'.
bapiache09-username = sy-uname.
bapiache09-bus_act = 'RFBU'.
MOVE sy-index TO times.
CONCATENATE 'BAPI TEST N.' times INTO bapiache09-ref_doc_no.
REFRESH t_items.
First Item
MOVE 1 TO t_items-itemno_acc.
Account number
t_items-gl_account = '0012440130'.
The posting key are 40/50 by default, if you need different keys, set
the transaction business code here: check hits of table T030B to see
the link between transaction and posting keys
*accountgl-acct_key = 'ACC'. <----
APPEND t_items.
Second Item
MOVE 2 TO t_items-itemno_acc.
Account number
t_items-gl_account = '0012440140'.
The posting key are 40/50 by default, if you need different keys, set
the transaction business code here: check hits of table T030B to see
the link between transaction and posting keys
*accountgl-acct_key = 'ACC'. <----
APPEND t_items.
REFRESH t_amount.
Set amount
MOVE 1 TO t_amount-itemno_acc.
t_amount-currency = 'EUR'.
MOVE 1000 TO t_amount-amt_doccur.
APPEND t_amount.
MOVE 2 TO t_amount-itemno_acc.
t_amount-currency = 'EUR'.
MOVE 1000 TO t_amount-amt_doccur.
t_amount-amt_doccur = t_amount-amt_doccur * -1.
APPEND t_amount.
REFRESH t_result.
check posting
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = bapiache09
TABLES
accountgl = t_items
currencyamount = t_amount
return = t_result.
LOOP AT t_result WHERE ( type = 'E' OR
type = 'A' ).
EXIT.
ENDLOOP.
IF sy-subrc <> 0.
REFRESH t_result.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = bapiache09
TABLES
accountgl = t_items
currencyamount = t_amount
return = t_result.
*
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
Print Message
LOOP AT t_result.
WRITE: t_result-message.
Get Number
IF t_result-id = 'RW' AND
t_result-number = '605'.
belnr = t_result-message_v2(10).
gjahr = t_result-message_v2+14(4).
ENDIF.
ENDLOOP.
ENDDO.
Just as you can see, I insert my code into DO/ENDO cycle and so I re-call the BAPI three times.
In this situazione I posted document 3 documents and the field AWKEY is correctly filled.
Max