Input Length of ALV grid
Hi,
I am using an OO ALV, and have some fields editable.
I have a field in which the user can enter upto 250 characters, but I need to display only 50 characters on the output.
If i mention outputlen = 250 in my fieldcatalog, the column is displayed too big on the output. So i want to have the column displayed upto 50 or 60 characters on the ALV output, but the user can enter upto 250 characters. I have tried giving using the intlen in the fieldcatalog, but didnt help me.
Could anyone pls assist me in resolving this?
Thanks in advance
-Pavan
Give 250 as outputlen and Try with Col_width optimize option of ALV layout. I tested it is working fine for me, i used LVC FM, the same is applicable to OO ALV. there is no much difference.
REPORT ztest_lvc_fm.
TYPE-POOLS: slis.
DATA: x_fieldcat TYPE lvc_s_fcat,
it_fieldcat TYPE lvc_t_fcat.
DATA: BEGIN OF itab OCCURS 0,
vbeln LIKE vbak-vbeln,
posnr LIKE vbap-posnr,
char(250),
chk(1),
color(4),
END OF itab.
SELECT vbeln
posnr
FROM vbap
UP TO 20 ROWS
INTO TABLE itab.
x_fieldcat-fieldname = 'CHK'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 1.
x_fieldcat-edit = 'X'.
x_fieldcat-checkbox = 'X'.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-fieldname = 'VBELN'.
x_fieldcat-coltext = 'VBELN'.
x_fieldcat-hotspot = 'X'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 2.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-coltext = 'POSNR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-edit = 'X'.
x_fieldcat-col_pos = 3.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-fieldname = 'CHAR'.
x_fieldcat-coltext = 'CHAR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-outputlen = 250.
x_fieldcat-edit = 'X'.
x_fieldcat-col_opt = 'X'.
x_fieldcat-col_pos = 3.
APPEND x_fieldcat TO it_fieldcat.
CLEAR x_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
it_fieldcat_lvc = it_fieldcat
TABLES
t_outtab = itab
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 USER_COMMAND
* text
* -->R_UCOMM text
* -->RS_SELFIELD text
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: gd_repid LIKE sy-repid, "Exists
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.
"now check the entries in ALV table
BREAK-POINT.
ENDFORM. "USER_COMMAND
Similar Messages
-
Field Length in Alv Grid out put
hi,
How to increase the length of the filed in the output of alv grid,
Actually i am getting one blank field in the alv grid out put, my requirement is to increase the length through out the column how to do that
can anyone guide me plz
SIRIin your fieldcat of the field
wfieldcat-fieldname = '<your fieldname in caps>'
wfieldcat-outputlen = 10 (or the length you want for the field)
<you can define any other property also for that field>
append wfieldcat to ifieldcat.
now pass it in fm.
regards
shiba dutta -
Hi All,
I have a requirement to display one field in the ALV grid as input field,so that the user can enter value in that field when the ALV is displayed.I need to use this entered user value later in th eprg for further processing.
My worry is that i do not see any parameter such as "INPUT " or "EDIT " in the field catalog structure lvc_s_fcat for the ALV.
How can i acheive having editable input field in the ALV grid?
Please suggest.
Thanks,
SwatiEDIT field in field catalog is there, you must have ommited it.
ls_fieldcat-edit = 'X'. "set your desired column to be edited
Now you need to get entered value for further processing.
Define a class as a event receiver for data_changed or data_changed_finished events. Here is how to implement the latter method:
CLASS cl_alv_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
cell_changed FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified et_good_cells.
ENDCLASS.
CLASS cl_alv_event_receiver IMPLEMENTATION.
METHOD cell_changed.
check e_modified = 'X'. "if content of cell was changed
"here you check et_good_cells table, it will contain new values
"it is of type lvc_t_modi
ENDMETHOD.
ENDCLASS.
CREATE OBJECT cl_alv_event_receiver.
"now just indicate the handler for this event
SET HANDLER cl_avl_event_receiver->cell_changed FOR cl_gui_alv_grid.
Each time some action was perfomed on edit field, the method will be invoked and you can check inside what was changed and what is the new value.
Additionally after displaying your output table in alv, you need to register this event
"register edit events
CALL METHOD W_ROGRID->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
Now all you need is to update appropraite records to your internal table in your METHOD cell_changed. -
How to display field of 250 character length using ALV Grid display
Hello Experts,
Currently I'm using 4.6 version.
I got to insert a new field of length 250 characters into an existing ALV grid display.
I passed a value of length 250 chars into the field and assigned it to the itab passing to the fn module
'REUSE_ALV_GRID_DISPLAY'.
But in the ALV display I am able to view only 132 chars only. I increased the line-size of the report also accordingly. But I'm unable to view all the 250 chars.
Kindly help me out in fixing this issue.you just can't do that
I suggest that you put the first characters in cell and allow user to double-click on cell in order to view the full value in a popup window -
Multiple Input Rows In ALV Grid (Editable)
Hi,
I have an editable ALV grid and need to have multiple blank rows ready for input. Something similar to what happens when you click the "New Entries" button in SM30 (Table Maintainance).
There is a local function for appending lines in the ALV grid toolbar but this only allows a single entry.
I have replaced the local function with my own button (same icon etc) and on user_command event, I am appending several blank lines to my output table.
However these lines are not being shown on the screen. I have looked through the layout and field catalog but there is no field to allow blank lines to be shown.
My 2 questions are:
1. Is there some standard way of entering multiple entries in ALV Grid Editable.
2. If not then how to allow blank lines to be shown as ready for input.
Also if someone could suggest a way to do error checking for all entries on the screen especially duplicate entries I will be extremely grateful.
Many Thanks,
PreetHi, Preet!
You can easily do whatever checks you wish. You should declare an event handling method for event DATA_CHANGED and call the ADD_PROTOCOL_ENTRY method of the ER_DATA_CHANGED event parameter (it's an object of the class CL_ALV_CHANGED_DATA_PROTOCOL). You must not forget to set handler for your ALV grid.
For example, this piece of code checks for all changed fields resulting in error message if they are initial. In short, this makes all the fields obligatory.
METHODS: on_data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed.
SET HANDLER your_object->on_data_changed FOR your_alv_grid.
METHOD on_data_changed.
DATA: s_mod_cell TYPE lvc_s_modi.
LOOP AT er_data_changed->mt_mod_cells INTO s_mod_cell.
IF s_mod_cell-value IS INITIAL.
* issue message 'Make an entry in all required fields'
CALL METHOD er_data_changed->add_protocol_entry
EXPORTING i_msgid = '00'
i_msgno = '055'
i_msgty = 'E'
i_fieldname = s_mod_cell-fieldname
i_row_id = s_mod_cell-row_id.
ENDIF.
ENDMETHOD.
Furthermore, if you make your class inherited from CL_GUI_ALV_GRID you can make use of protected attribute MT_OUTTAB which is a data object referencing your output table. Then you can have:
FIELD-SYMBOLS: <outtab> TYPE STANDARD TABLE.
ASSIGN me->mt_outtab->* TO <outtab>.
* do whatever you want with <outtab>
Hope this helps.
Kind regards,
Igor
P.S. Regarding the blank lines that you need, what's wrong with standard ALV grid buttons "Append row" and "Insert row" which appear whenever the grid is editable (unless you deliberately remove them)? They work just fine with me (just like on SM30). I don't see reason for programatically appending lines to your internal table. -
How to display a field that has more than 136 char length in ALV GRID
Hi Experts,
I have an issue and need to solve ASAP.
I want to display a text of length 400 character in a particular column in ALV GRID DISPLAY. After executing the report it is displaying only 136 length char in the output and when I download the report to an excel it is showing only 255 characters, but my field length is almost 400 char and want to display in the report output.
I checked in SDN and didnt get any answers which will solve this.
Please help me to complete this issue.
Thanks
RetheeshCurrently I'm in a same problem with you.
And this is what I found
Size of data fields: While the list-based ALVList can display only tables of up to 90 columns, the control-based *ALVGrid and ALVFullscreen have a limitation of 128 characters per data cell.*
So it means that maximum for alv grid is only 128.
Please refer to this documentation
[https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/4544e790-0201-0010-c29c-e46c389f5a96]
you can find the statement above in page 5.
Please let me know if you have another solution, because I would like to see it too.
Thanks
Regards
Hadi -
Increase edit length in ALV GRID
Hi All,
I am using wa_fieldcat-edit for editing the ALV outreport.
But here by editing i am able to enter only 10 characters in that filed.
How can i increase this length upto 40 characters.
Please help me in this.
Regard,
Kalyan VarmaHi Kalyan.
You can make any field of your alv editable by passing "X'in the edit parameter of the field catalog.Once you have made the field editable you can change its value.By deafult the width of that field with be equal to the size of the field of the internal table through which you are displaying the data in alv.If u want to increase or decrease the width by using the outputlen parameter of the field catalog as i have mentioned in my earlier post.
I tried it on my code.Initially the matnr was of length 18 but i increased it length to 40.The code is as follows:
DATA : OUT_LEN LIKE dd03p-outputlen VALUE '40'.
DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV,
wa_fcat TYPE SLIS_FIELDCAT_ALV.
DATA : C_CHECK TYPE C VALUE 'X'.
LOOP AT I_FCAT INTO WA_FCAT.
if ( wa_fcat-fieldname = 'MATNR' ).
WA_FCAT-HOTSPOT = C_CHECK.
WA_FCAT-EDIT = C_CHECK.
WA_FCAT-outputlen = OUT_LEN.
ENDIF.
MODIFY i_fcat FROM wa_fcat TRANSPORTING edit OUTPUTLEN.
ENDLOOP.
In the end you have to pass the i_fact(field catalog) to the IT_FIELDCAT parameter of REUSE_ALV_GRID_DISPLAY like this.
IT_FIELDCAT = i_fcat
I think you would be able to solve it now.
Thanks!! -
Making a particular row input enabled in ALV grid
I am using set_table_for_first_display Method of class cl_gui_alv_grid in order to display the ALV table control.i want one whole column(flag) to be input enabled all the time.so i have defined in FCAT for that column EDIT as X.Now i have defined a custom toolbar button SAVE using handle_toolbar. My requirement is when the user inputs M in the flag column of a particular row and press SAVE button that row should be made input enabled. i have used method set_ready_for_input in the handle_user_command FOR go_grid, but it is not working.Please help.Thanks in advance.
done..
-
ALV GRID Using oo abap example
Hi Friends,
I am new to oo abap, Can any one give me a basic example how i can create alv grid in oo abap.
regards,
DVNSHI,
Programming for ALV grid display using the classes involves creation of a screen and calling it for display.
Since there has to be a linking between the program and the screen we have created , this comes in the form of a container. We use two important classes during the programming for displaying ALV grid, CL_GUI_ALV_GRID and CL_GUI_CUSTOM_CONTAINER.
Steps To Use ALV Grid in a Program
1. Declare reference variables for,
Container (class CL_GUI_CUSTOM_CONTAINER) and
Grid (class CL_GUI_ALV_GRID)
Example
DATA: grid TYPE REF TO cl_gui_alv_grid,
custom_container TYPE REF TO cl_gui_custom_container
2. Create Standard Screen and a container on that screen and give a name to that container ( Use custom control button from tool bar) . This name will be used to link the container we have created on the screen with the object reference of class CL_GUI_CUSTOM_CONTAINER, which we have declared in the first step
3. Call the screen which has been created
4. Instantiate the container control and the ALV Grid Control in PBO of the screen.
Example
IF custom_container IS INITIAL.
CREATE OBJECT custom_container
EXPORTING
CONTAINER_NAME = MY_CONTAINER'.
CREATE OBJECT grid
EXPORTING
I_PARENT = custom_container.
ENDIF
5. For displaying the data, call the method set_table_for_first_display of object reference of CL_GUI_ALV_GRID.
Example
CALL METHOD grid->set_table_for_first_display
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT =
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
IT_OUTTAB =
IT_FIELDCATALOG =
IT_SORT =
IT_FILTER =
EXCEPTION
INVALID_PARAMETER_COMBINATION =
PROGRAM_ERROR =
TOO_MANY_LINES =
others =
EXPLANATION OF SOME IMPORTANT PARAMETERS.
I_BYPASSING_BUFFER & I_BUFFER_ACTIVE :
When the program is run for the first time, the fields present in the output table and their positions are stored in a buffer. So the buffer is taken as reference for the successive executions. In order to bypass this buffer the above parameter values should be X and (space) respectively. If these values are not passed to the function module, the changes made in the structure of the internal table will not be reflected in the output.
I_STRUCTURE_NAME:
If the structure of your output table corresponds to a structure stored in the Data Dictionary (DDIC), the ALV Grid Control can use this information to generate the field catalog automatically. Pass the table structure as parameter. In this case, all fields of this DDIC structure are displayed in the list.
IS_VARIANT :
It allows the user to save and reuse the layout. It is a structure of type DISVARIANT and contain the display variant name. It facilitates pre-assignment for a layout, rather than displaying report and then choosing displaying variant.
I_SAVE:
This single character variable specifies whether the user specific display variants can be saved or not.
The I_SAVE "Options for saving layouts" parameter can have the following values:
U Only user specific layouts can be saved
X Only global layouts can be saved
A Both user specific and global layouts can be saved
Space Layouts can not be saved
IS_LAYOUT:
This structure of type LVC_S_LAYO
is used to control the layout of the ALV. Two important fields are:
GRID TITLE. : Title of grid
ZEBRA : Alternate lines in list are displayed in different colors.
IT_FIELDCATALOG:
This internal table of type LVC_T_FCAT
is used to specify the position of various fields in the report itab.
There are three ways we can fill the field catalog table
1. Automatically through data dictionary structure (DDIC). In this case we pass the table structure to I_STRUCTURE_NAME.
2. Manually in ABAP program. Filling the internal table of type LVC_T_FCAT
1. . With each row corresponding to each column of output table. Each row of this table will hold value like
i). TABNAME & FIELDNAME specifies the reference fields for F1 help
ii). CTABNAME & CFIELDNAME specifies the reference fields for currency formatting
iii). QTABNAME & QFIELDNAME specifies the reference fields for quantity formatting
iv). SELTEXT_L holds the long description of the field
v). SELTEXT_M holds the medium description of the field
vi). SELTEXT_S holds the small description of the field
vii). KEY specifies the Key field ( cannot be hidden )
viii). OUTPUTLEN species the output length of the field
ix). DO_SUM specifies that subtotal is required on this field
x). NO_OUT specifies a hidden field
3. Semi-Automatically by combining the above 2 procedures.
Call function Module REUSE_ALV_FIELDCATALOG_MERGE and pass DDIC
structure or the output table to generate the field catalog.
Add additional Rows or modify existing properties of the fields to be displayed.
METHODS OF IMPLEMENTING SOME EXTRA FEATURES
Set focus to the grid
After CALL METHODgrid->set_table_for_first_display insert the following stament:
CALL METHOD cl_gui_control=>set_focus EXPORTING control = grid
Refresh grid display
Use the grid method REFRESH_TABLE_DISPLAY
Example:
CALL METHOD grid->refresh_table_display.
Set the title of the grid
Fill the grid_title field of structure lvc_s_layo.
DATA:
gs_layout TYPE lvc_s_layo.
gs_layout-grid_title = 'TITLE'.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'structure name'
is_layout = gs_layout
CHANGING it_outtab = Output table.
The structure lvc_s_layo contains fields for setting graphical properties, displaying exceptions, calculating totals and enabling specific interaction options
Event Handling
We can handle the events triggered by
1. User defined Text Output
2. Mouse-controlled Actions
3. Self-defined and Standard Functions
Steps for Event Handling
1. Define a (local) class for event handling
2. Define a method for each event you need to handle
3. Implement your event handler methods.
4. Create Object of the above class
5. Link used events and event handler methods of the receiver object and the grid
object.
Example program : Handling Double Click Event
Step1.Define a class.
class lcl_my_event_receiver definition.
public section.
methods:
handle_double_click
for event double_click of cl_gui_alv_grid.
endclass.
Step 2. Implement the class
class lcl_my_event_receiver implementation.
method handle_double_click.
message i001(zz) with ' double click event - Triggerd '.
endmethod.
endclass.
Step 3. Declare and create Object for the local class defined and implemented in steps 1 and 2 respectively
o_receiver TYPE REF TO lcl_my_event_receiver (Declaration)
create object o_receiver. (Instantiation)
Step 4. Link the method for handling the event with the grid object in the PBO of screen after instantiating the grid object
set handler o_receiver->handle_double_click for grid.
EXAMPLE PROGRAM TO CHANGE A CLASSICAL REPORT OUTPUT TO A ALV GRID
This can be used as a template program to convert a classical report layout to a ALV grid.
Report<Report name>
Grid data Declarations----------------------------------------------*
INCLUDE ZVINALVD.
Internal table for ALV grid
TYPES: BEGIN OF T_ALV,
Field1 like table-field1,
Field2 like table-field2,
END OF T_ALV.
DATA: I_ALV TYPE TABLE OF T_ALV.
DATA: WA_ALV TYPE T_ALV.
-Class declarations----
INCLUDE ZVINALVE.
Add a checkbox in selection screen for ALV grid display. If it is unchecked
output will be of classical type.
SELECTION-SCREEN BEGIN OF BLOCK box01.
SELECTION-SCREEN: BEGIN OF LINE.
SELECTION-SCREEN: COMMENT 4(30) To display repot output as a ALV grid.
PARAMETERS: p_alv AS CHECKBOX.
SELECTION-SCREEN: END OF LINE.
SELECTION-SCREEN END OF BLOCK box01.
START-OF-SELECTION.
Fill the ALV grid internal table
END-OF-SELECTION.
IF P_ALV = X.
PERFORM ALV_DISPLAY.
ELSE.
PERFORM CLASSICAL_DISPLAY.
ENDIF.
Alv Display
FORM ALV_DISPLAY.
CALL SCREEN 100.
ENDFORM.
Module STATUS_0100 OUTPUT
PBO for ALV Grid
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'GRID_DISPLAY'.
DATA:
For parameter IS_VARIANT that is used to set up options for storing
the grid layout as a variant in method set_table_for_first_display
l_layout TYPE disvariant.
GS_LAYOUT-SEL_MODE = 'B'.
Optimize column width
GS_LAYOUT-CWIDTH_OPT = 'X'.
Read data and create objects
IF go_custom_container IS INITIAL.
Create objects for container and ALV grid
CREATE OBJECT go_custom_container
EXPORTING container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING i_parent = go_custom_container.
Create object for event_receiver class
and set handlers
CREATE OBJECT o_event_receiver.
SET HANDLER o_event_receiver->handle_user_command FOR go_grid.
SET HANDLER o_event_receiver->handle_toolbar FOR go_grid.
Layout (Variant) for ALV grid
l_layout-report = sy-repid. "Layout to report
To built fieldcatalog
PERFORM alv_build_fieldcatalog.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
is_variant = l_layout
i_save = 'A'
is_layout = gs_layout
CHANGING it_outtab = I_ALV
it_fieldcatalog = fieldcat.
Raise event toolbar to show the modified toolbar
CALL METHOD go_grid->set_toolbar_interactive.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
Form ALV_BUILD_FIELDCATALOG.
Store contents of selected line in a internal table
FORM alv_build_fieldcatalog.
CLEAR afield.
afield-fieldname = 'FIELD1'.
afield-tabname = 'I_ALV'.
afield-coltext = Field Name 1.
afield-lzero = ' '.
afield-key = 'X'.
afield-outputlen = XX.
APPEND afield TO fieldcat.
CLEAR afield.
afield-fieldname = 'FIELD2'.
afield-tabname = 'I_ALV'.
afield-coltext = Field Name 2.
APPEND afield TO fieldcat.
ENDFORM. " alv_build_fieldcatalog
Module USER_COMMAND_0100 INPUT
PAI for ALV Grid
MODULE USER_COMMAND_0100 INPUT.
CASE OK_100.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
Form SELECT_LINE
Store contents of selected line in a internal table
FORM SELECT_LINE.
DATA:l_lines TYPE i.
REFRESH gi_index_rows.
CLEAR g_selected_row.
Read index of selected rows
CALL METHOD go_grid->get_selected_rows
IMPORTING et_index_rows = gi_index_rows.
Check if any row are selected at all. If not
table gi_index_rows will be empty
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'You must choose a line'.
EXIT.
ENDIF.
Read indexes of selected rows.
LOOP AT gi_index_rows INTO g_selected_row.
IF sy-tabix = 1.
READ TABLE I_ALV INDEX g_selected_row-index INTO
WA_ALV.
ENDIF.
ENDLOOP.
ENDFORM. " SELECT_LINE
Includes:
1. ZVINALVD for data declarations
INCLUDE ZVINALVD .
Type pool for icons - used in the toolbar
TYPE-POOLS: icon.
To allow the declaration of o_event_receiver before the
lcl_event_receiver class is defined, decale it as deferred in the
start of the program
CLASS lcl_event_receiver DEFINITION DEFERRED.
GLOBAL DATA FOR ALV GRID
DATA:
OK code for alv grid screen
OK_100(4) TYPE C,
ALV control: Layout structure
gs_layout TYPE lvc_s_layo,
Declare reference variables to the ALV grid and the container
go_grid TYPE REF TO cl_gui_alv_grid,
go_custom_container TYPE REF TO cl_gui_custom_container,
o_event_receiver TYPE REF TO lcl_event_receiver,
Data for storing information about selected rows in the grid
Internal table
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
fieldcatalog
DATA: fieldcat TYPE LVC_T_FCAT,
afield TYPE LVC_S_FCAT.
2. ZVINALVE for Class/object declarations
INCLUDE ZVINALVE.
C L A S S E S
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
CLASS lcl_event_receiver IMPLEMENTATION
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
Event handler method for event toolbar.
CONSTANTS:
Constants for button type
c_button_normal TYPE i VALUE 0,
c_menu_and_default_button TYPE i VALUE 1,
c_menu TYPE i VALUE 2,
c_separator TYPE i VALUE 3,
c_radio_button TYPE i VALUE 4,
c_checkbox TYPE i VALUE 5,
c_menu_entry TYPE i VALUE 6.
DATA: ls_toolbar TYPE stb_button.
Append seperator to the normal toolbar
CLEAR ls_toolbar.
MOVE c_separator TO ls_toolbar-butn_type..
APPEND ls_toolbar TO e_object->mt_toolbar.
Append a new button that to the toolbar. Use E_OBJECT of
event toolbar. E_OBJECT is of type CL_ALV_EVENT_TOOLBAR_SET.
This class has one attribute MT_TOOLBAR which is of table type
TTB_BUTTON. The structure is STB_BUTTON
CLEAR ls_toolbar.
MOVE 'DISPLAY' TO ls_toolbar-function.
MOVE icon_DISPLAY TO ls_toolbar-icon.
MOVE 'Displaying customer' TO ls_toolbar-quickinfo.
MOVE 'Display' TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
Handle own functions defined in the toolbar
CASE e_ucomm.
WHEN 'DISPLAY'.
PERFORM SELECT_LINE.
ENDCASE.
ENDMETHOD.
Reward if useful -
F4 help for field in ALV grid control (using ABAP objects)
Hi All,
I have created a z table ZTAB which is a master table( with single column X). field X should be a input field in ALV Grid through F4 key. I have created searchelp and assigned it to data element of X feild, and in domain level I have assigned ZTAB as value table.
And in ALV field catalog wrote ls_fcat-ref_tab = 'ZTAB'. But still I'm not getting list of values when I press F4.
Can anyone help me to understand what is missing here? How to call standardard F4 help?
This is very urgent..
Regards
Jaker.u can refer to this standard program :BCALV_EDIT_08
also u wont get the list of values automatically..
declare a class :
CLASS LCL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS :
handle_on_f4 for event onf4 of cl_gui_alv_grid
importing e_fieldname es_row_no er_event_data,
ENDCLASS. "LCL_EVENT_HANDLER
implementation of class
here u pass ur internal table what u want to display as pop up for f4 help.
*& Class (Implementation) LCL_EVENT_HANDLER
Text
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
*Method to handle F4 click.
Method handle_on_f4.
Function to create a popup and passing the values of internal table in it.
CALL FUNCTION 'POPUP_WITH_TABLE'
EXPORTING
ENDPOS_COL = 60
ENDPOS_ROW = 60
STARTPOS_COL = 5
STARTPOS_ROW = 5
TITLETEXT = 'pop up'
IMPORTING
CHOICE = wa_grid-zfield
TABLES
VALUETAB = ITAB
EXCEPTIONS
BREAK_OFF = 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.
RETURN.
ENDIF.
endmethod. "handle_on_f4
ENDCLASS. "LCL_EVENT_HANDLER
hope this gives u some idea. -
Position button at the end of ALV grid
Hi,
I have a requirement to place position button (like in OB52 or any table/view maintenance ) to search and position the record on the top of list. I have placed the position pushbutton with function code and have called TABLE_GET_KEY_TO_SET_CUR_ROW for the input . My alv grid doesn't show the toolbar till the records cross one page. can you please suggest 1- how to make the scrollbar visible always ? 2- How to make the position button work as in tables for ALV grid?
Regards,
GarimaI have created the pushbutton in the same screen as container and assigned a function code. I have put this logic in user-command for this button and refreshed display. But it doesn't work, moreover the scrollbar is not visible if the records are less than one page.
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN '&BACK&'.
LEAVE TO SCREEN 0.
WHEN '&EXIT&'.
LEAVE PROGRAM.
WHEN '&POSI&'.
DATA: LV_EBELN(15) TYPE C,
IT_EXCL TYPE VIMEXCLFLD OCCURS 0,
WA_EXCL TYPE VIMEXCLFLD,
LV_PO TYPE EKKO-EBELN.
DATA: LT_CELL1 TYPE TABLE OF LVC_S_ROID,
LS_ROW_ID TYPE LVC_S_ROID,
LS_COL_ID TYPE LVC_S_COL.
DATA: LWA_CELL1 LIKE LINE OF LT_CELL1.
WA_EXCL-FIELDNAME = 'MANDT'.
APPEND WA_EXCL TO IT_EXCL.
CALL FUNCTION 'TABLE_GET_KEY_TO_SET_CUR_ROW'
EXPORTING
TABLE = 'EKKO'
IMPORTING
TABLE_KEY = LV_EBELN
TABLES
EXCLUDE_FIELDS = IT_EXCL
EXCEPTIONS
CANCELLED_BY_USER = 1
TABLE_NOT_FOUND = 2
OTHERS = 3.
IF SY-SUBRC EQ 0.
SHIFT LV_EBELN LEFT DELETING LEADING SPACE.
MOVE LV_EBELN+0(10) TO LV_PO.
READ TABLE GT_FINAL INTO WA_FINAL WITH KEY EBELN = LV_PO.
CALL METHOD R_GRID->GET_SCROLL_INFO_VIA_ID
iMPORTING
ES_ROW_NO = LS_ROW_ID
ES_COL_INFO = LS_COL_ID.
LS_ROW_ID-ROW_ID = sy-tabix.
LS_COL_ID-FIELDNAME = 'EKGRP'.
data: ls_row type LVC_S_ROW,
ls_col type LVC_S_COL.
ls_row-index = 2.
CALL METHOD r_grid->set_scroll_info_via_id
EXPORTING
IS_ROW_INFO = ls_row
is_col_info = ls_col.
ENDIF.
**Row and column of the alv are refreshed after changing values
STABLE-ROW = 'X'.
STABLE-COL = 'X'.
*REfreshed ALV display with the changed values
*This ALV is non editable and contains new values
CALL METHOD R_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = STABLE
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.
Please help!! -
How to implement functionkeys on the ALV GRID tool bar
Hello All,
I need to implement functionkeys(Ex.given below) to the standard buttons like Ascending order etc. on the ALVGRID Tool Bar . I have implementedObject orient concept( Methods) to display the out put.I tried by using set pf-status but it is not comming.
Ex:
ALV Grid Toll Bar Buttons ( Func.Keys )
Print Preview ( CtrlShiftF10)
Sort in Ascending order ( Ctrl+F6 )
Thanks in Advance.
Vijay
Edited by: Vijay Reddy on Aug 19, 2008 10:12 AM
Edited by: Vijay Reddy on Aug 19, 2008 10:13 AMHi,
check this code,
REPORT zcl_timesheet_approval MESSAGE-ID zcl_msg.
* CLASS L_CL_EVENTS DEFINITION *
* Class for inserting buttons on the toolbar *
CLASS l_cl_events DEFINITION.
PUBLIC SECTION.
METHODS:
toolbar FOR EVENT toolbar
OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
user_command FOR EVENT user_command
OF cl_gui_alv_grid
IMPORTING e_ucomm .
ENDCLASS. " L_CL_EVENTS DEFINITION
* CLASS L_CL_EVENTS IMPLEMENTATION *
* Implementation of class L_CL_EVENTS *
CLASS l_cl_events IMPLEMENTATION.
METHOD toolbar.
PERFORM event_toolbar USING e_object.
ENDMETHOD. " TOOLBAR
METHOD user_command.
PERFORM event_ucomm USING e_ucomm.
ENDMETHOD. " USER_COMMAND
ENDCLASS. " L_CL_EVENTS IMPLEMENTATION
CONSTANTS:
c_boolean_yes(1) TYPE c " Boolean - yes
VALUE 'X',
c_approve_status(1) TYPE c " Approval status
VALUE 'A',
c_rej_status(1) TYPE c " Rejected status
VALUE 'R',
c_save_status(1) TYPE c " Save status
VALUE 'S',
c_fcode_approve(7) TYPE c " Function code - APPROVE
VALUE 'APPROVE',
c_fcode_rej(6) TYPE c " Function code - REJECT
VALUE 'REJECT',
c_fcode_back(4) TYPE c " Function code - BACK
VALUE 'BACK',
c_fcode_onli(4) TYPE c " Function code - EXECUTE
VALUE 'ONLI',
c_fcode_exit(4) TYPE c " Function code - EXIT
VALUE 'EXIT',
c_fcode_cancel(6) TYPE c " Function code - CANCEL
VALUE 'CANCEL',
c_zero(1) TYPE c " Constant value 0
VALUE '0',
c_alv_scr(7) TYPE c " GUI status : ALV screen
VALUE 'ALV_SCR'.
* Field-string declarations...........................................
DATA:
* Field-string to build fieldcat.
fs_fcat TYPE lvc_s_fcat,
* Field-string for t_temp
fs_temp TYPE type_s_temp.
* Working variables...................................................
* Internal table declarations........................................
DATA:
* Internal table to build fieldcat.
t_fcat TYPE lvc_t_fcat,
* For ALV ...........................................................
DATA:
* To create instance for cl_gui_custom_container
g_grid TYPE REF TO cl_gui_custom_container,
* To create instance for cl_gui_alv_grid
g_alv TYPE REF TO cl_gui_alv_grid,
* To create instance for l_cl_events
g_events TYPE REF TO l_cl_events,
* To assign name for custom container
g_container TYPE scrfname VALUE 'CONTAINER',
* To assign layout
g_fcatlayo TYPE lvc_s_layo.
* AT SELECTION-SCREEN EVENT *
AT SELECTION-SCREEN.
* To perform user actions on the selection screen
PERFORM user_command.
* MODULE STATUS_0100 OUTPUT *
* This module will create the objects for the instance and display *
* the records *
MODULE status_0100 OUTPUT.
SET PF-STATUS c_alv_scr.
PERFORM set_titlebar USING w_display.
* If program executed in foreground.
IF sy-batch IS INITIAL.
* If g_grid is empty.
IF g_grid IS INITIAL.
* To create object for instance grid
CREATE OBJECT g_grid
EXPORTING
container_name = g_container.
* To create object for object grid
CREATE OBJECT g_alv
EXPORTING
i_parent = g_grid.
ELSE.
* IF W_SUBMIT EQ
CALL METHOD g_alv->refresh_table_display.
ENDIF. " IF G_GRID IS INITIAL
ENDIF. " IF SY-BATCH IS INITIAL
REFRESH t_fcat.
* If w_display eq 'X' .
IF w_display EQ c_boolean_yes.
* To display all records except saved data
PERFORM display_allrecords.
ENDIF. " IF W_FLAG EQ C_BOOLEAN_YES
IF w_submit EQ c_boolean_yes.
* To display submitted records
PERFORM submitted_records.
ENDIF. " IF W_SUBMIT EQ C_BOOLEAN_YES
ENDMODULE. " STATUS_0100 OUTPUT
* MODULE USER_COMMAND_0100 INPUT *
* To perform user actions in the screen 100 *
MODULE user_command_0100 INPUT.
* To update the data in the ALV grid
PERFORM check_changed_data.
w_okcode = ok_code.
CLEAR ok_code.
CASE w_okcode.
WHEN c_fcode_back.
LEAVE TO SCREEN 0.
WHEN c_fcode_exit OR c_fcode_cancel.
LEAVE PROGRAM.
ENDCASE. " CASE W_OKCODE
ENDMODULE. " USER_COMMAND_0100
* FORM BUILD_FCAT *
* To build the field catalog giving managers comment in editable mode *
* -->PR_Tabname type lvc_tname *
* -->PR_Fieldname type lvc_fname *
* -->PR_Coltext type lvc_txtcol *
* -->PR_Colpos type lvc_colpos *
FORM build_fcat USING pr_tabname TYPE lvc_tname
pr_fieldname TYPE lvc_fname
pr_coltext TYPE lvc_txtcol
pr_colpos TYPE lvc_colpos.
CLEAR fs_fcat.
fs_fcat-tabname = pr_tabname.
fs_fcat-fieldname = pr_fieldname.
fs_fcat-coltext = pr_coltext.
fs_fcat-col_pos = pr_colpos.
IF fs_fcat-fieldname EQ 'MNGCOMMENT'.
fs_fcat-edit = c_boolean_yes.
fs_fcat-lowercase = c_boolean_yes.
fs_fcat-dd_outlen = 60.
ELSE.
fs_fcat-edit = space.
ENDIF. " IF FS_FCAT-FIELDNAME...
APPEND fs_fcat TO t_fcat.
ENDFORM. " BUILD_FCAT
* FORM BUILD_FCATD *
* To build fieldcatalog in the display mode *
* -->pr_Tabname type lvc_tname *
* -->pr_Fieldname type lvc_fname *
* -->pr_Coltext type lvc_txtcol *
* -->pr_Colpos type lvc_colpos *
FORM build_fcatd USING pr_tabname TYPE lvc_tname
pr_fieldname TYPE lvc_fname
pr_coltext TYPE lvc_txtcol
pr_colpos TYPE lvc_colpos .
CLEAR fs_fcat.
fs_fcat-tabname = pr_tabname.
fs_fcat-fieldname = pr_fieldname.
fs_fcat-coltext = pr_coltext.
fs_fcat-col_pos = pr_colpos.
fs_fcat-edit = space.
APPEND fs_fcat TO t_fcat.
ENDFORM. " BUILD_FCATD
* FORM ALV_DISPLAY *
* To display data in ALV *
* --> pr_table type standard table *
* --> pr_fcat type lvc_t_fcat *
FORM alv_display USING pr_table TYPE STANDARD TABLE
pr_fcat TYPE lvc_t_fcat .
* Local data declaration....
DATA: lt_exclude TYPE ui_functions.
* To exclude buttons on the ALV grid
PERFORM exclude_tb_functions CHANGING lt_exclude.
* To display ALV
CALL METHOD g_alv->set_table_for_first_display
EXPORTING
i_default = space
is_layout = g_fcatlayo
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = pr_table[]
it_fieldcatalog = pr_fcat[].
ENDFORM. " ALV_DISPLAY
* FORM EVENT_TOOLBAR *
* Setting toolbar in the alv grid *
* -->E_OBJECT TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET *
FORM event_toolbar USING e_object
TYPE REF TO cl_alv_event_toolbar_set.
* Local declaration for the button.
DATA: ls_toolbar TYPE stb_button.
* To add Approve button
ls_toolbar-function = c_fcode_approve.
ls_toolbar-butn_type = c_zero.
ls_toolbar-text = text-001.
APPEND ls_toolbar TO e_object->mt_toolbar.
* To add Reject button
CLEAR ls_toolbar.
ls_toolbar-function = c_fcode_rej.
ls_toolbar-butn_type = c_zero.
ls_toolbar-text = text-013.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDFORM. " EVENT_TOOLBAR
* FORM EXCLUDE_TB_FUNCTIONS *
* To exclude buttons from ALV grid *
* <--> PR_EXCLUDE TYPE UI_FUNCTIONS *
FORM exclude_tb_functions CHANGING pr_exclude TYPE ui_functions.
* Local data declaration...
DATA ls_exclude TYPE ui_func.
* To remove the buttons on the ALV grid.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND ls_exclude TO pr_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND ls_exclude TO pr_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND ls_exclude TO pr_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND ls_exclude TO pr_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
APPEND ls_exclude TO pr_exclude.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
* FORM EVENT_UCOMM *
* After Input in the ALV grid,if user select record and press *
* approve or reject then the record will get updated *
* --> PR_ucomm type sy-ucomm *
FORM event_ucomm USING pr_ucomm LIKE sy-ucomm.
CASE pr_ucomm.
* If e_ucomm contains 'APP' i.e.function code for Approve button
WHEN c_fcode_approve. " To approve selected record
PERFORM app_timesheet USING c_approve_status.
* If e_ucomm contains 'REJ' i.e. function code for Reject
WHEN c_fcode_rej. " To reject selected record
PERFORM app_timesheet USING c_rej_status.
ENDCASE. " CASE E_UCOMM
ENDFORM. " EVENT_UCOMM
* FORM APP_TIMESHEET *
* To get the selected records and update the records in database *
* --> pr_status type char01 *
FORM app_timesheet USING pr_status TYPE char01 .
* Local data declaration......
DATA:
lt_marked_rows TYPE lvc_t_roid, " Table to get rowid
l_fs_marked_row LIKE LINE OF lt_marked_rows.
" Field-string for lt_marked_rows
* To get all the selected rows in the table lt_marked_rows
CALL METHOD g_alv->get_selected_rows
IMPORTING
et_row_no = lt_marked_rows.
* Reading each row id and updating the database.
LOOP AT lt_marked_rows INTO l_fs_marked_row.
* Reading the table t_timesheet with rowid
READ TABLE t_timesheet INTO fs_timesheet INDEX
l_fs_marked_row-row_id.
* If record is there in the table.
IF sy-subrc EQ 0.
CLEAR fs_timesheet-appstatus.
GET PARAMETER ID 'ZEMPID' FIELD w_empid.
* Changing the appstatus.
fs_timesheet-appstatus = pr_status.
fs_timesheet-approvedby = w_empid.
* Updating the database table.
UPDATE zcl_timesheet FROM fs_timesheet.
IF sy-subrc EQ 0.
fs_temp-empid = fs_timesheet-empid.
fs_temp-workdate = fs_timesheet-workdate.
fs_temp-linenum = fs_timesheet-linenum.
append fs_temp to t_temp.
ENDIF. " IF SY-SUBRC EQ 0.
ENDIF. " IF SY-SUBRC EQ 0
ENDLOOP. " LOOP AT LT_MARKED_ROWS...
perform delete_data .
PERFORM refresh_table USING pr_status.
ENDFORM. " APP_TIMESHEET
* FORM CHECK_CHANGED_DATA *
* To change the data *
* No parameters are passsed to this subroutine *
FORM check_changed_data .
* To change the data.
CALL METHOD g_alv->check_changed_data.
ENDFORM. " CHECK_CHANGED_DATA
* FORM REFFRESH_TABLE *
* To refresh output table and issue message according p_status *
* -->PR_STATUS TYPE CHAR01 *
FORM refresh_table USING pr_status TYPE char01.
* To refresh output table.
CALL METHOD g_alv->refresh_table_display.
* Depending upon pr_status message is given.
IF pr_status EQ c_approve_status.
MESSAGE s001.
ELSE.
MESSAGE s002.
ENDIF. " IF P_STATUS EQ C_APPROVE_STATUS
ENDFORM. " REFRESH_TABLE
* FORM SET_TITLEBAR *
* To set titlebar on the screen 100. *
* -->PR_STATUS TYPE CHAR01 *
FORM set_titlebar USING pr_status TYPE char01.
* If pr_status eq 'X'.
IF pr_status EQ c_boolean_yes.
SET TITLEBAR c_alv_scr WITH text-017.
ELSE.
SET TITLEBAR c_alv_scr WITH text-018.
ENDIF. " IF P_STATUS EQ C_BOOLEAN_YES
ENDFORM. " SET_TITLEBAR
* FORM USER_COMMAND *
* According to sy-ucomm the action is performed in the screen 100 *
* No parameters are passsed to this subroutine *
FORM user_command .
CASE sy-ucomm.
* If p_app is selected, submitted data will be displayed for approval
WHEN c_fcode_onli OR c_fcode_approve.
CLEAR sy-ucomm.
* To display the submitted records.
IF p_app EQ c_boolean_yes.
w_submit = c_boolean_yes.
* To get submitted records
PERFORM get_data.
ENDIF. " IF P_APP EQ C_BOOLEAN_YES
* To display all records according to selection.
IF p_disp EQ c_boolean_yes.
w_display = c_boolean_yes.
* To display
PERFORM display_all.
CLEAR w_display.
ENDIF. " IF P_DISP EQ C_BOOLEAN_YES
IF p_sdn EQ c_boolean_yes.
PERFORM GET_GRAPH.
ENDIF.
ENDCASE. " CASE SY-UCOMM
ENDFORM. " USER_COMMAND
* FORM DISPLAY_ALLRECORDS *
* To display all the records in the display mode *
* No parameters are passsed to this subroutine *
FORM display_allrecords .
CLEAR w_display.
PERFORM build_fcatd USING 'T_TIME' 'WORKDATE' text-002 '1'.
PERFORM build_fcatd USING 'T_TIME' 'EMPID' text-009 '2'.
PERFORM build_fcatd USING 'T_TIME' 'PROJECTID' text-003 '3'.
PERFORM build_fcatd USING 'T_TIME' 'PROJECTNAME' text-004 '4'.
PERFORM build_fcatd USING 'T_TIME' 'OBJECTID' text-005 '5'.
PERFORM build_fcatd USING 'T_TIME' 'OBJECTNAME' text-006 '6'.
PERFORM build_fcatd USING 'T_TIME' 'ACTIVITYID' text-007 '7'.
PERFORM build_fcatd USING 'T_TIME' 'ACTIVITYNAME' text-008 '8'.
PERFORM build_fcatd USING 'T_TIME' 'TIMEWORKED' text-010 '9'.
PERFORM build_fcatd USING 'T_TIME' 'DESCRIPTION' text-011 '10'.
PERFORM build_fcatd USING 'T_TIME' 'APPSTATUS' text-012 '11'.
PERFORM build_fcatd USING 'T_TIME' 'BILLSTATUS' text-016 '12'.
PERFORM build_fcatd USING 'T_TIME' 'SDNSTATUS' text-019 '13'.
PERFORM build_fcatd USING 'T_TIME' 'MNGCOMMENT' text-014 '14'.
PERFORM alv_display USING t_time t_fcat.
ENDFORM. " DISPLAY_ALLRECORDS
* FORM SUBMITTED_RECORDS *
* To display submitted records for the manager to approve *
* No parameters are passsed to this subroutine *
FORM submitted_records .
CLEAR w_submit.
* To create object for instance g_events
CREATE OBJECT g_events.
* If w_first equal to space
IF w_first IS INITIAL.
SET HANDLER g_events->toolbar
FOR g_alv.
w_first = c_boolean_yes.
ENDIF. " IF W_FIRST IS INITIAL..
SET HANDLER g_events->user_command
FOR g_alv.
g_fcatlayo-sel_mode = c_approve_status.
REFRESH t_fcat.
* to fill ur field cat table.
ENDFORM. " SUBMITTED_RECORDS
* FORM DELETE_DATA *
* This form is used to delete thedata from output table after updating *
* the database *
* No parameters are passsed to this subroutine *
form delete_data .
loop at t_temp into fs_temp.
loop at t_timesheet into fs_timesheet where
empid = fs_temp-empid
and workdate = fs_temp-workdate
and linenum = fs_temp-linenum.
delete t_timesheet index sy-tabix.
endloop. " LOOP AT T_TEMP INTO FS_TEMP
endloop . " LOOP AT T_TIMESHEET INTO FS_T..
endform. " DELETE_DATA
Hope it helps you.
Regards
Manjari. -
ALV grid - using f4 search help - want separate value from hit list
I have the following scenario that I am trying to resolve.
I have created my own search help with a search help exit for a bespoke maintenance table which lists categories against HR positions which are to receive workflow for these categories. I am designing a front-end for this table using an ALV grid whereby the person holding that position (i.e. name) is shown instead of position number. The search help allows you to select by First name and last name and brings up a hit list which includes employee number, first name last name, formatted name field, position number, position description and org unit it belongs in.
The issue occurs where the list brings back more than one hit.
e.g.:
1 Fred Bloggs Fred Bloggs 50000001 pos1 org 1
2 Frederic Bloggs Fred Bloggs 50000002 pos2 org 3
If you select an entry, the formatted name field goes in the ALV grid field. I call the search help via F4IF_FIELDVALUE_REQUEST using the onf4 event .
What I want to do is retrieve the position number of the entry selected and put this into another table without having to add this to my ALV grid and make available for input. I want to use name only for the input in my ALV grid (i.e. if I select the second example, the return table in F4IF_FIELDVALUE_REQUEST shows the name Fred Bloggs but does not show the position number which I need to add to another table to update my maintenance table).
Can anyone suggest any way around this?
Many thanks
LarissaYou are right, you can add this fields as an import parameter to the list.
In Custom search help you must have marked fields as Export or Import parameters.
If field is marked as Export parameters, it will be displayed in the selection pop up.
If Import paramter check box is selected then this will be imported to the screen.
Check this SAP documentation for both these options -
Flag for IMPORT parameter of the search help
Flag if the parameter is an import parameter.
Context information from the processed input template (screen) can be
copied to the help process with an import parameter. Where an import
parameter gets its values from is defined when the search help is
attached to the corresponding field of the input template.
Flag for EXPORT parameter of the search help
Flag if the parameter is an export parameter.
Values can be returned from the hit list to the input template (screen)
with an export parameter. The fields of the input template in which the
contents of the export parameter are returned are defined by the search
help attachment.
Message was edited by: Ashish Gundawar -
Hello All,
Is it possible to have a user input in ALV grid. I know there can be editable columns/cells but suppose the application demands an input field to be placed in ALV Grid where the user will enter some value.
Could someone please suggest if this can be done.
Regards
IndrajitHere's THE definitive way to do it.
This little proggy demonstrates the following.
1) Create a DYNAMIC FCAT for an internal table with USER defined fields (i.e non ddic) and colour some columns in the FCAT.
2) Create a DYNAMIC TABLE.
3) Define a subclass of CL_GUI_ALV_GRID so you can access some very useful protected methods and attributes - you can get original and changed table IN ROWS which is a lot easier sometimes than messing around with individual
cells.
4) Create extra buttons on the toolbar.
5) Define EVENT handlers including data change so you can get control when the user enters data. YOU DON'T NEED PAI anymore with event handlers.
6) Call methods in your subclass of CL_GUI_ALV_GRID (you can also call methods in CL_GUI_ALV_GRID by virtue of Inheritance) from methods in your event handler class.
7) Display an editable Grid.
This method will work for almost any conditions you need to use.
I'm sure this covers all the bases -- please reply if any queries.
Run the program, click on the EDIT button and enter your data. Press ENTER when done.
All you need to do is copy this code and create one empty screen (SE51) with a custom container called CCONTAINER1 with the following logic in it.
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
(In the program you don't actually do anything in the PAI as the event handler takes care of this)
Now here's the program
PROGRAM zdynfieldcat.
class zcltest definition deferred. "For field symbol reference.
Simple test of dynamic ITAB with user defined (not ddic) fields
Build dynamic fcat
Table structure obtained via new RTTI functionality
use ALV grid to display and edit.
Create a blank screen 100 with a custom container called CCONTAINER1.
Define field symbols as these can't be defined in classes
field-symbols: <dyn_table> type standard table,
<g2> type ref to zcltest,
<g1> type ref to cl_gui_custom_container,
<actual_tab> type standard table,
<outtab> type table,
<fs1> type ANY,
<FS2> TYPE TABLE,
<fs3> type table,
<fs4> type table,
<fs5> type table.
class zcltest definition inheriting from cl_gui_alv_grid.
define this as a subclass so we can access the protected attributes
of the superclass cl_gui_alv_grid
public section.
types: g4 type ref to cl_gui_custom_container.
types: g3 type ref to cl_alv_changed_data_protocol.
data: i_parent type g4,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
zog like line of lr_rtti_struc->components. "RTTI
types: struc like zog.
types: struc1 type table of struc.
methods:
constructor
importing i_parent type g4,
disp_tab
importing p_er_data_changed type g3,
create_dynamic_fcat
importing zogt type struc1
exporting it_fldcat type lvc_t_fcat.
Protected section.
data: stab type ref to data,
wa_it_fldcat type lvc_s_fcat,
c_index type sy-index.
endclass.
class zcltest implementation.
METHOD constructor.
CALL METHOD super->constructor
EXPORTING
i_appl_events = 'X'
i_parent = i_parent.
endmethod.
method disp_tab.
mt_outtab is the data table held as a protected
attribute in class cl_gui_alv_grid.
assign me->mt_outtab->* TO <outtab>. "Original data
assign p_er_data_changed->mp_mod_rows TO <FS1>.
stab = p_er_data_changed->mp_mod_rows.
assign p_er_data_changed->mt_inserted_rows to <fs3>.
assign p_er_data_changed->mt_deleted_rows to <fs4>.
assign p_er_data_changed->mt_mod_cells to <fs5>.
assign stab->* TO <fs2>.
do whatever you want with <outtab>
contains data BEFORE changes each time.
Note that NEW (Changed) table has been obtained
already by call to form
check_data USING P_ER_DATA_CHANGED
TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL.
Entered data is in table defined by <fs2>
In this method you can compare original and changed data.
Easier than messing around with individual cells.
do what you want with data in <fs2> validate / update / merge etc
endmethod.
method create_dynamic_fcat.
loop at zogt into zog.
c_index = c_index + 1.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
if c_index eq 2.
wa_it_fldcat-emphasize = 'C411'.
endif.
if c_index eq 3.
wa_it_fldcat-emphasize = 'C511'.
endif.
append wa_it_fldcat to it_fldcat .
endloop.
endmethod. "create_dynamic_fcat
endclass. "zcltest IMPLEMENTATION
class lcl_grid_event_receiver definition.
public section.
note that zcltest inherits all of events etc from
class cl_gui_alv_grid so specify event handler for
zcltest.
methods:
handle_data_changed
for event data_changed of zcltest
importing er_data_changed,
toolbar
for event toolbar of zcltest
importing e_object
e_interactive,
user_command
for event user_command of zcltest
importing e_ucomm.
endclass.
class lcl_grid_event_receiver implementation.
method handle_data_changed.
code whatever required after data entry.
various possibilites here as you
can get back Cell(s) changed
columns or the entire updated table.
Data validation is also possible here.
Note here the field sybol <g2> contains our
instance of class zcltest so we can now
call any methods / access
attributes of that class from this method
in our event handler class.
call method <g2>->disp_tab
EXPORTING
p_er_data_changed = er_data_changed.
endmethod. "handle_data_changed
method toolbar.
data : ls_toolbar type stb_button.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EDIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Edit' to ls_toolbar-text.
move icon_change_text to ls_toolbar-icon.
move 'Click2Edit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'UPDA' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Update' to ls_toolbar-text.
move icon_system_save to ls_toolbar-icon.
move 'Click2Update' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 0 to ls_toolbar-butn_type.
move 'EXIT' to ls_toolbar-function.
move space to ls_toolbar-disabled.
move 'Exit' to ls_toolbar-text.
move icon_system_end to ls_toolbar-icon.
move 'Click2Exit' to ls_toolbar-quickinfo.
append ls_toolbar to e_object->mt_toolbar.
endmethod. "toolbar
method user_command.
case e_ucomm .
when 'EDIT'. "From Tool bar
perform set_input.
perform init_grid.
when 'UPDA'. "From Tool bar
perform refresh_disp.
perform update_table.
when 'EXIT'. "From Tool bar
leave program.
endcase.
endmethod. "user_command
endclass. "lcl_grid_event_receiver IMPLEMENTATION
program data
include <icon>.
define any old internal structure NOT in DDIC
types: begin of s_elements,
anyfield1(20) type c,
anyfield2(20) type c,
anyfield3(20) type c,
anyfield4(20) type c,
anyfield5(11) type n,
end of s_elements.
data: wa_element type s_elements,
wa_data type s_elements.
Note new RTTI functionality allows field detail
retrieval at runtime for dynamic tables.
data:
grid1 type ref to zcltest,
grid_handler type ref to lcl_grid_event_receiver,
c_dec2 type s_elements-anyfield5,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat,
lr_rtti_struc TYPE REF TO cl_abap_structdescr, "RTTI
lt_comp TYPE cl_abap_structdescr=>component_table,"RTTI
ls_comp LIKE LINE OF lt_comp, "RTTI
zog like line of lr_rtti_struc->components, "RTTI
struct_grid_lset type lvc_s_layo,
l_valid type c,
new_table type ref to data.
types: struc like zog.
data: zogt type table of struc,
grid_container1 type ref to cl_gui_custom_container,
g_event_receiver type ref to lcl_grid_event_receiver,
ok_code like sy-ucomm,
i4 type int4.
start-of-selection.
call screen 100.
module status_0100 output.
if grid_container1 is initial.
create object grid_container1
exporting
container_name = 'CCONTAINER1'.
assign grid_container1 to <g1>.
create object grid1
exporting i_parent = grid_container1.
we need reference to this instance so we can use
Methods etc of zcltest class and alv (superclass)
in our event receiver class.
assign grid1 to <g2>.
create object grid_handler.
set handler:
grid_handler->user_command for grid1,
grid_handler->toolbar for grid1,
grid_handler->handle_data_changed for grid1.
Get the Internal table structure
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( wa_data ).
Build field catalog just use basic data here
colour specific columns as well
zogt[] = lr_rtti_struc->components.
call method grid1->create_dynamic_fcat
EXPORTING
zogt = zogt
IMPORTING
it_fldcat = it_fldcat.
Create dynamic internal table and assign
to field symbol.
Use dynamic field catalog just built.
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = new_table.
assign new_table->* to <dyn_table>.
perform populate_dynamic_itab.
perform init_grid.
perform register_enter_event.
set off ready for input initially
i4 = 0.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endif.
endmodule. "status_0100 OUTPUT
module user_command_0100 input.
*PAI not needed in OO ALV anymore as User Commands
are handled as events
*in method user_command.
we can also get control if any data was entered
and the ENTER is pressed by
raising an event.
Control then returns to method handle_data_changed.
endmodule. "user_command_0100 INPUT
form populate_dynamic_itab.
load up a line of the dynamic table
c_dec2 = c_dec2 + 11.
wa_element-anyfield1 = 'Tabbies'.
wa_element-anyfield2 = 'ger.shepards'.
wa_element-anyfield3 = 'White mice'.
wa_element-anyfield4 = 'Any old text'.
wa_element-anyfield5 = c_dec2.
append wa_element to <dyn_table>.
endform. "populate_dynamic_itab
form exit_program.
call method grid_container1->free.
call method cl_gui_cfw=>flush.
leave program.
endform. "exit_program
form refresh_disp.
call method grid1->refresh_table_display.
endform. "refresh_disp
form update_table.
The dynamic table here is the changed table
read from the grid
after user has changed it
Data can be saved to DB or whatever.
loop at <dyn_table> into wa_element.
do what you want with the data here
endloop.
switch off edit mode again for next function
i4 = 0.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "update_table
form set_input.
i4 = 1.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "set_input
form switch_input.
if i4 = 1.
i4 = 0.
else.
i4 = 1.
endif.
call method grid1->set_ready_for_input
EXPORTING
i_ready_for_input = i4.
endform. "switch_input
form init_grid.
Enabling the grid to edit mode,
struct_grid_lset-edit = 'X'. "To enable editing in ALV
struct_grid_lset-grid_title = 'Jimbos Test'.
call method grid1->set_table_for_first_display
EXPORTING
is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
endform. "init_grid
form register_enter_event.
call method grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
Instantiate the event or it won't work.
create object g_event_receiver.
set handler g_event_receiver->handle_data_changed for grid1.
endform. "register_enter_event
Have fun with this
Cheers
jimbo -
Re: Increasing Column Header Length While Printing in ALV Grid
Hi
For some column headers in a report, the translations in Turkey are more than 40 characters, because of which while executing the report in TR language, the column header is getting truncated.
So, I would like to know if we can increase the column header length while printing the ALV Grid(OO ALV) output.
Or else, Is there any way where we can divide the column header into 2 rows.
Please let me know.
Thanks and Regards,
Vishwa.Jose and Sivaram,
Thanks for replying.
The problem we have is with the column headers, there is a limit of 40 characters for the column header in ALV reports. So, increasing the outputlen also did not help.
Regards,
Vishwa.
Maybe you are looking for
-
Adobe Bridge CS3 - does not display thumbnails for Canon 40D or 50D RAW files
I wanted to use Bridge to view my Canon EOS 50D RAW files and it does not display the thumbnails, just icons. I checked my 40D cr2 files and saw same thing. I have purged the cache and rest the cache preferences and it has not helped. I would like to
-
The AMD Radeon HD 7770 graphics card that came with the system is going bad, so I thought rather than just replacing it with a new one I would upgrade to an R9 270X from XFX. The 600W power supply that came on the PC can handle it, and the 2nd 6-pin
-
Mobile Design in Business Catalyst
Is there any tutorials and/or videos that teaches us how to make a mobile version of a business catalyst site??
-
SharePoint in DSfW environment...
Hi I'm looking for any information and/or experiences about getting SharePoint working in a DSfW environment (OES2SP3) In particular interested in kerberos authentication... Anyone had any joy?!? Cheers David
-
Software update via desktop manager failed, phone will not boot
I used the Desktop Software (I had to update this first to version 6.00.43; anyway, that's what the Rim.Desktop.exe file properties in Windows Explorer says it is) to update my Curve 8900 's software. It went through the first two steps of downloadin