Mass Deletion of Purchase Requisition?
In
SAP no standard T-Code is available for mass deletion of PR. You have
to go for custom program.
This
can be achieved by using BAPI.
BAPI_REQUISITION_DELETE
_________________________________________________
Short Text
Delete/close
purchase requisition
Functionality
This
method enables you to delete and/or close purchase requisitions.
All
requisition items for which the deletion indicator and/or the
"closed" indicator is to be set are passed on in the table RequisitionItemsToDe.
Since this method changes the purchase requisition, change documents are
created when you save.
Messages
are returned in the Return parameter. The parameter documentation
shows the return codes and their meanings
Procedure: Go to the EBAN table
and get the PR you need to delete (SE16N). Then, download these PR to a
spreadsheet. Execute your program and paste PR you want to delete. Then, mass
delete all PR.
Here
is a sample program for the same.
*&---------------------------------------------------------------------*
*& Report ZPR_BAPI_DEL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT XXXXXXXXXX.
***Tables
TABLES: eban, mard.
*** DATA
DATA: ex_numer LIKE bapieban-preq_no,
tb_item_to_del LIKE bapieband OCCURS 0 WITH HEADER LINE,
tb_return LIKE bapireturn OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF i_eban OCCURS 0,
banfn LIKE eban-banfn,
bnfpo LIKE eban-bnfpo,
bsart LIKE eban-bsart,
matnr LIKE eban-matnr,
txz01 LIKE eban-txz01,
menge LIKE eban-menge,
meins LIKE eban-meins,
erdat LIKE eban-erdat,
END OF i_eban.
DATA: BEGIN OF i_msg OCCURS 0,
light(1) TYPE c,
banfn LIKE eban-banfn,
message LIKE bapireturn-message,
END OF i_msg.
DATA: index LIKE sy-tabix.
DATA c_i_eban LIKE i_eban OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: r_eban FOR eban-banfn.
PARAMETER: p_del AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK bl1.
START-OF-SELECTION.
SELECT banfn bnfpo bsart matnr txz01 menge meins erdat
FROM eban INTO TABLE i_eban
WHERE banfn IN r_eban
AND loekz = space.
c_i_eban[] = i_eban[].
SORT i_eban BY banfn.
DELETE ADJACENT DUPLICATES FROM i_eban COMPARING banfn.
SORT c_i_eban BY banfn bnfpo.
LOOP AT i_eban.
FREE: tb_item_to_del, tb_return. CLEAR ex_numer.
READ TABLE c_i_eban WITH KEY banfn = i_eban-banfn.
IF sy-subrc = 0.
index = sy-tabix.
ex_numer = i_eban-banfn.
LOOP AT c_i_eban FROM index.
IF c_i_eban-banfn NE i_eban-banfn.
EXIT.
ENDIF.
tb_item_to_del-preq_item = c_i_eban-bnfpo.
tb_item_to_del-delete_ind = p_del.
APPEND tb_item_to_del.
ENDLOOP.
CALL FUNCTION 'BAPI_REQUISITION_DELETE'
EXPORTING
number = ex_numer
TABLES
requisition_items_to_delete = tb_item_to_del
return = tb_return.
LOOP AT tb_return.
CLEAR i_msg.
i_msg-banfn = i_eban-banfn.
i_msg-message = tb_return-message.
IF tb_return-type = 'E' OR tb_return-type = 'A'.
i_msg-light = '1'.
ELSEIF tb_return-code = 'W5041'.
i_msg-light = '3'.
ENDIF.
APPEND i_msg.
ENDLOOP.
ENDIF.
ENDLOOP.
END-OF-SELECTION.
PERFORM show_messages TABLES i_msg.
FORM show_messages TABLES it_msg STRUCTURE i_msg.
DATA lt_fieldcat TYPE slis_t_fieldcat_alv.
DATA ls_fieldcat TYPE slis_fieldcat_alv.
DATA ls_layout TYPE slis_layout_alv.
DATA lt_events TYPE slis_t_event.
DATA ls_event TYPE slis_alv_event.
* build fieldcat
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BANFN'.
ls_fieldcat-ref_fieldname = 'BANFN'.
ls_fieldcat-ref_tabname = 'EBAN'.
ls_fieldcat-key = 'X'.
ls_fieldcat-hotspot = 'X'.
INSERT ls_fieldcat INTO TABLE lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MESSAGE'.
ls_fieldcat-ref_fieldname = 'MESSAGE'.
ls_fieldcat-ref_tabname = 'BAPIRETURN'.
INSERT ls_fieldcat INTO TABLE lt_fieldcat.
ls_layout-colwidth_optimize = 'X'.
ls_layout-f2code = 'ANZ'.
ls_layout-lights_fieldname = 'LIGHT'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
i_callback_user_command = 'USER_COMMAND2'
* I_STRUCTURE_NAME =
is_layout = ls_layout
it_fieldcat = lt_fieldcat[]
* IT_EXCLUDING =
* IT_EVENTS = lt_events[]
* IT_EVENT_EXIT =
TABLES
t_outtab = it_msg
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " show_messages
No comments:
Post a Comment