cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically check checkbox

Former Member
0 Kudos

Hi Experts !

I have an application written in WEB DYNPRO ABAP. The application is passed to the variable CHAR. In the window, which displays when you start is a CHECKBOX. When a variable has a value of X the CHECKBOX should be selected. Not if the variable is empty. How to do this?

I have structure:

ROOTUIELEMENTCONTAINER

- OZS (Group)

- Element1

- Element2

.

.

.

- Checkbox

Thanks for your help.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi.

My CheckBox is associated with str_node_bool-sd_bool, the second with str_node_bool-ps_bool.

Former Member
0 Kudos

Hi

Try by changing this code ..

IF str_node_str-sd EQ 'X'.

str_node_bool-sd_bool = abap_true.

ELSE.

str_node_bool-sd_bool = abap_false.

ENDIF.

IF str_node_str-ps EQ 'X'.

str_node_bool-ps_bool = abap_true.

ELSE.

str_node_bool-ps_bool = abap_false.

ENDIF.

Try this... create SD_BOOL and PS_BOOL of type wdy_boolean and bind this attributes to checked properties of check box.

IF str_node_str-sd is not INITIAL.

  • set single attribute

el_node_bool ->set_attribute(

name = `SD_BOOL`

value = 'X' ).

else.

  • set single attribute

el_node_bool ->set_attribute(

name = `SD_BOOL`

value = ' ' ).

endif.

IF str_node_str-ps is not INITIAL.

  • set single attribute

el_node_bool ->set_attribute(

name = `PS_BOOL`

value = 'X' ).

else.

  • set single attribute

el_node_bool ->set_attribute(

name = `PS_BOOL`

value = ' ' ).

endif.

Cheers,

Kris.

Edited by: kissnas on Mar 21, 2011 11:48 AM

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi.

It works! Thank you very much Kris and others. Helped me out. Thanks again.

Andy

Former Member
0 Kudos

Hi.

YES

Former Member
0 Kudos

Hi.

KISSNAS sorry, but this does not work. When I run the program I get the message: Could not find attribute CHECK. Lines


lr_group ?= view->get_element( id = 'OZS' ).
sd_check = lr_group-> get_child (id = 'OZS_SD').

returns the element of CheckBox but I can get to its parameters.

Please help.

Former Member
0 Kudos

Hi Jedeus,

U have to create CHECK attribute of type wdy_boolean.

Cheers,

Kris.

Former Member
0 Kudos

Hi.

I check variable. Depending on its value I want to select the checkbox or not. This is method wddomodifyview:


METHOD wddomodifyview .
  DATA node_str TYPE REF TO if_wd_context_node.
  DATA node_bool TYPE REF TO if_wd_context_node.
  DATA el_node_str TYPE REF TO if_wd_context_element.
  DATA el_node_bool TYPE REF TO if_wd_context_element.
  DATA str_node_str TYPE ig_componentcontroller=>element_str.
  DATA str_node_bool TYPE ig_componentcontroller=>element_bool.
  DATA sd_check TYPE REF TO cl_wd_uielement."cl_wd_checkbox.
  DATA ps_check TYPE REF TO cl_wd_checkbox.
  DATA l_view_sd type ref to cl_wd_view_container_uielement.
  DATA lr_ui_root TYPE REF TO if_wd_view_element.
  DATA lr_container TYPE REF TO cl_wd_uielement_container.
  DATA lr_group TYPE REF TO cl_wd_group.

  node_str = wd_context->get_child_node( name = 'STR' ).
  el_node_str = node_str->get_element( ).
  el_node_str->get_static_attributes(
    IMPORTING
      static_attributes = str_node_str ).

  node_bool = wd_context->get_child_node( name = 'BOOL' ).
  el_node_bool = node_bool->get_element( ).
  el_node_bool->get_static_attributes(
    IMPORTING
      static_attributes = str_node_bool ).

  lr_ui_root = view->get_root_element( ).
  lr_container ?= lr_ui_root.

  lr_group ?= view->get_element( id = 'OZS' ).
  sd_check = lr_group->get_child( id = 'OZS_SD' ).
  *sd_check->checked( abap_true ). ????(How to do it ?)*

  IF str_node_str-sd EQ 'X'.
    str_node_bool-sd_bool = abap_true.
  ELSE.
    str_node_bool-sd_bool = abap_false.
  ENDIF.

  IF str_node_str-ps EQ 'X'.
    str_node_bool-ps_bool = abap_true.
  ELSE.
    str_node_bool-ps_bool = abap_false.
  ENDIF.
ENDMETHOD.

Former Member
0 Kudos

Hi Jedeus,

create one attribute of type WDY_BOOLEAN and bind this to checkbox checked property.

try below example code, in this i am taking one input field, if this input field is filled at initialization

checkbox will checke, if not initial checkbox will be unchecked. Change this according your requirement.

Hope it solves your problem.

method WDDOINIT .

DATA lo_el_context TYPE REF TO if_wd_context_element.

DATA ls_context TYPE wd_this->Element_context.

DATA lv_text TYPE wd_this->Element_context-text.

DATA lv_check TYPE wd_this->Element_context-check.

  • get element via lead selection

lo_el_context = wd_context->get_element( ).

  • get single attribute

lo_el_context->get_attribute(

EXPORTING

name = `TEXT`

IMPORTING

value = lv_text ).

lv_text = 'Webdynpro'.

  • get single attribute

lo_el_context->set_attribute(

EXPORTING

name = `TEXT`

value = lv_text ).

if lv_text is not INITIAL.

  • set single attribute

lo_el_context->set_attribute(

name = `CHECK`

value = 'X' ).

endif.

endmethod.

cheers,

Kris.

Former Member
0 Kudos

hi,

See this help [http://help.sap.com/saphelp_nw70ehp1/helpdata/en/97/ad884118aa1709e10000000a155106/content.htm|http://help.sap.com/saphelp_nw70ehp1/helpdata/en/97/ad884118aa1709e10000000a155106/content.htm]

Checkbox UI checked property is need to be binded to wdy_boolean type context attribute.

Since you said that you get passed a variable of type char. it would be just fine to bind this variable (context attribute) to the UI property checked.