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

save data in alv grid.

Former Member
0 Likes
3,110

hi ,

I am having a problem while using alv grid , in my program I am adding a new row to the output that i get in the alv grid format and then i enter new values in the newly created row but the problem is i am not able to figure out where is the new data that i have entered in the new row is getting saved.

thanks in advance .

regards ,

Arpit.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,467

Hi Arpit,

In this case you might have to handle the change events in ALV grid

You can go in for a creation and implementation of Class and handle the events in this class via itu2019s methods, I have tried to code a few lines.

Attaching the code in two halves.

Hope it helps you,

Enjoyu2026u2026u2026u2026

--


start--
Declaration----

CLASS ISM_CUSTOMER_LIST DEFINITION DEFERRED.

DATA: GV_CUSTOMER_LIST TYPE REF TO ISM_CUSTOMER_LIST.

----


End -
Declaration----

--


start--
Class Defination----

CLASS ism_customer_list DEFINITION.

PUBLIC SECTION.

METHODS:

constructor

IMPORTING i_container TYPE scrfname,

check_changed_data,

exe_display,

field_catalog_merge.

DATA: g_custom_container TYPE REF TO cl_gui_custom_container,

alv_grid TYPE REF TO cl_gui_alv_grid.

endclass.

--


end--
Class Defination----

--


start--
Class Implementation----

CLASS ism_customer_list IMPLEMENTATION.

METHOD constructor.

IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container

EXPORTING container_name = i_container.

CREATE OBJECT alv_grid

EXPORTING i_parent = g_custom_container.

ENDIF.

CALL METHOD me->field_catalog_merge.

CALL METHOD alv_grid->set_table_for_first_display

EXPORTING

  • is_layout = fs_layout

is_variant = ls_variant

i_save = 'A'

i_default = 'X'

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = it_data

it_fieldcatalog = it_fieldcat.

*

endmethod.

method exe_display.

CALL METHOD alv_grid->set_table_for_first_display

EXPORTING

  • is_layout = fs_layout

is_variant = ls_variant

i_save = 'A'

i_default = 'X'

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = it_data

it_fieldcatalog = it_fieldcat.

endmethod.

METHOD FIELD_CATALOG_MERGE.

DATA wf_pos TYPE i.

ADD 1 TO wf_pos.

DATA : wa_fieldcat TYPE lvc_s_fcat.

DATA: ls_fieldcatalog TYPE lvc_t_fcat.

  • WITH HEADER LINE .

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MATNR'.

  • ls_fieldcatalog-checkbox = 'X'.

  • ls_fieldcatalog-datatype = 'C'.

ADD 1 TO wf_pos.

wa_fieldcat-col_pos = wf_pos.

wa_fieldcat-outputlen = '8'.

wa_fieldcat-reptext = 'PRODUCT'.

wa_fieldcat-coltext = 'PRODUCT'.

wa_fieldcat-seltext = 'PRODUCT'.

wa_fieldcat-tooltip = 'PRODUCT'.

wa_fieldcat-key = 'X'.

wa_fieldcat-icon = 'X'.

*ls_fieldcatalog-edit = 'X'.

wa_fieldcat-edit = 'X'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

u2026u2026u2026u2026u2026u2026..here transfer fieldcat for all the columns.

Endmethod.

*----


  • Check if data was changed (automatically raises "ENTER" event)

*----


METHOD check_changed_data.

DATA: lv_valid TYPE xfeld,

lv_refresh TYPE xfeld.

CALL METHOD alv_grid->check_changed_data

IMPORTING

e_valid = lv_valid

CHANGING

c_refresh = lv_refresh.

ENDMETHOD. "check_changed_data

*----


endclass.

--


end--
Class Implementation----

hi ,

I am having a problem while using alv grid , in my program I am adding a new row to the output that i get in the alv grid format and then i enter new values in the newly created row but the problem is i am not able to figure out where is the new data that i have entered in the new row is getting saved.

thanks in advance .

regards ,

Arpit.

4 REPLIES 4
Read only

Former Member
0 Likes
1,467

Hi

Please check the demo program BCALV_EDIT_01

thanks

anurag

Read only

Former Member
1,467

http://wiki.sdn.sap.com/wiki/display/Snippets/ALVGRIDCOMPLETEEXAMPLEWITHTOOLBARBUTTONSUSINGCLASS.

