Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Checkboxes in ALV

Former Member
0 Likes
1,240

Hello Experts,

I have a column in alv which contains checkbox. On the click of a button, i want to know which checkboxes are checked. Please suggest how to do it.

Thanks.

Hello Experts,

I have a column in alv which contains checkbox. On the click of a button, i want to know which checkboxes are checked. Please suggest how to do it.

Thanks.

10 REPLIES 10
Read only

Former Member
0 Likes
1,204

Hi Prathiba,

Use CALL METHOD G_GRID->CHECK_CHANGED_DATA

IMPORTING

E_VALID = L_VALID.

or DATA_CHANGED event.

Cheers,

Sanil

Read only

Former Member
0 Likes
1,204

Hello,

you might have defined a char field for the check box in the internal table passing to ALV Fm.. ( the first field should be f1 type char 1 )

that char filed will be with a value 'X'..

loop or read nternal table with that field value F1 ='X'

rgards,

NZ

.

Read only

Former Member
0 Likes
1,204

Hi

i can suggest u simple way.

U can cret first column like this for fieldcat.

CLEAR wa_alv_fcat.

wa_alv_fcat-tabname = 'IT_FINAL1'.

wa_alv_fcat-fieldname = 'SEL'.

wa_alv_fcat-outputlen = '1'.

wa_alv_fcat-no_out = 'X'.

APPEND wa_alv_fcat TO it_alv_fcat1.

declare field sel in itab as char1.

In this u can select the records from grid by clicking on left side for that grid.

It easily updates sel field in itab wen u click on button as sel = 'X'.

It is simple to do. Wen u select records that entire row is marked row. U can select multiple rows by pressing control.

Thanks,

Yogesh

Read only

Former Member
0 Likes
1,204

Hi,

Check this program BCALV_EDIT_05.

Read only

Kanagaraja_L
Active Contributor
0 Likes
1,204

For Normal ALV List check the sample code below

TYPE-POOLS: slis.

DATA: BEGIN OF lt_sales OCCURS 0,
    vbeln LIKE vbak-vbeln,
    erdat LIKE vbak-erdat,
    check TYPE c, "checkbox
END OF lt_sales.

DATA: BEGIN OF lt_final OCCURS 0,
    vbeln LIKE vbak-vbeln,
    erdat LIKE vbak-erdat,
END OF lt_final.

DATA: v_fieldcat TYPE slis_fieldcat_alv,
    gt_fieldcat TYPE slis_t_fieldcat_alv,
    gt_layout TYPE slis_layout_alv.

START-OF-SELECTION.
  PERFORM get_data.
  PERFORM fill_fieldcatalog.
  PERFORM write_data.
*-----------------------------------------------------------------
* get data
*-----------------------------------------------------------------
FORM get_data .
  SELECT a~vbeln
  a~erdat
  a~audat
  a~kunnr
  a~vkorg
  b~matnr
  b~netpr
  INTO CORRESPONDING FIELDS OF TABLE lt_sales
  FROM vbak AS a INNER JOIN vbap AS b ON a~vbeln = b~vbeln UP TO 10 ROWS.
ENDFORM. " get_data
*-----------------------------------------------------------------
* write_data
*-----------------------------------------------------------------
FORM write_data .
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'FOR_CHECK'
      i_callback_user_command  = 'USER_COMMAND'
      is_layout                = gt_layout
      it_fieldcat              = gt_fieldcat
    TABLES
      t_outtab                 = lt_sales.
ENDFORM. " write_data
*-----------------------------------------------------------------
* fill catalog
*-----------------------------------------------------------------
FORM fill_fieldcatalog .
  SORT lt_sales BY vbeln.
  CLEAR v_fieldcat.

  v_fieldcat-col_pos = 1.
  v_fieldcat-fieldname = 'CHECK'.
  v_fieldcat-seltext_m = 'chek'.
  v_fieldcat-checkbox = 'X'.
  v_fieldcat-input = 'X'.
  v_fieldcat-edit = 'X'.
  APPEND v_fieldcat TO gt_fieldcat.

  CLEAR v_fieldcat.
  v_fieldcat-col_pos = 2.
  v_fieldcat-fieldname = 'VBELN'.
  v_fieldcat-seltext_m = 'Sales Document'.
  APPEND v_fieldcat TO gt_fieldcat.
  CLEAR v_fieldcat.

  v_fieldcat-col_pos = 3.
  v_fieldcat-fieldname = 'ERDAT'.
  v_fieldcat-seltext_m = 'Creation Date'.
  APPEND v_fieldcat TO gt_fieldcat.
  CLEAR v_fieldcat.
ENDFORM.                    "fill_fieldcatalog
*&---------------------------------------------------------------------*
*& Form GUI_SET
*&---------------------------------------------------------------------*
FORM for_check USING rt_extab TYPE slis_t_extab .
  SET PF-STATUS 'GETDATA' .
