<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 &#39;08&#39;; this method works fine. However, I felt really uneasy as I was manually setting a field value directly, I always had the question of &#39;is this all or am I missing anything?&#39; 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 = &#39;B&#39;.<br>ls_document-doc_key  = object-key-number.<br>ls_document-trtyp    = &#39;V&#39;.<br>ls_document-process  = &#39;REQ_PROCESS&#39;.<br>ls_document-initiator-initiator = &#39;RELEASE&#39;.</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-&gt;attach<br>  EXPORTING<br>    im_trtyp = &#39;V&#39;.</div>
<div> </div>
<div>* Check if rejecting PR is possible<br>IF lc_pr_header-&gt;if_releasable_mm~is_rejection_allowed( ) EQ &#39;X&#39;.</div>
<div><br>* Reject the PR<br>  CALL METHOD lc_pr_header-&gt;my_real_object-&gt;if_releasable_mm~reject<br>    EXPORTING<br>      im_reset = space.</div>
<div><br>* Do a check<br>  CALL METHOD lc_pr_header-&gt;my_real_object-&gt;check.</div>
<div><br>* Then post</div>
<div>   CALL METHOD lc_pr_header-&gt;my_real_object-&gt;post<br>     EXPORTING<br>       im_uncomplete = space.</div>
<div><br> * And commit changes to database<br>   CALL METHOD lc_pr_agg_mm-&gt;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>