cancel
Showing results for 
Search instead for 
Did you mean: 

Read Dynamic data from Action button

former_member1193316
Participant
0 Kudos

Hi,

I have coded to generate few check boxes and button dynamically along with on_action method on button.

now in on_action method, how can i read the values of check boxes wether they r checked or not?

Kindly let me know the solution.

Thanks in advance,

venkat

Accepted Solutions (1)

Accepted Solutions (1)

gill367
Active Contributor
0 Kudos

Hi

You might have coded in teh wddomodify to create the checkbox and then you should have bound its checked property

to context as shown below. here i am binding the property checked of a newly created checkbox to attirbute CHK of the

node CHECKVAL. and this attribute if of type WDY_Boolean.



data chk type ref to cl_wd_checkbox.
  chk = cl_wd_checkbox=>new_checkbox(  ).
  
chk->bind_checked( 'CHECKVAL.CHK' ).

now go to the action event handler of the button.

there just check the value of this attribute if it is true means check box is checked other wise not checked.

code in the event handler

data node type ref to if_wd_context_node.
node = wd_context->get_child_node( 'CHECKVAL'  ).
data val type wdy_boolean.
node->get_attribute( 
name = 'CHK'
value  =  val

).

"now just check the value of val. 

if val eq abap_true.


" chceked


else.

"not checked

endif.

thanks

sarbjeet singh

former_member1193316
Participant
0 Kudos

i coded like below


method WDDOMODIFYVIEW .

data: it_modules TYPE STANDARD TABLE OF ymodule,
      wa_modules type ymodule.

DATA: lr_container TYPE REF TO cl_wd_uielement_container,
      lr_checkbox TYPE REF TO cl_wd_checkbox,
      lr_group     type ref to cl_wd_group,
      lr_header    type ref to cl_wd_caption,
      lr_button    type ref to cl_wd_button,
      lr_text      type ref to cl_wd_text_view,
      header_text  type string,
      button_text  type string.


select * from YMODULE into CORRESPONDING FIELDS OF TABLE it_modules.

* get a pointer to the RootUIElementContainer
lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

*   create the group and add it to the container
    lr_group = cl_wd_group=>new_group( id = 'UPPER_GROUP' width = '100%'
                                       design = cl_wd_group=>e_design-sapcolor ).
    cl_wd_grid_data=>new_grid_data( element = lr_group col_span = 3 ).
    cl_wd_grid_layout=>new_grid_layout( container = lr_group COL_COUNT = 3 ).
    lr_container->add_child( lr_group ).

* create the header and assign it to the group
  lr_header ?= cl_wd_caption=>new_caption( text = 'Select Modules' )."header_text ).
  lr_group->set_header( lr_header ).

* create the button and add it to the group
  lr_button     = cl_wd_button=>new_button( text = 'Select All' ON_ACTION = 'SELECT').
  cl_wd_grid_data=>new_grid_data( element = lr_button ).
  lr_group->add_child( lr_button ).

* create the button and add it to the group
  lr_button     = cl_wd_button=>new_button( text = 'De-Select ALL'  ON_ACTION = 'DESELECT').
  cl_wd_grid_data=>new_grid_data( element = lr_button ).
  lr_group->add_child( lr_button ).

* create the button and add it to the group
  lr_text = cl_wd_text_view=>new_text_view( text = '').
  cl_wd_grid_data=>new_grid_data( element = lr_text ).
  lr_group->add_child( lr_text ).


loop at it_modules into wa_modules.

  data: text type string.

  text = wa_modules-MODULE_DESC.
  lr_checkbox = cl_wd_checkbox=>new_checkbox( text = text bind_checked = 'CHECKBOX.CHECK_VALUE' view = view ).
  cl_wd_grid_data=>new_grid_data( element = lr_checkbox ).
  lr_group->add_child( lr_checkbox ).

endloop.


* create the button and add it to the group
  lr_button     = cl_wd_button=>new_button( text = 'Get Fields' ON_ACTION = 'GET' ).
  cl_wd_grid_data=>new_grid_data( element = lr_button ).
  lr_group->add_child( lr_button ).



endmethod.

now when i run the application, i got aroung 10 checkboxes.

with buttons.

Now i have a action method for a button.. I will check few of the checkboxes and click on a button. Now wer i can read the values of checkboxes ,

Thanks,

Venkat

gill367
Active Contributor
0 Kudos

Modify the code near the loop to create one attribute each for one checkbox.

data nd type ref to if_wd_context_node.
DATA NINF TYPE REF TO IF_WD_CONTEXT_NODE_INFO.
nd = wd_context->get_child_node( 'CHECKBOX' ).
DATA ATTRINF TYPE  WDR_CONTEXT_ATTRIBUTE_INFO.
data str type string.
NINF = ND->GET_NODE_INFO( ).
data text type string.


loop at it_modules into wa_modules.

  str = sy-tabix.
  concatenate 'ATTR' STR INTO STR.
  condense str.
ATTRINF-NAME = str.
ATTRINF-TYPE_NAME = 'WDY_BOOLEAN'.
NINF->ADD_ATTRIBUTE( ATTRINF ).
CONCATENATE 'CHECKBOX.' STR INTO STR.
  condense str.
 text = wa_modules-MODULE_DESC.
  lr_checkbox = cl_wd_checkbox=>new_checkbox( text = text bind_checked = STR view = view ).
  cl_wd_grid_data=>new_grid_data( element = lr_checkbox ).
  lr_group->add_child( lr_checkbox ).
  str = ''.

