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: 

Displaying a ticked check box in ALV

Former Member
0 Kudos
866

Hi,

I have an ALV report where i am populating it through data from the table. In the table there is a field where the value can be either 'X' or ' ' (space). My requiremnt is, in the ALV list display, whereever there is a 'X' in the database field, it should display in the ALV output as a <b><u>TICKED</u></b> checkbox.

How do I go about the same ? Points surely be awarded.

thanks,

Dev

1 ACCEPTED SOLUTION

Former Member
0 Kudos
515

Hi,

Check this simple code displaying checked checkboxes in the ALV output.



TYPE-POOLS slis.
DATA: BEGIN OF itab OCCURS 0,
       check,
       matnr TYPE matnr,
      END OF itab.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
      s_fieldcat TYPE LINE OF slis_t_fieldcat_alv,
      s_layout   TYPE slis_layout_alv.


* Fill up the internal table.
itab-check = 'X'.               " Check box checked
itab-matnr = 'TEST MATERIAL'.
APPEND itab.

itab-check = 'X'.               " Check box checked
itab-matnr = 'TEST 123456'.
APPEND itab.

* Fill up the field catalog.
s_fieldcat-fieldname     = 'MATNR'.
s_fieldcat-tabname       = 'ITAB'.
s_fieldcat-ref_tabname   = 'MARA'.
s_fieldcat-ref_fieldname = 'MATNR'.
APPEND s_fieldcat TO t_fieldcat.

* Fill up layout.
s_layout-box_fieldname = 'CHECK'.

* call the ALV
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
     EXPORTING
          is_layout     = s_layout
          it_fieldcat   = t_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.

Thanks,

Naren

16 REPLIES 16

former_member186741
Active Contributor
0 Kudos
515

SET THE 'checkbox' attribute of the field catalog entry for the field you are talking about to 'X'.

I usually use this form to achieve it:

  • output already extracted field as a checkbox

PERFORM set_fieldcat_attribute

USING

'T_headers'

'already_extracted'

'checkbox'

'X'

gt_fieldcat.

&----


*& Form SET_fieldCAT_attribute

&----


  • sets a fieldcat attribute, e.g. hides a field in ALV output

----


  • -->pv_table table name

  • -->pv_field field name

  • -->pv_attrib name of attribute to be changed

  • -->pv_newval new value to be put in attribute

  • -->pt_fieldcat field catlog

----


FORM set_fieldcat_attribute

USING pv_table TYPE tabname

pv_field TYPE fieldname

pv_attrib

pv_newval

pt_fieldcat TYPE slis_t_fieldcat_alv

.

FIELD-SYMBOLS: <attrib>,

<fieldcat> TYPE slis_fieldcat_alv.

TRANSLATE pv_table TO UPPER CASE.

TRANSLATE pv_field TO UPPER CASE.

READ TABLE pt_fieldcat ASSIGNING <fieldcat>

WITH KEY fieldname = pv_field tabname = pv_table.

IF sy-subrc = 0.

CONCATENATE '<FIELDCAT>-' pv_attrib INTO g_field_name.

ASSIGN (g_field_name) TO <attrib>.

<attrib> = pv_newval.

ENDIF.

ENDFORM. " set_fieldcat_attribute

0 Kudos
515

Yes, Ater checking the checkbox option in the field catalog. U have the internal table for that column withvalues 'X' or space( ' ' ). and also the type should be a character of length one.

Sudheer

Former Member
0 Kudos
515

try to undustand this program

<b>BCALV_EDIT_05</b>

Rewards if helpful.

Former Member
0 Kudos
515

IF you use the ALV OM, please consider the codes:


  try.
      lr_column ?= lr_columns->get_column( 'CHECKBOX' ). "a field where the       *      value can be either 'X' or ' ' (space).
      lr_column->set_cell_type( if_salv_c_cell_type=>checkbox ).
      lr_column->set_long_text( 'CHECKBOX' ).
    catch cx_salv_not_found.                            "#EC NO_HANDLER
  endtry.

