cancel
Showing results for 
Search instead for 
Did you mean: 

need a code for dynamic programming

Former Member
0 Kudos

i want to create a CONTEXT NODE dynamiclly of dictionary structure type SFLIGHT in which i want to add the attributes  Carrid , connid , fldate from SFLIGHT , and also want to create a input field , label and table to fetch the Data from sflight on giving input as CARRID ,its very urgent .

please provide me the code for this , i joined as a fresher 2 weeks before and working on dynamic programming.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Here is the complete code...please let me know if you have any other query...if it works mark the thread as answered.

METHOD wddoinit .
  DATA: lv_node TYPE REF TO if_wd_context_node,
        lv_root_node_info TYPE REF TO if_wd_context_node_info,
        lv_node_info TYPE REF TO if_wd_context_node_info.

  DATA: lv_attr TYPE wdr_context_attribute_info.

  lv_root_node_info = wd_context->get_node_info( ).

  CALL METHOD lv_root_node_info->add_new_child_node
    EXPORTING
      static_element_type          = 'SFLIGHT'
      name                         = 'FLIGHTS'
    RECEIVING
      child_node_info              = lv_node_info.

  lv_attr-name = 'CARRID'.
  lv_attr-type_name = 'SFLIGHT-CARRID'.

  CALL METHOD lv_root_node_info->add_attribute
    EXPORTING
      attribute_info = lv_attr.

ENDMETHOD.


METHOD wddomodifyview .
  DATA  l_root   TYPE REF TO cl_wd_uielement_container.
  DATA  lv_label_flow TYPE REF TO cl_wd_flow_data. 
  DATA: l_node   TYPE REF TO if_wd_context_node,
        l_table  TYPE REF TO cl_wd_table ,
        lv_button  TYPE REF TO cl_wd_button,
        lv_input  TYPE REF TO cl_wd_input_field,
        lv_label  TYPE REF TO cl_wd_label.

  IF first_time = abap_true.
    l_root ?= view->get_root_element( ).

  CALL METHOD cl_wd_button=>new_button
    EXPORTING
      id                     = 'BUTTON'
      on_action              = 'GET_DATA'
      text                   = 'Get Data'
    RECEIVING
      control                = lv_button.

  CALL METHOD cl_wd_input_field=>new_input_field
    EXPORTING
      bind_value             = 'CARRID'
      id                     = 'INPUT'
    RECEIVING
      control                = lv_input.

  CALL METHOD cl_wd_label=>new_label
    EXPORTING
      id                     = 'LABEL'
      label_for              = 'INPUT'
      text                   = 'Assigned To'
    RECEIVING
      control                = lv_label.


  CALL METHOD cl_wd_flow_data=>new_flow_data
    EXPORTING
      element = lv_label
    RECEIVING
      control = lv_label_flow.
  DATA lv_input_flow TYPE REF TO cl_wd_flow_data.
  CALL METHOD cl_wd_flow_data=>new_flow_data
    EXPORTING
      element = lv_input
    RECEIVING
      control = lv_input_flow.
  DATA lv_button_flow TYPE REF TO cl_wd_flow_data.
  CALL METHOD cl_wd_flow_data=>new_flow_data
    EXPORTING
      element = lv_button
    RECEIVING
      control = lv_button_flow.

  l_root->add_child( the_child = lv_label ).
  l_root->add_child( the_child = lv_input ).
  l_root->add_child( the_child = lv_button ).

    l_node = wd_context->get_child_node( 'FLIGHTS' ).
    l_table = cl_wd_dynamic_tool=>create_table_from_node(
    ui_parent = l_root
    table_id = 'MY_TABLE'
    node = l_node
    ).

  ENDIF.
ENDMETHOD.


METHOD onactionget_data .
  DATA lv_node   TYPE REF TO if_wd_context_node.
  DATA lv_carrid  TYPE zpm_employee_id.
  DATA itab   TYPE STANDARD TABLE OF sflight.

  CALL METHOD wd_context->get_attribute
    EXPORTING
      name  = 'CARRID'
    IMPORTING
      value = lv_carrid.

  CALL METHOD wd_context->get_child_node
    EXPORTING
      name       = 'FLIGHTS'
    RECEIVING
      child_node = lv_node.

  SELECT * FROM sflight INTO TABLE itab WHERE CARRID = lv_carrid.

  lv_node->bind_table( itab  ).
