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: 

The Records can be edited only when the Edit button is clicked.

sakthivel20720
Discoverer
0 Kudos

Hi,

I have created the ALV report using REUSE_ALV_GRID_DISPLAY, and I can edit the individual field by using the wa_field-edit = 'X'. And using the PF-STATUS, I can SAVE the changed data.

My requirement is.

a. Select one or more records and press EDIT – the Description field should be editable

b. If no record is selected and pressed an EDIT then it should give a message ‘Select at least one record’.

c. After modifying the Material description user can press on SAVE button

TABLES ztable.


DATA: it_final TYPE TABLE OF ztable,
wa_final TYPE ztable,
lv_index TYPE sy-tabix,
wa_layout TYPE slis_layout_alv,
ref1 TYPE REF TO cl_gui_alv_grid, " to capture changes in alv
it_zfinal TYPE TABLE OF ztable, "temproary final internal table
wa_zfinal TYPE ztable,
wa_zzfinal TYPE ztable, " temproary work area


gv_selected_rows TYPE TABLE OF i,
gv_edit_mode TYPE abap_bool,
gv_save_mode TYPE abap_bool,


*to move changed values in alv
it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
li_fieldcat TYPE lvc_t_fcat,
lwa_fieldcat TYPE lvc_s_fcat.

*FIELD-SYMBOLS: <gfs_fieldcat> TYPE slis_fieldcat_alv.



SELECTION-SCREEN BEGIN OF BLOCK b1.

SELECT-OPTIONS: s_matnr FOR ztable-matnr.

SELECTION-SCREEN END OF BLOCK b1.





START-OF-SELECTION.

PERFORM : getdata.

PERFORM: display.

FORM getdata .

SELECT *
FROM ztable
INTO TABLE it_final
WHERE matnr IN s_matnr
ORDER BY matnr.


ENDFORM.
END-OF-SELECTION.



CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
is_layout = wa_layout
it_fieldcat = it_fieldcat
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2
.


FORM display.

wa_fieldcat-tabname = 'IT_FINAL'.
wa_fieldcat-fieldname = 'matnr'.
wa_fieldcat-seltext_m = 'Material'.
wa_fieldcat-key = 'X'.

APPEND wa_fieldcat TO it_fieldcat.
CLEAR: wa_fieldcat.

wa_fieldcat-tabname = 'IT_FINAL'.
wa_fieldcat-fieldname = 'maktx'.
wa_fieldcat-seltext_m = 'DESCRIPTION'.
wa_fieldcat-key =' '.

APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

*appending values form final internal table to
* temproary final table for data comparision
it_zfinal[] = it_final[].

ENDFORM.

FORM user_command USING p_ucomm TYPE sy-ucomm
p_selfield TYPE slis_selfield.
CASE p_ucomm.
WHEN 'EDIT'.

" ----------HELP ME HERE-----------

WHEN 'SAVE'.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' "Capturing changes in ALV
IMPORTING
e_grid = ref1.
CALL METHOD ref1->check_changed_data.

*moving changed value into ztable on saving


LOOP AT it_final INTO wa_final.
READ TABLE it_zfinal INTO wa_zfinal WITH KEY matnr = wa_final-matnr.

IF wa_zfinal-matnr = wa_final-matnr AND wa_zfinal-maktx NE wa_final-maktx.
MOVE-CORRESPONDING wa_final TO wa_zzfinal.
MODIFY ztable FROM wa_zzfinal.
ENDIF.

ENDLOOP.

CLEAR: wa_final,wa_zfinal, wa_zzfinal.

ENDCASE.
ENDFORM.



FORM pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZPF_STATUS'.
ENDFORM.
3 REPLIES 3

moshenaveh
Community Manager
Community Manager
0 Kudos

Welcome to the SAP Community! Thank you for visiting us to get answers to your questions.

Since you're asking a question here for the first time, I'd like to offer some friendly advice on how to get the most out of your community membership and experience.

First, please see https://community.sap.com/resources/questions-and-answers, as this resource page provides tips for preparing questions that draw responses from our members. Secondly, feel free to take our Q&A tutorial at https://developers.sap.com/tutorials/community-qa.html as well, as that will help you when submitting questions to the community.

Finally, I recommend that you include a profile picture. By personalizing your profile, you encourage readers to respond: https://developers.sap.com/tutorials/community-profile.html.

I hope you find this advice useful, and we're happy to have you as part of SAP Community!

Eduardo-CE
Active Participant
0 Kudos

Hello,

Please check this program: BCALV_EDIT_01.

There's a good explanation on how to switch modes.

Regards Eduardo.

Sandra_Rossi
Active Contributor

I guess you mean that you have to display the ALV in display mode (NOT editable), and your question is about how to switch into editable mode when the user is pressing a button.

I guess that points B and C are easy and not part of your question?

For at least point A, I could immediately find the answer in the forum (by searching "reuse_alv_grid_display" switch edit mode site:sap.com")