Thursday, October 4, 2018

ALV Block List Report

In the following program we have used ALV block list approach for some materials and their description.

REPORT zsr_test NO STANDARD PAGE HEADING LINE-SIZE 255.

TYPE-POOLS: slis.
DATA: wa_fcat   TYPE slis_fieldcat_alv,
      it_fcat   TYPE slis_t_fieldcat_alv,
      wa_fcat2  TYPE slis_fieldcat_alv,
      it_fcat2  TYPE slis_t_fieldcat_alv,
      wa_layout TYPE slis_layout_alv,
      wa_event  TYPE slis_alv_event,
      it_event  TYPE slis_t_event.

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.

TYPES: BEGIN OF ty_makt,
         matnr TYPE makt-matnr,
         maktx TYPE makt-maktx,
       END OF ty_makt.
DATA: wa_makt TYPE ty_makt,
      it_makt TYPE TABLE OF ty_makt.

INITIALIZATION.
  PARAMETERS p_mtart TYPE mtart.
  SELECT-OPTIONS s_ersda FOR sy-datum.

START-OF-SELECTION.
  PERFORM get_mara.
  PERFORM field_catalog.
  PERFORM alv_events.
  PERFORM alv_display.

*&---------------------------------------------------------------------*
*&      Form  GET_MARA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_mara .

  SELECT matnr ersda ernam mtart matkl
    FROM mara INTO TABLE it_mara
    WHERE ersda IN s_ersda
      AND mtart = p_mtart.

  IF sy-subrc = 0.
    SELECT matnr maktx
      FROM makt INTO TABLE it_makt
      FOR ALL ENTRIES IN it_mara
      WHERE matnr = it_mara-matnr
        AND spras = sy-langu.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FIELD_CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM field_catalog .

  DATA lv_col TYPE VALUE 0.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'MATNR'.
  wa_fcat-seltext_l = 'Material'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'ERSDA'.
  wa_fcat-seltext_l = 'Created On'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'ERNAM'.
  wa_fcat-seltext_l = 'Created By'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'MTART'.
  wa_fcat-seltext_l = 'Type'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'MATKL'.
  wa_fcat-seltext_l = 'Group'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  CLEAR lv_col.
  lv_col            = + lv_col.
  wa_fcat2-col_pos   = lv_col.
  wa_fcat2-fieldname = 'MATNR'.
  wa_fcat2-seltext_l = 'Material'.
  APPEND wa_fcat2 TO it_fcat2.
  CLEAR wa_fcat2.

  lv_col            = + lv_col.
  wa_fcat2-col_pos   = lv_col.
  wa_fcat2-fieldname = 'MAKTX'.
  wa_fcat2-seltext_l = 'Material Description'.
  APPEND wa_fcat2 TO it_fcat2.
  CLEAR wa_fcat2.

  wa_layout-colwidth_optimize = 'X'.
  wa_layout-zebra = 'X'.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  ALV_EVENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_events .

  wa_event-form = 'TOP'.
  wa_event-name = 'TOP_OF_PAGE'.
  APPEND wa_event TO it_event.
  CLEAR wa_event.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_display .

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
    EXPORTING
      i_callback_program = sy-repid
*     I_CALLBACK_PF_STATUS_SET       = ' '
*     I_CALLBACK_USER_COMMAND        = ' '
*     IT_EXCLUDING       =
    .

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      is_layout                  = wa_layout
      it_fieldcat                = it_fcat
      i_tabname                  = 'MARA'
      it_events                  = it_event
*     IT_SORT                    =
*     I_TEXT                     = ' '
    TABLES
      t_outtab                   = it_mara
    EXCEPTIONS
      program_error              = 1
      maximum_of_appends_reached = 2
      OTHERS                     3.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
    EXPORTING
      is_layout                  = wa_layout
      it_fieldcat                = it_fcat2
      i_tabname                  = 'MAKT'
      it_events                  = it_event
*     IT_SORT                    =
*     I_TEXT                     = ' '
    TABLES
      t_outtab                   = it_makt
    EXCEPTIONS
      program_error              = 1
      maximum_of_appends_reached = 2
      OTHERS                     3.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
*   I_INTERFACE_CHECK             = ' '
*   IS_PRINT                      =
*   I_SCREEN_START_COLUMN         = 0
*   I_SCREEN_START_LINE           = 0
*   I_SCREEN_END_COLUMN           = 0
*   I_SCREEN_END_LINE             = 0
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER       =
*   ES_EXIT_CAUSED_BY_USER        =
* EXCEPTIONS
*   PROGRAM_ERROR                 = 1
*   OTHERS                        = 2
    .

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  TOP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top .
  WRITE:/ 'Blocked ALV Report - 2 Blocks' COLOR 3.
ENDFORM.


Output is as follows.
Selection Screen

Required Output


Tuesday, April 24, 2018

Modal Dialog BOX


In the following example we are creating a module pool program where a Modal dialog box will be implemented. There is a selection screen with select option for creation date of materials. There are radio buttons of Raw materials and finished good materials. We can enter date range here and select the material type radio button and click on the display button. Now it will open a pop up screen where a table control will display the required list of materials.

