cancel
Showing results for 
Search instead for 
Did you mean: 

how to enter data in input field

former_member574106
Participant
0 Kudos

Hi friends,

I am Saurav Lahiry. I am designing my first webdynpro application. In the output, i have got to enter data from the user in fields name and description

and then on clicking submit button, the data must be saved in the database. I saw many blogs relating to this, but i am unable to understand  how to write the code.Please go through the attachment.

Regards,

Saurav Lahiry

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Saurav,

This is the simplest application that can be in webdynpro I believe

You don't need to write the logic in WDDOINIT . It should be written in the Action method of the Submit button .

Follow the steps below :

1.) Create your input fields and bind them to the corresponding context attributes in your controller .

2.) Create a submit button, and a corresponding method for action in the right side properties of the button. ONSubmit, that method should trigger.

3.) In that method, use the code wizard to fetch the values of the input fields and use them to update your database table as required.

There is very less manual coding required here. Code wizard along with correct assignment of variables would do .

Regards.

former_member218528
Participant
0 Kudos

Thats what i specified in the NOTE Point of my First message in this conversation...The enter code must be written in action of your button.....

former_member574106
Participant
0 Kudos

Hi Rohan,

Thanks a lot for the tips. I did all the steps but when i am clicking on SUBMIT button but it is not getting saved in my custom table ZWEBDYNPRO. Please check the code. I have written it inside onSUBMIT event in the button.

method ONACTIONSUBMIT .

TYPES : BEGIN OF ty_employee,

        NAME TYPE pa0001-ename,

        PLANS TYPE pa0001-plans,

        END OF ty_employee.

DATA : itab TYPE STANDARD table of ty_employee ,

       wa   TYPE ty_employee.

  DATA LO_ND_EMPLOYEE TYPE REF TO IF_WD_CONTEXT_NODE.

  DATA LO_EL_EMPLOYEE TYPE REF TO IF_WD_CONTEXT_ELEMENT.

  DATA LS_EMPLOYEE TYPE wd_this->element_employee.

  DATA ls_table_data TYPE wd_this->element_employee.

    DATA lt_table_data TYPE wd_this->elements_employee.

* navigate from <CONTEXT> to <EMPLOYEE> via lead selection

  LO_ND_EMPLOYEE = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_EMPLOYEE ).

* @TODO handle non existant child

* IF lo_nd_employee IS INITIAL.

* ENDIF.

* get element via lead selection

  LO_EL_EMPLOYEE = LO_ND_EMPLOYEE->GET_ELEMENT( ).

* alternative access  via index

* lo_el_employee = lo_nd_employee->get_element( index = 1 ).

* @TODO handle not set lead selection

  IF LO_EL_EMPLOYEE IS INITIAL.

  ENDIF.

* get all declared attributes

  LO_EL_EMPLOYEE->GET_STATIC_ATTRIBUTES(

    IMPORTING

      STATIC_ATTRIBUTES = LS_EMPLOYEE ).

*get all desired attributes in an internal table

CALL METHOD LO_ND_EMPLOYEE->GET_STATIC_ATTRIBUTES_TABLE

     EXPORTING

       FROM   = 1

       TO     = 2147483647

     IMPORTING

        TABLE  =    lt_table_data

        .

MOVE lt_table_data TO itab.

LOOP AT itab INTO wa.

MODIFY ZWEBDYNPRO FROM wa.

CLEAR wa.

ENDLOOP.

COMMIT WORK.

endmethod.

former_member574106
Participant
0 Kudos

Hi Rishab,

Thanks a lot for the tips. I did all the steps but when i am clicking on SUBMIT button but it is not getting saved in my custom table ZWEBDYNPRO. Please check the code. I have written it inside onSUBMIT event in the button.

method ONACTIONSUBMIT .

TYPES : BEGIN OF ty_employee,

        NAME TYPE pa0001-ename,

        PLANS TYPE pa0001-plans,

        END OF ty_employee.

DATA : itab TYPE STANDARD table of ty_employee ,

       wa   TYPE ty_employee.

  DATA LO_ND_EMPLOYEE TYPE REF TO IF_WD_CONTEXT_NODE.

  DATA LO_EL_EMPLOYEE TYPE REF TO IF_WD_CONTEXT_ELEMENT.

  DATA LS_EMPLOYEE TYPE wd_this->element_employee.

  DATA ls_table_data TYPE wd_this->element_employee.

    DATA lt_table_data TYPE wd_this->elements_employee.

* navigate from <CONTEXT> to <EMPLOYEE> via lead selection

  LO_ND_EMPLOYEE = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_EMPLOYEE ).

* @TODO handle non existant child

* IF lo_nd_employee IS INITIAL.

* ENDIF.

