*& Report YPS_SHC_SEND_MAIL_2
*&
*&---------------------------------------------------------------------*
*& Purpose : This report is used to send a list of WBS which is INST *
*& Set. The report output is needed to be send as a mail *
*& for approval. *
*&-------------------------------------------------------------------
REPORT yps_shc_send_mail_2.
***********************************************************************
* G L O B A L V A R I A B L E S
***********************************************************************
CONSTANTS: lc_bcbatch TYPE syuname VALUE 'BC-BATCH'.
***--- data declaration for mail sending
DATA: gv_packing_list LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: gv_object_header LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: gv_contents_bin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: gv_contents_txt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: gv_receivers LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: gi_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0.
DATA: gw_message TYPE solisti1 .
DATA: gv_document_data LIKE sodocchgi1.
DATA: gv_lines LIKE sy-tabix.
***--- Binary store for PDF
TYPES: BEGIN OF gt_pdf_output.
INCLUDE STRUCTURE tline.
TYPES: END OF gt_pdf_output.
TYPES: BEGIN OF gt_receiver,
email TYPE ymm_email_recei-email,
END OF gt_receiver.
DATA: gi_receiver TYPE TABLE OF gt_receiver.
DATA: gw_receiver TYPE gt_receiver.
DATA: gi_pdf_output TYPE TABLE OF gt_pdf_output.
DATA: gw_pdf_output TYPE gt_pdf_output.
DATA: gi_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE.
***--- Spool to PDF conversions
DATA: gv_spool_nr LIKE tsp01-rqident,
gv_rqcretime LIKE tsp01-rqcretime,
gv_destination LIKE rlgrap-filename,
gv_bytecount LIKE tst01-dsize,
gv_buffer TYPE string.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
DATA: lv_mailid TYPE ad_smtpadr.
DATA: tab_lines TYPE i.
SELECT-OPTIONS: s_mailid FOR lv_mailid NO INTERVALS.
PARAMETER: p_user TYPE sy-uname.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
***--- fetch the list of receivers.
PERFORM f_fetch_receiver_list.
***--- populate message table.
PERFORM f_populate_message_table.
**--- send message to the user.
PERFORM f_send_message.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form fetch_receiver_list
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_fetch_receiver_list.
LOOP AT s_mailid.
gw_receiver-email = s_mailid-low.
APPEND gw_receiver TO gi_receiver.
CLEAR: gw_receiver.
ENDLOOP.
IF gi_receiver IS INITIAL.
MESSAGE e000(ymm) WITH 'No receivers found'.
LEAVE PROGRAM.
ENDIF.
ENDFORM. "fetch_receiver_list
*&---------------------------------------------------------------------*
*& Form populate_message_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_populate_message_table.
gw_message = text-005.
APPEND gw_message TO gi_message.
gw_message = text-002.
APPEND gw_message TO gi_message.
gw_message = '</span>'.
APPEND gw_message TO gi_message.
gw_message = '<P>'.
APPEND gw_message TO gi_message.
gw_message = text-003.
APPEND gw_message TO gi_message.
***This is an automatic scan of CTI's Project Management and Billing system.
gw_message = text-004.
APPEND gw_message TO gi_message.
gw_message = text-006.
APPEND gw_message TO gi_message.
gw_message = text-007.
APPEND gw_message TO gi_message.
gw_message = text-017.
APPEND gw_message TO gi_message.
gw_message = text-008.
APPEND gw_message TO gi_message.
gw_message = '</P>'.
APPEND gw_message TO gi_message.
gw_message = '<P>'.
APPEND gw_message TO gi_message.
gw_message = text-018.
APPEND gw_message TO gi_message.
gw_message = '</P>'.
APPEND gw_message TO gi_message.
gw_message = text-012.
APPEND gw_message TO gi_message.
gw_message = text-009.
APPEND gw_message TO gi_message.
gw_message = text-011.
APPEND gw_message TO gi_message.
gw_message = text-010.
APPEND gw_message TO gi_message.
gw_message = '</span>'.
APPEND gw_message TO gi_message.
ENDFORM. "populate_message_table
*&---------------------------------------------------------------------*
*& Form send_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_send_message.
CLEAR: gv_spool_nr, gv_bytecount, gi_pdf_output, gw_pdf_output,
gv_buffer, gv_destination, gv_packing_list, gv_contents_bin,
gv_receivers, gv_rqcretime.
*** find the latest spool generated by the PR delete program
SELECT MAX( rqcretime )
FROM tsp01
INTO gv_rqcretime
WHERE rq0name = 'LIST1S' AND
rq2name = 'YPS_SD_SHC_2' AND
rqowner = p_user AND
rqdoctype = 'LIST'.
SELECT MAX( rqident )
FROM tsp01
INTO gv_spool_nr
WHERE rq0name = 'LIST1S' AND
rq2name = 'YPS_SD_SHC_2' AND
rqowner = p_user AND
rqdoctype = 'LIST' AND
rqcretime = gv_rqcretime.
*** function to conver the spool into pdf format.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gv_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gv_bytecount
TABLES
pdf = gi_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
*** convert the pdf into attachment.
* Transfer the 132-long strings to 255-long strings
LOOP AT gi_pdf_output INTO gw_pdf_output.
TRANSLATE gw_pdf_output USING ' ~'.
CONCATENATE gv_buffer gw_pdf_output INTO gv_buffer.
ENDLOOP.
TRANSLATE gv_buffer USING '~ '.
DO.
gi_mess_att = gv_buffer.
APPEND gi_mess_att.
SHIFT gv_buffer LEFT BY 255 PLACES.
IF gv_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
*** Fill the document data.
gv_document_data-doc_size = 1.
*
*** Populate the subject/generic message attributes
* gv_document_data-obj_langu = sy-langu.
** gv_document_data-obj_name = 'SAPRPT'.
* gv_document_data-obj_descr = 'Status List of PR'.
* gv_document_data-sensitivty = 'F'.
*
*** Fill the document data and get size of attachment
READ TABLE gi_mess_att INDEX gv_lines.
gv_document_data-doc_size =
( gv_lines - 1 ) * 255 + STRLEN( gi_mess_att ).
gv_document_data-obj_langu = sy-langu.
gv_document_data-obj_name = 'SAPRPT'.
gv_document_data-obj_descr = text-m01.
gv_document_data-sensitivty = 'F'.
CLEAR gv_contents_bin.
REFRESH gv_contents_bin.
gv_contents_bin[] = gi_mess_att[].
*** Describe the body of the message
CLEAR gv_packing_list.
REFRESH gv_packing_list.
** changes to include the html body.
DESCRIBE TABLE gi_message LINES tab_lines.
READ TABLE gi_message INTO gw_message INDEX tab_lines.
gv_document_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( gw_message ).
gv_packing_list-head_start = 1.
gv_packing_list-head_num = 0.
gv_packing_list-body_start = 1.
gv_packing_list-body_num = tab_lines.
gv_packing_list-doc_type = 'HTM'.
APPEND gv_packing_list.
** Create attachment notification
gv_packing_list-transf_bin = 'X'.
gv_packing_list-head_start = 1.
gv_packing_list-head_num = 1.
gv_packing_list-body_start = 1.
DESCRIBE TABLE gi_mess_att LINES gv_packing_list-body_num.
gv_packing_list-doc_type = 'PDF'.
gv_packing_list-obj_descr = text-m01.
* gv_packing_list-obj_name = ld_attfilename.
gv_packing_list-doc_size = gv_packing_list-body_num * 255.
APPEND gv_packing_list.
*** Add the recipients email address
LOOP AT gi_receiver INTO gw_receiver.
CLEAR gv_receivers.
gv_receivers-receiver = gw_receiver-email.
gv_receivers-rec_type = 'U'.
gv_receivers-com_type = 'INT'.
gv_receivers-notif_del = 'X'.
gv_receivers-notif_ndel = 'X'.
APPEND gv_receivers.
ENDLOOP.
*** send mail function.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gv_document_data
put_in_outbox = 'X'
* sender_address = ld_sender_address
* sender_address_type = ld_sender_address_type
commit_work = 'X'
* IMPORTING
* sent_to_all = w_sent_all
TABLES
packing_list = gv_packing_list
contents_bin = gv_contents_bin
contents_txt = gi_message
receivers = gv_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
CASE sy-subrc.
WHEN 0.
COMMIT WORK AND WAIT.
WRITE: / text-p01.
LOOP AT gv_receivers.
WRITE: / gv_receivers-receiver(48), ':'.
IF gv_receivers-retrn_code = 0.
WRITE text-p02.
ELSE.
WRITE text-p03.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / text-p04.
WHEN 2.
WRITE: / text-p05.
WHEN 4.
WRITE: / text-p06.
WHEN OTHERS.
WRITE: / text-p07.
ENDCASE.
***--- send the email immediately.
WAIT UP TO 3 SECONDS.
SUBMIT rsconn01
WITH mode EQ 'INT'
AND RETURN.
ENDFORM. "send_message
*&
*&---------------------------------------------------------------------*
*& Purpose : This report is used to send a list of WBS which is INST *
*& Set. The report output is needed to be send as a mail *
*& for approval. *
*&-------------------------------------------------------------------
REPORT yps_shc_send_mail_2.
***********************************************************************
* G L O B A L V A R I A B L E S
***********************************************************************
CONSTANTS: lc_bcbatch TYPE syuname VALUE 'BC-BATCH'.
***--- data declaration for mail sending
DATA: gv_packing_list LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: gv_object_header LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: gv_contents_bin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: gv_contents_txt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: gv_receivers LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: gi_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0.
DATA: gw_message TYPE solisti1 .
DATA: gv_document_data LIKE sodocchgi1.
DATA: gv_lines LIKE sy-tabix.
***--- Binary store for PDF
TYPES: BEGIN OF gt_pdf_output.
INCLUDE STRUCTURE tline.
TYPES: END OF gt_pdf_output.
TYPES: BEGIN OF gt_receiver,
email TYPE ymm_email_recei-email,
END OF gt_receiver.
DATA: gi_receiver TYPE TABLE OF gt_receiver.
DATA: gw_receiver TYPE gt_receiver.
DATA: gi_pdf_output TYPE TABLE OF gt_pdf_output.
DATA: gw_pdf_output TYPE gt_pdf_output.
DATA: gi_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE.
***--- Spool to PDF conversions
DATA: gv_spool_nr LIKE tsp01-rqident,
gv_rqcretime LIKE tsp01-rqcretime,
gv_destination LIKE rlgrap-filename,
gv_bytecount LIKE tst01-dsize,
gv_buffer TYPE string.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
DATA: lv_mailid TYPE ad_smtpadr.
DATA: tab_lines TYPE i.
SELECT-OPTIONS: s_mailid FOR lv_mailid NO INTERVALS.
PARAMETER: p_user TYPE sy-uname.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION *
*&---------------------------------------------------------------------*
START-OF-SELECTION.
***--- fetch the list of receivers.
PERFORM f_fetch_receiver_list.
***--- populate message table.
PERFORM f_populate_message_table.
**--- send message to the user.
PERFORM f_send_message.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form fetch_receiver_list
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_fetch_receiver_list.
LOOP AT s_mailid.
gw_receiver-email = s_mailid-low.
APPEND gw_receiver TO gi_receiver.
CLEAR: gw_receiver.
ENDLOOP.
IF gi_receiver IS INITIAL.
MESSAGE e000(ymm) WITH 'No receivers found'.
LEAVE PROGRAM.
ENDIF.
ENDFORM. "fetch_receiver_list
*&---------------------------------------------------------------------*
*& Form populate_message_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_populate_message_table.
gw_message = text-005.
APPEND gw_message TO gi_message.
gw_message = text-002.
APPEND gw_message TO gi_message.
gw_message = '</span>'.
APPEND gw_message TO gi_message.
gw_message = '<P>'.
APPEND gw_message TO gi_message.
gw_message = text-003.
APPEND gw_message TO gi_message.
***This is an automatic scan of CTI's Project Management and Billing system.
gw_message = text-004.
APPEND gw_message TO gi_message.
gw_message = text-006.
APPEND gw_message TO gi_message.
gw_message = text-007.
APPEND gw_message TO gi_message.
gw_message = text-017.
APPEND gw_message TO gi_message.
gw_message = text-008.
APPEND gw_message TO gi_message.
gw_message = '</P>'.
APPEND gw_message TO gi_message.
gw_message = '<P>'.
APPEND gw_message TO gi_message.
gw_message = text-018.
APPEND gw_message TO gi_message.
gw_message = '</P>'.
APPEND gw_message TO gi_message.
gw_message = text-012.
APPEND gw_message TO gi_message.
gw_message = text-009.
APPEND gw_message TO gi_message.
gw_message = text-011.
APPEND gw_message TO gi_message.
gw_message = text-010.
APPEND gw_message TO gi_message.
gw_message = '</span>'.
APPEND gw_message TO gi_message.
ENDFORM. "populate_message_table
*&---------------------------------------------------------------------*
*& Form send_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_send_message.
CLEAR: gv_spool_nr, gv_bytecount, gi_pdf_output, gw_pdf_output,
gv_buffer, gv_destination, gv_packing_list, gv_contents_bin,
gv_receivers, gv_rqcretime.
*** find the latest spool generated by the PR delete program
SELECT MAX( rqcretime )
FROM tsp01
INTO gv_rqcretime
WHERE rq0name = 'LIST1S' AND
rq2name = 'YPS_SD_SHC_2' AND
rqowner = p_user AND
rqdoctype = 'LIST'.
SELECT MAX( rqident )
FROM tsp01
INTO gv_spool_nr
WHERE rq0name = 'LIST1S' AND
rq2name = 'YPS_SD_SHC_2' AND
rqowner = p_user AND
rqdoctype = 'LIST' AND
rqcretime = gv_rqcretime.
*** function to conver the spool into pdf format.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gv_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gv_bytecount
TABLES
pdf = gi_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11
OTHERS = 12.
CHECK sy-subrc = 0.
*** convert the pdf into attachment.
* Transfer the 132-long strings to 255-long strings
LOOP AT gi_pdf_output INTO gw_pdf_output.
TRANSLATE gw_pdf_output USING ' ~'.
CONCATENATE gv_buffer gw_pdf_output INTO gv_buffer.
ENDLOOP.
TRANSLATE gv_buffer USING '~ '.
DO.
gi_mess_att = gv_buffer.
APPEND gi_mess_att.
SHIFT gv_buffer LEFT BY 255 PLACES.
IF gv_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
*** Fill the document data.
gv_document_data-doc_size = 1.
*
*** Populate the subject/generic message attributes
* gv_document_data-obj_langu = sy-langu.
** gv_document_data-obj_name = 'SAPRPT'.
* gv_document_data-obj_descr = 'Status List of PR'.
* gv_document_data-sensitivty = 'F'.
*
*** Fill the document data and get size of attachment
READ TABLE gi_mess_att INDEX gv_lines.
gv_document_data-doc_size =
( gv_lines - 1 ) * 255 + STRLEN( gi_mess_att ).
gv_document_data-obj_langu = sy-langu.
gv_document_data-obj_name = 'SAPRPT'.
gv_document_data-obj_descr = text-m01.
gv_document_data-sensitivty = 'F'.
CLEAR gv_contents_bin.
REFRESH gv_contents_bin.
gv_contents_bin[] = gi_mess_att[].
*** Describe the body of the message
CLEAR gv_packing_list.
REFRESH gv_packing_list.
** changes to include the html body.
DESCRIBE TABLE gi_message LINES tab_lines.
READ TABLE gi_message INTO gw_message INDEX tab_lines.
gv_document_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( gw_message ).
gv_packing_list-head_start = 1.
gv_packing_list-head_num = 0.
gv_packing_list-body_start = 1.
gv_packing_list-body_num = tab_lines.
gv_packing_list-doc_type = 'HTM'.
APPEND gv_packing_list.
** Create attachment notification
gv_packing_list-transf_bin = 'X'.
gv_packing_list-head_start = 1.
gv_packing_list-head_num = 1.
gv_packing_list-body_start = 1.
DESCRIBE TABLE gi_mess_att LINES gv_packing_list-body_num.
gv_packing_list-doc_type = 'PDF'.
gv_packing_list-obj_descr = text-m01.
* gv_packing_list-obj_name = ld_attfilename.
gv_packing_list-doc_size = gv_packing_list-body_num * 255.
APPEND gv_packing_list.
*** Add the recipients email address
LOOP AT gi_receiver INTO gw_receiver.
CLEAR gv_receivers.
gv_receivers-receiver = gw_receiver-email.
gv_receivers-rec_type = 'U'.
gv_receivers-com_type = 'INT'.
gv_receivers-notif_del = 'X'.
gv_receivers-notif_ndel = 'X'.
APPEND gv_receivers.
ENDLOOP.
*** send mail function.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = gv_document_data
put_in_outbox = 'X'
* sender_address = ld_sender_address
* sender_address_type = ld_sender_address_type
commit_work = 'X'
* IMPORTING
* sent_to_all = w_sent_all
TABLES
packing_list = gv_packing_list
contents_bin = gv_contents_bin
contents_txt = gi_message
receivers = gv_receivers
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
CASE sy-subrc.
WHEN 0.
COMMIT WORK AND WAIT.
WRITE: / text-p01.
LOOP AT gv_receivers.
WRITE: / gv_receivers-receiver(48), ':'.
IF gv_receivers-retrn_code = 0.
WRITE text-p02.
ELSE.
WRITE text-p03.
ENDIF.
ENDLOOP.
WHEN 1.
WRITE: / text-p04.
WHEN 2.
WRITE: / text-p05.
WHEN 4.
WRITE: / text-p06.
WHEN OTHERS.
WRITE: / text-p07.
ENDCASE.
***--- send the email immediately.
WAIT UP TO 3 SECONDS.
SUBMIT rsconn01
WITH mode EQ 'INT'
AND RETURN.
ENDFORM. "send_message
No comments:
Post a Comment