2013 Sep 24 6:10 AM
Dear All,
I want to add push button (for printing purpose) as a column in my non OOP ALV Grid output. The print button should call smartform whenever clicked. I tried to add it like checkbox column. But it is not working. Also i have added icon and hotspot in fieldcatlog. Plz help me. My code snippet is below.
FORM set_field_attributes_next .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
* Populate style variable (FIELD_STYLE) with style properties
LOOP AT it_tab3 INTO wa_tab3.
ls_stylerow-fieldname = ' ' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_button.
"set field to disabled
APPEND ls_stylerow TO wa_tab3-field_style_next.
MODIFY it_tab3 FROM wa_tab3.
ENDLOOP.
ENDFORM.
FORM user_command_next USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
CASE r_ucomm.
WHEN '&IC1'. " This is the fcode for hotspot link.
READ TABLE it_tab3 INTO wa_tab3 INDEX rs_selfield-tabindex.
IF "wa_tab3-p_button = ' '.
wa_tab3-p_button = 'X'. " The value for checkbox will not be stored with hotspot link, thats why the check on the previous value.
ls_stylerow-fieldname = ' '.
ls_stylerow-style = cl_gui_alv_grid=>mc_style_button..
DELETE wa_tab3-field_style_next WHERE fieldname = ' '.
APPEND ls_stylerow TO wa_tab3-field_style_next.
MODIFY it_tab3 FROM wa_tab3 INDEX rs_selfield-tabindex.
ENDIF.
rs_selfield-refresh = 'X'.
ENDFORM.
Also I want to name the button as 'Print'.
Dear All,
I want to add push button (for printing purpose) as a column in my non OOP ALV Grid output. The print button should call smartform whenever clicked. I tried to add it like checkbox column. But it is not working. Also i have added icon and hotspot in fieldcatlog. Plz help me. My code snippet is below.
FORM set_field_attributes_next .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
* Populate style variable (FIELD_STYLE) with style properties
LOOP AT it_tab3 INTO wa_tab3.
ls_stylerow-fieldname = ' ' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_button.
"set field to disabled
APPEND ls_stylerow TO wa_tab3-field_style_next.
MODIFY it_tab3 FROM wa_tab3.
ENDLOOP.
ENDFORM.
FORM user_command_next USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
CASE r_ucomm.
WHEN '&IC1'. " This is the fcode for hotspot link.
READ TABLE it_tab3 INTO wa_tab3 INDEX rs_selfield-tabindex.
IF "wa_tab3-p_button = ' '.
wa_tab3-p_button = 'X'. " The value for checkbox will not be stored with hotspot link, thats why the check on the previous value.
ls_stylerow-fieldname = ' '.
ls_stylerow-style = cl_gui_alv_grid=>mc_style_button..
DELETE wa_tab3-field_style_next WHERE fieldname = ' '.
APPEND ls_stylerow TO wa_tab3-field_style_next.
MODIFY it_tab3 FROM wa_tab3 INDEX rs_selfield-tabindex.
ENDIF.
rs_selfield-refresh = 'X'.
ENDFORM.
Also I want to name the button as 'Print'.
2013 Sep 24 6:33 AM
Hi,
The print button is common to the entire ALV right? or specific to a particular row?
2013 Sep 24 6:50 AM
Dear Susmitha,
Thanks for your reply. The Print button is common to the entire ALV. User will take print based on their requirement.
regards.
2013 Sep 24 7:00 AM
Hi,
Check this link.. it may help you.
http://help.sap.com/saphelp_erp2004/helpdata/en/88/387f380c2f2e3ce10000009b38f8cf/content.htm
Check this code it is for coloring a particular row or cell using hotspot.
START-OF-SELECTION.
PERFORM get_data_from_database .
PERFORM build_fieldcatalog.
w_layout-info_fieldname = 'COLOR'. "color
PERFORM display_data.
FORM display_data .
DATA :program LIKE sy-repid VALUE sy-repid.
SORT i_mard BY werks.
DELETE ADJACENT DUPLICATES FROM i_mard COMPARING werks.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = program
i_callback_user_command = 'USER_COMMAND'
is_layout = w_layout
it_fieldcat = i_fieldcat
it_events = i_events
TABLES
t_outtab = i_mard.
ENDFORM. " display_data
*&---------------------------------------------------------------------*
*& Form BUILD_FCAT
*&---------------------------------------------------------------------*
FORM build_fcat USING l_field l_tab l_text.
w_fieldcat-fieldname = l_field.
w_fieldcat-tabname = l_tab.
w_fieldcat-seltext_m = l_text.
IF l_field = 'WERKS'.
w_fieldcat-hotspot = 'X'.
ENDIF.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.
ENDFORM. " BUILD_FCAT
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.
IF r_ucomm = '&IC1'.
READ TABLE i_mard WITH KEY werks = rs_selfield-value.
IF sy-subrc = 0.
i_mard-color = 'C610'.
MODIFY i_mard INDEX sy-tabix.
ENDIF.
rs_selfield-refresh = 'X'.
ENDIF.
ENDFORM. "USER_COMMAND
Regards,
Lokesh
2013 Sep 24 7:13 AM
Will like to add one more information that the print button will be only one for same column value of column1. Because i need to take a print for the same column1 values only once. Plz give me idea how to do this.
Thanks.
2013 Sep 24 7:28 AM
Hi,
Follow these steps.
1. Create a menu painter in Se41 for the program that you are using copied from standard program.
You can use std prgm like SAPLKKBL and copy the pf status 'STANDARD' to your program and pf-status 'ZSTANDARD'.
2. In the application tool bar, create a print button. Here have given the function code &PNT for the print function.
3. Call this in your ALV function module.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
is_layout_lvc = gd_layout1
it_fieldcat_lvc = gt_alv_fieldcat1
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
i_save = 'X'
TABLES
t_outtab = i_data1
EXCEPTIONS
program_error = 1
OTHERS = 2.
* If you are using the following FM.
* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
* EXPORTING
* i_callback_program = sy-repid
* it_fieldcat = gt_alv_fieldcat1
* i_callback_pf_status_set = 'SET_PF_STATUS'
* i_callback_user_command = 'USER_COMMAND'
* i_default = 'X'
* i_save = 'S'
* is_layout = gd_layout1
* TABLES
* t_outtab = i_data1.
4. Implement the pf status as a subroutine below the FM.
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZSTANDARD'.
"Copy of 'STANDARD' pf_status from fgroup SALV, eg pgm SAPLKKBL
ENDFORM.
5. Capture the event in the user command.
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
IF r_ucomm = '&PNT'.
* To capture any values changed in ALV.
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.
* Call the subroutine to print form
PERFORM form_call.
ENDIF.
This will be the output.
Do ask if there is any doubt in the above code.
2013 Sep 24 7:47 AM
Dear Susmitha,
I know this one, i, e adding button in application toolbar. But i have to add button not in application toolbar but in my ALV GRID as Column.
The output should be like this.
Col1 Col2 Col3
1 10 print
20
2 30 print
3 10 print
Here print is the button that i need.
2013 Sep 24 8:28 AM
OK, that means you need a print button specific to each row, not common to entire ALV. I am afraid that was not what you mentioned before!
2013 Sep 24 8:58 AM
You are right. I misunderstood you last time. I need print button specific to each row. Also on click on the print button a smaftform will be called for that row.
2013 Sep 24 9:44 AM
Hi,
For push button, if we double click, the fcode will be the same ie '&IC1'. If you want to trigger the event with single click, you need to set hotspot, though it may not look good to have the line (link) under print button. So its a tradeoff between user friendliness and look.
Add the following statement to yesterday's code.
In your output table, have one more field named, say print.
TYPES: BEGIN OF gtyp_data1,
flag(1),
print(5),
* other fields.
end of gtyp_data1.
form set_specific_field_attributes .
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
data : prev_txt50(50).
LOOP AT i_data1 INTO wa_data1.
clear ls_stylerow.
if wa_data1-txt50 ne prev_txt50. " Here the requirement to have print button for only new values for a particular column would be provided. Just make sure, table is sorted based on that column. In this example, for every new values in txt 50, there will be a push button in the print column. Table has to be sorted by txt50.
ls_stylerow-fieldname = 'PRINT' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_button.
"set field to disabled
APPEND ls_stylerow TO wa_data1-field_style.
wa_data1-print = 'Print'.
endif.
clear ls_stylerow.
ls_stylerow-fieldname = 'TXT50' .
ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
"set field to disabled
APPEND ls_stylerow TO wa_data1-field_style.
MODIFY i_data1 FROM wa_data1.
prev_txt50 = wa_data1-txt50.
clear wa_data1.
ENDLOOP.
endform.
In the field catalog,
lv_pos = lv_pos + 1.
CLEAR gw_alv_fieldcat1.
gw_alv_fieldcat1-fieldname = 'PRINT'. " name of field from internal table
gw_alv_fieldcat1-tabname = 'I_DATA1'. " internal table name
gw_alv_fieldcat1-outputlen = 6. " output length on screen
gw_alv_fieldcat1-scrtext_m = text-h07. " header information
* gw_alv_fieldcat1-hotspot = 'X'. " If this is set, then the button click will be triggered by single click, else it would be double click. However, the function code is the same.
gw_alv_fieldcat1-col_pos = lv_pos.
APPEND gw_alv_fieldcat1 TO gt_alv_fieldcat1. " append field catalog internal table
In the user command
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
if r_ucomm = '&IC1'. " This is the fcode for hotspot link and button click.
IF rs_selfield-fieldname = 'PRINT' . "To distinguish between the fields that triggered event
read table i_data1 into wa_data1 index rs_selfield-tabindex.
perform print.
message 'Button Clicked' type 'I'.
endif.
endif.
endform.
Thanks,
Susmitha
2013 Sep 24 7:14 AM
Hi
Check the below.... It may helpful for your scnario.
http://saptechnical.com/Tutorials/ALV/HighlightVisitedRecord/Demo.htm
http://scn.sap.com/message/1606448#1606448
Thanks,
Rajesh.B
2013 Sep 24 7:20 AM
Hi,
check this program.
BCALV_TEST_GRID_EVENTS
use event button_click of cl_gui_alv_grid.
2013 Sep 24 8:02 AM
hi,
copy a standard report pfstatus into zpfstatus. and open this using se41.
Just add a button wat ever you want.
Now use this in your report at set pf-status.
and include this code....
I_CALLBACK_PF_STATUS_SET = 'ZSHAN'
after this FM.
form ZSHAN USING ZTAB TYPE SLIS_T_EXTAB.
set pf-status 'ZSHAN1'.
endform.
ZSHAN1 here u specify your pfstatus name which u created.
Try this...
Rgds,
Sam.