‎2009 Feb 02 3:01 PM
Hi,
In my program have written a code such that it fetches all the document numbers based on the company code and posting date.See based on this condition in a table it may contain N number of document numbers and each document number may have N number of line items.In my logic have to write the code such that if a document number consists of line items more than 10 then those document number has to be deleted.In my code have identified the document number based on the condition but dunno to write the logic to delete the document number if it has more line items.
the code is
LOOP AT gt_bsik.
AT NEW lifnr.
READ TABLE gt_lfb1 WITH KEY lifnr = gt_bsik-lifnr BINARY
SEARCH.
CLEAR lt_vendors.
lt_vendors-lifnr = gt_lfb1-lifnr.
ENDAT.
AT NEW belnr.
gv_new_invoice_ind = 'X'.
gt_bsik_copy-lifnr = gt_bsik-lifnr.
gt_bsik_copy-belnr = gt_bsik-belnr.
gt_bsik_copy-gjahr = gt_bsik-gjahr.
gt_bsik_copy-buzei = gt_bsik-buzei.
gv_count = gv_count + gt_bsik-buzei .
ENDAT.
IF gv_new_invoice_ind = 'X'.
ADD 1 TO lt_vendors-count.
ENDIF.
gv_new_invoice_ind = space.
AT END OF lifnr.
APPEND lt_vendors.
APPEND gt_bsik_copy.
ENDAT.
IF gv_count > 10.
* DELETE gt_bsik where lifnr =
*gt_bsik_copy-lifnr and belnr = gt_bsik_copy-belnr and
*gjahr = gt_bsik_copy-gjahr .
DELETE gt_bsik WHERE lifnr =
gt_bsik_copy-lifnr .
ENDIF.
ENDLOOP.
ENDIF.
gt_bsik is the internal table.Please help me to write the logic.The above mentioned logic is not workin
Edited by: Julius Bussche on Feb 2, 2009 4:47 PM
Please use code tags and meaningfull subject titles
‎2009 Feb 02 4:01 PM
AT NEW belnr.
gv_new_invoice_ind = 'X'.
gt_bsik_copy-lifnr = gt_bsik-lifnr.
gt_bsik_copy-belnr = gt_bsik-belnr.
gt_bsik_copy-gjahr = gt_bsik-gjahr.
gt_bsik_copy-buzei = gt_bsik-buzei.
gv_count = 0 .
ENDAT.
gv_count = gv_count + 1.
IF gv_count > 1.
DELETE gt_bsik WHERE belnr = gt_bsik-belnr.
ENDIF.
Replace the AT NEW control block in your program with the above code. I hope it works.
‎2009 Feb 02 3:52 PM
Hi,
In your select statment, you can specify in the where clause to select entries from bsik where buzei < 10
regards,
Advait
‎2009 Feb 02 4:01 PM
AT NEW belnr.
gv_new_invoice_ind = 'X'.
gt_bsik_copy-lifnr = gt_bsik-lifnr.
gt_bsik_copy-belnr = gt_bsik-belnr.
gt_bsik_copy-gjahr = gt_bsik-gjahr.
gt_bsik_copy-buzei = gt_bsik-buzei.
gv_count = 0 .
ENDAT.
gv_count = gv_count + 1.
IF gv_count > 1.
DELETE gt_bsik WHERE belnr = gt_bsik-belnr.
ENDIF.
Replace the AT NEW control block in your program with the above code. I hope it works.
‎2009 Feb 02 4:52 PM
HI
Before the loop statement take a copy the internal table into another internal table of the same type.
gt_bsik_2[] = gt_bsik[]
sort gt_bsek_2 by BUKRS GJAHR BELNR BUZEI descending.
LOOP AT gt_bsik.
read table gt_bsek_2 with key bukrs = gt_bsik-belnr
gjahr = gt_bsik-gjahr
belnr = gt_bsik-belnr.
if sy-subrc eq 0.
if gt_bsik_2-buzei > 10.
delete gt_bsik_2 where bukrs = gt_bsik-belnr and
gjahr = gt_bsik-gjahr and
belnr = gt_bsik-belnr.
endif.
endif.
endloop.
after the endloop table gt_bsik_2 will will have only document numbers which have line items less than 10.
Hope the above code helps you