‎2012 Jun 14 11:10 AM
Hi,
my requirement is in editable alv after display the data i need to change in output it gets
update in data base, i wrote the code but save functionality is not working can any ine help me?
my Itab and wa are
DATA V1 LIKE USR21-BNAME.
SELECT-OPTIONS S_BNAME FOR V1.
data : begin of WA_data,
bname like usr21-bname,
name_first like adrp-name_first,
name_last like adrp-name_last,
smtp_addr like adr6-smtp_addr,
end of wa_data,
it_data like table of wa_data,
i_index TYPE STANDARD TABLE OF i WITH HEADER LINE.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat like line of it_fcat.
DATA :WA LIKE WA_DATA,
IT LIKE TABLE OF WA.
*for gui
form zgui using x type slis_t_extab.
set PF-STATUS 'ZSTAT'.
ENDFORM.
FORM ZUC USING A LIKE SY-UCOMM
B TYPE SLIS_SELFIELD.
CASE A.
* When a record is selected
WHEN 'SAVE'.
* Read the selected record
READ TABLE IT_DATA INTO wa_DATA INDEX
B-tabindex.
IF sy-subrc = 0.
* Store the record in an internal table
APPEND WA_DATA TO IT.
* Fetch the field catalog info
* CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
* EXPORTING
* i_program_name = SY-REPID
* CHANGING
* ct_fieldcat = iT_fcat
* EXCEPTIONS
* inconsistent_interface = 1
* program_error = 2
* OTHERS = 3.
* IF sy-subrc = 0.
* Make all the fields input enabled except key fields
wA_FCAT-input = 'X'.
MODIFY iT_fcat FROM wA_fCAT TRANSPORTING input
WHERE key IS INITIAL.
ENDIF.
* Display the record for editing purpose
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* i_structure_name = p_table
it_fieldcat = iT_fcat
i_screen_start_column = 10
i_screen_start_line = 15
i_screen_end_column = 200
i_screen_end_line = 20
TABLES
t_outtab = IT_DATA
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
* Read the modified data
READ TABLE IT INDEX 1 INTO WA.
* If the record is changed then track its index no.
* and populate it in an internal table for future
* action
IF sy-subrc = 0 AND WA_DATA <> WA.
WA_DATA = WA.
i_index = B-tabindex.
APPEND i_index.
ENDIF.
ENDIF.
* ENDIF.
* When save button is pressed
* WHEN 'SAVE'.
*
** Sort the index table
* SORT i_index.
*
** Delete all duplicate records
* DELETE ADJACENT DUPLICATES FROM i_index.
*
* LOOP AT i_index.
*
** Find out the changes in the internal table
** and populate these changes in another internal table
* READ TABLE IT_DATA INTO WA_DATA INDEX i_index.
* IF sy-subrc = 0.
* APPEND WA_DATA TO IT.
* ENDIF.
*
* ENDLOOP.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
B-refresh = 'X'.
ENDCASE.
ENDFORM. "user_command
thanks in advance..............
‎2012 Jun 14 1:27 PM
‎2012 Jun 14 1:37 PM
Hi Maesh,
You can check BCALV_EDIT* in SE38.
Regards,
Manuel H.
‎2012 Jun 14 1:42 PM
Hi
Logic is to update your internal table from the ALV list display once changes have been made in the ALV output. Unless you are sucecssfully able to update the internal table you cant go ahead. I have never done this with FM ALV but in the ALV class there is a method specifically for this.
For your case try FM REUSE_ALV_TABLES_GET or REUSE_ALV_HS_TABLES_GET
I'm assuming that field catalogue already has the fields which are editable in the ALV and you have an event which would trigger the FM above.
Next time try doing it OO way, its much more easier and gives you a lot of options but make sure you choose the right class.
Cheers
Arnab
‎2012 Jun 14 8:51 PM
Hi Mahesh,
Inside subroutine USER_COMMAND , you need to write the code as follows:
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP_OF_PAGE'
i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
* is_variant = z_template
TABLES
t_outtab = it_ekko
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*------On saving the value
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
*--------- Check function code
CASE r_ucomm.
WHEN '&DATA_SAVE'.
SELECT *
FROM USR21
INTO CORRESPONDING FIELDS OF TABLE IT_USR21.
*-------- Read data table, using index of row user Edited
*--------- WA_DATA contains Edited field contents.
READ TABLE IT_DATA INTO WA_DATA INDEX rs_selfield-tabindex.
*-------- Now use primary key of Database table SAY BNAME from WA_DATA to update
*--------- data base tablefield
LOOP AT IT_USR21 INTO WA_USR21 WHERE BNAME = WA_DATA-BNAME.
IF SY-SUBRC EQ 0.
MODIFY USR21 FROM WA_DATA .
COMMIT WORK.
ENDIF.
ENDLOOP.
ENDCASE.
ENDFORM.
Best regards,
Sachin
‎2012 Jun 14 8:53 PM
Geez...spoon fed code to change table that shouldn't be touched by custom code, IMHO. I hope he doesn't write it to modify USR21
‎2012 Jun 14 9:00 PM
Hi Break point,
I have just used USR21 for demo purpose . it's written say USR21 in my code.