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
TABLES: crmd_orderadm_h.
*--BAPI related data
TYPES: BEGIN OF bapi_notif_ext_type,
numb(12) TYPE c,
refnum(20) TYPE c,
type_notif(6) TYPE c,
category(12) TYPE c,
subject(60) TYPE c,
priority(1) TYPE c,
language TYPE lang,
END OF bapi_notif_ext_type,
BEGIN OF bapi_notif_crm_type,
code(4) TYPE c,
codegroup(8) TYPE c,
category(3) TYPE c,
END OF bapi_notif_crm_type,
BEGIN OF bapi_notif_p_ext_type,
parnr(12) TYPE c,
type_par(2) TYPE c,
func_par(2) TYPE c,
par_active(1) TYPE c,
END OF bapi_notif_p_ext_type,
BEGIN OF bapi_notif_n_ext_type,
type_note(4) TYPE c,
ident(30) TYPE c,
description(60) TYPE c,
END OF bapi_notif_n_ext_type,
BEGIN OF bapi_notif_s_ext_type,
instn(10) TYPE c,
mnumm(24) TYPE n,
mstat(1) TYPE c,
comp(20) TYPE c,
ossys(30) TYPE c,
dbsys(30) TYPE c,
front(30) TYPE c,
swcomp(30) TYPE c,
swrel(10) TYPE c,
swptch(10) TYPE c,
add_swcomp(1) TYPE c,
systype(1) TYPE c,
sysid(8) TYPE c,
mandt(3) TYPE c,
sap_tstmp(8) TYPE p DECIMALS 0,
s2sap_tstmp(8) TYPE p DECIMALS 0,
rel_sap_tstmp(8) TYPE p DECIMALS 0,
solnumb(15) TYPE n,
busprocobj1(10) TYPE n,
busprocobj2(10) TYPE n,
busprocobj3(10) TYPE n,
busprocobj4(10) TYPE n,
busprocobj5(10) TYPE n,
swcomponent1(10) TYPE n,
swcomponent2(10) TYPE n,
swcomponent3(10) TYPE n,
swcomponent4(10) TYPE n,
swcomponent5(10) TYPE n,
projectnumb(10) TYPE c,
rolloutphase(10) TYPE n,
sessino_src(13) TYPE c,
sessitype_src(2) TYPE c,
sessino_trg(13) TYPE c,
sessitype_trg(2) TYPE c,
s2sap_first(8) TYPE p DECIMALS 0,
s2sap_last(8) TYPE p DECIMALS 0,
sfrsap_first(8) TYPE p DECIMALS 0,
sfrsap_last(8) TYPE p DECIMALS 0,
time_at_sdesk TYPE int4,
time_at_sap TYPE int4,
step1(10) TYPE n,
step2(10) TYPE n,
step3(10) TYPE n,
step4(10) TYPE n,
step5(10) TYPE n,
sysno(18) TYPE c,
END OF bapi_notif_s_ext_type,
BEGIN OF bapi_text_header_ext_type,
txt_num(4) TYPE n,
language TYPE lang,
type_text(2) TYPE c,
timestamp(8) TYPE p DECIMALS 0,
last_usr(12) TYPE c,
END OF bapi_text_header_ext_type,
BEGIN OF bapi_text_lines_ext_type,
txt_num(4) TYPE n,
tdformat(2) TYPE c,
tdline(132) TYPE c,
END OF bapi_text_lines_ext_type,
BEGIN OF bapi_notif_appx_type,
descr(60) TYPE c,
appxno(4) TYPE n,
filetyp(3) TYPE c,
filenam(128) TYPE c,
filelen(12) TYPE n,
firstl(8) TYPE n,
lastl(8) TYPE n,
filefm_ul(3) TYPE c,
timestamp(8) TYPE p DECIMALS 0,
last_usr(12) TYPE c,
objkey(70) TYPE c,
END OF bapi_notif_appx_type,
BEGIN OF bapi_notif_soli_type,
line(255) TYPE c,
END OF bapi_notif_soli_type,
BEGIN OF bapi_notif_solix_type,
line(255) TYPE x,
END OF bapi_notif_solix_type.
*--Other types
TYPES: BEGIN OF t_tvarvc,
name TYPE tvarvc-name,
low TYPE tvarvc-low,
END OF t_tvarvc.
TYPES: BEGIN 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.
TYPES: BEGIN OF ty_activity,
guid TYPE crmt_object_guid,
priority TYPE crmt_priority,
END OF ty_activity.
TYPES: BEGIN OF ty_crby,
crby(20) TYPE c,
END OF ty_crby.
TYPES: BEGIN OF ty_but000,
partner TYPE bu_partner,
bu_sort1 TYPE bu_sort1,
END OF ty_but000.
TYPES: BEGIN 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.
DATA: it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
DATA: it_service TYPE TABLE OF ty_service,
wa_service TYPE ty_service.
DATA: it_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.
DATA: it_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.
DATA: it_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.
DATA: lt_text_all TYPE comt_text_textdata_t.
DATA: it_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.
DATA: it_crby TYPE TABLE OF ty_crby,
wa_crby TYPE ty_crby.
DATA: it_but000 TYPE TABLE OF ty_but000,
wa_but000 TYPE ty_but000.
CONSTANTS: c_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.
DATA: lv_l1 TYPE string.
DO.
IF strlen( lv_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
TYPES: BEGIN OF lala,
text(132) TYPE c,
END OF lala.
DATA: lt_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.
REFRESH: it_partners, it_sap_data, it_notif_text_headers, it_text_line.
CLEAR: it_notif_ext, it_notif_crm.
ENDIF.
ENDLOOP.
MESSAGE 'Tickets'' creation successful' TYPE 'S'.
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
TABLES: crmd_orderadm_h.
*--BAPI related data
TYPES: BEGIN OF bapi_notif_ext_type,
numb(12) TYPE c,
refnum(20) TYPE c,
type_notif(6) TYPE c,
category(12) TYPE c,
subject(60) TYPE c,
priority(1) TYPE c,
language TYPE lang,
END OF bapi_notif_ext_type,
BEGIN OF bapi_notif_crm_type,
code(4) TYPE c,
codegroup(8) TYPE c,
category(3) TYPE c,
END OF bapi_notif_crm_type,
BEGIN OF bapi_notif_p_ext_type,
parnr(12) TYPE c,
type_par(2) TYPE c,
func_par(2) TYPE c,
par_active(1) TYPE c,
END OF bapi_notif_p_ext_type,
BEGIN OF bapi_notif_n_ext_type,
type_note(4) TYPE c,
ident(30) TYPE c,
description(60) TYPE c,
END OF bapi_notif_n_ext_type,
BEGIN OF bapi_notif_s_ext_type,
instn(10) TYPE c,
mnumm(24) TYPE n,
mstat(1) TYPE c,
comp(20) TYPE c,
ossys(30) TYPE c,
dbsys(30) TYPE c,
front(30) TYPE c,
swcomp(30) TYPE c,
swrel(10) TYPE c,
swptch(10) TYPE c,
add_swcomp(1) TYPE c,
systype(1) TYPE c,
sysid(8) TYPE c,
mandt(3) TYPE c,
sap_tstmp(8) TYPE p DECIMALS 0,
s2sap_tstmp(8) TYPE p DECIMALS 0,
rel_sap_tstmp(8) TYPE p DECIMALS 0,
solnumb(15) TYPE n,
busprocobj1(10) TYPE n,
busprocobj2(10) TYPE n,
busprocobj3(10) TYPE n,
busprocobj4(10) TYPE n,
busprocobj5(10) TYPE n,
swcomponent1(10) TYPE n,
swcomponent2(10) TYPE n,
swcomponent3(10) TYPE n,
swcomponent4(10) TYPE n,
swcomponent5(10) TYPE n,
projectnumb(10) TYPE c,
rolloutphase(10) TYPE n,
sessino_src(13) TYPE c,
sessitype_src(2) TYPE c,
sessino_trg(13) TYPE c,
sessitype_trg(2) TYPE c,
s2sap_first(8) TYPE p DECIMALS 0,
s2sap_last(8) TYPE p DECIMALS 0,
sfrsap_first(8) TYPE p DECIMALS 0,
sfrsap_last(8) TYPE p DECIMALS 0,
time_at_sdesk TYPE int4,
time_at_sap TYPE int4,
step1(10) TYPE n,
step2(10) TYPE n,
step3(10) TYPE n,
step4(10) TYPE n,
step5(10) TYPE n,
sysno(18) TYPE c,
END OF bapi_notif_s_ext_type,
BEGIN OF bapi_text_header_ext_type,
txt_num(4) TYPE n,
language TYPE lang,
type_text(2) TYPE c,
timestamp(8) TYPE p DECIMALS 0,
last_usr(12) TYPE c,
END OF bapi_text_header_ext_type,
BEGIN OF bapi_text_lines_ext_type,
txt_num(4) TYPE n,
tdformat(2) TYPE c,
tdline(132) TYPE c,
END OF bapi_text_lines_ext_type,
BEGIN OF bapi_notif_appx_type,
descr(60) TYPE c,
appxno(4) TYPE n,
filetyp(3) TYPE c,
filenam(128) TYPE c,
filelen(12) TYPE n,
firstl(8) TYPE n,
lastl(8) TYPE n,
filefm_ul(3) TYPE c,
timestamp(8) TYPE p DECIMALS 0,
last_usr(12) TYPE c,
objkey(70) TYPE c,
END OF bapi_notif_appx_type,
BEGIN OF bapi_notif_soli_type,
line(255) TYPE c,
END OF bapi_notif_soli_type,
BEGIN OF bapi_notif_solix_type,
line(255) TYPE x,
END OF bapi_notif_solix_type.
*--Other types
TYPES: BEGIN OF t_tvarvc,
name TYPE tvarvc-name,
low TYPE tvarvc-low,
END OF t_tvarvc.
TYPES: BEGIN 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.
TYPES: BEGIN OF ty_activity,
guid TYPE crmt_object_guid,
priority TYPE crmt_priority,
END OF ty_activity.
TYPES: BEGIN OF ty_crby,
crby(20) TYPE c,
END OF ty_crby.
TYPES: BEGIN OF ty_but000,
partner TYPE bu_partner,
bu_sort1 TYPE bu_sort1,
END OF ty_but000.
TYPES: BEGIN 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.
DATA: it_final TYPE TABLE OF ty_final,
wa_final TYPE ty_final.
DATA: it_service TYPE TABLE OF ty_service,
wa_service TYPE ty_service.
DATA: it_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.
DATA: it_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.
DATA: it_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.
DATA: lt_text_all TYPE comt_text_textdata_t.
DATA: it_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.
DATA: it_crby TYPE TABLE OF ty_crby,
wa_crby TYPE ty_crby.
DATA: it_but000 TYPE TABLE OF ty_but000,
wa_but000 TYPE ty_but000.
CONSTANTS: c_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.
DATA: lv_l1 TYPE string.
DO.
IF strlen( lv_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
TYPES: BEGIN OF lala,
text(132) TYPE c,
END OF lala.
DATA: lt_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.
REFRESH: it_partners, it_sap_data, it_notif_text_headers, it_text_line.
CLEAR: it_notif_ext, it_notif_crm.
ENDIF.
ENDLOOP.
MESSAGE 'Tickets'' creation successful' TYPE 'S'.
Comments
Post a Comment