ENDMETHOD.

Regards,

Sayan

Former Member
0 Kudos

hi sayan ,

i am doing like that only but the srroe is coming the lead selection has not been set in main_view.

Former Member
0 Kudos

Hi,

Actually, I am not getting the requirement why lead selection is required. Initialize lead selection is by default abap_true when we create a context node. Could you please explain the requirement and the error details like when you are getting it so that I can have a better understanding of the error.

Regards,

Sayan

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Please follow the link

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10c837ab-d4c4-2d10-fca0-a1b6c09bc...

It contains the code to create context nodes dynamically.

Hope it helps.

Regards,

Sayan

Former Member
0 Kudos

Hi ,

Here student node is having firstname, lastname and dateofbirth attributes.

'YSTR_PERSON'  structure contains  3 fields, like firstname, lastname and dateofbirth

 

DATA: lr_node TYPE REF TO if_wd_context_node,

lr_node_info TYPE REF TO if_wd_context_node_info,

lr_child_node_info TYPE REF TO if_wd_context_node_info.

lr_node_info = wd_context->get_node_info( ).

lr_child_node_info = lr_node_info->add_new_child_node(

name = 'STUDENT'

is_singleton = abap_true

is_multiple = abap_false

is_mandatory = abap_true

static_element_type = 'YSTR_PERSON'

).

lr_node = wd_context->get_child_node( 'STUDENT' ).

DATA ls_data TYPE ystr_person.

ls_data-firstname = 'Antonia Maria'.

ls_data-lastname = 'Keller'.

ls_data-dateofbirth = '19800306'.

lr_node->bind_structure( EXPORTING new_item = ls_data ).

For Input field  fallow below code...

 

DATA

lr_input_field TYPE REF TO cl_wd_input_field.

lr_input_field = cl_wd_input_field=>new_input_field(

id = ’NAME’

bind_value = lv_bind_name).

Regards,

Venkat

Former Member
0 Kudos

Hi , i am writing this code in wddoinit ..but its giving me dump

DATA: lv_root_node TYPE REF TO if_wd_context_node,

        lv_root_node_info TYPE REF TO if_wd_context_node_info,

        lv_node_info TYPE REF TO if_wd_context_node_info.

*

  lv_root_node_info = wd_context->get_node_info( ).



  CALL METHOD lv_root_node_info->add_new_child_node

    EXPORTING

*       static_element_type          = 'sflight'

      name                         = 'FLIGHTS'

      is_mandatory                 = abap_false

      is_mandatory_selection       = abap_false

      is_multiple                  = abap_true

      is_multiple_selection        = abap_true

      is_initialize_lead_selection = abap_true

    RECEIVING

      child_node_info              = lv_node_info.

    lv_root_node->get_child_node( name = 'FLIGHTS').(giving dump here acess via null object not possible ).



    data : itab TYPE TABLE OF sflight .

    select * from sflight INto TABLE itab .

    lv_root_node->bind_table( itab  ).

I also defind the label , input field for sflight-carrid and table to display the data and also defined the Action , on sort , on lead select while creating the table dynamiclly .

i am using the method cl_wd_table->new_table.

Former Member
0 Kudos

Hi,

Uncomment the static_element_type.....   SFLIGHT shouldbe structure with fields......

CALL METHOD lv_root_node_info->add_new_child_node

    EXPORTING

*       static_element_type          = 'sflight'

      name                         = 'FLIGHTS'

      is_mandatory                 = abap_false

      is_mandatory_selection       = abap_false

      is_multiple                  = abap_true

      is_multiple_selection        = abap_true

      is_initialize_lead_selection = abap_true

    RECEIVING

      child_node_info              = lv_node_info.

Former Member
0 Kudos

Hi,

You are getting the dump because lv_root_node is still initial. Variable lv_root_node_info contains the root node information.

Regards,

Sayan

Former Member
0 Kudos

Hi,

Make the properties like below...

is_singleton = abap_true

is_multiple = abap_false

is_mandatory = abap_true

Regards,

Venkat

Former Member
0 Kudos

Hi sayan ,

I joined as a frehser 10 days before so new to dynamic programming can you give me a correct code after correcting that code.

i am providing my whole code please you can go through it, its very urgent .

Former Member
0 Kudos

