Wednesday, August 23, 2017

Report Output via Email html format

Sometimes we need to send a mail to vendor for pending materials. In our system we have a list of that and we are reading that data set from the application server. Now most of the time that list doesn’t contain proper Vendor name. So we need to call vendor master table to get proper vendor name and then prepare an internal table for that. Now the list may contain multiple vendors as well. The mail will be shooting to a particular vendor and the list of the pending materials will be for that particular vendor only. Hence the function module for mail sending will be inside the loop of vendor list.

In the following program we have developed a mail sending scenario by which a mail will be sent to vendors for pending materials. The mail contains a specific format where we have created a table to show the list of pending materials. Here we need to incorporate HTML code inside the internal table.


The input file inside the application server is as follows:


The required Code:

REPORT zsr_test NO STANDARD PAGE HEADING.

TYPES: BEGIN OF ty_inp,
         vend_code TYPE lfa1-lifnr,
         vend_name TYPE string,
         mat_code  TYPE string,
         mat_desc  TYPE string,
         qty       TYPE string,
         color     TYPE string,
       END OF ty_inp.
DATA: wa_inp TYPE ty_inp,
      it_inp TYPE TABLE OF ty_inp.

DATA: wa_out TYPE solisti1,
      it_out TYPE TABLE OF solisti1.

TYPES: BEGIN OF ty_lfa1,
         lifnr TYPE lfa1-lifnr,
         name1 TYPE lfa1-name1,
         name2 TYPE lfa1-name2,
         adrnr TYPE lfa1-adrnr,
       END OF ty_lfa1.
DATA: wa_lfa1 TYPE ty_lfa1,
      it_lfa1 TYPE TABLE OF ty_lfa1.

TYPES: BEGIN OF ty_adr6,
         addrnumber TYPE adr6-addrnumber,
         smtp_addr  TYPE adr6-smtp_addr,
       END OF ty_adr6.
DATA: wa_adr6 TYPE ty_adr6,
      it_adr6 TYPE TABLE OF ty_adr6.

DATA: file_name TYPE char100 VALUE 'D:\SUM\abap\Vend_req.TXT',
      text      TYPE string,
      wa_rec    TYPE somlreci1,
      it_rec    TYPE TABLE OF somlreci1,
      subject   TYPE sodocchgi1.

START-OF-SELECTION.
  PERFORM read_dataset.
  PERFORM get_vendor_details.
  PERFORM mail_output.

*&---------------------------------------------------------------------*
*&      Form  READ_DATASET
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM read_dataset .

  OPEN DATASET file_name FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  DO.
    READ DATASET file_name INTO text.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.

    IF sy-index <> 1.
      SPLIT text AT '|' INTO wa_inp-vend_code
                             wa_inp-vend_name
                             wa_inp-mat_code
                             wa_inp-mat_desc
                             wa_inp-qty
                             wa_inp-color.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_inp-vend_code
        IMPORTING
          output = wa_inp-vend_code.

      APPEND wa_inp TO it_inp.
      CLEAR: wa_inp, text.
    ENDIF.
  ENDDO.
  CLOSE DATASET file_name.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  GET_VENDOR_DETAILS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_vendor_details .

  IF it_inp IS NOT INITIAL.
    SELECT lifnr name1 name2 adrnr
      FROM lfa1 INTO TABLE it_lfa1
      FOR ALL ENTRIES IN it_inp
      WHERE lifnr = it_inp-vend_code.

    IF sy-subrc = 0.
      SORT it_lfa1 BY lifnr.
    ENDIF.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  MAIL_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM mail_output .

  IF it_inp IS NOT INITIAL.
    LOOP AT it_inp INTO wa_inp.

      ON CHANGE OF wa_inp-vend_code.
        wa_out-line = '<html><body><p><strong><u>'.
        APPEND wa_out TO it_out.
        CLEAR: wa_out.

        READ TABLE it_lfa1 INTO wa_lfa1
        WITH KEY lifnr = wa_inp-vend_code
        BINARY SEARCH.

        IF sy-subrc = 0.
          CONCATENATE 'Following materials are pending from Vendor:'
                      wa_lfa1-name1 wa_lfa1-name2
                      INTO wa_out-line SEPARATED BY space.
          APPEND wa_out TO it_out.
          CLEAR: wa_out.

          wa_out-line = '</u></strong></p>'.
          APPEND wa_out TO it_out.
          CLEAR: wa_out.
        ENDIF.
      ENDON.

      wa_out-line = '<table border="1" cellspacing="0" cellpadding="0"><tbody>'.
      APPEND wa_out TO it_out.
      CLEAR: wa_out.

      ON CHANGE OF wa_inp-vend_code.
        wa_out-line = '<tr><td><p><strong>Material</strong></p></td>'.
        APPEND wa_out TO it_out.
        CLEAR: wa_out.

        wa_out-line = '<td><p><strong>Description</strong></p></td>'.
        APPEND wa_out TO it_out.
        CLEAR: wa_out.

        wa_out-line = '<td width="100"><p><strong>Qty</strong></p></td></tr>'.
        APPEND wa_out TO it_out.
        CLEAR: wa_out.
      ENDON.


      SHIFT wa_inp-mat_code LEFT DELETING LEADING '0'.
      CONCATENATE '<tr><td><p align="right">'
                  wa_inp-mat_code
                  '</p></td>'
                  INTO wa_out-line.
      APPEND wa_out TO it_out.
      CLEAR: wa_out.

      CONCATENATE '<td>' wa_inp-mat_desc '</td>'
                  INTO wa_out-line.
      APPEND wa_out TO it_out.
      CLEAR: wa_out.

      CONCATENATE '<td width="100"><p align="right">'
                  wa_inp-qty
                  '</p></td></tr></tbody></table>'
                  INTO wa_out-line.
      APPEND wa_out TO it_out.
      CLEAR: wa_out.

      AT END OF vend_code.
        APPEND INITIAL LINE TO it_out.
        wa_out-line = '<br>This is auto generated mail so don''t reply.</body></html>'.
        APPEND wa_out TO it_out.
        CLEAR: wa_out.

        subject-obj_descr = 'Pending Material'.
        wa_rec-receiver = 'sandip.aim@gmail.com'.
        wa_rec-rec_type = 'U'.
        wa_rec-express  = 'X'.
        APPEND wa_rec TO it_rec.
        CLEAR: wa_rec.

        CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
          EXPORTING
            document_data              = subject
            document_type              = 'HTM'
            put_in_outbox              = 'X'
            commit_work                = 'X'
          TABLES
            object_content             = it_out
            receivers                  = it_rec
          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.


        REFRESH: it_out, it_rec.
        CLEAR: wa_lfa1, wa_inp.
      ENDAT.
    ENDLOOP.
  ENDIF.

