Application Development 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: 

problem in deleting additional line items

aris_hidalgo
Contributor
0 Kudos

Hello experts,

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.

continue.

endif.

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.

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Try this...

SORT t_ekpo2 BY ebeln loekz.
LOOP AT it_hdr.
*ON CHANGE OF refbn.
READ TABLE t_ekpo2 WITH KEY ebeln = it_hdr-refbn AND loekz is initial BINARY SEARCH.
delete it_hdr where refbn = t_ekpo2-ebeln.
*ENDON.
ENDLOOP.

4 REPLIES 4

Former Member
0 Kudos

do this add field ststus like ekpo-elikz into internal table and delete it....

begin of int_tab occurs 0.

STATUS LIKE EKPO-ELIKZ,

end of int_tab.

DELETE INT_TAB WHERE STATUS = 'X'

Former Member
0 Kudos

Try this...

SORT t_ekpo2 BY ebeln loekz.
LOOP AT it_hdr.
*ON CHANGE OF refbn.
READ TABLE t_ekpo2 WITH KEY ebeln = it_hdr-refbn AND loekz is initial BINARY SEARCH.
delete it_hdr where refbn = t_ekpo2-ebeln.
*ENDON.
ENDLOOP.

Former Member
0 Kudos

Hi viraylab!

is refbn is your first field in the internla table. If not then try using

ON CHANGE Of refbn.

becoz the At New will trigger whenever there is a change in the previous fields also.

regards

kishore

Former Member
0 Kudos

hi

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 .

vijay.