i posted the code for do init before , this code i write in wddomodifyview.

please check it once .

this is the code i write in wddomodifyview ...and wddoinit i posted before.

DATA :lr_ui_root TYPE REF TO if_wd_view_element,

         lr_container TYPE REF TO cl_wd_uielement_container.

       CHECK first_time = abap_true.

     lr_ui_root = view->get_root_element( ).

     lr_container ?= lr_ui_root.

  cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).

  lr_container->set_width( value = '50%' ).

  lr_container->set_height( value = '50%' ).


  data : lr_label_carrid type ref to cl_wd_label,

         lr_input_carrid type ref to cl_wd_input_field,

         lr_button TYPE ref to cl_wd_button,

          lr_table TYPE REF TO cl_wd_table .


  lr_input_carrid =   cl_wd_input_field=>new_input_field( bind_value = 'FLIGHTS.CARRID'

                                                          id         = 'INPUT_FIELD_CARRID' ).


  lr_label_carrid = cl_wd_label=>new_label(  id         = 'LABEL_CARRID'

                                             label_for  = 'INPUT_FIELD_CARRID'

                                             text       = 'Enter The carrier id' ).

  call METHOD  CL_WD_BUTTON=>NEW_BUTTON

  exporting

                  ID                  = 'BUTTON'

                   ON_ACTION           = 'GET_DETAILS'

                   TEXT                = 'GET_DATA'

*                  VISIBLE             = E_VISIBLE-VISIBLE

*                  WIDTH               =

                 RECEIVING

                  CONTROL             = lr_button .



  CALL METHOD CL_WD_TABLE=>NEW_TABLE

   EXPORTING

      BIND_DATA_SOURCE              = 'MAIN_VIEW.FLIGHTS'

      BIND_DESIGN                   = 'STANDARD'

*      BIND_EMPTY_TABLE_TEXT         =

      BIND_ENABLED                  =  'X'

      BIND_FOOTER_VISIBLE           =  'X'

     BIND_ROW_SELECTABLE           = 'X'

     ENABLED                       = ABAP_TRUE

*      FIRST_ACTUAL_ROW              =

*      FIRST_VISIBLE_ROW             =

*      FIRST_VISIBLE_SCROLL_COL      =

*      FIXED_TABLE_LAYOUT            =

*      FOOTER_VISIBLE                = ABAP_TRUE

*      GRID_MODE                     = E_GRID_MODE-BOTH

      ID                            = 'TABLE'

*      LEGEND_ID                     =

     ON_FILTER                     = 'ON_FILTER'

      ON_LEAD_SELECT                = 'ON_LEAD_SELECT'

*      ON_SCROLL                     =

     ON_SORT                       = 'ON_SORT'

*      READ_ONLY                     =

*      ROW_COUNT                     = -1

*      ROW_SELECTABLE                = ABAP_TRUE

*      SCROLLABLE_COL_COUNT          = -1

*      SELECTED_POPIN                =

*      SELECTION_CHANGE_BEHAVIOUR    = E_SELECTION_CHANGE_BEHAVIOUR-AUTO

*      SELECTION_MODE                = E_SELECTION_MODE-AUTO

*      TOOLTIP                       =

*      VIEW                          =

*      VISIBLE                       = E_VISIBLE-VISIBLE

     VISIBLE_ROW_COUNT             = 5

*      WIDTH                         =

    RECEIVING

      CONTROL                       = lr_table .



  LR_TABLE ?= view->get_element('TABLE').( this is for sorting the table ).

  wd_this->table_control ?= LR_table->_method_handler .

  wd_this->table_control->set_key_attribute_name( 'CARRID').


  cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_label_carrid ).

  cl_wd_matrix_data=>new_matrix_data( element = lr_input_carrid ).

  cl_wd_matrix_head_data=>new_matrix_data( element = lr_button ).

   cl_wd_matrix_head_data=>new_matrix_data( element = lr_table ).


  lr_container->add_child( the_child = lr_label_carrid ).

  lr_container->add_child( the_child = lr_input_carrid ).

  lr_container->add_child( the_child = lr_button ).

  lr_container->add_child( the_child = lr_table ).



endmethod.

Former Member
0 Kudos

still giving me dump..acess via null object not possible....

Former Member
0 Kudos

Hi,

The code seems to be ok. What issue you are getting in this?