* get element via lead selection

  LO_EL_EMPLOYEE = LO_ND_EMPLOYEE->GET_ELEMENT( ).

* alternative access  via index

* lo_el_employee = lo_nd_employee->get_element( index = 1 ).

* @TODO handle not set lead selection

  IF LO_EL_EMPLOYEE IS INITIAL.

  ENDIF.

* get all declared attributes

  LO_EL_EMPLOYEE->GET_STATIC_ATTRIBUTES(

    IMPORTING

      STATIC_ATTRIBUTES = LS_EMPLOYEE ).

*get all desired attributes in an internal table

CALL METHOD LO_ND_EMPLOYEE->GET_STATIC_ATTRIBUTES_TABLE

     EXPORTING

       FROM   = 1

       TO     = 2147483647

     IMPORTING

        TABLE  =    lt_table_data

        .

MOVE lt_table_data TO itab.

LOOP AT itab INTO wa.

MODIFY ZWEBDYNPRO FROM wa.

CLEAR wa.

ENDLOOP.

COMMIT WORK.

endmethod.

former_member574106
Participant
0 Kudos

Hi Rohan,

Thanks a lot for the tips. I did all the steps but when i am clicking on SUBMIT button but it is not getting saved in my custom table ZWEBDYNPRO. Please check the code. I have written it inside onSUBMIT event in the button.

method ONACTIONSUBMIT .

TYPES : BEGIN OF ty_employee,

        NAME TYPE pa0001-ename,

        PLANS TYPE pa0001-plans,

        END OF ty_employee.

DATA : itab TYPE STANDARD table of ty_employee ,

       wa   TYPE ty_employee.

  DATA LO_ND_EMPLOYEE TYPE REF TO IF_WD_CONTEXT_NODE.

  DATA LO_EL_EMPLOYEE TYPE REF TO IF_WD_CONTEXT_ELEMENT.

  DATA LS_EMPLOYEE TYPE wd_this->element_employee.

  DATA ls_table_data TYPE wd_this->element_employee.

    DATA lt_table_data TYPE wd_this->elements_employee.

* navigate from <CONTEXT> to <EMPLOYEE> via lead selection

  LO_ND_EMPLOYEE = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_EMPLOYEE ).

* @TODO handle non existant child

* IF lo_nd_employee IS INITIAL.

* ENDIF.

* get element via lead selection

  LO_EL_EMPLOYEE = LO_ND_EMPLOYEE->GET_ELEMENT( ).

* alternative access  via index

* lo_el_employee = lo_nd_employee->get_element( index = 1 ).

* @TODO handle not set lead selection

  IF LO_EL_EMPLOYEE IS INITIAL.

  ENDIF.

* get all declared attributes

  LO_EL_EMPLOYEE->GET_STATIC_ATTRIBUTES(

    IMPORTING

      STATIC_ATTRIBUTES = LS_EMPLOYEE ).

*get all desired attributes in an internal table

CALL METHOD LO_ND_EMPLOYEE->GET_STATIC_ATTRIBUTES_TABLE

     EXPORTING

       FROM   = 1

       TO     = 2147483647

     IMPORTING

        TABLE  =    lt_table_data

        .

MOVE lt_table_data TO itab.

LOOP AT itab INTO wa.

MODIFY ZWEBDYNPRO FROM wa.

CLEAR wa.

ENDLOOP.

COMMIT WORK.

endmethod.

0 Kudos

Hey Saurav,

I think you've made it a bit complicated by using itab, I mean this is not needed as per your scenario . The structure itself would have been sufficient to update the database table .

Now that you have used it, debug and check whether your structure entries from the screen are coming in the internal table (itab) or not . If this is not working, you need to change your webdynpro code and simplify it as per this scenario.

Also check that the structure of your ZWEBDYNPRO table should be same as ty_employee because it updates on basis of primary keys in the table.

If structure is same, you can directly use MODIFY ZWEBDYNPRO FROM TABLE itab.

former_member218528
Participant
0 Kudos

Hi Saurav,

         Hope you are doing well...

* Inorder to save data to your table the workarea should be of the type table...

You need to do these below steps to save Data to your database...

1.First create a node in a context either in view controller or component controller and bind it to    your input fields

    Note:While you creating a node You should mention the same table name in the Dictionary             structure field.

