Dynamically calling a certain class
Hey all,
So I have some animated charts I have done up. They live in
my library and are linked with the names; "chart1", "chart2",
"chart3." If I want to add one of them to the stage based on a
selection by a user, how can I create a dynamic name call to the
class to add them. Instead of hard coding them, I want to insert
the number into the function. For example.
function createNewChart(myChart){
var newChart = new (this["chart"+myChart])()
addChild(newChart);
Of course that doesn't work, so I am looking for the syntax
to make it work. Ideas?
- B
I knew it was out there. Thanks man.
Similar Messages
-
Dynamic Call to Java Class or Method
Hi All,
I have a requirement to call a Class or a Method Within the same class dynamically based on the user choice. I will give an example with how I do it in pl sql.
begin
if (choice = 1) then
execute immediate 'package.procedure1(params)';
elsif (choice = 2) then
execute immediate 'package.procedure2(params)';
else
execute immediate 'package.procedure3(params)';
end if;
end;
From the Example above, I call a program based on user choice. How Can I do the same in Java?
Thank you.
Edited by: Eric S. on Jul 6, 2011 9:52 AMI have a requirement to call a Class or a MethodYou can call a method, but not the Class where as you can instantiate the Class.
I will give an example with how I do it in pl sql.
begin
if (choice = 1) then
execute immediate 'package.procedure1(params)';
elsif (choice = 2) then
execute immediate 'package.procedure2(params)';
else
execute immediate 'package.procedure3(params)';
end if;
end;
From the Example above, I call a program based on user choice. How Can I do the same in Java?The similar way. Here it takes the following structure.
ClassA object = new ClassA();
if(choice==1) {
object.callMethod1();
} else if(choice==2) {
object.callMethod2();
} else if(choice==3) {
object.callMethod3();
} Also you can switch case instead of if else. It takes the following structure.
ClassA object = new ClassA();
switch(choice) {
case 1: object.callMethod1(); break;
case 2: object.callMethod2(); break;
case 3: object.callMethod3(); break;
}I recommend you to go with the second one which using switch. -
Does anyone know how I could either
a) Dynamically call a ruleset with a decision service or
b) Have one ruleset call another ruleset in the rules engine
I am trying to dynamically call a certain ruletset set from a single BPEL process, a user will have their request passed to 1 of 10 possible rulesets.
Any help would be appreciated!Hi,
Use both onClientClick to call the client event an use onClick to execute the server event.onClientClick is executed with first priority and then the onClink event is fired in the server.
e.g :
<hbj:button
id="Send_Button"
text="Send"
tooltip="Sends my name"
jsObjectNeeded="true" onClientClick="validate();"
onClick="onSendButtonClicked"
width="100"
design="EMPHASIZED">
First the validate javascript method executes then the onClick "onSendButtonClicked()" method in the controller executes.
If helps reward with points.
Regards
Ritu
Thanks -
PI 7.1 Access to Dynamic Configuration through Java Class
My Current scenario involves IDCO -> FILE communications in PI 7.1 using XSL where the file name is dynamic.
I have attempted calling a Java Class from XSL with the use SAPXMLTOOL kit option set in the adaptor and it works but I need to be able to call the transform method
public void transform(TransformationInput arg0, TransformationOutput arg1)
from XSL so I can access the message and update the File Name via Dynamic Configuration.
Whilst I can call a static class with in the object I can not call transform with the correct arguments (arg0, arg1). I need access to arg0 (payload) to set/figure out the filename. I can calculate the filename in XSL and pass it to the Java but in a static method it is useless as it need to access the arg0 which is a object and obviously non-static context.
Is this possible ? How do I get access to Dynamic Configuration from XSL through Java in 7.1 ?
I have successfully called a static method but that is no help.
Thanks in advance.Suraj,
Unfortunately you link isnt operational but thankyou anyway, I have managed to call as Java class as per my original post, but a static method does not allow me to get a handle to the Dynamic Configuration Variables in the message.
It seems importing the 7.0 LIBS may be an option and Im not entirely sure I have that option.
It certainly isnt possible to use the JDK5 XML implementation to even call a static method on an Java OBJ from XSL (obviously the USE SAPXMLTOOLKIT option is there for a reason).
I think and again I could be wrong but direct access via XSLT..
LINK:http://help.sap.com/saphelp_nwpi71/helpdata/EN/e2/e13fcd80fe47768df001a558ed10b6/frameset.htm
Is what Im looking for, I shall report back success or failure but the doco seems to fit the bill. Im not sure why I wanted to instatiate a sperate Java class when it can all exist in the XSLT. -
Dynamic loading of a class at runtime with known inheritance
Hi,
I am trying to dynamically load a class during runtime where I know that the class implements a particular interface 'AInterface'. Also, this class may be linked to other classes in the same package as that class, with their implementations/extensions given in their particular definitions.
The class is found by using a JFileChooser to select the class that implements 'AInterface', and loaded up.
Because the name of the class can be practically anything, my current approach only works for certain classes under the package 'Foo' with classname 'Bar'. Some names have been changed to keep it abstract.
private AInterface loadAInterface(URL url) throws Exception {
URL[] urls = { url };
// Create a new class loader with the directory
URLClassLoader cl = new URLClassLoader(urls);
// Load in the class
Class<?> cls = cl.loadClass("Foo.Bar");
return (AInterface) cls.newInstance();
}As you can see, all that is being returned is the interface of the class so that the interface methods can be accessed. My problem is that I don't know what the class or package is called, I just know that the class implements AInterface. Also note that with this approach, the class itself isn't selected in the JFileChooser, rather the folder containing Foo/Bar.class is.ejp wrote:
The class is found by using a JFileChooser to select the class that implements 'AInterface', and loaded up.
Also note that with this approach, the class itself isn't selected in the JFileChooser, rather the folder containing Foo/Bar.class is.These two statements are mutually contradictory...My apologies, I worded that wrong. My current approach (the one given in the code) selects the root package folder. However, what I want to be able to do, is to simply select a single class file. The current code just makes some assumptions so that I can at least see results in the program.
As you said, if the root of the package hierarchy is known, then this could be achieved. The problem is that the user either selects the package root or the AInterface class, but not both.
Is there a way to get package details from a .class file to be used in the actual loading of the class? -
Dynamic call of a static method of an static attribute
Hi all,
is it possible to call dynamically a static method of a static attribute of a class.
The statement without dynamic call would look like this:
cl_test_class=>static_attribute=>static_method( ).
I would like to do it like this:
('CL_TEST_CLASS')=>static_attribute=>static_method( ).
Netiher the one nor the other way works for me - I'm getting the error "The notation used is reserved for business object classes".
Regards, StefanI guess, it is not possible to call method using the short form (parameters in brackets) is not possible in Dynamic Access. You may need to get the attribute first and then call the method.
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
CLASS-DATA: o_same TYPE REF TO lcl_main.
METHODS: run.
ENDCLASS. "lcl_main DEFINITION
CLASS lcl_main IMPLEMENTATION.
METHOD run.
WRITE: 'success'.
ENDMETHOD. "run
ENDCLASS. "lcl_main IMPLEMENTATION
START-OF-SELECTION.
DATA: lo_same TYPE REF TO lcl_main.
CREATE OBJECT lcl_main=>o_same.
* lcl_main=>o_same=>run( ).
TRY.
FIELD-SYMBOLS: <fs> TYPE REF TO lcl_main.
ASSIGN ('LCL_MAIN')=>('O_SAME') TO <fs>.
CALL METHOD <fs>->('RUN').
CATCH cx_root.
ENDTRY.
Regards,
Naimesh Patel -
Message zclass not found in Programs (possibly dynamic calls!)
Hi Experts,
When we are running MIRO transaction, Zmessage error is triggering. when i double-click on error message it is showing
"Message ZFI 002(Class) not found in Programs (possibly dynamic calls!)"
Please provide your solutions to resolve the issue.
Regards,
Bharat
Moderator message: please do some research before asking.
Edited by: Thomas Zloch on Mar 15, 2011 9:21 AMDear Miciuli,
I found the definition for the circle in the canvas class and used it to creates circles ! Thank you for jaring my brain into thinking !
Stan
Ellipse2D.Double circle = new Ellipse2D.Double(xPos, 70, 30 , 30); -
Jsp session variable to call in java class.
here i am facing a problem in calling a jsp session varibale to java class.
in my code.. i have seperate files for jsp pages and packaged java classes.
as i am developing a web tire application. the data entered in the front end i am getting to jsp page and putting the mandatory in session to use in other pages. now here the same session vaiable i have to use/call in java class file.
Please refer me the best method and any references on this to call the session vaiable to java class file.
in jsp page i decleared like this:
session.setAttribute("stuIdentification",stuid);
this id i have to use in java class.file.
how to call it?
Thanks
KurraGimbal2's got the right idea.
The reasons for choosing point 1) are also valid. Whenever possible try and do as much code that is not specifically tied to your business objects inside your dynamic element (the jsp page) instead of your static one (the compiled class)
this allows you to very easily update your jsp to make any changes without having to recompile class code. Recompiling seems like a little thing when you are in development but imagine if the class is executed by a business critical application that faces forward to customers, recompiling will mean shutting down your servers and that may not be an option.
Regards,
David -
Dynamical Call of ALV - No data update
Hi,
I tried to use use the ALV dynamically. With dynamically I mean that I that I have diffrent data structures, depending what was selected by the user. The first call of the program is always correct. The data is displayed correctly. But when the data structure is changing, the ALV display is not updated. For a better understanding I post a extract of my coding:
<b>1. Creation of Container</b>
CREATE OBJECT g_custom_container
EXPORTING
container_name = 'PARENT_CONT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
ASSERT 1 = 2.
ENDIF.
<b>2.Creation of splitter container</b>
CREATE OBJECT splitter
EXPORTING
parent = g_custom_container
rows = 2
columns = 2
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
ASSERT 1 = 2.
ENDIF.
container_2 = splitter->get_container(
row = 1
column = 2 ).
<b>3.Dynamic Creation of alv object</b>
CREATE OBJECT go_grid
EXPORTING
i_parent = container_2.
<b>4. Get Fieldcatalogue</b>
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = lv_structure_name
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
ASSERT 1 = 2.
ENDIF.
<b>5. Set table for first display</b>
CALL METHOD go_grid->set_table_for_first_display
* EXPORTING
* i_structure_name = lv_structure_name
CHANGING
it_fieldcatalog = lt_fieldcat
it_outtab = <lt_out_data>.
CALL METHOD ls_alv_ref-alv_ref->refresh_table_display.
CALL METHOD cl_gui_cfw=>flush.
Perhaps someone could help.....
Best Regards, EdgarHello Edgar
The following sample report <b>ZUS_SDN_TWO_ALV_GRIDS_8</b> shows how to solve your problem. Please note that for the sake of simplicity I replaced the tree containing the structure names with an ALV list. However, the switch between the different structures is triggered by the <b>DOUBLE_CLICK</b> event.
I like to add that the integration of the first displayed ALV list (DD02L) into GT_OUTTAB is not really elegant. In addition, with <b>$TMP</b> I marked a problematic part of the coding with respect to your requirement to have the right layout for each displayed ALV list:
If you have a <b>fixed </b>assignment of <i>tabname -> 4-digit handle</i> then it is ok. I my sample report the layouts only work if you select the tabnames in the very same order.
Before showing the entire coding I describe crucial parts of the coding:
[code]TYPES: BEGIN OF ty_s_outtab.
TYPES: tabname TYPE tabname.
TYPES: layout TYPE lvc_s_layo.
TYPES: variant TYPE disvariant.
TYPES: fcat TYPE lvc_t_fcat.
TYPES: data TYPE REF TO data.
TYPES: END OF ty_s_outtab.[/code]
Every time a new structure is selected the corresponding ALV data are stored as new record in GT_OUTTAB which is of line type TY_S_OUTTAB.
[code] READ TABLE gt_outtab INTO gs_outtab INDEX 2.
ASSIGN gs_outtab-fcat TO <gt_fcat>.
ASSIGN gs_outtab-data->* TO <gt_outtab>.[/code]
Since the ALV list data and the fieldcatalog are fully dynamic I use global field-symbols for these data.
[code]&----
*& Module STATUS_0100 OUTPUT
text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'. " contains push button "DETAIL"
SET TITLEBAR 'xxx'.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = gs_outtab-tabname
is_layout = gs_outtab-layout
is_variant = gs_outtab-variant
i_save = 'A'
CHANGING
it_outtab = <gt_outtab>
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.
ENDMODULE. " STATUS_0100 OUTPUT[/code]
The second ALV list which displays the table records is always newly displayed in the PBO module.
In the event handler method <b>HANDLE_DOUBLE_CLICK</b> we need to do two things:
- store the current fieldcatalog back to GT_OUTTAB
- store the name of the new selected table/structure -> trigger PAI
In routine <b>HANDLE_DB_CLICK</b> we create a new entry for GT_OUTTAB if it does not yet exist. Next we select this entry and display it again as second ALV list.
[code]
*& Report ZUS_SDN_TWO_ALV_GRIDS_8
*& Description: Display two ALV lists in splitter container (left/right)
*& Left ALV list contains DB table names,
*& right ALV list displays entries of selected DB table
*& SDN thread: Dynamical Call of ALV - No data update
*& Link: https:||Dynamical Call of ALV - No data update
*& Screen '0100' contains no elements.
*& ok_code -> assigned to GD_OKCODE
*& Flow logic:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
REPORT zus_sdn_two_alv_grids_8.
TYPE-POOLS: abap.
DATA:
gd_repid TYPE syst-repid,
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_left TYPE REF TO cl_gui_container,
go_cell_right 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.
TYPES: BEGIN OF ty_s_outtab.
TYPES: tabname TYPE tabname.
TYPES: layout TYPE lvc_s_layo.
TYPES: variant TYPE disvariant.
TYPES: fcat TYPE lvc_t_fcat.
TYPES: data TYPE REF TO data.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gt_dd02l TYPE STANDARD TABLE OF dd02l,
gs_outtab TYPE ty_s_outtab,
gt_outtab TYPE ty_t_outtab.
FIELD-SYMBOLS:
<gt_fcat> TYPE lvc_t_fcat,
<gt_outtab> TYPE table.
CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
md_tabname_selected TYPE tabname READ-ONLY.
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_dd02l TYPE dd02l,
ls_outtab TYPE ty_s_outtab.
CHECK ( sender = go_grid1 ).
READ TABLE gt_dd02l INTO ls_dd02l INDEX e_row-index.
" Store data of currently displayed ALV list (except for DD02L)
IF ( md_tabname_selected = space ).
ELSE.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY tabname = md_tabname_selected. " old
CALL METHOD go_grid2->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = ls_outtab-fcat.
MODIFY gt_outtab FROM ls_outtab INDEX syst-tabix.
ENDIF.
md_tabname_selected = ls_dd02l-tabname. " new selected DB table
Triggers PAI of the dynpro with the specified ok-code
cl_gui_cfw=>set_new_ok_code( 'HANDLE_DB_CLICK' ). " not 4.6c
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'HANDLE_DB_CLICK'
IMPORTING
RC =
ENDMETHOD. "handle_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
gd_repid = syst-repid.
SELECT * FROM dd02l INTO TABLE gt_dd02l
WHERE tabname LIKE 'KN%1' OR
tabname LIKE 'LF%1' OR
tabname LIKE 'VB%' OR
tabname LIKE 'MAR%' OR
tabname LIKE 'E07%'
AND tabclass = 'TRANSP'. " transparent table
SORT gt_dd02l BY tabname.
PERFORM init_controls.
PERFORM add_first_table.
Set event handler
SET HANDLER:
lcl_eventhandler=>handle_double_click FOR go_grid1.
READ TABLE gt_outtab INTO gs_outtab INDEX 1.
Display data
CALL METHOD go_grid1->set_table_for_first_display
EXPORTING
i_structure_name = gs_outtab-tabname
is_layout = gs_outtab-layout
CHANGING
it_outtab = gt_dd02l
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.
READ TABLE gt_outtab INTO gs_outtab INDEX 2.
ASSIGN gs_outtab-fcat TO <gt_fcat>.
ASSIGN gs_outtab-data->* TO <gt_outtab>.
NOTE: method called in PBO module
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = gs_outtab-tabname
is_layout = gs_outtab-layout
is_variant = gs_outtab-variant
i_save = 'A'
CHANGING
it_outtab = <gt_outtab>
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 = gd_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'.
CALL METHOD go_grid2->set_table_for_first_display
EXPORTING
i_structure_name = gs_outtab-tabname
is_layout = gs_outtab-layout
is_variant = gs_outtab-variant
i_save = 'A'
CHANGING
it_outtab = <gt_outtab>
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.
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 'HANDLE_DB_CLICK'.
PERFORM handle_db_click.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form HANDLE_DB_CLICK
text
--> p1 text
<-- p2 text
FORM handle_db_click.
define local data
DATA:
ld_handle(4) TYPE n,
ls_outtab TYPE ty_s_outtab.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY tabname = lcl_eventhandler=>md_tabname_selected.
IF ( syst-subrc NE 0 ).
CLEAR: ls_outtab.
ls_outtab-tabname = lcl_eventhandler=>md_tabname_selected.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BUFFER_ACTIVE =
i_structure_name = ls_outtab-tabname
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = ls_outtab-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.
CREATE DATA ls_outtab-data TYPE TABLE OF (ls_outtab-tabname).
ASSIGN ls_outtab-data->* TO <gt_outtab>.
SELECT * FROM (ls_outtab-tabname) UP TO 50 ROWS
INTO TABLE <gt_outtab>.
ls_outtab-layout-no_toolbar = abap_false.
ls_outtab-layout-zebra = abap_true.
ls_outtab-layout-smalltitle = abap_true.
CONCATENATE ls_outtab-tabname ':'
INTO ls_outtab-layout-grid_title.
CONCATENATE ls_outtab-layout-grid_title 'Table Records'
INTO ls_outtab-layout-grid_title
SEPARATED BY space.
ls_outtab-variant-report = gd_repid.
DESCRIBE TABLE gt_outtab.
ld_handle = syst-tfill + 1.
WRITE ld_handle TO ls_outtab-variant-handle. " $TMP: Problem!!!
APPEND ls_outtab TO gt_outtab.
ENDIF.
" NOTE: read into GLOBAL variable gs_outtab !!!!
READ TABLE gt_outtab INTO gs_outtab
WITH KEY tabname = lcl_eventhandler=>md_tabname_selected.
ASSIGN gs_outtab-fcat TO <gt_fcat>.
ASSIGN gs_outtab-data->* TO <gt_outtab>.
ENDFORM. " HANDLE_DB_CLICK
*& Form INIT_CONTROLS
text
--> p1 text
<-- p2 text
FORM init_controls .
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.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999 " full-size screen
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.
ENDIF.
Create splitter container
CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
rows = 1
columns = 2
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_left.
CALL METHOD go_splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = go_cell_right.
CALL METHOD go_splitter->set_column_mode
EXPORTING
mode = cl_gui_splitter_container=>mode_relative
IMPORTING
RESULT =
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.
CALL METHOD go_splitter->set_column_width
EXPORTING
id = 1
width = 25
IMPORTING
RESULT =
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.
CALL METHOD go_splitter->set_column_sash
EXPORTING
id = 1
type = cl_gui_splitter_container=>type_movable
value = cl_gui_splitter_container=>false
IMPORTING
RESULT =
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.
Create ALV grids
CREATE OBJECT go_grid1
EXPORTING
i_parent = go_cell_left
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_cell_right
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.
ENDFORM. " INIT_CONTROLS
*& Form ADD_FIRST_TABLE
text
--> p1 text
<-- p2 text
FORM add_first_table .
define local data
DATA:
ls_outtab TYPE ty_s_outtab.
ls_outtab-tabname = 'DD02L'.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BUFFER_ACTIVE =
i_structure_name = ls_outtab-tabname
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = ls_outtab-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.
GET REFERENCE OF gt_dd02l INTO ls_outtab-data.
ls_outtab-layout-no_toolbar = abap_false.
ls_outtab-layout-zebra = abap_true.
ls_outtab-layout-smalltitle = abap_true.
CONCATENATE ls_outtab-tabname ':'
INTO ls_outtab-layout-grid_title.
CONCATENATE ls_outtab-layout-grid_title 'Table Records'
INTO ls_outtab-layout-grid_title
SEPARATED BY space.
ls_outtab-variant-report = gd_repid.
ls_outtab-variant-handle = '0002'.
INSERT ls_outtab INTO gt_outtab INDEX 1.
ls_outtab-layout-no_toolbar = abap_true.
ls_outtab-layout-zebra = abap_true.
ls_outtab-layout-smalltitle = abap_true.
ls_outtab-layout-grid_title = 'DB Tables'.
ls_outtab-variant-report = gd_repid.
ls_outtab-variant-handle = '0001'.
DELETE ls_outtab-fcat WHERE ( fieldname NE 'TABNAME' ).
INSERT ls_outtab INTO gt_outtab INDEX 1.
ENDFORM. " ADD_FIRST_TABLE[/code]
Regards,
Uwe -
If you have lots of objects created in a class, how can you easilly call a certain object based on the user's input?
All I can think of is an awfully long if-structure. For example:
private Creature xA = new Creature();
private Creature xB = new Creature();
private Creature xC = new Creature();
private Creature xD = new Creature();
private Creature xE = new Creature();
String what = this.textfield.getText();
if (what.equals("a"))
xA.doSomething();
if (what.equals("b"))
xB.doSomething();
if (what.equals("c"))
xC.doSomething();
...and so on...
Is there any shorter way to do this?You could maybe have an HashMap of Creature objects. Then pick the correct object out based on the letter received from getText(),
e.g. for a HashMap the key could be related to 'a', 'b', 'c', ...
// fill HashMap with entries xA, xB, ... and keys hashCode("a"), ...
// Then ...
if(map.containsKey(what.hashCode())) {
(map.get(what.hashCode())).doSomething();
} -
Using Reflectors To Dynamically Call Objects
Hi,
I have a Class that has two methods and each method takes two parameters (1st Method Takes Integers / 2nd Takes Double) and returns and Integer. I want to invoke these methods using Java.Reflectors so I could Do dynamic instantiations and method calling.
I have generated an experimental test harness class as given below....
*========================================================*
public static void main(String[] args) {
try {
// Getting a Class available in the Pachage to Class Instance
Class cls = Class.forName("testreflection.ClassMethods");
// Instance of Current Class
Main o_Obj = new Main();
// Get the declared methods in the Class instand "cls"
Method[] m_Methods = cls.getDeclaredMethods();
for(int i=0; i<m_Methods.length; i++){
// Obtain the parameter types of each method
Type[] typ_MethodParameterTypes = m_Methods.getGenericParameterTypes();
// Int array for Random Integer inputs as Parameters
int[] i_Prameter = new int[typ_MethodParameterTypes.length];
Random r_RandomInt = new Random();
for(int j=0; j<typ_MethodParameterTypes.length;j++){
// Just Display the Input Type
System.out.println(typ_MethodParameterTypes[j].toString());
i_Prameter[j]=r_RandomInt.nextInt();
//Display the Input value to the above type
System.out.println(i_Prameter[j]);
// Trying to invke the 1st Method in the Mehtod array
m_Methods[0].invoke(o_Obj, i_Prameter);
} catch (IllegalArgumentException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
//} catch (InstantiationException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
*==============================================================*
THen I am getting the following error.... Can any one help me...
int
-1680302169
int
-1149051431
Mar 30, 2011 11:02:53 AM testreflection.Main main
SEVERE: null
java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at testreflection.Main.main(Main.java:52)
Edited by: EJP on 30/03/2011 12:17: added the code tags. Please use them.
Edited by: JLearner on Mar 29, 2011 6:18 PM
Edited by: JLearner on Mar 29, 2011 6:20 PMEJP wrote:
java.lang.IllegalArgumentException: wrong number of argumentsSo you are calling the method with the wrong number of arguments.
The error messages are quite clear, in both cases.Here is the Method that I am Calling in the Class "ClassMethods"
public int getAddition(int i_Number1,int i_Number2){
int i_Total = i_Number1+i_Number2;
return i_Total;
}This method Takes two Integer values and returns an Integer.
I am calling this method using java reflections as below.
// Get the declared methods in the Class instand "cls"
Method[] m_Methods = cls.getDeclaredMethods();
for(int i=0; i<m_Methods.length; i++){
// Obtain the parameter types of each method
Type[] typ_MethodParameterTypes = m_Methods.getGenericParameterTypes();
// Int array for Random Integer inputs as Parameters
int[] i_Prameter = new int[typ_MethodParameterTypes.length];
Random r_RandomInt = new Random();
for(int j=0; j<typ_MethodParameterTypes.length;j++){
// Just Display the Input Type
System.out.println(typ_MethodParameterTypes[j].toString());
i_Prameter[j]=r_RandomInt.nextInt();
//Display the Input value to the above type
// Currently hold two parameter values
System.out.println(i_Prameter[j]);
// Trying to invke the 1st Method in the Mehtod array
Object obj = cls.newInstance();
m_Methods[0].setAccessible(true);
// invoking with instance of Method own class and parameters (two integer parameters in an array )
m_Methods[0].invoke(obj, i_Prameter); -
Java Core Program :: Dynamic Object Creation for Classe & Invoking the same
Hi,
I need to create a dynamic object for a class & invoke it.
For eg: I have a table in my DB where all the names of my java classes are stored. I need to call name from the table of the DB and call that class dynamically in my java program.
ResultSet_01 = executeQuery("select classname from class_table where class_descrip = 'Sales Invoice' ");
while(ResultSet_01.next())
String class_name = ResultSet_01.getDouble("classname");
}Now using the string in class_name that is fetched from ResultSet_01, I need to create an object for the class_name & invoke the class that is been created with the same name.
Thank in advance.
Regards,
Haider ImaniWell for a start since a class name is a String, not a number you'd better start by getting the name with getString() not getDouble().
You need to work with fully qualified names, (FQNs) like "com.acme.myproject.MyDynamicClass", not just the bare MyDynamicClass.
The next question is where the .class files for the dynamically loaded classes are stored. If they are part of your normal program code, on the class path, then you can use Class.forName to load the class and return a Class object. If they are in some special place you'll need to create a URLClassLoader and get the Class from that.
Generally, when you load a class this way, it should implement some known interface, or extend some know abstract class. By placing objects of the dynamic class in a reference to that interface you can use the methods defined in the interface.
The usual way of getting an instance of a dynamic class is to call newInstance() on the Class object. -
Hello,
I'm reasonably new to working with EJBs so perhaps this isnt possible... Can you dynamically call an EJB at runtime ie like reflection.
I know once the bean has been created I can use reflection to call the method but how can I create the bean from the beans remote home interface?
Many thanks
MichaelGot it
EJBMetaData md = theHome.getEJBMetaData();
Class homeClass = md.getHomeInterfaceClass();
EJBObject theRemote = (EJBObject)invoke(homeClass,theHome,"create");
static Object invoke(Class c,Object obj,String mname){
Method[] methods = c.getMethods();
String name=null;
Object r= null;
try {
for(int i = 0; i<methods.length ;i++) {
name = methods.getName();
if(name.startsWith(mname)) {
r = methods[i].invoke(obj,null);
} catch(Exception e){
e.printStackTrace();
return r; -
Hi Gurus,
Can any one tell me how to debug dynamic calls?
The scenario is:
I know the message that is getting fired from a message class.
I didnot find its usage from the where-used list, as it says - possible dynamic calls.
How do i know, from where this message is getting fired?
Pls suggest.
Thanks, RashmiHi,
Just try this
In the new debugger Breakpoints --> Breakpoint at --> Breakpoint at Statement
give MESSAGE
This will set break point at all message statement. Execute till you get the message
Regards -
Here's the problem. Dynamically called VI becomes broken inside an executable in debug executable mode Error 1003 is occuring from "Open VI Reference" Block. The computer has all of the necessary drivers, NI-VISA and NI-DAQmx. This executable is a new release of software that currently works on the PC in question. I can using NI-VISA Remote Server control the instruments from my PC using the executable. But when I put the executable on the PC I am getting this error. The only way I have been able to get this to work properly is to build the executable from the console I believe the project was created in, note that the project file has been moved to a network drive and it still works. All of the stations I have opened the project in show the VI that is being called is runnable. I've tried building the executable from the console I am deploying to and the same thing happens.
I am honestly at a loss for ideas why this is occuring. Is this something about the way LabView works internally that may be causing this problem?
I have trolled this forum for idea's and none have made sense to me.
Any input would be greatly appreciated.
-NateTwo ideas:
Mass compile the project to ensure all linkages are ironed out
Include the dynamically launched VI's into the "Always Included" section of the build spec
Report back on if either of these actions solves your problem.
a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"] {color: black;} a.lia-user-name-link[href="/t5/user/viewprofilepage/user-id/88938"]:after {content: '';} .jrd-sig {height: 80px; overflow: visible;} .jrd-sig-deploy {float:left; opacity:0.2;} .jrd-sig-img {float:right; opacity:0.2;} .jrd-sig-img:hover {opacity:0.8;} .jrd-sig-deploy:hover {opacity:0.8;}
Maybe you are looking for
-
Corrupted QT file - what went wrong?
I have a 10 bit Blackmagic MOV file, that all works on the Mac G-RAID array. It wascopiedto a PC external drive, and for some bizarre reason, QT Pro tells me it is not a valid video file. There were 5 copied at once (Not by me, so I have no idea what
-
Our Web Pages Do Not Render Correctly in Dreamweaver
Afternoon All We've been using Dreamweaver on our company website for several years now. We've recently redesigned the site, and Dreamweaver doesn't render our pages properly. We have a page background image, and a center designed site with a backgro
-
10.5.7 hosed up my display settings!!
i just applied the 10.5.7 update and now my display setting are messed up...I can't get it straightened out.... downloading full installer now.... anyone else having any issues?
-
Change connection string in MS Excel 2013 powerpivot
I need to update connection strings of multiple files in Bulk using c# . But , Its working for MS Excel 2010 and not for Excel 2013. Code snippet : Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); M
-
Project Wizard (JDeveloper )
Hi, help me, please. In JDeveloper Project Wizard creating entity from VIEW contenting GROUP BY - PW givs error: "Entity creation error, no primary key atributes and does not support ROWID!" Thank you Regards Nodari null