Former Member
0 Kudos

Hi,

Use the following code in WDDOINIT.

  DATA: lv_node TYPE REF TO if_wd_context_node,
        lv_root_node_info TYPE REF TO if_wd_context_node_info,
        lv_node_info TYPE REF TO if_wd_context_node_info.
 
  lv_root_node_info = wd_context->get_node_info( ).

  CALL METHOD lv_root_node_info->add_new_child_node
    EXPORTING
      static_element_type          = 'SFLIGHT'
      name                         = 'FLIGHTS'
    RECEIVING
      child_node_info              = lv_node_info.
  CALL METHOD wd_context->get_child_node
    EXPORTING
      name       = 'FLIGHTS'
    RECEIVING
      child_node = lv_node.

    data : itab TYPE TABLE OF sflight .

    select * from sflight INto TABLE itab .

    lv_node->bind_table( itab  ).

Regards,

Sayan

Former Member
0 Kudos

Hi,

Here is the code to create a dynamic table to be written in WDDOMODIFYVIEW.

  DATA l_root TYPE REF TO cl_wd_uielement_container.
  DATA: l_node TYPE REF TO  if_wd_context_node,
      l_table TYPE REF TO cl_wd_table .

  IF first_time = abap_true.

    l_root ?= view->get_root_element( ).

    l_node = wd_context->get_child_node( 'FLIGHTS' ).

    l_table = cl_wd_dynamic_tool=>create_table_from_node(

    ui_parent = l_root

    table_id = 'MY_TABLE'

    node = l_node

    ).

  ENDIF.

I didn't get the requirement why the input field, button and label were created. If the table data is dependent on the input the code of WDDOINIT needs to be modified a bit. The context nodes needs to be populated in the onClick event of the button.

Hope the above code helps. Please let me know if you need any further input.

Regards,

Sayan

Former Member
0 Kudos

i was using cl_wd_table->new_table ...then i used cl_wd_dynamic_tool->create_table_from_node ..now its working ...why we can't use cl_wd_table->new_table method to create dynamic table..as we create button , inp filed , label like that only...

Former Member
0 Kudos

i was defining button also by cl_wd_button->new_button ..here i am defining an action getdata ..and defining label and input field carrid ..on the basis of carrid i have to fetch the data ...

Former Member
0 Kudos

ya sayan this code is absolutly right , if i want to fetch the data on the basis of input field CARRID ...i defined action getdata ...here is the code for that

DATA :  NODE_FLIGHTS TYPE REF TO IF_WD_CONTEXT_NODE ,
               ELEM_FLIGHTS TYPE REF TO IF_WD_CONTEXT_ELEMENT.

*          STRU_FLIGHTS TYPE   IF_MAIN_VIEW=>ELEMENT-FLIGHTS.


             DATA : ITAB TYPE TABLE OF sflight .
  NODE_FLIGHTS = WD_CONTEXT->GET_CHILD_NODE( 'FLIGHTS').



  ELEM_FLIGHTS = NODE_FLIGHTS->GET_ELEMENT( ).








  SELECT * FROM SFLIGHT INTO TABLE ITAB .

  NODE_FLIGHTS->BIND_TABLE( ITAB )...

i remove this data fetching code from wddoinit method ....i just want to define the node there ...and fetch the data here ..but now dump is lead selection is not set .

Former Member
0 Kudos

Hi,

You can always use NEW_TABLE of CL_WD_TABLE to create a table. But if the node is not created by that time, it would dump.

However what you can do is ,

1. Create a node dynamically

2. Then create a table dynamically where you can bind the table to node created in step 1.

OR

1. Create a table dynamically but dont bind it yet. i.e. dont pass anything in that parameter

2. Create the node. FIll it with data.

3. Now bind the table created in step 1 to node in step2.

Former Member
0 Kudos

1. After creating the node, get the context node info using NODE_INFO= NODE->GET_NODE_INFO( ).

2. Now call NODE_INFO->IS_INITIALIZE_LEAD_SELECTION( ABAP_TRUE ).

I hope the dump should go.

Former Member
0 Kudos

yeah , its correct thanks for the help  ...its good technology to work with...as a fresher i am enjoy working on webdynpro dynamic programming

Former Member
0 Kudos

If your questions are answered, please mark the thread as answered.

Thank You.