cancel
Showing results for 
Search instead for 
Did you mean: 

FM for creating GR cancellation or return delivery

former_member184741
Active Contributor
0 Kudos

hi experts,

i would like to know whether there is any FM/method to do the cancellation of GR in SRM 7. i found one BAPI for doinf confirmation BAPI_CONFEC_CREATE but not for cancellation. any ideas?

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Why dont you use class/method for cancellation of GR . Use method /SAPSRM/IF_PDO_BO_CONFDELETE_DOCUMENT(cancellation) and /SAPSRM/IF_PDO_BO_CONFRETURN_DELIVERY(return delivery) of the below interface after creating instance for confirmation.



  DATA: lo_bo_conf_adv TYPE REF TO /sapsrm/if_pdo_bo_conf_adv,
              lo_bo_conf         TYPE REF TO /sapsrm/if_pdo_bo_conf.


* Create confirmation object
  CALL METHOD /sapsrm/cl_pdo_fact_conf_adv=>create_new_instance
    EXPORTING
      iv_subtype         = lc_cf
      iv_header_guid     = lv_po_guid
      iv_object_type     = lv_objtyp
      iv_logsys          = lv_po_logsys
      iv_object_id       = p_ls_po_header-object_id
      iv_user_type       = lc_profi
    IMPORTING
      eo_instance        = lo_bo_conf_adv
    CHANGING
      co_message_handler = p_lo_message_consumer.

Check for sample code for creating confrimation, similarly you can cancel confirmation.

http://forums.sdn.sap.com/thread.jspa?threadID=2137361&tstart=15

former_member184741
Active Contributor
0 Kudos

hi,

Thanks for the reply.

i have tried to debug the cancellation process by keeping the breakpoint in delete_document method.. the control goes to this method first when i click cancel and then goes to the constructor you had mentioned. i am bit confused about how to code for cancellation. can you give some high level code for cancellation as well, as you given for confirmation

thanks

Former Member
0 Kudos

Check this :

Create an instance first with header guid and if you want to delete only one item then use item guid while creating instance and finally call the delete_document method using that instance.



* Create confirmation object
  CALL METHOD /sapsrm/cl_pdo_fact_conf_adv=>create_new_instance
    EXPORTING
      iv_subtype         = lc_cf
      iv_header_guid     = lv_po_guid
      iv_object_type     = lv_objtyp
      iv_logsys          = lv_po_logsys
      iv_object_id       = p_ls_po_header-object_id
      iv_user_type       = lc_profi
    IMPORTING
      eo_instance        = lo_bo_conf_adv
    CHANGING
      co_message_handler = p_lo_message_consumer.

          " Then call the delete document on that.
            CALL METHOD lo_bo_conf_adv->/sapsrm/if_pdo_bo_conf~delete_document
              IMPORTING
                eo_instance        = lo_bo_conf_adv
              CHANGING
                co_message_handler = mo_pdo_message_consumer.

            if lo_pdo_conf is initial.
              commit work.
            endif.

former_member184741
Active Contributor
0 Kudos

hi yadav,

the confusion i am having is this.

when i want to cancel an existing GR, for the instantiation of the object what should i pass. is it the PO guid ot the confirmation GUID. the reason i am asking this is for confirmation the source docuement is PO but for the cancellation the reference documnet is GR. so what should i pass in the below code.



* Create confirmation object
  CALL METHOD /sapsrm/cl_pdo_fact_conf_adv=>create_new_instance
    EXPORTING
      iv_subtype         = lc_cf
      iv_header_guid     = lv_po_guid
      iv_object_type     = lv_objtyp
      iv_logsys          = lv_po_logsys
      iv_object_id       = p_ls_po_header-object_id
      iv_user_type       = lc_profi
    IMPORTING
      eo_instance        = lo_bo_conf_adv
    CHANGING
      co_message_handler = p_lo_message_consumer.

thanks

Former Member
0 Kudos

Hello

Apologies, that just a copy past mistake

CALL METHOD /sapsrm/cl_pdo_fact_conf_adv=>create_new_instance

EXPORTING

iv_subtype = 'CA'

iv_header_guid = <Confermation header Guid>

IV_NUMBER_INT = <Item no>(optional)

iv_object_type = 'BUS2203'

iv_user_type = <type of user>( DSKTOP for standard user) or (PROFI for professional user)

IMPORTING

eo_instance = lo_bo_conf_adv

CHANGING

co_message_handler = p_lo_message_consumer.

