Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Tejas Jani
Submitted: 18/04/2007

ABAP Interactive ALV Program

This is a Sample Interactive ALV Code that may help an ABAP developer understand the basic ALV Interactive Programming.
This is an Interactive ALV report, where on line selection we can see the secondary list

Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT  zz_22038_22098_002
    NO STANDARD PAGE HEADING
    LINE-SIZE 650
    MESSAGE-ID zz_9838.

TYPE-POOLS: slis.
* Type declaration for values from ekko
TYPES: BEGIN OF i_ekko,
       ebeln LIKE ekko-ebeln,
       aedat LIKE ekko-aedat,
       bukrs LIKE ekko-bukrs,
       bsart LIKE ekko-bsart,
       lifnr LIKE ekko-lifnr,
       END OF i_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF i_ekko INITIAL SIZE 0,
      wa_ekko TYPE i_ekko.

*type declaration for values from ekpo
TYPES: BEGIN OF i_ekpo,
       ebeln LIKE ekpo-ebeln,
       ebelp LIKE ekpo-ebelp,
       matnr LIKE ekpo-matnr,
       menge LIKE ekpo-menge,
       meins LIKE ekpo-meins,
       netpr LIKE ekpo-netpr,
       END OF i_ekpo.

DATA: it_ekpo TYPE STANDARD TABLE OF i_ekpo INITIAL SIZE 0,
      wa_ekpo TYPE i_ekpo .

*variable for Report ID
DATA: v_repid LIKE sy-repid .

*declaration for fieldcatalog
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
      wa_fieldcat TYPE slis_fieldcat_alv.


DATA: it_listheader TYPE slis_t_listheader.

* declaration for events table where user comand or set PF status will
* be defined
DATA: v_events TYPE slis_t_event,
      wa_event TYPE slis_alv_event.

* declartion for layout
DATA: alv_layout TYPE slis_layout_alv.

* declaration for variant(type of display we want)
DATA: i_variant TYPE disvariant,
      i_variant1 TYPE disvariant,
      i_save(1) TYPE c.

*PARAMETERS : p_var TYPE disvariant-variant.

*Title displayed when the alv list is displayed
DATA:  i_title_ekko TYPE lvc_title VALUE 'FIRST LIST DISPLAYED'.
DATA:  i_title_ekpo TYPE lvc_title VALUE 'SECONDRY LIST DISPLAYED'.

INITIALIZATION.
  v_repid = sy-repid.
  PERFORM build_fieldcatlog.
  PERFORM event_call.
  PERFORM populate_event.

START-OF-SELECTION.
  PERFORM data_retrieval.
  PERFORM build_listheader USING it_listheader.
  PERFORM display_alv_report.

*&--------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATLOG
*&--------------------------------------------------------------------*
*       Fieldcatalog has all the field details from ekko
*---------------------------------------------------------------------*
FORM build_fieldcatlog.
  wa_fieldcat-tabname = 'IT_EKKO'.
  wa_fieldcat-fieldname = 'EBELN'.
  wa_fieldcat-seltext_m = 'PO NO.'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-tabname = 'IT_EKKO'.
  wa_fieldcat-fieldname = 'AEDAT'.
  wa_fieldcat-seltext_m = 'DATE.'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-tabname = 'IT_EKKO'.
  wa_fieldcat-fieldname = 'BUKRS'.
  wa_fieldcat-seltext_m = 'COMPANY CODE'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-tabname = 'IT_EKKO'.
  wa_fieldcat-fieldname = 'BUKRS'.
  wa_fieldcat-seltext_m = 'DOCMENT TYPE'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-tabname = 'IT_EKKO'.
  wa_fieldcat-fieldname = 'LIFNR'.
  wa_fieldcat-no_out    = 'X'.
  wa_fieldcat-seltext_m = 'VENDOR CODE'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.


ENDFORM.                    "BUILD_FIELDCATLOG

*&--------------------------------------------------------------------*
*&      Form  EVENT_CALL
*&--------------------------------------------------------------------*
*   we get all events - TOP OF PAGE or USER COMMAND in table v_events
*---------------------------------------------------------------------*
FORM event_call.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = v_events.
ENDFORM.                    "EVENT_CALL

*&--------------------------------------------------------------------*
*&      Form  POPULATE_EVENT
*&--------------------------------------------------------------------*
*      Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM populate_event.
  READ TABLE v_events INTO wa_event WITH KEY name = 'TOP_OF_PAGE'.
  IF sy-subrc EQ 0.
    wa_event-form = 'TOP_OF_PAGE'.
    MODIFY v_events FROM wa_event TRANSPORTING form
        WHERE name = wa_event-form.
  ENDIF.

  READ TABLE v_events INTO wa_event WITH KEY name = 'USER_COMMAND'.
  IF sy-subrc EQ 0.
    wa_event-form = 'USER_COMMAND'.
    MODIFY v_events FROM wa_event TRANSPORTING form
        WHERE name = wa_event-name.
  ENDIF.
ENDFORM.                    "POPULATE_EVENT
*&--------------------------------------------------------------------*
*&      Form  data_retrieval
*&--------------------------------------------------------------------*
*   retreiving values from the database table ekko
*---------------------------------------------------------------------*
FORM data_retrieval.
  SELECT ebeln aedat bukrs bsart lifnr FROM ekko INTO TABLE it_ekko.

