User defined methods as variable input

Hello everyone.
I'm reading through a teach yourself java programming guide and am a little confused about a couple things when it comes to variables and methods.
I was wondering if it is "legal" to use a method as a variable input. Ex:
variable = usermethod(num1, 23.43, 32.13); /* Assuming the variable and method parameters
are of the same data type */
I was also wondering if you can call a method as output to the stand output such as:
System.out.println(usermethod(num1, 23.43, 32.13));
I think that these are vaild uses but this book is not very clear on this point, it simply says that a user defined method is called from the method main and if it is a return type it will return a value. I assume that the returned value can be store in a variable using the syntax above, am I correct?

Whenever the compiler sees a method name, it calls the method to get a return value from it. Both of those lines above are legal.
You can use a method call pretty much anywhere you would put an expression; for example, if you had a function foo() which took an int, and you had another function bar() which returned an int, you could call foo() like this:
foo(bar());Just make sure that methods you pass to other methods don't result in any unintended side-effects, such as printing to the screen.

Similar Messages

  • Problem with user defined methods

    Hello,
    I have created a user-defined method using the constructer and a number of sub-methods. The toString method is supposed to return the maximum, minimum, average, and median for an input data set. This program compiles with no problem, but doesn't seem to calculate the statistics. The max, min, med, and mean are all 0. Any help would be appreciated. Thanks a lot.
    import java.util.*;
    public class SO{
    private String id;
    private int N;
    private double[] data;
    private double average;
    private double minimum;
    private double maximum;
    private double med;
         public SO(){
         public void readData(){
              Scanner keyBoard = new Scanner(System.in);
              System.out.println("Enter the id: ");
              id = keyBoard.nextLine();
              System.out.println("Enter the amount of data values in the id: ");
              N = keyBoard.nextInt();
              data = new double[N];
              System.out.println("Enter the values one line at a time: ");
              int j = 0;
              for(int h=0; h<=N-1; h++){
                   data[h] = keyBoard.nextDouble();
              Arrays.sort(data);
         public void setDataValue(int k, double v){
              data[k] = v;
              System.out.printf("Changing data[%d] to %f", k, v);     
         public double getDataValue(int k){
              double get = data[k];
              return get;
         private double mean(){
              double sum = 0;
              for(int k = 0; k<=N-1; k++){
                   sum = sum + data[k];
              average = sum/N;
              return average;
         private double min(){
              minimum = data[0];
              return minimum;
         private double max(){
              maximum = data[N-1];
              return maximum;
         private double median(){
              if(N%2 != 0){
                   med = data[N/2];
              else if(N%2 == 0){
                   med = (data[N/2] + data[N/2-1])/2.;
              return med;
         public void displayData(){
              System.out.printf("[");
              for(int k = 0; k<=N-1; k++){
                   System.out.printf("%.2f", data[k]);
                   if(k != N-1){
                        System.out.printf(", ");
              System.out.printf("]");
         public void sortData(){
              Arrays.sort(data);
              System.out.printf("[");
              for(int k = 0; k<=N-1; k++){
                   System.out.printf("%.2f", data[k]);
                   if(k != N-1){
                        System.out.printf(", ");
              System.out.printf("]");
         public void analyzeData(){
              System.out.println(this);     
         public String toString(){
              return id +"\n" + "minimum = " + minimum + "\n" + "maximum = " + maximum + "\n" + "median = " + med + "\n" + "mean = " + average;
         public static void main(String[] args){
              SO v = new SO();
              System.out.println("Read Data");
              v.readData();
              System.out.println("Display Data");
              v.displayData();
              System.out.println("Analyze Data");
              v.analyzeData();
              System.out.println("Set Data\n");
              v.setDataValue(0,98.75);
              v.displayData();
              System.out.println("Sort Data");
              v.sortData();
              System.out.println("Access Data\n");
              System.out.println("data[0] = " + v.getDataValue(0));
              System.out.println("\nDisplay v");
              System.out.println(v);
    }

    Sorry
    import java.util.*;
    public class SO{
       private String id;      
       private int N;          
       private double[] data;
       private double average;
       private double minimum;
       private double maximum;
       private double med;
         public SO(){
            public void readData(){
                 Scanner keyBoard = new Scanner(System.in);
              System.out.println("Enter the id: ");
              id = keyBoard.nextLine();
              System.out.println("Enter the amount of data values in the id: ");
              N = keyBoard.nextInt();
              data = new double[N];
              System.out.println("Enter the values one line at a time: ");
              int j = 0;
              for(int h=0; h<=N-1; h++){
                   data[h] = keyBoard.nextDouble();
              Arrays.sort(data);
            public void setDataValue(int k, double v){
                 data[k] = v;
              System.out.printf("Changing data[%d] to %f", k, v);     
            public double getDataValue(int k){
                 double get = data[k];
              return get;
            private double mean(){
                 double sum = 0;
              for(int k = 0; k<=N-1; k++){
                   sum = sum + data[k];
              average = sum/N;
              return average;
            private double min(){
                 minimum = data[0];
              return minimum;
            private double max(){
                 maximum = data[N-1];
              return maximum;
            private double median(){
                 if(N%2 != 0){
                   med = data[N/2];
              else if(N%2 == 0){
                   med = (data[N/2] + data[N/2-1])/2.;
              return med;
            public void displayData(){
                 System.out.printf("[");
              for(int k = 0; k<=N-1; k++){
                   System.out.printf("%.2f", data[k]);
                   if(k != N-1){
                        System.out.printf(", ");
              System.out.printf("]");
            public void sortData(){
                 Arrays.sort(data);
              System.out.printf("[");
              for(int k = 0; k<=N-1; k++){
                   System.out.printf("%.2f", data[k]);
                   if(k != N-1){
                        System.out.printf(", ");
              System.out.printf("]");
            public void analyzeData(){
                 System.out.println(this);       
            public String toString(){
                 return id +"\n" + "minimum = " + minimum + "\n" + "maximum = " + maximum + "\n" + "median = " + med + "\n" + "mean = " + average;
         public static void main(String[] args){
              SO v = new SO();
              System.out.println("Read Data");
                     v.readData();
                     System.out.println("Display Data");
                     v.displayData();
                     System.out.println("Analyze Data");
                     v.analyzeData();
                     System.out.println("Set Data\n");
                     v.setDataValue(0,98.75);
                     v.displayData();
                     System.out.println("Sort Data");
                     v.sortData();
                     System.out.println("Access Data\n");
                     System.out.println("data[0] = " + v.getDataValue(0));
                     System.out.println("\nDisplay v");
                     System.out.println(v);
    }

  • Cannot logon user defined in header variable!

    Dear Guru's
    I'm seeing this this error when I type the URL. "Cannot logon user defined in header variable!"
    I have stopped and sterted the portal.
    I could not find the authschemes.xml (if this is related)
    Thanks,
    EP6 SP2
    Naren

    Hi ,
    Please explain what exactly you want to do ..If you want to use  Header Variables for User Authentication  go through this links
    http://help.sap.com/saphelp_nw2004s/helpdata/en/68/5ddc40132a8531e10000000a1550b0/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/68/5ddc40132a8531e10000000a1550b0/frameset.htm
    Thanks n Regards
    Santosh
    Reward if helpful !!!

  • Call a user defined method in web dynpro from interactive forms

    Hi All,
    how to call a user defined method in web dynpro java, when a selecting value from drop down list which is in interactive forms by adobe
    thanks.
    Edited by: venkat99 on May 24, 2010 4:52 PM

    Well, you can use F4 help, of course, check here: http://help.sap.com/saphelp_nw70ehp1/helpdata/en/48/a1900622ec062be10000000a42189d/frameset.htm
    You need to select the value first and then use the submit button, which is mapped to the WD action submit (you have to set this up in WD designer!!). To use the submit button for more actions, you need to use something like a hidden field, where the value is set according to the action you want to do with your submit button. The submit sends this value back to WD, where you can switch the program code according to the value.
    Otto
    p.s.: and maybe this blog can help: /people/shruti.rathour/blog/2008/02/07/uploading-sap-interactive-form-on-the-abap-webdynpro-view

  • SRM User defined fields -- can not input values

    Hi,
    We are using SRM 4.0. I have created a user defined field at the PO header according to note 672960. But I can not input anything to this field.
    This is what I did:
    1. in both structures INCL_EEW_PD_HEADER_CSF and INCL_EEW_PD_HEADER_CSF_PO add the append structure with the new field ZZCONTRACT.
    2. in BADI BBP_CUF_BADI_2 created an implementation Z_BBP_CUF_BADI_2. In method MODIFY_SCREEN set: xdisplay = 'X' and xinput = 'X' for this new field.
    This new field showed up in SRM, but it is greyed out. I can not type in anything. Could anyone tell me what I did wrong or what I have missing? Thanks a lot!

    hi,
      If you can see the custom fields,the problem is with the BADi implementation.You can write something like this in the method for the PO cust fields:
    IF iv_doc_type = 'BUS2201'.
      *Hide all customer fields
    *Will change this coding if any other document type needs
    *customer fields
          LOOP AT et_fields INTO wa_et_fields.
            wa_et_fields-xdisplay = 'X'.
            MODIFY et_fields FROM wa_et_fields.
          ENDLOOP.
         ENDIF.
    Save and activate the implementation.
    HTH.
    BR,
    Disha.
    Pls reward points for useful answers.

  • How to execute function takes user defined type parameters as input &output

    Hi All,
    I want to execute a function which takes user defined type as input & output parameters. But i don't know how to execute that function in pl/sql statements.
    CREATE TYPE T_INPUT AS OBJECT
    USER          VARCHAR2(255),
    APPLICATION     VARCHAR2(255),
    REFERENCE          VARCHAR2(30)
    ) NOT FINAL;
    CREATE TYPE T_ID UNDER T_INPUT
    E_ID                    VARCHAR2 (50),
    CODE                    VARCHAR2 (3),
    SERVICE                    VARCHAR2 (10),
    C_TYPE                    VARCHAR2 (1)
    ) NOT FINAL;
    CREATE TYPE T_OUTPUT AS OBJECT
         R_STATUS               NUMBER(10),
         E_DESC_LANG_1          VARCHAR2(1000),
         E_DESC_LANG_2          VARCHAR2(1000),
         A_REFERENCE          VARCHAR2(30)
    ) NOT FINAL;
    CREATE TYPE T_INFO UNDER T_OUTPUT
    E_INFO XMLTYPE
    CREATE FUNCTION Get_Dtls
    I_DETAILS IN T_ID,
    O_DETAILS OUT T_INFO
    RETURN NUMBER AS
    END;
    Here
    1. T_ID is an input parameter which is a combination of T_ID + T_INPUT,
    2. T_INFO is an output parameter which is a combination of T_INFO + T_OUTPUT.
    Here i'll assign the T_ID values.
    --- T_INPUT values
    USER          = "admin";
    APPLICATION     = "test";
    REFERENCE     = "null";
    ---- T_ID values
    E_ID               = "1234";
    CODE               = "TTT";
    SERVICE               = "NEW";
    C_TYPE = "P";
    Now i want to execute Get_Dtls function with T_ID,T_INFO parameters in pl/sql statements.
    I want to catch the E_INFO value from T_INFO type.
    How can i Do this ?
    Pls Help. Thanxs in advance.
    Anil.

    I am very new to this. New to Oracle, PL/SQL, OO programming or testing?
    set serveroutput on
    declare
      tst_obj ctype;
    begin
      tst_obj := pkg.proc(11);
      dbms_output.put_line('id='||tst_obj.id||'::code='||tst_obj.code||'::usage='||tst_obj.usage);
    end;
    /Generally I disapprove of the use of DBMS_OUTPUT (for just about anything) but it is sufficient to demonstrate the basic principle.
    Really you should start using proper testing practices, ideally with an automated test harness like QUTE.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • User defined method

    Heres the score, I have created this game but I need to create a new method (which I have never done before and need some guidance) When you play the game after each shot the programme should tell you if you are hot or cold, but this is not doing it after each shot, plus at the end of the game the programme should tell the user how good they were at the game. Anyway that bit works but i need to create a method for the "how close" part of the window. Any help would be great.
    import javax.swing.JOptionPane;
    public class CourseworkPart1{
         public static void main(String args[]) {
              int randomNum, usersGuess = 0, diffNum, numGoes = 0;
              String output= "";
              String output2 = "";
              //generate a random between 1 and 10 inclusive
              randomNum = (int) (Math.random()*10) +1;
              //Allows the user to guess three times
           for (int numAttempts = 1; numAttempts <=10; numAttempts++){
              //users guess
              usersGuess = Integer.parseInt(JOptionPane.showInputDialog("please enter a number"+ randomNum));
              //difference between random number and users guess
            diffNum = (usersGuess - randomNum);
            //users guess compared to the generated random number
              if (randomNum == usersGuess){
                   output = "You won";
                   numGoes = numGoes ++;
            //call method
                   //else {
                   //     output = "The Random number was " + randomNum ;
                   //How close is the players guess
                switch (diffNum){
                    case 1:
                        output = "hot";
                        break;
                    case -1:
                       output = "hot";
                        break;
                 case 2:
                       output = "warm";
                    break;
                 case -2:
                       output = "warm";
                    break;
                 default:
                        output = "cold";
                        break;
               //Players ratings
               switch(numGoes){
                      case 1:
                           output = "champion";
                           break;
                      case 2:
                       output = "professional";
                       break;
                      case 3:
                       output = "advanced";
                       break;
                      default:
                       output = "amateur";
                       break;
              //print message
              JOptionPane.showMessageDialog(null, output, "Player's Guess",
                                                      JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
    //User defined method

    public class AATest1
         public static void displayEvaluation(String rating)
              System.out.println("You were: " + rating);
         public static void main(String[] args)
              String str = "hot";
              displayEvaluation(str);
    }

  • User Defined methods

    Hi,
    I have a query as to where are the user defined methos in jsp/servlets are stored after compilation.
    and in a given jsp page 1.jsp when i include 2 files (2.jsp and 3.jsp). so when the 1.jsp gets loaded then in all how much total .class files get created?
    Thanks

    Sounds like homework question. At least I don't stop you from looking in the class folder yourself.

  • Fill user defined fields via batch input

    Hello All,
    In CJ01 I have added certain new fields using the enhancements CNEX0006 and CNEX0007.
    Now I need to do a conversion to upload project system data to SAP, I am using BDC for that. The following is the piece of code.
          PERFORM bdc_dynpro   USING  'SAPLCJWB' '0100'.
          PERFORM bdc_field       USING  'BDC_CURSOR' '*PROJ-PSPID'.
          PERFORM bdc_field       USING  'BDC_OKCODE' '=MDTB'.
          PERFORM bdc_field       USING  '*PROJ-PSPID' fs_proj_final1-proj_def.
          PERFORM bdc_field       USING  'RCWBS-PROFL' fs_proj_final1-profl.
          l_proj_profl   = fs_proj_final1-profl .
          PERFORM bdc_dynpro   USING  'SAPLCJWB' '0998'.
          PERFORM bdc_field       USING  'BDC_OKCODE' '/00'.
          PERFORM bdc_field       USING  'PROJ-POST1' fs_proj_final1-post1.
          PERFORM bdc_field       USING  'BDC_CURSOR' 'PROJ-PRCTR'.
          PERFORM bdc_field       USING  'PROJ-VERNR' fs_proj_final1-vernr.
          PERFORM bdc_field       USING  'PROJ-VBUKR' fs_proj_final1-vbukr.
          PERFORM bdc_field       USING  'PROJ-STORT' fs_proj_final1-stort.
          PERFORM bdc_field       USING  'PROJ-PRCTR' fs_proj_final1-prctr.
          PERFORM bdc_field       USING  'PROJ-PRCTR' fs_proj_final1-prctr.
          PERFORM bdc_field       USING  'PROJ-PLFAZ' w_strt_dt.
    New Fields
          PERFORM bdc_dynpro   USING  'SAPLCJWB' '0215'.
          PERFORM bdc_field       USING  'BDC_OKCODE' '/00'.
          PERFORM bdc_field       USING  'PROJ-ZZACC_EXEC' fs_proj_final1-                                                                               
    zacc_exec.
          PERFORM bdc_field       USING  'PROJ-ZZBUS_DIR'  fs_proj_final1-zzbus_dir.
          PERFORM bdc_field       USING  'PROJ-ZZOPS_DIR'  fs_proj_final1-
                                                                                    zzops_dir.
          PERFORM bdc_dynpro   USING  'SAPLCJWB'  '0998'.
          PERFORM bdc_field       USING  'BDC_OKCODE' '=LETB'.
    I am getting an error message -
    "Currency copied from company code,No batch input data for screen SAPLCJWB
      0998"
    How to avoid this error? Please suggest.
    Thanks
    Indrajit

    Hello All,
    In CJ01 I have added certain new fields using the enhancements CNEX0006 and CNEX0007.
    Now I need to do a conversion to upload project system data to SAP, I am using BDC for that. The following is the piece of code.
          PERFORM bdc_dynpro   USING  'SAPLCJWB' '0100'.
          PERFORM bdc_field       USING  'BDC_CURSOR' '*PROJ-PSPID'.
          PERFORM bdc_field       USING  'BDC_OKCODE' '=MDTB'.
          PERFORM bdc_field       USING  '*PROJ-PSPID' fs_proj_final1-proj_def.
          PERFORM bdc_field       USING  'RCWBS-PROFL' fs_proj_final1-profl.
          l_proj_profl   = fs_proj_final1-profl .
          PERFORM bdc_dynpro   USING  'SAPLCJWB' '0998'.
          PERFORM bdc_field       USING  'BDC_OKCODE' '/00'.
          PERFORM bdc_field       USING  'PROJ-POST1' fs_proj_final1-post1.
          PERFORM bdc_field       USING  'BDC_CURSOR' 'PROJ-PRCTR'.
          PERFORM bdc_field       USING  'PROJ-VERNR' fs_proj_final1-vernr.
          PERFORM bdc_field       USING  'PROJ-VBUKR' fs_proj_final1-vbukr.
          PERFORM bdc_field       USING  'PROJ-STORT' fs_proj_final1-stort.
          PERFORM bdc_field       USING  'PROJ-PRCTR' fs_proj_final1-prctr.
          PERFORM bdc_field       USING  'PROJ-PRCTR' fs_proj_final1-prctr.
          PERFORM bdc_field       USING  'PROJ-PLFAZ' w_strt_dt.
    New Fields
          PERFORM bdc_dynpro   USING  'SAPLCJWB' '0215'.
          PERFORM bdc_field       USING  'BDC_OKCODE' '/00'.
          PERFORM bdc_field       USING  'PROJ-ZZACC_EXEC' fs_proj_final1-                                                                               
    zacc_exec.
          PERFORM bdc_field       USING  'PROJ-ZZBUS_DIR'  fs_proj_final1-zzbus_dir.
          PERFORM bdc_field       USING  'PROJ-ZZOPS_DIR'  fs_proj_final1-
                                                                                    zzops_dir.
          PERFORM bdc_dynpro   USING  'SAPLCJWB'  '0998'.
          PERFORM bdc_field       USING  'BDC_OKCODE' '=LETB'.
    I am getting an error message -
    "Currency copied from company code,No batch input data for screen SAPLCJWB
      0998"
    How to avoid this error? Please suggest.
    Thanks
    Indrajit

  • View Object with User Defined Type input

    I am trying to use a View Object with a query that requires a user defined object as an input parameter.
    I have the query working with a PreparedStatement, but would like to use a View Object.
    When I use the PreparedStatement, I prepare the user defined type data like this:
    // get the data into an object array
    Object[] wSRecObjArr = wSRec.getObjectArray();
    // set up rec descriptor
    StructDescriptor WSRecDescriptor = StructDescriptor.createDescriptor("WS_REC",conn);
    // populate the record struct
    STRUCT wSRecStruct = new STRUCT(WSRecDescriptor,conn,wSRecObjArr);
    Then I can use this in the PreparedStatement like this:
    OraclePreparedStatement stat = null;
    ResultSet rs = null;
    stat = (OraclePreparedStatement)conn.prepareStatement("Select test_pkg.test_function(?) FROM DUAL");
    stat.setSTRUCT(1, wSRecStruct);
    rs = stat.executeQuery();
    I would like to do the same process with a View Object instead of the PreparedStatement.
    My question is "How do I create the input objects"?
    I obtain the View Object from the Application Module using findViewObject(). I don't actually have a connection object to pass into the StructDescriptor.createDescriptor method.
    I have tried just using Java Object Arrays (Object[]) to pass the data, but that gave an error:
    oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation.
    Any help or pointers are greatly appreciated.
    Thank you.
    Edited by: 942120 on May 1, 2013 8:45 AM
    Edited by: 942120 on May 1, 2013 8:46 AM
    Edited by: 942120 on May 1, 2013 9:05 AM
    Edited by: 942120 on May 1, 2013 9:06 AM

    Custom domains are the way to go.
    When I try to pass custom domains that represent my user defined types - it works.
    However, one of the functions requires a table of a user defined type be passed in.
    I tried creating a domain of the table type. It forces me to add a field during creation (in JDEV), so I tried adding a field of type Array of Element of the domain representing the user defined type.
    I populate the table by setting the field I created, but the table is empty in PL/SQL (TEST_TAB.COUNT = 0).
    I also tried passing the oracle.jbo.domain.Array object, but that produced an error:
    java.sql.SQLException: ORA-06553: PLS-306: wrong number or types of arguments in call
    I also tried passing Object[], but that produced an error:
    oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation.
    How do I properly create, and pass an domain that represents a table of a user defined type?
    When I use a OraclePreparedStatement, I can pass a oracle.sql.ARRAY using stat.setARRAY.
    Thank you for the help you have provided, and any future advice.
    JDEV 10.1.2.3
    JDBC 10.2.0.5
    Edited by: 942120 on May 13, 2013 7:13 AM
    Edited by: 942120 on May 13, 2013 7:16 AM

  • How to read a user defined java method inside a javascript

    I have a scenario where I have a form with 2 fields and a submit button. On clicking submit button, I call a javascript which needs to call a user-defined method.
    Please provide solution to do this and also please provide any useful links that i can go follow.
    Thanks

    Java != javascript.
    You can not call java directly from javascript.
    The lifecycle:
    Request received
    Java/JSP runs produces an HTML page
    Java stops running
    Javascript runs on page when page is loaded.
    The only way to call java code again is to submit a request and get the result back in a response. Traditionally the response is a new JSP page to replace the old one.
    Using AJAX the response can be just information that you then alter the current page with.
    The first example given by skp71 will probably NOT be what you are after. The java code is executed when you load the page, NOT when you push the button which is most probably what you are after.
    AJAX is a solution, as is loading a new page.
    Cheers,
    evnafets

  • 9144 with custom FPGA and SGL EtherCAT User-defined Variables?

    Hi,
    I currently have a small instrument driver (rs485) running on a 9144 chassis. The output values are communicated to the EtherCAT Master using FXP numbers. I would like to switch these FXP to SGL since I upgraded to LV 2012 SP1 with FPGA now supporting SGL numbers.
    Is this possible? I tried several times to create the SGL User-defined Variables in the project, but the date type is grayed out.
    Greetings from Munich,
    Götz
    Solved!
    Go to Solution.

    Unfortunately, SGL is not a supported data type for communication to/from a 9144. The available data types for user-defined I/O variables are:
    * Fixed Point
    * Signed Integers(Int8, Int16, Int32, Int64)
    * Unsigned Integers (UInt8, UInt16, UInt32, UInt64)
    * U32 Bit Field
    * Boolean
    More information regarding user-defined I/O variables can be found at:
    Programming EtherCAT I/O With FPGA Intelligence: Differences in the LabVIEW FPGA Programming API
    http://www.ni.com/white-paper/10618/en#toc4

  • Pass an array of a user defined class to a stored procedure in java

    Hi All,
    I am trying to pass an array of a user defined class as an input parameter to a stored procedure. So far i have done the following:
    Step 1: created an object type.
    CREATE TYPE department_type AS OBJECT (
    DNO NUMBER (10),
    NAME VARCHAR2 (50),
    LOCATION VARCHAR2 (50)
    Step 2: created a varray of the above type.
    CREATE TYPE dept_array1 AS TABLE OF department_type;
    Step 3:Created a package to insert the records.
    CREATE OR REPLACE PACKAGE objecttype
    AS
    PROCEDURE insert_object (d dept_array);
    END objecttype;
    CREATE OR REPLACE PACKAGE BODY objecttype
    AS
    PROCEDURE insert_object (d dept_array)
    AS
    BEGIN
    FOR i IN d.FIRST .. d.LAST
    LOOP
    INSERT INTO department
    VALUES (d (i).dno,d (i).name,d (i).location);
    END LOOP;
    END insert_object;
    END objecttype;
    Step 4:Created a java class to map the columns of the object type.
    public class Department
    private double DNO;
    private String Name;
    private String Loation;
    public void setDNO(double DNO)
    this.DNO = DNO;
    public double getDNO()
    return DNO;
    public void setName(String Name)
    this.Name = Name;
    public String getName()
    return Name;
    public void setLoation(String Loation)
    this.Loation = Loation;
    public String getLoation()
    return Loation;
    Step 5: created a method to call the stored procedure.
    public static void main(String arg[]){
    try{
    Department d1 = new Department();
    d1.setDNO(1); d1.setName("Accounts"); d1.setLoation("LHR");
    Department d2 = new Department();
    d2.setDNO(2); d2.setName("HR"); d2.setLoation("ISB");
    Department[] deptArray = {d1,d2};
    OracleCallableStatement callStatement = null;
    DBConnection dbConnection= DBConnection.getInstance();
    Connection cn = dbConnection.getDBConnection(false); //using a framework to get connections
    ArrayDescriptor arrayDept = ArrayDescriptor.createDescriptor("DEPT_ARRAY", cn);
    ARRAY deptArrayObject = new ARRAY(arrayDept, cn, deptArray); //I get an SQLException here
    callStatement = (OracleCallableStatement)cn.prepareCall("{call objecttype.insert_object(?)}");
    ((OracleCallableStatement)callStatement).setArray(1, deptArrayObject);
    callStatement.executeUpdate();
    cn.commit();
    catch(Exception e){ 
    System.out.println(e.toString());
    I get the following exception:
    java.sql.SQLException: Fail to convert to internal representation
    My question is can I pass an array to a stored procedure like this and if so please help me reslove the exception.
    Thank you in advance.

    OK I am back again and seems like talking to myself. Anyways i had a talk with one of the java developers in my team and he said that making an array of structs is not much use to them as they already have a java bean/VO class defined and they want to send an array of its objects to the database not structs so I made the following changes to their java class. (Again hoping some one will find this useful).
    Setp1: I implemented the SQLData interface on the department VO class.
    import java.sql.SQLData;
    import java.sql.SQLOutput;
    import java.sql.SQLInput;
    import java.sql.SQLException;
    public class Department implements SQLData
    private double DNO;
    private String Name;
    private String Location;
    public void setDNO(double DNO)
    this.DNO = DNO;
    public double getDNO()
    return DNO;
    public void setName(String Name)
    this.Name = Name;
    public String getName()
    return Name;
    public void setLocation(String Location)
    this.Location = Location;
    public String getLoation()
    return Location;
    public void readSQL(SQLInput stream, String typeName)throws SQLException
    public void writeSQL(SQLOutput stream)throws SQLException
    stream.writeDouble(this.DNO);
    stream.writeString(this.Name);
    stream.writeString(this.Location);
    public String getSQLTypeName() throws SQLException
    return "DOCCOMPLY.DEPARTMENT_TYPE";
    Step 2: I made the following changes to the main method.
    public static void main(String arg[]){
    try{
    Department d1 = new Department();
    d1.setDNO(1);
    d1.setName("CPM");
    d1.setLocation("LHR");
    Department d2 = new Department();
    d2.setDNO(2);
    d2.setName("Admin");
    d2.setLocation("ISB");
    Department[] deptArray = {d1,d2};
    OracleCallableStatement callStatement = null;
    DBConnection dbConnection= DBConnection.getInstance();
    Connection cn = dbConnection.getDBConnection(false);
    ArrayDescriptor arrayDept = ArrayDescriptor.createDescriptor("DEPT_ARRAY", cn);
    ARRAY deptArrayObject = new ARRAY(arrayDept, cn, deptArray);
    callStatement = (OracleCallableStatement)cn.prepareCall("{call objecttype.insert_array_object(?)}");
    ((OracleCallableStatement)callStatement).setArray(1, deptArrayObject);
    callStatement.executeUpdate();
    cn.commit();
    catch(Exception e){
    System.out.println(e.toString());
    and it started working no more SQLException. (The changes to the department class were done manfully but they tell me JPublisher would have been better).
    Regards,
    Shiraz

  • How to call User Define Function

    Hi,
    I need a help....
    In my Project I have Login.jspx page in which there is a textbox Username.
    I have second success.jspx page which has its success.java bean class in which i have define a method "display()".Now i want to cal display() in my success.jspx page.
    can anyone help me out what is the way to do this.
    Thanks in advance...
    Thanks,
    Nehal

    Hi Abhijit,
    Sure i can give you more details on the same:
    I have written a displayVal method in ForgotPassword.java bean class
    public String displayVal() {    
    String txtVal = AdfFacesContext.getCurrentInstance().getPageFlowScope().get("testValue").toString();
    nameID.setValue(txtVal);
    return txtVal;
    Now in ForgotPassword.jspx page i have one input text box named "nameID" in which i want to display some value from the user-define method called displayVal()
    now i am trying to call my user-define method in my ForgotPassword.jspx page:
    <af:inputText label="Name"
    binding="#{backingBeanScope.backing_FrgtPwd.nameID}"
    id="nameID"
    value="#{backingBeanScope.backing_FrgtPwd.displayVal}">
    </af:inputText>
    but is is showing an error that: backingBeanScope.backing_FrgtPwd.displayVal is not a property as this a method.
    So now my query is : Is there any way by which i can call my user-define method on the jspx page from the bean class of the same page.

  • Forward excel attachment  to  the  user-defined  mail id

    Hello  Everybody
    i  hv  collect all data into the ITAB and want to transfer that data to  excel format and send that  excel file as an attachment to  the   user-defined  mail id  .
    Input  on selection-screen 
    SELECTION-SCREEN : BEGIN OF BLOCK B1 .
    PARAMETERS  :  MAILID(255)  TYPE C .
    SELECTION-SCREEN : END OF BLOCK B1 .
    plz suggest me 
    ASAP

    Hi Sandeep,
    EMAIL as EXCEL ATTACJEMENTS
    Refer the following codes ..
    Hope this will help you..
    TYPE-POOLS: truxs.
    DATA t5 LIKE t005t OCCURS 0 WITH HEADER LINE.
    START-OF-SELECTION.
    SELECT * INTO TABLE t5
    FROM t005t
    WHERE spras = sy-langu.
    DATA wa_data TYPE truxs_t_text_data.
    CALL FUNCTION 'SAP_CONVERT_TO_TXT_FORMAT'
    EXPORTING
    i_line_header = 'X'
    TABLES
    i_tab_sap_data = t5
    CHANGING
    i_tab_converted_data = wa_data
    EXCEPTIONS
    conversion_failed = 1
    OTHERS = 2.
    DATA stmp(4096) TYPE c.
    DATA itmp TYPE i.
    LOOP AT wa_data INTO stmp.
    itmp = STRLEN( stmp ).
    stmp+itmp = cl_abap_char_utilities=>cr_lf.
    MODIFY wa_data FROM stmp.
    ENDLOOP.
    PERFORM send_email.
    *& Form send_email
    FORM send_email .
    DATA docs LIKE docs OCCURS 0 WITH HEADER LINE.
    DATA excelsize TYPE i.
    DATA excel LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    DATA doc LIKE sodocchgi1.
    DATA excelln TYPE i.
    DATA int_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
    DATA int_objhead LIKE solisti1 OCCURS 2 WITH HEADER LINE.
    DATA int_objtext LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    DATA int_reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
    DATA bodyln LIKE sy-tabix.
    DATA output_data TYPE ssfcrescl.
    excel[] = wa_data[].
    excel table sizes
    DESCRIBE TABLE excel LINES excelln.
    Body Email
    int_objtext-line = 'Test Body'.
    APPEND int_objtext.
    DESCRIBE TABLE int_objtext LINES bodyln.
    READ TABLE int_objtext INDEX bodyln.
    CLEAR doc.
    doc-doc_size = ( bodyln - 1 ) * 255 + STRLEN( int_objtext ).
    doc-obj_name = ' '.
    doc-sensitivty = 'P'.
    doc-proc_syst = sy-sysid.
    doc-proc_clint = sy-mandt.
    CLEAR: int_objpack, int_objpack[].
    int_objpack-transf_bin = ' '.
    int_objpack-head_start = 1.
    int_objpack-head_num = 0.
    int_objpack-body_start = 1.
    int_objpack-body_num = bodyln.
    int_objpack-doc_type = 'RAW'.
    int_objpack-obj_descr = 'Test'.
    APPEND int_objpack.
    CLEAR: int_objhead, int_objhead[].
    int_objhead = 'Attachment'.
    APPEND int_objhead.
    int_objpack-transf_bin = 'X'.
    int_objpack-head_start = 1.
    int_objpack-head_num = 0.
    int_objpack-body_start = 1.
    int_objpack-body_num = excelln.
    int_objpack-doc_size = excelsize.
    int_objpack-doc_type = 'XLS'.
    int_objpack-obj_name = 'excel'.
    int_objpack-obj_descr = 'test.xls'. "File name
    APPEND int_objpack.
    Set Receiver
    int_reclist-receiver = 'SAPUSER'.
    int_reclist-rec_type = 'B'.
    int_reclist-notif_del = 'X'.
    int_reclist-notif_read = 'X'.
    int_reclist-notif_ndel = 'X'.
    int_reclist-express = 'X'.
    APPEND int_reclist.
    doc-obj_descr = 'Report in Excel'.
    Sending Email
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = doc
    put_in_outbox = 'X'
    commit_work = 'X'
    TABLES
    packing_list = int_objpack
    object_header = int_objhead
    contents_bin = excel
    contents_txt = int_objtext "Body
    receivers = int_reclist
    EXCEPTIONS
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    OTHERS = 8.
    ENDFORM. " send_email
    Note:
    - If you are using FM SAP_CONVERT_TO_TXT_FORMAT you will not be able to execute this program in the background.
    - dont forget to change 'SAPUSER' to your SAP user ID
    - you can check the email by using tcode 'SBWP'.
    Reward points if this Helps.
    Manish

Maybe you are looking for

  • Receiving calls while in text screen

    I have a Curve, and if I am reading or writing a text in SMS the phone will not ring to notify me of a call, nor will it indicate "missed call."  If I am reading or composing an email, an incoming call interrrupts and I can choose either answer or ig

  • Error in Create Travel Request

    Good Morning. I am implementing Travel for ESS. But in the moment of give clic in the service for Create Travel Request the system display the following error: [Error Travel ESS|http://www.freeimagehosting.net/uploads/46ed778b99.jpg] What is cause of

  • Transfer itunes music from flash drive to new pc

    I have a new PC, HP Envy.   I had previously copied my Music, etc. onto ex-hard-drive from my old PC but do not know how to get this music onto my new PC.   I have an I-Pod which I attach to my computer on occasions to update it.  I have just downloa

  • Open saved draft report via API/UI

    How could I open an saved Draft report via API/UI. I have draft an report via API/UI and now I would show this report on Desktop/SAP

  • Mini won't start up

    our mini suddenly shut off by itself. There was no error message or anything unusual until it went black. Now it will not start up. There is no chime nor does the light come on. I have checked the powerbar that it is plug into and the powerbar is fin