About CL_GUI_ALV_GRID's event-handling & PAI/PBO
Hi, all,
I met a problem when using CL_GUI_ALV_GRID's event-handling.
I created a simple event-handling-class with an event-handling-method for DOUBLE-CLICK event of CL_GUI_ALV_GRID. And the event-handling-method, only makes some changes to the contents of itab to be shown in ALV_GRID.
The problem is: In my idea, after event-dispatch and event-handling in PAI, subsequent PBO will be called. Since SET_TABLE_FOR_FIRST_DISPLAY is called in PBO, I would saw the changed itab shown. BUT, I saw the contents of the itab remaining unchanged.
* PAI module, DISPATCH the event
CASE OK_CODE.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
I debugged, and found that, after event-handling-method, PBO module doesn't execute.
That's my wondering, after the preceding PAI, shouldn't the subsequent PBO appear? OR is event-handling different from other user actions?
Many thanks.
Hi,
for double click you need explicit handler ,
just check it.
REPORT ZTEST1234 MESSAGE-ID ZZ .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID, "First
G_GRID1 TYPE REF TO CL_GUI_ALV_GRID. "Second
DATA: L_VALID TYPE C,
V_FLAG,
V_DATA_CHANGE,
V_ROW TYPE LVC_S_ROW,
V_COLUMN TYPE LVC_S_COL,
V_ROW_NUM TYPE LVC_S_ROID.
DATA: OK_CODE LIKE SY-UCOMM,
SAVE_OK LIKE SY-UCOMM,
G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST', "First Container
G_CONTAINER2 TYPE SCRFNAME VALUE 'TEST1',"Second container
GS_LAYOUT TYPE LVC_S_LAYO.
DATA:BEGIN OF ITAB OCCURS 0,
VBELN LIKE LIKP-VBELN,
POSNR LIKE LIPS-POSNR,
LFDAT like lips-vfdat,
BOX(1),
HANDLE_STYLE TYPE LVC_T_STYL,
END OF ITAB.
* CLASS lcl_event_handler DEFINITION
CLASS LCL_EVENT_HANDLER DEFINITION .
PUBLIC SECTION .
METHODS:
**Hot spot Handler
HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
**Handler to Check the Data Change
HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED
OF CL_GUI_ALV_GRID
IMPORTING ER_DATA_CHANGED
E_ONF4
E_ONF4_BEFORE
E_ONF4_AFTER,
**Double Click Handler
HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN ES_ROW_NO.
ENDCLASS. "lcl_event_handler DEFINITION
* CLASS lcl_event_handler IMPLEMENTATION
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
*Handle Hotspot Click
METHOD HANDLE_HOTSPOT_CLICK .
CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
V_ROW = E_ROW_ID.
V_COLUMN = E_COLUMN_ID.
V_ROW_NUM = ES_ROW_NO.
MESSAGE I000 WITH V_ROW 'clicked'.
ENDMETHOD. "lcl_event_handler
*Handle Double Click
METHOD HANDLE_DOUBLE_CLICK.
CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
V_ROW = E_ROW.
V_COLUMN = E_COLUMN.
V_ROW_NUM = ES_ROW_NO.
IF E_COLUMN = 'VBELN'.
SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
ENDIF.
IF E_COLUMN = 'POSNR'.
MESSAGE I000 WITH 'Click on POSNR row number ' E_ROW.
"with this row num you can get the data
ENDIF.
ENDMETHOD. "handle_double_click
**Handle Data Change
METHOD HANDLE_DATA_CHANGED.
CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY
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.
ENDMETHOD. "HANDLE_DATA_CHANGED
ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION
*& Global Definitions
DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1
G_HANDLER TYPE REF TO LCL_EVENT_HANDLER, "handler
G_CUSTOM_CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER. "Container2
*- Fieldcatalog for First and second Report
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
X_FIELDCAT TYPE LVC_S_FCAT,
LS_VARI TYPE DISVARIANT.
* START-OF_SELECTION
START-OF-SELECTION.
SELECT VBELN
POSNR
FROM LIPS
UP TO 20 ROWS
INTO CORRESPONDING FIELDS OF TABLE ITAB.
END-OF-SELECTION.
IF NOT ITAB[] IS INITIAL.
CALL SCREEN 100.
ELSE.
MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
ENDIF.
*& Form CREATE_AND_INIT_ALV
* text
FORM CREATE_AND_INIT_ALV .
DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
"First Grid
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = G_CONTAINER1.
CREATE OBJECT G_GRID
EXPORTING I_PARENT = G_CUSTOM_CONTAINER.
"Second Grid
CREATE OBJECT G_CUSTOM_CONTAINER1
EXPORTING CONTAINER_NAME = G_CONTAINER2.
CREATE OBJECT G_GRID1
EXPORTING I_PARENT = G_CUSTOM_CONTAINER1.
* Set a titlebar for the grid control
CLEAR GS_LAYOUT.
GS_LAYOUT-GRID_TITLE = TEXT-003.
GS_LAYOUT-ZEBRA = SPACE.
GS_LAYOUT-CWIDTH_OPT = 'X'.
GS_LAYOUT-NO_ROWMARK = 'X'.
GS_LAYOUT-BOX_FNAME = 'BOX'.
GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
GS_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
CREATE OBJECT G_HANDLER.
SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
* SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
SET HANDLER G_HANDLER->HANDLE_DATA_CHANGED FOR G_GRID.
data: ls_outatb like line of itab,
v_index type sy-tabix.
DATA: LS_EDIT TYPE LVC_S_STYL,
LT_EDIT TYPE LVC_T_STYL.
LOOP AT ITAB INTO ls_outatb WHERE POSNR = '000010'.
V_INDEX = SY-TABIX.
LS_EDIT-FIELDNAME = 'VBELN'.
LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
LS_EDIT-STYLE2 = SPACE.
LS_EDIT-STYLE3 = SPACE.
LS_EDIT-STYLE4 = SPACE.
LS_EDIT-MAXLEN = 8.
INSERT LS_EDIT INTO TABLE LT_EDIT.
INSERT LINES OF LT_EDIT INTO TABLE ls_outatb-handle_style.
MODIFY ITAB INDEX V_INDEX FROM ls_outatb TRANSPORTING
HANDLE_STYLE.
ENDLOOP.
* setting focus for created grid control
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = G_GRID.
* Build fieldcat and set editable for date and reason code
* edit enabled. Assign a handle for the dropdown listbox.
PERFORM BUILD_FIELDCAT.
* Optionally restrict generic functions to 'change only'.
* (The user shall not be able to add new lines).
PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
**Vaiant to save the layout
LS_VARI-REPORT = SY-REPID.
LS_VARI-HANDLE = SPACE.
LS_VARI-LOG_GROUP = SPACE.
LS_VARI-USERNAME = SPACE.
LS_VARI-VARIANT = SPACE.
LS_VARI-TEXT = SPACE.
LS_VARI-DEPENDVARS = SPACE.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED.
**Calling the Method for ALV output for First Grid
CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
IS_VARIANT = LS_VARI
IS_LAYOUT = GS_LAYOUT
I_SAVE = 'A'
CHANGING
IT_FIELDCATALOG = IT_FIELDCAT
IT_OUTTAB = ITAB[].
**Calling the Method for ALV output for Second Grid
CALL METHOD G_GRID1->SET_TABLE_FOR_FIRST_DISPLAY
* EXPORTING
* IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
CHANGING
IT_FIELDCATALOG = IT_FIELDCAT
IT_OUTTAB = ITAB[].
* Set editable cells to ready for input initially
CALL METHOD G_GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 1.
ENDFORM. "CREATE_AND_INIT_ALV
*& Form EXCLUDE_TB_FUNCTIONS
* text
* -->PT_EXCLUDE text
FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
* Only allow to change data not to create new entries (exclude
* generic functions).
DATA LS_EXCLUDE TYPE UI_FUNC.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
*& Form build_fieldcat
* Fieldcatalog
FORM BUILD_FIELDCAT .
DATA: L_POS TYPE I.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-NO_ZERO = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Item'(025).
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Del Date'(015).
X_FIELDCAT-FIELDNAME = 'LFDAT'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '10'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
ENDFORM. " build_fieldcat
*& Module STATUS_0100 OUTPUT
* text
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
IF G_CUSTOM_CONTAINER IS INITIAL.
**Initializing the grid and calling the fm to Display the O/P
PERFORM CREATE_AND_INIT_ALV.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
Regards
vijay
Similar Messages
-
Cl_gui_alv_grid onf4 event handler
Has anyone got a nice, tight, example of an ONF4 event handler using CL_GUI_ALV_GRID that they'd be willing to share?
I'm trying to figure out the example in BCALV_EDIT_08. But, it's very difficult to follow.
If BCALV_EDIT_08 is indicative of how much work you have to do to enable this event ... phew, that's a lot of code you have to enter just for this 'simple' task.Hi,
Try this one
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
PERFORM f230_value_request.
FORM f230_value_request.
DATA: lv_exit TYPE c,
lw_variant LIKE w_variant.
w_variant-report = sy-repid.
w_variant-username = sy-uname.
Invoke function to provide drop down entries
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = w_variant
i_save = c_a
IMPORTING
e_exit = lv_exit
es_variant = lw_variant
EXCEPTIONS
not_found = 1
program_error = 2
OTHERS = 3.
IF sy-subrc IS INITIAL.
IF lv_exit IS INITIAL.
p_layout = lw_variant-variant.
ENDIF.
ELSE.
MESSAGE i037. "'No layouts found'
ENDIF.
ENDFORM. " f230_value_request
Thanks & Regards,
Judith. -
Error in event handler method in window
Hi,
I have created configuration in SEFVISU, to receive the workitem i have created a parameter in event handler method in window
but it is throwing dump The ASSERT condition was violated, if i remove that parameter means application executing properly but i am not able to pass the unique, values please guide me.
Regards,
Srini.Hello Srini,
are you talking about the default event handler method of the window? if so then you need to ensure that the parameter name defined in the event and passed in name are same. And also its better to go for the parameter type as STRING.
other option would be instead of defining the static parameters in the event handler method, you can get the parameters from the WDEVENT itself by accessing WDEVENT->PARAMETERS table.
hope this helps.
BR, Saravanan -
Forcing PAI processing in the absence of a local event handler
I have a dynpro screen with a splitter container on it.
Each side is populated with a readonly gui object (of cl_gui_textedit and cl_gui_alv_grid).
No special event handling had been enabled for these objects.
I have an application toolbar button defined in the gui status as an application event.
When I click the button, I do not go into PAI processing. (buttons defined as exit commands do hit PAI)
Is there a way to force PAI processing here in the absence of a local event handler, or I must I implement one. If so, to what event would it respond as I am not hitting a gui control.
( Is there a way to force a set_new_okay_code into it? )
Thanks...
...MikeMike,
Not sure 100% of what you are asking, however, I'll respond in hopes of a hit.
The ALV Grid allows you to create events in the initialization of the grid. You build a line for USER_COMMAND and can respond to an event in a FORM you have in your program that
looks something like the following.
FORM user_command
USING p_ucomm LIKE sy-ucomm
p_selfield TYPE slis_selfield.
CASE P_UCOMM.
WHEN .....
Generally, when I use this routine, I add the buttons to the ALV's Toolbar and respond to it in the USER_COMMAND form.
The routines I've provided here come from a report program, but the concept is the same for the
ALV_GRID OO that you are likely using. -
Site
Hello everyone. I get an error in my chrome cosole, what can I do about this?
I dont have this problem in all browsers, just in chrome, and in some versions of Firefox.
The problem occurs when I click any label in the iframe (see website, speaks for itself).
line 5838 window.console.log("Javascript error in event handler! Event Type = " + eventType);
does anyone know how to fix this?
And why do I only have this problem in some browsers?I basically want the labels in the Iframe to make the parent page animate to a specific anchor tag.
ps. This is what I posted on the jquery forum as well:
I tried to do this by letting the iframe .trigger a .click to a button on the .parent page.
I did this in two ways.
one: the click is triggerd in (/by) the iframe
two: the click is triggerd by a script in the parent window, that script is launched by the iframe
Here's the thing:
this is what one of the <a>'s that the iframe will click looks like:
<a class="nonblock nontext anim_swing" id="u185" href="index.html#contact"><!-- simple frame --></a>
The code is generated by adobe muse which has a function to smoothly scroll to a location on the page, and I am guessing the "anim_swing" class takes care of that.
I would like the colorful labels in the iframe to do the same thing as the <a> above.
and it works in some browsers on some computers but somehow not on all of them (with method two the adblocker doesn't seem to be an issue ).
I also tried to let the parent page scroll directly with the jquery .scrollto function. That did not work either (see the jquery forum). -
hi
i am trying to develop a event handler for all the attributes of a resource that when user is modified is attributes. he need get a notification that paritcular attribute or u r data is modified..
actually i have seen that they have return adapter for each attribute but dont want so many adapters to be writtten so i want to develop a event handler for that scenario... please provide the sample code so that i can modifie or re coding it....
thanks
avinashHi,
I had created one dissconnected resource and one application form for it... the user had filled the form of that resource and submitted and when he want to update the form once again the event handler should be tirrger and paritcular attribute should be update and he had to send email notification that attribute is changed...
here is once thing that if he had change numberof attributes at a time but we have to send only one email notification for all the attributes...
regards
avinash -
Question on program structure about event handling in nested JPanels in GUI
Hi All,
I'm currently writing a GUI app with a wizard included in the app. I have one class that acts as a template for each of the panels in the wizard. That class contains a JPanel called contentsPanel that I intend to put the specific contents into. I also want the panel contents to be modular so I have a couple of classes for different things, e.g. name and address panel, etc. these panels will contain checkboxes and the like that I want to event listeneres to watch out for. Whats the best way of implementing event handling for panel within panel structure? E.g for the the checkbox example,would it be a good idea to have an accessor method that returns the check book object from the innerclass/panel and use an addListener() method on the returned object in the top level class/panel. Or is it better to have the event listeners for those objects in the same class? I would appreciate some insight into this?
Regards!MyMainClass.main(new String[] { "the", "arguments" });
// or, if you defined your main to use varags (i.e. as "public static void main(String... args)") then you can just use
MyMainClass.main("the", "arguments");But you should really extract your functionality out of the main method into meaningful classes and methods and just use those from both your console code and your GUI code. -
Beginners Questions about Multiple JPanels in JFrame and event handling
I am a newbie with SWING, and even a newerbie in Event Handling. So here goes.
I am writing a maze program. I am placing a maze JPanel (MazePanel) at the center of a JFrame, and a JPanel of buttons (ButtonPanel) on the SOUTH pane. I want the buttons to be able to re-randomize the maze, solve the maze, and also ouput statistics (for percolation theory purposes). I have the backbone all done already, I am just creating the GUI now. I am just figuring out EventHandlers and such through the tutorials, but I have a question. I am adding an ActionListener to the buttons which are on the ButtonPanel which are on JFrame (SOUTH) Panel. But who do I make the ActionListener--Basically the one doing the work when the button is pressed. Do I make the JFrame the ActionListener or the MazePanel the ActionListener. I need something which has access to the maze data (the backbone), and which can call the Maze.randomize() function. I'm trying to make a good design and not just slop too.
Also I was wondering if I do this
JButton.addActionListener(MazePanel), and lets say public MazePanel implments ActionListenerdoesn't adding this whole big object to another object (namely the button actionlistener) seem really inefficient? And how does something that is nested in a JPanel on JFrame x get information from something nested in another JPanel on a JFrame x.
Basically how is the Buttons going to talk to the maze when the maze is so far away?I'm not an expert, but here's what I'd do....
You already have your business logic (the Maze classes), you said. I'm assuming you have some kind of public interface to this business logic. I would create a new class like "MazeGui" that extends JFrame, and then create the GUI using this class. Add buttons and panels as needed to get it to look the way you want. Then for each button that does a specific thing, add an anonymous ActionListener class to it and put whatever code you need inside the ActionListener that accesses the business logic classes and does what it needs to.
This is the idea, though my code is totally unchecked and won't compile:
import deadseasquirrels.mazestuff.*;
public class MazeGui extends JFrame {
JPanel buttonPanel = new JPanel();
JPanel mazePanel = new JPanel();
JButton randomizeB = new JButton();
JButton solveB = new JButton();
JButton statsB = new JButton();
// create instanc(es) of your Maze business logic class(es)
myMaze = new MazeClass();
// add the components to the MazeGui content pane
Component cp = getContentPane();
cp.add(); // this doesn't do anything, but in your code you'd add
// all of your components to the MazeGui's contentpane
randomizeB.addActionListener(new ActionListener {
void actionPerformed() {
Maze newMaze = myMaze.getRandomMazeLayout();
mazePanel.setContents(newMaze); // this is not a real method!
// it's just to give you the idea
// of how to manipulate the JPanel
// representing your Maze diagram,
// you will probably be changing a
// subcomponent of the JPanel
solveB.addActionListener(new ActionListener {
void actionPerformed() {
Solution mySolution = myMaze.getSolution();
mazePanel.setContents(mySolution); // again, this is not a real
// method but it shows you how
// the ActionListener can
// access your GUI
// repeat with any other buttons you need
public static void main(String[] args) {
MazeGui mg = new MazeGui();
mg.setVisible(true);
// etc...
} -
About Event Handling in user Defined Form (In Addon)
Hi Every One,
Can Anyone Give Me Notes On EventHandling in forms That are Disgened using Sdk UIAPI .Like Button event ,application event, menuevent... etc with saple code
Regards
SrinivasHi Sura,
Hope this helps. C# sample code.
// SAP MANAGE UI API 2005 SDK Sample
// File: CatchingEvents.cs
// Copyright (c) SAP MANAGE
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// BEFORE STARTING:
// 1. Add reference to the "SAP Business One UI API"
// 2. Insert the development connection string to the "Command line argument"
// 1.
// a. Project->Add Reference...
// b. select the "SAP Business One UI API 2005" From the COM folder
// 2.
// a. Project->Properties...
// b. choose Configuration Properties folder (place the arrow on Debugging)
// c. place the following connection string in the 'Command line arguments' field
// 0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056
using System;
using System.Windows.Forms;
class CatchingEvents {
// This parameter will use us to manipulate the
// SAP Business One Application
private SAPbouiCOM.Application SBO_Application;
private void SetApplication() {
// Use an SboGuiApi object to establish connection
// with the SAP Business One application and return an
// initialized appliction object
SAPbouiCOM.SboGuiApi SboGuiApi = null;
string sConnectionString = null;
SboGuiApi = new SAPbouiCOM.SboGuiApi();
// by following the steps specified above, the following
// statment should be suficient for either development or run mode
sConnectionString = System.Convert.ToString( Environment.GetCommandLineArgs().GetValue( 1 ) );
// connect to a running SBO Application
SboGuiApi.Connect( sConnectionString );
// get an initialized application object
SBO_Application = SboGuiApi.GetApplication( -1 );
public CatchingEvents() {
// set SBO_Application with an initialized application object
SetApplication();
// events handled by SBO_Application_AppEvent
SBO_Application.AppEvent += new SAPbouiCOM._IApplicationEvents_AppEventEventHandler( SBO_Application_AppEvent );
// events handled by SBO_Application_MenuEvent
SBO_Application.MenuEvent += new SAPbouiCOM._IApplicationEvents_MenuEventEventHandler( SBO_Application_MenuEvent );
// events handled by SBO_Application_ItemEvent
SBO_Application.ItemEvent += new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler( SBO_Application_ItemEvent );
// events handled by SBO_Application_ProgressBarEvent
SBO_Application.ProgressBarEvent += new SAPbouiCOM._IApplicationEvents_ProgressBarEventEventHandler( SBO_Application_ProgressBarEvent );
// events handled by SBO_Application_StatusBarEvent
SBO_Application.StatusBarEvent += new SAPbouiCOM._IApplicationEvents_StatusBarEventEventHandler( SBO_Application_StatusBarEvent );
private void SBO_Application_AppEvent( SAPbouiCOM.BoAppEventTypes EventType ) {
// the following are the events sent by the application
// (Ignore aet_ServerTermination)
// in order to implement your own code upon each of the events
// place you code instead of the matching message box statement
switch ( EventType ) {
case SAPbouiCOM.BoAppEventTypes.aet_ShutDown:
SBO_Application.MessageBox( "A Shut Down Event has been caught" + Environment.NewLine + "Terminating Add On...", 1, "Ok", "", "" );
// Take care of terminating your AddOn application
System.Windows.Forms.Application.Exit();
break;
case SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged:
SBO_Application.MessageBox( "A Company Change Event has been caught", 1, "Ok", "", "" );
// Check the new company name, if your add on was not meant for
// the new company terminate your AddOn
// If SBO_Application.Company.Name Is Not "Company1" then
// Close
// End If
break;
case SAPbouiCOM.BoAppEventTypes.aet_LanguageChanged:
SBO_Application.MessageBox( "A Languge Change Event has been caught", 1, "Ok", "", "" );
break;
private void SBO_Application_MenuEvent( ref SAPbouiCOM.MenuEvent pVal, out bool BubbleEvent ) {
// in order to activate your own forms instead of SAP Business One system forms
// process the menu event by your self
// change BubbleEvent to False so that SAP Business One won't process it
BubbleEvent = true;
if ( pVal.BeforeAction == true ) {
SBO_Application.SetStatusBarMessage( "Menu item: " + pVal.MenuUID + " sent an event BEFORE SAP Business One processes it.", SAPbouiCOM.BoMessageTime.bmt_Long, true );
// to stop SAP Business One from processing this event
// unmark the following statement
// BubbleEvent = False
else {
SBO_Application.SetStatusBarMessage( "Menu item: " + pVal.MenuUID + " sent an event AFTER SAP Business One processes it.", SAPbouiCOM.BoMessageTime.bmt_Long, true );
private void SBO_Application_ItemEvent( string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent ) {
// BubbleEvent sets the behavior of SAP Business One.
// False means that the application will not continue processing this event.
BubbleEvent = true;
if ( pVal.FormType != 0 ) {
// the message box form type is 0
// I chose not to deal with events triggered by a message box
// every event will open a message box with the event
// name and the form UID how sent it
SAPbouiCOM.BoEventTypes EventEnum = 0;
EventEnum = pVal.EventType;
// To prevent an endless loop of MessageBoxes,
// we'll not notify et_FORM_ACTIVATE and et_FORM_LOAD events
if ( ( EventEnum != SAPbouiCOM.BoEventTypes.et_FORM_ACTIVATE ) & ( EventEnum != SAPbouiCOM.BoEventTypes.et_FORM_LOAD ) ) {
SBO_Application.MessageBox( "An " + EventEnum.ToString() + " has been sent by a form with the unique ID: " + FormUID, 1, "Ok", "", "" );
private void SBO_Application_ProgressBarEvent( ref SAPbouiCOM.ProgressBarEvent pVal, out bool BubbleEvent) {
SAPbouiCOM.BoProgressBarEventTypes EventEnum = 0;
EventEnum = pVal.EventType;
BubbleEvent = true;
SBO_Application.MessageBox( "The event " + EventEnum.ToString() + " has been sent", 1, "Ok", "", "" );
private void SBO_Application_StatusBarEvent( string Text, SAPbouiCOM.BoStatusBarMessageType MessageType ) {
SBO_Application.MessageBox( @"Status bar event with message: """ + Text + @""" has been sent", 1, "Ok", "", "" );
Regards,
Jay. -
Question about event handling in JComponents
I have often found it useful to create a component that acts as an event handler for events the component generates itself. For example, a panel that listens for focus events that effect it and handle these events internally. (See below).
My question is: Can this practice cause synchronization issues or any other type of problem that I need to watch out for? Is it good/bad or neither. Are there any issues I should be aware of?
Thanks in advance for the help.
Example:
public class qPanel extends JPanel implements FocusListener
public qPanel () {
super.addFocusListener(this);
public void focusGained(FocusEvent e) {
//Do stuff
public void focusLost(FocusEvent e) {
//Do stuff
}Hi,
Handling events this way is completely fine and saves on number of classes. Only thing you may want to watch out for is that the handler methods have to be public. This means that someone could use your component and call one of the methods. For example, I could write:
panel.focusGained(new FocusEvent(....))
when it's not really gaining focus. So, if you're writing this component for re-use you might want to be aware of this.
An alternative:
Use a single internal class to handle all events. It can then delegate to private methods of your component. Example:
class MyEventHandler implements FocusListener, MouseListener, etc... {
public void focusGained(FocusEvent fe) {
doFocusGained(fe);
public void mousePressed(MouseEvent me) {
doMousePressed(me);
Then your component could have:
private void doFocusGained(FocusEvent fe) {
private void doMousePressed(MouseEvent me) {
etc...
Just ideas :)
Thanks!
Shannon Hickey (Swing Team)
I have often found it useful to create a component
that acts as an event handler for events the component
generates itself. For example, a panel that listens
for focus events that effect it and handle these
events internally. (See below).
My question is: Can this practice cause
synchronization issues or any other type of problem
that I need to watch out for? Is it good/bad or
neither. Are there any issues I should be aware of?
Thanks in advance for the help.
Example:
public class qPanel extends JPanel implements
FocusListener
public qPanel () {
super.addFocusListener(this);
public void focusGained(FocusEvent e) {
//Do stuff
public void focusLost(FocusEvent e) {
//Do stuff -
Event handling in global class (abap object)
Hello friends
I have 1 problem regarding events in abap object... how to handel an event in global class in se24 .
Regards
Reema jain.
Message was edited by:
Reema JainHello Reema
The following sample report shows how to handle event in principle (see the § marks)..
The following sample report show customer data ("Header"; KNB1) in the first ALV list and sales areas ("Detail"; KNVV) for the selected customer (event double-click) in the second ALV list.
*& Report ZUS_SDN_TWO_ALV_GRIDS
REPORT zus_sdn_two_alv_grids.
DATA:
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_splitter TYPE REF TO cl_gui_splitter_container,
go_cell_top TYPE REF TO cl_gui_container,
go_cell_bottom TYPE REF TO cl_gui_container,
go_grid1 TYPE REF TO cl_gui_alv_grid,
go_grid2 TYPE REF TO cl_gui_alv_grid,
gs_layout TYPE lvc_s_layo.
DATA:
gt_knb1 TYPE STANDARD TABLE OF knb1,
gt_knvv TYPE STANDARD TABLE OF knvv.
"§1. Define and implement event handler method
" (Here: implemented as static methods of a local class)
* 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_knb1 TYPE knb1.
CHECK ( sender = go_grid1 ).
READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
CALL METHOD go_grid1->set_current_cell_via_id
EXPORTING
* IS_ROW_ID =
* IS_COLUMN_ID =
is_row_no = es_row_no.
* Triggers PAI of the dynpro with the specified ok-code
CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
SELECT * FROM knb1 INTO TABLE gt_knb1
WHERE bukrs = '1000'.
* 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 splitter container
CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
rows = 2
columns = 1
* NO_AUTODEF_PROGID_DYNNR =
* NAME =
EXCEPTIONS
cntl_error = 1
cntl_system_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.
* Get cell container
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = go_cell_top.
CALL METHOD go_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = go_cell_bottom.
* Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_cell_top
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.
"§2. Set event handler (after creating the ALV instance)
SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid1. " Or:
" SET HANDLER: lcl_eventhandler=>handle_double_click FOR all instances.
CREATE OBJECT go_grid2
EXPORTING
i_parent = go_cell_bottom
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.
* Display data
gs_layout-grid_title = 'Customers'.
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'KNB1'
is_layout = gs_layout
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.
gs_layout-grid_title = 'Customers Details (Sales Areas)'.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'KNVV'
is_layout = gs_layout
CHANGING
it_outtab = gt_knvv " empty !!!
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.
* NOTE: dynpro does not contain any elements
CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*PROCESS BEFORE OUTPUT.
* MODULE STATUS_0100.
*PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"
* SET TITLEBAR 'xxx'.
* Refresh display of detail ALV list
CALL METHOD go_grid2->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
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.
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.
* User has pushed button "Display Details"
WHEN 'DETAIL'.
PERFORM entry_show_details.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form ENTRY_SHOW_DETAILS
* text
* --> p1 text
* <-- p2 text
FORM entry_show_details .
* define local data
DATA:
ld_row TYPE i,
ls_knb1 TYPE knb1.
CALL METHOD go_grid1->get_current_cell
IMPORTING
e_row = ld_row.
READ TABLE gt_knb1 INTO ls_knb1 INDEX ld_row.
CHECK ( syst-subrc = 0 ).
SELECT * FROM knvv INTO TABLE gt_knvv
WHERE kunnr = ls_knb1-kunnr.
ENDFORM. " ENTRY_SHOW_DETAILS
Regards
Uwe -
Enhance standard class with event handler method
In trying to enhance a standard class with a new event handler class, I find that the ECC 6.0 EHP4 system does not appear to recognise the fact the method is an event handler method. The specific example is a new method to handle the event CL_GUI_ALV_GRID->USER_COMMAND.
I notice that the flag called Active has not been ticked - see image below. Perhaps this is the reason why the event handler is not being triggered.
Note that there is an event handler for the same event in the standard class which obviously is executed as expected. Any ideas on limitations in the system or I am missing a step?
Thanks
JohnThank you for your replies.
There is a bug in the ALV handler of a standard SAP class (when executed in ITS WebGUI) and I was hoping to create a custom event handler as an Enhancement to execute some custom code to sort of "handle the bug".
I agree - ideally it should be done in a Z class but that will not give me access to the object methods and attributes of the enhanced class.
Cheers,
John -
Event handling in alv oops With buttons
Hi Experts
I have some doubt in ALV OOPS using Events. Could any one please tell me the procedure to how to handle events in oops ( Like interactive reports using events ).
Thank you
Satyendra.Hello Satyendra
The following sample report shows you how to handle the event HOTSPOT_CLICK and BUTTON_CLICK.
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 '2000' OBLIGATORY.
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, " grid instance that raised the event
handle_button_click FOR EVENT button_click OF cl_gui_alv_grid
IMPORTING
es_col_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
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 ).
CASE e_column_id-fieldname.
WHEN 'KUNNR'.
SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
WHEN 'ERNAM'.*
SET PARAMETER ID 'USR' FIELD ls_knb1-ernam.
CALL TRANSACTION 'SU01' AND SKIP FIRST SCREEN.
WHEN OTHERS.
ENDCASE.
* 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
METHOD handle_button_click.
* define local data
DATA:
ls_knb1 TYPE knb1.
READ TABLE gt_knb1 INTO ls_knb1 INDEX es_row_no-row_id.
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.
ENDMETHOD. "handle_button_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,
lcl_eventhandler=>handle_button_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.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
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 .
* 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.
LOOP AT gt_fcat INTO ls_fcat
WHERE ( fieldname = 'KUNNR' OR
fieldname = 'ERNAM' OR
fieldname = 'BUKRS' ).
IF ( ls_fcat-fieldname = 'BUKRS' ).
ls_fcat-style = cl_gui_alv_grid=>mc_style_button. " column appears as button
ELSE.
ls_fcat-hotspot = abap_true.
ENDIF.
MODIFY gt_fcat FROM ls_fcat.
ENDLOOP.
ENDFORM. " BUILD_FIELDCATALOG_KNB1
Regards
Uwe -
hi experts,
event double click.
when double click on vbeln it should go to va03 transaction . how would i do that in oops alv.hai,
you can go through code below .
*& Report Z_CLARIFY *
REPORT Z_CLARIFY .
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: L_VALID TYPE C,
V_FLAG,
V_DATA_CHANGE,
V_ROW TYPE LVC_S_ROW,
V_COLUMN TYPE LVC_S_COL,
V_ROW_NUM TYPE LVC_S_ROID.
DATA: IT_ROW_NO TYPE LVC_T_ROID,
X_ROW_NO TYPE LVC_S_ROID.
DATA:BEGIN OF ITAB OCCURS 0,
VBELN LIKE LIKP-VBELN,
POSNR LIKE LIPS-POSNR,
CELLCOLOR TYPE LVC_T_SCOL, "required for color
DROP(10),
END OF ITAB.
*The Below Definitions Must.....
DATA:
Reference to document
DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT,
Reference to split container
DG_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
Reference to grid container
DG_PARENT_GRID TYPE REF TO CL_GUI_CONTAINER,
Reference to html container
DG_HTML_CNTRL TYPE REF TO CL_GUI_HTML_VIEWER,
Reference to html container
DG_PARENT_HTML TYPE REF TO CL_GUI_CONTAINER.
"up to here
CLASS lcl_event_handler DEFINITION
CLASS LCL_EVENT_HANDLER DEFINITION .
PUBLIC SECTION .
METHODS:
**Hot spot Handler
HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
**Double Click Handler
HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN ES_ROW_NO,
TOP_OF_PAGE FOR EVENT TOP_OF_PAGE "event handler
OF CL_GUI_ALV_GRID
IMPORTING E_DYNDOC_ID.
END_OF_LIST FOR EVENT end_of_list "event handler
OF CL_GUI_ALV_GRID
IMPORTING E_DYNDOC_ID.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
*Handle Hotspot Click
METHOD HANDLE_HOTSPOT_CLICK .
CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
V_ROW = E_ROW_ID.
V_COLUMN = E_COLUMN_ID.
V_ROW_NUM = ES_ROW_NO.
MESSAGE I000 WITH V_ROW 'clicked'.
CLEAR IT_ROW_NO[].
X_ROW_NO-ROW_ID = V_ROW.
APPEND X_ROW_NO TO IT_ROW_NO .
CALL METHOD G_GRID->SET_SELECTED_ROWS
EXPORTING
IT_ROW_NO = IT_ROW_NO.
ENDMETHOD. "lcl_event_handler
*Handle Double Click
METHOD HANDLE_DOUBLE_CLICK.
CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
V_ROW = E_ROW.
V_COLUMN = E_COLUMN.
V_ROW_NUM = ES_ROW_NO.
IF E_COLUMN = 'VBELN'.
SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
ENDIF.
IF E_COLUMN = 'POSNR'.
SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN."
ENDIF.
ENDMETHOD. "handle_double_click
METHOD END_OF_LIST. "implementation
Top-of-page event
PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
ENDMETHOD. "top_of_page
METHOD TOP_OF_PAGE. "implementation
Top-of-page event
PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
ENDMETHOD. "top_of_page
ENDCLASS. "LCL_EVENT_HANDLER IMPLEMENTATION
*& Global Definitions
DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
"Container1
G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler
DATA: OK_CODE LIKE SY-UCOMM,
SAVE_OK LIKE SY-UCOMM,
G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
GS_LAYOUT TYPE LVC_S_LAYO.
data: v_lines type i.
data: v_line(3) type c.
*- Fieldcatalog for First and second Report
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
X_FIELDCAT TYPE LVC_S_FCAT,
LS_VARI TYPE DISVARIANT.
START-OF_SELECTION
START-OF-SELECTION.
SELECT VBELN
POSNR
FROM LIPS
UP TO 20 ROWS
INTO CORRESPONDING FIELDS OF TABLE ITAB.
describe table itab lines v_lines.
END-OF-SELECTION.
IF NOT ITAB[] IS INITIAL.
CALL SCREEN 100.
ELSE.
MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
ENDIF.
*& Form CREATE_AND_INIT_ALV
text
FORM CREATE_AND_INIT_ALV .
DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
"attention.....from here
"split your container here...into two parts
"create the container
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING CONTAINER_NAME = 'SCR100_CUST'.
"this is for top of page
Create TOP-Document
CREATE OBJECT DG_DYNDOC_ID
EXPORTING STYLE = 'ALV_GRID'.
Create Splitter for custom_container
CREATE OBJECT DG_SPLITTER
EXPORTING PARENT = G_CUSTOM_CONTAINER
ROWS = 2
COLUMNS = 1.
Split the custom_container to two containers and move the reference
to receiving containers g_parent_html and g_parent_grid
"i am allocating the space for grid and top of page
CALL METHOD DG_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = DG_PARENT_HTML.
CALL METHOD DG_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = DG_PARENT_GRID.
CALL METHOD DG_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = DG_PARENT_HTML.
CALL METHOD DG_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = DG_PARENT_GRID.
"you can set the height of it
Set height for g_parent_html
CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT
EXPORTING
ID = 1
HEIGHT = 5.
"from here as usual..you need to specify parent as splitter part
"which we alloted for grid
CREATE OBJECT G_GRID
EXPORTING I_PARENT = DG_PARENT_GRID.
Set a titlebar for the grid control
CLEAR GS_LAYOUT.
GS_LAYOUT-GRID_TITLE = TEXT-003.
GS_LAYOUT-ZEBRA = SPACE.
GS_LAYOUT-CWIDTH_OPT = 'X'.
GS_LAYOUT-NO_ROWMARK = 'X'.
GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
CALL METHOD G_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
CREATE OBJECT G_HANDLER.
SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
SET HANDLER G_HANDLER->END_OF_LIST FOR G_GRID.
SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.
DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color
DATA: L_INDEX TYPE SY-TABIX.
"Here i am changing the color of line 1,5,10...
"so you can change the color of font conditionally
LOOP AT ITAB.
L_INDEX = SY-TABIX.
IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.
LS_CELLCOLOR-FNAME = 'VBELN'.
LS_CELLCOLOR-COLOR-COL = '6'.
LS_CELLCOLOR-COLOR-INT = '0'.
LS_CELLCOLOR-COLOR-INV = '1'.
APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
LS_CELLCOLOR-FNAME = 'POSNR'.
LS_CELLCOLOR-COLOR-COL = '6'.
LS_CELLCOLOR-COLOR-INT = '0'.
LS_CELLCOLOR-COLOR-INV = '1'.
APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
ENDIF.
ENDLOOP.
setting focus for created grid control
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING
CONTROL = G_GRID.
Build fieldcat and set editable for date and reason code
edit enabled. Assign a handle for the dropdown listbox.
PERFORM BUILD_FIELDCAT.
PERFORM SET_DRDN_TABLE.
Optionally restrict generic functions to 'change only'.
(The user shall not be able to add new lines).
PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
**Vaiant to save the layout
LS_VARI-REPORT = SY-REPID.
LS_VARI-HANDLE = SPACE.
LS_VARI-LOG_GROUP = SPACE.
LS_VARI-USERNAME = SPACE.
LS_VARI-VARIANT = SPACE.
LS_VARI-TEXT = SPACE.
LS_VARI-DEPENDVARS = SPACE.
**Calling the Method for ALV output
CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
IS_VARIANT = LS_VARI
IS_LAYOUT = GS_LAYOUT
I_SAVE = 'A'
CHANGING
IT_FIELDCATALOG = IT_FIELDCAT
IT_OUTTAB = ITAB[].
"do these..{
Initializing document
CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.
Processing events
CALL METHOD G_GRID->LIST_PROCESSING_EVENTS
EXPORTING
I_EVENT_NAME = 'TOP_OF_PAGE'
I_DYNDOC_ID = DG_DYNDOC_ID.
"end }
Set editable cells to ready for input initially
CALL METHOD G_GRID->SET_READY_FOR_INPUT
EXPORTING
I_READY_FOR_INPUT = 1.
ENDFORM. "CREATE_AND_INIT_ALV
*& Form EXCLUDE_TB_FUNCTIONS
text
-->PT_EXCLUDE text
FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
Only allow to change data not to create new entries (exclude
generic functions).
DATA LS_EXCLUDE TYPE UI_FUNC.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
APPEND LS_EXCLUDE TO PT_EXCLUDE.
ENDFORM. " EXCLUDE_TB_FUNCTIONS
*& Form build_fieldcat
Fieldcatalog
FORM BUILD_FIELDCAT .
DATA: L_POS TYPE I.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-TABNAME = 'IT_FINAL'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-NO_ZERO = 'X'.
X_FIELDCAT-OUTPUTLEN = '10'.
X_FIELDCAT-HOTSPOT = 'X'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Item'(025).
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-TABNAME = 'IT_FINAL'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_POS = L_POS + 1.
X_FIELDCAT-SCRTEXT_M = 'Drop'(025).
X_FIELDCAT-FIELDNAME = 'DROP'.
X_FIELDCAT-TABNAME = 'IT_FINAL'.
X_FIELDCAT-COL_POS = L_POS.
X_FIELDCAT-OUTPUTLEN = '5'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-DRDN_HNDL = '1'.
X_FIELDCAT-DRDN_ALIAS = 'X'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
ENDFORM. " build_fieldcat
*& Module STATUS_0100 OUTPUT
text
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAIN100'.
IF G_CUSTOM_CONTAINER IS INITIAL.
**Initializing the grid and calling the fm to Display the O/P
PERFORM CREATE_AND_INIT_ALV.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
text
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
there are many such examples
goto->se38->type bcalv* and press f4, u can see many examples.
Reward points if helpful.
Thanks and regards
Swetha Singh. -
Event Handling in labview with arrays as event data
Hey folks,
I have a Labview Application which uses a dll to read Ethernet data. The setup is such that, when the dll has fresh data it sends out an event to the Labview Application so that the fresh data can be displayed.
However i have only managed to get this event based mechanism to send out a single structure at a time. Hence if there are 10 fresh data values, i need to send out 10 events (each event structure contains the parameter name, parameter value, unit and time stamp). It would be more efficient to send out an array of structures in a sigle shot.
I have tried this but Labview keeps crashing saying that an error was encountered and Labview needs to close along with an access violation message. I did a lot of online searching and found some LV code for event handling but not come accross any implementation which uses arrays as evend data. Is this supoorted? And if so is there any example vi that can be shared so that i get some knowledge about this.
Many Thanks in adavance,
Abel.I also gave a try by using a variant as the event data type instead of the cluster which contains the array of floats. I converted the cluster into a variant and used that to create the user event reference. Followed the same logic while decoding the dats.
But still the crash.... Here is the windbg output...
ModLoad: 07580000 075b7000 C:\Program Files\National Instruments\LabVIEW 2012\resource\lvalarms.dll
ModLoad: 0ca90000 0cb72000 C:\Program Files\National Instruments\LabVIEW 2012\resource\mesa.dll
ModLoad: 0c7f0000 0c7f9000 C:\Program Files\National Instruments\LabVIEW 2012\resource\lvuste.dll
ModLoad: 35000000 3509b000 C:\Program Files\National Instruments\Shared\TDMS\tdms.dll
ModLoad: 0c860000 0c87c000 D:\SapphireViewer\dll\SapphireClientDll.dll
ModLoad: 0e240000 0e2c7000 C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86\MSVCP80.dll
ModLoad: 0e2d0000 0e36b000 C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.6195_x-ww_44262b86\MSVCR80.dll
(1cb0.1a34): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0e47f8b4 ebx=051f0040 ecx=051f0040 edx=061e5764 esi=22820840 edi=07b10040
eip=03c2050c esp=0e47f5cc ebp=0e47f810 iopl=0 nv up ei pl nz na po nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010202
*** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\Program Files\National Instruments\LabVIEW 2012\resource\tdcore_12_0.dll -
tdcore_12_0!LvVariant:etContents+0xac:
03c2050c 837e3100 cmp dword ptr [esi+31h],0 ds:0023:22820871=????????
I cannot really tell whats going on. Looking for some pointers.
Regards,
Abel.
Maybe you are looking for
-
How do I convert an e-mail into a Word file that can be edited and printed?
I received an e-mail from a relative that I want to convert into a Word file that can be edited and printed?
-
Lync 2010 client and SRV record
When Lync 2010 was originally set up in our environment, we included our login domain which is a .local as a SIP domain but everyone uses our additional SIP domain which is a .org. In our internal DNS, we have SRV records under both domains. Question
-
X4200 with Red Hat Linux - Network not coming up
I have a new X4200 with a fresh install of Red Hat. I have eth0 configured with static IP and iptables disabled. When I connect the Ethernet cable between server and switch, I get link LED and activity LED. However, I can ping anything on the local n
-
Hi All, Please let me know is it possible to update registers in case of stock transfer from one plant to another (same comp code) with one step or two step procedures. Here i am not creating any STO-PO and i would like to update RG23Part1 register a
-
No wave form showing in regions
I recently have the problem that when I record my guitar signal thru my audio interface (tc near or Guitar Rig 3) the wave form of the recording doesn't show in the region. When I open the sample editor I can see the waveform. As soon as i change the