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: 

editable field in alv

Former Member
0 Kudos

hiii

when doing editable field in alv

you set

i_fieldcat-edit = C_X

i_fieldcat-input = C_X

P_selfield-refresh = C_X

this is not working when i click on save the internal table is not keeping the change i have edit on the screen and the p_selfield value also has still the old value.

but when i double click the p_selfield is keeping the editable value. Please advise ??

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi,

Check out this sample program.The part for 'EDIT' is in Bold..

report zalv_color_display_edit.

type-pools: slis.

tables : zcust_master2.

types : begin of wi_zcust_master2,

zcustid like zcust_master2-zcustid,

zcustname like zcust_master2-zcustname,

zaddr like zcust_master2-zaddr,

zcity like zcust_master2-zcity,

zstate like zcust_master2-zstate,

zcountry like zcust_master2-zcountry,

zphone like zcust_master2-zphone,

zemail like zcust_master2-zemail,

zfax like zcust_master2-zfax,

zstat like zcust_master2-zstat,

field_style type lvc_t_styl,

end of wi_zcust_master2.

data: it_wi_zcust_master2 type standard table of wi_zcust_master2

initial size 0,

wa_zcust_master2 type wi_zcust_master2.

data: fieldcatalog type slis_t_fieldcat_alv with header line.

data: it_fieldcat type lvc_t_fcat,

wa_fieldcat type lvc_s_fcat,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type lvc_s_layo, "slis_layout_alv,

gd_repid like sy-repid.

start-of-selection.

perform data_retrieval.

perform set_specific_field_attributes.

perform build_fieldcatalog.

perform build_layout.

perform display_alv_report.

form build_fieldcatalog.

wa_fieldcat-fieldname = 'ZCUSTID'.

wa_fieldcat-scrtext_m = 'CUSTOMER ID'.

wa_fieldcat-col_pos = 0.

wa_fieldcat-outputlen = 10.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZCUSTNAME'.

wa_fieldcat-scrtext_m = 'CUSTOMER NAME'.

wa_fieldcat-col_pos = 1.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZADDR'.

wa_fieldcat-scrtext_m = 'ADDRESS'.

wa_fieldcat-col_pos = 2.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZCITY'.

wa_fieldcat-scrtext_m = 'CITY'.

wa_fieldcat-col_pos = 3.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZSTATE'.

wa_fieldcat-scrtext_m = 'STATE'.

wa_fieldcat-col_pos = 4.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZCOUNTRY'.

wa_fieldcat-scrtext_m = 'COUNTRY'.

wa_fieldcat-col_pos = 5.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZPHONE'.

wa_fieldcat-scrtext_m = 'PHONE NUMBER'.

wa_fieldcat-col_pos = 6.

  • wa_fieldcat-edit = 'X'. "sets whole column to be editable

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZEMAIL'.

wa_fieldcat-scrtext_m = 'EMAIL'.

wa_fieldcat-edit = 'X'. "sets whole column to be editable wa_fieldcat-col_pos = 7.

wa_fieldcat-outputlen = 15.

wa_fieldcat-datatype = 'CURR'.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZFAX'.

wa_fieldcat-scrtext_m = 'FAX'.

wa_fieldcat-col_pos = 8.

wa_fieldcat-edit = 'X'. "sets whole column to be editable

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZSTAT'.

wa_fieldcat-scrtext_m = 'STATUS'.

wa_fieldcat-col_pos = 9.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

endform. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


form build_layout.

  • Set layout field for field attributes(i.e. input/output)

gd_layout-stylefname = 'FIELD_STYLE'.

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'

*----


call function 'REUSE_ALV_GRID_DISPLAY_LVC'

exporting

i_callback_program = gd_repid

is_layout_lvc = gd_layout

it_fieldcat_lvc = it_fieldcat

i_save = 'X'

tables

t_outtab = it_wi_zcust_master2

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

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form data_retrieval .

data: ld_color(1) type c.

select zcustid zcustname zaddr zcity zstate zcountry zphone zemail

zfax zstat up to 10 rows from zcust_master2 into corresponding fields of

table it_wi_zcust_master2.

endform. "data_retrieval

&----


*& Form set_specific_field_attributes

&----


  • populate FIELD_STYLE table with specific field attributes

----


form set_specific_field_attributes .

data ls_stylerow type lvc_s_styl .

data lt_styletab type lvc_t_styl .

  • Populate style variable (FIELD_STYLE) with style properties

  • The following code sets it to be disabled(display only) if 'ZFAX'

  • is NOT INITIAL.

loop at it_wi_zcust_master2 into wa_zcust_master2.

if wa_zcust_master2-zfax is not initial.

ls_stylerow-fieldname = 'ZFAX' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.

"set field to disabled

append ls_stylerow to wa_zcust_master2-field_style.

modify it_wi_zcust_master2 from wa_zcust_master2.

endif.

endloop.

endform. "set_specific_field_attributes

Hope this helps you,

Arunsri

3 REPLIES 3

former_member188685
Active Contributor
0 Kudos

you need to call the function 'GET_GLOBALS_FROM_SLVC_FULLSCR' and from this you get the grid reference, using that you need to call the method check_changed_data. then only you can get the modified content.

form user_command using p_ucomm type sy-ucomm
p_selfld type slis_selfield.

