cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic creation of context node

Former Member
0 Kudos

Hi All,

I have to create the context node dynamically by using SE38 program . After searching in SDN , I found the below code which will create context node in the run time.

The code is useful to me. But i have a doubt in this.

In the below code i could not use wd_context and instead i will use if_wd_context_node variable. Thats not a problem.

The lr_rootnode_info will be blank when i am running this code . Right? So how can i get the instance of the lr_rootnode_info.?

lr_rootnode_info = wd_context->get_node_info( ).

  CALL METHOD lr_rootnode_info->add_new_child_node
   
EXPORTING
      static_element_type          =
'SFLIGHT'
      name                         =
'FLIGHT'
    RECEIVING
      child_node_info              = lr_node_info.
  lr_node = wd_context->get_child_node( name =
'FLIGHT' ).

Thanks,

Pradeep

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Take a look at this document which details the creation of nodes and attributes.

http://scn.sap.com/docs/DOC-35485

thanks, Phil

Former Member
0 Kudos

Hi Phil,

Thanks for your document . It was nice. But what i need is the input box should be created by the SE38 program. The document explains how to create the Input box dynamically and the code has been written inside the WD method.

I have a question and if i get the answer for this i can able to create the WD inpup box by the Zprogram ( SE38).

Consider I have a WD component and a view as shown below.

And the context node i has is shown below.

My question is How to get the instance of this context from the SE38 program?

Please share !!!

Thanks,

Pradeep.

Former Member
0 Kudos

Well, you have certainly peaked my curiosity as to why you want to do this.  Which program is calling which?  Is the SE38 program executing the WebDynpro?  Or is it the other way round?  While I'm not sure why you would want to do this and I really can't see a reason to do it, there is the option of sharing an instance of a class between the programs.  The instanced class would need to reference the context of the dynpro.  Please explaing more of what you are doing and why.  There might be a better approach. Thanks, Phil

Former Member
0 Kudos

Hi Phil ,

I was confussed and also i made you confussed. I have got my correct requirement now.

I have to create the Label and a Input box dynamically and the coding part should be in the WD component itself. No Need of Se38.

Could  you please tell me what all are the steps to be done to achieve this.

First have i need to create a node??? Or the default Context is enough.

Thanks,

Pradeep.

Former Member
0 Kudos

Hi Phil ,

I have also tryed with the documenet you prefered and i got the dumb as "

  • The following error occurred in system  : Error in FLOW_LAYOUT "_02" of view "YPP_SDN.MAIN": LayoutData type "MATRIX_HEAD_DATA" for child element "CONTROLA" is not permitted "
Former Member
0 Kudos

That's an easy fix.  Go to the properties of your:  ROOTUIELEMENT container and change the layour to matrixdata.  That should fix it.  Remember to mark this post as answered if this is the correct answer you require.  thanks, Phil

Former Member
0 Kudos

Well its works fine Phil. my requirement is simple.

1. Have to create a node

2. Have to create the Label

3. have to create the input box

I have almost done the coding and i have pasted the code below.

Do i want to write all those code in Do modify method?

My code

*************

data : lo_cn_info TYPE REF TO if_wd_context_node_info,
          lo_cn
TYPE REF TO if_wd_context_node.
data : lv_node type string VALUE 'SRM2013',
        lo_new_node
type REF TO if_wd_context_node,
        lr_matrix
type ref to cl_wd_matrix_data,
        lr_container 
type ref to cl_wd_uielement_container,
        lv_label
type ref to cl_wd_label,
lr_attribute_info 
type wdr_context_attribute_info.


lo_cn_info
= wd_context->get_node_info( ).
if lo_cn_info is bound.

 
call method lo_cn_info->add_new_child_node
   
exporting*      supply_method                =*      supply_object                =*      dispose_method               =*      dispose_object               =*      static_element_type          =
      name                        
= lv_node
      is_mandatory                
= ABAP_FALSE
      is_mandatory_selection      
= ABAP_FALSE
      is_multiple                 
= ABAP_TRUE
      is_multiple_selection       
= ABAP_false
      is_singleton                
= ABAP_FALSE
      is_initialize_lead_selection
= ABAP_TRUE*      static_element_rtti          =
      is_static                   
= ABAP_false*      attributes                   =*      is_range_node                =
    receiving
      child_node_info             
= lo_cn_info.

   lr_attribute_info
-name           = 'SYS_ID'.
  lr_attribute_info
-type_name      = 'CHAR100'.
  lr_attribute_info
-value_help_mode = '0'.

  lo_cn_info
->add_attribute(
        
exporting attribute_info = lr_attribute_info
                            
).
endif.
lo_new_node
= wd_context->get_child_node( lv_node ).
IF  lo_new_node is BOUND.
   
call method cl_wd_label=>new_label(
     
exporting
        design   
= '00'
        enabled  
= 'X'
       
id        = 'LABEL1'
        label_for
= 'INPUTBOX'
       
text      = 'Enter the value'
      receiving
       
control   = lv_label ).
data lo_control TYPE REF TO CL_WD_INPUT_FIELD.
call method cl_wd_input_field=>new_input_field
 
