Application Development 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: 

ALV - selection of rows when check box is clicked

Former Member
0 Kudos

Hi all,

The requirement is to fill a row in Yellow color when the check box is clicked. Currently i'm using the Hotspot feature of ALV.

The processing takes time. So it would be helpful if you have any other alternative for this issue.

Thanks,

Lakshmi.

6 REPLIES 6

Former Member
0 Kudos

What do you mean by taking time, if you can post the code here that does that, we can look and see if that is the best way.

How are you making a specific row colored?

Regards,

Ravi

Former Member
0 Kudos

u have to create a checkbox and color in the itab.

If u cklikc the checkbox,

In Button press event,

If Itab1-CHK = 'X'.

layout-color= itab1-clor.

set the color from itab.

endif.

Former Member
0 Kudos

Hi santhanalakshmi,

1. The color will come for TICKED rows,

but not immediately at the time of ticking.

2. But after some event like double-click.

3. just copy paste in new program.

(it will give YELLOW COLOR

to all ticked rows)

4.

REPORT abc.

TYPE-POOLS : slis.

*----


Data

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE t001.

DATA : flag tyPE c,

clr(3) 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.

ALVLY-INFO_FIELDNAME = 'CLR'.

*----


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.

DATA : TABIX TYPE SY-TABIX.

*----


IMPORTANT.

LOOP AT ITAB.

TABIX = SY-TABIX.

IF ITAB-FLAG = 'X'.

ITAB-CLR = 'C30'.

MODIFY ITAB INDEX TABIX.

ENDIF.

ENDLOOP.

WHATROW-REFRESH = 'X'.

ENDFORM. "ITAB_user_command

regards,

amit m.

former_member188685
Active Contributor
0 Kudos

Hi,

try this way..

REPORT  ZTEST_ALV_CHECK     MESSAGE-ID ZZ           .


TYPE-POOLS: SLIS.
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
      IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      L_LAYOUT TYPE SLIS_LAYOUT_ALV,
      X_EVENTS TYPE SLIS_ALV_EVENT,
      IT_EVENTS TYPE SLIS_T_EVENT.

DATA: BEGIN OF ITAB OCCURS 0,
      VBELN LIKE VBAK-VBELN,
      POSNR LIKE VBAP-POSNR,
      CHK(1),
      color(4),
     END OF ITAB.

SELECT VBELN
       POSNR
       FROM VBAP
       UP TO 20 ROWS
       INTO TABLE ITAB.

X_FIELDCAT-FIELDNAME = 'CHK'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 1.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-CHECKBOX = 'X'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.

X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-SELTEXT_L = 'VBELN'.
X_FIELDCAT-HOTSPOT = 'X'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 2.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.

X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-SELTEXT_L = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 3.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.

L_LAYOUT-info_fieldname = 'COLOR'.
*L_LAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM       = SY-REPID
    IS_LAYOUT                = L_LAYOUT
    I_CALLBACK_PF_STATUS_SET = 'STATUS'
    I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
    IT_FIELDCAT              = IT_FIELDCAT
  TABLES
    T_OUTTAB                 = ITAB
  EXCEPTIONS
    PROGRAM_ERROR            = 1
    OTHERS                   = 2.
IF SY-SUBRC <> 0.

  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


*&---------------------------------------------------------------------*
*&      Form  STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_EXTAB    text
*----------------------------------------------------------------------*
FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.
*- Pf status
  SET PF-STATUS 'STATUS'.
ENDFORM.                 " STATUS

*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM     LIKE SY-UCOMM
                               RS_SELFIELD TYPE SLIS_SELFIELD.

  DATA: GD_REPID LIKE SY-REPID, "Exists
        REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
  IF REF_GRID IS INITIAL.
    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        E_GRID = REF_GRID.
  ENDIF.
  IF NOT REF_GRID IS INITIAL.
    CALL METHOD REF_GRID->CHECK_CHANGED_DATA .
  ENDIF.

loop at itab where chk = 'X'.
itab-color = 'C300'.
modify itab index sy-tabix transporting color.
endloop.
RS_SELFIELD-refresh = 'X'.
break-point.

ENDFORM.                    "USER_COMMAND

Former Member
0 Kudos

Hi all,

All the ideas suggested requires some additional input from user like double clicking, clicking on another field of ALV etc.

I need a solution to trigger some event immediately after the check box is checked.

since i have set the HOTSPOT attribute for the CHECKBOX column, it triggers the HOTSPOT_CLICK event. i need an alternative for the same.

Please give me some guidelines in this regard.

Thanks,

Lakshmi.

0 Kudos

As you have made the check box editable

1. DATA_CHANGED event will fire as soon as you check / uncheck the check box.

2. The HOTSPOT_CLICK event als will fire immediately when the user checks the check box.

Regards,

Ravi