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:


Thursday, August 17, 2017

ALV Report Refresh Timely

Sometimes we need a report which will be updated timely and the output screen will reflect with the updated data. In production department we need this kind of approach which displays timely updated data for production control. In the following example we have developed a custom table and the table has been populated data in different time. The report fetches data from that custom table and displays output in ALV. Now whenever data is updated into the table the report will display the updated record after a particular time slab. This is very useful when we deal with transnational data.

Create a table as follows:


The table contains one line of data.


The program is as follows:

REPORT zsr_test NO STANDARD PAGE HEADING.

CLASS lcl_timer DEFINITION DEFERRED.
DATA: mesg     TYPE char50,
      lv_uzeit TYPE char8,
      wa_tab   TYPE zdbtablog,
      it_tab   TYPE TABLE OF zdbtablog.

DATA: ob_grid  TYPE REF TO cl_gui_alv_grid,
      ob_recev TYPE REF TO lcl_timer,
      ob_timer TYPE REF TO cl_gui_timer.

CLASS lcl_timer DEFINITION.
  PUBLIC SECTION.
    METHODS:
      handle_finished FOR EVENT finished OF cl_gui_timer.
ENDCLASS.

CLASS lcl_timer IMPLEMENTATION.
  METHOD handle_finished.
    PERFORM refresh_data.
    CONCATENATE sy-uzeit+0(2) ':'
                sy-uzeit+2(2) ':'
                sy-uzeit+4(2)
                INTO lv_uzeit.
    CONCATENATE 'Last Update at' lv_uzeit
           INTO mesg SEPARATED BY space.
    MESSAGE mesg TYPE 'S'.
    CALL METHOD ob_timer->run.
  ENDMETHOD.                    "handle_finished
ENDCLASS.

START-OF-SELECTION.
  PERFORM select_data.

END-OF-SELECTION.
  CREATE OBJECT ob_timer.
  CREATE OBJECT ob_recev.
  SET HANDLER ob_recev->handle_finished FOR ob_timer.
  ob_timer->interval = 30.
  CALL METHOD ob_timer->run.
  PERFORM display_data.
*&---------------------------------------------------------------------*
*&      Form  SELECT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM select_data .

  SELECT FROM zdbtablog INTO TABLE it_tab.
  IF sy-subrc = 0.
    SORT it_tab BY zmatnr.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  REFRESH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM refresh_data .

  IF ob_grid IS INITIAL .
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = ob_grid.
  ENDIF.

  IF ob_grid IS NOT INITIAL.
    PERFORM select_data.
    CALL METHOD ob_grid->refresh_table_display.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display_data .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program = sy-repid
      i_structure_name   = 'ZDBTABLOG'
    TABLES
      t_outtab           = it_tab
    EXCEPTIONS
      program_error      = 1
      OTHERS             2.

ENDFORM.


Report Output timely:




Data is uploaded by TMG with SM30:

Monday, August 7, 2017

ALV Grid Color Line with Bold Text

In the ALV Grid display report we can colour one particular line (condition based) and also we can BOLD text. In the following example we are showing PO list with quantity calculation list. We have Sub Total line (colour = yellow & BOLD text) and Similar kind of Grand Total line. Here we have the output table structure as follows.

TYPES: BEGIN OF ty_out,
         ebeln TYPE char15,
         ebelp TYPE char5,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         menge TYPE ekpo-menge,
         meins TYPE ekpo-meins,
         color TYPE char4,
         bold  TYPE lvc_t_styl,
       END OF ty_out.

Here we have a field of colour of 4 character types & BOLD field of table lvc_t_styl type. This table is a sorted internal table and we insert style field with value ‘00000121’. Here we are using the function - REUSE_ALV_GRID_DISPLAY_LVC and Field catalogue type is lvc_t_fcat & Layout type is lvc_s_layo.

REPORT zsr_test NO STANDARD PAGE HEADING.

TABLES: ekko.
TYPE-POOLS: slis.
DATA: wa_fcat   TYPE lvc_s_fcat,
      it_fcat   TYPE lvc_t_fcat,
      wa_layout TYPE lvc_s_layo,
      wa_top    TYPE slis_listheader,
      it_top    TYPE slis_t_listheader.

TYPES: BEGIN OF ty_ekko,
         ebeln TYPE ekko-ebeln,
         aedat TYPE ekko-aedat,
       END OF ty_ekko.
DATA: wa_ekko TYPE ty_ekko,
      it_ekko TYPE TABLE OF ty_ekko.

TYPES: BEGIN OF ty_ekpo,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         menge TYPE ekpo-menge,
         meins TYPE ekpo-meins,
       END OF ty_ekpo.