exporting*    activate_access_key    =*    alignment              = E_ALIGNMENT-AUTO*    bind_alignment         =*    bind_display_as_text   =*    bind_enabled           =*    bind_ime_mode          =*    bind_input_prompt      =*    bind_length            =*    bind_password_field    =*    bind_read_only         =*    bind_state             =*    bind_text_direction    =*    bind_tooltip           =*    bind_value             =*    bind_visible           =*    bind_width             =*    context_menu_behaviour = E_CONTEXT_MENU_BEHAVIOUR-INHERIT*    context_menu_id        =*    display_as_text        =*    enabled                = 'X'*    explanation            =
   
id                     = 'INPUTBOX'*    ime_mode               = E_IME_MODE-AUTO*    input_prompt           =
    length                
= '20'*    on_enter               =*    password_field         =*    read_only              =*    state                  = E_STATE-NORMAL*    suggest_values         =*    text_direction         = E_TEXT_DIRECTION-INHERIT*    tooltip                =*    view                   =
    visible               
= '02'"E_VISIBLE-VISIBLE*    width                  =
  receiving
   
control                = lo_control
   
.


data : lo_layout TYPE REF TO CL_WD_LAYOUT_DATA,
       lv_flow
TYPE REF TO cl_wd_flow_data.


     
if lv_label is bound.*      lr_matrix_link = cl_wd_matrix_data=>new_matrix_data(*                       element = lv_link ).
       
call method cl_wd_flow_data=>new_flow_data
         
exporting
            element
= lv_label
          receiving
           
control = lv_flow.

*        if lv_flow is bound.*          lv_label->set_layout_data( lr_matrix ).*          call method lv_label->set_layout_data*            exporting*              the_layout_data = lr_matrix .
*       lv_label->set_layout_data( lv_flow ).
*        endif.
     
endif.
data : lr_matrix_link     type ref to cl_wd_matrix_data.
call method cl_wd_matrix_data=>new_matrix_data
                 
exporting
                    element
= lo_control
                  receiving
                   
control = lr_matrix_link.
               
if lr_matrix_link is bound.
                  lo_control
->set_layout_data( lr_matrix_link ).
               
endif.

e
ndif.

lr_container ?= view
->get_element( 'ROOTUIELEMENTCONTAINER' ).
if lr_container is bound.
 
call method lr_container->add_child
                   
exporting
                     
index     = 01
                      the_child
= lv_label.

 
call method lr_container->add_child
                   
exporting
                     
index     = 02
                      the_child
= lo_control.
endif.

Those code has been written in the method .WDDOMODIFYVIEW.

But i am getting the dumb. I guess i would be a blunder.

thanks,

Pradeep.

B

Former Member
0 Kudos

You put your dynamic code in the WDDOMODIFYVIEW event.  You wil notice that there is a FIRST_TIME parameter.  You should put your code betwwen a check for first_time.  Like:

if first_time = abap_true.

  Put your code here

endif.

Former Member
0 Kudos

Hi Phil,

Now i am getting an error as " Error in LABEL "LABEL1" of view "YPP_DEEP2.MAIN": Property "labelFor" has value "INPUTBOX"; at any rate there is no view element with this ID "

Could you please run this code ?

Former Member
0 Kudos

When you create labels, you create them to assign to other controls.  So if you create "CONTROLA" which is an input box and need a label for it, create a label "CONTROLB" and assign the labelfor attribute:  "CONTROLA".

Former Member
0 Kudos

Yes i have assigned that , But now i am getting an error as "Access via 'NULL' object reference not possible." Hope some object is null. Have to find out.

Former Member
0 Kudos

Hi Phill,

Finally i have done ..

Former Member
0 Kudos

Awesome.  It always feel good to figure out new development areas.  If my information assisted you, please remember to "like" my responses.  thanks..

Answers (1)

Answers (1)

former_member184578
Active Contributor
0 Kudos

Hi,

Why couldn't you use wd_context? lr_rootnode_info will not be blank. get_node_info( ) method will return the instance of type CL_WDR_CONTEXT_NODE_INFO.

Please see DEMODYNAMIC standard Web Dynpro Component.

Also Check   sir's Video tutorial on how to Dynamically Create Context nodes and context mapping for clear idea in this document: http://scn.sap.com/docs/DOC-10230

Hope this helps u.,

Regards,

Kiran

Former Member
0 Kudos

Hi Kiran,

You cannot use wd_context outside the webdynpro component . It will throw you an error.

former_member184578
Active Contributor
0 Kudos

Hi,

Am sorry. I didn't read it that you are creating from SE38. wd_context will be instantiated automatically when you are running web dynpro application.

Am not sure you can get that from SE38 as the wd_context instance will be created from delegation component class.

Keep a break point in DO_INIT method of CL_WDR_DELEGATING_COMPONENT class. Then in debugger press F5 you will find the corresponding delegator class init method. You will find the call

f_Appl_class->wddoint( ).

here f_Appl_class will contain the wd_context attribute which already got instantiated.

you can find the instantiation of f_Appl_class in the same class constructor method.

this may help you for getting the wd_context instance.

Regards,

Kiran

Former Member
0 Kudos

Hi Kiran,

I have kept the break point as you have said. And my doubt is what else i have to run to get this debug???

former_member184578
Active Contributor
0 Kudos

Hi,

Run any web dynpro application. It will trigger the debugger. This is jus for your info. So that you can code accordingly. 

May I know the purpose of your requirement!!

You want to create node dynamically in WDA and it should be persistent..? If so, this may not help you because as far i knew the add_child_node and related methods for dynamic node creation, will create context nodes dynamically at run time and after exiting the application the context will be empty.

Regards,

Kiran