cancel
Showing results for 
Search instead for 
Did you mean: 

Create GR using BBP_PD_CONF_CREATE

Former Member
0 Kudos

Hi Experts

I have a requirement in which I have to automatically create GR from PO.

For this I have created an FM. In this FM I first call BBP_CF_ASSIGNMENT and then map the header structure(without the dummy guid as it gives error in the BBP_PD_CONF_CREATE FM) and the item table.

When I pass this data to BBP_PD_CONF_CREATE, my returned header structure has the new guid of confirmation but no object id, ie the confirmation number is not present. Also the returned item table is empty and when I try to save the confirmation I get the error 'Enter atleast one item'.

Please help me out. I have been stuck here for a very long time now.

Points will be rewarded.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Which version of SRM are you in ?. if you are above SRM 6.0 you can use Class (/sapsrm/if_pdo_bo_conf_adv and /sapsrm/if_pdo_bo_conf) create the confirmation.

Let me know i will send you a sample code.

Former Member
0 Kudos

Hi Surendra

I'm using SRM 7.1

I have tried that approach. I can create confirmation for some POs but not for all using the class.

I get a dump in create_conf_adv_instance method saying that : PO contains no items for confirmation.

Here is my code.


  lo_pd_model = /sapsrm/cl_pdo_model_factory=>get_instance( ).


  lo_pd_model->get_detail( EXPORTING iv_guid = im_po_guid
                                     iv_object_type = c_obj_typ_po
                           IMPORTING es_header   = ls_pd_header ).


  ls_selection-h_object_type = ls_pd_header-be_object_type.
*ls_selection-number_int    = 1.
  ls_selection-logsys        = ls_pd_header-be_log_system."itm logsys
  ls_selection-object_id     = im_po_num.
  APPEND ls_selection TO lt_selection.
  CREATE OBJECT l_helper.

  TRY.

      CALL METHOD l_helper->get_enriched_po_data_for_conf   "To get open PO items
        EXPORTING
          iv_object_type     = c_obj_typ_be
          iv_subtype         = c_subtyp
          it_selection       = lt_selection
          iv_user_info       = ls_user_info
          iv_mode            = c_mode_dspl
          iv_process_type    = c_process_type
          iv_no_messages     = abap_false
        IMPORTING
          et_cfitem          = li_cfitem
*         et_sdln_exist      = lt_sdln_exist
*         ev_sdln_exist      = lv_sdln_exist
        CHANGING
          co_message_handler = co_message_handler.

   CATCH /sapsrm/cx_pdo_abort.                          "#EC NO_HANDLER
   CATCH /sapsrm/cx_pdo_parameter_error.                "#EC NO_HANDLER
  ENDTRY.

 CALL METHOD /sapsrm/cl_pdo_bo_conf_adv=>create_conf_adv_instance
    EXPORTING
      iv_subtype         = c_subtyp
      iv_header_guid     = im_po_guid
      iv_object_type     = c_obj_typ_be
*     iv_number_int      = c_number_int
*     iv_logsys          =
      iv_object_id       = im_po_num
      iv_user_type       = c_user_typ
    IMPORTING
      eo_instance        = lo_conf
    CHANGING
      co_message_handler = co_message_handler.



*Getting header data of confirmation for updation
  TRY.
      CALL METHOD lo_conf->/sapsrm/if_pdo_bo_conf~get_header_detail
*  EXPORTING
*    it_requested_fields  =
        IMPORTING
          es_header            = ls_header_im
*    eo_meta_data_handler =
        CHANGING
          co_message_handler   = co_message_handler
          .
    CATCH /sapsrm/cx_pdo_abort .
  ENDTRY.


*Updating header data of confirmation
  MOVE-CORRESPONDING ls_header_im TO ls_header_ex.
  ls_header_ex-description = 'TEST 10/2/2012'.

  l_guid = ls_header_im-guid.

  TRY.
      CALL METHOD lo_conf->/sapsrm/if_pdo_bo_conf~update_header
        EXPORTING
          is_header          = ls_header_ex
        CHANGING
          co_message_handler = co_message_handler.
    CATCH /sapsrm/cx_pdo_wrong_mode .
    CATCH /sapsrm/cx_pdo_abort .
  ENDTRY.


