2016 Jan 04 6:22 AM
Hi,
I am writing piece of code in driver program( FORM ENTRY_NEU configured in NACE).
During change PO the output type will be called and calling the FORM ENTRY_NEU as well. I have written the below code.
SELECT objectclas
objectid
changenr
udate
utime
FROM cdhdr INTO TABLE i_cdhdr
WHERE objectclas = 'EINKBELEG'
AND objectid = lv_ebeln.
During debug mode I could see 20 records but when I see 19 entries in table CDHDR(SE16)
I am taking latest updated entries from CDHDR and select from CDPOS(no records on change number)
Due to some discrepancy our logic is failing...
Is there any commit work issue or what could be the issue?
Please advise.
Regards,
A Vadamalai.
2016 Jan 04 6:46 AM
Hi Vadamalai,
I guess, the custom output type which you have used has the output condition records with Dispatch Time as "Immediate". If you need to refer the tables for this corresponding change, you would need to set the Dispatch time as "Processing using own transaction" or any other mode and let the standard completely update the standard tables.
Try by changing the output condition records and let us know.
Thanks,
Karthikeyan
2016 Jan 05 1:30 AM
Hi Karthikeyan,
Earlier it was working fine with the same setup "Immediate".
Please advise some alternate way.
Regards,
A Vadamalai
2016 Jan 05 11:09 AM
Hi Vadamalai,
I have tested the same in my system. The changes are written using the function module EINKBELEG_WRITE_DOCUMENT. The table CDHDR & CDPOS updates happen in the FM CHANGEDOCUMENT_CLOSE. In the form write_normal_changedocu, CDHDR is updated using the statement INSERT INTO , while the CDPOS is updated using
INSERT (pv_tabname) FROM TABLE pt_in.
Documentation as on help.sap for the above Insert from
Notes
The inserted rows are included permanently in the table in the next database commit. Up until this point, they can still be removed by a database rollback.
IMO, SAP calls the update function modules in a predefined order. EINKBELEG_WRITE_DOCUMENT gets executed ahead of RV_MESSAGE_UPDATE. So CDHDR is updated using INSERT INTO & updates the record in the table. CDPOS is updated using INSERT FROM, the records will be updated only in the next database commit (SAP issues the commit after all the update function modules are executed).
RV_MESSAGE_UPDATE triggers your custom output type and you are selecting the CDPOS before SAP issues the final commit and so you are not able to see the table entries in CDPOS for that change number.
I would suggest you to change the dispatch time other than "Immediate" or
1. Wrap all your CDPOS selection logic, email code to a function module 'Z_CALL_IN_NEW_LUW
2. In your output type call
CALL FUNCTION 'Z_CALL_IN_NEW_LUW
IN BACKGROUND TASK
AS SEPARATE UNIT
EXPORTING
<your data>
3. In Z_CALL_IN_NEW_LUW, check if the PO is not locked and write the select query to fetch CDPOS. (As Z_CALL_IN_NEW_LUW is called as a separate unit, it will be called in a new LUW. By this time CDPOS data will be saved to database.) write your logic using the fetched values of CDPOS.
Hope this helps you.
Thanks,
Karthikeyan
2016 Jan 05 3:58 AM
Hi Vadamalai,
just an advice..you should not use SELECT query on CDHDR and CHPOS as they are huge table and SAP does not recommend SELECT on any such huge table.in production it can cause an performance issue.
try using FM CHANGEDOCUMENT_READ_HEADERS to read header and CHANGEDOCUMENT_READ_POSITIONS for items.
how to pass the data to these FMs you can check on below link.
Function Module to Read Change Documents from T... | SCN
Regards,
Menka
2016 Jan 05 2:52 PM
Menka Dahiya wrote:
..you should not use SELECT query on CDHDR and CHPOS as they are huge table and SAP does not recommend SELECT on any such huge table.in production it can cause an performance issue.
There is nothing wrong with SELECTing from large tables and SAP does not recommend against it; they do it themselves. You just have to be careful that you are using indexes wisely.
Rob