former_member2382
Active Participant
0 Kudos
515

I think u can do this by setting the checkbox = 'X' in fieldcatalog

like...

clear w_fieldcat.

w_fieldcat-col_pos = 1.

w_fieldcat-fieldname = 'fieldname'.

w_fieldcat-checkbox = 'X'.

append w_fieldcat to t_fieldcat.

regards,

parvez.

Former Member
0 Kudos
515

Hi,

Check out this thread.

Hope this helps.

Regards,

Kumar.

Former Member
0 Kudos
515

hi,

while declaring fieldcatalogs.

d_fieldcat_wa-fieldname = 'MATNR'.

d_fieldcat_wa-checkbox = 'X'.

d_fieldcat_wa-seltext_l = 'material number'.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

reward with points if helpful.

Former Member
0 Kudos
515

Hi,

Actually I want a ticked checkbox in output. I tried with the field catalog stuff where i am updating it with the CHECKBOX = 'X' but still it is only siplaying the box but without a tick. Is there any method of displaying it as an ICON or like that? Please help

0 Kudos
515

You have to change it in your internal table you want to display.

If you have named it 'check'

you have to put in the catalog for 'check' checkbox = true and in your table line-check = true.

Regards,

Walter

Former Member
0 Kudos
515

Hi Narendra,

in the output internal table take one field for checkbox i.e <b> w_check. </b>

Let <b>w_field </b>is the field in the database table.

then try the below code.

<b>loop at itab .

if itab-w_field = 'X'.

itab-w_check = 'X'.

modify itab.

endif.

endloop. </b>

then you need to pass the name of the checkbox field to the field

<b>box_fieldname </b> in <b>layout </b> structure.

i.e.

<b> fs_layout-box_fieldname = 'w_check'. </b>

<b>This will definitely helps you. try this.</b>

Regards,

Bhargavi.D

Former Member
0 Kudos
515

Hi Bhargavi,

Where do we put the code u had asked to use esp the one below, layout one?

do we need to loop and then popuate this field and passs it to FM?

fs_layout-box_fieldname = 'w_check'.

Please reply. Thanks

0 Kudos
515

No not in the layout,

In the table you pass the FM, you have to set the field 'check' to true when you want it to be checked.

0 Kudos
515

show us the code of the call to ALV and the field-cat declarations

Former Member
0 Kudos
516

Hi,

Check this simple code displaying checked checkboxes in the ALV output.



TYPE-POOLS slis.
DATA: BEGIN OF itab OCCURS 0,
       check,
       matnr TYPE matnr,
      END OF itab.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
      s_fieldcat TYPE LINE OF slis_t_fieldcat_alv,
      s_layout   TYPE slis_layout_alv.


* Fill up the internal table.
itab-check = 'X'.               " Check box checked
itab-matnr = 'TEST MATERIAL'.
APPEND itab.

itab-check = 'X'.               " Check box checked
itab-matnr = 'TEST 123456'.
APPEND itab.

* Fill up the field catalog.
s_fieldcat-fieldname     = 'MATNR'.
s_fieldcat-tabname       = 'ITAB'.
s_fieldcat-ref_tabname   = 'MARA'.
s_fieldcat-ref_fieldname = 'MATNR'.
APPEND s_fieldcat TO t_fieldcat.

* Fill up layout.
s_layout-box_fieldname = 'CHECK'.

* call the ALV
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
     EXPORTING
          is_layout     = s_layout
          it_fieldcat   = t_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.

Thanks,

Naren

Former Member
0 Kudos
515

U need to <b><u>award points for all the useful replies</u></b>, and also u nees to <b><u>mark it as Answered if ur problem is solved</u></b>.

Regards

Sudheer

0 Kudos
515

Hi Narendra,

I got same requirement to add check box in alv output like material is active or Inactive. Please do send me the piece of code which is related to alv display , if your query is already solved.

Thank You,

Partha.