11-01-2015 7:31 AM
Hello,
I have a simple ooalv report with few editable columns.
What i want is this:
while punching values from excel file(simple CTRL C and CTRL V) in the editable column of alv. it is possible that user may copy more records then the no of records are currently displayed in alv.
Like this.
There are 5 records in displayed ALV. but user selects 10 records(or more if mistakenly) and paste them in alv.
Paste them in ALV.
Then as you can see - now rows are inserted.
It is possible that while pasting records in alv only 5 records gets pasted( no of pasted records = no of displayed records).
No new rows gets insert.
11-01-2015 11:24 AM
Hi Abhishek,
yes, you can do this by using the event
mc_evt_modified.
METHOD handle_data_changed.
FIELD-SYMBOLS <ls_sflight> TYPE sflight.
IF lines( lt_sflight ) > 5.
DELETE lt_sflight FROM 11 TO lines( lt_sflight ).
ENDIF .
IF lr_alv IS NOT INITIAL.
lr_alv->refresh_table_display( ).
MESSAGE 'You are not allowed to enter more than 5 records' TYPE 'I'.
ENDIF.
ENDMETHOD.
Regards
Ebrahim
11-01-2015 11:29 AM
thanks ,
But i found better shortcut:
Just set this parameter in alv grid. this is in layout. And it will prevent creation of new rows.
11-01-2015 1:00 PM
Hi,
you are right, I have tried it out, and it works without needig for the code, but this code may it help for something else,
anyhow, thank you
Regards
Ebrahim
11-01-2015 5:49 PM
Hi,
but this statement ls_layout-no_rowins = abap_true does not allow you to enter any record,
what you will do if you want to delete a record and you would like to add a new one!!
no more than 5 records as an example.
Regards
Ebrahim
11-01-2015 11:27 AM
Hi,
this is the code,
may it help you, if you face any problem,just let us to know.
REPORT zibo_pg_test99.
DATA lt_sflight TYPE TABLE OF sflight.
DATA ls_sflight TYPE sflight.
DATA lr_cont TYPE REF TO cl_gui_custom_container.
DATA: lr_alv TYPE REF TO cl_gui_alv_grid.
data lt_fcat TYPE LVC_T_FCAT.
FIELD-SYMBOLS <ls_fcat> like line of lt_fcat.
INCLUDE zclasses.
*CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
*DATA: G_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
data lr_event TYPE REF TO LCL_EVENT_RECEIVER.
START-OF-SELECTION.
select * from sflight into TABLE lt_sflight UP TO 5 ROWS.
CALL SCREEN 100.
form build_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
ct_fieldcat = lt_fcat.
read TABLE lt_fcat ASSIGNING <ls_fcat>
with key fieldname = 'PRICE'.
IF sy-subrc = 0.
<ls_fcat>-edit = abap_true.
ENDIF.
ENDFORM.
MODULE status_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
PERFORM build_fcat.
IF lr_cont IS INITIAL.
CREATE OBJECT lr_cont
EXPORTING
container_name = 'CONT'.
ENDIF.
IF lr_cont IS NOT INITIAL AND
lr_alv IS INITIAL.
CREATE OBJECT lr_alv
EXPORTING
i_parent = lr_cont.
ENDIF.
CREATE OBJECT lr_event.
CALL METHOD lr_alv->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>mc_evt_modified.
SET HANDLER:
lr_event->handle_data_changed FOR lr_alv.
lr_alv->set_table_for_first_display(
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_fieldcatalog = lt_fcat
it_outtab = lt_sflight ).
ENDMODULE. " STATUS_0100 OUTPUT
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN space.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
" Dont forget to create an Include with name ZCLASSES
*&---------------------------------------------------------------------*
*& Include ZCLASSES
*&---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
ENDCLASS. "lcl_event_receiver DEFINITION
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_data_changed.
FIELD-SYMBOLS <ls_sflight> TYPE sflight.
IF lines( lt_sflight ) > 5.
DELETE lt_sflight FROM 5 TO lines( lt_sflight ).
ENDIF .
IF lr_alv IS NOT INITIAL.
lr_alv->refresh_table_display( ).
MESSAGE 'You are not allowed to enter more than 5 records' TYPE 'I'.
ENDIF.
ENDMETHOD.
ENDCLASS.
Regards
Ebrahim Hatem