*getting item data of confirmation
  CALL METHOD lo_conf->get_item_details_buffer
    IMPORTING
      et_itm_dtls_buf = li_item.

  LOOP AT li_cfitem INTO ls_cfitem.
    READ TABLE li_item ASSIGNING <fs_item>     
    WITH KEY number_int = ls_cfitem-number_int.
    IF sy-subrc EQ 0.

      MOVE-CORRESPONDING <fs_item> TO ls_item.
*Marking final entry in confirmation
      ls_item-final_entry = c_x.
      BREAK-POINT.
      CONCATENATE c_obj_typ_po
                  <fs_item>-be_refobj_item+7(3)
                  INTO l_be_refobj_item_hist.

      ls_object_key-h_object_type = c_obj_typ_po.                   "'BUS2201'.   "PO Header
      ls_object_key-i_object_type = l_be_refobj_item_hist.        "'BUS2201001'. "Po Item
      ls_object_key-logsys = 'T85-010'.
      MOVE im_po_guid TO ls_object_key-h_guid.
      READ TABLE li_item_po ASSIGNING <fs_item_po>   " li_item_po contains PO data fetched using BBP_PD_PO_GETDETAIL
      WITH KEY NUMBER_INT = <fs_item>-NUMBER_INT.
      IF sy-subrc eq 0.
        MOVE <fs_item_po>-guid TO ls_object_key-i_guid.
      ENDIF.

*       Get the PO Docuemnt History
      CALL FUNCTION 'BBP_PD_GETHISTORY'
        EXPORTING
          i_object_key                  = ls_object_key
        TABLES
          et_history                    = li_history
        EXCEPTIONS
          incomplete_object_information = 1
          OTHERS                        = 2.

      IF sy-subrc EQ 0.

        LOOP AT li_history INTO ls_history WHERE objtype EQ 'BUS2017'.

          IF ls_history-dcind EQ 'S'.    "Debit
            l_total_gr_qty = l_total_gr_qty + ls_history-quantity.
          ELSE."Credit
            l_total_gr_qty = l_total_gr_qty - ls_history-quantity.
          ENDIF.
          CLEAR ls_history.

        ENDLOOP.

        READ TABLE li_history INTO ls_history WITH KEY
        objtype = c_obj_typ_be. "'BUS2012'.
        IF sy-subrc EQ 0.
          l_total_po_qty = ls_history-quantity.
        ENDIF.

        ls_item-quantity = l_total_po_qty - l_total_gr_qty.
        BREAK-POINT.

      ENDIF.

      APPEND ls_item TO li_item_ex.
      CLEAR ls_item.
    ENDIF.

  ENDLOOP.

  TRY.
      CALL METHOD lo_conf->/sapsrm/if_pdo_bo_conf~update_item
        EXPORTING
          it_item            = li_item_ex
        CHANGING
          co_message_handler = co_message_handler.
    CATCH /sapsrm/cx_pdo_wrong_mode .
    CATCH /sapsrm/cx_pdo_abort .
  ENDTRY.

  TRY.
      CALL METHOD lo_conf->/sapsrm/if_pdo_base~submit_update
        CHANGING
          co_message_handler = co_message_handler.
    CATCH /sapsrm/cx_pdo_wrong_mode .
    CATCH /sapsrm/cx_pdo_abort .
  ENDTRY.


  TRY.
      CALL METHOD lo_conf->/sapsrm/if_pdo_adv_base~submit_decision
        CHANGING
          co_message_handler = co_message_handler.
    CATCH /sapsrm/cx_wf_decision_missing .
    CATCH /sapsrm/cx_pdo_error .
    CATCH /sapsrm/cx_pdo_abort .
  ENDTRY.

  TRY.
      CALL METHOD lo_conf->/sapsrm/if_pdo_base~save
*  EXPORTING
*    iv_msg_scenario    =
        CHANGING
          co_message_handler = co_message_handler
          .
    CATCH /sapsrm/cx_pdo_abort .
    CATCH /sapsrm/cx_pdo_error .
  ENDTRY.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     wait          = 'X'
* IMPORTING
*   RETURN        =
            .
  