ENDFORM. "GUI_SET
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*

FORM user_command USING r_ucomm LIKE sy-ucomm
r_selfield TYPE slis_selfield.
  CASE r_ucomm.
    WHEN 'DATA'.
      CLEAR lt_final.
      CLEAR lt_sales.
      REFRESH lt_final.

      LOOP AT lt_sales .
        IF lt_sales-check = 'X'.
          lt_final-vbeln = lt_sales-vbeln.
          lt_final-erdat = lt_sales-erdat.
          IF NOT lt_final-vbeln IS INITIAL.
            APPEND lt_final .
          ENDIF.
        ENDIF.
      ENDLOOP.
      PERFORM final_display.
  ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form final_display
*&---------------------------------------------------------------------*
FORM final_display .
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      is_layout          = gt_layout
      it_fieldcat        = gt_fieldcat
    TABLES
      t_outtab           = lt_final.
ENDFORM. " final_display

Kanagaraja L

Read only

Former Member
0 Likes
1,204

Hi,

Try the following,


types: begin of ty_output,
           ............
           ............
           celltab     TYPE lvc_t_styl,       {color:red}"this is mandatory for this to work{color}
           checkbox    TYPE c,               {color:red}"this is mandatory for this to work{color}
           ...........
           .......
           end of ty_output.

DATA: it_output type standard table of ty_output.

DATA : ls_celltab TYPE lvc_s_styl,
       lt_celltab TYPE lvc_t_styl,
       ls_coupon TYPE ty_coupon.


loop at it_output into wa_output.
..............
..........

* Initially, set all checkbox cells editable.
   ls_celltab-fieldname = 'CHECKBOX'.
   ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
   INSERT ls_celltab INTO TABLE lt_celltab.
   INSERT LINES OF lt_celltab INTO TABLE wa_coupon-celltab.
 MODIFY it_output FROM wa_output TRANSPORTING vbeln celltab
endloop.


 LOOP AT it_output INTO ls_coupon WHERE checkbox = 'X'.
     .................
    ..................
   
    ENDLOOP.

Hope it helps you,

Regards,

Abhijit G. Borkar

Edited by: Abhijit Borkar on Jan 7, 2010 11:41 AM

Read only

Former Member
0 Likes
1,204

Hi pratibha,

To get a taste of it, just copy paste this program.

It will display alv (t001) and DOUBLE-CLICK ON any row.

It will TICK ALL THE CHECKBOXES.




REPORT abc.

TYPE-POOLS : slis.


*-------------- Data

DATA : BEGIN OF itab OCCURS 0.
        INCLUDE STRUCTURE t001.
DATA : flag tyPE c,
       END OF itab.
DATA : alvfc TYPE slis_t_fieldcat_alv.
DATA : alvly TYPE slis_layout_alv.

*--------- Select Data

SELECT * FROM t001 INTO TABLE itab.


*------- Field Catalogue
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
  EXPORTING
    i_program_name         = sy-repid
    i_internal_tabname     = 'ITAB'
    i_inclname             = sy-repid
  CHANGING
    ct_fieldcat            = alvfc
  EXCEPTIONS
    inconsistent_interface = 1
    program_error          = 2
    OTHERS                 = 3.


*---------------Display
alvly-box_fieldname = 'FLAG'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  EXPORTING
    it_fieldcat             = alvfc
    i_callback_program      = sy-repid "<-------Important
    i_callback_user_command = 'ITAB_USER_COMMAND' "<------ Important
    is_layout               = alvly
  TABLES
    t_outtab                = itab
  EXCEPTIONS
    program_error           = 1
    OTHERS                  = 2.



*-------------------------------------------------
* CALL BACK FORM
*-------------------------------------------------

FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
slis_selfield.



  LOOP AT itab.
    itab-flag = 'X'.
    MODIFY itab.
  ENDLOOP.


*--------- IMPORTANT.
WHATROW-REFRESH = 'X'.


ENDFORM. "ITAB_user_command


regards,

amit m.

Read only

0 Likes
1,204

Hi again,

Just replace the form (from my above reply) with this code.

It will give a message box and inform which-which rows are already ticked.





*-------------------------------------------------
* CALL BACK FORM
*-------------------------------------------------

FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
slis_selfield.

data : msg(500) type c.
data : s(10) type c.

  LOOP AT itab.
    if itab-flag = 'X'.
    s = sy-tabix.
    condense s.

    concatenate msg s ',' into msg.
    endif.


  ENDLOOP.

message msg type 'I'.
.

ENDFORM. "ITAB_user_command


Regards,

Amit Mittal.

Read only

Former Member
0 Likes
1,204

Hello,

The field for "Check box" will have value as "X" once it is checked in the output. You can check this by keeping a break point in your program after the ALV list or grid FM.

Best Regards,

Pavan

Read only

Former Member
0 Likes
1,204

thanks...