ALV Report - edit option
Hi,
This is BalaNarasimman. i am making one field as editable field in alv report.
The requirement is that field should have input with decimal also. Eg. 2.2.
So i am declaring data type as, data:per type P DECIMALS 1.
if i am giving input as '2', then system is converting as '0.2'.
if i want to get '2.2',then i need to give '22'. so How can i avoid such kind of situation?
Please give suggestion to me.
hi,
check this
*& Report ZDEMO_ALVGRID_EDIT *
*& Example of a simple ALV Grid Report *
*& The basic ALV grid, Enhanced to display specific fields as *
*& editable depending on field value *
REPORT ZDEMO_ALVGRID_EDIT .
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,
field_style TYPE lvc_t_styl, "FOR DISABLE
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.
DATA: it_fieldcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv WITH HEADER LINE,
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.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM set_specific_field_attributes.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
FORM build_fieldcatalog.
wa_fieldcat-fieldname = 'EBELN'.
wa_fieldcat-scrtext_m = 'Purchase Order'.
wa_fieldcat-col_pos = 0.
wa_fieldcat-outputlen = 10.
wa_fieldcat-emphasize = 'X'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'EBELP'.
wa_fieldcat-scrtext_m = 'PO Item'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'STATU'.
wa_fieldcat-scrtext_m = 'Status'.
wa_fieldcat-col_pos = 2.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'AEDAT'.
wa_fieldcat-scrtext_m = 'Item change date'.
wa_fieldcat-col_pos = 3.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-scrtext_m = 'Material Number'.
wa_fieldcat-col_pos = 4.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MENGE'.
wa_fieldcat-scrtext_m = 'PO quantity'.
wa_fieldcat-col_pos = 5.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_m = 'Order Unit'.
wa_fieldcat-col_pos = 6.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'NETPR'.
wa_fieldcat-scrtext_m = 'Net Price'.
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 = 'PEINH'.
wa_fieldcat-scrtext_m = 'Price Unit'.
wa_fieldcat-col_pos = 8.
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
i_callback_user_command = 'USER_COMMAND'
is_layout_lvc = gd_layout
it_fieldcat_lvc = it_fieldcat
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.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE it_ekko.
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 NETPR field/column has been set to editable in the fieldcatalog...
The following code sets it to be disabled(display only) if 'NETPR'
is gt than 10.
LOOP AT it_ekko INTO wa_ekko.
IF wa_ekko-netpr GT 1000.
ls_stylerow-fieldname = 'NETPR' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
"set field to disabled
APPEND ls_stylerow TO wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ENDIF.
ENDLOOP.
endform. " set_specific_field_attributes
regards,
Prabhu
Reward if it is helpful
Similar Messages
-
How to make the field in the output ALV report editable ?
Hi,
I have a requirement to make fields like MATNR,WERKS in the output ALV report editable . Could any of you help me with this ?.
Thank you.
Moderator Message: Search.
Edited by: kishan P on Sep 6, 2010 6:35 PMHi
Please for available information on SCN. There are a lot of information on SCN about ALV wit hEDIT functionality.
Regards
Abhii -
Hi All,
I am developing an ALV report. These are the requirements to meet.
In the output Grid display, I have to add header using ALV_COMMENTARY_WRITE, passing material number, plant, date. And this changes when the material number changes. Is it possible to pass value to ALV_commentary_write from internal table and add separate header when ever the material number changes?
Thanks
RickyHi ricky,
here a short example. with doubleclick of a oututline the header change.
TABLES: MARA.
TYPE-POOLS: SLIS.
DATA: PROGNAME LIKE SY-REPID,
FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
EVENT_EXIT TYPE SLIS_T_EVENT_EXIT,
EVENTS TYPE SLIS_T_EVENT,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
END OF ITAB.
START-OF-SELECTION.
PERFORM EINLESEN.
PERFORM AUSGABE_ALV.
END-OF-SELECTION.
FORM EINLESEN.
SELECT * FROM MARA UP TO 100 ROWS.
ITAB-MATNR = MARA-MATNR.
ITAB-MTART = MARA-MTART.
APPEND ITAB.
ENDSELECT.
CLEAR ITAB.
ENDFORM. "EINLESEN
FORM AUSGABE_ALV.
PROGNAME = SY-REPID.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = PROGNAME
I_INTERNAL_TABNAME = 'ITAB'
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = PROGNAME
CHANGING
CT_FIELDCAT = FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
PERFORM EVENT_EXIT_DEFINIEREN USING EVENT_EXIT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = PROGNAME
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE_GRID'
IT_FIELDCAT = FIELDCAT
I_SAVE = 'A'
IT_EVENTS = EVENTS
TABLES
T_OUTTAB = ITAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. "AUSGABE_ALV
FORM EVENT_EXIT_DEFINIEREN USING EVENT_EXIT TYPE SLIS_T_EVENT_EXIT.
DATA: WA_EVENT_EXIT TYPE SLIS_EVENT_EXIT.
MOVE: '&IC1' TO WA_EVENT_EXIT-UCOMM,
'X' TO WA_EVENT_EXIT-BEFORE.
APPEND WA_EVENT_EXIT TO EVENT_EXIT.
ENDFORM. "EVENT_EXIT_DEFINIEREN
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
READ TABLE ITAB INDEX RS_SELFIELD-TABINDEX.
IF R_UCOMM EQ '&IC1'.
PERFORM TOP_OF_PAGE_GRID.
ENDIF.
ENDFORM. "USER_COMMAND
FORM TOP_OF_PAGE_GRID.
DATA: LS_LINE TYPE SLIS_LISTHEADER.
REFRESH GT_LIST_TOP_OF_PAGE.
CLEAR LS_LINE.
LS_LINE-TYP = 'S'.
LS_LINE-KEY = 'Material'.
WRITE ITAB-MATNR TO LS_LINE-INFO.
APPEND LS_LINE TO GT_LIST_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
ENDFORM. "TOP_OF_PAGE_GRID
Regards, Dieter -
ALV report editable to enter text and print with including the text?
Hi all,
I have to display output of a report in ALV format and i have to make two fileds can be editable to enter texts by user and able to print the list with that texts .
Is it possible using standard Function modules or I have to go for OO methods? Please give the sample code ?
Thanks,
Vamshi
Edited by: VAMSHI KRISHNA on Oct 31, 2008 4:25 PMHi Vamshi,
Check out the Below sample code for the editable ALV.
*& Report Z7CC_OOPS_ALV_EDITABLE
report z7cc_oops_alv_editable.
tables sflight.
data: begin of gt_outtab occurs 0. "with header line
include structure sflight.
data: celltab type lvc_t_styl.
data: end of gt_outtab.
data: gt_fieldcat type lvc_t_fcat.
data: g_carrid like sflight-carrid,
g_connid like sflight-connid.
data: gs_spfli type spfli. "#EC NEEDED
data: g_custom_container type ref to cl_gui_custom_container.
data: g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1'.
data: g_grid type ref to cl_gui_alv_grid.
data: wa_outtab like gt_outtab.
* CLASS lcl_event_receiver DEFINITION
class lcl_event_receiver definition.
public section.
types: begin of sflight_key.
types: carrid type s_carr_id.
types: connid type s_conn_id.
types: fldate type s_date.
types: end of sflight_key.
types: sflight_keys type standard table of sflight_key,
sflight_table type standard table of sflight.
methods:
handle_data_changed
for event data_changed of cl_gui_alv_grid
importing er_data_changed.
methods:
get_inserted_rows
exporting
inserted_rows type sflight_keys.
methods:
get_deleted_rows
exporting
deleted_rows type sflight_table.
methods:
refresh_delta_tables.
methods: set_table_is_initial.
methods: set_table_is_not_initial.
methods: table_is_initial
returning value(initial) type char01.
private section.
* §4.Define internal tables to remember inserted and deleted lines,
* thus the delta between input made after the last saving.
data: inserted_rows type sflight_keys,
deleted_rows type standard table of sflight.
* This flag is set if any error occured in one of the
* following methods:
data: error_in_data type c.
* This flag signals that no records were read for the flight
* table initially:
data: initial_table type c.
** Methods to modularize event handler method HANDLE_DATA_CHANGED:
methods:
check_double_entries
importing
pr_data_changed type ref to cl_alv_changed_data_protocol.
methods:
update_delta_tables
importing
pr_data_changed type ref to cl_alv_changed_data_protocol.
methods:
perform_semantic_checks
importing
pr_data_changed type ref to cl_alv_changed_data_protocol.
methods:
get_cell_values
importing
row_id type int4
pr_data_changed type ref to cl_alv_changed_data_protocol
exporting
key type sflight_key.
endclass. "lcl_event_receiver DEFINITION
class lcl_event_receiver implementation.
method handle_data_changed.
* data: ls_good type lvc_s_modi,
* l_price type s_price,
* ls_new type lvc_s_moce.
* error_in_data = space.
** check if there exist double entries
* call method check_double_entries( er_data_changed ).
** remember new or deleted lines for saving
* call method update_delta_tables( er_data_changed ).
** check mt_good_cells semantically
* call method perform_semantic_checks( er_data_changed ).
* if error_in_data = 'X'.
* call method er_data_changed->display_protocol.
* endif.
endmethod. "handle_data_changed
method check_double_entries.
data: lt_good_cells type lvc_t_modi,
ls_good type lvc_s_modi,
ls_key type sflight_key,
ls_sflight type sflight,
l_flightdate like gt_outtab-fldate,
l_del_row type lvc_s_moce,
ls_outtab like line of gt_outtab,
l_reentered type c.
* §5.Check if there exist already other records with equal key fields.
* Check if the user has entered two new lines where the key fields
* are equal.
* Since CARRID and CONNID are read only, the check is restrained
* to field FLDATE.
* Algorithm: Copy all entries in MT_GOOD_CELLS to a dummy table.
* During the copying procedure check if there exists
* already a line with the same Flight date.
* loop at pr_data_changed->mt_good_cells into ls_good.
* case ls_good-fieldname.
* when 'FLDATE'.
* call method pr_data_changed->get_cell_value
* exporting
* i_row_id = ls_good-row_id
* i_fieldname = ls_good-fieldname
* importing e_value = l_flightdate.
* read table lt_good_cells with key
* value = l_flightdate
* transporting no fields.
* if sy-subrc = 0.
** There exists already a line with the same flight date!
* call method pr_data_changed->add_protocol_entry
* exporting
* i_msgid = '0K' i_msgno = '000' i_msgty = 'E'
* i_msgv1 = text-m01
* i_fieldname = ls_good-fieldname
* i_row_id = ls_good-row_id.
* error_in_data = 'X'.
* else.
* ls_good-value = l_flightdate.
* append ls_good to lt_good_cells.
* endif.
* endcase.
* endloop.
** Check if any new entries already exist in gt_outtab.
** At this point, lt_good_cells contains only lines with
** FIELDNAME = 'FLDATE'.
* loop at lt_good_cells into ls_good.
* l_flightdate = ls_good-value. "flightdate, see above
* read table gt_outtab with key
* carrid = g_carrid
* connid = g_connid
* fldate = l_flightdate
* transporting no fields.
* if sy-subrc = 0.
** Check if this entry was deleted before, i.e. it is in the table
** of deleted rows. If so, the entry does not exist twice. The user
** has deleted a line and then reentered it.
* l_reentered = space.
* loop at pr_data_changed->mt_deleted_rows into l_del_row.
* read table gt_outtab into ls_outtab index l_del_row-row_id.
* if sy-subrc ne 0.
* message i000(0k) with text-e01."Fehler beim Löschen
* elseif
* ls_outtab-carrid eq g_carrid
* and ls_outtab-connid eq g_connid
* and ls_outtab-fldate eq ls_good-value.
* l_reentered = 'X'.
* endif.
* endloop.
* if l_reentered ne 'X'.
* call method pr_data_changed->add_protocol_entry
* exporting
* i_msgid = '0K' i_msgno = '000' i_msgty = 'E'
* i_msgv1 = text-m01
* i_fieldname = ls_good-fieldname
* i_row_id = ls_good-row_id.
* error_in_data = 'X'.
* endif.
* endif.
* endloop.
** In this demo report you may prevent the selection
** of data by setting parameter 'p_ds'.
** If this is done, the next check is required:
* if me->table_is_initial( ) eq 'X'.
* call method get_cell_values
* exporting row_id = 1
* pr_data_changed = pr_data_changed
* importing key = ls_key.
* select single * from sflight into ls_sflight
* where carrid = ls_key-carrid
* and connid = ls_key-connid
* and fldate = ls_key-fldate.
* if sy-subrc = 0.
* call method pr_data_changed->add_protocol_entry
* exporting
* i_msgid = '0K' i_msgno = '000' i_msgty = 'E'
* i_msgv1 = text-m01
* i_fieldname = 'FLDATE'
* i_row_id = 1.
* error_in_data = 'X'.
* endif.
** flag initial_table is reset in method 'update_delta_tables'
* endif.
endmethod. "check_double_entries
method update_delta_tables.
* data: l_ins_row type lvc_s_moce,
* l_del_row type lvc_s_moce,
* ls_key type sflight_key,
* ls_sflight type sflight,
* ls_outtab like line of gt_outtab.
** §6.Use protocol attributes MT_DELETED_ROWS and MT_INSERTED_ROWS
** to remember which lines where deleted or inserted. Save this
** information in your internal tables.
** deleted rows
* loop at pr_data_changed->mt_deleted_rows into l_del_row.
* read table gt_outtab into ls_outtab index l_del_row-row_id.
* if sy-subrc ne 0.
* message i000(0k) with text-e01."Fehler beim Löschen
* else.
* move-corresponding ls_outtab to ls_sflight.
** It should no be possible that the same line is deleted twice,
** so we just add the new key line to 'deleted_rows'.
* append ls_sflight to deleted_rows.
** If this line was inserted just before it is deleted:
* delete me->inserted_rows
* where carrid = ls_outtab-carrid
* and connid = ls_outtab-connid
* and fldate = ls_outtab-fldate.
* endif.
* endloop.
** inserted rows
** At this point ALV has not added new lines
** to gt_outtab, so you can not access their values
** by reading gt_outtab.
** Table MT_GOOD_CELLS holds new values that can be
** referenced using the ROW_ID.
* if me->table_is_initial( ) eq 'X'.
** No flights were selected initially. This is the first new line.
* call method get_cell_values
* exporting row_id = 1
* pr_data_changed = pr_data_changed
* importing key = ls_key.
* append ls_key to inserted_rows.
* call method me->set_table_is_not_initial.
* endif.
* loop at pr_data_changed->mt_inserted_rows into l_ins_row.
* call method get_cell_values
* exporting row_id = l_ins_row-row_id
* pr_data_changed = pr_data_changed
* importing key = ls_key.
** READ TABLE gt_outtab INTO ls_outtab INDEX l_ins_row-row_id.
** Just insert the new row regardless if the input is wrong
* append ls_key to inserted_rows.
* endloop.
endmethod. "update_delta_tables
method get_cell_values.
* get values of key cells of row ROW_ID
** CARRIER
* call method pr_data_changed->get_cell_value
* exporting
* i_row_id = row_id
* i_fieldname = 'CARRID'
* importing
* e_value = key-carrid.
* if sy-subrc ne 0.
* message i000(0k) with text-e02. "Fehler beim Einfügen
* endif.
** CONNID
* call method pr_data_changed->get_cell_value
* exporting
* i_row_id = row_id
* i_fieldname = 'CONNID'
* importing
* e_value = key-connid.
* if sy-subrc ne 0.
* message i000(0k) with text-e02. "Fehler beim Einfügen
* endif.
** FLDATE
* call method pr_data_changed->get_cell_value
* exporting
* i_row_id = row_id
* i_fieldname = 'FLDATE'
* importing
* e_value = key-fldate.
* if sy-subrc ne 0.
* message i000(0k) with text-e02. "Fehler beim Einfügen
* endif.
endmethod. "get_cell_values
method perform_semantic_checks.
* data: ls_good type lvc_s_modi,
* l_planetype type s_planetye,
* l_seatsmax type s_seatsmax.
* loop at pr_data_changed->mt_good_cells into ls_good.
* case ls_good-fieldname.
* when 'PLANETYPE'.
* call method pr_data_changed->get_cell_value
* exporting
* i_row_id = ls_good-row_id
* i_fieldname = ls_good-fieldname
* importing
* e_value = l_planetype.
* select single seatsmax from saplane into l_seatsmax
* where planetype = l_planetype.
* if sy-subrc ne 0.
* call method pr_data_changed->add_protocol_entry
* exporting
* i_msgid = '0K' i_msgno = '000' i_msgty = 'E'
* i_msgv1 = text-m02
* i_fieldname = ls_good-fieldname
* i_row_id = ls_good-row_id.
* error_in_data = 'X'.
* else.
* call method pr_data_changed->modify_cell
* exporting i_row_id = ls_good-row_id
* i_fieldname = 'SEATSMAX'
* i_value = l_seatsmax.
* endif.
* endcase.
* endloop.
endmethod. "perform_semantic_checks
method get_inserted_rows.
* inserted_rows = me->inserted_rows.
endmethod. "get_inserted_rows
method get_deleted_rows.
* deleted_rows = me->deleted_rows.
endmethod. "get_deleted_rows
method refresh_delta_tables.
* clear me->inserted_rows[].
* clear me->deleted_rows[].
endmethod. "refresh_delta_tables
method set_table_is_initial.
* initial_table = 'X'.
endmethod. "set_table_is_initial
method set_table_is_not_initial.
* initial_table = space.
endmethod. "set_table_is_not_initial
method table_is_initial.
* if initial_table = 'X'.
* initial = 'X'.
* else.
* initial = space.
* endif.
endmethod. "table_is_initial
endclass. "lcl_event_receiver IMPLEMENTATION
data: g_verifier type ref to lcl_event_receiver.
data: g_max type i value 100.
data: gs_layout type lvc_s_layo.
data: ok_code like sy-ucomm,
save_ok like sy-ucomm.
parameters: p_ds type c as checkbox. "delete selection
select-options s_carrid for sflight-carrid
no intervals no-extension default 'LH'.
select-options s_connid for sflight-connid
no intervals no-extension default '0400'.
start-of-selection.
g_carrid = s_carrid-low.
g_connid = s_connid-low.
* first check airline and connection
select single * from spfli into gs_spfli
where carrid = g_carrid
and connid = g_connid.
call screen 100.
*& Module STATUS_0100 OUTPUT
* text
module status_0100 output.
set pf-status 'MAIN100'.
set titlebar 'MAIN100'.
if g_custom_container is initial.
perform create_and_init_alv changing gt_outtab[]
gt_fieldcat.
endif.
endmodule. " STATUS_0100 OUTPUT
*& Form create_and_init_alv
* text
* <--P_GT_OUTTAB[] text
* <--P_GT_FIELDCAT text
form create_and_init_alv changing pt_outtab like gt_outtab[]
pt_fieldcat type lvc_t_fcat.
data: lt_exclude type ui_functions.
create object g_custom_container
exporting container_name = g_container.
create object g_grid
exporting i_parent = g_custom_container.
* Create Objekt to verify input values.
* (This object is already needed in form SELECT_DATA).
create object g_verifier.
* SET HANDLER g_verifier->handle_data_changed FOR g_grid.
perform select_data changing pt_outtab[].
perform build_fieldcat changing pt_fieldcat.
perform exclude_tb_functions changing lt_exclude.
gs_layout-stylefname = 'CELLTAB'.
call method g_grid->set_table_for_first_display
exporting
it_toolbar_excluding = lt_exclude
is_layout = gs_layout
changing
it_fieldcatalog = pt_fieldcat
it_outtab = pt_outtab[].
* Set editable cells to ready for input initially
call method g_grid->set_ready_for_input
exporting
i_ready_for_input = 1.
endform. " create_and_init_alv
*& Form select_data
* text
* <--P_GT_OUTTAB text
form select_data changing pt_outtab like gt_outtab[].
data: lt_sflight type table of sflight,
ls_sflight type sflight,
ls_outtab like line of gt_outtab,
l_index type i,
ls_spfli type spfli, "#EC NEEDED
lt_celltab type lvc_t_styl.
* Check parameter 'p_ds'=>optionally select no data
if p_ds is initial.
* Select data from sflight
select * from sflight into table lt_sflight up to g_max rows
where carrid = g_carrid
and connid = g_connid.
endif.
if sy-subrc ne 0 or not p_ds is initial.
* no flights were found!
* We provide some default values for the first line that is entered:
ls_outtab-carrid = g_carrid.
ls_outtab-connid = g_connid.
case g_carrid.
when 'LH'.
ls_outtab-currency = 'DEM'.
when others.
ls_outtab-currency = 'US'.
endcase.
ls_outtab-seatsocc = 0.
ls_outtab-paymentsum = 0.
* set fields FLDATE, PRICE and PLANETYPE to editable
perform fill_celltab using 'RW'
changing lt_celltab.
insert lines of lt_celltab into table ls_outtab-celltab.
append ls_outtab to pt_outtab.
* Tell Verify-Objekt that the table was initial
call method g_verifier->set_table_is_initial.
else.
call method g_verifier->set_table_is_not_initial.
* move corresponding fields from lt_sflight to gt_outtab
loop at lt_sflight into ls_sflight.
move-corresponding ls_sflight to ls_outtab.
append ls_outtab to pt_outtab.
endloop.
* §3.Set all cells of the table non-editable by using the style table.
loop at pt_outtab into ls_outtab.
l_index = sy-tabix.
refresh lt_celltab.
perform fill_celltab using 'RO'
changing lt_celltab.
* Copy your celltab to the celltab of the current row of gt_outtab.
insert lines of lt_celltab into table ls_outtab-celltab.
modify pt_outtab from ls_outtab index l_index.
endloop.
endif.
endform. " select_data
*& Form fill_celltab
* text
* -->VALUE(P_MODE) text
* -->PT_CELLTAB text
form fill_celltab using value(p_mode)
changing pt_celltab type lvc_t_styl.
data: ls_celltab type lvc_s_styl,
l_mode type raw4.
* This forms sets the style of columns 'PRICE', FLDATE and PLANETYPE
* editable
if p_mode eq 'RW'.
l_mode = cl_gui_alv_grid=>mc_style_enabled.
else. "p_mode eq 'RO'
l_mode = cl_gui_alv_grid=>mc_style_disabled.
endif.
ls_celltab-fieldname = 'FLDATE'.
ls_celltab-style = l_mode.
insert ls_celltab into table pt_celltab.
ls_celltab-fieldname = 'PRICE'.
ls_celltab-style = l_mode.
insert ls_celltab into table pt_celltab.
ls_celltab-fieldname = 'PLANETYPE'.
ls_celltab-style = l_mode.
insert ls_celltab into table pt_celltab.
endform. " FILL_CELLTAB
*& Form BUILD_FIELDCAT
* text
* <--P_GT_FIELDCAT text
form build_fieldcat changing pt_fieldcat type lvc_t_fcat.
data ls_fcat type lvc_s_fcat.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'SFLIGHT'
changing
ct_fieldcat = pt_fieldcat.
loop at pt_fieldcat into ls_fcat.
if ls_fcat-fieldname eq 'PRICE'
or ls_fcat-fieldname eq 'PLANETYPE'
or ls_fcat-fieldname eq 'FLDATE'.
* §1.Set status of columns FLDATA, PRICE and PLANETYPE to editable.
* Since all cells are set to non-editable (see step 3) the cells
* of this columns will only be editable for new lines.
ls_fcat-edit = 'X'.
* Field 'checktable' is set to avoid shortdumps that are caused
* by inconsistend data in check tables. You may comment this out
* when the test data of the flight model is consistent in your system.
ls_fcat-checktable = '!'. "do not check foreign keys
modify pt_fieldcat from ls_fcat.
elseif ls_fcat-fieldname = 'CARRID'
or ls_fcat-fieldname = 'CONNID'
or ls_fcat-fieldname = 'CURRENCY'.
* §2.Use field AUTO_VALUE of the fieldcatalog to preset values when new
* lines are added.
ls_fcat-auto_value = 'X'.
ls_fcat-checktable = '!'. "do not check foreign key relations
modify pt_fieldcat from ls_fcat.
endif.
endloop.
endform. "build_fieldcat
*& Form exclude_tb_functions
* text
* <--P_LT_EXCLUDE text
form exclude_tb_functions changing pt_exclude type ui_functions.
data ls_exclude type ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
append ls_exclude to pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
append ls_exclude to pt_exclude.
endform. " EXCLUDE_TB_FUNCTIONS
*& Module USER_COMMAND_0100 INPUT
* text
module user_command_0100 input.
save_ok = sy-ucomm.
clear ok_code.
case save_ok.
when 'SAVE'.
* perform save_data.
when 'BACK'.
* §10.Unlock your database table.
* perform unlock_sflight.
leave to screen 0.
when 'EXIT'.
perform exit_program.
when 'ADD'.
perform add_line_item.
when others.
* do nothing
endcase.
endmodule. " USER_COMMAND_0100 INPUT
* FORM EXIT_PROGRAM *
form exit_program.
leave program.
endform. "exit_program
*& Form ADD_LINE_ITEM
* text
* --> p1 text
* <-- p2 text
form add_line_item .
data: lt_rows type lvc_t_row.
data: wa_rows type lvc_t_row with header line.
data: tabix type sy-tabix.
*&Find the row ( index ) number
call method g_grid->get_selected_rows
importing et_index_rows = lt_rows.
call method cl_gui_cfw=>flush.
read table lt_rows into wa_rows index 1.
tabix = wa_rows-index .
insert gt_outtab index tabix.
*REFRESH_TABLE_DISPLAY
call method g_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.
endform. " ADD_LINE_ITEM
Thanks,
Chidanand -
hi experts,
I have an executable program which displays alv output, my requirement is after the output is displayed in ultilities tab(drop down) we have saving option which is generally disabled.
how to make this enabled?
regards,
jayantI guess you are talking about saving variants, aren't you?
For this you should use
data: ls_variant type disvariant.
ls_variant-report = sy-repid.
l_variant-variant = 'SOME_SAVED_VARIANT'.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
i_save = 'A' "this will enable save option
is_variant = ls_variant "this will set default variant in layout
Regards
Marcin -
Narrative Report-Edit Option?
Hi
Is there any option to edit once the narrative report generated through weblink.?
(i.e we have rdf for refresh,download,print,similarly any way to edit the report content)
regards
sowmHi
Is there any option to edit once the narrative report generated through weblink.?
(i.e we have rdf for refresh,download,print,similarly any way to edit the report content)
regards
sowm -
hi
could u plz tell me how to edit the values of the alv grid display
could u plz explain clearly with codeHi,
Check this Program .
data: ok_code like sy-ucomm,
save_ok like sy-ucomm,
g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
g_grid type ref to cl_gui_alv_grid,
g_custom_container type ref to cl_gui_custom_container,
gs_layout type lvc_s_layo,
g_max type i value 100.
data: gt_outtab type table of sflight.
MAIN *
call screen 100 starting at 1 1..
MODULE PBO OUTPUT *
module pbo output.
set pf-status 'MAIN100'.
set titlebar 'MAIN100'.
if g_custom_container is initial.
create object g_custom_container
exporting container_name = g_container.
create object g_grid
exporting i_parent = g_custom_container.
*§1.Set status of all cells to editable using the layout structure.
gs_layout-edit = 'X'.
select * from sflight into table gt_outtab up to g_max rows.
call method g_grid->set_table_for_first_display
exporting i_structure_name = 'SFLIGHT'
is_layout = gs_layout
changing it_outtab = gt_outtab.
*§2.Use SET_READY_FOR_INPUT to allow editing initially.
(state "editable and ready for input").
call method g_grid->set_ready_for_input
exporting i_ready_for_input = 1.
endif.
endmodule.
MODULE PAI INPUT *
module pai input.
save_ok = ok_code.
clear ok_code.
case save_ok.
when 'EXIT'.
perform exit_program.
when 'SWITCH'.
perform switch_edit_mode.
when others.
do nothing
endcase.
endmodule.
FORM EXIT_PROGRAM *
form exit_program.
leave program.
endform.
*& Form SWITCH_EDIT_MODE
text
--> p1 text
<-- p2 text
form switch_edit_mode.
*§3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
if g_grid->is_ready_for_input( ) eq 0.
*§4.Use SET_READY_FOR_INPUT to switch between the substates.
call method g_grid->set_ready_for_input
exporting i_ready_for_input = 1.
else.
call method g_grid->set_ready_for_input
exporting i_ready_for_input = 0.
endif.
endform. " SWITCH_EDIT_MODE
For more information check the standard programs :BCALV_EDIT_*
reward if it helps..
Regards,
Omkar. -
Hi Experts,
I want to show comments (which I give from program) in
ALV grid display.
It's like an excel,if put comment on one cell,then if we right click, we can see the comment details.
the same property,I need in ALV cell also.
Kindly help me.
Regards,
Chitu.No,I want to display my own comments.
Yes, I know when we right click, we will get details options.
but it is not use ful for me.
thanks in advance. -
Hi Expart ,
Ex: In ALV O/P having check box field have 10 row . I want editable perticular row in o/p list . how can i create .
Please tell me or give me one Example .
Regards
BhabaniHi Sankardey,
You can make use of method MC_STYLE_ENABLED of class CL_GUI_ALV_GRID to achieve this.
Please refer below code snippet for your reference :-
FIELD-SYMBOLS : <fs_fieldcat> TYPE lvc_s_fcat.
LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>.
CASE <fs_fieldcat>-fieldname.
WHEN 'ERNAM'.
* Making a column as Editable
<fs_fieldcat>-edit = 'X'.
ENDCASE.
ENDLOOP.
* Making a particular cell as non-editable and other editable
CLEAR w_style.
w_style-fieldname = 'ERNAM'.
w_style-style = cl_gui_alv_grid=>mc_style_enabled.
REFRESH wa-cellstyles.
APPEND w_style TO wa-cellstyles.
MODIFY itab FROM wa INDEX 3 TRANSPORTING cellstyles.
Kindly set to resolved if it helps you.
Regards
Abhii -
List- Export- Spreadsheet option disabled in ALV Report
Hi,
In one of the ALV Report the option List->Export->Spreadsheet option is disabled. How to enable that option?
I am calling the REUSE_ALV_GRID_DISPLAY Function module with the following parameters
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid
it_fieldcat = i_fieldtab[]
is_layout = ls_layout
it_events = i_events[]
i_save = 'A'
is_variant = i_variant
TABLES
t_outtab = it_display
EXCEPTIONS
program_error = 1
OTHERS = 2.
This is the problem with only this report. So I believe it is not due to authorization.
Regards,
AnushaHi Anusha,
This link should help you. You just need to change the deep structure.
[Export Option is Grayed out in ALV Grid Display;
You already figured it out
Edited by: sap_wiz on Jul 6, 2011 4:42 PM -
Print or download ALV report with sort options
Dear friends,
How i can download into excel or print ALV report with sort options, like customer name column with similar values should not repeat in the print out or download file.
Regards,
Praveen LoboHi Praveen,
Use this code, its working:-
*FOR SORTING DATA
DATA : it_sort TYPE slis_t_sortinfo_alv,
wa_sort TYPE slis_sortinfo_alv.
* SORT W.R.T. CUSTOMER NAME
wa_sort-spos = 1.
wa_sort-fieldname = 'NAME1'. "field customer name
wa_sort-tabname = 'IT_KNA1'. "internal table with records
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
CLEAR wa_sort.
"this will sort the ALV o/p for customer with same name
"now the name will not be repeated
"records with same name will be grouped
* DISPLAY RECORDS IN ALV GRID
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid "report id
it_fieldcat = it_field "field catalog
it_sort = it_sort "sort info
TABLES
t_outtab = it_kna1 "internal table
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
Hope this solves your problem.
Thanks & Regards,
Tarun Gambhir
Edited by: Tarun Gambhir on Dec 31, 2008 1:13 PM -
In ALV Reports, i want to edit records manually in out put display
hello all,
in ALV Reports, i want to edit records manually in out put display. how can i do that?*& Report ZTEST1
REPORT ztest1.
TYPE-POOLS: slis.
DATA:i_sbook TYPE STANDARD TABLE OF sbook INITIAL SIZE 0,
i_sbook1 TYPE STANDARD TABLE OF sbook INITIAL SIZE 0,
i_fieldcatalog TYPE slis_t_fieldcat_alv,
wa_fieldcatalog LIKE LINE OF i_fieldcatalog,
wa_sbook TYPE sbook.
DATA:wa_layout TYPE slis_layout_alv.
SELECT-OPTIONS:
s_carrid FOR wa_sbook-carrid.
AT SELECTION-SCREEN.
IF s_carrid IS NOT INITIAL.
SELECT COUNT( * )
FROM scarr WHERE carrid IN s_carrid.
IF sy-subrc <> 0.
MESSAGE e000(ztest) WITH 'Invalid Airline Code'.
ENDIF.
ENDIF.
START-OF-SELECTION.
SELECT *
FROM sbook
INTO TABLE i_sbook
UP TO 50 ROWS
WHERE carrid IN s_carrid.
CHECK sy-subrc = 0.
i_sbook1[] = i_sbook[].
DATA: l_repid TYPE syrepid VALUE sy-repid.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = l_repid
i_internal_tabname = 'I_SBOOK'
i_structure_name = 'SBOOK'
i_client_never_display = 'X'
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = i_fieldcatalog
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.
LOOP AT i_fieldcatalog INTO wa_fieldcatalog.
IF wa_fieldcatalog-fieldname = 'SMOKER'.
wa_fieldcatalog-edit = 'X'. " REUSE_ALV_GRID_DISPLAY
* wa_fieldcatalog-input = 'X'. " REUSE_ALV_LIST_DISPLAY
ENDIF.
MODIFY i_fieldcatalog FROM wa_fieldcatalog TRANSPORTING edit input.
ENDLOOP.
wa_layout-window_titlebar = 'My Title'.
wa_layout-zebra = 'X'.
wa_layout-colwidth_optimize = 'X'.
DATA repid TYPE syrepid VALUE sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = repid
i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_user_command = 'SUB_USER_COMMAND'
is_layout = wa_layout
it_fieldcat = i_fieldcatalog
TABLES
t_outtab = i_sbook
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.
*& Form sub_user_command
* text
* -->R_UCOMM text
* -->RS_SELFIELD text
FORM sub_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'. "Double click
IF i_sbook1[] NE i_sbook[].
MESSAGE i001(00) WITH 'Hmm...some data changed'.
ENDIF.
ENDCASE.
ENDFORM. "sub_user_command
*& Form set_pf_status
* text
* -->RT_EXTAB text
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZSTANDARD'.
ENDFORM. "set_pf_status -
How to edit ALV report using function modules
I have a ALV report , i want to edit the report
using function modules.
how can i do that...
Edited by: ms kumar on Mar 6, 2008 3:24 PMhi i had used this report with the check box,
using the fm of alvs.....
*& Report ZZZ00
REPORT ZPR_02.
TYPE-POOLS: SLIS.
TABLES:pa0002,pa0008.
data:begin of it_pa0002 occurs 0,
checkbox,
pernr like pa0002-pernr,
begda like pa0002-begda,
endda like pa0002-endda,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
end of it_pa0002.
data:begin of it_pa00021 occurs 0,
pernr like pa0002-pernr,
begda like pa0002-begda,
endda like pa0002-endda,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
expand TYPE xfeld value 'X',
end of it_pa00021.
data:begin of it_pa0008 occurs 0,
pernr like pa0008-pernr,
begda like pa0008-begda,
endda like pa0008-endda,
ANSAL like pa0008-ANSAL,
LGA01 like pa0008-LGA01,
BET01 LIKE PA0008-BET01,
end of it_pa0008.
DATA: IT_FIELD_CAT TYPE SLIS_T_FIELDCAT_ALV,
IT_FIELD_CAT1 TYPE SLIS_T_FIELDCAT_ALV,
IT_LAYOUT1 TYPE SLIS_LAYOUT_ALV,
WA_FIELD_CAT TYPE SLIS_FIELDCAT_ALV,
WA_FIELD_CAT1 TYPE SLIS_FIELDCAT_ALV,
IT_LAYOUT TYPE SLIS_LAYOUT_ALV,
IT_EVENTS TYPE SLIS_T_EVENT,
WA_EVENTS TYPE SLIS_ALV_EVENT,
IT_HEADER TYPE SLIS_T_LISTHEADER,
WA_HEADER TYPE SLIS_LISTHEADER,
wa_keyinfo TYPE slis_keyinfo_alv.
CONSTANTS:c VALUE 'X'.
SELECT-OPTIONS: S_pernr FOR pa0002-pernr.
START-OF-SELECTION.
SET PF-STATUS 'DATA' .
PERFORM GET_DATA.
PERFORM BUILD_FIELD_CAT.
PERFORM GET_EVENTS.
PERFORM DISPLAY_DATA.
*& Form get_data
text
FORM GET_DATA .
SELECT pernr
begda
endda
vorna
nachn
FROM pa0002
INTO CORRESPONDING FIELDS OF TABLE IT_pa0002
WHERE pernr IN S_pernr.
ENDFORM. " get_data
*& Form build_field_cat
text
FORM BUILD_FIELD_CAT .
wa_field_cat-tabname = 'PA0002'.
WA_FIELD_CAT-FIELDNAME = 'CHECKBOX'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
WA_FIELD_CAT-REPTEXT_DDIC = 'Check Box'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
CLEAR WA_FIELD_CAT.
wa_field_cat-tabname = 'PA0002'.
WA_FIELD_CAT-FIELDNAME = 'PERNR'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
WA_FIELD_CAT-REPTEXT_DDIC = 'Personnel no'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
CLEAR WA_FIELD_CAT.
wa_field_cat-tabname = 'PA0002'.
WA_FIELD_CAT-FIELDNAME = 'BEGDA'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
WA_FIELD_CAT-REPTEXT_DDIC = 'Start date'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
CLEAR WA_FIELD_CAT.
wa_field_cat-tabname = 'PA0002'.
WA_FIELD_CAT-FIELDNAME = 'ENDDA'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
WA_FIELD_CAT-REPTEXT_DDIC = 'End date'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
CLEAR WA_FIELD_CAT.
wa_field_cat-tabname = 'PA0002'.
WA_FIELD_CAT-FIELDNAME = 'VORNA'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
WA_FIELD_CAT-REPTEXT_DDIC = 'First name'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
CLEAR WA_FIELD_CAT.
wa_field_cat-tabname = 'PA0002'.
WA_FIELD_CAT-FIELDNAME = 'NACHN'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
WA_FIELD_CAT-REPTEXT_DDIC = 'Last name'.
APPEND WA_FIELD_CAT TO IT_FIELD_CAT.
CLEAR WA_FIELD_CAT.
wa_field_cat1-tabname = 'PA0002'.
WA_FIELD_CAT1-FIELDNAME = 'PERNR'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
WA_FIELD_CAT1-REPTEXT_DDIC = 'Personnel no'.
APPEND WA_FIELD_CAT1 TO IT_FIELD_CAT1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0002'.
WA_FIELD_CAT1-FIELDNAME = 'BEGDA'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
WA_FIELD_CAT1-REPTEXT_DDIC = 'Start date'.
APPEND WA_FIELD_CAT1 TO IT_FIELD_CAT1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0002'.
WA_FIELD_CAT1-FIELDNAME = 'ENDDA'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
WA_FIELD_CAT1-REPTEXT_DDIC = 'End date'.
APPEND WA_FIELD_CAT1 TO IT_FIELD_CAT1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0002'.
WA_FIELD_CAT1-FIELDNAME = 'VORNA'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
WA_FIELD_CAT1-REPTEXT_DDIC = 'First name'.
APPEND WA_FIELD_CAT1 TO IT_FIELD_CAT1.
CLEAR WA_FIELD_CAT.
wa_field_cat1-tabname = 'PA0002'.
WA_FIELD_CAT1-FIELDNAME = 'NACHN'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
WA_FIELD_CAT1-REPTEXT_DDIC = 'Last name'.
APPEND WA_FIELD_CAT1 TO IT_FIELD_CAT1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'PERNR'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-REPTEXT_DDIC = 'personnelno'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'BEGDA'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-REPTEXT_DDIC = 'begindate'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'ENDDA'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-REPTEXT_DDIC = 'enddate'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'ANSAL'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-REPTEXT_DDIC = 'annualsalary'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'LGA01'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-REPTEXT_DDIC = 'wagetype'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR WA_FIELD_CAT1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'BET01'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-REPTEXT_DDIC = 'Amount'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR WA_FIELD_CAT1.
ENDFORM. " build_field_cat
*& Form display_data
text
FORM DISPLAY_DATA .
it_layout-box_fieldname = 'CHECKBOX'.
it_layout-EDIT = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = IT_FIELD_CAT
IS_LAYOUT = IT_LAYOUT
IT_EVENTS = IT_EVENTS
TABLES
T_OUTTAB = IT_pa0002.
ENDFORM. " display_data
*& Form get_events
text
FORM GET_EVENTS .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
ET_EVENTS = IT_EVENTS .
READ TABLE IT_EVENTS INTO WA_EVENTS
WITH KEY NAME = SLIS_EV_TOP_OF_PAGE.
IF SY-SUBRC = 0.
WA_EVENTS-FORM = 'TOP_OF_PAGE'.
MODIFY IT_EVENTS FROM WA_EVENTS INDEX SY-TABIX.
ENDIF.
ENDFORM. " get_events
*& Form top_of_page
text
FORM TOP_OF_PAGE.
WA_HEADER-TYP = 'H'.
WA_HEADER-INFO = 'EMPLOYEE DATA'.
APPEND WA_HEADER TO IT_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_HEADER
ENDFORM. "top_of_page
*& Form GUI_SET
FORM GUI_SET USING RT_EXTAB TYPE SLIS_T_EXTAB .
SET PF-STATUS 'DATA' .
ENDFORM. "GUI_SET
*& Form USER_COMMAND
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
R_SELFIELD TYPE SLIS_SELFIELD.
DATA:V_PERNR LIKE PA0002-PERNR.
CASE R_UCOMM.
WHEN 'DET'.
DATA: V_FLAG.
clear : v_flag.
LOOP AT IT_PA0002.
if it_PA0002-checkbox = 'X'.
v_flag = 'X'.
v_pernr = IT_PA0002-PERNR.
SELECT PERNR
BEGDA
ENDDA
VORNA
NACHN
FROM PA0002
INTO CORRESPONDING FIELDS OF TABLE IT_PA00021
WHERE PERNR = V_PERNR.
SORT IT_PA00021 BY PERNR.
DELETE ADJACENT DUPLICATES FROM IT_PA00021 COMPARING PERNR.
READ TABLE IT_PA00021 INDEX 1.
SELECT PERNR
BEGDA
ENDDA
ANSAL
LGA01
BET01
FROM PA0008
INTO TABLE IT_PA0008
FOR ALL ENTRIES IN IT_PA00021
WHERE PERNR = IT_PA00021-PERNR.
if not it_PA0008[] Is initial.
SORT IT_PA0008 BY PERNR.
delete adjacent duplicates from it_PA0008 comparing pernr.
READ TABLE IT_PA0008 INDEX 1.
endif.
endif.
enddo.
it_layout1-group_change_edit = c.
it_layout1-colwidth_optimize = c.
it_layout1-zebra = c.
it_layout1-detail_popup = c.
it_layout1-get_selinfos = c.
it_layout-expand_fieldname = 'EXPAND'.
wa_keyinfo-header01 = 'PERNR'.
wa_keyinfo-item01 = 'PERNR'.
IF NOT V_FLAG IS INITIAL.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = IT_LAYOUT1
IT_FIELDCAT = IT_FIELD_CAT1
I_TABNAME_HEADER = 'PA0002'
I_TABNAME_ITEM = 'PA0008'
IS_KEYINFO = wa_keyinfo
TABLES
T_OUTTAB_HEADER = IT_PA00021
T_OUTTAB_ITEM = IT_PA0008.
ENDIF.
CLEAR: IT_PA00021,IT_PA0002,IT_PA0008.
ENDLOOP.
WHEN 'BACK'.
EXIT.
ENDCASE.
ENDFORM. "USER_COMMAND
reward points if useful,
venkat. -
Doubt regarding editable ALV report using Classes
I need to create an ALV report and make few fields editable
and i need to update the changes to the corresponding database tables
for that please suggest me some idea or provide me sample code for that
urgentHi ramesh,
Please check this example program. I think it will help for some extent.
[code]&----
*& Report ZSUMA_INTERACTIVEREPORT *
report zsuma_interactivereport.
tables: vbak.
data :gr_alvgrid type ref to cl_gui_alv_grid,
gr_cc_name type scrfname value 'CC_ALV',
gr_ccontainer type ref to cl_gui_custom_container,
gr_fieldcat type lvc_t_fcat,
gr_layout type lvc_s_layo,
gr_sort type lvc_t_sort,
gr_get_cell type lvc_t_cell,
gr_set_cell type lvc_t_cell,
gr_hyper type lvc_t_hype,
gr_drop_down type lvc_t_drop,
is_variant type disvariant,
line_number type lvc_s_roid-row_id,
line(5) type c ,
cell_value type lvc_value.
data: begin of it_vbak occurs 0,
vbeln type vbak-vbeln,
erdat like vbak-erdat,
erzet like vbak-erzet,
netwr like vbak-netwr,
waerk like vbak-waerk,
*Below field is useful for making the entire row with different colors.
it must be a char of 4.and layout-info_fname should populate with
*this field.
rowcolor(4) type c,
*Below field is useful for making the INDIVIDUAL CELL with different
*colors.for this we have to include structure of type lvc_t_scol.
*layout-ctab_fname should be populate with this field.
cellcolor type lvc_t_scol,
*below field is added for for providing the hyperlinks to perticular
*field. at the time of field catalog , it_fcatalog-web_field should be
*populate with this field.
vbeln_hyper type int4,
*For displaying one cell as button.we have to declare one styles
*internal table .it has to be populate.at layout structure this table
*name has to be populate at layout-stylename.
cellstyle type lvc_t_styl,
end of it_vbak.
*& SELECTION SCREEN
selection-screen begin of block b1 with frame title text-001.
select-options s_vbeln for vbak-vbeln.
selection-screen end of block b1.
start-of-selection.
select vbeln
erdat
erzet
netwr
waerk
from vbak
into corresponding fields of table it_vbak
where vbeln in s_vbeln.
data: wa_cellcolor type lvc_s_scol,
wa_style type lvc_s_styl.
loop at it_vbak.
FOR ROW COLORING
if sy-tabix = 1.
it_vbak-rowcolor = 'C511'.
FOR PUTTING THE HYPERLINKS ON VBELN FIELD
it_vbak-vbeln_hyper = '1'.
modify it_vbak.
endif.
FOR CELL COLORING
if sy-tabix = 2.
wa_cellcolor-fname = 'ERZET'.
wa_cellcolor-color-col = '6'.
wa_cellcolor-color-int = '1'.
wa_cellcolor-color-inv = '1'.
append wa_cellcolor to it_vbak-cellcolor.
modify it_vbak index 2.
endif.
FOR DISPLAYING THE CELL AS A BUTTON
clear it_vbak-cellstyle.
at last.
read table it_vbak index sy-tabix.
wa_style-fieldname = 'NETWR'.
wa_style-style = cl_gui_alv_grid=>mc_style_button.
append wa_style to it_vbak-cellstyle .
modify it_vbak .
endat.
endloop.
if not it_vbak[] is initial.
call screen 100.
endif.
*CLASS DEFINITION FOR HANDLING THE EVENTS IN ALV GRID
class gr_event_handler definition.
public section.
methods:handle_hotspot_click
for event hotspot_click of cl_gui_alv_grid
importing e_row_id e_column_id es_row_no.
endclass.
*CLASS IMPLEMENTATIONFOR HANDLING THE EVENTS IN ALV GRID
class gr_event_handler implementation.
method handle_hotspot_click.
perform handle_hotspot_click using e_row_id e_column_id es_row_no.
endmethod.
endclass.
*& Form BUILDING_FIELDCATALOG
text
<--P_GR_FIELDCAT text
form building_fieldcatalog changing p_gr_fieldcat type lvc_t_fcat.
data s_fieldcat type lvc_s_fcat.
s_fieldcat-fieldname = 'VBELN'.
s_fieldcat-outputlen = '15'.
s_fieldcat-col_pos = '1'.
s_fieldcat-coltext = 'DOCCUMENT NO.'.
s_fieldcat-key = ' '.
s_fieldcat-emphasize = 'C511'.
s_fieldcat-web_field = 'VBELN_HYPER'.
append s_fieldcat to p_gr_fieldcat .
clear s_fieldcat.
s_fieldcat-fieldname = 'ERDAT'.
s_fieldcat-outputlen = '15'.
s_fieldcat-col_pos = '2'.
s_fieldcat-coltext = 'REC CREATE DATE.'.
s_fieldcat-emphasize = 'C311'.
s_fieldcat-hotspot = 'X'.
append s_fieldcat to p_gr_fieldcat .
clear s_fieldcat.
s_fieldcat-fieldname = 'ERZET'.
s_fieldcat-outputlen = '15'.
s_fieldcat-col_pos = '3'.
s_fieldcat-coltext = 'TIME ENTRY.'.
*S_FIELDCAT-EMPHASIZE = 'C311'.
append s_fieldcat to p_gr_fieldcat .
clear s_fieldcat.
s_fieldcat-fieldname = 'NETWR'.
s_fieldcat-outputlen = '15'.
s_fieldcat-col_pos = '4'.
s_fieldcat-emphasize = 'C311'.
s_fieldcat-coltext = 'NET WEIGHT.'.
s_fieldcat-do_sum = 'X'.
append s_fieldcat to p_gr_fieldcat .
clear s_fieldcat.
s_fieldcat-fieldname = 'WAERK'.
s_fieldcat-outputlen = '5'.
s_fieldcat-col_pos = '5'.
s_fieldcat-emphasize = 'C511'.
s_fieldcat-coltext = 'CURR.'.
FOR PUTTING THE DROP DOWN BOX.
s_fieldcat-drdn_hndl = '1'.
s_fieldcat-edit = 'X'.
append s_fieldcat to p_gr_fieldcat .
clear s_fieldcat.
endform. " BUILDING_FIELDCATALOG
*& Form CREATE_CCONTAINER_INSTANCE
text
--> p1 text
<-- p2 text
form create_ccontainer_instance .
create object gr_ccontainer
exporting
container_name = gr_cc_name
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
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.
endform. " CREATE_CCONTAINER_INSTANCE
*& Form CREATE_ALVGRID_INSTANCE
text
--> p1 text
<-- p2 text
form create_alvgrid_instance .
create object gr_alvgrid
exporting
i_parent = gr_ccontainer
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
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.
endform. " CREATE_ALVGRID_INSTANCE
*& Form DISPLAYING_ALVGRID
text
--> p1 text
<-- p2 text
form displaying_alvgrid .
call method gr_alvgrid->set_table_for_first_display
exporting
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
is_variant = is_variant
i_save = 'A'
I_DEFAULT = 'X'
is_layout = gr_layout
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
it_hyperlink = gr_hyper
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
changing
it_outtab = it_vbak[]
it_fieldcatalog = gr_fieldcat
it_sort = gr_sort
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
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.
*CALL METHOD GR_ALVGRID->GET_FRONTEND_LAYOUT
IMPORTING
ES_LAYOUT = GR_LAYOUT
*GR_LAYOUT-GRID_TITLE = 'HAI ALV'.
*CALL METHOD GR_ALVGRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GR_LAYOUT
endform. " DISPLAYING_ALVGRID
*& Form REFRESH_DISPLAY_TABLE
text
--> p1 text
<-- p2 text
form refresh_display_table .
call method gr_alvgrid->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.
endform. " REFRESH_DISPLAY_TABLE
*& Form SETTING_LAYOUT
text
<--P_GR_LAYOUT text
form setting_layout changing p_gr_layout type lvc_s_layo.
p_gr_layout-grid_title = 'ALV GRID USING ABAP OBJECTS'.
p_gr_layout-zebra = 'X'.
p_gr_layout-no_toolbar = ''.
p_gr_layout-sel_mode = 'D'.
p_gr_layout-info_fname = 'ROWCOLOR'.
p_gr_layout-ctab_fname = 'CELLCOLOR'.
p_gr_layout-stylefname = 'CELLSTYLE'.
endform. " SETTING_LAYOUT
*& Module STATUS_0100 OUTPUT
text
module status_0100 output.
SET PF-STATUS 'xxxxxxxx'.
SET TITLEBAR 'xxx'.
set pf-status 'MENU'.
if gr_alvgrid is initial.
*CREATING THE CONTAINER INSTANCE BY SENDING THE CONTAINER NAME( IT HAS
*TO COINSIDE WITH COSTUM CONTROL NAME OF TRANSACTION SCREEN
perform create_ccontainer_instance.
perform create_alvgrid_instance.
*VARIANT POPULATION.
perform setting_variants changing is_variant.
*BELOW FORM IS USEFUL TO FILL THE HYPER LINK TABLE AND WE PASS THAT
*TABLE TO 'IT_HYPERLINK' PARAMETER IN FIRST DISPLAY METHOD.
perform setting_hyperlinks_field changing gr_hyper.
*TO MAKE THE COLOUMN AS DROP DOWN.
perform setting_dropdown_column changing gr_drop_down.
perform building_fieldcatalog changing gr_fieldcat.
perform setting_layout changing gr_layout.
perform setting_sorting changing gr_sort.
perform setting_cells changing gr_set_cell.
perform displaying_alvgrid.
*PERFORM GETTING_CELL_DETAILS CHANGING GR_GET_CELL. " IT IS NOT WORKING
FOR ME AND I HAVE DOUBT .
perform creating_event_object.
*PERFORM REFRESH_DISPLAY_TABLE.
endif.
endmodule. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
module user_command_0100 input.
case sy-ucomm.
when 'BACK'.
leave to screen 000.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
*& Form SETTING_SORTING
text
<--P_GR_SORT text
form setting_sorting changing p_gr_sort type lvc_t_sort.
data: lr_sort type lvc_s_sort.
lr_sort-spos = '1'.
lr_sort-fieldname = 'VBELN'.
lr_sort-up = 'X'.
append lr_sort to p_gr_sort.
lr_sort-spos = '2'.
lr_sort-fieldname = 'ERDAT'.
lr_sort-up = 'X'.
append lr_sort to p_gr_sort.
endform. " SETTING_SORTING
*& Form GETTING_CELL_DETAILS
text
<--P_GR_GET_CELL text
form getting_cell_details changing p_gr_get_cell.
call method gr_alvgrid->get_selected_cells
importing
et_cell = p_gr_get_cell
*CELL_VALUE = P_GR_GET_CELL-VALUE.
endform. " GETTING_CELL_DETAILS
*& Form SETTING_CELLS
text
<--P_GR_SET_CELL text
form setting_cells changing p_gr_set_cell type lvc_t_cell.
data:s_gr_set_cell type lvc_s_cell.
s_gr_set_cell-col_id-fieldname = 'NETWR'.
s_gr_set_cell-row_id-index = '3'.
append s_gr_set_cell to p_gr_set_cell.
call method gr_alvgrid->set_selected_cells
exporting
it_cells = p_gr_set_cell.
endform. " SETTING_CELLS
*& Form SETTING_HYPERLINKS_FIELD
text
<--P_GR_HYPER text
form setting_hyperlinks_field changing p_gr_hyper type lvc_t_hype.
data: is_hype type lvc_s_hype.
is_hype-handle = '1'.
is_hype-href = 'HTTP://WWW.GOOGLE.CO.IN'.
append is_hype to p_gr_hyper.
is_hype-handle = '2'.
is_hype-href = 'HTTP://SDN.SAP.COM'.
append is_hype to p_gr_hyper.
endform. " SETTING_HYPERLINKS_FIELD
*& Form SETTING_DROPDOWN_COLUMN
text
<--P_GR_DROP_DOWN text
form setting_dropdown_column changing p_gr_drop_down type lvc_t_drop.
data: wa_drop type lvc_s_drop.
wa_drop-handle = '1'.
wa_drop-value = '$'.
append wa_drop to p_gr_drop_down.
wa_drop-handle = '1'.
wa_drop-value = 'Rs'.
append wa_drop to p_gr_drop_down.
wa_drop-handle = '1'.
wa_drop-value = 'CUR'.
append wa_drop to p_gr_drop_down.
call method gr_alvgrid->set_drop_down_table
exporting
it_drop_down = p_gr_drop_down
IT_DROP_DOWN_ALIAS =
endform. " SETTING_DROPDOWN_COLUMN
*& Form SETTING_VARIANTS
text
<--P_IS_VARIANT text
form setting_variants changing p_is_variant type disvariant.
p_is_variant-report = sy-repid.
endform. " SETTING_VARIANTS
*& Form HANDLE_HOTSPOT_CLICK
text
-->P_E_ROW text
-->P_E_COLUMN text
-->P_E_ROW_NO text
form handle_hotspot_click using p_e_row_id type lvc_s_row
p_e_column_id type lvc_s_col
p_es_row_no type lvc_s_roid.
read table it_vbak index p_es_row_no-row_id.
if sy-subrc = 0 and p_e_column_id-fieldname = 'ERDAT'.
line = p_es_row_no-row_id.
line_number = p_es_row_no-row_id.
leave to screen 200.
endif.
endform. " HANDLE_HOTSPOT_CLICK
*& Form CREATING_EVENT_OBJECT
text
--> p1 text
<-- p2 text
form creating_event_object .
data event_handle type ref to gr_event_handler.
create object event_handle.
set handler event_handle->handle_hotspot_click for gr_alvgrid.
endform. " CREATING_EVENT_OBJECT
*& Module STATUS_0200 OUTPUT
text
module status_0200 output.
set pf-status 'BB'.
SET TITLEBAR 'xxx'.
*LINE = LINE_NUMBER.
endmodule. " STATUS_0200 OUTPUT
*& Module USER_COMMAND_0200 INPUT
text
module user_command_0200 input.
if sy-ucomm = 'BACK'.
leave to screen 100.
endif.
endmodule. " USER_COMMAND_0200 INPUT[/code]
Reward points if helpful
Thanks,
Suma. -
hi,
do we have an option of creating Editable ALV reports in SAP.If yes can u plz explain me how to ? wht function modules should be used?use -> wa_fieldcat-edit = 'X'. "sets whole column to be editable
here is a code i did for editable ALV,
*& Report ZDEMO_ALVGRID_EDIT *
*& Example of a simple ALV Grid Report *
*& The basic ALV grid, Enhanced to display specific fields as *
*& editable depending on field value *
REPORT ZDEMO_ALVGRID_EDIT .
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,
field_style TYPE lvc_t_styl, "FOR DISABLE
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.
DATA: it_fieldcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv WITH HEADER LINE,
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.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM set_specific_field_attributes.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
FORM build_fieldcatalog.
wa_fieldcat-fieldname = 'EBELN'.
wa_fieldcat-scrtext_m = 'Purchase Order'.
wa_fieldcat-col_pos = 0.
wa_fieldcat-outputlen = 10.
wa_fieldcat-emphasize = 'X'.
wa_fieldcat-key = 'X'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'EBELP'.
wa_fieldcat-scrtext_m = 'PO Item'.
wa_fieldcat-col_pos = 1.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'STATU'.
wa_fieldcat-scrtext_m = 'Status'.
wa_fieldcat-col_pos = 2.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'AEDAT'.
wa_fieldcat-scrtext_m = 'Item change date'.
wa_fieldcat-col_pos = 3.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-scrtext_m = 'Material Number'.
wa_fieldcat-col_pos = 4.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MENGE'.
wa_fieldcat-scrtext_m = 'PO quantity'.
wa_fieldcat-col_pos = 5.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MEINS'.
wa_fieldcat-scrtext_m = 'Order Unit'.
wa_fieldcat-col_pos = 6.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'NETPR'.
wa_fieldcat-scrtext_m = 'Net Price'.
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 = 'PEINH'.
wa_fieldcat-scrtext_m = 'Price Unit'.
wa_fieldcat-col_pos = 8.
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
i_callback_user_command = 'USER_COMMAND'
is_layout_lvc = gd_layout
it_fieldcat_lvc = it_fieldcat
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.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO CORRESPONDING FIELDS OF TABLE it_ekko.
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 NETPR field/column has been set to editable in the fieldcatalog...
The following code sets it to be disabled(display only) if 'NETPR'
is gt than 10.
LOOP AT it_ekko INTO wa_ekko.
IF wa_ekko-netpr GT 10.
ls_stylerow-fieldname = 'NETPR' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
"set field to disabled
APPEND ls_stylerow TO wa_ekko-field_style.
MODIFY it_ekko FROM wa_ekko.
ENDIF.
ENDLOOP.
endform. " set_specific_field_attributes
Thanks
Seshu
Maybe you are looking for
-
Ipod shuffle will not charge and is not recognized by itunes or computer
HELP, My G2 ipod shuffle will not charge and is not recognized at all by my computer or itunes. it is like there is nothing even pligged in to the usb port. and when i plug in my ipod to the charger my ipod blinks orange 4 times and then stops whats
-
Windows 8.1 and external hard drives
I have a new computer with windows 8.1and an external hard drive which is about 4 years old & has family videos and pictures on it. when I plug it into the 3.0usb port it shows up under printers and devices and says it is working properly but it is n
-
PrintToPrinter is having incorrect margins (Export to PDF is working fine)
I've met with a strange situation where my report wont print properly when I use PrintToPrinter from .NET application. But if I export or preview it in the designer it works as expected. When I print, margins set in the reports are lost. How can I ma
-
How do I import bookmarks to a different computer?
same as before
-
Cash Flow statement as per Schedule 6
Hi How can we map the cash flow statement as per schedule 6 of the companies act regards Rahul