*Confirming
    TRY.
        CALL METHOD lo_conf->/sapsrm/if_pdo_bo_conf~confirm
          CHANGING
            co_message_handler = co_message_handler.
      CATCH /sapsrm/cx_pdo_abort .
      CATCH /sapsrm/cx_pdo_order_invalid .
      CATCH /sapsrm/cx_pdo_status_change .
      CATCH /sapsrm/cx_pdo_no_authorizatio .
      CATCH /sapsrm/cx_pdo_ts_not_found .
      CATCH /sapsrm/cx_pdo_error .
    ENDTRY.

    

*Commit after confirmation completed
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
     EXPORTING
       wait          = 'X'
* IMPORTING
*   RETURN        =
              .

As I said, I dont know why but this code doesn't work for all the POs.

Please share your code/suggest modification to my code.

Also please share your contact details so that I can contact you, I'm stuck in this issue for a very long time and I need to close it asap.

Thanks

Ankit Pradhan

Former Member
0 Kudos

I didnt not understand the code as it is completely mixed up when you pasted it. pls. use below tags to place your code in SDN.

...

-> Displays the line as programming code.

look at below sample code.



  CONSTANTS: lc_cf      TYPE bbp_h_subtype    VALUE 'CF',
             lc_bus2012 TYPE swo_objtyp       VALUE 'BUS2012',
             lc_bus2201 TYPE swo_objtyp       VALUE 'BUS2201',
             lc_profi   TYPE bbp_iv_user_type VALUE 'PROFI'.

  DATA: lv_po_guid   TYPE bbp_guid,
        lv_po_logsys TYPE bbp_logsys,
        lv_objtyp    TYPE swo_objtyp.

  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.

  DATA: ls_conf_header     TYPE bbp_pds_conf_header_d,
        ls_conf_header_upd TYPE bbp_pds_conf_header_u,
        lt_conf_item       TYPE /sapsrm/t_pdo_conf_item_app,
        ls_conf_item       TYPE bbp_cf_item_app,
        lt_conf_item_upd   TYPE bbpt_pd_conf_item_icu,
        ls_conf_item_upd   TYPE bbp_pds_conf_item_icu.
       

  lv_po_guid   = p_ls_po_header-guid.
  lv_po_logsys = p_ls_po_header-be_log_system.

* Check if PO exists in backend
  IF lv_po_logsys IS INITIAL.
    lv_objtyp = lc_bus2201.
  ELSE.
    lv_objtyp = lc_bus2012.
  ENDIF.

* 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.

* Cast to PDO object
  lo_bo_conf ?= lo_bo_conf_adv.


* Get header data from PO
  CALL METHOD lo_bo_conf->get_header_detail
    IMPORTING
      es_header          = ls_conf_header
    CHANGING
      co_message_handler = p_lo_message_consumer.

* Add header data
  CLEAR: ls_conf_header_upd.
  MOVE-CORRESPONDING ls_conf_header TO ls_conf_header_upd.

*Update header
  CALL METHOD lo_bo_conf->update_header
    EXPORTING
      is_header          = ls_conf_header_upd
    CHANGING
      co_message_handler = p_lo_message_consumer.

* Get item data from PO
  CALL METHOD lo_bo_conf->get_item_details
    IMPORTING
      et_item            = lt_conf_item
    CHANGING
      co_message_handler = p_lo_message_consumer.

  LOOP AT lt_conf_item INTO ls_conf_item.
    MOVE-CORRESPONDING ls_conf_item TO ls_conf_item_upd.

      ls_conf_item_upd-quantity =  lv_qty.
.

    ls_conf_item_upd-selected = abap_true.

    APPEND ls_conf_item_upd TO lt_conf_item_upd.
    CLEAR  ls_conf_item_upd.

  ENDLOOP.

* Update item
  CALL METHOD lo_bo_conf->update_item
    EXPORTING
      it_item            = lt_conf_item_upd
    CHANGING
      co_message_handler = p_lo_message_consumer.

* Submit update
  CALL METHOD lo_bo_conf->/sapsrm/if_pdo_base~submit_update
    CHANGING
      co_message_handler = p_lo_message_consumer.

* 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 = p_lo_message_consumer.

Former Member
0 Kudos

Hi Surendra

I was able to use the FM.

Sorry for not pasting my code properly. I still can't figure out how to do that, otherwise I would shown it to you, even though I'm not using it.

Thanks to you, now I know 2 methods of creating confirmations.

Answers (0)