Friday, February 16, 2018

Classical Report Output in Email



In the following example we have created a classical report output and now we shall send it through email. The user will see the output in his mail box. The output format is in HTML format.

Simple Classical Report

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: / '|''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: / '|'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 OCCURS 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.
  PERFORM list_to_asci.
  PERFORM list_to_html_format.
  PERFORM mail_subject.
  PERFORM mail_content.
  PERFORM mail_receivers.
  PERFORM send_mail.

*&---------------------------------------------------------------------*
*&      Form  REPORT_LIST_FROM_MEMORY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM report_list_from_memory .

  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 .

  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 .

  CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
    TABLES
      html       = html
      listobject = listobject.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  MAIL_SUBJECT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM mail_subject .

  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 .

  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 .

  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 .

  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.


Selection Screen



Mail Output




19 comments:

Resma Biswal said...


It's so nice article thank you for sharing a valuable content
Sap Online Access

manoj reddy said...

it's very help full to share this program.

logistic-solutions said...

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
sas strategic consulting services

gilledashivani said...

Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD

logistic-solutions said...

Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
emc software vendors
bmc software vendors
Microsoft goldpartner
sap crm service providers

ERP Training said...

It was so nice article.I was really satisified by seeing this article sap training videos.

ERP Training Videos said...

Thank you. sir, Really I like your post on sap training videos.

ganesh kumar said...

ERP Leather nowadays is working well in organizing the workplace and work and carefully all the authoritative information!

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sap hana video tutorials.

APTRON GURGAON said...

informative content
SAP TRAINING IN GURGAON

ERP Training Videos said...

Thank you ,
Well it was nice post and very helpful information on sap tutorial videos.

ERP Training Videos said...

Thank you ,
Well it was nice post and very helpful information on sap videos.

ERP Training Videos said...

Thank you. sir, Really I like your post on sap training videos.

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sapvideos.

ananthinfo said...

nice post..ERP for Dhall Solution
SAP BUSINESS ONE for Rice mill solution
SAP BUSINESS ONE for flour mill
SAP BUSINESS ONE for appalam
SAP BUSINESS ONE for water solution

ERP Training Videos said...

It was Nice post and very useful information on sap simple finance videos.

ERP Training Videos said...

It was Nice post and very useful information on sap video tutorials.

ERP Training Videos said...

Thank you ,
Well it was nice post and very helpful information on sapvideos.

ERP Training Videos said...

Thank you ,
Well it was nice post and very helpful information on sap videos.