endloop.

now if there are 10 checkboxes created. read all the attribute accordingly.

if first checkbox is checked then attribute ATTR0 of the node CHECKBOX will be true.

thanks

sarbjeet singh

former_member1193316
Participant
0 Kudos

Hi Sarbjeet,

Thanks for your code...

I modified my code as below



data nd type ref to if_wd_context_node.
DATA NINF TYPE REF TO IF_WD_CONTEXT_NODE_INFO.
nd = wd_context->get_child_node( 'CHECKBOX' ).
DATA ATTRINF TYPE  WDR_CONTEXT_ATTRIBUTE_INFO.
data str type string.
NINF = ND->GET_NODE_INFO( ).
*data text type string.



select * from YMODULE into TABLE it_modules.

if first_time eq abap_true.



* get a pointer to the RootUIElementContainer
lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).

*   create the group and add it to the container
    lr_group = cl_wd_group=>new_group( id = 'UPPER_GROUP' width = '100%'
                                       design = cl_wd_group=>e_design-sapcolor ).
    cl_wd_grid_data=>new_grid_data( element = lr_group col_span = 3 ).
    cl_wd_grid_layout=>new_grid_layout( container = lr_group COL_COUNT = 3 ).
    lr_container->add_child( lr_group ).

* create the header and assign it to the group
  lr_header ?= cl_wd_caption=>new_caption( text = 'Select Modules' )."header_text ).
  lr_group->set_header( lr_header ).

* create the button and add it to the group
  lr_button     = cl_wd_button=>new_button( text = 'Select All' ON_ACTION = 'SELECT').
  cl_wd_grid_data=>new_grid_data( element = lr_button ).
  lr_group->add_child( lr_button ).

* create the button and add it to the group
  lr_button     = cl_wd_button=>new_button( text = 'De-Select ALL'  ON_ACTION = 'DESELECT').
  cl_wd_grid_data=>new_grid_data( element = lr_button ).
  lr_group->add_child( lr_button ).

* create the button and add it to the group
  lr_text = cl_wd_text_view=>new_text_view( text = '').
  cl_wd_grid_data=>new_grid_data( element = lr_text ).
  lr_group->add_child( lr_text ).

  i = 1."sy-index.
loop at it_modules into wa_modules.



  str = sy-tabix.
  concatenate 'ATTR' STR INTO STR.
  condense str.

  ATTRINF-NAME = str.
  ATTRINF-TYPE_NAME = 'WDY_BOOLEAN'.
  NINF->ADD_ATTRIBUTE( ATTRINF ).

  CONCATENATE 'CHECKBOX.' STR INTO STR.
  condense str.
  text = wa_modules-MODULE_DESC.

  lr_checkbox = cl_wd_checkbox=>new_checkbox( text = text bind_checked = STR view = view ).
  cl_wd_grid_data=>new_grid_data( element = lr_checkbox ).
  lr_group->add_child( lr_checkbox ).
  str = ''.

endloop.

* create the button and add it to the group
  lr_button     = cl_wd_button=>new_button( text = 'Get Fields' ON_ACTION = 'GET' ).
  cl_wd_grid_data=>new_grid_data( element = lr_button ).
  lr_group->add_child( lr_button ).
else.

  loop at it_modules into wa_modules.

  str = sy-tabix.
  concatenate 'ATTR' STR INTO STR.
  condense str.  
 
  ATTRINF-NAME = str.
  ATTRINF-TYPE_NAME = 'WDY_BOOLEAN'.

CALL METHOD NINF->get_attribute
  EXPORTING
    name           = ATTRINF-NAME
  receiving
    attribute_info = ATTRINF   .

  str = ''.


  endloop.
endif.

But I didnt get the attribute info wether I checked it or not.

How to read the value wether it is checked or not?

gill367
Active Contributor
0 Kudos

Hi

No need of writing this code in the wddomodify.


loop at it_modules into wa_modules.
 
  str = sy-tabix.
  concatenate 'ATTR' STR INTO STR.
  condense str.  
 
  ATTRINF-NAME = str.
  ATTRINF-TYPE_NAME = 'WDY_BOOLEAN'.
 
CALL METHOD NINF->get_attribute
  EXPORTING
    name           = ATTRINF-NAME
  receiving
    attribute_info = ATTRINF   .
 
  str = ''.
 
 
  endloop.


write the code in the eventhandler of the button



data nd type ref to if_wd_context_node.
nd = wd_context->get_child_node( 'CHECKBOX' ).
data result type string.
data indx type string.
data result_vs type wdy_boolean.
data: it_modules TYPE STANDARD TABLE OF ymodule,
      wa_modules type ymodule.

select * from YMODULE into TABLE it_modules.
loop at it_modules into wa_modules.
 indx = sy-tabix.
 
 
  str = sy-tabix.
  concatenate 'ATTR' STR INTO STR.
  condense str.
nd->get_attribute( 
name = str
value = result_vs
). 
if result_vs eq abap_true.

concatenate result ' -- ' indx into result.

endif. 
endloop.


at the end your string result will contain all the index numbers of the checkboxes checked.

so if 1st , 5th and 9th check boxes are checked then, result string will be

159.

thanks

sarbjeet singh

former_member1193316
Participant
0 Kudos

Dear Sarbjeet,

U helped me lot...thanks for ur co-operation....

Thanks,

Venkat

Answers (0)