ENDFORM.

The Mail Output:


76 comments:

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 video tutorials.

ERP Training Videos said...

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

ERP Training said...

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

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sapvideos.

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sapvideos.

ERP Training Videos said...

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

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap video tutorial.

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap video training.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap video training.

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sap videos.

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap videos.

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap tutorial videos.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap videos.

Vinseo said...

Thanks for sharing this Information,
Got to learn new things from your Blog on Sap fiori.
SAP ABAP Consultant India

ERP Training Videos said...

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

ERP Training said...

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

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap hana videos.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap hana videos.

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap video tutorials.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap video tutorials.

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sap videos.

ERP Training Videos said...

Thankyou for wonderful article. It has more Information in Your Website sap videos.

ERP Training said...

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

ERP Training said...

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

ERP Training Videos said...

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

ERP Training Videos said...

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

Neethu said...

"ON CHANGE OF" is an obsolete statement and is not supported if we are using classes/ Object-oriented concepts. Is there any other statements/way to check whether a value has been changed or not(other than AT-NEW).

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap tutorial videos.

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sap tutorial videos.

Bhargav Jack said...

Nice post, Problem solved. But can tell me how to attach PDF in mail??

Anonymous said...

Hi

I have used CL_BCS, in SOST I am able to view the HTML Body and XLS attachment but after processing it to external email (outlook) HTML Body message not received its coming as blank only XLS attachment present. Could you pls share your thoughts.

ERP Training Videos said...

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

jabashree said...

Thanks for sharing this valuable information.I have read your blog and i got a very useful and knowledgeable information from your blog.You have done a great job.


SAP HR Training in Chennai


SAP SD Training in Chennai


BEST SAP BASIS Training in Chennai

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap learning videos.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap learning videos.

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sap videos.

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap videos.

ERP Training said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap videos.

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap videos.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap hana video tutorials.

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sap learning videos.

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap videos.

ERP Training Videos said...

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

ERP Training said...

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

ERP Training Videos said...

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

ERP Training said...

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

ERP Training Videos said...

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

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap videos.

ERP Training Videos said...

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

ERP Training said...

It was so nice article.I was really satisified by seeing this article sapvideos.

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap fiori training videos.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sapvideos.

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sap training videos for sale.

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap videos.

ERP Training Videos said...

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

ERP Training said...

It was so nice article.I was really satisified by seeing this article sapvideos.

ERP Training Videos said...

Thankyou for Sharing Great Information. It is Very Helpful Information on sap training videos for sale.

ERP Training said...

Thank you. It is such a wonderful post. it has great information it is very useful for sap training videos for sale.

ERP Training Videos said...

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

ERP Training said...

It was so nice article.I was really satisified by seeing this article sapvideos.

ERP Training Videos said...

Fabulous..!! Thank you.The information you provided is much usful information on sap fiori training videos.

ERP Training said...

Thankyou for wonderful article. It has more Information in Your Website sap video training.

ERP Training Videos said...

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

ERP Training Videos said...

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

ERP Training said...

It was so nice article.I was really satisified by seeing this article sap video tutorial.

ERP Training Videos said...

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

ERP Training said...

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

ERP Training Videos said...

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

ERP Training said...

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

ERP Training Videos said...

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

ERP Training said...

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

logistic-solutions said...


Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
sap strategic consulting and 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

ERP Training said...

It was so nice article.I was really satisified by seeing this article sap video tutorial.

ERP Training Videos said...

Thank you. sir, Really I like your post on sap video tutorial.