Field Editing in ALV Report
hello everyone,
I have created an alv report using MARA table. but i am unable to edit any field and save the changes back to the table in the database.
I
Hi Ravi,
Check out the below demo program for editable ALV .
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
Similar Messages
-
To edit the field in the ALV report
Hi,
i want to edit the field of the ALV report what i need to do for that..
Thanks & Regards
Ashu Singhhi,
check the code,
REPORT zalv_fcat.* Output table T006 structure declarationTYPES : BEGIN OF ty_t006.
INCLUDE STRUCTURE t006.
TYPES : END OF ty_t006.*Internal table and wa declaration for T006
DATA : it_t006 TYPE STANDARD TABLE OF ty_t006,
wa_t006 TYPE ty_t006.*declarations for ALV
DATA: ok_code TYPE sy-ucomm,
fieldcatalog for T006
it_fielcat TYPE lvc_t_fcat,
fieldcatalog for fieldcatalog itself:
it_fielcatalogue TYPE lvc_t_fcat,
it_layout TYPE lvc_s_layo.*declaration for toolbar function
DATA: it_excl_func TYPE ui_functions.
Controls to display it_t006 and corresponding fieldcatalog
DATA: cont_dock TYPE REF TO cl_gui_docking_container,
cont_alvgd TYPE REF TO cl_gui_alv_grid.*controls to display the fieldcatalog as editable alv grid and container
DATA: cont_cust TYPE REF TO cl_gui_custom_container,
cont_editalvgd TYPE REF TO cl_gui_alv_grid.*intialization event
INITIALIZATION.*start of selection event
START-OF-SELECTION.
LOCAL CLASS Definition for data changed in fieldcatalog ALV
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
LOCAL CLASS implementation for data changed in fieldcatalog ALV
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_data_changed.
ENDMETHOD. "handle_data_changed
ENDCLASS. "lcl_event_receiver IMPLEMENTATION*data declaration for event receiver
DATA: event_receiver TYPE REF TO lcl_event_receiver.*end of selection event
END-OF-SELECTION.*setting the screen for alv output for table display and
*changed fieldcatalalogue display
SET SCREEN 600.
On this statement double click it takes you to the screen painter SE51. Enter the attributes
*Create a Custom container and name it CCONT and OK code as OK_CODE.
*Save check and Activate the screen painter.
*Now a normal screen with number 600 is created which holds the ALV grid.
PBO of the actual screen , Here we can give a title and customized menus
*Go to SE41 and create status 'STATUS600' and create THE function code 'SUBMIT'
*and 'EXIT' with icons and icon texts
Also create a TitleBar 'TITLE600' and give the relevant title.&----
*& Module STATUS_0600 OUTPUT
MODULE status_0600 OUTPUT.
SET PF-STATUS 'STATUS600'.
SET TITLEBAR 'TITLE600'.
CREATE ALV GRID CONTROL IF DOES NOT EXISTS INITIALLY
IF cont_dock IS INITIAL.
PERFORM create_alv.
ENDIF.ENDMODULE. " STATUS_0600 OUTPUT* PAI module of the screen created. In case we use an interactive ALV or
*for additional functionalities we can create OK codes and based on the
*user command we can do the coding as shown below
*& Module USER_COMMAND_0600 INPUT
MODULE user_command_0600 INPUT.
CASE ok_code.
WHEN 'SUBMIT'.
*TO GET THE CURRENT FIELDCATALOGUE FROM THE FRONTEND
CALL METHOD cont_alvgd->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = it_fielcat.
*refresh the alv
CALL METHOD cont_alvgd->refresh_table_display.
*to Send Buffered Automation Queue to Frontend
CALL METHOD cl_gui_cfw=>flush.*Exit button clicked to leave the program
WHEN 'EXIT'.
LEAVE PROGRAM. ENDCASE.ENDMODULE. " USER_COMMAND_0600 INPUT&----
*& Form CREATE_ALV
&----FORM create_alv.*create a docking container and dock the control at the botton
CREATE OBJECT cont_dock
EXPORTING
dynnr = '600'
extension = 100
side = cl_gui_docking_container=>dock_at_bottom.*create the alv grid for display the table
CREATE OBJECT cont_alvgd
EXPORTING
i_parent = cont_dock.*create custome container for alv
CREATE OBJECT cont_cust
EXPORTING
container_name = 'CCONT'.
*create alv editable grid
CREATE OBJECT cont_editalvgd
EXPORTING
i_parent = cont_cust.* register events for the editable alv
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_data_changed FOR cont_editalvgd. CALL METHOD cont_editalvgd->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.*building the fieldcatalogue for the initial display
PERFORM build_fieldcat CHANGING it_fielcat it_fielcatalogue.*building the fieldcatalogue after the user has changed it
PERFORM change_fieldcat CHANGING it_fielcatalogue.*fetch data from the table
PERFORM fetch_data.* Get excluding functions for the alv editable tool bar APPEND cl_gui_alv_grid=>mc_fc_loc_append_row TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_loc_insert_row TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_loc_cut TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_sort TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_sort_asc TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_sort_dsc TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_subtot TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_sum TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_graph TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_info TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_print TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_filter TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_views TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_mb_export TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_mb_sum TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_mb_sum TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_mb_paste TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_find TO it_excl_func.
APPEND cl_gui_alv_grid=>mc_fc_loc_copy TO it_excl_func.
*Alv display for the T006 table at the bottom
CALL METHOD cont_alvgd->set_table_for_first_display
CHANGING
it_outtab = it_t006[]
it_fieldcatalog = it_fielcat[].
optimize column width of grid displaying fieldcatalog
it_layout-cwidth_opt = 'X'.* Get fieldcatalog of table T006 - alv might have
modified it after passing.
CALL METHOD cont_alvgd->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = it_fielcat[].to Send Buffered Automation Queue to Frontend CALL METHOD cl_gui_cfw=>flush. Display fieldcatalog of table T006 in editable alv grid
CALL METHOD cont_editalvgd->set_table_for_first_display
EXPORTING
is_layout = it_layout
it_toolbar_excluding = it_excl_func
CHANGING
it_outtab = it_fielcat[]
it_fieldcatalog = it_fielcatalogue[].
ENDFORM. " CREATE_alv
*& Form fetch_data
FORM fetch_data.* select data of T006
SELECT * FROM t006 INTO TABLE it_t006 UP TO 50 ROWS.
ENDFORM. " fetch_data
*& Form BUILD_FIELDCAT
FORM build_fieldcat CHANGING it_fldcat TYPE lvc_t_fcat
it_fcat TYPE lvc_t_fcat.
Fieldcatalog for table T006: it_fldcat
to generate the fields automatically CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'T006'
CHANGING
ct_fieldcat = it_fldcat[]
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.*----
Fieldcatalog for table LVC_T_FCAT:it_fcat
Generate fieldcatalog of fieldcatalog structure.
This fieldcatalog is used to display fieldcatalog 'it_fldcat'
on the top of the screen. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'LVC_S_FCAT'
CHANGING
ct_fieldcat = it_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.
ENDFORM. " BUILD_FIELDCAT
*& Form CHANGE_FIELDCAT
*after the user has modified the fieldcatalogue we build another fieldcat
*for the modified alv display
FORM change_fieldcat CHANGING it_fcat TYPE lvc_t_fcat. DATA ls_fcat TYPE lvc_s_fcat. LOOP AT it_fcat INTO ls_fcat.
ls_fcat-coltext = ls_fcat-fieldname.
ls_fcat-edit = 'X'. IF ls_fcat-fieldname = 'COL_POS' OR ls_fcat-fieldname = 'FIELDNAME'.
ls_fcat-key = 'X'.
ENDIF. MODIFY it_fcat FROM ls_fcat.
ENDLOOP.
ENDFORM. " CHANGE_FIELDCAT
ref:saptechnical tutorial.
Regards,
Anirban -
How to save data in ztable after editing in alv report
how to save data in ztable after editing in alv report?
Hi,
Please find the attachment below.This may be usefull to you.
[http://wiki.sdn.sap.com/wiki/display/Snippets/ALV-Editingandsavingtheeditedvaluesin+Database%28OOPS%29]
Regards,
Ramakrishna Yella. -
Tool Tip Text for field values in ALV report
Hi,
How to get the tool tip text for the field values in ALV report.
Thanks & Regards,
Pallavi.Hi,
In fieldcatalog specify the TOOLTIP.
<b>
LVC_S_FCAT-TOOLTIP
</b>
In this speicfyteh tooltip you want.
Then append this to the fieldcatalog.
Hope this solves ur problem. -
How to make a particular row and column field editable in ALV
Hi Experts,
I have a requirement to make a particular row and column field editable in ALV output. Like i need to make 2nd row - 4th column editable of ALV output.
Kindly help me out to solve this.
Any help would be appreciated.
Thanks,
AshutoshHi Ashutosh,
please check below, explained by some experts.
In the below link editing two columns MOD_RANK and TECH_RANK.
These two columns will be in edit mode once after selecting the required record
Editing single cell in a row of ALV table
And also look for more info
http://scn.sap.com/thread/884976 -
To capture the selected rows along with edited field contents in alv report
Dear All,
I do have requirement where, in alv report output one field is editable and need to save the content of the edited field along with the selected rows.
For example If there are 10 records displayed in the alv output with 20 fields.
Out of this 20 fields one field (say XYZ) is editable. Also i have already created a new pushbutton (say ABC) on alv output. Now in the alv output if we maintain some value in the field (XYZ ) for the 2nd and 4th record and select this two records, and when clicked on the pushbutton (ABC) it has to update the DB table.
I am using the Func Module 'REUSE_ALV_GRID_DISPLAY'.
Your early reply with sample code would be appreciated.
Thanks in Advance.HI Naveen ,
There is an import parameter "i_callback_program" in the function module,
plz pass the program name to it.
Capture the command by passing a field of type sy-ucomm to "I_CALLBACK_USER_COMMAND ". Check the returned command and
and program a functionality as desired.
u can try the event double_click or at line selection. there u can use READLINE command to c if the line has been selected.
In case it is , process the code segment.
Regards
Pankaj -
Edit the field in an alv report, also save the changes.
Hi Everyone,
I have made one interactive ALV report using function
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
also i had provided the code to edit a particular col.
fs_fieldcat-fieldname = 'AENAM'.
fs_fieldcat-tabname = 't_mara'.
fs_fieldcat-seltext_m = 'Changed by'.
fs_fieldcat-emphasize = 'X'.
fs_fieldcat-edit = 'X'.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.
now i want to make changes in the AENAM field and save the changes done back on the database table MARA.
pls, if anyone can provide me some assitance on how to save the changes on the alv.
Regards
Ravi Aswani.When SAVE Using the User_command handle the Changed records, and modify the Material using BAPI.
Just check this following code sample. For this you need to handle to events one PF-STATUS and other USER_COMMAND. see the below comments.
REPORT zalv_edit.
TYPE-POOLS: slis.
DATA: x_fieldcat TYPE slis_fieldcat_alv,
it_fieldcat TYPE slis_t_fieldcat_alv.
data: BEGIN OF itab OCCURS 0,
vbeln LIKE vbak-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
END OF itab.
SELECT vbeln
posnr
kwmeng
FROM vbap
UP TO 20 ROWS
INTO TABLE itab.
x_fieldcat-fieldname = 'VBELN'.
x_fieldcat-seltext_l = 'VBELN'.
x_fieldcat-hotspot = 'X'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 1.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-seltext_l = 'POSNR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 2.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-fieldname = 'KWMENG'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 3.
x_fieldcat-input = 'X'.
x_fieldcat-edit = 'X'.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'STATUS'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab
EXCEPTIONS
program_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.
*& Form STATUS
* PF-STATUS
FORM status USING p_extab TYPE slis_t_extab.
"Set the Button using the staus
"Copy the Standard status from the program SAPLKKBL status
" STANDARD using SE41, and use that here.
"Pf status
SET PF-STATUS 'STATUS' EXCLUDING p_extab.
ENDFORM. " STATUS
*& Form USER_COMMAND
* USER_COMMAND
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: gd_repid LIKE sy-repid,
ref_grid TYPE REF TO cl_gui_alv_grid.
IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref_grid.
ENDIF.
IF NOT ref_grid IS INITIAL.
CALL METHOD ref_grid->check_changed_data .
ENDIF.
CASE r_ucomm.
WHEN 'SAVE'.
"Here you will get the data(along with modified rows/data)
"Filter the modified rows and update to DB using BAPI/BDC
"Accordingly
ENDCASE.
rs_selfield-refresh = 'X'.
ENDFORM. "USER_COMMAND -
Hi,
I'm using REUSE_ALV function module for the ALV display. I want to make a particular field editable in my display. How do I do it, and if I do it will the edited value get updated in my internal table as well.
Thanks for the help in advance.
Regards,
VijayHi,
there is sample code for it...
REPORT ZTESTDFALV1 .
*Data Declaration
DATA: BEGIN OF T_EKKO,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
* FLAG TYPE C,
* HANDLE_STYLE TYPE LVC_T_STYL,
END OF T_EKKO.
DATA: GD_REPID LIKE SY-REPID, "Exists
REF_GRID TYPE REF TO CL_GUI_ALV_GRID. "new
DATA: BEGIN OF IT_EKKO OCCURS 0.
INCLUDE STRUCTURE T_EKKO.
DATA: END OF IT_EKKO.
DATA: BEGIN OF IT_BACKUP OCCURS 0.
INCLUDE STRUCTURE T_EKKO.
DATA: END OF IT_BACKUP.
*ALV data declarations
TYPE-POOLS: SLIS. "ALV Declarations
DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV.
*Start-of-selection.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_FIELDCATALOG.
PERFORM BUILD_LAYOUT.
IT_BACKUP[] = IT_EKKO[].
PERFORM DISPLAY_ALV_REPORT.
*& Form build_fieldcatalog
* text
FORM BUILD_FIELDCATALOG.
REFRESH FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'EBELN'.
FIELDCATALOG-SELTEXT_M = 'Purchase Order'.
FIELDCATALOG-INPUT = 'X'.
FIELDCATALOG-EDIT = 'X'.
FIELDCATALOG-COL_POS = 2.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'EBELP'.
FIELDCATALOG-SELTEXT_M = 'PO Item'.
FIELDCATALOG-COL_POS = 3.
APPEND FIELDCATALOG.
CLEAR FIELDCATALOG.
ENDFORM. " BUILD_FIELDCATALOG
*& Form BUILD_LAYOUT
* Build layout for ALV grid report
FORM BUILD_LAYOUT.
"Permet d'ajuster les colonnes au text
* gd_layout-colwidth_optimize = 'X'.
* GD_LAYOUT-TOTALS_TEXT = 'Totals'(201).
* gd_layout-box_fieldname = 'SELECT'.
* gd_layout-box_tabname = 'IT_EKKO'.
ENDFORM. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
* Display report using ALV grid
FORM DISPLAY_ALV_REPORT .
GD_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GD_REPID
* i_callback_top_of_page = 'TOP-OF-PAGE'
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
* i_grid_title = 'My Title'
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = FIELDCATALOG[]
TABLES
T_OUTTAB = IT_EKKO
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE:/ SY-SUBRC.
ENDIF.
ENDFORM. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
* Retrieve data form EKPO table and populate itab it_ekko
FORM DATA_RETRIEVAL.
SELECT EBELN EBELP
UP TO 10 ROWS
FROM EKPO
INTO CORRESPONDING FIELDS OF TABLE IT_EKKO.
ENDFORM. " DATA_RETRIEVAL
* FORM SET_PF_STATUS *
FORM SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STANDARD_FULLSCREEN1' EXCLUDING RT_EXTAB.
ENDFORM. "set_pf_status
*& Form user_command
* text
* -->R_UCOMM text
* -->RS_SELFIELDtext
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
*then insert the following code in your USER_COMMAND routine...
IF REF_GRID IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF_GRID.
ENDIF.
IF NOT REF_GRID IS INITIAL.
CALL METHOD REF_GRID->CHECK_CHANGED_DATA
ENDIF.
*modify
CASE R_UCOMM.
WHEN '&IC1'.
CHECK RS_SELFIELD-TABINDEX > 0.
IF RS_SELFIELD-VALUE EQ '6000000001'.
CALL TRANSACTION 'ZDF2'.
ENDIF.
WHEN 'REFRESH'.
READ TABLE IT_EKKO INDEX RS_SELFIELD-TABINDEX.
IF SY-SUBRC = 0.
READ TABLE IT_BACKUP INDEX RS_SELFIELD-TABINDEX.
IF SY-SUBRC = 0.
IF IT_EKKO <> IT_BACKUP.
* then do your check
ENDIF.
ENDIF.
ENDIF.
PERFORM DATA_RETRIEVAL.
RS_SELFIELD-REFRESH = 'X'.
ENDCASE.
ENDFORM. "user_command
and also check this thread in which i gave the solution....
REUSE_ALV_GRID EDITABLE
Regards
vijay -
Prefix Negative sign in type P field in an ALV report
Generally, -vs sign appears after the number in an ALV report. I have a type P field where I want to prefix the -ve sign ( before the number ). I donot want to convert it to C type as I want the sorting feature. Is there any other way ?
U can do as per the suggestion given by Raja
or
U can copy the fm CLOI_PUT_SIGN_IN_FRONT to CONVERSION_EXIT_SIGN_OUTPUT and activate it. Then in edit mask use this '==SIGN' or u can create one domain and refer the domain to that field. In that domain u set the convertion routine = SIGN.
regards
gv -
Hi,
How to increase the field width of a field in ALV report.
I mean, in a ALV report, the field description of a field is not showing correctly. IF i try to extend the field width by the mouse/coursor, it displays the correct description.
IS there any way where for displaying the field description correctly?
Thanks,
KumarHi,
Go through the sample code,
*& Report ZDEMO_ALVLIST *
*& Example of a simple ALV List Report *
*& The basic requirement for this demo is to display a number of *
*& fields from the EKKO table. *
REPORT zdemo_alvlist .
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,
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.
There are a number of ways to create a fieldcat.
For the purpose of this example i will build the fieldcatalog manualy
by populating the internal table fields individually and then
appending the rows. This method can be the most time consuming but can
also allow you more control of the final product.
Beware though, you need to ensure that all fields required are
populated. When using some of functionality available via ALV, such as
total. You may need to provide more information than if you were
simply displaying the result
I.e. Field type may be required in-order for
the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-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-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
Display report using ALV grid
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
i_save = 'X'
is_variant = z_template
tables
t_outtab = it_ekko
exceptions
program_error = 1
others = 2.
if sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
form data_retrieval.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
endform. " DATA_RETRIEVAL
Form TOP-OF-PAGE *
ALV Report Header *
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_header.
Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header.
i_logo = 'Z_LOGO'.
endform.
Regards,
Raj. -
How to display the fields using field catelog in ALV Report
Hi,
I have rquiremrnt in ALV report.I would need to add the new fileld in the ALV output screen.I have added the field but its appearing in the layout set but not directly displaying in the output screen.
I have written the below logic for field catelog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'LOGGR'.
wa_fieldcatalog-ref_tabname = 'MARC'.
wa_fieldcatalog-col_pos = l_pos.
wa_fieldcatalog-outputlen = 13.
wa_fieldcatalog-seltext_s = 'Log. group'.
wa_fieldcatalog-seltext_m = 'Logistics group'.
wa_fieldcatalog-seltext_l = 'Log. handling group'.
wa_fieldcatalog-reptext_ddic = 'Log. handling group'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
l_pos = l_pos + 1.
Please let me know why the added field was not displaying automaticaly in the output screen.
Regards,
Reddyhi,
try this
clear wa_fieldcatalog.
wa_fieldcat-tabname = 'ITAB' ( give the internal table which has the field LOGGR)
wa_fieldcatalog-fieldname = 'LOGGR'.
wa_fieldcatalog-ref_tabname = 'MARC'.
wa_fieldcatalog-col_pos = l_pos.
wa_fieldcatalog-outputlen = 13.
wa_fieldcatalog-seltext_s = 'Log. group'.
wa_fieldcatalog-seltext_m = 'Logistics group'.
wa_fieldcatalog-seltext_l = 'Log. handling group'.
wa_fieldcatalog-reptext_ddic = 'Log. handling group'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
l_pos = l_pos + 1. -
How can i change field width in ALV report
hello,
i have to modify vendor payment list. it is a ALv report
proble is that when i gave vendor acc range for any month (range of posting date) it shows list,
but for february it show run time error
error description- the resulting values are too large for the designated field.
for posting dates 1.02.2009 to 25.02.09 it shows list. but when i gave posting date after 25 it doesnt show list.
just i cant understand how to solve it.
thanks in advance,
Anuradha.Hi...
Best option is first deside which format you want to put in that date field...
then before filling internal table do one thing format that date field and then add into ur internal table which u later will use to show in ALV Grid Report...
Example...Suppose you want DD.MM.YYYY
then use
concatenate Fieldname0(2) Fieldname2(2) Fieldname+4(4) into Fieldname...
This way you can format the date in any format with proper logic. and ur problem getting solved
Regards,
Chintan -
How can i choose row to edit in alv report
hello ,
i done alv report with one coloumne that can be edit ,
in this coloumne i want to choose which rows can be edit
and which will be close according to event .
i saw example program "BCALV_EDIT_02" that show this case
but stile , i don't understand what is the action that
do it .
this is the part
IF p_mode EQ 'RW'.
*§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell
to status "editable".
l_mode = cl_gui_alv_grid=>mc_style_enabled.
ELSE. "p_mode eq 'RO'
*§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell
to status "non-editable".
l_mode = cl_gui_alv_grid=>mc_style_disabled.
ENDIF.
so what is the part that will close the row for edit ?
when i add this part in my report all the row is deleted.
thanks.Dakota,
You can change the settings at runtime.
What you need to do is to have another column as part of the internal table, that has the data. This column, say, STYLE will refer to LVC_T_STYL. So, this becomes a nested internal table.
Set the editable flga switched off at Fieldcat and layout level.
Now, while filling the data in the table, or looping it separately, fill the Styles table for each row accordingly depending on the conditions. So, if you want the entire row to be enabled for editing, there will so many rows as the no. of columns in the inner internal table which is a column of that row.
col1 col2 Col3 Style
1 1 2 Col1 -- Style_Disabled
___________________Col2 -- Style_Disabled
___________________Col3 -- Style_Disabled
This should solve your problem.
Regards,
Ravi
note : Please reward the posts that help you.
Message was edited by: Ravikumar Allampallam -
How to make field editable in ALV tree in OOPs?
Hi Gems,
Again I need help from you all.
I am writing a program using OOPs and the uotput will be in ALV tree. I need to make a field editable in a perticular row.
I am doing it using layout but the program is giving error during
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
This method is returning sy-subrc = 2 and I am unable to get the output.
I am using below code to make the field editable:
DATA: LT_LAYOUT_ITEM TYPE LVC_T_LAYI,
LS_LAYOUT_ITEM TYPE LVC_S_LAYI.
LS_LAYOUT_ITEM-FIELDNAME = 'ACPCKTWRT'. "ACPCKTWRT is the field name in the Internal table
LS_LAYOUT_ITEM-EDITABLE = 'X'.
APPEND LS_LAYOUT_ITEM TO LT_LAYOUT_ITEM.
CALL METHOD G_ALV_TREE->ADD_NODE
EXPORTING
I_RELAT_NODE_KEY = FP_RELAT_KEY
I_RELATIONSHIP = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD
IS_OUTTAB_LINE = LS_TMP_FINFCNO "structure of the internal table
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT = LT_LAYOUT_ITEM "Added layout to make the field editable
I_NODE_TEXT = LV_NODE_TEXT "Node text
IMPORTING
E_NEW_NODE_KEY = FP_NODE_KEY
EXCEPTIONS
RELAT_NODE_NOT_FOUND = 1
NODE_NOT_FOUND = 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.
Please help me and let me know how to get the solution.Hello
The ALV tree control is not intended for making values editable (e.g. see
[How to make ALV tree columns editable|http://sap.ittoolbox.com/groups/technical-functional/sap-abap/how-to-make-alv-tree-columns-editable-2052414])
However, if you need an editable tree control then you have to use a different class (e.g. CL_ITEM_TREE_MODEL or CL_COLUMN_TREE_MODEL) but you will not have the ALV functionality of the ALV tree control.
Regards
Uwe -
Add field in standard ALV report.
Hi friends,
In SAP standard ALV report, t.code- S_ALR_87012050, user wants the vendor to include information about source document - vendor number, vendor name, invoice number, original document number of the transaction in the case of payroll being capitalized.
I tell me weather this information is already present in the report or I have to create Z report for adding this information and how do I proceed to add new fields in the created Z program.
Please help me.
Thanks in advance,
SayaHI Saya,
Check in the ALV output whether these fields are already there and not displaying in the ALV output, if the fields are not at all printing in the ALV output,then copy the Program to Z program and change it.
write the Code to add the new fields to the internal table and change the Field catalaog to come your fields in the ALV output then print it
Regards
SUdheer
Maybe you are looking for
-
What Cable Do I Need for Vehicle Jack?
Hi! I bought a new car yesterday and it has a jack (little hole in the radio area) to plug my 4th generation iPod Touch into so I can get audio. I don't know what sort of a cable I need to make this work. Do I need a 30 pin connector on one end and a
-
MBP FREEZES AFTER 10.4.6 UPDATE WITH WINDOWS PARTITION
Just updated software to 10.4.6, and rebooted the computer unattended. It booted on the Windows partition, and worked fine. Just rebooted in Mac mode, and everything froze. Had to reinstall the OS, from the original DVD. Did anyone experience the sam
-
Hi, I installed the 2.0 firmware for the iPod Touch, and it seemed to work fine. Then the next time I synced with iTunes all the apps would just like start up but it would only display the loading screens, not the acutal app. Like it was frozen, none
-
How to attach the documents.
Hello Gurus, My requirement is only attach the pdf documents but do not allow the remaining documents like msword,excel ....in custom page. please tell me any idea and give me sample code.Is it possible to attach only pdf. Thanks, Kumar.
-
Can i just have apple replace the earphone jack on my ipod classic 160gb; nothing else?
I really don't want to spend $150 on replacing a 10-20 dollar part. I just want them to replace the part, nothing else.