Reject purchase requisition or order in a background method
Sarawana K Vijayakumar
sarawana.vijayakumar at gmail.com
Wed May 25 14:33:02 EDT 2011
Dear Friends,
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.
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.
Hope this information is useful to you.
begin_method reject changing container.
DATA: lc_pr_agg_mm TYPE REF TO cl_requisition_aggregate_mm,
lc_pr_header TYPE REF TO cl_req_header_proxy_mm,
ls_document TYPE mepo_document.
ls_document-doc_type = 'B'.
ls_document-doc_key = object-key-number.
ls_document-trtyp = 'V'.
ls_document-process = 'REQ_PROCESS'.
ls_document-initiator-initiator = 'RELEASE'.
* Instantiate PR aggregate class
CREATE OBJECT lc_pr_agg_mm
EXPORTING
im_document = ls_document.
* Instantiate PR header class
CREATE OBJECT lc_pr_header
EXPORTING
im_banfn = object-key-number
im_aggregate = lc_pr_agg_mm.
* Use ATTACH method in header class to instantiate MY_REAL_OBJECT attrib
CALL METHOD lc_pr_header->attach
EXPORTING
im_trtyp = 'V'.
* Check if rejecting PR is possible
IF lc_pr_header->if_releasable_mm~is_rejection_allowed( ) EQ 'X'.
* Reject the PR
CALL METHOD lc_pr_header->my_real_object->if_releasable_mm~reject
EXPORTING
im_reset = space.
* Do a check
CALL METHOD lc_pr_header->my_real_object->check.
* Then post
CALL METHOD lc_pr_header->my_real_object->post
EXPORTING
im_uncomplete = space.
* And commit changes to database
CALL METHOD lc_pr_agg_mm->if_purchase_req_factory~commit.
ENDIF.
end_method.
Similarly for rejecting a purchase order in the backgroud you can use
methods of class CL_PO_HEADER_HANDLE_MM.
Thank you,
*-Sarawana K Vijayakumar*
SAP ABAP / Workflow Senior Consultant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.mit.edu/pipermail/sap-wug/attachments/20110525/8002e8e9/attachment.htm
More information about the SAP-WUG
mailing list