cancel
Showing results for 
Search instead for 
Did you mean: 

Check Box in ALV

Former Member
0 Kudos

Hi All

I have one ALV created using a standard structure (in the node), now i need to add a Check Box before each and every row in the ALV, how can i achieve this , only the Check should be in editable mode and rest of the ALV content should me readonly , say which ever records i choose from ALV ,those must be stored in DB

Thanks and Regards

Chaitanya.A

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Is there any way to export the content of a table into Excel , just like EXPORT functionality in ALV

Best Regards

Chaitanya.A

Former Member
0 Kudos

We have a button over there by which we can download to excel.

Former Member
0 Kudos

Hi Manjunath

I want to achieve the same functionality in a TABLE [Not in ALV] , ie a custom button in table tool bar

Best Regards

Chaitanya.A

Former Member
0 Kudos

Check the below code.

DO.

lo_el_err_emp_proj = lo_nd_err_emp_proj->get_element( index = sy-index ).

IF lo_el_err_emp_proj IS NOT INITIAL.

lo_el_err_emp_proj->get_static_attributes(

IMPORTING

static_attributes = ls_err_emp_proj ).

CONCATENATE v_string

ls_err_emp_proj-empid tab

ls_err_emp_proj-ztask tab

ls_err_emp_proj-begda tab

ls_err_emp_proj-endda tab

cl_abap_char_utilities=>newline

INTO v_string.

ELSE.

EXIT.

ENDIF.

ENDDO.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = v_string

IMPORTING

buffer = v_xstring.

CONCATENATE 'Emp Proj Relations_' sy-datum '_' sy-uzeit '.csv' INTO filename1.

cl_wd_runtime_services=>attach_file_to_response(

i_filename = filename1

i_content = v_xstring

i_mime_type = 'application/vnd.ms-excel' "'text/plain'

i_in_new_window = i_in_new_window

i_inplace = i_inplace ).

uday_gubbala2
Active Contributor
0 Kudos

Hi Chaitanya,

Sorry had posted off when I got to check your updated thread asking for achieving the functionality using a normal table and not ALV. In order to get the download functionality. Create an button in the Table toolbar and put the below coding into it. You need to basically do the following tasks:

1) First read the table's data into an internal table.

2) Convert the internal table data to STRING format.

3) Now convert it into tab delimited format.

4) Convert this STRING format to XSTRING format

5) Make use of the attach_file_to_response method to download in desired word/excel/notepad format.

Regards,

Uday

You can also go through this [link |http://saptechnical.com/Tutorials/WebDynproABAP/Export/toexcel.htm]where you would find step-by-step explanation along with snapshots for the same functionality.

METHOD onactionon_submit .
  DATA: lv_node TYPE REF TO if_wd_context_node,
        lt_mara TYPE if_main=>elements_mara,
        wa_mara TYPE if_main=>element_mara,
        lead_selection_index TYPE i,
 
        mara_string  TYPE string,
        mara_xstring TYPE xstring.
 
  lv_node = wd_context->get_child_node( name = 'MARA' ).
  CALL METHOD lv_node->get_static_attributes_table
    IMPORTING
      table = lt_mara.
 
  LOOP AT lt_mara INTO wa_mara.
    CONCATENATE mara_string
                wa_mara-matnr
                wa_mara-ersda
                wa_mara-ernam
                wa_mara-matkl
                wa_mara-meins
                cl_abap_char_utilities=>newline INTO mara_string
                                        SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
  ENDLOOP.
 
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text   = mara_string
    IMPORTING
      buffer = mara_xstring.
 
 
  wdr_task=>client_window->client->attach_file_to_response(  i_filename  = 'TEMP.DOC'
                                                             i_content   = mara_xstring
                                                             i_mime_type = 'WORD' ).
ENDMETHOD.

The above is the code to export the Internal Table to Word Document. You can proceed as shown below for Excel & NOTEPAD formats.

To Export the Internal Table to Text File:

WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
    I_FILENAME    = 'WDP.txt'
    I_CONTENT     =  mara_xstring
    I_MIME_TYPE   = 'NOTEPAD' ).

To Export the Internal Table to Excel File:

WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
    I_FILENAME    = 'Excel.xls'
    I_CONTENT     =  mara_xstring
    I_MIME_TYPE   = 'EXCEL' ).

Former Member
0 Kudos

Hi Duo

Thank you

Best Regards

Chaitanya.A

Former Member
0 Kudos

Hi

I got the Export functionality , but i need labels for my data as in table. how can i get them in excel

Regards

Chaitanya.A

Former Member
0 Kudos

You mean Headings in Excel ? If that is the case check the below logic.

Note: We can get headings. But i think we cant get them as Bold, Italic .......

Before appending the data into the string, pass texts first and then data. So further if u want to process the same file , delete the first record and then process remaining records.

Answers (2)

Answers (2)

uday_gubbala2
Active Contributor
0 Kudos

Hi Chaitanya,

By default the column containing the checkboxes would appear in the order as how it appears within your context node. If you want to move it to a particular position you can try do it as shown below:

You can use below coding to change the position of column SEATSOCC to 3rd column

DATA: lr_column TYPE REF TO cl_salv_wd_column,
      lv_image TYPE REF TO cl_salv_wd_uie_image.

lr_column = lo_value->if_salv_wd_column_settings~get_column(id = 'CHECK' ).

DATA: ls_column TYPE salv_wd_s_column_ref.

ls_column-r_column = lr_column.
ls_column-r_column->set_position( 1 ).

This would result in the checkbox column being displayed as the 1st column of your ALV.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Hi Chaitanya,

Its not that difficult. Create an attribute (say by name CHECK) of type WDY_BOOLEAN under the same context node which you are binding to your ALV. So when you bind this node to your ALV you would get a column by name CHECK. You would have to loop through your ALV columns & embed the checkbox element within the cells for the column by name CHECK. Try going through this sample fragment shown below:

METHOD build_alv .
  DATA:
    lr_alv_usage       TYPE REF TO if_wd_component_usage,
    lr_if_controller   TYPE REF TO iwci_salv_wd_table,
    lr_config          TYPE REF TO cl_salv_wd_config_table,
    lr_column_settings TYPE REF TO if_salv_wd_column_settings,
    lt_columns         TYPE        salv_wd_t_column_ref,
    lr_checkbox        TYPE REF TO cl_salv_wd_uie_checkbox.
  FIELD-SYMBOLS
    <fs_column> LIKE LINE OF lt_columns.

" Instantiate the ALV Component (Done through the code wizard)
  lr_alv_usage = wd_this->wd_cpuse_alv( ).
  IF lr_alv_usage->has_active_component( ) IS INITIAL.
    lr_alv_usage->create_component( ).
  ENDIF.

" Get reference to model (Done through the code wizard)
  lr_if_controller = wd_this->wd_cpifc_alv( ).
  lr_config        = lr_if_controller->get_model( ).

"  If you want the entire ALV to be in editable mode then you will have to comment the below line
"   lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).

" Get the column references
  lr_column_settings ?= lr_config.
  lt_columns = lr_column_settings->get_columns( ).

" Loop through the individual columns & place checkboxes for the desired column
  LOOP AT lt_columns ASSIGNING <fs_column>.
    IF <fs_column>-id = 'CHECK'.
      CREATE OBJECT lr_checkbox
        EXPORTING
          checked_fieldname = 'CHECK'.
      <fs_column>-r_column->set_cell_editor( lr_checkbox ).
    ENDIF.
  ENDLOOP.
ENDMETHOD.

You can also try go through this [blog|https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/webDynproABAP-UsingUIelementsinALVcomponentcells] by David Pietroniro in which he is embedding a checkbox within the column RESERVED. He's also conditionally enabling the checkbox in his program. My sandbox servers currently down or would have pasted the full working code for your desired functionality.

Regards,

Uday

Former Member
0 Kudos

Hello Uday

Thanks for responding

will revert back to you

Regards

Chaitanya.A

Former Member
0 Kudos

Hi Uday

I followed the same procedure, but no luck..

i am able to display ALV , but in readonly mode

Best Regards

Chaitanya.A

Former Member
0 Kudos

Try this out

*----


DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

lo_cmp_usage = wd_this->wd_cpuse_alv1( ).