former_member184741
Active Contributor
0 Kudos

hi,

no problem. i have tried this. i am getting the cancellation document number but the status is 'DELETED' at the header level in BBP_PD for the cancellation document. not sure why? if i do the cancellation from webgui it works fine.

thanks

Former Member
0 Kudos

In that case use the SUBTYPE as 'CF' instead of 'CA'. Try this option.

Regards.

former_member184741
Active Contributor
0 Kudos

hi

No i need to create cancellation so we should use CA

former_member184741
Active Contributor
0 Kudos

hi

what i am suspecting is the create_new_instance method actually calls delete_document inside it. so because we are calling that method explicitly again it is updating the status as delete? i will try by commenting the delete_documnent method and see what happens.

Former Member
0 Kudos

I have debugged it and found that the create instance is creating a new instance for the confirmation which shouldnu2019t happen.

When we use 'CA' as Subtype it treats it as a new deletion confirmation document. Hence if we want to use DELETE_DOCUMENT we shouldnu2019t be calling create_new_instance with 'CA' it won't work. Just get the Conf. Instance and then call delete_document or only call create_new_instance with subtype 'CA'. That will work.

Pls. try this one. It will definitely work.


  CALL METHOD /sapsrm/cl_pdo_fact_conf_adv=>create_new_instance
    EXPORTING
      iv_subtype         = 'CA'
      iv_header_guid     = lv_guid
      iv_object_type     = 'BUS2203'
*      iv_number_int      = '0000000001'
*      iv_logsys          = 'DXXCLNT010'
*      iv_object_id       = 'X000056XXX'
      iv_user_type       = 'DSKTOP'
    IMPORTING
      eo_instance        = lo_bo_conf_adv
    CHANGING
      co_message_handler = lo_message_consumer.

* Cast to PDO object
  lo_bo_conf ?= lo_bo_conf_adv.

* Set save flag
  CALL METHOD lo_bo_conf->set_save_or_park_flag
    EXPORTING
      iv_save_flag = abap_true.

* Confirm document
  CALL METHOD lo_bo_conf->confirm
    CHANGING
      co_message_handler = lo_message_consumer.

  COMMIT WORK.

OR


  CALL METHOD /sapsrm/cl_pdo_fact_conf_adv=>get_instance
    EXPORTING
      iv_header_guid = lv_guid
      iv_mode        = 'DISPLAY'
    RECEIVING
      ro_instance    = lo_bo_conf_adv.

** Then call the delete document on that.
  CALL METHOD lo_bo_conf_adv->/sapsrm/if_pdo_bo_conf~delete_document
    IMPORTING
      eo_instance        = lo_bo_conf_adv
    CHANGING
      co_message_handler = lo_message_consumer.

* Cast to PDO object
  lo_bo_conf ?= lo_bo_conf_adv.

* Set save flag
  CALL METHOD lo_bo_conf->set_save_or_park_flag
    EXPORTING
      iv_save_flag = abap_true.

* Confirm document
  CALL METHOD lo_bo_conf->confirm
    CHANGING
      co_message_handler = lo_message_consumer.
  COMMIT WORK.

Both Works.

former_member184741
Active Contributor
0 Kudos

hi Yadav,

even i was debugging the code yesterday and came to a similar conclusion. I really appreciate you for taking time and helping me out here. i am planning to write a blog/article about it in SDN, so that other people can take advantage of it.

thank you very much once again.

former_member184741
Active Contributor
0 Kudos

Hi Yadav,

one more clarification i need in this. when i am executing this methods in a FM manually with my id, the created_by and changed_by fields in the GR are getting updated by my user id. i want to updated these fields with some other user id. how can i do that. i have explored the structures of update_hdr and update_item methods of interface /sapsrm/if_pdo_bo_conf, bu surprisingly they don't have any field for created_by or changed_by. i went through the interface methods as well, but could not find anything relevant.

thanks

Former Member
0 Kudos

Try changing the system field SY-UNAME before calling the method and also Check the exporting parameter of DELETE_DOCUMENT method, it has created by Field.

former_member184741
Active Contributor
0 Kudos

hi yadav,

i am having another issue. as you know when you update the 'final entry' flag in gr system updates the po item also with 'no further confiramtions' radio button . is there any way i can remove this flags using some method and create new confirmations for the po item.

thanks

former_member184741
Active Contributor
0 Kudos

hi yadav

need your help again for updating the PO items. i using the below code. system is creating the change versions but with no items. not sure why



