Inserting row in ALV
hi experts ..
I want to add a row in the alv when i click on add button..
I know there is insert row and append row buttons available in alv but i dont want those names ..
Can i change the name of standard buttons or is there sm class that i can use to develop this functionality.
jagruti.
Hi Jagruti,
You just have to add a new button with whatever name you want, and map it to the existing functionality in ALV. It will work and you dont need to do anything else.
The code will be:
data:
lr_button type ref to cl_salv_wd_fe_button,
lr_function type ref to cl_salv_wd_function.
CREATE OBJECT lr_button.
lr_button->set_text( 'Your text' ).
lr_button->set_tooltip( 'Your tooltip' ).
lr_function = l_alv_model->if_salv_wd_function_settings~create_function( id = 'INSERT' ).
<b>lr_function->set_function_std( IF_SALV_WD_C_STD_FUNCTIONS=>EDIT_APPEND_ROW ).</b>
lr_function->set_editor( lr_button ).
The method set_function_std sets your funcion to take the behaviour of the standard ALV function for inserting rows. So it would work automatically. You have only changed the text.
<b>If your problem is solved, please award points and close the threads. Couple of your previous threads are still open, please close them</b>
Regards,
Nithya
Similar Messages
-
Hi,
Want to insert rows in editable cell of ALV grid display without using classes and methods.
Thanks in advanceyou need to have a button to append the Rows. it can be possible with the PF_STATUS event. and handling will be done using the User_command.
FORM PF_STATUS using extab type slis_t_extab.
set pf-status 'STANDARD' excluding extab.
ENDFORM.
FORM USER_COMMAND using r_cuomm type sy-ucomm
selfield type slis_selfield.
case r_ucomm.
when 'APPEND'.
APPEND EMPTY LINE HERE to internal table
endcase.
selefield-refresh = 'X'.
ENDFORM. -
Hi Experts,
Which part of the program in BCALV_EDIT04 is responsible for inserting a row in the grid? there is code to handle the data in the inserted line, to check the cells modified using the protocol, and event handler too. Can you please explain which fm or subroutine or step adds a new row to the grid when teh insert button in tool bar is pressed.
I also want some guidance reg the event handler thing. Is mouse click on the cell makes the methods of the protocol to be called? ( I am a java student.. learning SAP slowly.. can you please help me?)methods:
get_inserted_rows
exporting
inserted_rows type sflight_keys.
This part of the code is responsible for inserting rows in a grid. We call this method to insert records in the Grid.
There is no such function module implemented here. We implement the above functionality using <b>Classes and Methods</b>.
Just go to transaction SE24. You'll have a list of Classes in that transaction. Also, we can implement methods using those classes.
Regards,
Pavan. -
Auto value for the inserted row in ALV
Hey experts,
I was following this tutorialALV Grid Insert row function
but he has a strange code there what doesn't work and I don't know how it should be.
This is that part:
ASSIGN er_data_changed->mp_mod_rows->* TO FROM ls_outtab INDEX sy-tabix.
I'm a junior developer and I'm doing this first time and I can't figure it out, how to do it, I was also debuging the BCALV_EDIT_04, but I can't find there what I need.
P.S. Moderator please don't delete my post, I'm working on it a few hours already.
Regards,
RobertHi
I don't know what the tutorial you're linked wanted to do anyway you can try this:
data: l_ins_row type lvc_s_moce.
loop at er_data_changed->mt_inserted_rows into l_ins_row.
er_data_changed->modify_cell(
exporting i_row_id = l_ins_row-row_id
i_fieldname = 'PLANETYPE'
i_value = 'BUBU' ).
endloop.
You need to do it in DATA_CHANGED event and you need to raise the events
call method g_grid->register_edit_event
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
call method g_grid->register_edit_event
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
in order to triggered DATA_CHANGED for a new line
Max -
Hi ,
I need to insert a row in ALV output. On click of a Inser Row button a pop up should show with a parameter.Once the value in entered in the parameter enter is hit , the first column of the new row should have value put in that parameter as non editable field.
The Insert row of standard toolbar inserts a blank row . Is there any way to incorporate the above logic in the standard toolbar?
I'm using CL_GUI_ALV_GRID to display the ALV.
It would be helpful if you provide sample coding.
Thanks.
Ajith
Edited by: Ajith Krishna on Oct 28, 2008 8:01 PMHello Ajith
The enhanced version of sample report ZUS_SDN_ALVGRID_EDITABLE_8A demonstrates how to implement your requirement.
*& ZUS_SDN_ALVGRID_EDITABLE_8A
*& Thread: Insert a row in ALV
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1105097"></a>
*& Thread: Blanking values on ALV Grid Row Duplicate
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1057161"></a>
*& Thread: Delete line event in ALV
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="945471"></a>
REPORT zus_sdn_alvgrid_editable_8a.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knb1.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syst-repid,
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
DATA:
gt_outtab TYPE ty_t_outtab.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
mt_sel_rows TYPE lvc_t_row.
CLASS-METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object
sender,
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_toolbar.
* define local data
DATA: ls_button TYPE stb_button.
LOOP AT e_object->mt_toolbar INTO ls_button.
CASE ls_button-function.
when cl_gui_alv_grid=>MC_FC_LOC_INSERT_ROW.
ls_button-function = 'INSERT_ROW'.
MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
WHEN cl_gui_alv_grid=>mc_fc_loc_delete_row.
ls_button-function = 'DELETE_ROW'.
MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
WHEN cl_gui_alv_grid=>mc_fc_loc_copy_row OR
cl_gui_alv_grid=>mc_fc_loc_copy.
ls_button-function = 'COPY_ROW'.
MODIFY e_object->mt_toolbar FROM ls_button INDEX syst-tabix.
WHEN OTHERS.
CONTINUE.
ENDCASE.
ENDLOOP.
ENDMETHOD. "handle_toolbar
METHOD handle_user_command.
* define local data
DATA: lt_rows TYPE lvc_t_row,
ls_row TYPE lvc_s_row.
REFRESH: mt_sel_rows.
CASE e_ucomm.
when 'INSERT_ROW'.
WHEN 'DELETE_ROW'.
WHEN 'COPY_ROW'.
WHEN OTHERS.
RETURN.
ENDCASE.
" User wants to delete or copy rows => store them in class attribute
" and trigger PAI afterwards where we actually delete /copy the rows
" and do the recalculations (in case of deletion)
CALL METHOD sender->get_selected_rows
IMPORTING
et_index_rows = mt_sel_rows
* et_row_no =
* Trigger PAI
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = e_ucomm
* IMPORTING
* rc =
ENDMETHOD. "user_command
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
PARAMETERS:
p_bukrs TYPE bukrs DEFAULT '2000' OBLIGATORY.
START-OF-SELECTION.
SELECT * FROM knb1 INTO CORRESPONDING FIELDS OF TABLE gt_outtab
UP TO 15 ROWS
WHERE bukrs = p_bukrs.
PERFORM init_controls.
SET HANDLER:
lcl_eventhandler=>handle_toolbar FOR go_grid,
lcl_eventhandler=>handle_user_command FOR go_grid.
" Used to replace standard toolbar function code with custom FC
go_grid->set_toolbar_interactive( ).
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
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.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
** CALL METHOD go_grid1->refresh_table_display
*** EXPORTING
*** IS_STABLE =
*** I_SOFT_REFRESH =
** EXCEPTIONS
** FINISHED = 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.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'INSERT_ROW'.
perform INSERT_ROW.
WHEN 'DELETE_ROW'.
PERFORM delete_rows.
WHEN 'COPY_ROW'.
PERFORM copy_rows.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
CALL METHOD go_grid->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
finished = 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.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form BUILD_FIELDCATALOG_KNB1
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog_knb1 .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNB1'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Only non-key fields are editable
ls_fcat-edit = 'X'.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING edit
WHERE ( key NE 'X' ).
ENDFORM. " BUILD_FIELDCATALOG_KNB1
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
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 ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
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.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog_knb1.
* Display data
CALL METHOD go_grid->set_table_for_first_display
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
EXCEPTIONS
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.
ENDFORM. " INIT_CONTROLS
*& Form delete_rows
* text
* --> p1 text
* <-- p2 text
FORM delete_rows .
* define local data
DATA: ls_row TYPE lvc_s_row.
SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!
LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
DELETE gt_outtab INDEX ls_row-index.
ENDLOOP.
" After deleting rows do RE-CALCULATION
* perform RECALCULATION.
ENDFORM. " delete_rows
*& Form COPY_ROWS
* text
* --> p1 text
* <-- p2 text
FORM copy_rows .
* define local data
DATA: ld_next TYPE i,
ls_row TYPE lvc_s_row,
ls_outtab TYPE ty_s_outtab.
SORT lcl_eventhandler=>mt_sel_rows BY index DESCENDING. " !!!
LOOP AT lcl_eventhandler=>mt_sel_rows INTO ls_row.
READ TABLE gt_outtab INTO ls_outtab INDEX ls_row-index.
CLEAR: ls_outtab-akont. " In your case: clear GUID
ld_next = ls_row-index + 1.
INSERT ls_outtab INTO gt_outtab INDEX ld_next.
ENDLOOP.
ENDFORM. " COPY_ROWS
*& Form INSERT_ROW
* text
* --> p1 text
* <-- p2 text
form INSERT_ROW .
* define local data
DATA: ld_value1 type SPOP-VARVALUE1,
ls_outtab TYPE ty_s_outtab.
CALL FUNCTION 'POPUP_TO_GET_ONE_VALUE'
EXPORTING
textline1 = 'Enter Value (4 Chars):'
* TEXTLINE2 = ' '
* TEXTLINE3 = ' '
titel = 'Enter Value'
valuelength = 4
IMPORTING
* ANSWER =
VALUE1 = ld_value1
EXCEPTIONS
TITEL_TOO_LONG = 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.
ls_outtab-kunnr = ld_value1.
ls_outtab-bukrs = ld_value1.
append ls_outtab to gt_outtab.
endform. " INSERT_ROW
Regards
Uwe -
Insert Blank row After every Row in alv report
How to insert blank row After every row in Alv report
what do you mean by a 'blank row'? ALV displays tabular data with 'any' number of columns. Now if you actually want a blank row (no columns at all, just a row), then that is just not possible. If I'm not mistaken, this question was posted before, so try to do a search on SCN. See what is says.
-
How to get Inserted and Deleted Rows in ALV
I have looked at the BC_EDIT* examples but I still can't figure out how to determine which rows were Inserted and Deleted from the ALV list. Can someone please provide me the code to do this?
Thanks.
SandyHi sandy,
i dont think you will have issue in inserting a row in ALV because whenever the user done some actions say for eg clicking the pushbutton at the toolbar you could insert the a new row into the ALV.for creating pushbutton you need to use the events TOOLBAR,USER_COMMAND.
deleting a row may also follow the above procedure.
Have a look at the demo program
BCALV_GRID_05
Cheers,
Abdul Hakim -
About inserting color to rows in alv
hi ,
could any one tell me how to insert colors to rows in alv.
regards,
pavan.hi,
try like this
TABLES: ekko.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
line_color(4) TYPE c, "Used to store row color attributes
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*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.
*Start-of-selection.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
FORM build_fieldcatalog.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
*& Form BUILD_LAYOUT
Build layout for ALV grid report
FORM build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-info_fieldname = 'LINE_COLOR'.
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
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
i_save = 'X'
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.
DATA: ld_color(1) TYPE c.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekko.
*Populate field with color attributes
LOOP AT it_ekko INTO wa_ekko.
Populate color variable with colour properties
Char 1 = C (This is a color property)
Char 2 = 3 (Color codes: 1 - 7)
Char 3 = Intensified on/off ( 1 or 0 )
Char 4 = Inverse display on/off ( 1 or 0 )
i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
Only 7 colours so need to reset color value
IF ld_color = 8.
ld_color = 1.
ENDIF.
CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.
wa_ekko-line_color = 'C410'.
MODIFY it_ekko FROM wa_ekko.
ENDLOOP.
ENDFORM. " DATA_RETRIEVAL
reward if usefull.... -
Add row to ALV grid highlighting mandatory fields
hello experts,
I am using grid object of cl_gui_alv_grid to display output table. Rows can be added to grid using Insert Row button of ALV toolbar (No custom button added here). The requirement is to highlight the mandatory input cells either with border or display them in different color.
This needs to be done immediatly after pressing the Insert row button, but before the row is displayed on the screen as ready for input ( NOT as a part of data validation on save or enter button).
I tried following method:
- I SET HANDLER event_receiver->handle_user_command FOR obj_grid.
- I am handling EVENT before_user_command OF cl_gui_alv_grid
- I thought of modifying CELLTAB of inserted row in this event to set display properties of required entry fields
However, the problem I am facing here is, Insert_Row button directly populates a row on display screen without triggering before_user_command event.
Is there any way I can highlight the cells of inserted row when it's populated on screen?Hi,
Indeed this event is not triggered for some standard function. Anyhow you could do some trick:
- hide standard insert row button
- add custom button with same icon on in
- then once you press it, you will be able to hanlde it in before_user_commnad event
If you want to stick to standard solution. maybe there is some flag which must be set with some SET.. or REGISTER... method. Unfortunatelly I am not aware of such switch.
Regards
Marcin -
How to change the colour of row in ALV depending on condition?
Hi All,
I want to change the color(from green to red )of perticular row in ALV depending on certain conditions like if amount in some field in row is more than 5000.
Can anybody please tell me how to do that?
expecting early reply.
Thanks in advance,
Rohini.Hi
Check this sample report
*& Report ZALVCOLOR *
REPORT ZALVCOLOR .
DATA : mara TYPE mara. " General Material Data
TYPE-POOLS: slis. " ALV Global types
FIELD-SYMBOLS :
<data> TYPE table. " Data to display
SELECT-OPTIONS :
s_matnr FOR mara-matnr. " Material number
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '50' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
INITIALIZATION.
v_1 = 'Maximum of lines to display'.
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
* Form f_read_data
FORM f_read_data.
FIELD-SYMBOLS :
<field> TYPE ANY,
<field2> TYPE ANY,
<header> TYPE ANY,
<header2> TYPE ANY,
<lt_data> TYPE table. " Data read from DB
DATA:
lp_struct TYPE REF TO data,
lp_struct2 TYPE REF TO data,
lp_table TYPE REF TO data, " Pointer to dynamic table
lp_table2 TYPE REF TO data, " Pointer to dynamic table
ls_lvc_cat TYPE lvc_s_fcat,
lt_lvc_cat TYPE lvc_t_fcat. " Field catalog
* First column
CLEAR ls_lvc_cat.
ls_lvc_cat-fieldname = 'MATNR'.
ls_lvc_cat-ref_table = 'MARA'.
APPEND ls_lvc_cat TO lt_lvc_cat.
* 2nd column
CLEAR ls_lvc_cat.
ls_lvc_cat-fieldname = 'MAKTX'.
ls_lvc_cat-ref_table = 'MAKT'.
APPEND ls_lvc_cat TO lt_lvc_cat.
* 3rd column
CLEAR ls_lvc_cat.
ls_lvc_cat-fieldname = 'MATKL'.
ls_lvc_cat-ref_table = 'MARA'.
APPEND ls_lvc_cat TO lt_lvc_cat.
* Create 1st internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING it_fieldcatalog = lt_lvc_cat
IMPORTING ep_table = lp_table.
ASSIGN lp_table->* TO <lt_data>.
* Read data into 1st internal table
SELECT matnr maktx matkl
INTO TABLE <lt_data>
FROM v_matnr
UP TO p_max ROWS
WHERE matnr IN s_matnr.
* Create 2nd internal table
* Checkbox
CLEAR ls_lvc_cat.
ls_lvc_cat-fieldname = 'CHECKBOX'.
APPEND ls_lvc_cat TO lt_lvc_cat.
* Table color
CLEAR ls_lvc_cat.
ls_lvc_cat-fieldname = 'TABCOLOR'.
ls_lvc_cat-ref_table = 'CALENDAR_TYPE'.
ls_lvc_cat-ref_field = 'COLTAB'.
APPEND ls_lvc_cat TO lt_lvc_cat.
* Create 2nd internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING it_fieldcatalog = lt_lvc_cat
IMPORTING ep_table = lp_table2.
ASSIGN lp_table2->* TO <data>.
* Create structure = structure of the 1st internal table
CREATE DATA lp_struct LIKE LINE OF <lt_data>.
ASSIGN lp_struct->* TO <header>.
* Create structure = structure of the 2nd internal table
CREATE DATA lp_struct2 LIKE LINE OF <data>.
ASSIGN lp_struct2->* TO <header2>.
* Move data from 1st internal table --> 2nd internal table
LOOP AT <lt_data> ASSIGNING <header>.
DESCRIBE TABLE lt_lvc_cat.
CLEAR <header2>.
* Fill the internal to display <data>
DO sy-tfill TIMES.
READ TABLE lt_lvc_cat INTO ls_lvc_cat INDEX sy-index.
* For each field of lt_lvc_cat.
ASSIGN COMPONENT ls_lvc_cat-fieldname OF STRUCTURE <header>
TO <field>.
IF sy-subrc NE 0. EXIT .ENDIF.
ASSIGN COMPONENT ls_lvc_cat-fieldname OF STRUCTURE <header2>
TO <field2>.
IF sy-subrc NE 0. EXIT .ENDIF.
<field2> = <field>.
ENDDO.
* Modify color
ASSIGN COMPONENT 'TABCOLOR' OF STRUCTURE <header2>
TO <field2>.
IF sy-subrc EQ 0.
PERFORM f_modify_color USING 'MAKTX' <field2>.
PERFORM f_modify_color USING 'MATKL' <field2>.
ENDIF.
APPEND <header2> TO <data> .
ENDLOOP.
ENDFORM. " f_read_data
* Form F_DISPLAY_DATA
FORM f_display_data.
* Macro definition
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-down = 'X'.
append ls_sort to lt_sort.
END-OF-DEFINITION.
DATA:
ls_layout TYPE slis_layout_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv. " Field catalog
* Build Fieldcatalog - First column
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MATNR'.
ls_fieldcat-ref_tabname = 'MARA'.
ls_fieldcat-key = 'X'.
APPEND ls_fieldcat TO lt_fieldcat.
* Build Fieldcatalog - 2nd column
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MAKTX'.
ls_fieldcat-ref_tabname = 'MAKT'.
APPEND ls_fieldcat TO lt_fieldcat.
* Build Fieldcatalog - 3rd column
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'MATKL'.
ls_fieldcat-ref_tabname = 'MARA'.
APPEND ls_fieldcat TO lt_fieldcat.
* Layout
ls_layout-zebra = 'X'.
ls_layout-colwidth_optimize = 'X'.
ls_layout-box_fieldname = 'CHECKBOX'.
ls_layout-coltab_fieldname = 'TABCOLOR'.
m_sort 'MATNR'. " Sort by creation date
* Display data
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
TABLES
t_outtab = <data>.
ENDFORM. " F_DISPLAY_DATA
* Form F_modify_color
FORM f_modify_color USING u_fieldname TYPE lvc_fname
ut_tabcolor TYPE table.
DATA:
l_rnd_value TYPE datatype-integer2,
ls_tabcolor TYPE lvc_s_scol.
* Random value
CALL FUNCTION 'RANDOM_I2'
EXPORTING
rnd_min = 0
rnd_max = 3
IMPORTING
rnd_value = l_rnd_value.
CLEAR ls_tabcolor.
ls_tabcolor-fname = u_fieldname.
CASE l_rnd_value.
WHEN 0.
ls_tabcolor-color-col = 1. " Blue.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 1.
ls_tabcolor-color-col = 3. " Yellow.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 2.
ls_tabcolor-color-col = 5. " Green.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
WHEN 3.
ls_tabcolor-color-col = 6. " Red.
ls_tabcolor-color-int = 0.
ls_tabcolor-color-inv = 0.
ENDCASE.
INSERT ls_tabcolor INTO TABLE ut_tabcolor.
ENDFORM. " F_MODIFY_COLOR
Reward all helpfull answers
Regards
Pavan -
How to set some rows in ALV to be editable or some non editable.
Dear all Gurus,
I'm facing a situation here, I need your assistance.
I'm creating a alv table where the user can enter a data and then this will be uploaded into the system. Now upon validation some records might fail and would need some changes and some records that had no problems would have been successfully posted.
When the program returns to the user i want the successful one's to be greyed out and not editable. I'm not sure on how i could acess the rows of the table. I tried few classes and an all i could manage was to change the table setting and configs.
Below i've pasted the code on how i've code my alv table. Please advice on how i could access the rows and disable the successfull ones. Please.
METHOD wddoinit .
DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage,
l_interface TYPE REF TO iwci_salv_wd_table,
l_model TYPE ref to cl_salv_wd_config_table, "Contains all characteristics of a table(collumns, fields, etc)
lt_columns TYPE salv_wd_t_column_ref, " Table type
lt_fields TYPE salv_wd_t_field_ref, " Table type
l_btn_ins TYPE REF TO cl_salv_wd_fe_button,
l_btn_del TYPE REF TO cl_salv_wd_fe_button,
l_btn_sell_all TYPE REF TO cl_salv_wd_fe_button,
l_btn_dell_all TYPE REF TO cl_salv_wd_fe_button,
l_btn_calc TYPE REF TO cl_salv_wd_fe_button,
l_btn_save TYPE REF TO cl_salv_wd_fe_button,
l_function TYPE REF TO cl_salv_wd_function,
l_column TYPE REF TO cl_salv_wd_column,
l_header TYPE REF TO cl_salv_wd_column_header,
lr_input_1 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_2 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_3 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_4 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_5 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_6 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_7 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_8 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_9 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_10 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_11 TYPE REF TO cl_salv_wd_uie_input_field,
lr_input_12 TYPE REF TO cl_salv_wd_uie_input_field,
l_link TYPE REF TO cl_salv_wd_uie_button.
CONSTANTS:
zzto TYPE string VALUE 'ZZTO',
zzfrom TYPE string VALUE 'ZZFROM',
takeoff_date TYPE string VALUE 'TAKEOFF_DATE',
read_date TYPE string VALUE 'READ_DATE',
takeoff_time TYPE string VALUE 'TAKEOFF_TIME',
read_time TYPE string VALUE 'READ_TIME',
ac_hrs TYPE string VALUE 'AC_HRS',
le_hrs TYPE string VALUE 'LE_HRS',
re_hrs TYPE string VALUE 'RE_HRS',
ac_cycle TYPE string VALUE 'AC_CYCLE',
re_cycle TYPE string VALUE 'RE_CYCLE',
le_cycle TYPE string VALUE 'LE_CYCLE',
ltext TYPE string VALUE 'LTEXT'.
l_ref_cmp_usage = wd_this->wd_cpuse_multi_alv( ).
IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
l_ref_cmp_usage->create_component( ).
ENDIF.
*Map the interface.
l_interface = wd_this->wd_cpifc_multi_alv( ).
DATA:
node_mdoc TYPE REF TO if_wd_context_node,
elem_mdoc TYPE REF TO if_wd_context_element.
navigate from <CONTEXT> to <MDOC> via lead selection
node_mdoc = wd_context->get_child_node( name = if_create_mass_entry=>wdctx_mdoc ).
l_interface->set_data( r_node_data = node_mdoc ).
*Map the model
wd_this->l_model = l_interface->get_model( ).
*Map the columns
lt_columns = wd_this->l_model->if_salv_wd_column_settings~t_columns.
*Map the fields
lt_fields = wd_this->l_model->if_salv_wd_field_settings~t_fields.
cl_salv_wd_model_table_util=>if_salv_wd_table_util_stdfuncs~set_all(
EXPORTING r_model = wd_this->l_model
allowed = abap_false ). " try abap_true
*Enable or Disable the ALV desired outlook and design
wd_this->l_model->if_salv_wd_table_settings~delete_header( ).
wd_this->l_model->if_salv_wd_table_settings~set_selection_mode(
value = cl_wd_table=>e_selection_mode-auto ).
wd_this->l_model->if_salv_wd_table_settings~set_width( value = '100%' ).
wd_this->l_model->if_salv_wd_table_settings~set_visible_row_count( value = '10' ).
wd_this->l_model->if_salv_wd_table_settings~set_read_only( value = abap_false ).
wd_this->l_model->if_salv_wd_std_functions~set_filter_filterline_allowed( value = abap_true ).
wd_this->l_model->if_salv_wd_std_functions~set_sort_headerclick_allowed( value = abap_true ).
wd_this->l_model->if_salv_wd_std_functions~set_export_allowed( value = abap_false ).
*Adding functionalities to the ALV
*'Insert Row' Button
CREATE OBJECT l_btn_ins.
l_btn_ins->set_text( 'Insert Row' ).
l_btn_ins->set_tooltip( 'To enter a new row' ).
l_btn_ins->set_image_source( value = 'ICON_INSERT_ROW' ).
l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'INSERT' ).
l_function->set_position( value = '1' ).
l_function->set_editor( value = l_btn_ins ).
*'Delete Row' Button
CREATE OBJECT l_btn_del.
l_btn_del->set_text( 'Delete Row' ).
l_btn_del->set_tooltip( 'Delete the selected row' ).
l_btn_del->set_image_source( value = 'ICON_DELETE_ROW' ).
l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'DELETE' ).
l_function->set_position( value = '2' ).
l_function->set_editor( value = l_btn_del ).
*'Select All' Button
CREATE OBJECT l_btn_sell_all.
l_btn_sell_all->set_text( 'Select All' ).
l_btn_sell_all->set_tooltip( 'Select all entered record' ).
l_btn_sell_all->set_image_source( value = 'ICON_INSERT_ROW' ).
l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'SELECT' ).
l_function->set_position( value = '3' ).
l_function->set_editor( value = l_btn_sell_all ).
*'Deselect All' Button
CREATE OBJECT l_btn_dell_all.
l_btn_dell_all->set_text( 'Deselect All' ).
l_btn_dell_all->set_tooltip( 'Deselect all records selected' ).
l_btn_dell_all->set_image_source( value = 'ICON_DESELECT_ALL' ).
l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'DESELECT' ).
l_function->set_position( value = '4' ).
l_function->set_editor( value = l_btn_dell_all ).
*'Calculate' Button
CREATE OBJECT l_btn_calc.
l_btn_calc->set_text( 'Calculate Hours' ).
l_btn_calc->set_tooltip( 'Calculate hours of each record' ).
l_btn_calc->set_image_source( value = 'ICON_CALCULATION' ).
l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'CALC' ).
l_function->set_position( value = '5' ).
l_function->set_editor( value = l_btn_calc ).
*'Save' Button
CREATE OBJECT l_btn_save.
l_btn_save->set_text( 'Save All' ).
l_btn_save->set_tooltip( 'Save all' ).
l_btn_save->set_image_source( value = 'ICON_SYSTEM_SAVE' ).
l_function = wd_this->l_model->if_salv_wd_function_settings~create_function( id = 'SAVE' ).
l_function->set_position( value = '6' ).
l_function->set_editor( value = l_btn_save ).
FIELD-SYMBOLS: <fs_column> TYPE salv_wd_s_column_ref.
LOOP AT lt_columns ASSIGNING <fs_column>.
l_column = <fs_column>-r_column.
l_column->get_header( RECEIVING value = l_header ).
l_header->set_ddic_binding_field( value = if_salv_wd_c_column_settings=>ddic_bind_none ).
CASE <fs_column>-id .
WHEN zzfrom.
CREATE OBJECT lr_input_1 EXPORTING value_fieldname = zzfrom.
l_header->set_text( value = 'Flt Fr' ).
l_column->set_position( value = '1' ).
l_column->set_cell_editor( lr_input_1 ).
l_column->set_visible( '0' ).
WHEN zzto.
CREATE OBJECT lr_input_2 EXPORTING value_fieldname = zzto.
l_header->set_text( value = 'Flt To' ).
l_column->set_position( value = '2' ).
l_column->set_cell_editor( lr_input_2 ).
WHEN takeoff_date.
CREATE OBJECT lr_input_3 EXPORTING value_fieldname = takeoff_date.
l_header->set_text( value = 'Takeoff Date' ).
l_column->set_position( value = '3' ).
l_column->set_cell_editor( lr_input_3 ).
WHEN read_date.
CREATE OBJECT lr_input_4 EXPORTING value_fieldname = read_date.
l_header->set_text( value = 'Landing Date' ).
l_column->set_position( value = '4' ).
l_column->set_cell_editor( lr_input_4 ).
WHEN takeoff_time.
CREATE OBJECT lr_input_5 EXPORTING value_fieldname = takeoff_time.
l_header->set_text( value = 'Takeoff Time' ).
l_column->set_position( value = '5' ).
l_column->set_cell_editor( lr_input_5 ).
WHEN read_time.
CREATE OBJECT lr_input_6 EXPORTING value_fieldname = read_time.
l_header->set_text( value = 'Landing Time' ).
l_column->set_position( value = '6' ).
l_column->set_cell_editor( lr_input_6 ).
WHEN ac_hrs.
CREATE OBJECT lr_input_7 EXPORTING value_fieldname = ac_hrs.
l_header->set_text( value = 'Flt Time' ).
l_column->set_position( value = '7' ).
l_column->set_cell_editor( lr_input_7 ).
WHEN le_hrs.
CREATE OBJECT lr_input_8 EXPORTING value_fieldname = le_hrs.
l_header->set_text( value = 'LH Eng Runtime' ).
l_column->set_position( value = '8' ).
l_column->set_cell_editor( lr_input_8 ).
WHEN re_hrs.
CREATE OBJECT lr_input_9 EXPORTING value_fieldname = re_hrs.
l_header->set_text( value = 'RH Eng Runtime' ).
l_column->set_position( value = '9' ).
l_column->set_cell_editor( lr_input_9 ).
WHEN ac_cycle.
CREATE OBJECT lr_input_10 EXPORTING value_fieldname = ac_cycle.
l_header->set_text( value = 'No. of Landings' ).
l_column->set_position( value = '10' ).
l_column->set_cell_editor( lr_input_10 ).
WHEN re_cycle.
CREATE OBJECT lr_input_11 EXPORTING value_fieldname = re_cycle.
l_header->set_text( value = 'RH Eng Start' ).
l_column->set_position( value = '11' ).
l_column->set_cell_editor( lr_input_11 ).
WHEN le_cycle.
CREATE OBJECT lr_input_12 EXPORTING value_fieldname = le_cycle.
l_header->set_text( value = 'LH Eng Start' ).
l_column->set_position( value = '12' ).
l_column->set_cell_editor( lr_input_12 ).
WHEN ltext.
CREATE OBJECT l_link.
l_link->set_image_source( value = 'ICON_CREATE_TEXT' ).
l_link->set_text_fieldname( ltext ).
l_link->set_tooltip( value = 'Create Log' ).
l_header->set_text( value = 'Enter Log').
l_column->set_cell_editor( l_link ).
l_column->set_h_align( cl_wd_table_column=>e_h_align-center ).
l_column->set_position( value = '13' ).
WHEN OTHERS.
l_column->set_visible( '01' ).
ENDCASE.
ENDLOOP.
ENDMETHOD.
Your any help is highly appreciated. Thank you.
Regards,
VinodOk, here you go.
In your context, apart from your display fields, add another attribute READ_ONLY, type char01. And lets assume you want the field by name field_1 to be editable or not based on some validation. Your code will be like this to initialize the ALV.
DATA:
l_alv_model TYPE REF TO cl_salv_wd_config_table,
lr_column_settings TYPE REF TO if_salv_wd_column_settings,
lr_column TYPE REF TO cl_salv_wd_column,
lt_col TYPE SALV_WD_T_COLUMN_REF,
ls_col TYPE SALV_WD_S_COLUMN_REF,
lr_input_field type ref to cl_salv_wd_uie_input_field.
l_alv_model = l_ref_interfacecontroller->get_model( ).
l_alv_model->IF_SALV_WD_TABLE_SETTINGS~SET_READ_ONLY( abap_false ).
lr_column_settings ?= l_alv_model.
lt_col = lr_column_settings->get_columns( ).
LOOP AT lt_col INTO ls_col where ID = 'FIELD_1'.
create object lr_input_field exporting value_fieldname = ls_col-id.
lr_input_field->set_read_only_fieldname( 'READ_ONLY' ).
ls_col-r_column->set_cell_editor( lr_input_field ).
ENDLOOP.
In your event handler, you read your node, do a get_static_attributes_table. Perform all validations. Loop through your internal table and set the field READ_ONLY as 'X' when validation succeeds. Do READ_ONLY = space when validation fails. Then do a bind_elements. Now the rows for which read_only is false, will be editable and vice versa.
Hope I was clear enough. Get back if you have any doubts.
Regards,
Nithya -
Hotspot-clicking (Insert function) plus ALV Sorting
Hi,
I have a requirement where the ALV display has to be SORTED based on values entered/changed on a certain column. The sort works ok when used with a custom APPEND button for new records (always inserted at the bottom of the list).
However, it does not work correctly when used with the Hotspot-click (INSERT functionality). It looks like if you CLICK on a particular record onscreen, you are actually addressing the original record in that position before the SORT was effected.
Is the Hotspot-clicking (Insert functionality) possible with ALV sorting? The ideal solution would be to have the ALV sorted at PBO and also at PAI so that the user can change existing records and add new ones with the sorting being updated everytime ON_DATA_CHANGED is triggered.
Will appreciate any help on this.
Thanks!
MichaelHello Michael
Thanks for further specifying your requirements. I have created the sample variant ZUS_SDN_ALVGRID_HOTSPOT_SORT_1 which contains two differences as compared to its template:
Replace table VBAK with VBAP (so we have two levels of sorting: VBELN, POSNR)
Move SET_TABLE_FOR_FIRST_DISPLAY method call into PBO
When I click on the hotspot (VBELN) a new row entry for the order number is created. The sorting (VBELN, POSNR) is kept even though the new row has been appended to the itab.
*& Report ZUS_SDN_ALVGRID_HOTSPOT_SORT
*& Thread: Hotspot-clicking (Insert function) plus ALV Sorting
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1159431"></a>
REPORT zus_sdn_alvgrid_hotspot_sort.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbap.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA: gt_outtab TYPE ty_t_outtab.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syrepid,
gt_sort TYPE lvc_t_sort,
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
ms_sel_row TYPE lvc_s_row. " selected row
CLASS-METHODS:
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING
er_data_changed
e_onf4
e_onf4_before
e_onf4_after
sender,
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_data_changed.
FIELD-SYMBOLS: <lt_outtab> TYPE ty_t_outtab.
BREAK-POINT.
ENDMETHOD. "handle_data_changed
METHOD handle_hotspot_click.
" define local data
DATA: ls_outtab TYPE ty_s_outtab,
ld_msg TYPE bapi_msg.
BREAK-POINT.
CLEAR: lcl_eventhandler=>ms_sel_row.
ms_sel_row = e_row_id.
READ TABLE gt_outtab INTO ls_outtab INDEX e_row_id-index.
CONCATENATE 'Selected Sales Order = ' ls_outtab-vbeln ' / '
ls_outtab-posnr
INTO ld_msg.
message i398(00) with ld_msg.
" Trigger PAI
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'INSERT'
* IMPORTING
* rc =
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
PARAMETERS:
p_vkorg TYPE vkorg DEFAULT '0001' OBLIGATORY.
START-OF-SELECTION.
** SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE gt_outtab
** UP TO 200 ROWS
** WHERE vkorg = p_vkorg.
SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE gt_outtab
UP TO 100 ROWS.
PERFORM init_controls.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog.
PERFORM set_layout_and_variant.
PERFORM set_sorting.
" Register EDIT event
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SET HANDLER:
lcl_eventhandler=>handle_data_changed FOR go_grid,
lcl_eventhandler=>handle_hotspot_click FOR go_grid.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
* Display data
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
i_bypassing_buffer = abap_true
is_variant = gs_variant
i_save = 'A'
* i_default = 'X'
is_layout = gs_layout
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
it_sort = gt_sort
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
** CALL METHOD go_grid->refresh_table_display
*** EXPORTING
*** IS_STABLE =
*** I_SOFT_REFRESH =
** EXCEPTIONS
** finished = 1
** OTHERS = 2.
** IF sy-subrc ne 0.
*** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
** ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'INSERT'.
PERFORM insert_row.
WHEN OTHERS.
" Check for changed data at the frontend (= grid control)
CALL METHOD go_grid->check_changed_data( ).
ENDCASE.
CALL METHOD go_grid->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
others = 6.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
others = 5.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " INIT_CONTROLS
*& Form BUILD_FIELDCATALOG
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog.
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'VBAP' " 'VBAK'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
** LOOP AT gt_fcat INTO ls_fcat.
** CASE ls_fcat-fieldname.
** WHEN 'VBELN' OR
** 'ERDAT' OR
** 'ERZET' OR
** 'ERNAM' OR
** 'AUART' OR
** 'NETWR' OR
** 'WAERK'.
** CONTINUE.
** WHEN OTHERS.
** ls_fcat-no_out = abap_true.
** ENDCASE.
** MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
** ENDLOOP.
* Only non-key fields are editable
** ls_fcat-edit = 'X'.
** MODIFY gt_fcat FROM ls_fcat
** TRANSPORTING edit
** WHERE ( fieldname NE space ).
ls_fcat-hotspot = abap_true.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING hotspot
WHERE ( fieldname = 'AUART' OR
fieldname = 'VBELN' ).
** DELETE gt_fcat FROM 15 TO 99.
ENDFORM. " BUILD_FIELDCATALOG_KNB1
*& Form SET_LAYOUT_AND_VARIANT
* text
* --> p1 text
* <-- p2 text
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_layout-cwidth_opt = abap_true.
gs_variant-report = syst-repid.
gs_variant-handle = 'GRID'.
ENDFORM. " SET_LAYOUT_AND_VARIANT
*& Form SET_SORTING
* text
* --> p1 text
* <-- p2 text
FORM set_sorting .
* define local data
DATA: ls_sort TYPE lvc_s_sort.
REFRESH: gt_sort.
CLEAR: ls_sort.
ls_sort-spos = 1.
ls_sort-fieldname = 'VBELN'.
ls_sort-up = abap_true.
APPEND ls_sort TO gt_sort.
CLEAR: ls_sort.
ls_sort-spos = 1.
ls_sort-fieldname = 'POSNR'.
ls_sort-up = abap_true.
APPEND ls_sort TO gt_sort.
ENDFORM. " SET_SORTING
*& Form INSERT_ROW
* text
* --> p1 text
* <-- p2 text
FORM insert_row .
* define local data
DATA: ls_outtab TYPE ty_s_outtab,
ld_order TYPE vbeln.
READ TABLE gt_outtab INTO ls_outtab
INDEX lcl_eventhandler=>ms_sel_row-index.
ld_order = ls_outtab-vbeln.
" Find last item of sales order
LOOP AT gt_outtab INTO ls_outtab
WHERE ( vbeln = ld_order ).
ENDLOOP.
" Create next item:
add 10 to ls_outtab-posnr.
" NOTE: added at the end of the list
APPEND ls_outtab TO gt_outtab.
" NOTE: insert new row AFTER selected row => works, too
** INSERT ls_outtab INTO gt_outtab
** INDEX lcl_eventhandler=>ms_sel_row-index.
ENDFORM. " INSERT_ROW -
Hi,
Is it possible that when a user higlights a row in ALV, the entire row will be uneditable? Please teach me how.
Thanks,
JimThis code works for grey cells...But it could be adapted to lines -;) It uses OO ALV...
*& Report Z_DUMMY_ATG
REPORT Z_DUMMY_ATG NO STANDARD PAGE HEADING.
TABLES: SPFLI.
*============================================================
* Variables
*============================================================
DATA: OK_CODE TYPE SY-UCOMM,
L_MODE TYPE RAW4,
W_TABIX TYPE SY-TABIX.
*============================================================
* Tablas internas
*============================================================
DATA: L_S_LAYO TYPE LVC_S_LAYO.
DATA: WA_EDIT TYPE LVC_T_STYL WITH HEADER LINE.
DATA: IT_EDIT TYPE LVC_T_STYL WITH HEADER LINE.
DATA: BEGIN OF G_WA_SFLIGHT.
INCLUDE STRUCTURE SPFLI.
DATA: CELL_TAB TYPE LVC_T_STYL.
DATA: END OF G_WA_SFLIGHT.
TYPES: BEGIN OF SPFLI_TAB.
INCLUDE STRUCTURE SPFLI.
TYPES: CELL_TAB TYPE LVC_T_STYL.
TYPES: END OF SPFLI_TAB.
TYPES: SPFLI_TABS TYPE STANDARD TABLE OF SPFLI_TAB.
DATA: GI_SFLIGHT TYPE SPFLI_TABS.
DATA: BEGIN OF AUX_TAB OCCURS 0,
CARRID LIKE SPFLI-CARRID,
CONNID LIKE SPFLI-CONNID,
CITYFROM LIKE SPFLI-CITYFROM,
AIRPFROM LIKE SPFLI-AIRPFROM,
CITYTO LIKE SPFLI-CITYTO,
AIRPTO LIKE SPFLI-AIRPTO,
END OF AUX_TAB.
DATA: SPFLI_TAB_WA LIKE G_WA_SFLIGHT.
FIELD-SYMBOLS: <SF> STRUCTURE G_WA_SFLIGHT
DEFAULT SPFLI_TAB_WA.
*============================================================
* Objetos
*============================================================
DATA: CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
ALV_LIST TYPE REF TO CL_GUI_ALV_GRID.
*============================================================
* Selección de Datos
*============================================================
SELECT *
FROM SPFLI
INTO CORRESPONDING FIELDS OF TABLE AUX_TAB .
LOOP AT AUX_TAB.
MOVE-CORRESPONDING AUX_TAB TO <SF>.
APPEND <SF> TO GI_SFLIGHT.
ENDLOOP.
*============================================================
* Instancimiento de Objetos
*============================================================
CREATE OBJECT CONTAINER
EXPORTING CONTAINER_NAME = 'LIST_AREA'.
CREATE OBJECT ALV_LIST
EXPORTING I_PARENT = CONTAINER.
*============================================================
* Procesamiento
*============================================================
LOOP AT GI_SFLIGHT INTO G_WA_SFLIGHT.
W_TABIX = SY-TABIX.
IF G_WA_SFLIGHT-CITYTO EQ 'SAN FRANCISCO'.
L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
MOVE 'CITYTO' TO WA_EDIT-FIELDNAME.
MOVE L_MODE TO WA_EDIT-STYLE.
INSERT WA_EDIT INTO IT_EDIT INDEX W_TABIX.
G_WA_SFLIGHT-CELL_TAB[] = IT_EDIT[].
ENDIF.
MODIFY GI_SFLIGHT FROM G_WA_SFLIGHT.
ENDLOOP.
MOVE 'CELL_TAB' TO L_S_LAYO-STYLEFNAME.
CALL METHOD ALV_LIST->SET_READY_FOR_INPUT
EXPORTING I_READY_FOR_INPUT = 1.
CALL METHOD ALV_LIST->SET_TABLE_FOR_FIRST_DISPLAY(
EXPORTING I_STRUCTURE_NAME = 'SPFLI'
IS_LAYOUT = L_S_LAYO
CHANGING IT_OUTTAB = GI_SFLIGHT ).
*============================================================
* Dynpro
*============================================================
CALL SCREEN 100.
*& Module STATUS_0100 OUTPUT
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS '100'.
ENDMODULE.
*& Module USER_COMMAND_0100 INPUT
MODULE USER_COMMAND_0100 INPUT.
OK_CODE = SY-UCOMM.
IF OK_CODE = 'BACK'.
SET SCREEN 0.
LEAVE SCREEN.
CLEAR OK_CODE.
ENDIF.
ENDMODULE.
Greetings,
Blag. -
Multiple Input Rows In ALV Grid (Editable)
Hi,
I have an editable ALV grid and need to have multiple blank rows ready for input. Something similar to what happens when you click the "New Entries" button in SM30 (Table Maintainance).
There is a local function for appending lines in the ALV grid toolbar but this only allows a single entry.
I have replaced the local function with my own button (same icon etc) and on user_command event, I am appending several blank lines to my output table.
However these lines are not being shown on the screen. I have looked through the layout and field catalog but there is no field to allow blank lines to be shown.
My 2 questions are:
1. Is there some standard way of entering multiple entries in ALV Grid Editable.
2. If not then how to allow blank lines to be shown as ready for input.
Also if someone could suggest a way to do error checking for all entries on the screen especially duplicate entries I will be extremely grateful.
Many Thanks,
PreetHi, Preet!
You can easily do whatever checks you wish. You should declare an event handling method for event DATA_CHANGED and call the ADD_PROTOCOL_ENTRY method of the ER_DATA_CHANGED event parameter (it's an object of the class CL_ALV_CHANGED_DATA_PROTOCOL). You must not forget to set handler for your ALV grid.
For example, this piece of code checks for all changed fields resulting in error message if they are initial. In short, this makes all the fields obligatory.
METHODS: on_data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed.
SET HANDLER your_object->on_data_changed FOR your_alv_grid.
METHOD on_data_changed.
DATA: s_mod_cell TYPE lvc_s_modi.
LOOP AT er_data_changed->mt_mod_cells INTO s_mod_cell.
IF s_mod_cell-value IS INITIAL.
* issue message 'Make an entry in all required fields'
CALL METHOD er_data_changed->add_protocol_entry
EXPORTING i_msgid = '00'
i_msgno = '055'
i_msgty = 'E'
i_fieldname = s_mod_cell-fieldname
i_row_id = s_mod_cell-row_id.
ENDIF.
ENDMETHOD.
Furthermore, if you make your class inherited from CL_GUI_ALV_GRID you can make use of protected attribute MT_OUTTAB which is a data object referencing your output table. Then you can have:
FIELD-SYMBOLS: <outtab> TYPE STANDARD TABLE.
ASSIGN me->mt_outtab->* TO <outtab>.
* do whatever you want with <outtab>
Hope this helps.
Kind regards,
Igor
P.S. Regarding the blank lines that you need, what's wrong with standard ALV grid buttons "Append row" and "Insert row" which appear whenever the grid is editable (unless you deliberately remove them)? They work just fine with me (just like on SM30). I don't see reason for programatically appending lines to your internal table. -
Print,Check,Apppend Row,Delete Row,Insert Row buttons actions code
HI,
I have a ALV table in that buttons Print,Check,Apppend Row,Delete Row,Insert Row buttons are there.But client requirement is they don't want those buttons in ALV they want in above the ALV table.
Can you please let me know how to hide those buttons in ALV.and give me code Print,Check,Apppend Row,Delete Row,Insert Row action code..HI,I hope you have instantiated your ALV. Check the below code
* Instantiate the used component " You can use code wizard to get this code.
DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
lo_cmp_usage = wd_this->wd_cpuse_usg_alv( ). "usg_alv should be your usage name
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
lo_cmp_usage->create_component( ).
ENDIF.
* Get Model
DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
lo_interfacecontroller = wd_this->wd_cpifc_usg_alv( ).
DATA lo_value TYPE REF TO cl_salv_wd_config_table.
lo_value = lo_interfacecontroller->get_model(
* Hide Standard buttons on ALV toolbar
DATA: l_std_func TYPE REF TO if_salv_wd_std_functions.
l_std_func ?= lo_value .
l_std_func->set_edit_append_row_allowed( abap_false ) .
l_std_func->set_sort_headerclick_allowed( abap_true ) .
l_std_func->set_edit_append_row_allowed( abap_false ) .
l_std_func->set_edit_insert_row_allowed( abap_false ) .
l_std_func->set_edit_delete_row_allowed( abap_false ) .
l_std_func->set_view_list_allowed( abap_false ) .
l_std_func->set_sort_headerclick_allowed( abap_false ) .
l_std_func->set_edit_check_available( abap_false ) .
l_std_func->set_pdf_allowed( abap_false ) .
l_std_func->set_export_allowed( abap_true ) .
Radhika.
Maybe you are looking for
-
Hi- I got a new PC laptop, retrieved all old HD contents from my external HD, installed LR 5.6 (5.4 on previous PC) and when I tried to open up my old Lightroom catalog it has an error saying "Lightroom has encountered problems reading this photo. Y
-
My camera is not working .shutter appears closed.tried to restart ipad but problem still there.no problem with photo booth problem with istangram
-
Pay laod in not comming to SXMB_MONI
Hi Experts, I created on scenario file to proxy. it was working fine Dev Environment. i have trasported into Quality system. I congigured ID objects prolerly. Here i am using file is sender adapter. this file adapter has to pick the Xml file and pro
-
I just went out and spent $55 on cables and adapters to connect my $260 x-fi platinum card to my reciever so i can get 5. sound. So far all i've got is the ability to select pro logic 2 in my reciever, something i was able to do with onboard sound of
-
Hyper-V Failover Cluster - Inconsistent Network Availability
We've got a Small cluster with, 7 hosts and a dozen or two VM's. For some reason i'm getting inconsistent availability with the Cluster networks. The host seem to function fine on there own but theres all types of issues using Migration which i'm a