2.Coding part in Action method of button

   data:lo_context type ref to if_wd_context_node.

   call method wd_context->get_child_node

     exporting

       name  = 'NODE'   "Here NODE is the Name of your node which u created in your context

     receiving

       value = lo_context.

    

    data:ls_employee type wd_this->element_node.

    *Note:Here i have declared workarea from the local interface created for this view

    *        You can check it through below steps...

    *         Click on MAIN(View)-->Click on Attributes tab( Now you can see their Three                           attributes like WD_CONTEXT , WD_THIS , WD_COMP_CONTROLLER and their                     Associated type in Third column-->Click on Associated type( IF_MAIN ) of Attribute                 WD_THIS.

    *        In this you can see the System code for our program..

    *        You have to declare the Workarea using the Structure Element_*<> Which is                           specified under Types

    *        you can also declare Internal table Using Elements_*<>

   call method lo_context->get_static_attributes

     importing

      static_attributes =  ls_employee.

   modify zemployee from ls_employee.

   if sy-subrc eq 0.

     commit work.

   else.

     rollback work.

   endif.

Try this ....It will work...

Regards ,

 

     Rohan

former_member574106
Participant
0 Kudos

Hi Rohan,

Thanks a lot . it is working correctly now. one more doubt. Please send some screenshot, if possible on how to debug the webdynpro method . I want to see what data is  coming in lt_table_data in the method get_static_attributes_table.

Regards,

Saurav Lahiry

former_member574106
Participant
0 Kudos

Hi Rishab,

Thanks a lot . it is working correctly now. one more doubt. Please send some screenshot, if possible on how to debug the webdynpro method . I want to see what data is  coming in lt_table_data in the method get_static_attributes_table.

Regards,

Saurav Lahiry

0 Kudos

Hello,

Great that it worked for you finally.

For debugging, you just need to place an external breakpoint on your below method and then run the application .

It will stop at this line.

CALL METHOD LO_ND_EMPLOYEE->GET_STATIC_ATTRIBUTES_TABLE

     EXPORTING

       FROM   = 1

       TO     = 2147483647

     IMPORTING

        TABLE  =    lt_table_data

former_member574106
Participant
0 Kudos

Hi Rishab,

Got it . Thanks a lot.

Regards,

Saurav Lahiry

former_member218528
Participant
0 Kudos

Hi Saurav,

* You can debug using BREAK Statement or else you can also set break point by clicking on gray         color vertical line in your editor.

* First of all,If you have created an instance(Object) for an interface and then you can get the object        reference by giving node name .Then you can check inside the object reference.All the Data that          entered in your Application will be in the object reference of that particular context node.

* So using those methods which provided in the interface( Here interface specifies the one which i          mentioned for object creation),we need to extract the data to structure or workarea.


Hope you understand this....


Regards,


     Rohan

Answers (4)

Answers (4)

former_member218528
Participant
0 Kudos

check out this.....This may help you..Hope so..            Regards,

          Rohan

former_member218528
Participant
0 Kudos

Hope you got the desired output...

former_member574106
Participant
0 Kudos

Hi,

I am still not getting desired output. Actually, i want to enter say Rohit in Name field and Sriram in description field. On clicking submit button, the values must be stored in the database. Please provide me with sample code, which i need to write in action of the button or in wddoinit.

Regards,

Saurav Lahiry

Former Member
0 Kudos

Hi,

Your XML says that the code is written in method WDDOINIT, which is not required to address your requirement. WDDOINIT is one of the factory method which would trigger first time when that controller is loaded.

Now let us come to your requirement. You need to read the data from input fields and save in the database.

Read the data

To read the data we must know the context binding of the input field (To locate this, go to Layout tab of the view controller, select the UI element(the input field), go to right side panel which shows UI element property, click on Binding column for Value property of the input field). Upon clicking, you will get one new window displaying the context node and attribute with which the input field is attached.

Now you need to know when the data is to be saved, I hope when you click the button, hence you need to create one event handler method. In Layout tab, you can select the Button and right side panel will display the element properties and bindings. there you get event sub section, you need to give a name to onAction event and then double click on it.

Now you need to read the values here, to do it from code wizard, do -> code wizard ->read context->select the attribute which we saw from Layout tab.

the same way you need to read other input fields.

Save the data

Once you have all the values of required input fields, you may do normal ABAP here, you may write the logic to save the values in the database (It is advisable to write database specific logic in the methods of assistance class and those methods must be called in the view methods)

I hope you had been to below link--

Web Dynpro for ABAP - Create a simple Web Dynpr... | SCN

former_member218528
Participant
0 Kudos

Hi Saurav,


NOTE : This entire process should be done in Actions of your Submit button...


* First you have to get the object reference of INTERFACE (  IF_WD_CONTEXT_NODE  ) using WD_CONTEXT through method ( GET_CHILD_NODE )  ( Note : If the attributes are created below node ).

* Then using that reference,you need to Get attributes using method ( GET_ATTRIBUTES ) of      INTERFACE ( IF_WD_CONTEXT_NODE ) to your structure or workarea.

* Through workarea you can change your database tables using modify statement


Regards,

         Rohan