CLASSICAL REPORT WITH MAIL
*&---------------------------------------------------------------------*
*& Form REPORT_LIST_FROM_MEMORY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM report_list_from_memory_del .
SUBMIT zsr_test EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form LIST_TO_ASCI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM list_to_asci_details .
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listobject = listobject
listasci = listasci
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form LIST_TO_HTML_FORMAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM list_to_html_format_details .
CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
TABLES
html = html
listobject = listobject.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_SUBJECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM mail_subject_details .
CLEAR: document_data, wa_content, wa_rec.
REFRESH: object_content, receivers.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = sy-datum
IMPORTING
date_external = v_date
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
document_data-obj_name = 'FERT'.
CONCATENATE 'Finished Goods Materials for' v_date
INTO document_data-obj_descr SEPARATED BY space.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_CONTENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM mail_content_details .
LOOP AT html INTO wa_html.
wa_content = wa_html.
APPEND wa_content TO object_content.
CLEAR: wa_content.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_RECEIVERS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM mail_receivers_details .
LOOP AT s_email.
wa_rec-receiver = s_email-low.
wa_rec-rec_type = 'U'.
wa_rec-express = 'X'..
APPEND wa_rec TO receivers.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SEND_MAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM send_mail_option_details .
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
document_type = 'HTM'
put_in_outbox = 'X'
TABLES
object_content = object_content
receivers = 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.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
ENDFORM.
REPORT zsr_test NO STANDARD PAGE HEADING.
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
END OF ty_mara.
DATA: wa_mara TYPE ty_mara,
it_mara TYPE TABLE OF ty_mara.
START-OF-SELECTION.
PERFORM get_mara.
PERFORM classical_output.
*&---------------------------------------------------------------------*
*& Form GET_MARA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_mara .
SELECT matnr ersda ernam mtart matkl
FROM mara INTO TABLE it_mara
WHERE mtart = 'FERT'.
IF sy-subrc = 0.
SORT it_mara BY ersda DESCENDING.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CLASSICAL_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM classical_output .
ULINE AT /0(60).
WRITE: / '|', 2 'Material' COLOR 3, 21 '|',
22 'Created On' COLOR 3, 34 '|',
35 'Created By' COLOR 3, 49 '|',
50 'Group' COLOR 3, 60 '|'.
ULINE AT /0(60).
LOOP AT it_mara INTO wa_mara.
WRITE: / '|', 2 wa_mara-matnr, 21 '|',
22 wa_mara-ersda DD/MM/YYYY, 34 '|',
35 wa_mara-ernam, 49 '|',
50 wa_mara-matkl, 60 '|'.
ENDLOOP.
ULINE AT /0(60).
ENDFORM.
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr,
ersda TYPE mara-ersda,
ernam TYPE mara-ernam,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
END OF ty_mara.
DATA: wa_mara TYPE ty_mara,
it_mara TYPE TABLE OF ty_mara.
START-OF-SELECTION.
PERFORM get_mara.
PERFORM classical_output.
*&---------------------------------------------------------------------*
*& Form GET_MARA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_mara .
SELECT matnr ersda ernam mtart matkl
FROM mara INTO TABLE it_mara
WHERE mtart = 'FERT'.
IF sy-subrc = 0.
SORT it_mara BY ersda DESCENDING.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CLASSICAL_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM classical_output .
ULINE AT /0(60).
WRITE: / '|', 2 'Material' COLOR 3, 21 '|',
22 'Created On' COLOR 3, 34 '|',
35 'Created By' COLOR 3, 49 '|',
50 'Group' COLOR 3, 60 '|'.
ULINE AT /0(60).
LOOP AT it_mara INTO wa_mara.
WRITE: / '|', 2 wa_mara-matnr, 21 '|',
22 wa_mara-ersda DD/MM/YYYY, 34 '|',
35 wa_mara-ernam, 49 '|',
50 wa_mara-matkl, 60 '|'.
ENDLOOP.
ULINE AT /0(60).
ENDFORM.
Mail Sending Program
REPORT zsr_test1 NO STANDARD PAGE HEADING.
DATA: document_data TYPE sodocchgi1,
wa_content TYPE solisti1,
object_content TYPE TABLE OF solisti1,
wa_rec TYPE somlrec90,
receivers TYPE TABLE OF somlrec90,
listobject TYPE TABLE OF abaplist,
listasci(1024) TYPE c OCCURS 0 WITH HEADER LINE,
wa_html TYPE w3html,
html TYPE TABLE OF w3html,
v_date TYPE char10.
INITIALIZATION.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
SELECT-OPTIONS s_email FOR wa_rec-receiver NO INTERVALS.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM report_list_from_memory_del.
PERFORM list_to_asci_details.
PERFORM list_to_html_format_details.
DATA: document_data TYPE sodocchgi1,
wa_content TYPE solisti1,
object_content TYPE TABLE OF solisti1,
wa_rec TYPE somlrec90,
receivers TYPE TABLE OF somlrec90,
listobject TYPE TABLE OF abaplist,
listasci(1024) TYPE c OCCURS 0 WITH HEADER LINE,
wa_html TYPE w3html,
html TYPE TABLE OF w3html,
v_date TYPE char10.
INITIALIZATION.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
SELECT-OPTIONS s_email FOR wa_rec-receiver NO INTERVALS.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM report_list_from_memory_del.
PERFORM list_to_asci_details.
PERFORM list_to_html_format_details.
PERFORM mail_subject_details.
PERFORM mail_content_details.
PERFORM mail_receivers_details.
PERFORM send_mail_option_details.
*&---------------------------------------------------------------------*
*& Form REPORT_LIST_FROM_MEMORY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM report_list_from_memory_del .
SUBMIT zsr_test EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form LIST_TO_ASCI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM list_to_asci_details .
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listobject = listobject
listasci = listasci
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form LIST_TO_HTML_FORMAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM list_to_html_format_details .
CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
TABLES
html = html
listobject = listobject.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_SUBJECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM mail_subject_details .
CLEAR: document_data, wa_content, wa_rec.
REFRESH: object_content, receivers.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = sy-datum
IMPORTING
date_external = v_date
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
document_data-obj_name = 'FERT'.
CONCATENATE 'Finished Goods Materials for' v_date
INTO document_data-obj_descr SEPARATED BY space.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_CONTENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM mail_content_details .
LOOP AT html INTO wa_html.
wa_content = wa_html.
APPEND wa_content TO object_content.
CLEAR: wa_content.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form MAIL_RECEIVERS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM mail_receivers_details .
LOOP AT s_email.
wa_rec-receiver = s_email-low.
wa_rec-rec_type = 'U'.
wa_rec-express = 'X'..
APPEND wa_rec TO receivers.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SEND_MAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM send_mail_option_details .
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = document_data
document_type = 'HTM'
put_in_outbox = 'X'
TABLES
object_content = object_content
receivers = 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.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
ENDFORM.
No comments:
Post a Comment