Skip to Content
author's profile photo Former Member
Former Member

Issue in updating Z table

Dear Friends,

I have an issue in Updating Ztable sequentially.

Scenario : One program updates my Ztable, from that table my program read records and post the documents ( BAPI_ACC_DOCUMENT_POST) . After successful posting of document that Z-table has to update with document number. Programs are scheduled in background(SM37). Here problem is for few records even document get created successfully it's not updating the Z-Table. Please check the code below and suggest. Thanks in advance.

Code :

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
DOCUMENTHEADER = BAPIACHE09
IMPORTING
OBJ_TYPE = OBJ_TYPE
OBJ_KEY = OBJ_KEY
OBJ_SYS = OBJ_SYS
TABLES
ACCOUNTGL = IT_ACCOUNTGL[]
ACCOUNTRECEIVABLE = IT_ACCOUNTRECEIVABLE[]
CURRENCYAMOUNT = IT_CURRENCYAMOUNT[]
RETURN = IT_RETURN[].

READ TABLE IT_RETURN WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0. " ERROR OCCURED
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
" updating error status in staging table
LS_HEADER-BAPI_FLAG = 'E'.
LS_HEADER-SAP_DATE = SY-DATUM.
LS_HEADER-SAP_TIME = SY-UZEIT.
READ TABLE IT_RETURN INDEX 2.
LS_HEADER-STS_DESC = IT_RETURN-MESSAGE.
UPDATE ZIB_INVOICE_HD FROM LS_HEADER.
COMMIT WORK.
WAIT UP TO 1 SECONDS.
ELSEIF OBJ_KEY IS NOT INITIAL. " SUCCESS
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
WAIT UP TO 2 SECONDS.
* CONDENSE OBJ_KEY.
LS_HEADER-BAPI_FLAG = 'S'.
LS_HEADER-SAP_DATE = SY-DATUM.
LS_HEADER-SAP_TIME = SY-UZEIT.
LS_HEADER-STS_DESC = OBJ_KEY.
UPDATE ZIB_INVOICE_HD FROM LS_HEADER.
COMMIT WORK.
WAIT UP TO 1 SECONDS.
ENDIF.
ELSE.
LS_HEADER-BAPI_FLAG = 'E'.
LS_HEADER-SAP_DATE = SY-DATUM.
LS_HEADER-SAP_TIME = SY-UZEIT.
LS_HEADER-STS_DESC = 'ERROR: Data issue'.
UPDATE ZIB_INVOICE_HD FROM LS_HEADER.
COMMIT WORK.
WAIT UP TO 1 SECONDS.

ENDIF.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 14, 2015 at 06:50 AM

    Thanks for your early reply.

    @ Mr. Krishnamurthy

    I have written the code same way, you have suggested with If Else.

    @ Mr. Rawat : Primary key is a field called Invoice_No in the Z-Table.

    Main problem at a given point my program picks 300 records and try to post, It loops 300 times, each time after successful document creation , it should update Ztable against that Invoice number (Primary Key) with newly document number generated through that BAPI.

    Suppose all 300 are successful but after few successful updation there will be couple of blank status field, even though document created successfully.

    I am suspecting WAIT UP TO 1 SECONDS statement causing problem.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 14, 2015 at 06:12 AM

    Your IF-Else condition is not seems to be correct.

    Reformat like this

    After the BAPI

    Check for IT_RETURN[]. is initial

    if it is initial

    write code for success - update / insert data into z table

    else

    write code for failure - update / insert data into z-table

    endif

    Also, what is the primary key for your z-table. There is a chance of getting overwriten by the last document.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 14, 2015 at 06:13 AM

    What are the key fields of your ztable ?

    Try using "BAPI_TRANSACTION_COMMIT after update command and in which case you wont have to use COMMIT WORK statement.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.