Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV EDIT

Former Member
0 Likes
704

Hi,

In my program i fill the ALV grid with the data from internal table. Here user can edit one column and change the values.

How do i save back the modified values back to the internal table from ALV?

Pls help. I'm using OO ABAP

Thanks

Ram

7 REPLIES 7
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
670

Hi,

First register_edit_event for registering the changes done.

Use refresh_table_display of alv grid for refreshing the grid.

Check this tutorial.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a41...

Read only

Former Member
0 Likes
670

Hi,

You can create a button in PF-STATUS on which the user will click to save data.

Now,at user-command check if you sy-uccom matches with the function code of save button.If so then call a perform save_data.

Form save_data.

CALL METHOD grid1->check_changed_data

IMPORTING

e_valid = l_valid.

The internal table trhat you have passed in the output contains the changed data now.Now you can proceed as you need.

Read only

0 Likes
670

Hi Nandi,

Thanks fo rthe reply,

Can u get me some examples on this?

Is it enogh if we call this method "check_changed_data:"?

Do we need to do anything programatically to save the data?

Pls help

Thanks

Ram

Read only

Former Member
0 Likes
670

Hi Prabha.

While preparing field catalog you have to set edit field as in this code.

ls_fcat-fieldname = 'VBELN'.

ls_fcat-ref_table = 'VBAK'.

ls_fcat-ref_field = 'VBELN'.

ls_fcat-coltext = 'Sales order'.

<b> ls_fcat-edit = 'X'.</b>

APPEND ls_fcat TO gt_fieldcat_edit.

you can use check_changed_data method on alv object to fetch the changed data

Hope this helps

award forum points to helpful answers

Read only

Former Member
0 Likes
670

Hi Prabha

In the PAI when a user event occurs u call the method

grid object->checked_changed_data.

this will raise the event data_changed.

you write a method for data_changed event as follows

METHOD HANDLE_DATA_CHANGED.

in that you will get an object called er_data_changed that will have an internal tables MT_MOD_CELLS which have modified record you can read that .

LOOP AT ER_DATA_CHANGED->MT_MOD_CELLS INTO LS_MOD_CELLS.

Please reward if useful.

Read only

0 Likes
670

Can you pls help me with an example

Thanks

Ram

Read only

Former Member
0 Likes
670

Hi Prabha

class abc DEFINITION.

HANDLE_DATA_CHANGED

FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID

IMPORTING ER_DATA_CHANGED,

CLASS abc IMPLEMENTATION.

METHOD HANDLE_DATA_CHANGED.

LOOP AT ER_DATA_CHANGED->MT_MOD_CELLS INTO LS_MOD_CELLS.

ASSIGN COMPONENT LS_MOD_CELLS-FIELDNAME OF STRUCTURE

<GS_PRICE_DATA>

TO <FS1>.

IF LS_MOD_CELLS-FIELDNAME = 'CONTMBREFFDATE' OR LS_MOD_CELLS-FIELDNAME

=

'CONTMBREXPDATE'.

PERFORM CONVERSION.

IF LS_MOD_CELLS-FIELDNAME = 'CONTMBREFFDATE' .

IF DATE IS INITIAL .

CALL METHOD ER_DATA_CHANGED->ADD_PROTOCOL_ENTRY

EXPORTING

I_MSGID = '/CPC/HIST_UPDATE'

I_MSGNO = '024'

I_MSGTY = 'E'

I_FIELDNAME = LS_MOD_CELLS-FIELDNAME

I_ROW_ID = LS_MOD_CELLS-ROW_ID.

ERROR_DATA = 'X'.

EXIT.

ELSE.

<FS1> = DATE.

VAR = DATE.

ENDIF.

MODIFY GT_PRICE_DATA FROM <GS_PRICE_DATA> INDEX LS_MOD_CELLS-ROW_ID

TRANSPORTING (LS_MOD_CELLS-FIELDNAME).

ELSEIF LS_MOD_CELLS-FIELDNAME = 'CONTMBREXPDATE'.

IF DATE IS INITIAL .

CALL METHOD ER_DATA_CHANGED->ADD_PROTOCOL_ENTRY

EXPORTING

I_MSGID = '/CPC/HIST_UPDATE'

I_MSGNO = '024'

I_MSGTY = 'E'

I_FIELDNAME = LS_MOD_CELLS-FIELDNAME

I_ROW_ID = LS_MOD_CELLS-ROW_ID.

ERROR_DATA = 'X'.

EXIT.

ELSE.

<FS1> = DATE.

ENDIF.

IF NOT VAR IS INITIAL.

IF VAR GE <FS1>.

CALL METHOD ER_DATA_CHANGED->ADD_PROTOCOL_ENTRY

EXPORTING

I_MSGID = '/CPC/HIST_UPDATE'

I_MSGNO = '004'

I_MSGTY = 'E'

I_FIELDNAME = LS_MOD_CELLS-FIELDNAME

I_ROW_ID = LS_MOD_CELLS-ROW_ID.

ERROR_DATA = 'X'.

EXIT.

ELSEIF VAR LT <FS1>.

MODIFY GT_PRICE_DATA FROM <GS_PRICE_DATA> INDEX LS_MOD_CELLS-ROW_ID

TRANSPORTING (LS_MOD_CELLS-FIELDNAME).

ENDIF.

ELSE.

MODIFY GT_PRICE_DATA FROM <GS_PRICE_DATA> INDEX

LS_MOD_CELLS-ROW_ID

TRANSPORTING (LS_MOD_CELLS-FIELDNAME).

ENDIF.

ENDIF.

ELSE.

<FS1> = LS_MOD_CELLS-VALUE.

MODIFY GT_PRICE_DATA FROM <GS_PRICE_DATA> INDEX

LS_MOD_CELLS-ROW_ID TRANSPORTING (LS_MOD_CELLS-FIELDNAME).

ENDIF.

AT END OF ROW_ID.

ASSIGN COMPONENT 'COUNTER' OF STRUCTURE

<GS_PRICE_DATA>

TO <FS1>.

<FS1> = LS_MOD_CELLS-ROW_ID.

ASSIGN COMPONENT 'MOD_FLAG' OF STRUCTURE

<GS_PRICE_DATA>

TO <FS3>.

<FS3> = GV_FLAG.

MODIFY GT_PRICE_DATA FROM <GS_PRICE_DATA> INDEX <FS1> TRANSPORTING

COUNTER MOD_FLAG..

ENDAT.

ASSIGN COMPONENT 'COUNTER' OF STRUCTURE

<GS_PRICE_DATA>

TO <FS1>.

<FS1> = LS_MOD_CELLS-ROW_ID.

ASSIGN COMPONENT 'MOD_FLAG' OF STRUCTURE

<GS_PRICE_DATA>

TO <FS3>.

<FS3> = GV_FLAG.

MODIFY GT_PRICE_DATA FROM <GS_PRICE_DATA> INDEX <FS1> TRANSPORTING

COUNTER MOD_FLAG..

ENDAT.

ENDLOOP.

Here modiffying my internal table GT_PRICE_data .

Please reward if useful.