‎2005 Sep 28 12:49 PM
Hi
I want to use the bapi_acc_document_post to create accounting documents. I have used the following code in order to test the funcitonality.
[code]&----
*& Report ZZBAPI *
&----
REPORT zzbapi.
DATA: l_bkpf TYPE bapiache09,
l_obj_type TYPE bapiache02-obj_type,
l_obj_key TYPE bapiache02-obj_key,
l_obj_sys TYPE bapiache02-obj_sys.
DATA: t_return TYPE STANDARD TABLE OF bapiret2,
t_bseg TYPE STANDARD TABLE OF bapiacgl09,
t_value TYPE STANDARD TABLE OF bapiaccr09,
w_return LIKE bapiret2.
DATA: w_value TYPE bapiaccr09,
w_return2 TYPE bapiret2,
w_bseg TYPE bapiacgl09.
START-OF-SELECTION.
l_bkpf-obj_type = 'BKPFF'.
l_bkpf-obj_sys = 'DEV101'.
l_bkpf-obj_key = '$'.
l_bkpf-username = sy-uname.
l_bkpf-comp_code = '1000'.
l_bkpf-bus_act = 'RFBU'.
l_bkpf-header_txt = 'BAPI TEST'.
l_bkpf-fisc_year = '2005'.
l_bkpf-doc_date = sy-datum.
l_bkpf-pstng_date = sy-datum.
l_bkpf-fis_period = sy-datum+4(2).
l_bkpf-doc_type = 'DC'.
CLEAR: w_bseg.
w_bseg-itemno_acc = 1.
w_bseg-gl_account = '0000012350'.
w_bseg-comp_code = '1000'.
w_bseg-pstng_date = sy-datum.
w_bseg-doc_type = 'DC'.
w_bseg-fisc_year = sy-datum+0(4).
w_bseg-fis_period = sy-datum+4(2).
w_bseg-stat_con = 'S'.
INSERT w_bseg INTO TABLE t_bseg.
CLEAR: w_bseg.
w_bseg-itemno_acc = 2.
w_bseg-gl_account = '0000790500'.
w_bseg-comp_code = '1000'.
w_bseg-pstng_date = sy-datum.
w_bseg-doc_type = 'DC'.
w_bseg-fisc_year = sy-datum+0(4).
w_bseg-fis_period = sy-datum+4(2).
w_bseg-stat_con = 'H'.
INSERT w_bseg INTO TABLE t_bseg.
CLEAR: w_value.
w_value-itemno_acc = 1.
w_value-currency_iso = 'EUR'.
w_value-amt_doccur = 1000.
w_value-amt_base = 1000.
INSERT w_value INTO TABLE t_value.
CLEAR: w_value.
w_value-itemno_acc = 2.
w_value-currency_iso = 'EUR'.
w_value-amt_doccur = 1000.
w_value-amt_base = 1000.
INSERT w_value INTO TABLE t_value.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = l_bkpf
IMPORTING
obj_type = l_obj_type
obj_key = l_obj_key
obj_sys = l_obj_sys
TABLES
accountgl = t_bseg
currencyamount = t_value
return = t_return.
LOOP AT t_return INTO w_return.
WRITE : /1 w_return-message.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = ' '.
[/code]
The message printed on the screen look promissing :
[code]Document correct posted: BKPFF 000120001610002005 DEV101
[/code]
But when I look in the BKPF or VBKPF table there is no entry created. I know there are many items in the forum about the BAPI's to create financial postings, but I have not been able to find a good solution.
So if someone can help me with a solution I'll be happy.
Kind regards,
Ronald Groennou.
‎2005 Sep 28 11:35 PM
Roland,
This is a long shot but try commenting out the following lines:
l_bkpf-obj_type = 'BKPFF'.
l_bkpf-obj_sys = 'DEV101'.
l_bkpf-obj_key = '$'.
I have used this BAPI and I never populate these values.
Also when you are putting in the Fiscal Year and Fiscal Period, they may not always match up the month and year of the date (this is determined via your fiscal year variant). Try using FM FTI_FISCAL_YEAR_MONTH_GET and pass in your Company Code and Date.
Hope this helps.
Cheers,
Pat.
PS. Kindly assign Reward Points tot he posts you find helpful.
‎2005 Sep 28 12:53 PM
Hi
Perhaps this BAPI doesn't run the commit, so you should call the BAPI_TRANSACTION_COMMIT for to do it.
Max
Message was edited by: max bianchi
‎2005 Sep 28 12:54 PM
Hi,
You can also write the COMMIT WORK statement after calling the BAPI.
Regards
Abhishek
‎2005 Sep 28 12:55 PM
I use at the end of the code the BAPI_TRANSACTION_COMMIT. I have tried it with and without wait. Also the commit work has been tried.
‎2005 Sep 28 3:15 PM
Ronald - try doing the commit like this:
data myret like bapiret2.
call function 'BAPI_TRANSACTION_COMMIT'
importing
return = myret
Then see what's in myret.
Rob
‎2005 Sep 29 11:30 AM
Rob,
in I have added the code you suggested, but the structure MYRET is blanc after the commit.
Someone else any other suggestions. Or is there someone who is able to post financial documents with the BAPI_ACC_DOCUMENT_POST?
Kind regards,
Ronald Groennou.
‎2005 Sep 29 12:17 PM
Hi Ronald,
I think you are missing a field called DE_CRE_IND which is debit credit indicator of structure BAPIACGL09. You are using field STAT_CON for debit credit. Try DE_CRE_IND instead of STAT_CON.
Regards,
Vin
‎2005 Sep 29 12:35 PM
Hi Vinayak,
after the modification I get the following error :
[code]
Error in document: BKPFF $ DEV101
Balance in transaction currency
[/code]
‎2005 Sep 29 12:59 PM
Humm,
I think this is the total balance of the account post which isn't equal to 0.
Do u have tax lines ? Do you fill them correctly ?
regards,
Erwan.
‎2005 Sep 29 2:15 PM
Hi Erwan,
the posting is in the GL and there is no tax related to this booking. I have also tried to add the tax structure but without result.
I am more and more wondering if the BAPI itself is working correctly.
Kind regards,
Ronald.
‎2005 Sep 29 2:57 PM
You say nothing is BKPF. How do you know? What select statement are you using. Try selecting where the creation date (CPUDT) is today (or yesterday). It might take a while, but it might prove instructive.
Rob
‎2005 Sep 30 7:51 AM
Hello Rob,
I have looked in BKPF and VBKBF (parked documents) if there is an entry for the CPU date, the retuned documentnumber and so on. I have even checked if the total rows in the BKPF and VBKPF tables are increased after the posting. And also no.
‎2005 Sep 30 3:10 PM
Very peculiar - if you get a message that the document was posted and do a commit that returns no errors, then a document was posted. A couple of things you can do:
After executing the bapi, what are in the importing parameters, l_obj_type, l_obj_key and l_obj_sys?
Also try executing the BAPI and commit with the performance trace turned on. You should be able to see which tables are being updated.
Rob
‎2005 Oct 03 4:11 AM
I tried basically the same code and got the same results as you. I'll do a little further digging.
OK - I'm at a loss. I notice that you don't have tax codes and your're using a negative amount in one case instead of a debit/credit indicator; but if that's a problem, then the BAPI should return an error not say it's posted a document when it certainly looks like it has not.
Rob
Message was edited by: Rob Burbank
‎2005 Sep 28 11:35 PM
Roland,
This is a long shot but try commenting out the following lines:
l_bkpf-obj_type = 'BKPFF'.
l_bkpf-obj_sys = 'DEV101'.
l_bkpf-obj_key = '$'.
I have used this BAPI and I never populate these values.
Also when you are putting in the Fiscal Year and Fiscal Period, they may not always match up the month and year of the date (this is determined via your fiscal year variant). Try using FM FTI_FISCAL_YEAR_MONTH_GET and pass in your Company Code and Date.
Hope this helps.
Cheers,
Pat.
PS. Kindly assign Reward Points tot he posts you find helpful.
‎2005 Sep 29 11:25 AM
Patrick,
I have excluded the 3 lines you mentioned. But this did not solve the problem.
‎2005 Sep 30 9:41 AM
Hi,
Try putting the amounts with sign in the value field structure as 1000 and 1000-.
Also provide the account type field(ACCT_TYPE) value as 'S' for GL posting in BAPIACGL09.
Also there is no need to pass AMT_BASE if you are not using tax code
Regards,
Vin
‎2005 Sep 30 12:33 PM
Hello Vinayak,
thanks for your coorporation, but this did not resolve my problem.
Kind regards,
Ronald Groennou.
‎2005 Nov 02 9:07 PM
Ronald,
I am experiencing the same issue, kindly share your solution when you resolve it.
Thanks in advance,
Frank
‎2005 Nov 03 9:41 AM
Hi Ronald
Please see the following code.
Hope to help.
*----
REPORT ZSKY_TEST10.
DATA:
WA_DOCUMENTHEADER TYPE BAPIACHE09,
OBJ_TYPE TYPE BAPIACHE02-OBJ_TYPE,
OBJ_KEY TYPE BAPIACHE02-OBJ_KEY,
OBJ_SYS TYPE BAPIACHE02-OBJ_SYS.
DATA:
IT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
IT_ACCOUNTGL TYPE STANDARD TABLE OF BAPIACGL09,
IT_CURRENCY TYPE STANDARD TABLE OF BAPIACCR09,
IT_ACCOUNTTAX TYPE STANDARD TABLE OF BAPIACTX09,
IT_ACCOUNTRECEIVABLE TYPE STANDARD TABLE OF BAPIACAR09,
WA_RETURN LIKE BAPIRET2.
DATA:
WA_CURRENCY TYPE BAPIACCR09,
WA_RETURN2 TYPE BAPIRET2,
WA_RETURN3 TYPE BAPIRET2 ,
WA_ACCOUNTGL TYPE BAPIACGL09,
WA_ACCOUNTRECEIVABLE TYPE BAPIACAR09,
WA_ACCOUNTTAX TYPE BAPIACTX09.
START-OF-SELECTION.
WA_DOCUMENTHEADER-OBJ_TYPE = 'BKPFF'.
CONCATENATE SY-SYSID 'CLNT' SY-MANDT INTO WA_DOCUMENTHEADER-OBJ_SYS.
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
OWN_LOGICAL_SYSTEM = WA_DOCUMENTHEADER-OBJ_SYS.
WA_DOCUMENTHEADER-OBJ_SYS = 'Z300'.
WA_DOCUMENTHEADER-OBJ_KEY = '$'.
WA_DOCUMENTHEADER-USERNAME = SY-UNAME.
WA_DOCUMENTHEADER-COMP_CODE = 'C002'.
WA_DOCUMENTHEADER-BUS_ACT = 'RFBU'.
WA_DOCUMENTHEADER-HEADER_TXT = 'BAPI TEST'.
WA_DOCUMENTHEADER-FISC_YEAR = '2005'.
WA_DOCUMENTHEADER-DOC_DATE = SY-DATUM.
WA_DOCUMENTHEADER-PSTNG_DATE = SY-DATUM.
WA_DOCUMENTHEADER-FIS_PERIOD = '11'.
WA_DOCUMENTHEADER-DOC_TYPE = 'DZ'.
CLEAR: WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = 1.
WA_ACCOUNTGL-GL_ACCOUNT = '5102010200'.
WA_ACCOUNTGL-COSTCENTER = '0000210100'.
WA_ACCOUNTGL-ITEM_TEXT = 'KEMU' .
WA_ACCOUNTGL-STAT_CON = 'S'.
WA_ACCOUNTGL-ACCT_KEY = '40'.
WA_ACCOUNTGL-ACCT_TYPE = 'S'.
WA_ACCOUNTGL-COMP_CODE = 'C002'.
WA_ACCOUNTGL-FISC_YEAR = '2005'.
WA_ACCOUNTGL-FIS_PERIOD = '11'.
WA_ACCOUNTGL-PSTNG_DATE = SY-DATUM.
WA_ACCOUNTGL-DOC_TYPE = 'DZ'.
INSERT WA_ACCOUNTGL INTO TABLE IT_ACCOUNTGL.
CLEAR: WA_ACCOUNTGL.
WA_ACCOUNTGL-ITEMNO_ACC = 3.
WA_ACCOUNTGL-GL_ACCOUNT = '2171010200'.
WA_ACCOUNTGL-ITEM_TEXT = 'SHUI.' .
WA_ACCOUNTGL-STAT_CON = 'S'.
WA_ACCOUNTGL-ACCT_KEY = '40'.
WA_ACCOUNTGL-ACCT_TYPE = 'S'.
WA_ACCOUNTGL-COMP_CODE = 'C002'.
WA_ACCOUNTGL-FISC_YEAR = '2005'.
WA_ACCOUNTGL-FIS_PERIOD = '11'.
WA_ACCOUNTGL-PSTNG_DATE = SY-DATUM.
WA_ACCOUNTGL-DOC_TYPE = 'DZ'.
INSERT WA_ACCOUNTGL INTO TABLE IT_ACCOUNTGL.
CLEAR: WA_ACCOUNTRECEIVABLE.
WA_ACCOUNTRECEIVABLE-ITEMNO_ACC = 2.
WA_ACCOUNTRECEIVABLE-CUSTOMER = '0001000002'.
WA_ACCOUNTRECEIVABLE-COMP_CODE = 'C002'.
WA_ACCOUNTRECEIVABLE-ITEM_TEXT = 'KEHU'.
WA_ACCOUNTRECEIVABLE-PYMT_CUR = 'RMB'.
WA_ACCOUNTRECEIVABLE-PYMT_AMT = 100.
INSERT WA_ACCOUNTRECEIVABLE INTO TABLE IT_ACCOUNTRECEIVABLE.
CLEAR: WA_CURRENCY.
WA_CURRENCY-ITEMNO_ACC = 1.
WA_CURRENCY-CURRENCY = 'RMB'.
WA_CURRENCY-CURR_TYPE = '00'.
WA_CURRENCY-AMT_DOCCUR = '854.70'.
INSERT WA_CURRENCY INTO TABLE IT_CURRENCY.
CLEAR: WA_CURRENCY.
WA_CURRENCY-ITEMNO_ACC = 2.
WA_CURRENCY-CURR_TYPE = '00'.
WA_CURRENCY-CURRENCY = 'RMB'.
WA_CURRENCY-AMT_DOCCUR = '1000-'.
INSERT WA_CURRENCY INTO TABLE IT_CURRENCY.
CLEAR: WA_CURRENCY.
WA_CURRENCY-ITEMNO_ACC = 3.
WA_CURRENCY-CURR_TYPE = '00'.
WA_CURRENCY-CURRENCY = 'RMB'.
WA_CURRENCY-AMT_DOCCUR = '145.30'.
INSERT WA_CURRENCY INTO TABLE IT_CURRENCY.
--------------------------------------------------------
Post
--------------------------------------------------------
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = WA_DOCUMENTHEADER
IMPORTING
OBJ_TYPE = OBJ_TYPE
OBJ_KEY = OBJ_KEY
OBJ_SYS = OBJ_SYS
TABLES
ACCOUNTGL = IT_ACCOUNTGL
ACCOUNTRECEIVABLE = IT_ACCOUNTRECEIVABLE
CURRENCYAMOUNT = IT_CURRENCY
ACCOUNTTAX = IT_ACCOUNTTAX
RETURN = IT_RETURN.
COMMIT WORK AND WAIT.
LOOP AT IT_RETURN INTO WA_RETURN.
WRITE : /1 WA_RETURN-MESSAGE.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = WA_RETURN3.