DATA: wa_ekpo TYPE ty_ekpo,
      it_ekpo TYPE TABLE OF ty_ekpo.

TYPES: BEGIN OF ty_out,
         ebeln TYPE char15,
         ebelp TYPE char5,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         menge TYPE ekpo-menge,
         meins TYPE ekpo-meins,
         color TYPE char4,
         bold  TYPE lvc_t_styl,
       END OF ty_out.
DATA: wa_out TYPE ty_out,
      it_out TYPE TABLE OF ty_out.

INITIALIZATION.
  SELECT-OPTIONS s_aedat FOR ekko-aedat.

START-OF-SELECTION.
  PERFORM get_ekko.
  PERFORM get_ekpo.

END-OF-SELECTION.
  PERFORM prepare_output.
  PERFORM field_catalog.
  PERFORM alv_grid_display.

TOP-OF-PAGE.
  PERFORM top_of_page.
*&---------------------------------------------------------------------*
*&      Form  GET_EKKO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_ekko .

  SELECT ebeln aedat FROM ekko
    INTO TABLE it_ekko
    WHERE aedat IN s_aedat.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  GET_EKPO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_ekpo .

  IF it_ekko IS NOT INITIAL.
    SELECT ebeln ebelp matnr werks menge meins
      FROM ekpo INTO TABLE it_ekpo
      FOR ALL ENTRIES IN it_ekko
      WHERE ebeln = it_ekko-ebeln
        AND matnr NE ' '.

    IF sy-subrc = 0.
      SORT it_ekpo BY ebeln ebelp.
    ENDIF.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  PREPARE_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM prepare_output .

  DATA: lw_bold TYPE lvc_s_styl,
        lt_bold TYPE lvc_t_styl.

  IF it_ekpo IS NOT INITIAL.
    LOOP AT it_ekpo INTO wa_ekpo.
      wa_out-ebeln = wa_ekpo-ebeln.
      wa_out-ebelp = wa_ekpo-ebelp.
      wa_out-matnr = wa_ekpo-matnr.
      SHIFT wa_out-matnr LEFT DELETING LEADING '0'.
      wa_out-werks = wa_ekpo-werks.
      wa_out-menge = wa_ekpo-menge.
      wa_out-meins = wa_ekpo-meins.
      APPEND wa_out TO it_out.
      CLEAR: wa_out.

      AT END OF ebeln.
        SUM.
        wa_out-ebeln = 'Sub Total'.
        wa_out-menge = wa_ekpo-menge.
        wa_out-color = 'C200'.
        lw_bold-style = '00000121'.
        INSERT lw_bold INTO lt_bold INDEX 1.
        wa_out-bold = lt_bold.
        FREE lt_bold.

        APPEND wa_out TO it_out.
        CLEAR: wa_out, lw_bold, wa_ekpo.
      ENDAT.

      AT LAST.
        SUM.
        wa_out-ebeln = 'Grand Total'.
        wa_out-menge = wa_ekpo-menge.
        wa_out-color = 'C210'.
        lw_bold-style = '00000121'.
        INSERT lw_bold INTO lt_bold INDEX 1.
        wa_out-bold = lt_bold.
        FREE lt_bold.

        APPEND wa_out TO it_out.
        CLEAR: wa_out, lw_bold, wa_ekpo.
      ENDAT.
    ENDLOOP.
  ENDIF.

  FREE it_ekpo.

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 = 'EBELN'.
  wa_fcat-reptext   = 'Purchase Order'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'EBELP'.
  wa_fcat-reptext   = 'Item'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

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

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'WERKS'.
  wa_fcat-reptext   = 'Plant'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'MENGE'.
  wa_fcat-reptext   = 'Quantity'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  lv_col            = + lv_col.
  wa_fcat-col_pos   = lv_col.
  wa_fcat-fieldname = 'MEINS'.
  wa_fcat-reptext   = 'Unit'.
  APPEND wa_fcat TO it_fcat.
  CLEAR wa_fcat.

  wa_layout-zebra      = 'X'.
  wa_layout-cwidth_opt = 'X'.
  wa_layout-info_fname = 'COLOR'.
  wa_layout-stylefname = 'BOLD'.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  ALV_GRID_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_grid_display .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program     = sy-repid
      i_callback_top_of_page = 'TOP_OF_PAGE'
      is_layout_lvc          = wa_layout
      it_fieldcat_lvc        = it_fcat
    TABLES
      t_outtab               = it_out
    EXCEPTIONS
      program_error          = 1
      OTHERS                 2.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page .

  REFRESH it_top.

  wa_top-typ  = 'H'.
  wa_top-info = 'Purchasing List'.
  APPEND wa_top TO it_top.
  CLEAR wa_top.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_top.

ENDFORM.


Output is: