Search This Blog

Saturday, February 13, 2021

Interactive Report ALV

 

Simple Example for the ALV Interactive report using user_command.


Step1: Data decelerations.

Step2: Get the data from MARA.

Step3: Build field catalog.

Step4: Display ALV.

Step5: Implement user command.



REPORT ztest.
TABLES mara.
TYPE-POOLSslis.

TYPESBEGIN OF ty_mara,

         matnr TYPE mara-matnr,
         ersda TYPE mara-ersda,
         ernam TYPE mara-ernam,
       END OF ty_mara.

DATAitab TYPE TABLE OF ty_mara.
DATAit_fieldcat TYPE slis_t_fieldcat_alv,
      wa_fcat     TYPE slis_fieldcat_alv.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONSs_matnr FOR mara-matnr OBLIGATORY.
SELECTION-SCREENEND OF BLOCK b1.

START-OF-SELECTION.

  PERFORM get_data.

  PERFORM display_data.
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .

  SELECT matnr ersda ernam FROM mara INTO TABLE itab WHERE matnr IN s_matnr.

ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_data .

  PERFORM create_fieldcat.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      sy-repid
*     I_CALLBACK_PF_STATUS_SET          = ' '
      i_callback_user_command 'INT_ALV1'
      it_fieldcat             it_fieldcat
      i_default               'X'
      i_save                  'I'
    TABLES
      t_outtab                itab[]
    EXCEPTIONS
      program_error           1
      OTHERS                  2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " DISPLAY_DATA
*&---------------------------------------------------------------------*
*&      Form  CREATE_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_fieldcat .

  wa_fcat-fieldname 'MATNR'.
  wa_fcat-tabname 'ITAB'.
  wa_fcat-seltext_m 'MAT. NO.'.
  APPEND wa_fcat TO it_fieldcat.
  CLEAR wa_fcat.

  wa_fcat-fieldname 'ERSDA'.
  wa_fcat-tabname 'ITAB'.
  wa_fcat-seltext_m 'DATE'.
  APPEND wa_fcat TO it_fieldcat.
  CLEAR wa_fcat.

  wa_fcat-fieldname 'ERNAM'.
  wa_fcat-tabname 'ITAB'.
  wa_fcat-seltext_m 'PERSON NAME '.
  APPEND wa_fcat TO it_fieldcat.
  CLEAR wa_fcat.


ENDFORM.                    " CREATE_FIELDCAT

FORM int_alv1 USING s_comm TYPE sy-ucomm
                    sfield TYPE slis_selfield.

  MESSAGE i000(zmsgWITH sfield-value.
ENDFORM.

No comments:

Post a Comment

Pages