Report to create Support Tickets in Solution Manager using BAPI_NOTIFICATION_CREATE

Points to understand:
1) Go to table CRMD_ORDERADM_H and give old process type as 'SLFN' to see the old data.
2) New Process type is 'ZMIN'. Support Tickets will be created under new process type.
3) Use Transaction Code: SM_CRM to see the Incident. Give the Object ID generated in CRMD_ORDERADM_H for 'ZMIN' Process Type through the below program to see the Support Ticket Details.

REPORT  zag_support.

*--Data Declarations
TABLEScrmd_orderadm_h.

*--BAPI related data
TYPESBEGIN OF bapi_notif_ext_type,
         numb(12TYPE c,
         refnum(20TYPE c,
         type_notif(6TYPE c,
         category(12TYPE c,
         subject(60TYPE c,
         priority(1TYPE c,
         language TYPE lang,
       END OF bapi_notif_ext_type,

       BEGIN OF bapi_notif_crm_type,
         code(4TYPE c,
         codegroup(8TYPE c,
         category(3TYPE c,
       END OF bapi_notif_crm_type,

       BEGIN OF bapi_notif_p_ext_type,
         parnr(12TYPE c,
         type_par(2TYPE c,
         func_par(2TYPE c,
         par_active(1TYPE c,
       END OF bapi_notif_p_ext_type,

       BEGIN OF bapi_notif_n_ext_type,
         type_note(4TYPE c,
         ident(30TYPE c,
         description(60TYPE c,
       END OF bapi_notif_n_ext_type,

       BEGIN OF bapi_notif_s_ext_type,
         instn(10TYPE c,
         mnumm(24TYPE n,
         mstat(1TYPE c,
         comp(20TYPE c,
         ossys(30TYPE c,
         dbsys(30TYPE c,
         front(30TYPE c,
         swcomp(30TYPE c,
         swrel(10TYPE c,
         swptch(10TYPE c,
         add_swcomp(1TYPE c,
         systype(1TYPE c,
         sysid(8TYPE c,
         mandt(3TYPE c,
         sap_tstmp(8TYPE DECIMALS 0,
         s2sap_tstmp(8TYPE DECIMALS 0,
         rel_sap_tstmp(8TYPE DECIMALS 0,
         solnumb(15TYPE n,
         busprocobj1(10TYPE n,
         busprocobj2(10TYPE n,
         busprocobj3(10TYPE n,
         busprocobj4(10TYPE n,
         busprocobj5(10TYPE n,
         swcomponent1(10TYPE n,
         swcomponent2(10TYPE n,
         swcomponent3(10TYPE n,
         swcomponent4(10TYPE n,
         swcomponent5(10TYPE n,
         projectnumb(10TYPE c,
         rolloutphase(10TYPE n,
         sessino_src(13TYPE c,
         sessitype_src(2TYPE c,
         sessino_trg(13TYPE c,
         sessitype_trg(2TYPE c,
         s2sap_first(8TYPE DECIMALS 0,
         s2sap_last(8TYPE DECIMALS 0,
         sfrsap_first(8TYPE DECIMALS 0,
         sfrsap_last(8TYPE DECIMALS 0,
         time_at_sdesk TYPE int4,
         time_at_sap TYPE int4,
         step1(10TYPE n,
         step2(10TYPE n,
         step3(10TYPE n,
         step4(10TYPE n,
         step5(10TYPE n,
         sysno(18TYPE c,
       END OF bapi_notif_s_ext_type,

       BEGIN OF bapi_text_header_ext_type,
         txt_num(4TYPE n,
         language TYPE lang,
         type_text(2TYPE c,
         timestamp(8TYPE DECIMALS 0,
         last_usr(12TYPE c,
       END OF bapi_text_header_ext_type,

       BEGIN OF bapi_text_lines_ext_type,
         txt_num(4TYPE n,
         tdformat(2TYPE c,
         tdline(132TYPE c,
       END OF bapi_text_lines_ext_type,

       BEGIN OF bapi_notif_appx_type,
         descr(60TYPE c,
         appxno(4TYPE n,
         filetyp(3TYPE c,
         filenam(128TYPE c,
         filelen(12TYPE n,
         firstl(8TYPE n,
         lastl(8TYPE n,
         filefm_ul(3TYPE c,
         timestamp(8TYPE DECIMALS 0,
         last_usr(12TYPE c,
         objkey(70TYPE c,
       END OF bapi_notif_appx_type,

       BEGIN OF bapi_notif_soli_type,
         line(255TYPE c,
       END OF bapi_notif_soli_type,

       BEGIN OF bapi_notif_solix_type,
         line(255TYPE x,
       END OF bapi_notif_solix_type.

*--Other types
TYPESBEGIN OF t_tvarvc,
         name              TYPE tvarvc-name,
         low               TYPE tvarvc-low,
       END OF t_tvarvc.

TYPESBEGIN OF ty_service,
        guid TYPE crmt_object_guid,
        component TYPE /aicrm/dtel001c,
       END OF ty_service,

       BEGIN OF ty_text,
         guid TYPE crmt_object_guid,
         text TYPE string,
       END OF ty_text.

TYPESBEGIN OF ty_activity,
        guid TYPE crmt_object_guid,
        priority TYPE crmt_priority,
       END OF ty_activity.

TYPESBEGIN OF ty_crby,
        crby(20TYPE c,
       END OF ty_crby.
TYPESBEGIN OF ty_but000,
        partner TYPE bu_partner,
        bu_sort1 TYPE bu_sort1,
       END OF ty_but000.

TYPESBEGIN OF ty_final,
        guid TYPE crmt_object_guid,
        bpno TYPE crmt_created_by,
        priority TYPE crmt_priority,
        text TYPE string,
        description TYPE crmt_process_description,
        component TYPE /aicrm/dtel001c,
       END OF ty_final.

DATAit_final TYPE TABLE OF ty_final,
      wa_final TYPE ty_final.

DATAit_service TYPE TABLE OF ty_service,
      wa_service TYPE ty_service.

DATAit_text TYPE TABLE OF ty_text,
      it_text_text TYPE TABLE OF ty_text,
      wa_text_text TYPE ty_text,
      wa_text TYPE ty_text.

DATAit_notif_ext TYPE bapi_notif_ext_type,
      it_notif_crm TYPE bapi_notif_crm_type,

      it_text_line TYPE TABLE OF bapi_text_lines_ext_type,
      wa_text_line TYPE bapi_text_lines_ext_type,

      it_partners TYPE TABLE OF bapi_notif_p_ext_type,
      wa_partners TYPE bapi_notif_p_ext_type,

      it_sap_data TYPE TABLE OF bapi_notif_s_ext_type,
      wa_sap_data TYPE bapi_notif_s_ext_type,

      su_number TYPE bapi_notif_ext_type-refnum,

      it_appx_headers TYPE TABLE OF bapi_notif_appx_type,
      wa_appx_headers TYPE bapi_notif_appx_type,

      it_appx_lines TYPE TABLE OF bapi_notif_soli_type,
      wa_appx_lines TYPE bapi_notif_soli_type,

      it_appx_lines_bin  TYPE TABLE OF bapi_notif_solix_type,
      wa_appx_lines_bin  TYPE bapi_notif_solix_type,

      it_notif_notes TYPE TABLE OF bapi_notif_n_ext_type,
      wa_notif_notes TYPE bapi_notif_n_ext_type,

      it_notif_text_headers TYPE TABLE OF bapi_text_header_ext_type,
      wa_notif_text_headers TYPE bapi_text_header_ext_type.


DATAit_crmd TYPE TABLE OF crmd_orderadm_h,
      wa_crmd TYPE crmd_orderadm_h.

DATA l_timestamp TYPE tzntstmpl,
       l_timestamp1 TYPE tzonref-tstamps,
       l_seconds TYPE i.

DATA:  i_tvarvc  TYPE TABLE OF t_tvarvc,
       wa_tvarvc TYPE t_tvarvc.

DATAlt_text_all TYPE comt_text_textdata_t.

DATAit_activity TYPE TABLE OF ty_activity,
      wa_activity TYPE ty_activity.
FIELD-SYMBOLS<ls_textdata> LIKE LINE OF lt_text_all.

DATA:    lt_text_table   TYPE string_table,
         lv_string TYPE string,
         lv_flag(1) TYPE c.
DATAit_crby TYPE TABLE OF ty_crby,
      wa_crby TYPE ty_crby.
DATAit_but000 TYPE TABLE OF ty_but000,
      wa_but000 TYPE ty_but000.

CONSTANTSc_crlf        TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf.

START-OF-SELECTION.

* Get the Date & Time Range
  CONVERT DATE sy-datum TIME sy-uzeit
      INTO TIME STAMP l_timestamp1 TIME ZONE sy-zonlo.

* Get the time period from TVARVC
  SELECT name low
     FROM tvarvc
     INTO TABLE i_tvarvc
     WHERE  name 'Z_SRVDSK_WO_COMP_TIMEFRAME'
          OR name 'Z_SRVDSK_WO_COMP_EMAIL'.

  IF sy-subrc 0.
    READ TABLE i_tvarvc
             INTO wa_tvarvc
             WITH KEY name 'Z_SRVDSK_WO_COMP_TIMEFRAME'.
    IF sy-subrc 0.
      l_seconds wa_tvarvc-low.
    ENDIF.
  ENDIF.
  IF l_seconds IS NOT INITIAL.
    CALL METHOD cl_abap_tstmp=>subtractsecs
      EXPORTING
        tstmp   l_timestamp1
        secs    l_seconds
      RECEIVING
        r_tstmp l_timestamp.
  ENDIF.
*--Data Fetching
  SELECT FROM crmd_orderadm_h
     INTO TABLE it_crmd
     WHERE process_type 'SLFN' AND
           created_at BETWEEN l_timestamp AND l_timestamp1.

  IF it_crmd IS NOT INITIAL.
*--Fetching of BP No. from BUT000
    LOOP AT it_crmd INTO wa_crmd.
      wa_crby-crby wa_crmd-created_by.
      APPEND wa_crby TO it_crby.
      CLEAR wa_crby.
    ENDLOOP.

    SELECT partner
           bu_sort1
           FROM but000
           INTO TABLE it_but000
           FOR ALL ENTRIES IN it_crby
           WHERE bu_sort1 it_crby-crby.

*--Fetching Component from CRMD_SERVICE_H by passing the above GUIDs
    SELECT guid
           /aicrm/sap_comp
           FROM crmd_service_h
           INTO TABLE it_service
           FOR ALL ENTRIES IN it_crmd
           WHERE guid it_crmd-guid.

*--Fetching priorities for all GUIDs
    SELECT guid
           priority
           FROM crmd_activity_h
           INTO TABLE it_activity
           FOR ALL ENTRIES IN it_crmd
           WHERE guid it_crmd-guid.
  ENDIF.

*--Fetching Text for all GUIDs
  LOOP AT it_crmd INTO wa_crmd.
    CLEAR lv_flag.
    CALL FUNCTION 'CRM_DNO_READ_ORDER_TEXT'
      EXPORTING
        iv_header_guid wa_crmd-guid
      IMPORTING
        et_alltexts    lt_text_all.
    LOOP AT lt_text_all ASSIGNING <ls_textdata>.
      CALL FUNCTION 'CONVERT_ITF_TO_STREAM_TEXT'
        EXPORTING
          language     sy-langu
          lf           'X'
        IMPORTING
          stream_lines lt_text_table
        TABLES
          itf_text     <ls_textdata>-lines.
      LOOP AT lt_text_table INTO lv_string.
        DATAlv_l1 TYPE string.
        DO.
          IF strlenlv_string 130.
            lv_l1 lv_string+0(130).
            CONCATENATE wa_text-text lv_l1 INTO wa_text-text SEPARATED BY c_crlf.
            SHIFT lv_string BY 130 PLACES LEFT.
            CLEAR lv_l1.
          ELSE.
            lv_l1 lv_string.
            CONCATENATE wa_text-text lv_l1 INTO wa_text-text SEPARATED BY c_crlf.
            CLEAR lv_l1.
            EXIT.
          ENDIF.
        ENDDO.
      ENDLOOP.
IF lv_flag IS INITIAL.
CONCATENATE wa_text-text c_crlf c_crlf 'System Details:' c_crlf INTO wa_text-text.
lv_flag = 'X'.
ENDIF.

    ENDLOOP.
    wa_text-guid wa_crmd-guid.
    APPEND wa_text TO it_text.
    CLEAR wa_text.
  ENDLOOP.


*--Bringing all necessary details to it_final
  SORT it_crmd BY guid.
  LOOP AT it_crmd INTO wa_crmd.
    READ TABLE it_service INTO wa_service
                          WITH KEY guid wa_crmd-guid.
    IF sy-subrc EQ 0.
      READ TABLE it_activity INTO wa_activity
                             WITH KEY guid wa_crmd-guid.
      IF sy-subrc EQ 0.
        READ TABLE it_text INTO wa_text
                           WITH KEY guid wa_crmd-guid.
        IF sy-subrc EQ 0.
          READ TABLE it_but000 INTO wa_but000
                               WITH KEY bu_sort1 wa_crmd-created_by.
          IF sy-subrc EQ 0.
            wa_final-guid wa_crmd-guid.
            wa_final-bpno wa_but000-partner.
            wa_final-priority wa_activity-priority.
            wa_final-text wa_text-text.
            wa_final-description wa_crmd-description.
            wa_final-component wa_service-component.
            APPEND wa_final TO it_final.
            CLEAR wa_final.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDLOOP.

*--Final assembly and BAPI process
  LOOP AT it_final INTO wa_final.

*--Collecting values to pass to BAPI
*--For IT_NOTIF_EXT
    it_notif_ext-subject wa_final-description.
    it_notif_ext-priority wa_final-priority.
    it_notif_ext-type_notif 'ZMIN'.
    it_notif_ext-language 'E'.

*--For IT_NOTIF_CRM

*--For IT_PARTNERS
    wa_partners-parnr wa_final-bpno.
    wa_partners-type_par 'BP'.
    wa_partners-func_par 'RP'.
    APPEND wa_partners TO it_partners.
    CLEAR wa_partners.

*--For IT_NOTIF_NOTES


*--For IT_SAP_DATA
    wa_sap_data-instn '0020211464'.
    wa_sap_data-comp =  wa_final-component.
    wa_sap_data-swcomp 'SAP_BASIS'.
    wa_sap_data-ossys 'AIX 5.3'.
    wa_sap_data-dbsys 'ORACLE 10.2.0.2.0'.
    wa_sap_data-swrel '700'.
    wa_sap_data-swptch '0008'.
    wa_sap_data-systype 'T'.
    wa_sap_data-mandt '200'.
    wa_sap_data-sysid 'SP1'.
    APPEND wa_sap_data TO it_sap_data.
    CLEAR wa_sap_data.

*--For IT_NOTIF_TEXT_HEADERS
    wa_notif_text_headers-txt_num ='0001'.
    wa_notif_text_headers-language ='EN'.
    wa_notif_text_headers-type_text ='99'.
    wa_notif_text_headers-last_usr '3P_PRAKASHN'.
    APPEND wa_notif_text_headers TO it_notif_text_headers.
    CLEAR wa_notif_text_headers.

*--For IT_TEXT_LINE
    TYPESBEGIN OF lala,
            text(132TYPE c,
          END OF lala.
    DATAlt_split TYPE TABLE OF lala,
          wa_split TYPE lala.
    SPLIT wa_final-text AT c_crlf INTO TABLE lt_split.
    REFRESH it_text_line.
    LOOP AT lt_split INTO wa_split.
      wa_text_line-tdline wa_split-text.
      wa_text_line-txt_num '0001'.
      wa_text_line-tdformat '/'.     " For new line
      APPEND wa_text_line TO it_text_line.
      CLEAR wa_text_line.
    ENDLOOP.

*--Support Message Creation using BAPI
    CALL FUNCTION 'BAPI_NOTIFICATION_CREATE'
      EXPORTING
        notif_ext          it_notif_ext           "Has values
        notif_crm          it_notif_crm           "Has values
      TABLES
        notif_partners     it_partners            "Has values
        notif_notes        it_notif_notes
        notif_sap_data     it_sap_data            "Has values
        notif_text_headers it_notif_text_headers  "Has values
        notif_text_lines   it_text_line           "Has values
        appx_headers       it_appx_headers
        appx_lines         it_appx_lines
        appx_lines_bin     it_appx_lines_bin.
    IF sy-subrc EQ 0.
      REFRESHit_partnersit_sap_datait_notif_text_headersit_text_line.
      CLEARit_notif_extit_notif_crm.
    ENDIF.
  ENDLOOP.
  MESSAGE 'Tickets'' creation successful' TYPE 'S'.

Comments

Popular posts from this blog

EWM PPF Trigger the existing PPF Action through Custom Program

ABAP 7.5 - FILTER Statement

Useful Transaction Codes / Tools in OData ABAP Service / SAP UI5/ SAP Fiori