cancel
Showing results for 
Search instead for 
Did you mean: 

Webdynpro ABAP ALV tutorial - simple update or use changelog ?

Former Member
0 Kudos

I was working through the alv tutorials for webdynpro abap, and while trying to complete the

"Editing ALV in Web Dynpro for ABAP", I got to page 8 of the pdf document where it explains how to do the ONDATACHECK event handler, and it comments out the portion for updating/saving the data (as noted below), and does not explain anything further about the save.

* save data to database
{* update... => only simlate, to not change the flight data model
* content!

Now, I am new to webdynpro abap, and don't know if I am supposed to utlize the changelog for this, or if a simple update will work.

Any Ideas ?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Michael,

The updation and the saving of data is possible.

But the tutorial, suggests you not to change the contents of the flight data model.

The saving of data depends on your requirement.

You can write your own method to save the updation in the database table.

Regards...

Arun.

Former Member
0 Kudos

Thank you for your answer - I am guessing from your response that a method would need to be built - similar to one which I found in the SWDP_DEMO_TUTORIALS for a webdynpro called WDT_TABLE (see below) - where a check of the table changes would need to be made before an update to the table - rather than a simple one line update statement placed at that point in the code.

 METHOD save_changes.

  DATA: table_node           TYPE REF TO if_wd_context_node,
        read_sbook           TYPE
if_componentcontroller=>elements_sbook_node,
        aux_read_sbook       TYPE
if_componentcontroller=>elements_sbook_node,
        wa_read_sbook        TYPE LINE OF
if_componentcontroller=>elements_sbook_node,
        context              TYPE REF TO if_wd_context,
        change_line          TYPE LINE OF wdr_context_change_list,
        changes              TYPE wdr_context_change_list,
        aux_changes          TYPE wdr_context_change,
        lv_change_tab_size   TYPE sy-tfill,
        aux_string           TYPE string,
        lv_node_size         TYPE sy-tfill,
        aux_div              TYPE int4,
        aux_index            TYPE i,
        l_current_controller TYPE REF TO if_wd_controller,
        l_message_manager    TYPE REF TO if_wd_message_manager,
        text                 TYPE string,
        it_int TYPE STANDARD TABLE OF i WITH KEY table_line.

* check whether context has changed
  context = wd_context->get_context( ).
  changes = context->get_context_change_log( ).
  LOOP AT changes INTO aux_changes.
    IF aux_changes-change_kind = 'A' AND aux_changes-node_name = 'SBOOK_NODE'.
      INSERT aux_changes INTO TABLE wd_this->sbook_delta.
    ENDIF.
  ENDLOOP.

* get the complete context in 'read_sbook' table
  table_node = wd_context->get_child_node( name = 'MY_BOOKING_NODE' ).
  table_node = table_node->get_child_node( name = 'SBOOK_NODE' ).
  table_node->get_static_attributes_table( IMPORTING table = read_sbook
).

* get the size of table and changes
  DESCRIBE TABLE read_sbook LINES lv_node_size.
  LOOP AT wd_this->sbook_delta INTO change_line.
    APPEND change_line-element_index TO it_int.
  ENDLOOP.
  SORT it_int.
  DELETE ADJACENT DUPLICATES FROM it_int.
  DESCRIBE TABLE it_int LINES lv_change_tab_size.

* get message manager
  l_current_controller ?= wd_this->wd_get_api( ).
  CALL METHOD l_current_controller->get_message_manager
    RECEIVING
      message_manager = l_message_manager.

* decide which way to update databse
  IF lv_change_tab_size <> 0.
    aux_div = lv_node_size / lv_change_tab_size.
    IF aux_div <= 3.

* write complete table to database
      lv_change_tab_size = lv_node_size.
      CL_WDT_FLIGHT_MODEL=>write_sbook_complete( read_sbook ).
    ELSE.
* write only the changed records to database
      LOOP AT it_int INTO aux_index.
        READ TABLE read_sbook INDEX aux_index INTO wa_read_sbook.
        APPEND wa_read_sbook TO aux_read_sbook.
      ENDLOOP.
      CL_WDT_FLIGHT_MODEL=>write_sbook_records_changed( aux_read_sbook )
.
    ENDIF.
    REFRESH wd_this->sbook_delta.
    REFRESH it_int.
    wd_this->sbook_changed = abap_false.

* report message
    aux_string = lv_change_tab_size .
    IF lv_change_tab_size = 1.
      CONCATENATE aux_string 'record written to database' INTO text.
    ELSE.
      CONCATENATE aux_string 'records written to database' INTO text.
    ENDIF.
    CALL METHOD l_message_manager->report_success
      EXPORTING
        message_text = text.

  ELSE.

*  report message
    CALL METHOD l_message_manager->report_success
      EXPORTING
        message_text = 'there are no changes to be written to database'.
  ENDIF.

ENDMETHOD.

Answers (0)