Header Ads

Code for using CRM_ORDER_READ

* Get Order details...
    lv_guid = iv_guid.

* insert values into importing tables for one order read .
    INSERT lv_guid INTO TABLE lt_header_guid.
    MOVE gc_object_name-orderadm_h TO lv_req_obj.  INSERT lv_req_obj INTO TABLE lt_req_obj ." header
    MOVE gc_object_name-partner    TO lv_req_obj.  INSERT lv_req_obj INTO TABLE lt_req_obj ." Partners
    MOVE gc_object_name-doc_flow   TO lv_req_obj.  INSERT lv_req_obj INTO TABLE lt_req_obj ." Documents
*    MOVE gc_object_name-orderadm_i TO lv_req_obj.  INSERT lv_req_obj INTO TABLE lt_req_obj ." Item details .

* Get the details of the appointment .
    CALL FUNCTION 'CRM_ORDER_READ'
      EXPORTING
        it_header_guid       = lt_header_guid
        it_requested_objects = lt_req_obj
      IMPORTING
        et_orderadm_h        = lt_orderadm_h
*        et_orderadm_i        = et_orderadm_i
        et_partner           = lt_partner
        et_doc_flow          = lt_doc_flow
      EXCEPTIONS
        document_not_found   = 1
        error_occurred       = 2
        document_locked      = 3
        no_change_authority  = 4
        no_display_authority = 5
        no_change_allowed    = 6
        OTHERS               = 7.

    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      RETURN.
    ENDIF.

    READ TABLE lt_orderadm_h ASSIGNING <fs_ord> INDEX 1.
    CHECK sy-subrc EQ 0.

*** Proceed only for Process type 'ZAPP'..........
    CHECK <fs_ord>-process_type EQ 'ZAPP' AND
*        lt_doc_flow[] IS NOT INITIAL    AND
          lt_partner[]  IS NOT INITIAL      .

********* Code for adding the Employee responsible when the appointment is created as a followon document ******
**Read employee responsible from lt_partner..
    READ TABLE lt_partner ASSIGNING <fs_part> WITH KEY ref_partner_fct =  lc_partner_ese_fct.
*  if sy-subrc eq 0.
    CHECK  sy-subrc EQ 0.
    MOVE <fs_part>-partner_no TO lv_partner_no.

**Read main partner..........

    CALL FUNCTION 'CRM_PARTNER_READ_OW'
      EXPORTING
        iv_ref_guid          = lv_guid
        iv_ref_kind          = 'A'
        iv_partner_fct       = '00000009'
        iv_mainpartner_only  = 'X'
      IMPORTING
        et_partner_wrk       = lt_mpart
        es_partner_wrk       = ls_mpart
      EXCEPTIONS
        error_occurred       = 1
        parameter_error      = 2
        entry_does_not_exist = 3
        OTHERS               = 4.

    MOVE ls_mpart-partner_no TO lv_mpart.

    CALL FUNCTION 'BUPA_RELATIONSHIPS_GET'
      EXPORTING
        iv_partner               = lv_mpart
        iv_relationship_category = 'BUR011'
      TABLES
        et_relationships         = lt_relations.

    IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*           WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
*********Read employee responsible from lt_partner..
*******  read table lt_partner assigning <fs_part> with key REF_PARTNER_FCT =  lc_partner_ese_fct.
********  if sy-subrc eq 0.
*******  check  sy-subrc eq 0.
*******  MOVE <fs_part>-partner_no TO lv_partner_no.
*  endif.             "  if sy-subrc eq 0.
    DESCRIBE TABLE lt_relations LINES lv_nr.
    IF lv_nr NE 0 .
*    READ TABLE lt_relations WITH  KEY partner2 =   lv_partner_no ASSIGNING <fs_rel> .
      READ TABLE lt_relations INTO ls_relations WITH  KEY partner2 =   lv_partner_no. " ASSIGNING <fs_rel> .
      IF sy-subrc NE 0 .
        CLEAR ls_relations.
        READ TABLE lt_relations INTO ls_relations WITH KEY defaultrelationship = 'X'.
        IF sy-subrc EQ 0.                    " In case Default Key is checked........
          CALL FUNCTION 'BAPI_BUPR_RELATIONSHIP_CREATE'
            EXPORTING
              businesspartner1     = lv_mpart
              businesspartner2     = lv_partner_no
              relationshipcategory = 'BUR011'.
*            TABLES
*              return               = lt_return.
        ELSE.                         " In Case Default Key is unchecked.........
          CALL FUNCTION 'BAPI_BUPR_RELATIONSHIP_CREATE'
            EXPORTING
              businesspartner1     = lv_mpart
              businesspartner2     = lv_partner_no
              relationshipcategory = 'BUR011'
              xdfrel               = 'X'.