CALL FUNCTION 'BBP_PD_PO_GETDETAIL'
EXPORTING
*   I_GUID                           =
  I_OBJECT_ID                      =  po_no
*   I_ATTACH_WITH_DOC                = ' '
  I_WITH_ITEMDATA                  = 'X'
IMPORTING
  E_HEADER                         = ls_hdr
*   ET_ATTACH                        =
TABLES
  E_ITEM                           = lt_item .

data : obj_hdr_guid type BBP_GUID,
      lo_po_inst type ref to /SAPSRM/IF_PDO_BO_PO_ADV,
      lo_po type ref to /SAPSRM/IF_PDO_BO_PO.
obj_hdr_guid = ls_hdr-guid.
TRY.
CALL METHOD /sapsrm/cl_pdo_factory_po_adv=>get_instance
  EXPORTING
    iv_header_guid  = obj_hdr_guid
    iv_mode         =  'EDIT'
    iv_process_type = 'ECPO'
*    iv_wiid         =
*    iv_user_id      =
  RECEIVING
    ro_instance     = lo_po_inst
    .

lo_po ?= lo_po_inst.
data: lt_parguid type BBPT_GUID,
      ls_parguid like line of lt_parguid.
ls_parguid-guid = ls_hdr-guid.
append ls_parguid to lt_parguid.
CALL METHOD lo_po->/sapsrm/if_pdo_item_list~get_item_list
  EXPORTING
        it_parent_guid = lt_parguid
  IMPORTING
    et_item_guid   = lt_itmguid
    .


CALL METHOD lo_po->get_item_detail
  EXPORTING
    it_item_guid         = lt_itmguid
*    it_requested_fields  =
  IMPORTING
    et_item              =  lt_item
*    eo_meta_data_handler =
  CHANGING
   co_message_handler   = lo_msg
    .
data: lt_item_upd type BBPT_PD_PO_ITEM_ICU,
      ls_item_upd like line of lt_item_upd.
loop at lt_item into ls_item.
  move-corresponding ls_item to ls_item_upd.
  IF ls_item_upd-final_entry eq space.
     ls_item_upd-final_entry = 'S'.
  else.
     ls_item_upd-final_entry = 'D'.
  ENDIF.
  ls_item_upd-quantity = '3'.
  append ls_item_upd to lt_item_upd.
  clear : ls_item_upd, ls_item.
  endloop.

CALL METHOD lo_po->update_item
  EXPORTING
    it_item            = lt_item_upd
  CHANGING
    co_message_handler = lo_msg
    .
*TRY.
CALL METHOD lo_po->/sapsrm/if_pdo_base~submit_update
  CHANGING
    co_message_handler = lo_msg
    .
* CATCH /sapsrm/cx_pdo_wrong_mode .
* CATCH /sapsrm/cx_pdo_abort .
*ENDTRY.

CALL METHOD lo_po->order
  CHANGING
    co_message_handler = lo_msg
    .
CALL METHOD lo_msg->get_messages
              IMPORTING
                et_messages = lt_messages_class.

    CATCH /sapsrm/cx_pdo_incons_user
    /sapsrm/cx_pdo_lock_failed
* CATCH /sapsrm/cx_pdo_abort .

* CATCH /sapsrm/cx_pdo_error .


* CATCH /sapsrm/cx_pdo_no_authorizatio .
  /sapsrm/cx_pdo_no_authorizatio
  /sapsrm/cx_pdo_order_invalid
 /sapsrm/cx_pdo_parameter_error
  /sapsrm/cx_pdo_pd_read_error
  /sapsrm/cx_pdo_status_change
  /sapsrm/cx_pdo_status_error
  /sapsrm/cx_pdo_wf_mode_ban
  /sapsrm/cx_pdo_wrong_bus_type
  /sapsrm/cx_pdo_wrong_mode
    /sapsrm/cx_pdo_error
      /sapsrm/cx_pdo_abort into lo_root.
* CATCH /sapsrm/cx_pdo_abort .
* CATCH /sapsrm/cx_pdo_no_authorizatio .


  lv_msg = lo_root->get_text( ).



* CATCH /sapsrm/cx_pdo_abort .


ENDTRY.
commit work.

Answers (1)

Answers (1)

EmersonTosin
Explorer
0 Kudos

Hello Folks,

I have the same requirement, but it's not working. Any idea?

https://answers.sap.com/questions/13655888/srm-gr-cancellation-problem.html

Thanks,