1)      At first we created the module pool program. Four includes will be there as follows.

   INCLUDE zsr_top                                 .  " global Data
INCLUDE zsr_o01                                 .  " PBO-Modules
INCLUDE zsr_i01                                 .  " PAI-Modules
INCLUDE zsr_f01                                 .  " FORM-Routines

2)      Create the top include where all data & table declarations are there.

   PROGRAM sapmzsr_test.

TABLES: mara.
DATA: ok_9000 TYPE sy-ucomm,
      ok_9001 TYPE sy-ucomm,
      roh     TYPE VALUE 'X',
      fert    TYPE c.

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,
         meins TYPE mara-meins,
       END OF ty_mara.
DATA: wa_mara TYPE ty_mara,
      it_mara TYPE TABLE OF ty_mara.

SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECT-OPTIONS s_date FOR mara-ersda.
SELECTION-SCREEN END OF SCREEN 100.

CONTROLS: tabc TYPE TABLEVIEW USING SCREEN 9001.

3)      Now create the screens where the modal dialog box will be selected. Since we are implementing select option, a default 100 number of screen will be created. Hence there will be three screens: sub screen for select option, calling screen 9000 and modal dialog box 9001.

      PROCESS BEFORE OUTPUT.
  MODULE status_9000.
  CALL SUBSCREEN sel INCLUDING sy-repid '100'.

PROCESS AFTER INPUT.
  CALL SUBSCREEN sel.
  MODULE user_command_9000.
__________________________________________________________________________

      PROCESS BEFORE OUTPUT.
  MODULE status_9001.

  LOOP AT it_mara INTO wa_mara WITH CONTROL tabc.
    MODULE tabc_modal.
  ENDLOOP.

PROCESS AFTER INPUT.
  LOOP AT it_mara.
    MODULE tabc_modify_modal.
  ENDLOOP.

  MODULE user_command_9001.



4)      Now create the GUI status of 9000 and then call the sub screen for select option @ PBO.

   MODULE status_9000 OUTPUT.
  SET PF-STATUS 'PF_9000'.
*  SET TITLEBAR 'T_9000'.
ENDMODULE.




5)      Then create the PAI logic for 9000 screen. Write the logic of the Display button to display material list.

   MODULE user_command_9000 INPUT.

  CASE ok_9000.
    WHEN 'BACK'.
      LEAVE PROGRAM.
    WHEN 'DISP'.
      PERFORM display_materials.
  ENDCASE.

ENDMODULE.

____________________________________________________________________________

   FORM display_materials .

  DATA: lv_mtart TYPE mara-mtart.

  IF roh = 'X'.
    lv_mtart = 'ROH'.
  ELSE.
    lv_mtart = 'FERT'.
  ENDIF.

  SELECT matnr ersda ernam mtart matkl meins
    FROM mara INTO TABLE it_mara
    WHERE ersda IN s_date
      AND mtart = lv_mtart.

  IF sy-subrc = 0.
    SORT it_mara BY ersda.
    REFRESH CONTROL 'TABC' FROM SCREEN 9001.
    CALL SCREEN 9001
    STARTING AT 4
    ENDING AT   95 18.
  ENDIF.

ENDFORM.



6)      Here we shall mention the modal dialog screen starting and ending co-ordinate. This co-ordinate is mandatory to display the modal dialog box.

                CALL SCREEN 9001
    STARTING AT 4
    ENDING AT   95 18.


7)      Now write the PBO modules of modal dialog. There is no need to create GUI status (if you want then you can) separately. Since we are using table control here, loop with control for ITAB. The same pattern will be used as we use to create table control. Similarly to modify the table we create PAI module over there. In screen you can disable the input option in table control as usual.

   MODULE tabc_modal OUTPUT.

  DESCRIBE TABLE it_mara LINES sy-dbcnt.
  tabc-current_line  = sy-loopc.
  tabc-lines         = sy-dbcnt.

  mara-matnr = wa_mara-matnr.
  mara-ersda = wa_mara-ersda.
  mara-ernam = wa_mara-ernam.
  mara-mtart = wa_mara-mtart.
  mara-matkl = wa_mara-matkl.
  mara-meins = wa_mara-meins.
  CLEAR: wa_mara.

ENDMODULE.
_________________________________________________________________________

   MODULE tabc_modify_modal INPUT.

  READ TABLE it_mara INTO wa_mara INDEX tabc-current_line.
  IF sy-subrc = 0.
    MODIFY it_mara FROM wa_mara INDEX tabc-current_line.
  ENDIF.

ENDMODULE.




8)      Now create the PAI user command code as follows.

   MODULE user_command_9001 INPUT.

  CASE ok_9001.
    WHEN 'ENTER'.
      LEAVE LIST-PROCESSING.
      CLEAR ok_9001.
      LEAVE TO SCREEN 0.
  ENDCASE.

ENDMODULE.

9)      Finally create the transaction code to execute this program.

 Enter T-code.


Click on the Display button. Then the following pop up screen will open which contains the list of Raw materials.


Now click on the close button and it will be back to the previous screen. Select the finished good button and then Display.


The following pop up screen will come which contains the list of finished good materials.



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




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: