ALV template

INCLUDE ZDATAI_TOP:

TABLES:
  vbap,
  marc,
  sscrfields.
 
DATA: BEGIN OF sd_main OCCURS 0.
  data matnr like marc-matnr.
  data vbeln like vbap-vbeln.
  data arktx like vbap-arktx.
  data kdmat like vbap-kdmat.
  data stdpd like marc-stdpd.
DATA: END OF sd_main.

INCLUDE ZSD_SEL:

SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK selection WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (32) text-a11 FOR FIELD p_datef.
PARAMETERS :     p_datef LIKE sy-datum DEFAULT space.  "OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (32) text-a12 FOR FIELD p_datet.
PARAMETERS :     p_datet LIKE sy-datum DEFAULT sy-datum OBLIGATORY.
SELECTION-SCREEN END OF LINE.
 
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK dest WITH FRAME TITLE text-e10.
PARAMETERS :     dest LIKE rfcdisplay-rfcdest DEFAULT 'NONE'.
SELECTION-SCREEN END OF BLOCK dest.
SELECTION-SCREEN BEGIN OF BLOCK optional WITH FRAME TITLE d10.
SELECT-OPTIONS : s_matnr FOR vbap-matnr.
SELECT-OPTIONS : s_vbeln  FOR vbap-vbeln.              "Transaction Code
SELECTION-SCREEN END OF BLOCK optional.
SELECTION-SCREEN END OF BLOCK selection.
 
SELECTION-SCREEN SKIP.
SELECTION-SCREEN PUSHBUTTON 1(10) bt1 USER-COMMAND uc2.
 
AT SELECTION-SCREEN.
  CASE sscrfields-ucomm.
    WHEN 'UC2'.
      CLEAR: s_matnr, s_vbeln, p_datef, p_datet.
  ENDCASE.
REPORT  Z_ITJX
 
INCLUDE zdatai_top.
INCLUDE zsd_sel.
 
TYPE-POOLS: slis.  " SLIS contains all the ALV data types
 
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
 
DATA: it_vbak LIKE sd_main OCCURS 0.
 
 SELECT * FROM vbap "UP TO 500 ROWS
   INNER JOIN marc
   ON  vbap~matnr EQ marc~matnr
"   AND vbak~vbeln EQ vbap~vbeln
   INTO  CORRESPONDING FIELDS OF TABLE sd_main
   WHERE vbap~matnr IN s_matnr.
 
  wa_fieldcat-fieldname  = 'VBELN'.    " Fieldname in the data table (sd_main)
  wa_fieldcat-seltext_m  = 'Sales document'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.
 
  wa_fieldcat-fieldname  = 'KDMAT'.
  wa_fieldcat-seltext_m  = 'Client material'.
  APPEND wa_fieldcat TO it_fieldcat.
 
  wa_fieldcat-fieldname  = 'MATNR'.
  wa_fieldcat-seltext_m  = 'Material number'.
  APPEND wa_fieldcat TO it_fieldcat.
 
  wa_fieldcat-fieldname  = 'ARKTX'.
  wa_fieldcat-seltext_m  = 'Description'.
  APPEND wa_fieldcat TO it_fieldcat.
 
  wa_fieldcat-fieldname  = 'STDPD'.
  wa_fieldcat-seltext_m  = 'KMAT'.
  APPEND wa_fieldcat TO it_fieldcat.
 
*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = sd_main 
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.