Use of cl_gui_cfw= flush
Hi all,
what is the use of the class cl_gui_cfw=>flush. in alv object?
Thanks
ANUPAM
Hi,
Use this method to synchronize the automation queue. The buffered operations are sent to the frontend using GUI RFC. At the frontend, the automation queue is processed in the sequence in which you filled it.
If an error occurs, an exception is triggered. You must catch and handle this error. Since it is not possible to identify the cause of the error from the exception itself, there are tools available in the Debugger and the SAPgui to enable you to do so.
Debugger: Select the option Automation Controller: Always process requests synchronously. The system then automatically calls the method cl_gui_cfw=>flush after each method called by the Automation Controller.
SAPGUI: In the SAPgui settings, under Trace, select Automation. The communication between the application server and the Automation Controller is then logged in a trace file that you can analyze at a later date.
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
AWARD IF USEFUL
Similar Messages
-
Why do we use cl_gui_cfw= flush method in Object Oriented ALV programming
Dear Friends,
Please solve my query regarding control framework. Why do we use cl_gui_cfw=>flush method in Object Oriented ALV programming. I studied and found that this method transfers automation queue to Front end. But I could not find any further update on this.
Thanks & Regards
Amit SharmaGenerally this is to restrict the traffic b/w frontend and backend. This means that every operation in Control Framework should be first buffered in the backend and synchronized with the frontend at certain points (one of this point is calling synchronization method cl_gui_cfw=>flush ). This explicit order of synchronization is due to RFC call needed for every communication b/w front/back end. So to avoid to many RFC calls we do it only at certain time.
Please refer [Automation Queue|http://help.sap.com/saphelp_wp/helpdata/en/9b/d080ba9fc111d2bd68080009b4534c/frameset.htm]. I think it explains the concept quite well.
Regards
Marcin -
When to syncronize automation queue (calling cl_gui_cfw= flush)
Hello,
I'm using OO ALV (using cl_gui_alv_grid class), with checkboxes and user interaction, and it all seems to work OK. But i'm not calling class method cl_gui_cfw=>flush in any point at my program, because I don't clearly understand what's the method's use and need.
Could you please explain this to me? I've already read some SAP help about control framework, automation queue and all but still don't get it (so please try to explain instead of simply pasting SAP help links).
Many thanksOk, from your last post i deduce that for every control class (i.e. cl_gui_alv_grid), there's a proxy class in the application server. All that is transparent to the programmer.
But could you give some example of when the necessity arises to use the flush method explicitly?
My ALV code in this case isn't much complicated, i just call the check_changed_data method to detect changes in checkboxes and then call refresh_table_display. But would like to understand this fully so I can be prepared for any case.
EDIT: I guess the need depends on the context of the program being developed. But I understood the concept so I'm closing the thread.
Edited by: Alejandro Bindi on Aug 7, 2008 11:28 PM -
What is the functionality CALL METHOD CL_GUI_CFW= FLUSH
Hi,
What is the functionality of method "FLUSH" in class CL_GUI_CFW
Should it be used after every call method CL_GUI_FRONTEND_SERVICES=>......
What is the purpose of using it? What happens if we don't use it?hi
good
The class CL_GUI_CFW contains static methods that apply to all instantiated custom controls when you call them.
You can force a synchronization point in your program by calling a method that is not buffered, or by calling the static method FLUSH.
CLASS event_handler IMPLEMENTATION.
METHOD handle_f1.
DATA row TYPE i.
MESSAGE i888(sabapdocu) WITH text-003.
CALL METHOD sender->get_selection_pos
IMPORTING from_line = row.
CALL METHOD sender->get_line_text
EXPORTING line_number = row
IMPORTING text = field.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING new_code = 'F1'.
CALL METHOD cl_gui_cfw=>flush.
ENDMETHOD.
thanks
mrutyun^ -
Cl_gui_cfw= flush.
Hi,
May I know, What is the functionality of the following 2 sentenses,
1-cl_gui_cfw=>flush
2-cl_gui_cfw=>false?
ThanQ.Hi,
In OO approach, calling a Control-method does not imply that the method is automatically executed at runtime. Initially, the system buffers methods in a queue, referred to as the Automation Queue, when they are called in the ABAP program. The execution sequence of the methods therefore remains unchanged. However, the methods are only executed if they are transferred to the frontend via Remote Function Call (RFC) using method FLUSH. This means that the Automation Queue is used to reduce the number of RFC calls required.
(Due to the buffering of control methods in the Automation Queue, the method calls and the remaining ABAP code are executed at different times. Method FLUSH thus determines a synchronization point).
While communicating between the Automation Controller and the ABAP Objects Control Framework the automation queue uses GUI RFC calls. To minimize the network load between the backend and frontend, calls from the backend to the frontend are buffered and sent to the frontend in a single batch at defined synchronization points. A synchronization point occurs when you use a method call that is not buffered or explicitly call the generic synchronization method ( CALL METHOD cl_gui_cfw=>flush ).
cl_gui_cfw=>false is method which used to hide the border around the Splitter Container.
CALL METHOD go_splitter_container->set_border
EXPORTING
border = cl_gui_cfw=>false.
For more information, please check this link.
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIDOCK/BCCIDOCK.pdf
Regards,
Ferry Lianto -
CL_GUI_CFW= FLUSH giving short dump
hi,
i have got two servers. one for development and other for quality. in development my CL_GUI_CFW=>FLUSH is working fine, but when i try to execute my prog in quality "flush method" is giving short dump, its returning sy-subrc <> 0.
can anybody suggest possible causes of the same.
The server status are all the same for quality as well as development.
thanks
pratyushHello Pratyush
You may want to have a look at my sample report ZUS_SDN_TWO_ALV_GRIDS_3 in thread
[how to refresh the contents of a grid?|how to refresh the contents of a grid?;.
Most control events do not trigger PAI of the dynpro. Thus, they behave similar like calling a search help or F1 help.
The automatic flushing which occurs at PBO is done the following way:
METHOD handle_user_command.
* define local data
DATA:
ls_row TYPE lvc_s_row,
ls_knb1 TYPE knb1.
CHECK ( sender = go_grid1 ).
CHECK ( e_ucomm = 'SAVE' ).
CALL METHOD go_grid1->get_current_cell
IMPORTING
es_row_id = ls_row.
READ TABLE gt_knb1 INTO ls_knb1 INDEX ls_row-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
PERFORM entry_show_details.
* Triggers PAI of the dynpro with the specified ok-code
" CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ). " not on 4.6c
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
ok_code = 'DETAIL'.
ENDMETHOD. "handle_user_command
Regards
Uwe -
Using fortran library flush() in a subroutine
Hi,
Using studio 11.
There is a different behavior when using flush() in main compared to
when using it in a subroutine. flush() doesn't work in a subroutine.
When using flush() in main the output is flushed to th i/o unit.
When using flush() in a subroutine the buffer is not being flushed
until the i/o unit is actually closed.
In this case the i/o unit is a FIFO.
Any comments appreciated.
/BR
UlfI'm using tail -f f1 in one window for verifying the output activity.
dbx is used to step through in the main and p1 respectively.
compiled on Solaris 10 u3 Sparc as follows:
f90 -f77 -g -ftrap=%none -xrecursive -o FIFOTEST1 fifotest1.f
f90 -f77 -g -ftrap=%none -xrecursive -o FIFOTEST2 p1.f fifotest2.f
1. Using flush() from main:
fifotest1.f
program fifotest1
*** f1 is a fifo created with mkfifo
integer*4 ios
open(50, file="f1", iostat=ios)
write(50,'(a)', iostat=ios) 'First line'
call sleep(2)
write(50,'(a)', iostat=ios) 'Next line'
call flush(50)
call sleep(2)
close(50)
stop
end
2. The same but from a subroutine
fifotest2.f
program fifotest2
c --- execute :
c --- mkfifo f1
c --- FIFOTEST
c --- tail -f f1 in another window
call p1
stop
end
p1.f:
subroutine p1
integer*4 ios
open(50, file="f1", iostat=ios)
write(50,'(a)', iostat=ios) 'First line'
call sleep(2)
write(50,'(a)', iostat=ios) 'Next line'
call flush(50)
call sleep(2)
close(50)
return
end -
Used Mavericks DNS Flush Commands with 10.8.5
Mid 2011 Mac Book Air OS 10.8.5. In Terminal, I mistakenly used Maverick's DNS Flush commands dscacheutil -flushcache; sudo killall -HUP mDNSResponder.
I note that 10.8.5 only requires the second command.
Any problems with this blunder? Tks.Lex,
Hmm, flushing DNS cache. With Safari on all of my Mac devices, I started having difficulty, initially on my iPad, accessing Zite and an internet radio, Tunein Radio Pro. After googling the error message "....cannot find the server", I put in the two 208....DNS numbers. I will now add the others you suggest. at some stage I read an article about flushing DNS caches, it suggesting using the Apple Store app. It seemed a good idea... The app is https://itunes.apple.com/us/app/clean-dns-cache-english/id628459184?mt=12. As a precaution I have loaded it only on my Mac Book Air, which is due for a clean install of Mavericks 10.9.2 when it is finalised. The app had a good review, and it would have been nice to have used it instead of using terminal, but I take your point that DNS caches are best left alone. Particularly for tyros! I will delete the app in due course. Thank you for the time and thought you have put in.
Cheers
Ken
Lower Hutt NZ
On 21/02/2014, at 1:28, Apple Support Communities Updates <[email protected]> wrote:
208.67.222.222 -
Disbable button on alv report using oops
Hi all,
I have a button to toll bar of alv grid using oops
based on that when the user clicks on that some action is performed and list is displayed again
now when the list is diaplyed i need the button that i added to be disabled so that the user cannot click it agin
i have everything i don't know how to disable the button.
USING THIS STATMENT move 'X' to ls_toolbar-disabled WE CAN DISABLE BUT I DON'T WHERE TO PASS IT..
LOCAL CLASSES: Definition
*===============================================================
class lcl_event_receiver: local class to
define and handle own functions.
Definition:
~~~~~~~~~~~
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.
private section.
endclass.
lcl_event_receiver (Definition)
*===============================================================
LOCAL CLASSES: Implementation
*===============================================================
class lcl_event_receiver (Implementation)
class lcl_event_receiver implementation.
method handle_toolbar.
append a separator to normal toolbar
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
append an icon to show booking table
clear ls_toolbar.
move 'ADD' to ls_toolbar-function.
move icon_employee to ls_toolbar-icon.
move 'Show Bookings'(111) to ls_toolbar-quickinfo.
move 'Add Material'(112) to ls_toolbar-text.
move '' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
endmethod.
method handle_user_command.
case e_ucomm.
when 'ADD'.
call method g_grid->get_selected_rows
importing et_index_rows = lt_rows.
call method cl_gui_cfw=>flush.
if sy-subrc ne 0.
add your handling, for example
call function 'POPUP_TO_INFORM'
exporting
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
else.
*tHIS IS THE PART IAM HAVING PROBLEM WITH
*class lcl_event_receiver implementation.
method handle_toolbar.
*clear : ls_toolbar.
loop at e_object->mt_toolbar into ls_toolbar WHERE FUNCTION = 'ADD'.
DELETE e_object->mt_toolbar FROM ls_toolbar.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
endloop.
*ENDMETHOD.
*ENDCLASS.
***tHIS IS THE PART
call method g_grid->refresh_table_display.
endif.
endcase.
endmethod.
Thanks in advanceHi
hI ALL,
MY QUESTION IS WHEN method handle_toolbaR WOULD BE TRIGERRED
first time i have the button enabled and when i press the button its get disabled.This is what i need
But iam trying to understand how this is working
Let me know whether iam right or not
when this piece of code would be triggered
method handle_toolbar.
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 'ADD' to ls_toolbar-function.
move icon_employee to ls_toolbar-icon.
move 'Show Bookings'(111) to ls_toolbar-quickinfo.
move 'Add Material'(112) to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
IF FLAG = 'X'.
LOOP AT e_object->mt_toolbar INTO ls_toolbar.
if ls_toolbar-function = 'ADD'.
ls_toolbar-disabled = 'X'.
MODIFY e_object->mt_toolbar FROM ls_toolbar.
endif.
ENDLOOP.
ENDIF.
1 ) would this be triggered
when i call this call method g_grid->refresh_table_display.
2)or
call method g_grid->set_toolbar_interactive
This is my piece of code
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.
private section.
endclass.
class lcl_event_receiver implementation.
method handle_toolbar.
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 'ADD' to ls_toolbar-function.
move icon_employee to ls_toolbar-icon.
move 'Show Bookings'(111) to ls_toolbar-quickinfo.
move 'Add Material'(112) to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
IF FLAG = 'X'.
LOOP AT e_object->mt_toolbar INTO ls_toolbar.
if ls_toolbar-function = 'ADD'.
ls_toolbar-disabled = 'X'.
MODIFY e_object->mt_toolbar FROM ls_toolbar.
endif.
ENDLOOP.
ENDIF.
endmethod.
method handle_user_command.
case e_ucomm.
when 'ADD'.
call method g_grid->get_selected_rows
importing et_index_rows = lt_rows.
call method cl_gui_cfw=>flush.
if sy-subrc ne 0.
else.
perform test.
call method g_grid->refresh_table_display.
endif.
endcase.
endmethod. "handle_user_command
odule status_0100 output.
SET PF-STATUS 'STATUS'.
set pf-status 'MAIN100'.
set titlebar 'HEADER_CHECK'.
if g_custom_container is initial.
create object g_custom_container
exporting container_name = g_container.
create object g_grid
exporting i_parent = g_custom_container.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZTEST'
changing
ct_fieldcat = fieldcat
exceptions
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.
g_layout-sel_mode = 'A'. " TO GET SELECTION BOX
call method g_grid->set_table_for_first_display
exporting
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
is_layout = g_layout
IS_PRINT =
IT_SPECIAL_GROUPS =
it_toolbar_excluding = pt_exclude
IT_HYPERLINK =
IT_ALV_GRAPHICS =
changing
it_outtab = i_zTEST
it_fieldcatalog = fieldcat
IT_SORT =
IT_FILTER =
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4
create object event_receiver.
set handler event_receiver->handle_user_command for g_grid.
set handler event_receiver->handle_toolbar for g_grid.
call method g_grid->set_toolbar_interactive.
endif. "IF grid1 IS INITIAL
call method cl_gui_control=>set_focus exporting control = g_grid.
endmodule. " STATUS_0100 OUTPUT
Thanks
Suchitra -
Calling a web dynpro application via portal using SSO
Hello Expert,
i have a requirement where i need to call a web dnpro application via portal.
But it is asking for user name and password.
i want to call using single sign on.
Can u please suggest a way.
i did the coding like this:-
CALL METHOD cl_wd_utilities=>construct_wd_url
EXPORTING
application_name = l_c_appl_name
IMPORTING
out_absolute_url = l_v_gv_url_string.
l_v_icf_url = l_c_icf_url_val. "#EC SYNTCHAR
CALL METHOD cl_icf_tree=>if_icf_tree~service_from_url
EXPORTING
url = l_v_icf_url
hostnumber = l_c_0
authority_check = space
IMPORTING
icfactive = l_v_m_sso_active.
IF l_v_m_sso_active = l_c_x .
CREATE OBJECT o_viewer
EXPORTING
parent = o_empty_co.
CALL METHOD o_viewer->enable_sapsso
EXPORTING
enabled = l_c_x
EXCEPTIONS
OTHERS = 0.
l_v_gv_url_c = l_v_gv_url_string .
CONCATENATE l_v_gv_url_c l_c_url_string p0022-pernr INTO l_v_gv_url_c.
CALL METHOD o_viewer->detach_url_in_browser
EXPORTING
url = l_v_gv_url_c
EXCEPTIONS
cntl_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
RAISING error_occured.
ENDIF.
cl_gui_cfw=>flush( ).
ENDIF.
but it is not working
thanks
MaheshHi Mahesh,
You need to setup a Single Sign On between SAP Portal and ECC system where yoy are doing the development.
Ask basis team to setup the single sign on and usually this is the job done by Basis teams. Refer the below link to get some idea on SSO setup:
http://scn.sap.com/community/enterprise-portal/blog/2013/12/15/sso-configuration-between-sap-portal-73-and-ecc-60-ehp-6
Thanks
Krishna -
Using cl_gui_textedit, text blocks always display prior document.
We have two containers and we're using two instances of cl_gui_textedit.
On the first call to the text screen, we see the two texts that we should see.
The user saves the data and backs out to the selection screen, which contains an ALV display of documents.
The user selects the next document to process. During initialization, we attempt the FREE destructor but it does not destroy the text editor ref to cl_gui_textedit. We can initialize with clear and free as ABAP statement. Upon entry to the PBO, we can see that we have forcibly cleared the ref to cl_gui_textedit. It's 0: INITIAL for both text editors. We watch the table being built and the internal tables contain the correct text. After our set read_only true or false, we get a beep, and then arrive at our text screen without any error message.
What is on the screen at that point will be the texts from the prior document. We've tried inserting lifetime parameters for our custom container. We've tried CALL METHOD cl_gui_cfw=>flush (which appears to always be necessary in PAI when we get the unprotected portion and the indices, etc.). Neither of these alter the behavior of the screen and the erroneous content of the text editor blocks.
Question: is there a method or something that anyone can suggest to "force" the text blocks to contain the data that was in the table, rather than the data that was in the table for the prior transaction?Did you try calling the method DELETE_TEXT of the CL_GUI_TEXTEDIT before setting up the next text.
This is how I get rid of the existing text:
* Delete the Text
me->o_editor->delete_text( ).
* Set the new text
me->o_editor->set_textstream( EXPORTING text = iv_text ).
Regards,
Naimesh Patel -
Control problem in trees using class
Hi all i am creating tree structure using class method in that when i am creating only one node it is working properly but when i try to crate multiple nodes it is giving me dump my program is as follow.
I search these on sdn and try the things but it still giving me same error.
*& Report ZIRPT_HR_TEST_SPLITTER_01
report zirpt_hr_test_splitter_01.
tables : pa0001,t582s.
select-options : p_pernr for pa0001-pernr no intervals.
* CLASS screen_init DEFINITION
class screen_init definition create private.
public section.
class-methods init_screen.
methods constructor.
private section.
data: splitter_h type ref to cl_gui_splitter_container,
splitter_v type ref to cl_gui_splitter_container,
picture type ref to cl_gui_picture,
tree type ref to cl_gui_simple_tree,
it_pa0001 type table of pa0001,
it_pa0000 type table of pa0000.
methods: fill_tree,
fill_picture.
endclass. "screen_init DEFINITION
* CLASS screen_handler DEFINITION
class screen_handler definition.
public section.
methods: constructor importing container
type ref to cl_gui_container,
handle_node_double_click
for event node_double_click
of cl_gui_simple_tree
importing node_key.
private section.
data: html_viewer type ref to cl_gui_html_viewer,
it_pa0001 type table of pa0001,
it_pa0000 type table of pa0000,
list_viewer type ref to cl_gui_alv_grid.
methods:
fill_list importing pernr type pa0001-pernr
infty type t582s-infty.
endclass. "screen_handler DEFINITION
* CLASS screen_init IMPLEMENTATION
class screen_init implementation.
method init_screen.
data screen type ref to screen_init.
create object screen.
endmethod. "init_screen
method constructor.
data: events type cntl_simple_events,
event like line of events,
event_handler type ref to screen_handler,
container_left type ref to cl_gui_container,
container_right type ref to cl_gui_container,
container_top type ref to cl_gui_container,
container_bottom type ref to cl_gui_container.
create object splitter_h
exporting
parent = cl_gui_container=>screen0
rows = 1
columns = 2.
call method splitter_h->set_border
exporting
border = cl_gui_cfw=>false.
call method splitter_h->set_column_mode
exporting
mode = splitter_h->mode_absolute.
call method splitter_h->set_column_width
exporting
id = 1
width = 110.
container_left = splitter_h->get_container( row = 1 column = 1 ).
container_right = splitter_h->get_container( row = 1 column = 2 ).
create object splitter_v
exporting
parent = container_left
rows = 2
columns = 1.
call method splitter_v->set_border
exporting
border = cl_gui_cfw=>false.
call method splitter_v->set_row_mode
exporting
mode = splitter_v->mode_absolute.
call method splitter_v->set_row_height
exporting
id = 1
height = 160.
container_top = splitter_v->get_container( row = 1 column = 1 ).
container_bottom = splitter_v->get_container( row = 2 column = 1 ).
create object picture
exporting parent = container_top.
create object tree
exporting parent = container_bottom
node_selection_mode =
cl_gui_simple_tree=>node_sel_mode_single.
create object event_handler
exporting container = container_right.
event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
event-appl_event = ' '.
append event to events.
call method tree->set_registered_events
exporting
events = events.
set handler event_handler->handle_node_double_click for tree.
call method: me->fill_tree,
me->fill_picture.
call method cl_gui_cfw=>flush.
endmethod. "constructor
method fill_picture.
types pict_line(256) type c.
data pict_tab type table of pict_line.
data url(255) type c.
data : file type rlgrap-filename value 'C:\Documents and Settings\sapgroup.NITCOWRL\My Documents\nitco.gif'.
translate file to upper case.
*CALL FUNCTION 'WS_UPLOAD'
*EXPORTING
*filename = file
*filetype = 'BIN'
*TABLES
*data_tab = pict_tab.
data query_table_wa type w3query.
data query_table type table of w3query." OF like w3query occurs 1 with header line.
data html_table type table of w3html." like w3html occurs 1.
data return_code type w3param-ret_code.
data content_type type w3param-cont_type.
data content_length type w3param-cont_len.
data pic_data type table of w3mime." like w3mime occurs 0.
data pic_size type i.
refresh query_table.
query_table_wa-name = '_OBJECT_ID'.
query_table_wa-value = 'ENJOYSAP_LOGO'.
append query_table_wa to query_table.
call function 'WWW_GET_MIME_OBJECT'
tables
query_string = query_table
html = html_table
mime = pic_data
changing
return_code = return_code
content_type = content_type
content_length = content_length
exceptions
object_not_found = 1
parameter_not_found = 2
others = 3.
if sy-subrc = 0.
pic_size = content_length.
endif.
call function 'DP_CREATE_URL'
exporting
type = 'image'
subtype = cndp_sap_tab_unknown
size = pic_size
lifetime = cndp_lifetime_transaction
tables
data = pic_data
changing
url = url
exceptions
others = 1.
*IMPORT pict_tab = pict_tab FROM DATABASE abtree(pi) ID 'FLIGHTS'.
*CALL FUNCTION 'DP_CREATE_URL'
*EXPORTING
*type = 'IMAGE'
*subtype = 'GIF'
*TABLES
*data = pict_tab
*CHANGING
*url = url.
call method picture->load_picture_from_url
exporting
url = url.
call method picture->set_display_mode
exporting
display_mode = picture->display_mode_fit_center.
* CALL METHOD cl_gui_cfw=>flush.
endmethod. "fill_picture
method fill_tree.
data: node_table type table of abdemonode,
node type abdemonode.
*data : it_pa0001 TYPE TABLE OF p0001,
data :wa_pa0001 type pa0001,
wa_pa0000 type pa0000,
it_t582s type table of t582s,
wa_t582s type t582s.
types : begin of ttab,
itext type t582s-itext,
infty type t582s-infty,
pernr type p0001-pernr,
end of ttab.
data : itab type table of ttab,
wa_tab type ttab.
field-symbols : <fs> like p_pernr.
data : text1 type c.
node-hidden = ' '.
node-disabled = ' '.
node-isfolder = 'X'.
node-expander = ' '.
select * from t582s
into corresponding fields of table it_t582s
where sprsl = sy-langu
and infty in ('0001','0000')."'0002','0006',
* '0008','0015','0019').
loop at it_t582s into wa_t582s .
move-corresponding wa_t582s to wa_tab.
node-node_key = wa_t582s-infty.
clear node-relatkey.
clear node-relatship.
node-text = wa_t582s-itext.
node-n_image = ' '.
node-exp_image = ' '.
append node to node_table.
loop at p_pernr assigning <fs>.
wa_tab-pernr = <fs>-low.
append wa_tab to itab.
clear p_pernr-low.
node-node_key = <fs>-low.
node-relatkey = wa_tab-infty.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-text = <fs>-low.
node-n_image = '@AV@'.
append node to node_table.
endloop.
* SELECT SINGLE * FROM pa0001 INTO wa_pa0001 WHERE pernr in p_pernr.
* WHEN '0000'.
* SELECT SINGLE * FROM pa0000 INTO wa_pa0000 WHERE pernr = p_pernr.
* wa_tab-pernr = wa_pa0000-pernr.
* endcase.
clear : wa_tab,wa_pa0001,wa_pa0000.
endloop.
*node-hidden = ' '.
*node-disabled = ' '.
*node-isfolder = 'X'.
*node-expander = ' '.
*LOOP AT itab INTO wa_tab.
*AT NEW infty.
*node-node_key = wa_tab-infty.
*CLEAR node-relatkey.
*CLEAR node-relatship.
*node-text = wa_tab-itext.
*node-n_image = ' '.
*node-exp_image = ' '.
*APPEND node TO node_table.
*ENDAT.
*AT NEW pernr.
* node-node_key = wa_tab-pernr.
*node-relatkey = wa_tab-infty.
*node-relatship = cl_gui_simple_tree=>relat_last_child.
*node-text = wa_tab-pernr.
*node-n_image = '@AV@'.
*node-exp_image = '@AV@'.
*ENDAT.
*APPEND node TO node_table.
*ENDLOOP.
call method tree->add_nodes
exporting
table_structure_name = 'ABDEMONODE'
node_table = node_table.
* CALL METHOD cl_gui_cfw=>flush.
endmethod. "fill_tree
endclass. "screen_init IMPLEMENTATION
* CLASS screen_handler IMPLEMENTATION
class screen_handler implementation.
method constructor.
create object: html_viewer exporting parent = container,
list_viewer exporting i_parent = container.
endmethod. "constructor
method handle_node_double_click.
data: infty type t582s-infty,
pernr type pa0001-pernr.
infty = node_key(4).
pernr = node_key+4(8).
*IF pernr IS INITIAL.
*CALL METHOD: fill_html EXPORTING infty = infty,
*html_viewer->set_visible EXPORTING visible = 'X',
*list_viewer->set_visible EXPORTING visible = ' '.
*ELSE.
call method: fill_list exporting infty = infty
pernr = pernr,
list_viewer->set_visible exporting visible = 'X',
html_viewer->set_visible exporting visible = ' '.
*ENDIF.
* CALL METHOD cl_gui_cfw=>flush.
endmethod. "handle_node_double_click
*METHOD fill_html.
*DATA url TYPE scarr-url.
*SELECT SINGLE url
*FROM scarr
*INTO url
*WHERE infty = infty.
*CALL METHOD html_viewer->show_url EXPORTING url = url.
*ENDMETHOD.
method fill_list.
data: flight_tab type table of demofli,
begin of flight_title,
carrname type scarr-carrname,
cityfrom type spfli-cityfrom,
cityto type spfli-cityto,
end of flight_title,
list_layout type lvc_s_layo.
*DATA : it_pa0001 TYPE TABLE OF p0001.
if infty = '0001'.
select * from pa0001 into table it_pa0001 where pernr = pernr.
elseif infty = '0000'.
select * from pa0001 into table it_pa0001 where pernr = pernr.
endif.
*SELECT SINGLE c~carrname p~cityfrom p~cityto
*INTO CORRESPONDING FIELDS OF flight_title
*FROM ( scarr AS c
*INNER JOIN spfli AS p ON c~carrid = p~carrid )
*WHERE p~carrid = carrid AND
*p~connid = connid.
*SELECT fldate seatsmax seatsocc
*INTO CORRESPONDING FIELDS OF TABLE flight_tab
*FROM sflight
*WHERE carrid = carrid AND connid = connid
* ORDER BY fldate.
*CONCATENATE flight_title-carrname
*connid
*flight_title-cityfrom
*flight_title-cityto
list_layout-grid_title = 'TEST'.
list_layout-smalltitle = 'X'.
list_layout-cwidth_opt = 'X'.
list_layout-no_toolbar = 'X'.
*if infty = '0001'.
call method list_viewer->set_table_for_first_display
exporting
i_structure_name = 'PA0001'
is_layout = list_layout
changing
it_outtab = it_pa0001.
* CALL METHOD cl_gui_cfw=>flush.
*ELSEIF infty = '0001'.
*CALL METHOD list_viewer->set_table_for_first_display
*EXPORTING i_structure_name = 'PA0000'
*is_layout = list_layout
*CHANGING it_outtab = it_pa0000.
*endif.
endmethod. "fill_list
endclass. "screen_handler IMPLEMENTATION
start-of-selection.
data : it_pa0001 type table of p0001.
call screen 100.
* MODULE status_0100 OUTPUT
module status_0100 output.
set pf-status 'SCREEN_100'.
set titlebar 'TIT_100'.
call method screen_init=>init_screen.
* CALL METHOD cl_gui_cfw=>flush.
endmodule. "status_0100 OUTPUT
* MODULE cancel INPUT
module cancel input.
set screen 0.
leave program.
endmodule. "cancel INPUT
Plz Suggest ,
Regards ,
Paresh G.METHOD fill_tree.
DATA: node_table TYPE TABLE OF abdemonode,
node TYPE abdemonode.
*data : it_pa0001 TYPE TABLE OF p0001,
DATA :wa_pa0001 TYPE pa0001,
wa_pa0000 TYPE pa0000,
it_t582s TYPE TABLE OF t582s,
wa_t582s TYPE t582s.
TYPES : BEGIN OF ttab,
itext TYPE t582s-itext,
infty TYPE t582s-infty,
pernr TYPE p0001-pernr,
END OF ttab.
DATA : itab TYPE TABLE OF ttab,
wa_tab TYPE ttab.
FIELD-SYMBOLS : <fs> LIKE p_pernr.
DATA : text1 TYPE c.
node-hidden = ' '.
node-disabled = ' '.
node-isfolder = 'X'.
node-expander = ' '.
SELECT * FROM t582s
INTO CORRESPONDING FIELDS OF TABLE it_t582s
WHERE sprsl = sy-langu
AND infty IN ('0001','0000')."'0002','0006',
'0008','0015','0019').
LOOP AT it_t582s INTO wa_t582s .
MOVE-CORRESPONDING wa_t582s TO wa_tab.
node-node_key = wa_t582s-infty.
CLEAR node-relatkey.
CLEAR node-relatship.
node-text = wa_t582s-itext.
node-n_image = ' '.
node-exp_image = ' '.
APPEND node TO node_table.
LOOP AT p_pernr ASSIGNING <fs>.
wa_tab-pernr = <fs>-low.
APPEND wa_tab TO itab.
CLEAR p_pernr-low.
node-node_key = <fs>-low.
node-relatkey = wa_tab-infty.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-text = <fs>-low.
node-n_image = '@AV@'.
APPEND node TO node_table.
ENDLOOP.
CLEAR : wa_tab,wa_pa0001,wa_pa0000.
ENDLOOP.
CALL METHOD tree->add_nodes
EXPORTING
table_structure_name = 'ABDEMONODE'
node_table = node_table.
CALL METHOD cl_gui_cfw=>flush.
ENDMETHOD. "fill_tree -
Hello All,
I am calling the method FILE_OPEN_DIALOG of the class CL_GUI_FRONTEND_SERVICES to display the pop up to select the file from the desktop.After i select the file and execute the program it displays the report and when i clcik the back button it gives me the pop up again.I have used CALL METHOD CL_GUI_CFW=>FLUSH.Inspite of this it is not working properly.
Thanks,
Rakesh.Try This.....
AT SELECTION-SCREEN ON VALUE-REQUEST FOR F_PATH.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = file
rc = rtrncode
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
others = 5 -
How to use ABAP objects in ALV
Can u give me the steps for doing ALV with ABAP objects
Hello Mohammed
Here are a few simplified version of the SAP sample reports that I have posted within SDN.
This is a variant of my previously posted report ZUS_SDN_ALVGRID_EVENTS. Both dynpros (100 & 200) do not contain any elements. For simplicity I used the same flow logic for both dynpros:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
<b>&----
*& Report ZUS_SDN_ALVGRID_EVENTS_1
&----</b>
REPORT zus_sdn_alvgrid_events_1.
DATA:
gd_okcode TYPE ui_func,
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_docking2 TYPE REF TO cl_gui_docking_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid.
DATA:
gt_t001 TYPE STANDARD TABLE OF t001,
gt_knb1 TYPE STANDARD TABLE OF knb1.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row
e_column
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_double_click.
* define local data
DATA:
ls_t001 TYPE t001,
ls_col_id TYPE lvc_s_col.
CHECK ( sender = go_grid1 ).
READ TABLE gt_t001 INTO ls_t001 INDEX e_row-index.
CHECK ( ls_t001-bukrs IS NOT INITIAL ).
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = ls_t001-bukrs.
IF ( syst-subrc NE 0 ).
MESSAGE 'No customers found' TYPE 'S'.
ELSE.
* Trigger PAI of dynpro '0100' and set new ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code( 'CALL_SCREEN_0200' ).
ENDIF.
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM t001 INTO TABLE gt_t001.
REFRESH: gt_knb1.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT go_docking2
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT go_grid2
EXPORTING
i_parent = go_docking2
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Set event handler
SET HANDLER:
lcl_eventhandler=>handle_double_click FOR go_grid1.
* Display data
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'T001'
CHANGING
it_outtab = gt_t001
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'KNB1'
CHANGING
it_outtab = gt_knb1
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_docking2->link
EXPORTING
repid = syst-repid
dynnr = '0200'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'CALL_SCREEN_0200'.
go_grid2->refresh_table_display( ). " necessary
CALL SCREEN '0200'.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
The following sample report ZUS_SDN_ALVGRID_EVENTS shows how to call a transaction when event HOTSPOT_CLICK was raised:
<b>&----
*& Report ZUS_SDN_TWO_ALV_GRIDS
&----</b>
REPORT ZUS_SDN_ALVGRID_EVENTS.
DATA:
gd_okcode TYPE ui_func,
gt_fcat TYPE lvc_t_fcat,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid1 TYPE REF TO cl_gui_alv_grid.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1.
PARAMETERS:
p_bukrs TYPE bukrs DEFAULT '1000' OBLIGATORY.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_hotspot_click.
* define local data
DATA:
ls_knb1 TYPE knb1,
ls_col_id type lvc_s_col.
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row_id-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
* Set active cell to field BUKRS otherwise the focus is still on
* field KUNNR which will always raise event HOTSPOT_CLICK
ls_col_id-fieldname = 'BUKRS'.
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
IS_ROW_ID = e_row_id
IS_COLUMN_ID = ls_col_id.
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = p_bukrs.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_docking
EXCEPTIONS
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Set event handler
SET HANDLER:
lcl_eventhandler=>handle_hotspot_click FOR go_grid1.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog_knb1.
* Display data
CALL METHOD go_grid1->set_table_for_first_display
CHANGING
it_outtab = gt_knb1
it_fieldcatalog = gt_fcat
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Link the docking container to the target dynpro
CALL METHOD go_docking->link
EXPORTING
repid = syst-repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'END' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form BUILD_FIELDCATALOG_KNB1
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog_knb1 .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNB1'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE gt_fcat INTO ls_fcat
WITH KEY fieldname = 'KUNNR'.
IF ( syst-subrc = 0 ).
ls_fcat-hotspot = abap_true.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDIF.
ENDFORM. " BUILD_FIELDCATALOG_KNB1
Please note that the direct CALL TRANSACTION does not check the user's authority. To do so you could call the transaction using function module ABAP4_CALL_TRANSACTION.
Here is a sample program for OO-based ALV grids (CL_GUI_ALV_GRID) that simulates radio buttons by using icons with hotspots.
<b>PROGRAM ZUS_SDN_BCALV_GRID_DEMO_2.</b>
* Based on: BCALV_GRID_DEMO.
TYPE-POOLS: icon.
TYPES: BEGIN OF ty_s_sflight.
INCLUDE TYPE sflight.
TYPES: button1 TYPE lvc_emphsz.
TYPES: button2 TYPE lvc_emphsz.
TYPES: button3 TYPE lvc_emphsz.
TYPES: button4 TYPE lvc_emphsz.
TYPES: END OF ty_s_sflight.
DATA:
gt_sflight TYPE STANDARD TABLE OF ty_s_sflight,
gt_fcat TYPE lvc_t_fcat.
DATA: ok_code LIKE sy-ucomm,
* gt_sflight TYPE TABLE OF sflight,
g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
grid1 TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
md_cnt TYPE i.
CLASS-METHODS:
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_hotspot_click.
* define local data
FIELD-SYMBOLS:
<ls_entry> TYPE ty_s_sflight,
<ld_fld> TYPE ANY.
READ TABLE gt_sflight ASSIGNING <ls_entry> INDEX es_row_no-row_id.
CHECK ( <ls_entry> IS ASSIGNED ).
* Set all radio buttons "unselected"
<ls_entry>-button1 = icon_wd_radio_button_empty.
<ls_entry>-button2 = icon_wd_radio_button_empty.
<ls_entry>-button3 = icon_wd_radio_button_empty.
<ls_entry>-button4 = icon_wd_radio_button_empty.
ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE <ls_entry>
TO <ld_fld>.
IF ( <ld_fld> IS ASSIGNED ).
* Set selected radio button "selected".
<ld_fld> = icon_wd_radio_button.
ENDIF.
* Force PAI followed by refresh of table display in PBO
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'DUMMY'
* IMPORTING
* RC =
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
* MAIN *
PERFORM select_data.
CALL SCREEN 100.
* MODULE PBO OUTPUT *
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container.
CREATE OBJECT grid1
EXPORTING i_parent = g_custom_container.
PERFORM build_fieldcatalog.
CALL METHOD grid1->set_table_for_first_display
* EXPORTING
* i_structure_name = 'SFLIGHT'
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = gt_sflight.
* Set event handler for event TOOLBAR
SET HANDLER:
lcl_eventhandler=>handle_hotspot_click FOR grid1.
else.
CALL METHOD grid1->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
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.
ENDIF.
ENDMODULE. "PBO OUTPUT
* MODULE PAI INPUT *
MODULE pai INPUT.
* to react on oi_custom_events:
CALL METHOD cl_gui_cfw=>dispatch.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN OTHERS.
* do nothing
ENDCASE.
CLEAR ok_code.
ENDMODULE. "PAI INPUT
* FORM EXIT_PROGRAM *
FORM exit_program.
* CALL METHOD G_CUSTOM_CONTAINER->FREE.
* CALL METHOD CL_GUI_CFW=>FLUSH.
LEAVE PROGRAM.
ENDFORM. "EXIT_PROGRAM
*& Form BUILD_FIELDCATALOG
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat,
ls_hype TYPE lvc_s_hype.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'LVC_S_FCAT'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DELETE gt_fcat WHERE ( fieldname <> 'EMPHASIZE' ).
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'SFLIGHT'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE gt_fcat INTO ls_fcat
WITH KEY fieldname = 'EMPHASIZE'.
IF ( syst-subrc = 0 ).
DELETE gt_fcat INDEX syst-tabix.
ENDIF.
ls_fcat-fieldname = 'BUTTON4'.
ls_fcat-icon = 'X'.
ls_fcat-hotspot = 'X'.
INSERT ls_fcat INTO gt_fcat INDEX 4.
ls_fcat-fieldname = 'BUTTON3'.
INSERT ls_fcat INTO gt_fcat INDEX 4.
ls_fcat-fieldname = 'BUTTON2'.
INSERT ls_fcat INTO gt_fcat INDEX 4.
ls_fcat-fieldname = 'BUTTON1'.
INSERT ls_fcat INTO gt_fcat INDEX 4.
LOOP AT gt_fcat INTO ls_fcat.
ls_fcat-col_pos = syst-tabix.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDLOOP.
ENDFORM. " BUILD_FIELDCATALOG
*& Form SELECT_DATA
* text
* --> p1 text
* <-- p2 text
FORM select_data .
* define local data
DATA:
ls_sflight TYPE ty_s_sflight.
SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE gt_sflight.
ls_sflight-button1 = icon_wd_radio_button.
ls_sflight-button2 = icon_wd_radio_button_empty.
ls_sflight-button3 = icon_wd_radio_button_empty.
ls_sflight-button4 = icon_wd_radio_button_empty.
MODIFY gt_sflight FROM ls_sflight
TRANSPORTING button1 button2 button3 button4
WHERE ( carrid IS NOT INITIAL ).
ENDFORM. " SELECT_DATA
The various aspects of ALV list programming are collected within the reuse library (transaction <b>SE83</b>).
And do not miss to look at <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907">Easy Reference to ALV Grid Control</a>
Regards
Uwe -
Hi,
I am totally new to ALV Grids. Could you give a full example of creating a ALV Grid with 2 columns, thinking there is a internal table itab with itab-col1 & itab-col2. Please start from initialising variables and onwards.
Thanks,
KishanHi,
Simple example of how to implement an ALV grid
Note that this example uses table ZSFLIGHT. The table is equivalent to the table SFLIGHT.
Steps:
1. Create an executable program (Report)
2. Create a screen (100) and place a custom container named ALV_CONTAINER on the screen
3. Create a Pushbutton. Give it the text Exit and the functioncode EXIT
REPORT sapmz_hf_alv_grid .
TABLES: zsflight.
G L O B A L I N T E R N A L T A B L E S
DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
G L O B A L D A T A
DATA: ok_code LIKE sy-ucomm,
g_wa_sflight LIKE sflight.
Declare reference variables to the ALV grid and the container
DATA:
go_grid TYPE REF TO cl_gui_alv_grid,
go_custom_container TYPE REF TO cl_gui_custom_container.
S T A R T - O F - S E L E C T I O N.
START-OF-SELECTION.
SET SCREEN '100'.
*& Module USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Module STATUS_0100 OUTPUT
MODULE status_0100 OUTPUT.
Create objects
IF go_custom_container IS INITIAL.
CREATE OBJECT go_custom_container
EXPORTING container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
i_parent = go_custom_container.
PERFORM load_data_into_grid.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Form load_data_into_grid
FORM load_data_into_grid.
Read data from table SFLIGHT
SELECT *
FROM zsflight
INTO TABLE gi_sflight.
Load data into the grid and display them
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
CHANGING it_outtab = gi_sflight.
ENDFORM. " load_data_into_grid
Allow the user to save and reuse the layout
A button can be shown on the grid toolbar, allowing the user to save and reuse a layout. The button looks like this:
See also example in SAP standard program BCALV_GRID_09.
To do this use the parameters IS_VARIANT and I_SAVE of the set_table_for_first_display method. Note that the IS_VARIANT
parameter must have the structure DISVARIANT.
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
Add the following code to the example:
FORM load_data_into_grid.
DATA:
For parameter IS_VARIANT
l_layout TYPE disvariant.
Code..........
Load data into the grid and display them
l_layout-report = sy-repid.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_variant = l_layout
i_save = 'A'
CHANGING it_outtab = gi_
Integrate user defined functions in the grid toolbar
Possibilities:
· Replace existing functions in the toolbar or context men with user defined functions
· Add new functions to the toolbar or context menu
Note that the whole toolbar can be removed using the IT_TOOLBAR_EXCLUDING parameter of the set_table_for_first_display
method.
See also example in SAP standard program BCALV_GRID_05
1) To get access to the icons insert the following statement in the top of the program:
TYPE-POOLS: icon.
2) To allow the declaration of o_event_receiver before the lcl_event_receiver class is defined, declare it as deferred in the start of
the program
To allow the declaration of o_event_receiver before the lcl_event_receiver class is defined, declare it as deferred in the
start of the program
CLASS lcl_event_receiver DEFINITION DEFERRED.
3) Declare reference to the event handler class
DATA:
o_event_receiver TYPE REF TO lcl_event_receiver.
4) Class for event receiver. This class adds the new button to the toolbar and handles the event when the button is pushed
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 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'Change flight' TO ls_toolbar-quickinfo.
MOVE 'Change' 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 'CHANGE'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.
5) In the PBO module, crate object for event handler and set handler
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.
6) In the PBO module after the CALL METHOD go_grid->set_table_for_first_display, raise event
toolbar to show the modified toolbar
CALL METHOD go_grid->set_toolbar_interactive.
Set focus to the grid
After CALL METHOD go_grid->set_table_for_first_display insert the following statement:
CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
Set the title of the grid
Fill the grid_title field of structure lvc_s_layo.
Note that the structure lvc_s_layo can be used for to customize the grid appearance in many ways.
DATA:
ALV control: Layout structure
gs_layout TYPE lvc_s_layo.
Set grid title
gs_layout-grid_title = 'Flights'.
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
Customize the appearence of the grid
The structure lvc_s_layo contains fields for setting graphical properties, displaying exceptions, calculating totals and enabling specific
interaction options.
Fill the apporpiate fields of structure lvc_s_layo and insert it as a parameter in the CALL METHOD
go_grid->set_table_for_first_display. See the example under Set the title of the grid.
If you want to change apperance after list output, use the methods get_frontend_layout and set_frontend_layout.
Examples of fields in structure lvc_s_layo:
GRID_TITLE Setting the title of the grid
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.
Make an Exception field ( = Traffic lights)
There can be defined a column in the grid for display of traffic lights. This field is of type Char 1, and can contain the following values:
· 1 Red
· 2 Yellow
· 3 Green
The name of the traffic light field is supplied inh the gs_layout-excp_fname used by method set_table_for_first_display.
Example
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
TYPES: traffic_light TYPE c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
Set the exception field of the table
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-traffic_light = '1'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
ELSE.
g_wa_sflight-traffic_light = '3'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Name of the exception field (Traffic light field)
gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
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.
Color a line
The steps for coloring a line i the grid is much the same as making a traffic light.
To color a line the structure of the table must include a Char 4 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.
Refresh grid display
Use the grid method REFRESH_TABLE_DISPLAY
Example:
CALL METHOD go_grid->refresh_table_display.
Complete code for the ALV grid example
This example shows and ALV grid with flights. After selecting a line a change button can be pushed to display a change screen. After
the changes have been saved, the ALV grid screen is displayed again, and the grid is updated with the changes.
The example shows:
· How to setup the ALV grid
· How to ste focus to the grid
· How to set the title of the grid
· How to allow a user to save and reuse a grid layout (Variant)
· How to customize the ALV grid toolbar
· Refresh the grid
· Set and get row selection and read line contents
· Make and exception field (Traffic light)
· Coloring a line
Steps:
· Create screen 100 with the ALV grid. Remember to include an exit button
· Add a change button to the ALV grid toolbar
· Create screen 200 the Change screen
The screens:
The code:
REPORT sapmz_hf_alv_grid .
Type pool for icons - used in the toolbar
TYPE-POOLS: icon.
TABLES: zsflight.
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.
G L O B A L I N T E R N A L T A B L E S
*DATA: gi_sflight TYPE STANDARD TABLE OF sflight.
To include a traffic light and/or color a line the structure of the
table must include fields for the traffic light and/or the color
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for traffic light
TYPES: traffic_light TYPE c.
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.
G L O B A L D A T A
DATA: ok_code LIKE sy-ucomm,
Work area for internal table
g_wa_sflight TYPE st_sflight,
ALV control: Layout structure
gs_layout TYPE lvc_s_layo.
Declare reference variables to the ALV grid and the container
DATA:
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:
Work area for screen 200
g_screen200 LIKE zsflight.
Data for storing information about selected rows in the grid
DATA:
Internal table
gi_index_rows TYPE lvc_t_row,
Information about 1 row
g_selected_row LIKE lvc_s_row.
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 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'Change flight' TO ls_toolbar-quickinfo.
MOVE 'Change' 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 'CHANGE'.
PERFORM change_flight.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMETHOD.
ENDCLASS.
S T A R T - O F - S E L E C T I O N.
START-OF-SELECTION.
SET SCREEN '100'.
*& Module USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Module STATUS_0100 OUTPUT
MODULE status_0100 OUTPUT.
DATA:
For parameter IS_VARIANT that is sued to set up options for storing
the grid layout as a variant in method set_table_for_first_display
l_layout TYPE disvariant,
Utillity field
l_lines TYPE i.
After returning from screen 200 the line that was selected before
going to screen 200, should be selected again. The table gi_index_rows
was the output table from the GET_SELECTED_ROWS method in form
CHANGE_FLIGHT
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.
CALL METHOD cl_gui_cfw=>flush.
REFRESH gi_index_rows.
ENDIF.
Read data and create objects
IF go_custom_container IS INITIAL.
Read data from datbase table
PERFORM get_data.
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 fo report
Setup the grid layout using a variable of structure lvc_s_layo
Set grid title
gs_layout-grid_title = 'Flights'.
Selection mode - Single row without buttons
(This is the default mode
gs_layout-sel_mode = 'B'.
Name of the exception field (Traffic light field) and the color
field + set the exception and color field of the table
gs_layout-excp_fname = 'TRAFFIC_LIGHT'.
gs_layout-info_fname = 'LINE_COLOR'.
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
Value of traffic light field
g_wa_sflight-traffic_light = '1'.
Value of color field:
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
ELSE.
g_wa_sflight-traffic_light = '3'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_variant = l_layout
i_save = 'A'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
*-- End of grid setup -
Raise event toolbar to show the modified toolbar
CALL METHOD go_grid->set_toolbar_interactive.
Set focus to the grid. This is not necessary in this
example as there is only one control on the screen
CALL METHOD cl_gui_control=>set_focus EXPORTING control = go_grid.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0200 INPUT
MODULE user_command_0200 INPUT.
CASE ok_code.
WHEN 'EXIT200'.
LEAVE TO SCREEN 100.
WHEN'SAVE'.
PERFORM save_changes.
ENDCASE.
ENDMODULE. " USER_COMMAND_0200 INPUT
*& Form get_data
FORM get_data.
Read data from table SFLIGHT
SELECT *
FROM zsflight
INTO TABLE gi_sflight.
ENDFORM. " load_data_into_grid
*& Form change_flight
Reads the contents of the selected row in the grid, ans transfers
the data to screen 200, where it can be changed and saved.
FORM change_flight.
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. In this example only one
row can be selected as we are using gs_layout-sel_mode = 'B',
so it is only ncessary to read the first entry in
table gi_index_rows
LOOP AT gi_index_rows INTO g_selected_row.
IF sy-tabix = 1.
READ TABLE gi_sflight INDEX g_selected_row-index INTO g_wa_sflight.
ENDIF.
ENDLOOP.
Transfer data from the selected row to screenm 200 and show
screen 200
CLEAR g_screen200.
MOVE-CORRESPONDING g_wa_sflight TO g_screen200.
LEAVE TO SCREEN '200'.
ENDFORM. " change_flight
*& Form save_changes
Changes made in screen 200 are written to the datbase table
zsflight, and to the grid table gi_sflight, and the grid is
updated with method refresh_table_display to display the changes
FORM save_changes.
DATA: l_traffic_light TYPE c.
Update traffic light field
Update database table
MODIFY zsflight FROM g_screen200.
Update grid table , traffic light field and color field.
Note that it is necessary to use structure g_wa_sflight
for the update, as the screen structure does not have a
traffic light field
MOVE-CORRESPONDING g_screen200 TO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-traffic_light = '1'.
C = Color, 6=Color 1=Intesified on, 0: Inverse display off
g_wa_sflight-line_color = 'C610'.
ELSEIF g_wa_sflight-paymentsum => 100000 AND
g_wa_sflight-paymentsum < 1000000.
g_wa_sflight-traffic_light = '2'.
clear g_wa_sflight-line_color.
ELSE.
g_wa_sflight-traffic_light = '3'.
clear g_wa_sflight-line_color.
ENDIF.
MODIFY gi_sflight INDEX g_selected_row-index FROM g_wa_sflight.
Refresh grid
CALL METHOD go_grid->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
LEAVE TO SCREEN '100'.
ENDFORM. " save_changes
rgds,
latheesh
Maybe you are looking for
-
External drive has problems every day
I've got a 500GB Toshiba USB drive that I use for TimeMachine backups. When it works, it works. However, it breaks once a day. At the end of each day, I eject the drive and store the computer in a drawer. The next day, I wake up the computer and then
-
We can see the data in an indicator just fine, but when we try to write that string of hexadecimal data to a file, it will only save the data in ASCII format. This sounds fairly simple, as the indicator can be selected to display the data in severa
-
External transaction control and ability to find new registered objects
Hello, We are using Toplink with external transaction control and have a process inserting a complex hierarchy of objects. During the process we either do a registerObject or deepmergeClone depending on if the instance is already in the db. With exte
-
Hi when i open my email there is pdf docouments not open showing not valid file
-
Auto calc time for shot duration, fails to change or appears to be in fixed mode.
Switching back and forth online to offline as you recommended is causing sync issues, additionally, the shot duration set for auto calc defaults back to custom so not certain if times are fixed, correct or not. drgm