Appending a new line to ALV Grid
Hi,
I have created an editable ALV grid wherein the first 2 columns are key fields and hence non-editable and the rest are editable.
Now I try to append or create a row on the ALV Grid by using the standard toolbar buttons. By doing so, it adds a new line that has the first 2 columns (key fields) as non-editable and the rest as editable. I would like to open those key fields for edit mode when I try to append or insert a new row.
I overwrote the code for append and insert with my code like this
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
READ TABLE e_object->mt_toolbar INTO ls_toolbar
WITH KEY function = '&LOCAL&APPEND'.
IF sy-subrc = 0.
ls_toolbar-function = 'MY_APPEND'.
MODIFY e_object->mt_toolbar FROM ls_toolbar INDEX sy-tabix.
ENDIF.
ENDMETHOD.
METHOD handle_user_command.
DATA: ls_table TYPE ztable.
CASE e_ucomm.
WHEN 'MY_APPEND'.
APPEND ls_table TO gt_table. "append an initial line
PERFORM modify_alv TABLES gt_table.
CALL METHOD gref_alv->refresh_table_display.
ENDCASE.
ENDMETHOD.
FORM modify_alv TABLES xt_lt_table STRUCTURE ztable.
LOOP AT xt_lt_table INTO ls_table.
REFRESH lt_cell_style.
IF NOT ls_table IS INITIAL.
ls_cell_style-fieldname = 'FIELD1'.
ls_cell_style-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_cell_style INTO TABLE lt_cell_style.
ELSE.
ls_cell_style-fieldname = 'FIELD1'.
ls_cell_style-style = cl_gui_alv_grid=>mc_style_enabled.
INSERT ls_cell_style INTO TABLE lt_cell_style.
ENDIF.
INSERT LINES OF lt_cell_style
INTO TABLE ls_table-gt_cell_style .
MODIFY xt_lt_table FROM ls_table.
CLEAR: ls_cell_style.
ENDLOOP.
CALL METHOD gref_alv->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ENDFORM.
I used a field catalog to set my ALV for first display where I set the edit field to space for the first 2 columns. I used the modify_alv subroutine to overwrite the editability property of the fields inside the handle_user_command method.
But when I try to append a row, I don't see a switch to edit mode for the key fields.
I have tried searching through but couldn't find anything helpful. Please help me.
Edited by: Nitwick on Jul 13, 2010 4:46 PM
Hi,
Made a silly error in the code while populating the gs_layout.
My declaration had the cell style table to be 'GT_CELL_STYLE'. I have populated it with a local cell style table. So ideally it had to be
gs_layout-stylefname = 'GT_CELL_STYLE'.
Similar Messages
-
Add a New line to ALV Grid control
Hi experts,
My requirement is after filling ALV grid, user will select a + button from the menu, I need to add a new line next to the selected ALV line (Like in a table control). Does it posible to do this? If can any body tell me how I can do this.
Regards,
Venkat.Hi Venkat...
I have tried this and it worked...
Just copy paste this program...
Note : U will have to create a new PF status for this... and give the Function code as given in my program... then only it will work...
*& Report Z_ALV_TRAINING_LIST_EVENTS
REPORT Z_ALV_TRAINING_LIST_EVENTS.
Tables *************
TABLES : T001.
Type Pools Used **********
TYPE-POOLS : SLIS.
Types Declared **********
Internal Tables Declare ************
DATA : IT_company TYPE STANDARD TABLE OF T001 INITIAL SIZE 0 WITH HEADER LINE,
IT_FIELD_CAT TYPE SLIS_T_FIELDCAT_ALV,
it_alv_event type SLIS_T_EVENT.
Select Data ***********
start-of-selection.
SELECT * FROM T001 INTO TABLE IT_company.
Make Field Catalog ******
PERFORM MAKE_FIELD_CATALOG.
get evente *****
perform get_alv_events.
Display ALV *********
end-of-selection.
PERFORM DISPLAY_ALV_LIST.
*& Form make_field_catalog
text
--> p1 text
<-- p2 text
FORM MAKE_FIELD_CATALOG .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME =
I_INTERNAL_TABNAME =
I_STRUCTURE_NAME = 'T001'
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME =
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = it_field_cat
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. " make_field_catalog
*& Form display_alv_list
text
--> p1 text
<-- p2 text
FORM DISPLAY_ALV_LIST .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
I_CALLBACK_PF_STATUS_SET = 'SET_MY_PF_STATUS'
I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME =
IS_LAYOUT = fl_layout
IT_FIELDCAT = it_field_cat[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = 'X'
IS_VARIANT = '/TEST_VV'
IT_EVENTS = it_alv_event
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IR_SALV_LIST_ADAPTER =
IT_EXCEPT_QINFO =
I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = it_company
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_list
*& Form get_alv_events
text
--> p1 text
<-- p2 text
FORM get_alv_events .
data : wa type slis_alv_event.
wa-name = 'USER_COMMAND'.
wa-form = 'SUB_MY_PF_EVENT'.
append wa to it_alv_event.
ENDFORM. " get_alv_events
*& Form sub_my_pf_event
text
--> p1 text
<-- p2 text
FORM sub_my_pf_event using p_comm type sy-ucomm p_sEL_FIELD TYPE SLIS_SELFIELD.
data : wa type t001.
case p_comm.
when 'BACK'.
leave program.
when 'EXIT'.
leave program.
when 'NEW'.
clear wa.
insert wa into it_company[] index p_sel_field-tabindex.
PERFORM DISPLAY_ALV_LIST.
endcase.
ENDFORM. " sub_my_pf_event
*& Form SET_MY_PF_STATUS
text
--> p1 text
<-- p2 text
FORM SET_MY_PF_STATUS USING p_rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZALV_STATUS'.
ENDFORM. " SET_MY_PF_STATUS
Plz award points if this was helpful.... -
Populating Constant value to a column while inserting new lines to ALV Grid
Hi all,
I need to know how to populate a column in an ALV grid with a constant value , whenever a new line is inserted in the ALV.
Regards,
VijayakumarHi Arun,
g_t_alv is my Internal table. I am inseritng a button in the field name ICON.Now all my records in the ALV will contain a button in the field ICON. But when i create a new line in the ALV the field ICON is containing an empty space.
loop at g_t_alv into g_r_alv.
ls_edit-fieldname = 'ICON'.
ls_edit-style = cl_gui_alv_grid=>mc_style_button.
INSERT ls_edit INTO TABLE lt_edit.
INSERT LINES OF lt_edit INTO TABLE g_r_alv-handle_style.
MODIFY g_t_alv FROM g_r_alv.
endloop. -
How to append a line in alv grid display
Hi experts!
I have to append a new line into my existing alv and then save it in the database.
can you help me out with that.
thanksHi,
Check these links for more details -
http://www.sapfans.com/forums/viewtopic.php?t=84933
http://www.sapfans.com/forums/viewtopic.php?t=69878
ashish -
How to insert new record in ALV GRID?
Hi all,
I am displaying ztable data into grid format using method SET_TABLE_FOR_FIRST_DISPLAY of Class CL_GUI_ALV_GRID using OOPS concept.now i want to insert a new record into ALV grid?
If anyone has tried then please tell me?
Thanks and Regards,
ArpitaHi Avinash,
Thanks for replay.
My problem is solved.i did it as follows.
HANDLE_DATA_CHANGED
FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
IMPORTING ER_DATA_CHANGED
E_UCOMM.
METHOD HANDLE_DATA_CHANGED.
LOOP AT ER_DATA_CHANGED->MT_GOOD_CELLS INTO WA_GOOD_CELLS.
CASE WA_GOOD_CELLS-FIELDNAME.
WHEN 'ZCARRID'.
CALL METHOD ER_DATA_CHANGED->GET_CELL_VALUE
EXPORTING
I_ROW_ID = WA_GOOD_CELLS-ROW_ID
I_FIELDNAME = WA_GOOD_CELLS-FIELDNAME
IMPORTING
E_VALUE = ZCARRID1.
WA_FLI-ZCARRID = ZCARRID1.
ENDMETHOD.
Using method CALL METHOD ER_DATA_CHANGED->GET_CELL_VALUE,
i am reading individual values and assinning it to WA and then insert into ZTBALE.
Thanks,
Arpita -
How to Increase Line space between two lines in ALV Grid
hi,
I want to increase the line space between any two lines in ALV GRID. Can anybody has solution for this issue.
Regards,
MadanHi Madan
It's not possible
Regards
Gregory -
Color a line in ALV Grid Control
<<Do not ask for or offer points>>
Hi all,
How to color a line in ALV Grid Control using OOPs.
The appropriate replies will be rewarded.
regards,
S Philip
Edited by: Matt on Dec 22, 2008 11:05 AM<<Points unassigned - cut and paste not allowed. http://sgstocks.tripod.com/alvgrid_control.htm>>
Hi,
To color a line, the structure of the table must include a Char4 field for color properties
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
Loop trough the table to set the color properties of each line. The color properties field is
Char 4 and the characters is set as follows:
Char 1 = C = This is a color property
Char 2 = 6 = Color code (1 - 7)
Char 3 = Intensified on/of = 1 = on
Char 4 = Inverse display = 0 = of
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-line_color = 'C610'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Name of the color field
gs_layout-info_fname = 'LINE_COLOR'.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
Regards,
John
Edited by: Matt on Dec 22, 2008 11:18 AM -
Regarding user interface in subtotal line of ALV grid, ensure points
Hi,
I have 3 fields,
A= vendor , B = freight , C = Cost PMT
When the vendor get changed, My Grid is showing subtotal of B i.e freight.
Now my requirement is, in the same subtotal line, I want average of C (Cost PMT) field.
So how we can interact with the subtotal line of the ALV grid.
Pleas reply!!!! & have ur points.
cheersRead the documentation of FM ICON_CREATE, the purpose of the Function module is entirely different from what you are using it for.
To print Icons in ALV (Using FMs ) all you need to do is to send the Icon name in the field.
Also parameters TEXT and INFO of FM ICON_CREATE seem to be flags, that are appended to the icon name so that when you set it on the screen the appropriate info or Text is shown. -
Displaying items in a single line in ALV grid using ALV_TOP_OF_PAGE.
Hello Guys,
I am having a problem in displaying items in a single line in the ALV Grid using event ALV_TOP_OF_PAGE.
My requirement is to group items on a single line i.e. in the example below, Vendor code and posting date are on the same line. The next line the prints Vendor Name and Document no.
Vendor Code: 123123 Posting Date : 01.01.2011
Vendor Name: ABCD Document No: 152246598.
Here is my code in subroutine 'ALV_TOP_OF_PAGE',
wa_list_comments-typ = 'S'.
wa_list_comments-key = ''.
wa_list_comments-info = 'Vendor Code'.
APPEND wa_list_comments TO it_list_comments.
wa_list_comments-typ = 'S'.
wa_list_comments-key = ''.
wa_list_comments-info = 'Posting Date'.
APPEND wa_list_comments TO it_list_comments.
The above code prints in the following format i.e one below the other,
Vendor Code: 123123
Posting Date : 01.01.2011.
I also tried using HTML_TOP_OF_PAGE, but it didn't work.
Can anybody please help me out with this.
Regards,
Danish.Hi Danish,
Your problem is with the alignment and you need some fix positions .
The solution i feel is u can use as below :
In CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
use
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'.
Now on calling routine call use cl_dd_document class :
FORM html_top_of_page USING document TYPE REF TO cl_dd_document .
data : doctable TYPE REF TO cl_dd_table_element,
col1_t1 TYPE REF TO cl_dd_area,
col2_t1 TYPE REF TO cl_dd_area,
col1_t2 TYPE REF TO cl_dd_area,
col2_t2 TYPE REF TO cl_dd_area.
add quick table with five columns
CALL METHOD lw_document->add_table
EXPORTING
no_of_columns = 2
border = '0'
cell_background_transparent = ' '
width = '100%'
IMPORTING
table = doctable.
Filling columns in row
CALL METHOD doctable->add_column
EXPORTING
width = '40%'
IMPORTING
column = col1_t1.
Filling columns in row
CALL METHOD doctable->add_column
EXPORTING
width = '60%'
IMPORTING
column = col2_t1.* Filling columns in row
Call method doctable->new_row.
CALL METHOD doctable->add_column
EXPORTING
width = '40%'
IMPORTING
column = col1_t2.
Filling columns in row
CALL METHOD doctable->add_column
EXPORTING
width = '60%'
IMPORTING
column = col2_t2.
*Now adding the texts
lw_text1 = 'your first text'
CALL METHOD col1_t1->add_text
EXPORTING
text = lw_text.
*Similarly add text for other columns
*Adujust % in width to adjust the column as required
Endform.
Hope this will solve your problem . -
Total and non-total lines in ALV grid
Hi all,
Does anyone know if there is any standard SAP functionality for retrieving the non-total/raw item lines that lies beneath a total line in an ALV grid (after the user has selected the total line)?
All helpful answers will be rewarded!
Best regards,
MVTry the ALV event AFTER-LINE-OUTPUT may be it can help u to achieve ur requirement.
Append AFTER-LINE-OUTPUT event to the internal table T_EVENT.
CLEAR W_EVENT.
W_EVENT-FORM = SLIS_EV_AFTER_LINE_OUTPUT.
W_EVENT-NAME = SLIS_EV_AFTER_LINE_OUTPUT.u201CAFTER_LINE_OUTPUT event
APPEND W_EVENT TO T_EVENT.
FORM AFTER_LINE_OUTPUT
USING P_RS_LINEINFO TYPE SLIS_LINEINFO.
Here you have to write the logic to retrieve the 'total' line
ENDFROM.
Now call the alv FM
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = L_REPID "Program Name
IS_LAYOUT = W_LAYOUT "Layout of the Report
IT_FIELDCAT = T_FIELDCAT "Field Catalog for Report
IT_EVENTS = T_EVENT "For setting the events
TABLES
T_OUTTAB = T_OUTPUT "Report data Internal Table
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2. -
Hi,
Can I use a total line in an ALV grid and hide part of the columns, so that only the total line will be presented for some of the columns ?Hi,
Yes u can use a total column in the ALV Grid.
Check the code below:
AT LAST.
WA_ALV_CAT1-FIELDNAME = 'TOTAL'(004).
WA_ALV_CAT1-COL_POS = L_I.
WA_ALV_CAT1-COLTEXT = 'TOTAL'(004).
WA_ALV_CAT1-JUST = C_CENTER. " 'C'.
APPEND WA_ALV_CAT1 TO L_ALV_CAT1_TAB.
CLEAR WA_ALV_CAT1.
ENDAT.
Regards
Kannaiah -
Regarding subtotals and new page in ALV Grid
Hi All,
I have 5 employees in my internal table and each employee having five records.
Now iam displaying total employees in ALV grid and calculating their totals at the end of the hole records.
But i need to display the sub totals for each employee and i need new page for each employee.
means 1) New page for each employye
2) sub totals for each employee
3) grand total for all employees
How can i proceed for this requirement in ALV grid?For subtotals first you need to set the do_sum = 'X' in the fieldcatalog for the columns you want totals.
fieldcat-fieldname = 'ABC'.
fieldcat-do_sum = 'X'.
Append fieldcat to it_fieldcat,
for subtotals you need to populate the SORT table.
sort-fieldname = 'EMPLOYEE'.
sort-up = 'X'.
sort-group = '*'. "<----- this is for new page
"you can view new page in preview / print /
"if you are using the list function
sort-subtot = 'X'.
append sort to it_sort.
pass this it_sort to it_sort of the alv function. -
Hi experts,
I have developed <b>normal</b> ALV. There is an option( Insert row) to add new row in the grid.Now, i wanted to enter values in the new row.
If i make EDIT = 'X' in the fieldcatalog it opens up all of the existing records , which I don't want. I want to enter values in new row only.
if i use something like
data: wa_stg like gt_stage occurs 0 with header line,
lt_celltab type lvc_t_styl,
ls_celltab type lvc_s_styl.
loop at gt_stage into wa_stg.
ls_celltab-fieldname = 'FISTL'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
insert ls_celltab into table lt_celltab.
wa_stg-celltab[] = lt_celltab[].
modify gt_stage from wa_stg transporting celltab.
clear: ls_celltab, lt_celltab.
endloop.
i cant use
call method gv_grid->set_table_for_first_display
exporting
is_layout = gs_layout
changing
it_outtab = gt_stage[]
it_fieldcatalog = i_fieldcat.
because it is for OO.
Is there anyway to do this?
reward guaranteed,
ThanksHi kaki,
From your code, it looks like Your ARE using OOPS for your ALV.
Check this link:
http://help.sap.com/saphelp_erp2004/helpdata/en/0a/b55312d30911d2b467006094192fe3/content.htm
Check this sample program:
http://sapabap.iespana.es/sapabap/sap/reports/alv_grid.htm
Regards,
Ravi
Message was edited by:
Ravi Kanth Talagana -
Separator line in alv grid custome toolbar
I had created a toolbar in alv grid through CLASS cl_alv_grid_handler IMPLEMENTATION.
I would like to separate the control by separator line please suggest me how to do the same.
CLASS cl_alv_grid_handler IMPLEMENTATION.
METHOD handle_toolbar.
PERFORM handle_toolbar
USING e_object.
ENDMETHOD.
FORM handle_toolbar
USING i_object TYPE REF TO cl_alv_event_toolbar_set.
DATA: ls_toolbar TYPE stb_button.
CLEAR : i_object->mt_toolbar.
CLEAR: ls_toolbar.
MOVE 'Add' TO ls_toolbar-function.
MOVE icon_create TO ls_toolbar-icon.
MOVE 'Add row' TO ls_toolbar-quickinfo.
MOVE ' ' TO ls_toolbar-disabled.
MOVE 'Add' TO ls_toolbar-text.
APPEND ls_toolbar TO i_object->mt_toolbar.
MOVE 'CHECK_DATA' TO ls_toolbar-function.
MOVE icon_check TO ls_toolbar-icon.
MOVE 'Check Entries' TO ls_toolbar-quickinfo.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO i_object->mt_toolbar.
Endform.Hi,
Refer to the link given.
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907
Hope it helps.
Regards,
Rajesh Kumar -
Add new line in ALV report on click of button...
Dear All,
How to add a new line for input in ALV report at runtime, on click of a button.
Waiting for early and favorable reply.
Regards,
Dharmesh VyasHi,
First of all u have to Create ur own PF-status and Assign Fcode e.g 'INSERTROW'.
So, whenevr you will click Insertrow button it will be triggered in your User Command and then just Append the blank line in your Final Internal Table.
And Refresh Icon will be there by default...
To Trigger it You have to write rs_selfield-refresh = 'X'
You can also follow the below link...
Try it.
Link:[http://wiki.sdn.sap.com/wiki/display/ABAP/ALVeasytutorial].
Regards
Arbind
Maybe you are looking for
-
Reinstalli​ng Windows 8.1 pro on Thinkpad 8, activation error
Due to some issues with my tablet I had to reinstall it. The installation itself goes perfect. But for some reason my windows won't activate. I get the error that the server has blocked the key. As far as I know the tablet did not come with a licence
-
Color Picker Format CS5.1 Lion
i think the color picker its strange... and i can´t change it back to how it was, in fact i don´t know how it happen. it is set to adobe intead of apple, but anyway... it strange... and im used to how it was before.
-
Best Practice EJB 3.0 Question
I have a web application consisting of 3 projects: - Model (EJB 3.0 Session Beans connected to two different databases) - TagLibrary (custom tag library) - ViewController (Web App / GUI) Currently I am connecting to the EJB Beans using code that Jdev
-
Resolution (ppi) impact in quality on iDVD
I am creating slideshows of family photos. I scan the photos into Photoshop at a resolution of 300ppi. However, many of the photos sent to me by family members from their cameras and over the internet come in at a resolution of 72ppi. If I increase t
-
Where to see for the trace?
Hi, I have set autotrace on.Now i want to see the trace.Where do i see it?Which file specifies teh path if the dump file which has the exection plan.