cancel
Showing results for 
Search instead for 
Did you mean: 

Get the Change log for ALV line items

Former Member
0 Kudos

Hello Experts,

I am using editable ALV table to display/change data. When user modifies data from ALV line items manually (direct entry), this change is recorded in get_context_change_log method of context node. Also in the screen I have one button, on click of this button I do some calculation for selected line items in action method and update the context node with new values. But with this second approach (button action) though values gets changed this is not recorded in to get_context_change_log of context node. I tried to use method add_context_attribute_change in button action method to add attribute changes to change log tabel but it's not adding entries to change log. Does method add_context_attribute_change only works with OVS search helps and freely programmed value helps? And is there any other way for capturing changes(done by using action method and not manually) for ALV line items?

Thanks & Regards

Jayant

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

http://help.sap.com/saphelp_nw04s/helpdata/en/47/a8e5d273b12fe2e10000000a42189d/content.htm

The table records solely changes made by the user; changes to context elements that were made in the programs (for example, dynamic programming) are not listed.

Please, post the code where you call add_context_attribute_change

Former Member
0 Kudos

Here is code:

METHOD.

  • This method is in component controller, which gets called from View Action method (on click * of button).

FIELD-SYMBOLS:<lfs> TYPE Data.

*Data Declaration

DATA lo_nd_cn_apc_item TYPE REF TO if_wd_context_node.

DATA lit_apc_item TYPE wd_this->elements_cn_apc_item.

DATA lo_el_cn_apc_item TYPE REF TO if_wd_context_element.

data: l_component type ref to if_wd_component,

l_context type ref to if_wd_context,

lfd_added type abap_bool.

CLEAR:lo_nd_cn_apc_item,lo_el_cn_apc_item.

  • navigate from <CONTEXT> to <CN_APC_ITEM> via lead selection

lo_nd_cn_apc_item = wd_context->get_child_node( name = wd_this->wdctx_cn_apc_item ).

REFRESH:lit_apc_item.

  • @TODO handle non existant child

IF lo_nd_cn_apc_item IS NOT INITIAL.

lo_nd_cn_apc_item->get_static_attributes_table( IMPORTING table = lit_apc_item ).

  • get element via lead selection

lo_el_cn_apc_item = lo_nd_cn_apc_item->get_element( ).

ENDIF.

l_component = wd_this->wd_get_api( ).

l_context = l_component->get_context( ).

  • Calculate Cost

LOOP AT lit_apc_item ASSIGNING <lfs>.

<lfs>-cal_amount = ( <lfs>-cost_percent * <lfs>-sec_amount ) / 100.

lfd_added = l_context->add_context_attribute_change(

element = lo_el_cn_apc_item

attribute_name = 'CAL_AMOUNT'

new_value = <lfs>-cal_amount

).

ENDLOOP.

  • Bind Table.

lo_nd_cn_apc_item->bind_table( new_items = lit_apc_item set_initial_elements = abap_true ).

ENDMETHOD.

former_member182372
Active Contributor
0 Kudos

The problem is - you are iterating through table of node elements structures bu register change only for one (lead selected) element. And there is no need to call lo_nd_cn_apc_item->bind_table at the end

Smth like:


METHOD.
FIELD-SYMBOLS:<lfs> TYPE Data.

DATA lo_nd_cn_apc_item TYPE REF TO 	if_wd_context_node.
DATA lit_apc_item TYPE 				wd_this->elements_cn_apc_item.
DATA lo_el_cn_apc_item TYPE REF TO 	if_wd_context_element.

data: 
l_component type ref to 			if_wd_component,
l_context type ref to 				if_wd_context,
lfd_added type 						abap_bool.

DATA ELT TYPE WDR_CONTEXT_ELEMENT_SET.

l_component = wd_this->wd_get_api( ).
l_context = l_component->get_context( ).

lo_nd_cn_apc_item = wd_context->get_child_node( name = wd_this->wdctx_cn_apc_item ).

IF lo_nd_cn_apc_item IS NOT INITIAL.
	ELT = lo_nd_cn_apc_item->GET_ELEMENTS( ).
	LOOP AT ELT INTO lo_el_cn_apc_item.
		lo_el_cn_apc_item->GET_STATIC_ATTRIBUTES( IMPORTING STATIC_ATTRIBUTES = <lfs> ).
		
		<lfs>-cal_amount = ( <lfs>-cost_percent * <lfs>-sec_amount ) / 100.

		lfd_added = l_context->add_context_attribute_change(
			element = lo_el_cn_apc_item
			attribute_name = 'CAL_AMOUNT'
			new_value = <lfs>-cal_amount
		).	
	ENDLOOP
ENDIF.
ENDMETHOD.