Skip to Content
avatar image
Former Member

Check box in ALV

Hi,

I am using FM reuse_alv_grid_display for my output.I have to add one check box in the layout so that at a time i can select a single row and process on that row

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    May 24, 2006 at 06:36 AM

    Hi mukesh,

    (check box will come in ALV list,

    in ALV Grid, a selector on left will come)

    1. To get a taste of it,

    just copy paste this program.

    2. It will display alv (t001)

    and DOUBLE-CLICK ON any row.

    It will TICK ALL THE CHECKBOXES.

    3.

    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_GRID_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.

    BREAK-POINT.

    ENDFORM. "ITAB_user_command

    regards,

    amit m.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 24, 2006 at 06:51 AM

    Hi,

    refer this thread:

    radiobutton-or-checkbox-in-alv

    rgds,

    latheesh.

    Add comment
    10|10000 characters needed characters exceeded

  • May 24, 2006 at 06:53 AM

    You don't need to add a check box to process a line. Introduce the user_command event. The form you use will be able to detect which line you have double-clicked on.

    eg,

    FORM user_command

    USING i_ucomm LIKE sy-ucomm

    i_selfield TYPE slis_selfield.

    Check out the structure of slis_selfield, you can find out the whole line clicked on, the field name, the value of the field and more.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 24, 2006 at 06:46 AM

    HI

    GOOD

    GO THROUGH THIS REPORT

    TYPE-POOLS slis. " Global ALV types

    DATA : cdhdr TYPE cdhdr. " Change document header

    SELECT-OPTIONS :

    s_objcls FOR cdhdr-objectclas OBLIGATORY,

    s_objtid FOR cdhdr-objectid,

    s_chngnr FOR cdhdr-changenr,

    s_usrnam FOR cdhdr-username DEFAULT sy-uname,

    s_udate FOR cdhdr-udate DEFAULT sy-datum,

    s_time FOR cdhdr-utime,

    s_tcode FOR cdhdr-tcode,

    s_plncnr FOR cdhdr-planchngnr,

    s_chngno FOR cdhdr-act_chngno,

    s_wsplnd FOR cdhdr-was_plannd,

    s_chngid FOR cdhdr-change_ind.

    SELECTION-SCREEN SKIP.

    PARAMETERS p_max TYPE numc3 OBLIGATORY DEFAULT '200'.

    ----


    TYPES :

    BEGIN OF ty_s_cdhdr.

    INCLUDE STRUCTURE cdhdr.

    TYPES : checkbox,

    END OF ty_s_cdhdr,

    BEGIN OF ty_s_cdpos.

    INCLUDE STRUCTURE cdpos.

    TYPES : checkbox,

    END OF ty_s_cdpos.

    ----


    DATA :

    • Layout for ALV

    gs_layout TYPE slis_layout_alv,

    • Change document header

    t_cdhdr TYPE TABLE OF ty_s_cdhdr.

    ----


    START-OF-SELECTION.

    • Read Change document header

    SELECT * INTO TABLE t_cdhdr

    UP TO p_max ROWS

    FROM cdhdr

    WHERE objectclas IN s_objcls

    and objectid in s_objtid

    and changenr in s_chngnr

    AND username IN s_usrnam

    AND udate IN s_udate

    AND utime IN s_time

    AND tcode IN s_tcode

    AND planchngnr IN s_plncnr

    AND act_chngno IN s_chngno

    AND was_plannd IN s_wsplnd

    AND change_ind IN s_chngid.

    gs_layout-zebra = 'X'.

    gs_layout-colwidth_optimize = 'X'.

    gs_layout-box_fieldname = 'CHECKBOX'.

    • Display ALV

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = sy-cprog

    i_callback_user_command = 'USER_COMMAND'

    i_structure_name = 'CDHDR'

    is_layout = gs_layout

    TABLES

    t_outtab = t_cdhdr.

    ----


    • FORM USER_COMMAND *

    ----


    FORM user_command USING u_ucomm TYPE syucomm

    us_selfield TYPE slis_selfield. "#EC CALLED

    • Macro definition

    DEFINE m_sort.

    add 1 to ls_sort-spos.

    ls_sort-fieldname = &1.

    ls_sort-up = 'X'.

    append ls_sort to lt_sort.

    END-OF-DEFINITION.

    DATA :

    ls_cdhdr TYPE ty_s_cdhdr,

    ls_sort TYPE slis_sortinfo_alv,

    lt_sort TYPE slis_t_sortinfo_alv,

    • Change document items

    lt_cdpos TYPE TABLE OF ty_s_cdpos.

    CASE u_ucomm.

    WHEN '&IC1'.

    PERFORM check_marked USING us_selfield.

    • Read Change document items

    LOOP AT t_cdhdr INTO ls_cdhdr WHERE checkbox = 'X'.

    SELECT * APPENDING TABLE lt_cdpos

    FROM cdpos

    WHERE objectclas = ls_cdhdr-objectclas

    AND objectid = ls_cdhdr-objectid

    AND changenr = ls_cdhdr-changenr.

    ENDLOOP.

    m_sort 'CHANGENR'.

    • Display ALV

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_structure_name = 'CDPOS'

    is_layout = gs_layout

    it_sort = lt_sort

    TABLES

    t_outtab = lt_cdpos.

    ENDCASE.

    ENDFORM. " USER_COMMAND

    ----


    • Form CHECK_MARKED

    ----


    • What has been marked in t_cdhdr

    ----


    FORM check_marked USING us_selfield TYPE slis_selfield.

    FIELD-SYMBOLS :

    <cdhdr> TYPE ty_s_cdhdr.

    READ TABLE t_cdhdr TRANSPORTING NO FIELDS WITH KEY checkbox = 'X'.

    IF NOT sy-subrc IS INITIAL AND

    NOT us_selfield-tabindex IS INITIAL.

    READ TABLE t_cdhdr INDEX us_selfield-tabindex ASSIGNING <cdhdr>.

    <cdhdr>-checkbox = 'X'.

    ENDIF.

    ENDFORM. " CHECK_MARKED

    THANKS

    MRUTYUN

    Add comment
    10|10000 characters needed characters exceeded