01-30-2009 7:05 AM
hi abap guru's .
i have a requirement that , i want only one editable field , i am using fieldcatlog-edit = 'x'.
and not layout-edit b'coz i want only one editable field if i use layout-edit then all fieds are editable.
by using fieldcatlog-edit = 'x' it is allowing me to edit but internal table is not updated like that in
layout-edit and i want to updated internal table first & then database table.
thanks in advance.
01-30-2009 8:43 AM
Hi,
Use this code, its working:-
I have used c_check instead of using 'X', for setting a field value as 'X'.
So refer 'X' instead of c_check.
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
* FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
* AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
* DISPLAYED IN THE GRID FORMAT
*----------------------------------------------------------------------*
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_rep_id " report id
i_callback_pf_status_set = 'PF' " for PF-STATUS
i_callback_user_command = 'USER_COMMAND' " for User-Command
is_layout = wa_layout " for layout
it_fieldcat = it_field " field catalog
it_sort = it_sort " sort info
TABLES
t_outtab = it_final " internal table
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.
ENDFORM. " ALV_DISPLAY
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* SUB-ROUTINE USER_COMMAND IS USED TO HANDLE THE USER ACTION
* AND EXECUTE THE APPROPIATE CODE
*----------------------------------------------------------------------*
* -->LV_OKCODE used to capture the function code
* of the user-defined push-buttons
* -->L_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.
* assign the function code to variable v_okcode
lv_okcode = sy-ucomm.
* handle the code execution based on the function code encountered
CASE lv_okcode.
* when the function code is EXECUTE then process the selected records
WHEN 'EXECUTE'.
* to reflect the data changed into internal table
DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new
IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->check_changed_data.
ENDIF.
* refresh the ALV Grid output from internal table
l_selfield-refresh = c_check.
ENDCASE.
ENDFORM.
This code will update your internal table with changed contents.
Now you can use this internal table to update database table.
Hope this solves your problem.
Thanks & Regards,
Tarun Gambhir
Edited by: Tarun Gambhir on Jan 30, 2009 2:14 PM
01-30-2009 7:45 AM
Hi Paresh,
U can hav a checkbox as the first field which will allow you to update the internal table.
Sample Code:
gwa_fcat-fieldname = 'CHECK'.
gwa_fcat-seltext_m = 'CHECK'.
gwa_fcat-col_pos = 1.
gwa_fcat-checkbox = 'X'.
gwa_fcat-edit = 'X'.
gwa_fcat-outputlen = 06.
APPEND gwa_fcat TO git_fcat.
When the ALV is displayed and suppose you change the value of which ever field.
You can check for the changed field and update the same in the internal Table.
Sample Code:
DATA: ref_grid TYPE REF TO cl_gui_alv_grid.
IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->check_changed_data .
ENDIF.
LOOP AT git_final INTO gwa_final WHERE check = 'X'.
MOVE gwa_final TO gwa_final1.
MOVE gwa_final-kunnr TO g_kunnr.
APPEND gwa_final1 TO git_final1.
CLEAR: gwa_final,
gwa_final1.
ENDLOOP.
About having only one field editable i really doubt whether you can update that by only having that field editable if the fieldcatalog.
Hope this helps.
Regards,
Navin.
01-30-2009 8:10 AM
01-30-2009 8:38 AM
My report is as follows ,
suppose i want to edit the field netpr
&----
*& Report ZTESTFUNCTION
*&
&----
*&
*&
&----
REPORT ZTESTFUNCTION.
tables: ekko, ekpo.
type-pools: slis. "ALV Declarations
*Data Declaration
*----
types: begin of t_ekko,
sel,
CHECK TYPE SYMBOL, "stores which row user has selected
ebeln type ekpo-ebeln,
ebelp type ekpo-ebelp,
matnr type ekpo-matnr,
menge type ekpo-menge,
netpr type ekpo-netpr,
NETWR TYPE EKPO-NETWR,
end of t_ekko.
data: it_ekko type standard table of t_ekko initial size 0,
wa_ekko type t_ekko.
DATA : IT_EKKO1 TYPE STANDARD TABLE OF T_EKKO WITH HEADER LINE .
DATA : IT_EKKO2 TYPE STANDARD TABLE OF T_EKKO WITH HEADER LINE .
*ALV data declarations
data:
fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF it_fieldcat.
DATA: ref_grid TYPE REF TO cl_gui_alv_grid,
IT_EKKO3 TYPE T_EKKO .
************************************************************************
select-options: so_EBELN FOR ekpo-EBELN.
*Start-of-selection.
start-of-selection.
*SET LOCALE LANGUAGE 'EN'
country 'C'
modifier 'M'.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
form build_fieldcatalog.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-TABNAME = 'IT_EKKO'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 1.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-TABNAME = 'IT_EKKO'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-TABNAME = 'IT_EKKO'.
fieldcatalog-seltext_m = 'MATERIAL NO'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'TXZ01'.
fieldcatalog-TABNAME = 'IT_EKKO'.
fieldcatalog-seltext_m = 'MATERIAL DESC'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-TABNAME = 'IT_EKKO'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-TABNAME = 'IT_EKKO'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 6.
fieldcatalog-outputlen = 15.
fieldcatalog-edit = 'X'.
fieldcatalog-input = 'X'.
"Display column total
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETWRR'.
fieldcatalog-TABNAME = 'IT_EKKO'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-do_sum = 'X'. "Display column total
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
&----
*& Form BUILD_LAYOUT
&----
Build layout for ALV grid report
----
form build_layout.
gd_layout-box_fieldname = 'SEL'.
"set field name to store row selection
gd_layout-edit = 'X'.
gd_layout-zebra = 'X'.
endform. " BUILD_LAYOUT
&----
*& Form DISPLAY_ALV_REPORT
&----
Display report using ALV grid
----
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_fieldcat = it_fieldcat
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
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.
endform. " DISPLAY_ALV_REPORT
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
form data_retrieval.
SELECT * FROM EKPO INTO
CORRESPONDING FIELDS OF TABLE IT_EKKO
WHERE EBELN IN SO_EBELN.
SORT IT_ekko DESCENDING BY MATNR .
endform. " DATA_RETRIEVAL
01-30-2009 8:50 AM
Hi Paresh,
Within th form "build_fieldcatalog." , before populating ebeln populate the code which gives you a checkbox.
The same one mentioned as above
fieldcatalog-fieldname = 'CHECK'. etc......
About OOPS ALV:
Actually for this u need not hav an oops ALV. The Function Module ' GET_GLOBALS_FROM_SLVC_FULLSCR" gets the screen attributes dynamically.
Hence by using CALL METHOD ref_grid->check_changed_data.
you can find out as to which row data has been changed and update the same row in your internal table
which will inturn help you to update your database table also.
Kindly intergate the code and check. It will surely work.
Regards,
Navin.
01-30-2009 8:42 AM
01-30-2009 8:45 AM
01-30-2009 8:43 AM
Hi,
Use this code, its working:-
I have used c_check instead of using 'X', for setting a field value as 'X'.
So refer 'X' instead of c_check.
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* SUB-ROUTINE ALV_DISPLAY IS USED TO SET THE PARAMETERS
* FOR THE FUNCTION MODULE REUSE_ALV_GRID_DISPLAY
* AND PASS THE INTERNAL TABLE EXISTING THE RECORDS TO BE
* DISPLAYED IN THE GRID FORMAT
*----------------------------------------------------------------------*
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_rep_id " report id
i_callback_pf_status_set = 'PF' " for PF-STATUS
i_callback_user_command = 'USER_COMMAND' " for User-Command
is_layout = wa_layout " for layout
it_fieldcat = it_field " field catalog
it_sort = it_sort " sort info
TABLES
t_outtab = it_final " internal table
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.
ENDFORM. " ALV_DISPLAY
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* SUB-ROUTINE USER_COMMAND IS USED TO HANDLE THE USER ACTION
* AND EXECUTE THE APPROPIATE CODE
*----------------------------------------------------------------------*
* -->LV_OKCODE used to capture the function code
* of the user-defined push-buttons
* -->L_SELFIELD text
*----------------------------------------------------------------------*
FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.
* assign the function code to variable v_okcode
lv_okcode = sy-ucomm.
* handle the code execution based on the function code encountered
CASE lv_okcode.
* when the function code is EXECUTE then process the selected records
WHEN 'EXECUTE'.
* to reflect the data changed into internal table
DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new
IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->check_changed_data.
ENDIF.
* refresh the ALV Grid output from internal table
l_selfield-refresh = c_check.
ENDCASE.
ENDFORM.
This code will update your internal table with changed contents.
Now you can use this internal table to update database table.
Hope this solves your problem.
Thanks & Regards,
Tarun Gambhir
Edited by: Tarun Gambhir on Jan 30, 2009 2:14 PM
01-30-2009 8:49 AM
01-30-2009 8:55 AM
01-30-2009 9:14 AM