I am currently modifying a report where in I must delete all P.O's that has one or all of their materials deleted. So when I run my report it only deletes the PO's that have their first line items deleted but it doesnt delete/detect the PO's that have multiple line items/materials in them. For example, my report displays PO number 4550000034 and then I check it in t-code ME23 and it's first material/line is not deleted but additional materials/line items has been deleted(symbolized by a trash can) so it is displayed in my report. What I want to do is to check each and every material in a particular PO and if one of them is deleted I must disregard that certain PO and not include it in my report. the field wherein the deleted indicator is ekpo-loekz/t_ekpo2-loekz. I have pasted below my code. Thanks guys and take care!
LOOP AT it_hdr.
AT NEW refbn.
read table t_ekpo2 with key ebeln = it_hdr-refbn.
if not t_ekpo2-loekz is initial.
delete it_hdr where refbn = t_ekpo2-ebeln.
REFRESH: account, history.
CLEAR: account, history.
CALL FUNCTION 'BAPI_PO_GETDETAIL'
purchaseorder = it_hdr-refbn
account_assignment = 'X'
history = 'X'
po_item_account_assignment = account
po_item_history = pohistory
po_item_history_totals = history.
LOOP AT account.
t_account = account.
t_account-ebeln = it_hdr-refbn.
APPEND t_account. CLEAR t_account.
LOOP AT pohistory.
t_pohistory = pohistory.
t_pohistory-ebeln = it_hdr-refbn.
APPEND t_pohistory. CLEAR t_pohistory.
LOOP AT history.
t_history = history.
t_history-ebeln = it_hdr-refbn.
APPEND t_history. CLEAR t_history.
it_dtl-psphi = it_hdr-psphi.
it_dtl-name1 = it_hdr-name1.
it_dtl-ebeln = it_hdr-refbn.
SELECT SINGLE waers FROM ekko INTO it_dtl-waers
WHERE ebeln = it_hdr-refbn.
APPEND it_dtl. CLEAR it_dtl.
apply the reverse scenario.
1.see the process is as u said sometimes even though the items in ITEM level are deleted which are shown in EKPO table with deletion field indicator as LOEKZ but the header table EKKO may not have the indicator on . this may be due to Functional setting.
2.In ur problem proceed like first use select on EKPO table and include fields POSNR , LOEKZ in one internal table say IT_TAB1.
this gives u the list of all po's with deletion field indicator vs PO numbers at item level.
3.For all entries in IT_TAB1 select the relavent PO'numbers from EKKO table which only gives u the PO numbers for the entries in EKPO table .
means to say that
Now u r left with only those entries on which no item is deleted okay so ur query is resolved here.
4. DIscard PO numbers from ur final internal table .