‎2006 Feb 20 2:59 AM
Hello experts,
I am currently modifying a report where in when a certain material number is deleted(if ekpo-loekz/t_ekpo2-loekz is not initial delete it_hdr) so what I did was to put my IF statement inside the loop. So what I want to do is to remove all those records that has been deleted so when the report output is shown it will only display all the P.O's that has not been deleted but I can't seem to make it work. I have pasted below my code. Thanks guys and take care!
LOOP AT it_hdr.
read table t_ekpo2 with key ebeln = it_hdr-refbn.
AT NEW refbn.
REFRESH: account, history.
CLEAR: account, history.
CALL FUNCTION 'BAPI_PO_GETDETAIL'
EXPORTING
purchaseorder = it_hdr-refbn
account_assignment = 'X'
history = 'X'
TABLES
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.
ENDLOOP.
LOOP AT pohistory.
t_pohistory = pohistory.
t_pohistory-ebeln = it_hdr-refbn.
APPEND t_pohistory. CLEAR t_pohistory.
ENDLOOP.
LOOP AT history.
t_history = history.
t_history-ebeln = it_hdr-refbn.
APPEND t_history. CLEAR t_history.
ENDLOOP.
ENDAT.
**This is my IF statement**
if not t_ekpo2-loekz is initial.
delete it_hdr.
endif.
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.
ENDLOOP.
SORT t_account BY po_item ASCENDING
serial_no ASCENDING
ebeln ASCENDING
wbs_elem_e ASCENDING.
DELETE ADJACENT DUPLICATES FROM t_account.
SORT t_pohistory BY po_item ASCENDING
serial_no ASCENDING
ebeln ASCENDING
hist_type ASCENDING
mat_doc ASCENDING
matdoc_itm ASCENDING.
DELETE ADJACENT DUPLICATES FROM t_pohistory.
SORT t_history BY po_item ASCENDING
serial_no ASCENDING
ebeln ASCENDING.
DELETE ADJACENT DUPLICATES FROM t_history.
IF pa_augdt is initial.
IF so_augdt[] IS INITIAL.
PERFORM process_no_budat.
ELSE.
PERFORM process_with_budat.
ENDIF.
DELETE t_amount WHERE psphi IS initial.
LOOP AT t_amount.
it_dtl-netwr = t_amount-netwr.
it_dtl-dpamt = t_amount-dpamt.
it_dtl-gramt = t_amount-gramt.
it_dtl-iramt = t_amount-iramt.
it_dtl-tramt = t_amount-tramt.
it_dtl-blamt = t_amount-blamt.
MODIFY it_dtl TRANSPORTING netwr dpamt gramt
iramt tramt blamt
WHERE ebeln = t_amount-ebeln
AND psphi = t_amount-psphi.
CLEAR it_dtl.
ENDLOOP.
‎2006 Feb 20 3:02 AM
‎2006 Feb 20 3:02 AM
‎2006 Feb 20 3:03 AM
You can move read statement in AT NEW Block.
Also used INDEX while deleting record from IT_HDR.
After deletion you can use CONTINUE to process with next record.
Also it will be good if you use condition
DELTE IT_HDR WHERE REFBN = IT_HDR-REFBN.
This will help you to delete all POs which have deletion indicator set.