data ref1 type ref to cl_gui_alv_grid.
"For capturing the selected data
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
importing
e_grid = ref1.
call method ref1->check_changed_data.
 
case p_ucomm.
when '&DATA_SAVE'.  "based on your action

"Now you see/check here internal table will have changed 
"values
p_selfld-refresh = 'X'.
endcase.
endform. "user_command

Former Member
0 Kudos

hi,

Check out this sample program.The part for 'EDIT' is in Bold..

report zalv_color_display_edit.

type-pools: slis.

tables : zcust_master2.

types : begin of wi_zcust_master2,

zcustid like zcust_master2-zcustid,

zcustname like zcust_master2-zcustname,

zaddr like zcust_master2-zaddr,

zcity like zcust_master2-zcity,

zstate like zcust_master2-zstate,

zcountry like zcust_master2-zcountry,

zphone like zcust_master2-zphone,

zemail like zcust_master2-zemail,

zfax like zcust_master2-zfax,

zstat like zcust_master2-zstat,

field_style type lvc_t_styl,

end of wi_zcust_master2.

data: it_wi_zcust_master2 type standard table of wi_zcust_master2

initial size 0,

wa_zcust_master2 type wi_zcust_master2.

data: fieldcatalog type slis_t_fieldcat_alv with header line.

data: it_fieldcat type lvc_t_fcat,

wa_fieldcat type lvc_s_fcat,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type lvc_s_layo, "slis_layout_alv,

gd_repid like sy-repid.

start-of-selection.

perform data_retrieval.

perform set_specific_field_attributes.

perform build_fieldcatalog.

perform build_layout.

perform display_alv_report.

form build_fieldcatalog.

wa_fieldcat-fieldname = 'ZCUSTID'.

wa_fieldcat-scrtext_m = 'CUSTOMER ID'.

wa_fieldcat-col_pos = 0.

wa_fieldcat-outputlen = 10.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZCUSTNAME'.

wa_fieldcat-scrtext_m = 'CUSTOMER NAME'.

wa_fieldcat-col_pos = 1.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZADDR'.

wa_fieldcat-scrtext_m = 'ADDRESS'.

wa_fieldcat-col_pos = 2.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZCITY'.

wa_fieldcat-scrtext_m = 'CITY'.

wa_fieldcat-col_pos = 3.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZSTATE'.

wa_fieldcat-scrtext_m = 'STATE'.

wa_fieldcat-col_pos = 4.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZCOUNTRY'.

wa_fieldcat-scrtext_m = 'COUNTRY'.

wa_fieldcat-col_pos = 5.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZPHONE'.

wa_fieldcat-scrtext_m = 'PHONE NUMBER'.

wa_fieldcat-col_pos = 6.

  • wa_fieldcat-edit = 'X'. "sets whole column to be editable

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZEMAIL'.

wa_fieldcat-scrtext_m = 'EMAIL'.

wa_fieldcat-edit = 'X'. "sets whole column to be editable wa_fieldcat-col_pos = 7.

wa_fieldcat-outputlen = 15.

wa_fieldcat-datatype = 'CURR'.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZFAX'.

wa_fieldcat-scrtext_m = 'FAX'.

wa_fieldcat-col_pos = 8.

wa_fieldcat-edit = 'X'. "sets whole column to be editable

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

wa_fieldcat-fieldname = 'ZSTAT'.

wa_fieldcat-scrtext_m = 'STATUS'.

wa_fieldcat-col_pos = 9.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

endform. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


form build_layout.

  • Set layout field for field attributes(i.e. input/output)

gd_layout-stylefname = 'FIELD_STYLE'.

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'

*----


call function 'REUSE_ALV_GRID_DISPLAY_LVC'

exporting

i_callback_program = gd_repid

is_layout_lvc = gd_layout

it_fieldcat_lvc = it_fieldcat

i_save = 'X'

tables

t_outtab = it_wi_zcust_master2

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

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form data_retrieval .

data: ld_color(1) type c.

select zcustid zcustname zaddr zcity zstate zcountry zphone zemail

zfax zstat up to 10 rows from zcust_master2 into corresponding fields of

table it_wi_zcust_master2.

endform. "data_retrieval

&----


*& Form set_specific_field_attributes

&----


  • populate FIELD_STYLE table with specific field attributes

----


form set_specific_field_attributes .

data ls_stylerow type lvc_s_styl .

data lt_styletab type lvc_t_styl .

  • Populate style variable (FIELD_STYLE) with style properties

  • The following code sets it to be disabled(display only) if 'ZFAX'

  • is NOT INITIAL.

loop at it_wi_zcust_master2 into wa_zcust_master2.

if wa_zcust_master2-zfax is not initial.

ls_stylerow-fieldname = 'ZFAX' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.

"set field to disabled

append ls_stylerow to wa_zcust_master2-field_style.

modify it_wi_zcust_master2 from wa_zcust_master2.

endif.

endloop.

endform. "set_specific_field_attributes

Hope this helps you,

Arunsri

0 Kudos

Hiii

in your example what about the selfield- refresh = C_X??

i did put the i-fieldcat-edit = C_X

i-fieldcat-input = c_x

p-selfield-refresh = c_X

when i put a breakpoint in the user command and i click on save it doesn't the changes doesn't appear in the internal table nor in the p_selfield