<div>Dear Friends,</div>
<div> </div>
<div>Recently I was looking for a background method which can be used to reject a purchase requisition or purchase order and I would like to share my finds with this group. </div>
<div> </div>
<div>My initial search (in WUG and other forums) pointed me in the direction of a function module, ME_UPDATE_REQUISITION, using which we set the value of BANPR field to '08'; this method works fine. However, I felt really uneasy as I was manually setting a field value directly, I always had the question of 'is this all or am I missing anything?' After some more research I found couple of classes which will do the job for us, CL_REQUISITION_AGGREGATE_MM and CL_REQ_HEADER_PROXY_MM. Below is the piece of code I wrote and is working fine for me.</div>
<div> </div>
<div>Hope this information is useful to you.</div>
<div> </div>
<div>begin_method reject changing container.</div>
<div><br>DATA: lc_pr_agg_mm TYPE REF TO cl_requisition_aggregate_mm,<br> lc_pr_header TYPE REF TO cl_req_header_proxy_mm,<br> ls_document TYPE mepo_document.</div>
<div> </div>
<div>ls_document-doc_type = 'B'.<br>ls_document-doc_key = object-key-number.<br>ls_document-trtyp = 'V'.<br>ls_document-process = 'REQ_PROCESS'.<br>ls_document-initiator-initiator = 'RELEASE'.</div>
<div> </div>
<div>* Instantiate PR aggregate class<br>CREATE OBJECT lc_pr_agg_mm<br> EXPORTING<br> im_document = ls_document.</div>
<div> </div>
<div>* Instantiate PR header class<br>CREATE OBJECT lc_pr_header<br> EXPORTING<br> im_banfn = object-key-number<br> im_aggregate = lc_pr_agg_mm.</div>
<div> </div>
<div>* Use ATTACH method in header class to instantiate MY_REAL_OBJECT attrib<br>CALL METHOD lc_pr_header->attach<br> EXPORTING<br> im_trtyp = 'V'.</div>
<div> </div>
<div>* Check if rejecting PR is possible<br>IF lc_pr_header->if_releasable_mm~is_rejection_allowed( ) EQ 'X'.</div>
<div><br>* Reject the PR<br> CALL METHOD lc_pr_header->my_real_object->if_releasable_mm~reject<br> EXPORTING<br> im_reset = space.</div>
<div><br>* Do a check<br> CALL METHOD lc_pr_header->my_real_object->check.</div>
<div><br>* Then post</div>
<div> CALL METHOD lc_pr_header->my_real_object->post<br> EXPORTING<br> im_uncomplete = space.</div>
<div><br> * And commit changes to database<br> CALL METHOD lc_pr_agg_mm->if_purchase_req_factory~commit.</div>
<div><br> ENDIF.</div>
<div><br> end_method.</div>
<div> </div>
<div>Similarly for rejecting a purchase order in the backgroud you can use methods of class CL_PO_HEADER_HANDLE_MM.</div>
<div> </div>
<div>Thank you,</div>
<div><em>-<strong>Sarawana K Vijayakumar</strong></em></div>
<div>SAP ABAP / Workflow Senior Consultant</div>
<div> </div>
<div> </div>