cancel
Showing results for 
Search instead for 
Did you mean: 

Usage of update-bapi and getdetail-bapi within one view

Former Member
0 Kudos

Hello,

i'm a student and i'm new to webdynpro and abap. Im trying to get data through a bapi into some screens and want to update some of these inputfields back through an update-bapi.

I get all the needed data by a getdetails-bapi and can show the data within binded inputfields, but how could i get the infos about which field was changed and how could i implement an update through the update-bapi?

It is possible, that a view with two inputfileds gets the data through the getdetails-bapi and after a change in this fields there will be an update through a update-bapi, after pushing a button?

Could you give me an example code, or could you explane me a way for implementing these?

Thanks for your help!

John

Accepted Solutions (1)

Accepted Solutions (1)

former_member515618
Active Participant
0 Kudos

Hi John,

This is what i understand off yuur requirement.

You Get the data from a bapi and store it in a context.

You bind the context attributes to the input fields to display the data. User is presented with this screen and user changes some input field values and presses a button to update the same in the DB. This is done by the update bapi.

And your querry is to identify what fields are updated in order to pass to the Update the bapi. Please correct me if iam wrong.

When you bind the context attributes with the UI elements. The data present in the node is automatically mapped. So if user changes the values in the context node, they are automatically updated in the context attribute.

So What you can do is, Directly map the Context node attributes to the parameter interface of the BAPI and call it in the action handler of the button.

and if your requirement is to only pass the changed values then there is also a concept called CONTEXT_LOG for context nodes, in an application, if user changes some values bound to a context, a log is maintained. It gives us the old and new values of any given element if changed.

Please refer to the below link for more details.[Link:|http://help.sap.com/saphelp_nw2004s/helpdata/en/47/a8e5d273b12fe2e10000000a42189d/content.htm]

Please refer to the example program DEMO_CONTEXT_CHANGES in SAP package SWDP_DEMO.

Do let me know in case you need any more details.

Regards,

Sravan Varagani

Former Member
0 Kudos

Thank you all for your help!

I just implemented this right now. The update-bapi has two nodes, one with the information and one in which a 'X' which will mark every updated attribute.

So I just passed the information of the first node and write in every single attribute of the second node a 'x' for update.

But with this "context_log" it should be a lot easier. But how could i implement this?

If the user had changed inputfield1 and inputfield2 which are bound to node1 with attribute1(sting) and attribute2(string)

how could i pass these infos to node2 with attribute1(string) and attribute2(string) AND node3 with attribute1(the attribute has to be empty or a X for update) and attribute2(also: X). And this all with this context_log?

I looked at the demo_context_changes, but i can't get the infos out of the Changes-node into the node2 and node3 with the right information.

I hope you can understand this horrible explanation And can help me

Thank you!

Former Member
0 Kudos

Hi John,

changes made at Contexts are stored in a table WDR_CONTEXT_CHANGE_LIST. So you can retrieve the old and new values from the table.

Please follow the below steps :

1. Create a context node (Ex:Changes) with dict.str wdr_context_change.

2. Then create one subnode under Changes ex(details) with two attributes old_value and new_value with the type of string.

3. Then write the below code at any button action.

DATA: l_ref_componentcontroller TYPE REF TO ig_componentcontroller .
    DATA: l_changes                 TYPE        wdr_context_change_list,
          l_subnode                 type ref to if_wd_context_node,
          l_subnodedata             type if_USERLOG=>element_details.

    field-symbols: <change> type wdr_context_change,
                   <new>    type data,
                   <old>    type data.

    l_ref_componentcontroller =   wd_this->get_componentcontroller_ctr( ).
    l_changes = l_ref_componentcontroller->get_changes( ).

    data: l_node type ref to if_wd_context_node.
    l_node = wd_context->get_child_node( 'CHANGES' ).
    l_node->bind_table( l_changes ).

    loop at l_changes assigning <change>.
      if <change>-old_value is not initial and <change>-new_value is not initial.
        l_subnode = l_node->get_child_node( index = sy-tabix name = 'DETAILS' ).
        assign <change>-new_value->* to <new>.
        assign <change>-old_value->* to <old>.
*        l_subnodedata-new_value_string = cl_wdr_conversion_utils=>to_string( value = <new> ).
*        l_subnodedata-old_value_string = cl_wdr_conversion_utils=>to_string( value = <old> ).

         l_subnodedata-new_value_string = <new>.
        l_subnodedata-old_value_string = <old>.

*
*        l_subnodedata-new_value_string = 'AC'.
*        l_subnodedata-old_value_string = 'CD'.

        l_subnode->bind_structure( l_subnodedata ).

       endif.
      endloop.

So now your context has the changed records.

Thanks.

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks for your help!

Former Member
0 Kudos

Hello,

Yes, it's possible to update data using a button, just associate an action to this button and call the update BAPI over this action.

Here an example to get the updated data from view, insert this code in the action:


DATA: lr_fields TYPE REF TO if_wd_context_node,
  ls_fields TYPE SFLIGHT.

lr_fields = wd_context->get_child_nodes( name = node_name ).
IF sy-subrc EQ 0.
  RETURN.
ENDIF.
lr_fields->get_static_attributes( IMPORTING static_attributes = ls_update ).

CALL FUNCTION 'UPDATE_BAPI'
EXPORTING fields = ls_update.

Regards,

Former Member
0 Kudos

hi john....

when you clcik the update button.... read the node that is bound to the table and the input fields and pass it to the necessary bapi.

---regards,

alex b justin