IF lo_cmp_usage->has_active_component( ) IS INITIAL.

lo_cmp_usage->create_component( ).

ENDIF.

DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .

lo_interfacecontroller = wd_this->wd_cpifc_alv1( ).

DATA lo_value TYPE REF TO cl_salv_wd_config_table.

lo_value = lo_interfacecontroller->get_model(

).

lo_value->if_salv_wd_table_settings~set_read_only(

value = abap_false

).

Former Member
0 Kudos

Hi Manjunath

No luck

Regards

Chaitanya.A

Former Member
0 Kudos

Check the below code

DATA : l_column TYPE REF TO cl_salv_wd_column .

CALL METHOD lo_value->if_salv_wd_column_settings~get_column

EXPORTING

id = 'PROFL'

RECEIVING

value = l_column.

DATA : lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.

CREATE OBJECT lr_input_field

EXPORTING

value_fieldname = 'PROFL'.

CALL METHOD l_column->set_cell_editor

EXPORTING

value = lr_input_field.

Here we are making a field as Input Field. Similarly follow the same procedure to make the field as Check-box.

uday_gubbala2
Active Contributor
0 Kudos

Hi Chaitanya,

Am sorry was away for a while. In addition to using:

lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).

for making the ALV as input enabled you need to make the cells as input fields in order for your ALV to appear completely as editable. You can use some coding like shown below to embed an input field within the ALV cell:

DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
        lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.

  lr_column_settings ?= l_value.
  lr_column = lr_column_settings->get_column( 'TEMP' ).
  CREATE OBJECT lr_input_field
    EXPORTING
      value_fieldname = 'TEMP'.
  lr_column->set_cell_editor( lr_input_field ).

Coming to your functionality to download to excel you already have a button "Export" which appears beside the "Print Version" button using which you can export the contents to Excel.

Regards,

Uday

Former Member
0 Kudos

HI All

The procedure which i followed to make a Editable Check Box Column in ALV

1) Create a component usage

CMP_ALV -


SALV_WD_TABLE

2) Create the context which you want to show in ALV , create an attribute of type WDY_BOOLEAN for the check box

3) Under the Component Usage -> Interface Controller Bind the context node to the DATA node

4) Create a view and insert ViewContainerUIElement

5) Bind the ViewContainerUIElement

a) Open Window

b) Embed the view and Expand the View. right click on the ViewContainer -> embedView

c) View to be enbed -> select CMP_ALV's TABLE as View/Interface View

6) Create a Method Build_ALV in your view and write the following code

DATA:
    lr_alv_usage       TYPE REF TO if_wd_component_usage,
    lr_if_controller   TYPE REF TO iwci_salv_wd_table,
    lr_config          TYPE REF TO cl_salv_wd_config_table,
    lr_column_settings TYPE REF TO if_salv_wd_column_settings,
    lt_columns         TYPE        salv_wd_t_column_ref,
    lr_checkbox        TYPE REF TO cl_salv_wd_uie_checkbox.

  FIELD-SYMBOLS
    <fs_column> LIKE LINE OF lt_columns.

* Instantiate the ALV Component
  lr_alv_usage = wd_this->wd_cpuse_cmp_alv( ).
  IF lr_alv_usage->has_active_component( ) IS INITIAL.
    lr_alv_usage->create_component( ).
  ENDIF.

* Get reference to model
  lr_if_controller = wd_this->wd_cpifc_cmp_alv( ).
  lr_config        = lr_if_controller->get_model( ).

  lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).

* Set the UI elements.
  lr_column_settings ?= lr_config.
  lt_columns = lr_column_settings->get_columns( ).

  LOOP AT lt_columns ASSIGNING <fs_column>.
    IF <fs_column>-id = 'CHECK_BOX'.
      CREATE OBJECT lr_checkbox
        EXPORTING
          checked_fieldname = <fs_column>-id.
      <fs_column>-r_column->set_cell_editor( lr_checkbox ).

    ENDIF.
  ENDLOOP.

7) In the WDDOMODIFYVIEW call the Build_ALV method

wd_this->build_alv( )

😎 Test the application

Best Regards

Chaitanya.A