Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

how to enable the check box using cl_salv_table?

Hi Experts,

what code will change for to enable the check box in the following Report program?

REPORT ZMA_ALV_OOPS2.

TABLES:MARA.

TYPES:BEGIN OF T_MARA,

SEL TYPE C,

MATNR TYPE MARA-MATNR,

WERKS TYPE MARC-WERKS,

LGORT TYPE MARD-LGORT,

LABST TYPE MARD-LABST,

END OF T_MARA.

DATA:TB_MARA TYPE STANDARD TABLE OF T_MARA,

WA_MARA TYPE T_MARA.

DATA: GR_TABLE TYPE REF TO CL_SALV_TABLE.

DATA: GR_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS.

DATA: GR_DISPLAY TYPE REF TO CL_SALV_DISPLAY_SETTINGS.

DATA: GR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE.

DATA: GR_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE.

DATA: GR_SORTS TYPE REF TO CL_SALV_SORTS.

DATA: GR_AGG TYPE REF TO CL_SALV_AGGREGATIONS.

DATA: GR_FILTER TYPE REF TO CL_SALV_FILTERS.

DATA: GR_LAYOUT TYPE REF TO CL_SALV_LAYOUT.

DATA: GR_PRINT TYPE REF TO CL_SALV_PRINT.

DATA: GR_SELE TYPE REF TO CL_SALV_SELECTIONS.

DATA: GC_TRUE TYPE SAP_BOOL VALUE 'X'.

DATA: GR_ITEM TYPE REF TO CL_SALV_ITEM.

DATA: COLUMNNAME TYPE REF TO LVC_FNAME.

  • top of list for CCL

DATA: GR_CONTENT_CCL TYPE REF TO CL_SALV_FORM_ELEMENT.

DATA: GR_COL TYPE REF TO CL_SALV_COLUMN.

DATA: LT_SORT TYPE SALV_T_SORT_REF,

LS_SORT TYPE SALV_S_SORT_REF,

L_SEQUENCE TYPE SALV_DE_SORT_SEQUENCE,

T_SORT TYPE REF TO SALV_T_SORT_REF.

DATA: KEY TYPE SALV_S_LAYOUT_KEY.

DATA: COLOR TYPE LVC_S_COLO.

DATA: GR_EVENTS TYPE REF TO CL_SALV_EVENTS_TABLE.

DATA: GR_SELECTIONS TYPE REF TO CL_SALV_SELECTIONS.

**--Selection screen

SELECT-OPTIONS:S_MATNR FOR MARA-MATNR.

SELECT MATNR WERKS LGORT LABST

FROM MARD

INTO CORRESPONDING FIELDS OF TABLE TB_MARA

WHERE MATNR IN S_MATNR.

TRY.

CALL METHOD CL_SALV_TABLE=>FACTORY

IMPORTING

R_SALV_TABLE = GR_TABLE

CHANGING

T_TABLE = TB_MARA.

CATCH CX_SALV_MSG.

ENDTRY.

GR_TABLE->SET_SCREEN_STATUS(

PFSTATUS = 'SALV_TABLE_STANDARD'

REPORT = SY-REPID

SET_FUNCTIONS = GR_TABLE->C_FUNCTIONS_ALL ).

GR_FUNCTIONS = GR_TABLE->GET_FUNCTIONS( ).

GR_FUNCTIONS->SET_ALL( ABAP_TRUE ).

GR_DISPLAY = GR_TABLE->GET_DISPLAY_SETTINGS( ).

GR_SELE = GR_TABLE->GET_SELECTIONS( ).

GR_SELE->SET_SELECTION_MODE( ).

GR_TABLE->SET_TOP_OF_LIST( GR_CONTENT_CCL ).

*--- To change the column headings

GR_COLUMNS = GR_TABLE->GET_COLUMNS( ).

GR_COLUMNS->SET_OPTIMIZE( GC_TRUE ).

GR_SORTS = GR_TABLE->GET_SORTS( ).

TRY.

GR_COLUMN ?= GR_COLUMNS->GET_COLUMN( 'SEL' ) .

GR_COLUMN->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>CHECKBOX ).

GR_COLUMN->SET_LONG_TEXT( 'CHECKBOX' ).

CATCH CX_SALV_NOT_FOUND.

ENDTRY.

GR_COLUMN->SET_CELL_TYPE( 6 ).

GR_COLUMN->SET_SHORT_TEXT( 'Check Box' ).

GR_COLUMN->SET_LONG_TEXT( 'Check Box' ).

******Check box edit

******

TRY.

GR_SORTS->ADD_SORT( COLUMNNAME = 'MATNR' SEQUENCE =

IF_SALV_C_SORT=>SORT_UP ).

CATCH CX_SALV_DATA_ERROR

CX_SALV_NOT_FOUND

CX_SALV_EXISTING.

ENDTRY.

GR_LAYOUT = GR_TABLE->GET_LAYOUT( ).

KEY-REPORT = SY-REPID.

GR_LAYOUT->SET_KEY( KEY ).

GR_LAYOUT->SET_SAVE_RESTRICTION( CL_SALV_LAYOUT=>RESTRICT_NONE ).

TRY.

GR_COLUMN ?= GR_COLUMNS->GET_COLUMN( 'MATNR' ).

CATCH CX_SALV_NOT_FOUND.

ENDTRY.

COLOR-COL = '8'.

COLOR-INT = '0'.

COLOR-INV = '1'.

GR_COLUMN->SET_COLOR( COLOR ).

GR_TABLE->DISPLAY( ).

Thanks,

Mahesh.

Tags:
Former Member
Former Member replied

Hi,

You can use the method set_selection_mode to automatically show the checkbox for each row..and use the method get_selected_rows to get the rows selected..

Check this sample report..

TYPES: BEGIN OF type_output,
         matnr TYPE matnr,
       END OF type_output.

DATA:lt_output   TYPE STANDARD TABLE OF type_output,
     lwa_rows    TYPE int4,
     lwa_output  TYPE type_output,
     lt_rows     TYPE salv_t_row.

* Local declarations.
DATA: lr_table      TYPE REF TO cl_salv_table,
      lr_selections TYPE REF TO cl_salv_selections.
DATA: lr_columns    TYPE REF TO cl_salv_columns_table.


START-OF-SELECTION.

* Prepare data.
  lwa_output-matnr = 'TEST1'.APPEND lwa_output TO lt_output.
  lwa_output-matnr = 'TEST2'.APPEND lwa_output TO lt_output.
  lwa_output-matnr = 'TEST3'.APPEND lwa_output TO lt_output.

* Call the factory method
  TRY.
      cl_salv_table=>factory(
        EXPORTING
          list_display = 'X'
        IMPORTING
          r_salv_table = lr_table
        CHANGING
          t_table      = lt_output ).
    CATCH cx_salv_msg.                                  "#EC NO_HANDLER

  ENDTRY.

* Column selection
  lr_selections = lr_table->get_selections( ).
  lr_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

  lr_columns = lr_table->get_columns( ).
  lr_columns->set_optimize( abap_true ).

* Display
  lr_table->display( ).

* Get the selected rows.
  lt_rows = lr_selections->get_selected_rows( ).

* Display the selected rows.
  LOOP AT lt_rows INTO lwa_rows.
    READ TABLE lt_output INTO lwa_output INDEX lwa_rows.

    WRITE: / lwa_output-matnr.

  ENDLOOP.

Thanks

Naren

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question