ENDFORM.                    "data_retrieval
*&--------------------------------------------------------------------*
*&      Form  bUild_listheader
*&--------------------------------------------------------------------*
FORM build_listheader USING i_listheader TYPE slis_t_listheader.
  DATA hline TYPE slis_listheader.
  hline-info = 'this is my first alv pgm'.
  hline-typ = 'H'.
ENDFORM.                    "build_listheader
*&--------------------------------------------------------------------*
*&      Form  display_alv_report
*&--------------------------------------------------------------------*
FORM display_alv_report.
  v_repid = sy-repid.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = v_repid
      i_callback_user_command = 'USER_COMMAND'
      i_callback_top_of_page  = 'TOP_OF_PAGE'
      i_grid_title            = i_title_ekko
      it_fieldcat             = i_fieldcat[]
      i_save                  = 'A'
      it_events               = v_events
    TABLES
      t_outtab                = it_ekko.
ENDFORM.                    "display_alv_report
*&--------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&--------------------------------------------------------------------*
FORM top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_listheader.
ENDFORM.                    "TOP_OF_PAGE
*&--------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&--------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.
  CASE r_ucomm.
    WHEN '&IC1'.
      READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
      PERFORM build_fieldcatlog_ekpo.
      PERFORM event_call_ekpo.
      PERFORM populate_event_ekpo.
      PERFORM data_retrieval_ekpo.
      PERFORM build_listheader_ekpo USING it_listheader.
      PERFORM display_alv_ekpo.
  ENDCASE.
ENDFORM.                    "user_command
*&--------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATLOG_EKPO
*&--------------------------------------------------------------------*
FORM build_fieldcatlog_ekpo.

  wa_fieldcat-tabname = 'IT_EKPO'.
  wa_fieldcat-fieldname = 'EBELN'.
  wa_fieldcat-seltext_m = 'PO NO.'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
  wa_fieldcat-tabname = 'IT_EKPO'.
  wa_fieldcat-fieldname = 'EBELP'.
  wa_fieldcat-seltext_m = 'LINE NO'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
  wa_fieldcat-tabname = 'I_EKPO'.
  wa_fieldcat-fieldname = 'MATNR'.
  wa_fieldcat-seltext_m = 'MATERIAL NO.'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.
  wa_fieldcat-tabname = 'I_EKPO'.
  wa_fieldcat-fieldname = 'MENGE'.
  wa_fieldcat-seltext_m = 'QUANTITY'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-tabname = 'I_EKPO'.
  wa_fieldcat-fieldname = 'MEINS'.
  wa_fieldcat-seltext_m = 'UOM'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-tabname = 'I_EKPO'.
  wa_fieldcat-fieldname = 'NETPR'.
  wa_fieldcat-seltext_m = 'PRICE'.
  APPEND wa_fieldcat TO i_fieldcat.
  CLEAR wa_fieldcat.

ENDFORM.                    "BUILD_FIELDCATLOG_EKPO
*&--------------------------------------------------------------------*
*&      Form  event_call_ekpo
*&--------------------------------------------------------------------*
*   we get all events - TOP OF PAGE or USER COMMAND in table v_events
*---------------------------------------------------------------------*
FORM event_call_ekpo.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type = 0
    IMPORTING
      et_events   = v_events.
ENDFORM.                    "event_call_ekpo
*&--------------------------------------------------------------------*
*&      Form  POPULATE_EVENT
*&--------------------------------------------------------------------*
*        Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM populate_event_ekpo.
  READ TABLE v_events INTO wa_event WITH KEY name = 'TOP_OF_PAGE'.
  IF sy-subrc EQ 0.
    wa_event-form = 'TOP_OF_PAGE'.
    MODIFY v_events FROM wa_event TRANSPORTING form
        WHERE name = wa_event-form.
  ENDIF.

ENDFORM.                    "POPULATE_EVENT
*&--------------------------------------------------------------------*
*&      Form  TOP_OF_PAGE
*&--------------------------------------------------------------------*
FORM f_top_of_page.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_listheader.
ENDFORM.                    "TOP_OF_PAGE
*&--------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&--------------------------------------------------------------------*
FORM data_retrieval_ekpo.
*retreiving values from the database table ekko
  SELECT ebeln ebelp matnr menge meins netpr FROM ekpo INTO TABLE it_ekpo.
ENDFORM.                    "DATA_RETRIEVAL_EKPO
*&---------------------------------------------------------------------*
*&      Form  BUILD_LISTHEADER_EKPO
*&---------------------------------------------------------------------*
FORM build_listheader_ekpo USING i_listheader TYPE slis_t_listheader.
  DATA: hline1 TYPE slis_listheader.
  hline1-typ = 'H'.
  hline1-info = 'CHECKING PGM'.
ENDFORM.                    "BUILD_LISTHEADER_EKPO
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_EKPO
*&---------------------------------------------------------------------*
FORM display_alv_ekpo.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program     = v_repid
      i_callback_top_of_page = 'TOP_OF_PAGE'
      i_grid_title           = i_title_ekpo
      it_fieldcat            = i_fieldcat[]
      i_save                 = 'A'
      it_events              = v_events
    TABLES
      t_outtab               = it_ekpo
    EXCEPTIONS
      program_error          = 1
      OTHERS                 = 2.
ENDFORM.                    "DISPLAY_ALV_EKPO