*            TABLES
*              return               = lt_return.
        ENDIF.
      ENDIF.          " if sy-subrc ne 0.
    ELSE.
      CALL FUNCTION 'BAPI_BUPR_RELATIONSHIP_CREATE'
        EXPORTING
          businesspartner1     = lv_mpart
          businesspartner2     = lv_partner_no
          relationshipcategory = 'BUR011'
          xdfrel               = 'X'.
*            TABLES
*              return               = lt_return.
    ENDIF.  " if lv_nr GT 1.
    CALL FUNCTION 'BUPA_BSP_EMPLOYEE_SAVE'
      EXCEPTIONS
        not_saved = 1
        OTHERS    = 2.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.


*   Get the lead for which appointment is created as a follow-on document from document flow table .
    READ TABLE lt_doc_flow INTO ls_doc_flow WITH KEY objtype_a = lc_lead_obj
                                                     objtype_b = 'BUS2000126'
                                                     objkey_b  = <fs_ord>-guid .
    IF sy-subrc EQ 0.
      lv_guid_ = ls_doc_flow-objkey_a.
      IF lv_partner_no IS NOT INITIAL.
        MOVE <fs_part>-partner_no TO lv_partner_no.
* prepare the fields to be changed.
        CLEAR:ls_input_field.
        REFRESH: lt_input_field.
        ls_input_field-fieldname = lc_fieldname2.
        ls_input_field-inactive = space.
        INSERT ls_input_field INTO TABLE lt_input_field.
        CLEAR ls_input_field.

        ls_input_field-fieldname = lc_fieldname3.
        ls_input_field-inactive = space.
        INSERT ls_input_field INTO TABLE lt_input_field.
        CLEAR ls_input_field.

        ls_input_field-fieldname = lc_fieldname4.
        ls_input_field-inactive = space.
        INSERT ls_input_field INTO TABLE lt_input_field.
        CLEAR ls_input_field.

        ls_input_field-fieldname = lc_fieldname5.
        ls_input_field-inactive = space.
        INSERT ls_input_field INTO TABLE lt_input_field.
        CLEAR ls_input_field.

        ls_input_field-fieldname = lc_fieldname6.
*      ls_input_field-changeable = 'X'.
        ls_input_field-inactive = space.
        INSERT ls_input_field INTO TABLE lt_input_field.
        CLEAR ls_input_field.
* maintain employee responsible
        CLEAR ls_partner.
*      ls_partner-ref_handle    = lc_ref_handle .
        ls_partner-ref_guid      = lv_guid_.
************Get Partner Details............
*      CALL FUNCTION 'CRM_PARTNER_READ_OW'
*    EXPORTING
*      iv_ref_guid          = lv_guid
*      iv_ref_kind          = 'A'
*    IMPORTING
*      et_partner_wrk       = lt_part
*    EXCEPTIONS
*      error_occurred       = 1
*      parameter_error      = 2
*      entry_does_not_exist = 3
*      OTHERS               = 4.
*  IF sy-subrc <> 0.
*    EXIT.
*  ENDIF.
*  describe table lt_part lines lv_nr.
*
******************
        ls_partner-ref_kind      =  'A' .
        ls_partner-ref_partner_handle = '0001'.
*      ls_partner-kind_of_entry =  'C'.
        ls_partner-partner_fct   = lc_partner_ese_fct.
        ls_partner-partner_no    = lv_partner_no.
        ls_partner-display_type  = lc_display_type.
        ls_partner-no_type       = lc_no_type.

        CALL FUNCTION 'CRM_PARTNER_MAINTAIN_SINGLE_OW'
          EXPORTING
            iv_ref_guid          = lv_guid_
            iv_ref_kind          = 'A'
            is_partner_com       = ls_partner
          CHANGING
            ct_input_field_names = lt_input_field
          EXCEPTIONS
            error_occurred       = 1
            OTHERS               = 2.
        CLEAR: ls_partner.
        REFRESH: lt_input_field.
        REFRESH lt_header_guid.
        INSERT lv_guid_ INTO TABLE lt_header_guid.

        CALL FUNCTION 'CRM_ORDER_SAVE'
          EXPORTING
            it_objects_to_save = lt_header_guid
          EXCEPTIONS
            document_not_saved = 1
            OTHERS             = 2.
        IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      ENDIF.                             " if sy-subrc eq 0 for lt_partner.
    ENDIF.                               " if sy-subrc EQ 0 for lt_doc_flow
 
Powered by Blogger.