Application Development 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: 

how to save an editable field in alv

Former Member
0 Kudos

Hi Experts,

I am developing one alv report with some editable columns. If user change any data in any editable column then i need to capture and save the data changes in Data base. i am using normal alv i.e i am not using oops concepts.

4 REPLIES 4

Former Member
0 Kudos

Hi

Once the Output is displayed in ALV , then the user changes are to be handled

In the Interactive Part of the ALV .

Capture the changes into an Internal Table based on the (In the loop read the Lines and capture the SY-LISEL field and from it capture the field values to build the Internal Table) fields and update the Database table with that internal table using Modify/insert or Update.

Reward points if useful

Regards

Anji

Former Member
0 Kudos

Hi Narasimha,

Use USER-COMMAND event of ALV.

Refer this code :

form z8_user_command using p_ucomm type sy-ucomm

p_selfield type slis_selfield.

case p_ucomm.

WHEN '&IC1'.

CLEAR IT_NEWMATSTOCK.

REFRESH IT_NEWMATSTOCK.

if p_selfield-fieldname = 'MATNR' and p_selfield-tabname = 'IT_MATSTOCK'.

it_NEWmatstock-matnr = p_selfield-VALUE.

LOOP AT IT_MATSTOCK WHERE MATNR = p_selfield-VALUE.

it_NEWmatstock-longtext = it_matstock-longtext.

ENDLOOP.

APPEND IT_NEWMATSTOCK.

endif.

Now write BDC program to upadate data in database

LOOP AT IT_MATSTOCK WHERE V_CHKBOX = 'X'.

perform open_group.

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MATNR'.

perform bdc_field using 'BDC_OKCODE'

'=AUSW'.

perform bdc_field using 'RMMG1-MATNR'

IT_MATSTOCK-MATNR.

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(02)'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

perform bdc_field using 'MSICHTAUSW-KZSEL(01)'

'X'.

perform bdc_field using 'MSICHTAUSW-KZSEL(02)'

perform bdc_transaction using 'MM02'.

endloop.

endcase.

Reward points if helpful.

Regards,

Hemant

Former Member
0 Kudos

Hi Narasimha,

This is one sample program..

DATA: g_container TYPE scrfname VALUE 'CUSTOM CONTROL',

g_custom_container TYPE REF TO cl_gui_custom_container,

g_grid TYPE REF TO cl_gui_alv_grid,

gs_layout TYPE lvc_s_layo,

ok_code LIKE sy-ucomm,

save_ok LIKE sy-ucomm.

.

DATA: gt_outtab TYPE TABLE OF sflight.

*----


*

  • MAIN *

*----


*

CALL SCREEN 100 STARTING AT 1 1..

*&----


*

*& Module STATUS_0100 OUTPUT

*&----


*

MODULE status_0100 OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

ENDMODULE. " STATUS_0100 OUTPUT

*&----


*

*& Module pbo OUTPUT

*&----


*

MODULE pbo OUTPUT.

IF g_custom_container IS INITIAL.

CREATE OBJECT g_custom_container

EXPORTING

container_name = g_container

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5

OTHERS = 6.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CREATE OBJECT g_grid

EXPORTING

i_parent = g_custom_container

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

OTHERS = 5 .

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

gs_layout-edit = 'X'.

SELECT * FROM sflight INTO TABLE gt_outtab UP TO 10 ROWS.

*§1.Set status of all cells to editable using the layout structure.

CALL METHOD g_grid->set_table_for_first_display

EXPORTING

i_structure_name = 'SFLIGHT'

is_layout = gs_layout

CHANGING

it_outtab = gt_outtab

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*§2.Use SET_READY_FOR_INPUT to allow editing initially.

CALL METHOD g_grid->set_ready_for_input

EXPORTING

i_ready_for_input = 1.

ENDIF.

ENDMODULE. " pbo OUTPUT

*&----


*

*& Module pai INPUT

*&----


*

MODULE pai INPUT.

save_ok = ok_code.

CLEAR ok_code.

CASE save_ok.

WHEN 'EXIT'.

PERFORM exit_program.

WHEN 'SWITCH'.

PERFORM switch_edit_mode.

WHEN OTHERS.

  • do nothing

ENDCASE.

ENDMODULE. " pai INPUT

*&----


*

*& Form exit_program

*&----


*

FORM exit_program .

LEAVE PROGRAM.

ENDFORM. " exit_program

*&----


*

*& Form switch_edit_mode

*&----


*

FORM switch_edit_mode .

*§3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.

IF g_grid->is_ready_for_input( ) EQ 0.

CALL METHOD g_grid->set_ready_for_input

EXPORTING

i_ready_for_input = 1.

ELSE.

CALL METHOD g_grid->set_ready_for_input

EXPORTING

i_ready_for_input = 0.

ENDIF.

ENDFORM. " switch_edit_mode

***********************************************************************************

If you need more check this URL.

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_editable.htm

Award if useful

Former Member
0 Kudos

Hi,

The corresponding workarea/Internal table fields will automatically get updated with the new value. So you just need to call the BAPI or save the data direclty to the database.

In case you want the chaned values to be displayed when you save and come back then, you just need to call the FM 'REUSE_ALV_BLOCK_LIST_REFRESH' if you are using an alv list and 'RM_ALV_GRID_DISPLAY_REFRESH' if you are using an alv grid.

Reply if you need clarifications