Validations and default Values in ALV Grid
All,
I am using "set_table_for_first_display" to display a grid with empty editable rows wherein which users can enter data and process certain transactions.
My requirement is to know if we can provide drop-downs and default values in this grid. for ex. if user want to insert a row, that row should automatically have some default values like company code, sales org etc.
Also, if there is an error while validating the data, I should be able to set the focus on that field while displaying the error message. I was able to display error message but could not set the focus on the field that need to be corrected.
Your earlier response is much appreciated.
Regards
Kasi
Hi kasi,
check these links:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/an easy reference for alv grid control.pdf
http://www.abap4.it/download/ALV.pdf
hope this helps,
keerthi.
Similar Messages
-
Need to add Header and footer in an alv grid display output.
How can I add header and footer in an alv grid dispay output.
For the grid display, I am using the function module "REUSE_ALV_GRID_DISPLAY".HI,
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE'
i_callback_html_end_of_list = 'END_OF_LIST_HTML'
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
i_save = 'X'
tables
t_outtab = it_ekko
exceptions
program_error = 1
others = 2.
FORM end_of_list_html USING end TYPE REF TO cl_dd_document.
DATA: ls_text TYPE sdydo_text_element,
l_grid TYPE REF TO cl_gui_alv_grid,
f(14) TYPE c VALUE 'SET_ROW_HEIGHT'.
ls_text = 'Footer title'.
adds and icon (red triangle)
CALL METHOD end->add_icon
EXPORTING
sap_icon = 'IL'.
adds test (via variable)
CALL METHOD end->add_text
EXPORTING
text = ls_text
sap_emphasis = 'strong'.
adds new line (start new line)
CALL METHOD end->new_line.
display text(bold)
CALL METHOD end->add_text
EXPORTING
text = 'Bold text'
sap_emphasis = 'strong'.
adds new line (start new line)
CALL METHOD end->new_line.
display text(normal)
CALL METHOD end->add_text
EXPORTING
text = 'Nor'.
adds new line (start new line)
CALL METHOD end->new_line.
display text(bold)
CALL METHOD end->add_text
EXPORTING
text = 'Yellow '
sap_emphasis = 'str'.
adds and icon (yellow triangle)
CALL METHOD end->add_icon
EXPORTING
sap_icon = 'IC''.
display text(normal)
CALL METHOD end->add_text
EXPORTING
text = 'Mor'.
*set height of this section
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->parent->parent->(f)
EXPORTING
id = 3
height = 14.
ENDFORM. "end_of_list_html.
This will solve it. Post if you need more help in this.
Regards,
Madhu. -
How to change sub total value in ALV Grid.
Hi All,
Can u please explain how to change SUBTOTAL Value in ALV Grid display based on another field value.
EX; F1 subtotal is initial then we have to modify the F2 sub total to 9999.9.
Thanks
Radha.Hi Radha,
I doubt if that can be changed....because the event that i was referring to in my previous post works with ALV List display...But in any case you can try that.....
There is an event in SLIS....(As i told you, i dont remember the name and currently i dont have access to SAP system, so i am not able to verify and let you know that event name).....
Other thatn TOP and END of PAGE events, there is an event for sub-total text......i think it would start with "SUBTOTAL"...
you need to use that event in your events table and pass it to ALV Grid display.
Then create a sub-routine with that name (As you do for TOP-OF-PAGE event)....and in this event you can change the values in runtime (PROVIDED, this event gets triggered for ALV GRID).....
If this does not work, i think calculating sub-totals while you build the internal table would be a better option....(If you have time constraint....else you can do some more research on the same)........
Best Regards,
Ram. -
Medium, min, and max values on ALV
Hi friends ! How are are you ? Fine ?
How can i calc medium, min, and max values on ALV ?
Thanks !Hi Fabrício
I think you set fieldcatalog at runtime dynamically to arrange dynamic columns. So, while you are setting it just set proper values to the attribute "do_sum" for relevant fields.
For more information how to set fieldcatalog dynamically, you can refer to the tutorial "An Easy Reference for ALV Grid Control".
Regards
*--Serdar [[ BC ] | https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk sag jiw=] -
Pack and Integer type in ALV grid
Hello,
Can anyone give a small example of how to display fields of type I and P in an ALV grid. Using the alv grid FM and manually filling the fieldcatalog.
Thanks for your help.Hi Moussa Khelifi ,
u can manually fill fieldcatalog like this..
form manual_filling_fieldcatalog.
X_FIELDCAT-FIELDNAME = 'ATWRT'.
X_FIELDCAT-TABNAME = 'TB_FINAL'.
X_FIELDCAT-SELTEXT_L = 'Source of Supply'(001).
X_FIELDCAT-DDICTXT = L_DDICTXT.
X_FIELDCAT-FIELDNAME = 'MATNR'.
X_FIELDCAT-TABNAME = 'TB_FINAL'.
X_FIELDCAT-SELTEXT_L = 'MATERIAL'(002).
X_FIELDCAT-DDICTXT = L_DDICTXT.
APPEND X_FIELDCAT TO TB_FIELDCAT .
endform.
u can directly pass the table to 'REUSE_ALV_GRID_DISPLAY'
regardless of type p or i fields in it.
Regards,
kiran B -
How to merge rows with similar values in alv grid display in webdynpro
Hi experts,
i want to know about how to merge rows with similar values in alv grid display of webdynpro.grouping rows is possible in table display in webdynpro but i am not able to do row grouping in the alv grid display in webdynpro.
kindly suggest.
thanks ,
Anita.Hi Anita,
did you find a solution for this? I have opened a Thread, if you know the answer maybe you could help me out:
Is there an ALV function similar to the TABLE Row grouping?
Thanx in advanced!!!
Kind Regards,
Gerardo J -
How to calculate subtol and total values in alv.
Hi expert,
I want to calculate the subtol and total values in alv as follows,
example:
month: Jan Fer Mar Apr
-50 -30 40 -10
-20 -13 -12 -10
subtotal -70 -43 28 -20
-10 -10 -10 -10
-10 -31 -15 -10
subtotal -20 -41 -25 -20
total -90 -84 3 -40
when i put '-' in front of the month,i define the month type c,
and when the type is c,it cann't calculate the subtotals and totals.
how can i do can make the layout like the example.
thanks...
Edited by: Heum Kim on Aug 25, 2008 3:54 AMThe below code is not generic one. I am just looking for generic one. You try to fix it using the similiar approach.
REPORT ZTEST_ALV_DEC.
data: fcat type lvc_s_fcat,
tfcat type lvc_t_fcat.
data: begin of itab occurs 0,
carrid(10),
quan type DEC_16_02_S,
end of itab.
itab-carrid = 'AA'.
itab-quan = '-10000.00'.
append itab.
fcat-fieldname = 'QUAN'.
fcat-tabname = 'ITAB'.
fcat-decimals_o = 2.
fcat-edit_mask = 'V__,___.__'. "This is not generic
append fcat to tfcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IT_FIELDCAT_LVC = tfcat
TABLES
t_outtab = itab
EXCEPTIONS
PROGRAM_ERROR = 1 -
When i add a new row in ALV in webdynpro, i need some columns to have some default values. I am using the standard functionality of ALV in webdynpro to append rows (that is by setting the set_editable property to abap_true). Could someone tell how i can achieve this.
regards,
PriyankHi Juan,
thanks for the reply,
What i need is slightly different. When i append new rows, the new row should have default values based on the last row in the grid. For example, there are start dates and end dates in the grid, for the new row, the start date should be one day after the end date in the preceding row. Could you tell me how i can achieve this.
regards,
Priyank -
Urgent : Insert , save and Delete in the alv grid
Hi Experts,
I am having a alv grid and displaying data by fetching from backend.
i added a toolbar buttons "Insert " "Save" and "Delete".
when i click on "Insert " button the first row of the table should be empty with input fields. i want to insert data and when i click on "save" button it should update at backend.kindly let me know how to insert empty row at starting of alv grid and also how to save and delete records..
thanks in advance.Hi Bharath,
Go through this hope u can understand.
SEL_MODE. Selection mode, determines how rows can be selected. Can have the following values:
A Multiple columns, multiple rows with selection buttons.
B Simple selection, listbox, Single row/column
C Multiple rows without buttons
D Multiple rows with buttons and select all ICON
Setting and getting selected rows (Columns) and read line contents
You can read which rows of the grid that has been selected, and dynamic select rows of the grid using methods get_selected_rows and set_selected_rows. There are similar methods for columns.
Note that the grid table always has the rows in the same sequence as displayed in the grid, thus you can use the index of the selected row(s) to read the information in the rows from the table. In the examples below the grid table is named gi_sflight.
Data declaration:
DATA:
Internal table for indexes of selected rows
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
Example 1: Reading index of selected row(s) and using it to read the grid table
CALL METHOD go_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows.
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines = 0.
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
textline1 = 'You must choose a valid line'.
EXIT.
ENDIF.
LOOP AT gi_index_rows INTO g_selected_row.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Example 2: Set selected row(s).
DESCRIBE TABLE gi_index_rows LINES l_lines.
IF l_lines > 0.
CALL METHOD go_grid->set_selected_rows
exporting
it_index_rows = gi_index_rows.
ENDIF.
Reward points if helpful.
Thanks
Naveen khan -
Text Box/Area and default value
Is it possible to display a Text Box (or Text Area) in a Form page assigned a default value and prevent the user to change it? I need to register the actual user submitting the form. I have done this in WebDB22 Text Box and #user function but in Portal 3.0.6.6.5 it seems to be impossible to prevent the user to change the text value. Deselecting Validation Options, Updatable does not seems to help. Why?
The equivalent of Webdb #user function in portal is #portal30.wwctx_api.get_user.
If you specify this as a default value for a field it will be the same as #user. Also, "inseratble" and "updatable" checkboxes control the presence of a column in INSERT and UPDATE statements, so unchecking any of those checkboxes will remove the column from a respective statement.
Thanks,
Dmitry -
Get checkbox values from alv grid
Hi,
I'm using the function REUSE_ALV_GRID_DISPLAY and I'm showing a table with a field like a checkbox.
In USER_COMMAND FORM to get selected values do as follow:
CALL METHOD REF_GRID->CHECK_CHANGED_DATA.
And then:
loop at i_pos (my table) with checkbox eq 'X'.
endloop.
The first time I execute the ALV every thing is OK but if I do any action (I use the function 'BAPI_GOODSMVT_CREATE' ...), I refresh the data and I raise the alv again. In USER COMMAND FORM the code is the same and I can not get checkbox values.
Can someone help me please?
Thanks and regards.Hi,
Check this
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = pt_grpfcat[]
it_excluding = p_grpexcltab2[]
is_layout = pt_grplayout2
i_callback_program = sy-repid
i_callback_html_top_of_page = p_header
i_callback_pf_status_set = v_status_set1
i_callback_user_command = f_user_command1
i_screen_start_column = 25
i_screen_start_line = 5
i_screen_end_column = 80
i_screen_end_line = 20
it_events = i_events[]
tables
t_outtab = i_grpoutput.
form f_user_command1 using p_ucomm type sy-ucomm
rs_selfield type slis_selfield.
data p_ref1 type ref to cl_gui_alv_grid.
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
importing
e_grid = p_ref1.
call method p_ref1->check_changed_data.
case p_ucomm.
when 'YCNC'.
leave to screen 0.
endcase.
rs_selfield-refresh = c_x. " Grid refresh < You need to fill up this
endform. " F_user_command1
aRs -
EDIT THE FIELV VALUE IN ALV GRID DISPLAY
Hi Guru ,
How can I edit the value of a particular one or two fields in ALV GRID DISPLAY .
Please reply mehi,
1.Set status of all cells to editable using the layout structure.
2.Use SET_READY_FOR_INPUT to activate the edit feature initially.
(state "editable activated").
3.Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
4.Use SET_READY_FOR_INPUT to switch between the substates.
CALL METHOD g_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gt_outtab.
*§2.Use SET_READY_FOR_INPUT to allow editing initially.
* (state "editable and ready for input").
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 1.
*Use IS_READY_FOR_INPUT to fetch current substate of editable cells.
IF g_grid->is_ready_for_input( ) EQ 0.
*Use SET_READY_FOR_INPUT to switch between the substates.
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 1.
ELSE.
CALL METHOD g_grid->set_ready_for_input
EXPORTING i_ready_for_input = 0.
ENDIF. -
Hello,
is there a method which sets the cell value of a certain cell in a alv grid.
I've to set a vallue of a cell after the user has entered a value in a special cell.Hi,
Refer this program:-
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_rep_id " report id
i_callback_pf_status_set = 'PF' " for PF-STATUS
i_callback_user_command = 'USER_COMMAND' " for User-Command
it_fieldcat = it_field " field catalog
TABLES
t_outtab = it_final " internal table
*& Form pf
* SUB-ROUTINE PF IS USED TO SET THE PF-STATUS OF THE SCREEN
* ON WHICH THE ALV GRID IS DISPLAYED
FORM pf USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZTG_STAT'.
ENDFORM. "pf
*& Form USER_COMMAND
* SUB-ROUTINE USER_COMMAND IS USED TO HANDLE THE USER ACTION
* AND EXECUTE THE APPROPIATE CODE
FORM user_command USING lv_okcode LIKE sy-ucomm l_selfield TYPE slis_selfield.
* assign the function code to variable v_okcode
lv_okcode = sy-ucomm.
* handle the code execution based on the function code encountered
CASE lv_okcode.
* when the function code is SAVE then save records into internal table
WHEN 'SAVE'.
* to reflect the data changed into internal table
DATA : ref_grid TYPE REF TO cl_gui_alv_grid. "new
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 at this time you have modified internal table
* refresh the ALV Grid output from internal table
l_selfield-refresh = 'X'.
"alv output is refreshed as per changes in internal table
"now you can include code to modify your ztable from internal table
ENDCASE.
ENDFORM. "USER_COMMAND
Regards,
Tarun -
Update values in AlV grid display after entering value
Hi,
I have an issue in ALV grid display.
Let me explain.
i have 8 fields to display in which one is editiable.
Fields are: date
material,
material Description,
Opening Stock,
Closing stock- ( this field is editiable)
Closing stock,
Received Stock,
Actual production.
Actual production = Closing stock + removal stock
- receipt stock - opening stock.
when i change the value of closing stock and press enter, actual production should get update, the new values should display.
Thany you in advance.Hi,
Please refer the code below:
REPORT z_demo_alv_jg.*******************************************************************
* TYPE-POOLS *
TYPE-POOLS: slis. *******************************************************************
* INTERNAL TABLES/WORK AREAS/VARIABLES *
DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
w_field TYPE slis_fieldcat_alv,
p_table LIKE dd02l-tabname,
dy_table TYPE REF TO data,
dy_tab TYPE REF TO data,
dy_line TYPE REF TO data.*******************************************************************
* FIELD-SYMBOLS *
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa> TYPE ANY,
<dyn_field> TYPE ANY,
<dyn_tab_temp> TYPE STANDARD TABLE.*******************************************************************
* SELECTION SCREEN *
PARAMETERS: tabname(30) TYPE c,
lines(5) TYPE n.*******************************************************************
* START-OF-SELECTION *
START-OF-SELECTION.* Storing table name
p_table = tabname.* Create internal table dynamically with the stucture of table name
* entered in the selection screen
CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_table->* TO <dyn_table>.
IF sy-subrc <> 0.
MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'. LEAVE TO LIST-PROCESSING.
ENDIF.
* Create workarea for the table
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.* Create another temp. table
CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN dy_tab->* TO <dyn_tab_temp>. SORT i_fieldcat BY col_pos.* Select data from table
SELECT * FROM (p_table)
INTO TABLE <dyn_table>
UP TO lines ROWS. REFRESH <dyn_tab_temp>.* Display report
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = p_table
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
TABLES
t_outtab = <dyn_table>
EXCEPTIONS
program_error = 1
OTHERS = 2. IF sy-subrc <> 0. ENDIF.*&-----------------------------------------------------------------*
*& Form SET_PF_STATUS
* Setting custom PF-Status
* -->RT_EXTAB Excluding table
FORM set_pf_status USING rt_extab TYPE slis_t_extab. SET PF-STATUS 'Z_STANDARD'.ENDFORM. "SET_PF_STATUS*&----------------------------------------------------------------*
*& Form user_command
* Handling custom function codes
* -->R_UCOMM Function code value
* -->RS_SELFIELD Info. of cursor position in ALV
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.* Local data declaration
DATA: li_tab TYPE REF TO data,
l_line TYPE REF TO data.* Local field-symbols
FIELD-SYMBOLS:<l_tab> TYPE table,
<l_wa> TYPE ANY.* Create table
CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).
ASSIGN li_tab->* TO <l_tab>.* Create workarea
CREATE DATA l_line LIKE LINE OF <l_tab>.
ASSIGN l_line->* TO <l_wa>. CASE r_ucomm.* When a record is selected
WHEN '&IC1'.* Read the selected record
READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX
rs_selfield-tabindex. IF sy-subrc = 0.* Store the record in an internal table
APPEND <dyn_wa> TO <l_tab>.* Fetch the field catalog info
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = 'Z_DEMO_PDF_JG'
i_structure_name = p_table
CHANGING
ct_fieldcat = i_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc = 0.* Make all the fields input enabled except key fields
w_field-input = 'X'. MODIFY i_fieldcat FROM w_field TRANSPORTING input
WHERE key IS INITIAL. ENDIF.* Display the record for editing purpose
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = p_table
it_fieldcat = i_fieldcat
i_screen_start_column = 10
i_screen_start_line = 15
i_screen_end_column = 200
i_screen_end_line = 20
TABLES
t_outtab = <l_tab>
EXCEPTIONS
program_error = 1
OTHERS = 2. IF sy-subrc = 0.* Read the modified data
READ TABLE <l_tab> INDEX 1 INTO <l_wa>.* If the record is changed then track its index no.
* and populate it in an internal table for future
* action
IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.
<dyn_wa> = <l_wa>.
i_index = rs_selfield-tabindex.
APPEND i_index.
ENDIF.
ENDIF. ENDIF.* When save button is pressed
WHEN 'SAVE'.* Sort the index table
SORT i_index.* Delete all duplicate records
DELETE ADJACENT DUPLICATES FROM i_index. LOOP AT i_index.* Find out the changes in the internal table
* and populate these changes in another internal table
READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX i_index.
IF sy-subrc = 0.
APPEND <dyn_wa> TO <dyn_tab_temp>.
ENDIF. ENDLOOP.* Lock the table
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname = p_table
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3. IF sy-subrc = 0.* Modify the database table with these changes
MODIFY (p_table) FROM TABLE <dyn_tab_temp>. REFRESH <dyn_tab_temp>.* Unlock the table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'E'
tabname = p_table. ENDIF.
ENDCASE. rs_selfield-refresh = 'X'.ENDFORM. "user_command
Thanks,
Sriram Ponna. -
How to capture changed value in ALV Grid
Hi Guys,
I have an ALV grid report where I have 'Edit On' for one of the quantity fields in the report. How do I capture the new (changed) value in the suboutine for user command when user changes the value in the report and clicks on a button ?
Points assured for helpful replies.FORM USER_COMMAND USING P_UCOMM LIKE SY-UCOMM...........
Data ref1 type ref to cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = ref1.
call method ref1->check_changed_data
ENDFORM.
Also chk the blog
/people/community.user/blog/2007/01/10/displaychange-mode-of-editable-fields-in-alv-using-function-modules-but-not-custom-containers
Maybe you are looking for
-
Can iMac with o/s Version 10.7.3 use USB 3.0
Can iMac with o/s Version 10.7.3 use USB 3.0 flash drives?
-
Hi, say I have a list of filenames 0 to n which I want to display on a page using the filedownload UI-Element. Im using NW 7.1 so the IWDModifiableBinaryType is deprecated. If I want to create a Resource with the ResourceFactory I have to provide one
-
A solution to my particular problem of iTunes 8.2.1 freezing.
Hopefully this might help others... I was having the issue that shortly after launching iTunes, it would freeze and become unusable. What was happening is that I have my podcasts set to automatically download new episodes. I finally narrowed it down
-
I have CS2 which doesn't seem to support the 1Ds MkIII (I can't open Raw files from the camera in CS2). Is there any alternative to upgrading to CS3 that anyone knows about?
-
How to get Functional Location of a Workcenter?
Hi there, I am looking for a function that brings me the functional location to a given workcenter of an operation (production order). In our case this is a one-to-one relation. In transaction IL03 I can see the workcenter on Location-tab. But how to