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_DOCUMENT_POST returns non-sequential numbers

Former Member
0 Likes
1,583

Hi All.

I am fixing someone's program that is using BAPI_ACC_DOCUMENT_POST. It creates the document correctly, but if you run it multiple times, the document numbers that it creates are not sequential. There doesn't seem to be a pattern for the document number gaps. Here is how the header is created and the BAPI is called. Maybe it will give you some insight.

T_BAPIACHE09-OBJ_TYPE = 'BKPFF'.

T_BAPIACHE09-BUS_ACT = 'RFBU'.

T_BAPIACHE09-OBJ_KEY = '001000000000000000'.

CONCATENATE '0010' SY-UZEIT SY-DATUM INTO T_BAPIACHE09-OBJ_KEY.

WRITE: / 'Object Key ', T_BAPIACHE09-OBJ_KEY.

CONCATENATE SY-SYSID 'CLNT' SY-MANDT INTO T_BAPIACHE09-OBJ_SYS.

WRITE: / 'Object System ', T_BAPIACHE09-OBJ_SYS.

T_BAPIACHE09-USERNAME = SY-UNAME.

T_BAPIACHE09-COMP_CODE = WA_HEADER-BUKRS.

T_BAPIACHE09-FISC_YEAR = SY-DATUM(4).

T_BAPIACHE09-DOC_DATE = SY-DATUM.

T_BAPIACHE09-PSTNG_DATE = SY-DATUM.

T_BAPIACHE09-FIS_PERIOD = SY-DATUM+4(2).

T_BAPIACHE09-DOC_TYPE = 'SA'.

T_BAPIACHE09-HEADER_TXT = WA_HEADER-BKTXT.

T_BAPIACHE09-AC_DOC_NO = SPACE.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

DOCUMENTHEADER = T_BAPIACHE09

TABLES

ACCOUNTGL = T_BAPIACGL09

CURRENCYAMOUNT = T_BAPIACCR09

RETURN = T_BAPIRET2.

Any help would be greatly appreciated and rewarded with points.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,163

we get the next available number with the FM NUMBER_GET_NEXT before we pass it to the obj_key so that the numbers can be sequential.

9 REPLIES 9
Read only

Former Member
0 Likes
1,163

Hi,

Try the folowing,

Create a new entry (i.e. ZCUS) in table TTYP (it has manteinance view --> SM30).

Repace value BKPFF by the one you just created ZCUS in header field object type.

Rgds,

Jose

Read only

Former Member
0 Likes
1,163

Hi

But have you some gaps in the document numerations?

Have you use the COMMIT after calling the BAPI for posting?

Max

Read only

0 Likes
1,163

Hi,

We use the BAPI as I told you and we don´t have problems with the numbering. I´m not sure if replacing the object type will solve your problem, but I remember having read somewhere that using standard sap object types with this BAPI could cause problems.

Yes, you must do a commit after calling the BAPI, if you don´t it will not create the document. You can use BAPI_TRANSACTION_COMMIT instead of doing the commit directly in your code.

Rgds,

Jose

Read only

0 Likes
1,163

I am already doing the bapi commit.

Read only

0 Likes
1,163

Hi

That's ok, but are there the document beetween 2 and 14, 16 and 34 and so.....

The range depends on only document type, so before creating the next document check if the range is currectly updated.

Max

Read only

Former Member
0 Likes
1,164

we get the next available number with the FM NUMBER_GET_NEXT before we pass it to the obj_key so that the numbers can be sequential.

Read only

0 Likes
1,163

You should not have to use the number_get_next for a standard BAPI that creates these documents. When I run mine, it creates the document, but there are gaps between the runs. For example, the first time I run it it creates document 1, the second time 15, then 35, then 37, and so on.

Read only

Former Member
0 Likes
1,163

as Max says try the check. Also just wanted to make sure you do not have a test run on this program. If test run then do you rollback. Even if you test it SE37 the number gets alloted but the document is not posted as there is no commit unless its update. Just a thought. Anyways do let us know how you solved it.

Read only

0 Likes
1,163

As already said: If a numer is drawn from the numer range (i.e. test without commit) this numer cannot be used again - it is lost.

Possibly your program tries to post a document and in error case drops it - numers are lost.

Another possible situation is using inbound IDOCS: IDOCS are processed in parrallel processing and it depends highly on the actual processing circumstances who comes first and how fast which document goes through. In that case the document number are anything but sequential.

Regards,

Clemens