Monday, December 20, 2010
This sample program shows check box and DISPLAY button on report output. When you select checkbox and click on display button, selected records are displayed.

REPORT zovh_alv_row_selection.
"Variables
DATA:
      BEGIN OF it_output OCCURS 0,
        select TYPE c,  "This variable stores the value when row selected
        bukrs  TYPE t001-bukrs,
        butxt  TYPE t001-butxt,
      END OF it_output.
TYPE-POOLS:slis.
DATA:
      it_events            TYPE STANDARD TABLE OF slis_alv_event,
      it_fieldcat          TYPE STANDARD TABLE OF slis_fieldcat_alv,
      wa_fieldcat          TYPE slis_fieldcat_alv,
      wa_events            TYPE slis_alv_event,
      wa_layout            TYPE slis_layout_alv.
DATA:g_program            TYPE sy-repid VALUE sy-repid.

START-OF-SELECTION.
  SELECT * FROM t001 INTO CORRESPONDING FIELDS OF TABLE it_output UP TO 100 ROWS.
  "Field Catalog creation
  DEFINE fieldcatalog.
    wa_fieldcat-fieldname = &1.
    wa_fieldcat-tabname   = &2.
    wa_fieldcat-seltext_l = &3.
    append wa_fieldcat to it_fieldcat.
    clear  wa_fieldcat.
  END-OF-DEFINITION.
  fieldcatalog: "Column table       col text
                'BUKRS' 'IT_OUTPUT' 'BUKRS',
                'BUTXT' 'IT_OUTPUT' 'BUTXT'.

  "Layout design
  wa_layout-box_fieldname     = 'SELECT'. "This has to be set to get selection
  wa_layout-colwidth_optimize = 'X'.
  "Events tables
  wa_events-name              = 'PF_STATUS_SET'.
  wa_events-form              = 'PF_STATUS_SET'.
  APPEND wa_events TO it_events.
  CLEAR wa_events.

  wa_events-name              = 'USER_COMMAND'.
  wa_events-form              = 'USER_COMMAND'.
  APPEND wa_events TO it_events.
  CLEAR wa_events.
  "Table Display in ALV format
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program = g_program
      is_layout          = wa_layout
      it_fieldcat        = it_fieldcat
      it_events          = it_events
    TABLES
      t_outtab           = it_output.
*&---------------------------------------------------------------------*
*&      Form  PF_STATUS_SET
*&---------------------------------------------------------------------*
FORM pf_status_set USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'ZTEST'.
* 1. When you set Pf status ZTEST, standard application tools will be removed.
* 2. Goto SE41 give program 'SAPLKKBL' and status 'STANDARD_FULLSCREEN'.
* 3. Copy the status from those to ZTEST of our program. Now you will see all standard functions.
ENDFORM.                    "PF_STATUS_SET

*------------------------------------------------------------------*
*       FORM USER_COMMAND                                          *
*------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
* Check function code
  CASE r_ucomm.
    WHEN 'DISPLAY'.  "user presses SAVE
      LOOP AT it_output.
        IF it_output-select EQ 'X'.
          "Process records that have been selected
          WRITE:/ it_output.
        ENDIF.
      ENDLOOP.
  ENDCASE.
ENDFORM.                    "user_command

1 comment:

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.