Monday, December 20, 2010
Use USER_COMMAND event in ALV to set SELECT ALL / DESELECT ALL button on ALV output.

REPORT ztest.
DATA: 
      BEGIN OF it_t100 OCCURS 0,
        checkbox LIKE abgr-kzart,
        arbgb    LIKE t100-arbgb,
        msgnr    LIKE t100-msgnr,
        text     LIKE t100-text,
      END OF it_t100.
DATA:
      program TYPE sy-repid VALUE sy-repid.
TYPE-POOLS 
      slis.
DATA:
      it_fieldcat TYPE slis_t_fieldcat_alv,
      wa_fieldcat LIKE LINE OF it_fieldcat.

DEFINE fieldcatalog.
  wa_fieldcat-fieldname = &1.
  wa_fieldcat-tabname   = 'IT_T100'.
  wa_fieldcat-checkbox  = &2.
  wa_fieldcat-edit      = &3.
  wa_fieldcat-seltext_m = &4.
  append wa_fieldcat to it_fieldcat.
  clear  wa_fieldcat.
END-OF-DEFINITION.

START-OF-SELECTION.
  SELECT * FROM t100 INTO TABLE it_t100 UP TO 100 ROWS.
  fieldcatalog: 
      'CHECKBOX' 'X' 'X' 'CHECKBOX',
      'ARBGB'    ''  ''  'ARBGB'   ,
      'MSGNR'    ''  ''  'MSGNR'   ,
      'TEXT'     ''  ''  'TEXT'    .
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program       = program
      i_callback_pf_status_set = 'PF_STATUS_SET'
      i_callback_user_command  = 'USER_COMMAND'
      it_fieldcat              = it_fieldcat
    TABLES
      t_outtab                 = it_t100.
*&---------------------------------------------------------------------*
*&      Form  PF_STATUS_SET
*&---------------------------------------------------------------------*
FORM pf_status_set USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS 'STATUS' EXCLUDING rt_extab.
ENDFORM.                    "PF_STATUS_SET
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
FORM user_command USING ucomm TYPE sy-ucomm selfield TYPE slis_selfield.
  IF ucomm = 'SEL_ALL'.
    LOOP AT it_t100.
      it_t100-checkbox = 'X'.
      MODIFY it_t100 INDEX sy-tabix.
    ENDLOOP.
    selfield-refresh = 'X'.
  ELSEIF ucomm = 'DESEL_ALL'.
    LOOP AT it_t100.
      it_t100-checkbox = space.
      MODIFY it_t100 INDEX sy-tabix.
    ENDLOOP.
    selfield-refresh = 'X'.
  ENDIF.
ENDFORM.                    "user_command

0 comments:

Post a 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.