check this link

thanks

anurag

Read only

Former Member
0 Likes
1,468

Hi Arpit,

In this case you might have to handle the change events in ALV grid

You can go in for a creation and implementation of Class and handle the events in this class via itu2019s methods, I have tried to code a few lines.

Attaching the code in two halves.

Hope it helps you,

Enjoyu2026u2026u2026u2026

--


start--
Declaration----

CLASS ISM_CUSTOMER_LIST DEFINITION DEFERRED.

DATA: GV_CUSTOMER_LIST TYPE REF TO ISM_CUSTOMER_LIST.

----


End -
Declaration----

--


start--
Class Defination----

CLASS ism_customer_list DEFINITION.

PUBLIC SECTION.

METHODS:

constructor

IMPORTING i_container TYPE scrfname,

check_changed_data,

exe_display,

field_catalog_merge.

DATA: g_custom_container TYPE REF TO cl_gui_custom_container,

alv_grid TYPE REF TO cl_gui_alv_grid.

endclass.

--


end--
Class Defination----

--


start--
Class Implementation----

CLASS ism_customer_list IMPLEMENTATION.

METHOD constructor.

IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container

EXPORTING container_name = i_container.

CREATE OBJECT alv_grid

EXPORTING i_parent = g_custom_container.

ENDIF.

CALL METHOD me->field_catalog_merge.

CALL METHOD alv_grid->set_table_for_first_display

EXPORTING

  • is_layout = fs_layout

is_variant = ls_variant

i_save = 'A'

i_default = 'X'

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = it_data

it_fieldcatalog = it_fieldcat.

*

endmethod.

method exe_display.

CALL METHOD alv_grid->set_table_for_first_display

EXPORTING

  • is_layout = fs_layout

is_variant = ls_variant

i_save = 'A'

i_default = 'X'

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = it_data

it_fieldcatalog = it_fieldcat.

endmethod.

METHOD FIELD_CATALOG_MERGE.

DATA wf_pos TYPE i.

ADD 1 TO wf_pos.

DATA : wa_fieldcat TYPE lvc_s_fcat.

DATA: ls_fieldcatalog TYPE lvc_t_fcat.

  • WITH HEADER LINE .

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = 'MATNR'.

  • ls_fieldcatalog-checkbox = 'X'.

  • ls_fieldcatalog-datatype = 'C'.

ADD 1 TO wf_pos.

wa_fieldcat-col_pos = wf_pos.

wa_fieldcat-outputlen = '8'.

wa_fieldcat-reptext = 'PRODUCT'.

wa_fieldcat-coltext = 'PRODUCT'.

wa_fieldcat-seltext = 'PRODUCT'.

wa_fieldcat-tooltip = 'PRODUCT'.

wa_fieldcat-key = 'X'.

wa_fieldcat-icon = 'X'.

*ls_fieldcatalog-edit = 'X'.

wa_fieldcat-edit = 'X'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

u2026u2026u2026u2026u2026u2026..here transfer fieldcat for all the columns.

Endmethod.

*----


  • Check if data was changed (automatically raises "ENTER" event)

*----


METHOD check_changed_data.

DATA: lv_valid TYPE xfeld,

lv_refresh TYPE xfeld.

CALL METHOD alv_grid->check_changed_data

IMPORTING

e_valid = lv_valid

CHANGING

c_refresh = lv_refresh.

ENDMETHOD. "check_changed_data

*----


endclass.

--


end--
Class Implementation----

Read only

0 Likes
1,467

this is the second half.....

u201C At Start of selection create the object

start-of-selection.

CREATE OBJECT gv_customer_list

EXPORTING i_container = c_list_container.

u201C where data: C_LIST_CONTAINER TYPE SCRFNAME VALUE 'APPROVALS'.

u2018APPROVALSu2019 is the custom container name in the output screen.

MODULE user_command_0100 INPUT.

*

CASE sy-ucomm.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN 'SAVE'.

PERFORM F013-LIST_TRANFER_CHANGED_DATA.

Endcase.

form F013-LIST_TRANFER_CHANGED_DATA .

CALL METHOD GV_CUSTOMER_LIST->CHECK_CHANGED_DATA.

endform. " F013-LIST_TRANFER_CHANGED_DATA

Regards,

Abhijit G. Borkar