Using a string to reference a variable

hi all,
i've encountered an interesting scenario where i need to use a string to reeference the value of a variable...the following would show the scenario in a simpler way...
let's say we have such function called foo:
void foo(String aString)
int a = 20;
int b = 20;
system.out.println(?????);
now let's say i run the function as:
foo("a")
and i want it to return:
20
what should be put to replace those "?????" in my function above?
please note that variables "a" and "b" are arbitary and so having a conditional statement like the following would NOT be useful:
void foo(String aString)
int a = 20;
int b = 20;
if (aString.equals("a"))
system.out.println(a);
if (aString.equals("b"))
system.out.println(b);
thank you very much!

There are two possibilities here.
The preferable one, if you have control over the names and nature of the variables, then don't use individual variables - use a Hashtable (or any implementation of Map). Your code would then look something like:void foo(String aString)
    Map table = new Hashtable();
    table.put("a", new Integer(20));
    table.put("b", new Integer(30));
    system.out.println(table.get(aString));
}The down side to this is that you have to use Integers - Maps can't take primitives.
If, on the other hand, you have to have variables, then take a look at using reflection. It's more complicated than using Maps, and less efficient, so I would recommend the first technique if possible.
RObin

Similar Messages

  • Using == with String object references

    Hi,
    I understand that using the == operator to compare two String object references in Java will yield false for two different object references even when the contents are the same, and that you are supposed to use the method .equals() instead. However, in my program the == operator actually works for two different object references that point to the same object since it yields true! I don't understand why it works in my program when it shouldn't. Does someone know why?
    Thanks!

    overrule. wrote:
    warnerja wrote:
    ... unless some sneaky thread jumps in and changes the a or b reference right before the expression (a == b) were evaluated. This would also assume a or b had greater scope than simply local method variables that only one thread could access.
    Just being a nitpickCould you provide an example of how that "greater scope" may look like in this case.
    * Greater scope.
    * @author Cynthia G.
    * @see http://forums.sun.com/thread.jspa?messageID=10520796
    public class ObjectAssignmentTest {
      static Object a; // outer scope: class variable
      static Object b; // outer scope: class variable
      public static void main(String[] args) throws InterruptedException {
        a = new Object();
        b = a;
        new Thread(new Runnable() {
          public void run() { ObjectAssignmentTest.b = new Object(); }
        }).start();
        System.out.println(a == b ? "equal" : "not equal");
    }For the record, this code is not even guaranteed to make the objects unequal with == before their equality is tested; both threads may go in parallel, the main thread first or the modifying thread first!
    s

  • How to reference the Instance name using Substitution string or SQL

    All:
    We have an Application that will be replicated in multiple Apex instances and would like to display the current Oracle Apex Instance name ( Similar to the &APP_USER. on the Welcome portion of the page ) .
    Is there a substitution string for this ?
    We plan on using a Show/Hide region on the splash page titled [About], that when clicked displays an HTML region with the subsitution strings.
    If no substitution strings, can someone help with an SQL that returns the Instance name ?
    Thanks for all the help.
    Aubrey Fernandes

    Aubrey Fernandes wrote:
    I currently have 3 URLs to get to my Development, QA and Production servers & will have many more production servers with different Application Ids.
    Development = http://canqa101:7777/pls/ngcrmd01/apex
    QA = http://canqa101:7777/pls/ngcrmq01/f?p=100:1
    Production = http://cancs105:7777/pls/ngcrmp01/f?p=100:1
    What I need are the portions before the final forward slash ( canqa101:7777/pls/ngcrmd01 ) which I assumed is the Oracle Apex instance.That information is determined by the web server configuration (e.g. the DADs when using OHS) rather than through APEX itself. There are no built-in substitution strings for this. Create an application item and an On New Instance (new session) computation to set the value using the function<tt>owa_util.get_cgi_env</tt> function to get the CGI environment variables <tt> HTTP_HOST</tt> and <tt>SCRIPT_NAME</tt>. You can then reference the value in the region using substitution string syntax.

  • Can substitution strings be used for table name references?

    Hi,
    I was wondering if it's possible to use substituion strings for table names in SQL queries. This would allow for me to edit all references to a table at one location. For instance, if a table name or dblink changed, I could edit the substitution string or application item to ensure all the queries reference the new table.
    For example:
    select * from &table1.
    table1 would be the substitution string for the actual table name
    I know this is possible if I used a pl/sql function returning a query, but I would much rather use a substition string in a SQL query.
    Thanks in advance.
    Brian

    i think not
    because how create the fields of * in this case
    in the other because all is dynamic, i think that you obtain only an error

  • Use a String to get data from a variable?

    Hi, I've got a major problem, I need to get data (int []) from a variable, using a String with the name of the variable..
    Does anyone know if this is possible?
    public class Commands {
        private static final int[] deploy_1 = {64,37,73,1};
        private static final int[] deploy_2 = {4,167,6,51};
        /** Creates a new instance of Commands */
        public Commands() {
        public int[] get(String name)
    // what code here?
    }I should be getting the data with
    int[] command = Commands.get("deploy_1");
    or something like that...
    Please help me!
    FYI, a hashtable is not a option!
    Many thanks, Vikko

    java.lang.NoSuchFieldException: deploy_1
    at java.lang.Class.getField(Class.java:1507)
    at dumb_commandstest.Commands.get(Commands.java:30)
    at dumb_commandstest.Main.getData(Main.java:36)
    at dumb_commandstest.Main.<init>(Main.java:21)
    at dumb_commandstest.Main.main(Main.java:28)
    Any ideas why I get a NoSuchFieldException?
    deploy_1 does exist.

  • Is it possible to use the value of a string to reference a component in the

    I'm fairly new to Java so this may be a stupid question!
    Is it possible to use the value of a string to reference a component in the code? For example in the code below, Wall is a class holding 3 different arrays. The Robot class has an array called finishBricks. When the buildWall method is run it receives the integers width and height which are used to construct the dimensions string. I want to use this string to then load the appropriate Wall array into the finishBricks array.
    I hope this makes sense! Any help would be greatly appreciated!
    class Robot {
    public double[][] finishBricks;
    public void buildWall(int width, int height) {
    Wall w = new Wall();
    String dimensions = "Wall" width "x" +height;
    this.finishBricks = w.xxxx; // where xxxx is replaced by whatever the String dimensions is
    class Wall {
         public double[][] Wall4x2 = {
              {-30.00,-01.60,27.45},
              {-30.00,-06.75,27.45},
              {-30.00,-13.55,27.45},
              {-30.00,-20.35,27.45},
              {-30.00,-22.00,28.65},
              {-30.00,-16.85,28.65},
              {-30.00,-10.05,28.65},
              {-30.00,-03.25,28.65}
         public double[][] Wall3x3 = {
              {-30.00,-01.60,27.45},
              {-30.00,-06.75,27.45},
              {-30.00,-13.55,27.45},
              {-30.00,-15.20,28.65},
              {-30.00,-10.05,28.65},
              {-30.00,-03.25,28.65},
              {-30.00,-01.60,29.85},
              {-30.00,-06.75,29.85},
              {-30.00,-13.55,29.85},
         public double[][] Wall2x4 = {
              {-30.00,-01.60,27.45},
              {-30.00,-06.75,27.45},
              {-30.00,-08.40,28.65},
              {-30.00,-03.25,28.65},
              {-30.00,-01.60,29.85},
              {-30.00,-06.75,29.85},
              {-30.00,-08.40,31.05},
              {-30.00,-03.25,31.05},

    Map walls = new HashMap ();
    walls.put ("2x2", new double[][] {
        new double[] {
            1,
            0
        new double[] {
            0,
            1
    double[][] wall = (double[][]) walls.get ("2x2");

  • Using a string variable to create an object

    Hi, I just have a quick question. It is probably very simple but I can not seem to find an asnwer anywhere.
    I have a class called Receive, from this class I derrive 12 difference other classes.
    I also have a hashtable with a bunch of Object objects. At run time I get one of these objects according to some hastable key. So once I have this object I need to cast it to the right type (one of the above mentioned 12).
    So I know I can find out which type this object is by doing this: object.getClass()
    This returns a Class object. I then need to somehow use this class object to perform the cast. I tried everything and it doesnt seem to work. Then I thought well I can get the string name of the class : object.getClass().getName()
    So I'm wandering if there is a way to use this string to cast my object. Or maybe there is another way.
    I did see the cast() method in the Class api but I can't figure out the point of it since is returns an Object class object and not my class's object.

    I took your advice and re factored the Receive class so it had all the functionality I needed except two methods which would then be overridden in the derived classes. What I had a hard time understanding is once an object of class say SpecialReceive extends Receive it can be referred to as Receive yet still maintain that it's a SpecialReceive.
    What I mean is if I give a Receive object to some method and this method has no idea that this object is actually SpecialReceive and it calls a method say run() which gets overridden by the SpecialReceive. I thought that since this method has no idea what type of Receive this object is it will execute Receive's run(). But it actually does know what type of class it is and it executes the right run() method (the one that SpecialReceive overrides).
    After I realized this there is no more need for casting.
    Thanks everyone for your contributions.

  • PLS-S-00487, Invalid reference to variable while compiling PRO*C program

    Hi,
    I am writing a PRO*C code and get an error in compilation.
    Code is as below:
    +#include <stdio.h>+
    +#include <string.h>+
    EXEC SQL INCLUDE sqlca.h;
    int main(int argc , char **argv)
    +{+
    int i;
    EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR connString[100];
    struct emp_record
    +{+
    char name[25];
    char dept[10];
    int id;
    int salary;
    int comm;
    int tot_sal;
    +}e1;+
    EXEC SQL END DECLARE SECTION;
    strcpy (connString.arr, "abcd/efgh@ijkl");
    connString.len = strlen ( connString.arr);
    +printf("\n Connection is [%d][%s]",connString.len,connString.arr);+
    +EXEC SQL CONNECT :connString;+
    +if(sqlca.sqlcode!=0)+
    +{+
    +printf("\nFailed to Connect, sqlcode is %d\n",sqlca.sqlcode);+
    +printf("\nOracle Message = %s", sqlca.sqlerrm.sqlerrmc);+
    +exit(-1);+
    +}+
    +else+
    +{+
    +printf("\nConnected\n");+
    +}+
    +EXEC SQL EXECUTE+
    +BEGIN+
    +emp_calc ( :e1.name,+
    +:e1.id,+
    +:e1.salary,+
    +:e1.tot_sal+
    +);+
    +END;+
    +END-EXEC;+
    +if(sqlca.sqlcode!=0)+
    +{+
    +printf("Oracle Error:[%d][%s]",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);+
    +}+
    +}+
    Procedure code is:
    +CREATE OR REPLACE PROCEDURE "EMP_CALC" (+
    +pi_empname in emp.ename%type,+
    +pi_empno in emp.empno%type,+
    +pi_sal in emp.sal%type,+
    +po_totsal out NUMBER)+
    +is+
    +begin+
    +po_totsal := 1.1 * pi_sal;+
    +dbms_output.put_line('Total Salary is:' || po_totsal);+
    +end;+
    *My main aim is to use elements of a structure in procedure call as parameters*
    *But when I compile I get error on such usage as follows:*
    Pro*C/C++: Release 11.2.0.3.0 - Production on Tue Apr 30 16:59:22 2013
    Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
    System default option values taken from: /mtsapp1/ora11g/product/11.2.0.3/dbhome_1/precomp/admin/pcscfg.cfg
    Error at line 52, column 20 in file singleStructOra.pc
    emp_calc ( :e1.name,
    ...................1
    PLS-S-00487, Invalid reference to variable 'E1'
    Error at line 52, column 1 in file singleStructOra.pc
    emp_calc ( :e1.name,
    1
    PLS-S-00000, Statement ignored
    Semantic error at line 50, column 1, file singleStructOra.pc:
    BEGIN
    1
    PCC-S-02346, PL/SQL found semantic errors
    *I would like to know how to resolve this compilation error and how do I use members of structures in such a procedure call.*
    Thanks....

    Sadly PL/SQL blocks do not understand structs (or arrays). DML statements do understand them.
    This is not very clearly stated in the manual, but it does say:
    http://docs.oracle.com/cd/E11882_01/appdev.112/e10825/pc_08arr.htm#autoId33
    Restrictions on Arrays of Structs
    The following restrictions apply to the use of arrays of structs in Pro*C/C++:
    Arrays of structs (just as with ordinary structs) are not permitted inside an embedded PL/SQL block.
    http://docs.oracle.com/cd/E11882_01/appdev.112/e10825/pc_07pls.htm#autoId13
    Do not use C pointer or array syntax in PL/SQL blocks. The PL/SQL compiler does not understand C host-variable expressions and is, therefore, unable to parse them.
    Although the example uses an array of structs, simple structs also fail. I have always had to copy the fields to and from simple variables when calling stored procedures.
    regards,
    David

  • How can I pass a String by reference in java?

    Hello!
    My question is how to pass a String by reference in java.
    I tried to declare my variable, instead of using "String xxx = "f";", I used "String xxx = new String ("f");" :
    public static void main (String []args)
    String xxx = new String("f");
    StatusEnum result2 = getErrorPointStr(xxx);
         public StatusEnum getErrorPointStr(String text)
              StatusEnum testStatus = StatusEnum.PASS;
              StringBuffer buffer = new StringBuffer();
    buffer.append("123");
              text = buffer.toString();
              return testStatus;
    After calling to getErrorPointStr(String text) function, xxx = "f"
    So it does not work.
    How can I solve this? It is very important, the function will receive String and not something else.
    Thanks!

    Tolls wrote:
    Which is why I said:
    Which is why you only managed to change what 'text' referred to in the methodExcept that's not why. Even if String was mutable, doing text = whatever; would have the same effect; it would change what that variable refers to in the method, but it would not change the object's state.
    I meant that, since there was no way to actually change the data (ie the char[] or whatever) within the object 'text' referred to, the OP was attempting to change what 'text' referred to and hoping it would be reflected outside the method...which we know won't happen as Java is pass-by-value.\Ah, now I see.
    These by-value/by-reference threads tend to get confusing, because usually the person is passing a String, so the immutability of String tends to get in the way and just muddy the waters.

  • IPhone: Database records that reference a variable

    Hello All,
    Firstly let me say that I am a total newbie to the iPhone and mac programming in general so please be gentle on me.
    An application I am working on pulls a bunch of dialogue text out of a database and I would like to have a person's name (whenever its used in the database records) reference a variable so i can change it easily everywhere its said.
    For instance consider the database record: "Hello there BOB, how are you doing?" (just one of many such statements involving bob). I'd like to easily change this (and all other dialogues) to: "Hello there JAMES, how are you doing?
    is there a way to put some special string in the database records so that they reference a global variable or some such? In keeping with the above; something like "Hello there @testName, how are you doing?
    Thanks.

    Thanks for the speedy reply. I think I understand the basics of string formating:
    for instance NSString *greeting = [[NSString alloc] initWithFormat:@"Hi there, %@!",
    nameString];
    means (if i'm correct) a variable called greeting is of the type NSStrin and is assigned the value of "hello [whatever is in the value of some other string called namestring]".
    My question is can we have code like this right in a database record...or is that problematic?
    Again I am very new to this all so please forgive my ignorance. I don't even know how to setup/access a sql database on the iPhone. I'm reading through the docs...but its quite a lot of stuff to take in. Thanks.

  • Error accesing/using a String object.......

    Hi again folks!
    Well now I have other problem, I don?t know what's happening, but I have simple C++ program as shared object which retrieves information from a Database, with the query results it makes a single string with all the data retrieved.
    This C++ program is called by a Java program using JNI, but when my Java program receives the string and tries to parse it with the StringTokenizer object I get an error like this:
    SIGSEGV 11* segmentation violation
    si_signo [11]: SIGSEGV 11* segmentation violation
    si_errno [0]: Error 0
    si_code [1]: SEGV_ACCERR [addr: 0x45cb2448]
    stackbase=DFFFF0A0, stackpointer=DFFFD0CC
    Full thread dump:
    "SIGQUIT handler" (TID:0xdd300190, sys_thread_t:0x42020, state:R, thread_t:
    t@5, sp:0x0 threadID:0xdeaf0dd8, stack_base:0xdeaf0d6c, stack_size:0x20000) prio
    =0
    "Finalizer thread" (TID:0xdd3000d0, sys_thread_t:0x41fb8, state:CW, thread_t
    : t@4, sp:0x0 threadID:0xdebb0dd8, stack_base:0xdebb0d6c, stack_size:0x20000) pr
    io=1
    "main" (TID:0xdd3000a8, sys_thread_t:0x42908, state:R, thread_t: t@1, sp:0x0
    threadID:0x20a18, stack_base:0xdffff0a0, stack_size:0x800000) prio=5 *current t
    hread*
    ObjectFactory.createObject(Compiled Code)
    Test.main(Compiled Code)
    Registered Monitor Dump:
    PCMap lock: <unowned>
    Thread queue lock: <unowned>
    Name and type hash table lock: <unowned>
    String intern lock: <unowned>
    JNI pinning lock: <unowned>
    JNI global reference lock: <unowned>
    BinClass lock: <unowned>
    Class loading lock: owner "main" (0x42908, 1 entry)
    Java stack lock: <unowned>
    Code rewrite lock: <unowned>
    Heap lock: <unowned>
    Has finalization queue lock: <unowned>
    Finalize me queue lock: <unowned>
    Waiting to be notified:
    "Finalizer thread"
    Monitor cache expansion lock: <unowned>
    Monitor registry: owner "main" (0x42908, 1 entry)
    Abort (core dumped)
    I dont know if I have to do something special before use the String, what's happening?
    Any comment will be welcome.
    Thanks in advance.

    I hope this could help to clarify the scenario
    In a previous query I get the number of rows returned by the next query
    this number is stored at SQL_NUM_SEGS.arr variable. When I have the number of rows I reserve memory for the char array that I'm going to return with all the information.
    AC01_TRAMA=(char *)malloc(atol(SQL_NUM_SEGS.arr) * INT02_TAM_SEG);
    /*embedded PL/SQL code*/
    EXEC SQL DECLARE CUR_EMISORA CURSOR FOR
    SELECT rtrim(to_char(NUM_EMISORA)) || '|' || rtrim(SERIE) || '|' || EMISORA || '|' || STATUS FROM NUCL_EMISORA WHERE STATUS NOT LIKE 'BAJA';
    EXEC SQL OPEN CUR_EMISORA;
    The next lines of code generate a string like this:
    "UTIL0000|366|239|93-1|FINASA |VIGE|243|3-90|BONSER |VIGE|248|2-94|BONSER |VIGE|287|970403|GOBFED |VIGE|362|93-4|BANOBRA |VIGE|404|2-90|BONSER |VIGE|407|2-95|FINASA |VIGE|633|95|BANMEXI |VIGE|641|2-94|PROMEX |VIGE|645|1-95|FINASA |VIGE|647|1-96|FINASA |VIGE|660|92|BANORTE |VIGE|677|93-3|BANOBRA |VIGE|678|1-90|BIATLAN |VIGE|736|2-95|BONSER |VIGE|786|1-94|BNCI |VIGE|1007|021024|GOBFED |VIGE|1008|021121|GOBFED |VIGE|"
    this string is assigned to AC01_TRAMA(char pointer)and then I return this string in the next way:
    return ( (env)->NewStringUTF(AC01_TRAMA) );
    My java program is this:
    public class Monitor
    public native String consultaGeneral();
    static
    System.load("/afs/invermexico.com.mx/usr2/salponce/gustavo/jni/src_db/Monitor.so");
    public String getTrama()
         String strTrama=consultaGeneral();
    return strTrama;
    public static void main(String []args)
    String strEmisora, strNumEmisora, strStatus,strSerie;
    Monitor m=new Monitor();
    System.out.println(m.getTrama());
    /*java.util.StringTokenizer STk = new java.util.StringTokenizer(m.getTrama(),"|");
    while(objSTk.hasMoreTokens())     
    strEmisora = objSTk.nextToken();
    strNumEmisora = objSTk.nextToken();
    strStatus = objSTk.nextToken();
    strSerie = objSTk.nextToken();
    System.out.println("\n<------>\n"+ strEmisora+"\n"+strNumEmisora+"\n"+strStatus+"\n"+strSerie);
    }//while
    Well, this java program works fine but if I try to create an String tokenizer with it the program crashes, even if I assign the result into a new String object.
    I'm going to put all the code rigth here
    C++ program
    #include "ast_bd.h"
    #include "Monitor.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <strings.h>
    #include <jni.h>
    #define CHA01_NOMBRE_APP "UTIL0000"
    #define CHA02_FIN_DE_SEG "|"
    #define INT01_TAM_LONG 20
    #define INT02_TAM_SEG 52 /*52 BYTES; Tama�o de los 4 datos en conjunto*/
    Prop�sito :-Determinar cuales son las emisoras con estado de vigente
    o bloqueado.
    -Obtener los datos de una emisora espec�fica.
    -Actualizar los datos de una emisora espec�fica.
    JNIEXPORT jstring JNICALL Java_Monitor_consultaGeneral
    (JNIEnv *env, jobject obj)
    long LO01_STATUS=1;
    char CH01_NUM_SEGS[INT01_TAM_LONG];
    char AC01_TRAMA, AC02_SEG;
    EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR SQL_NUM_SEGS[INT01_TAM_LONG],
    SQL_RESULT[INT02_TAM_SEG];
    EXEC SQL END DECLARE SECTION;
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    open_db();
    EXEC SQL SELECT to_char(COUNT(1)) INTO:SQL_NUM_SEGS FROM NUCL_EMISORA WHERE STATUS NOT LIKE 'BAJA';
    LO01_STATUS = sqlca.sqlcode;
    if( !LO01_STATUS ) /*si todo sali� bien*/
    strcpy(CH01_NUM_SEGS,SQL_NUM_SEGS.arr);
    CH01_NUM_SEGS[SQL_NUM_SEGS.len]='\0';
    AC01_TRAMA=(char *)malloc(atol(SQL_NUM_SEGS.arr) * INT02_TAM_SEG);
    sprintf(AC01_TRAMA,"%s|%s|\0", CHA01_NOMBRE_APP, CH01_NUM_SEGS);
    EXEC SQL DECLARE CUR_EMISORA CURSOR FOR
    SELECT rtrim(to_char(NUM_EMISORA)) || '|' || rtrim(SERIE) || '|' || EMISORA || '|' || STATUS FROM NUCL_EMISORA WHERE STATUS NOT LIKE 'BAJA';
    EXEC SQL OPEN CUR_EMISORA;
    LO01_STATUS = sqlca.sqlcode;
    if( !LO01_STATUS ) /*si todo sali� bien*/
    do
    EXEC SQL FETCH CUR_EMISORA INTO :SQL_RESULT;
    LO01_STATUS = sqlca.sqlcode;/*Recuperamos el estado de la operacion fetch*/
    if( !LO01_STATUS )
    AC02_SEG=(char *)malloc(SQL_RESULT.len);
    strcpy(AC02_SEG,SQL_RESULT.arr);
    AC02_SEG[SQL_RESULT.len]='\0';
    strcat(AC01_TRAMA,AC02_SEG);
    strcat(AC01_TRAMA,CHA02_FIN_DE_SEG);
    }/*if fetch correcto*/
    else
    LO01_STATUS=1;
    }while(!LO01_STATUS);
    EXEC SQL CLOSE CUR_EMISORA;/*Cerramos el cursor*/
    Si no se recuperaron registros, se indicara en el numero de segmentos
    al inicio de la trama.
    }/*if open cursor*/
    }/*if conteo*/
    puts(AC01_TRAMA);
    return ( (env)->NewStringUTF(AC01_TRAMA) );
    }/*consulta_general*/
    Java programs
    public class Monitor
    public native String consultaGeneral();
    static
    System.load("/afs/invermexico.com.mx/usr2/salponce/gustavo/jni/src_db/Monitor.so");
    public String getTrama()
         String strTrama=consultaGeneral();
    return strTrama;
    public static void main(String []args)
    String strEmisora, strNumEmisora, strStatus,strSerie;
    Monitor m=new Monitor();
    System.out.println(m.getTrama());
    /*java.util.StringTokenizer STk = new java.util.StringTokenizer(m.getTrama(),"|");
    while(objSTk.hasMoreTokens())     
    strEmisora = objSTk.nextToken();
    strNumEmisora = objSTk.nextToken();
    strStatus = objSTk.nextToken();
    strSerie = objSTk.nextToken();
    System.out.println("\n<------>\n"+ strEmisora+"\n"+strNumEmisora+"\n"+strStatus+"\n"+strSerie);
    }//while
    Thank's

  • Currency Translation not working with "Time Reference from Variable"

    We have created several Currency Translations using RSCUR with a fixed "Key Date".  All have been working fine until we got the request to allow a variable date for the exchange rate date.  I have built a variable on 0DATE which I am putting a default date value into using user exit.  This default date is the SAME date as the fixed "Key Date" which we have been using.  Unfortunately when we use the "Time Reference from Variable" option and use this new variable, no currency conversion is taking place, instead it only shows the original currency values.  I am 100% sure that my variable is getting a value and it is the same date we are using for the fixed "Key Date" value so both methods should be using the exact same exchange rates.  The documentation that I can find states:
    ●      Time reference: The time reference for the currency translation can be either fixed or variable.
    If the time reference is fixed, the time at which the exchange rate is determined is independent of the data. You have the following options:
    ○       You can establish that the time reference be determined upon translation.
    ○       You can select the current date.
    ○       You can specify a fixed date as the key date.
    ○       You can specify any variable that exists for InfoObject 0DATE.
    ○       You can establish that the query key date be used. This is determined in the query settings.
    In my case I am only switching from option "You can specify a fixed date as the key date"=(Key Date) to "You can specify any variable that exists for InfoObject 0DATE"=(Time Reference from Variable).
    What am I missing?  Any help is appreciated.

    I neglected to mention that we are calling this currency translation through a WAD button using the SET_CURRENCY_TRANSLATION command.  I did do a test by applying the currency conversion within query key figure.  This seems to work.  So it appears the issue is with how the WAD is processing the variable, not the query.  When I display the variable in a drop down item within the WAD it does have the default value that I have assigned in user exit.

  • Powershell use Connection String to query Database and write to Excel

    Right now I have a powershell script that uses ODBC to query SQL Server 2008 / 2012 database and write to EXCEL
    $excel = New-Object -Com Excel.Application
    $excel.Visible = $True
    $wb = $Excel.Workbooks.Add()
    $ws = $wb.Worksheets.Item(1)
    $ws.name = "GUP Download Activity"
    $qt = $ws.QueryTables.Add("ODBC;DSN=$DSN;UID=$username;PWD=$password", $ws.Range("A1"), $SQL_Statement)
    if ($qt.Refresh()){
    $ws.Activate()
    $ws.Select()
    $excel.Rows.Item(1).HorizontalAlignment = $xlCenter
    $excel.Rows.Item(1).VerticalAlignment = $xlTop
    $excel.Rows.Item("1:1").Font.Name = "Calibri"
    $excel.Rows.Item("1:1").Font.Size = 11
    $excel.Rows.Item("1:1").Font.Bold = $true
    $filename = "D:\Script\Reports\Status_$a.xlsx"
    if (test-path $filename ) { rm $filename }
    $wb.SaveAs($filename, $xlOpenXMLWorkbook) #save as an XML Workbook (xslx)
    $wb.Saved = $True #flag it as being saved
    $wb.Close() #close the document
    $Excel.Quit() #and the instance of Excel
    $wb = $Null #set all variables that point to Excel objects to null
    $ws = $Null #makes sure Excel deflates
    $Excel=$Null #let the air out
    I would like to use connection string to query the database and write results to EXCEL, i.e.
    $SQL_Statement = "SELECT ..."
    $conn = New-Object System.Data.SqlClient.SqlConnection
    $conn.ConnectionString = "Server=10.10.10.10;Initial Catalog=mydatabase;User Id=$username;Password=$password;"
    $conn.Open()
    $cmd = New-Object System.Data.SqlClient.SqlCommand($SQL_Statement,$conn)
    do{
    try{
    $rdr = $cmd.ExecuteReader()
    while ($rdr.read()){
    $sql_output += ,@($rdr.GetValue(0), $rdr.GetValue(1))
    $transactionComplete = $true
    catch{
    $transactionComplete = $false
    }until ($transactionComplete)
    $conn.Close()
    How would I read the columns and data for $sql_output into an EXCEL worksheet. Where do I find these tutorials?

    Hi Q.P.Waverly,
    If you mean to export the data in $sql_output to excel document, please try to format the output with psobject:
    $sql_output=@()
    do{
    try{
    $rdr = $cmd.ExecuteReader()
    while ($rdr.read()){
    $sql_output+=New-Object PSObject -Property @{data1 = $rdr.GetValue(0);data2 =$rdr.GetValue(1)}
    $transactionComplete = $true
    catch{
    $transactionComplete = $false
    }until ($transactionComplete)
    $conn.Close()
    Then please try to use the cmdlet "Export-Csv" to export the data to excel like:
    $sql_output | Export-Csv d:\data.csv
    Or you can export to worksheet like:
    $excel = New-Object -ComObject Excel.Application
    $excel.Visible = $true
    $workbook = $excel.Workbooks.Add()
    $sheet = $workbook.ActiveSheet
    $counter = 0
    $sql_output | ForEach-Object {
    $counter++
    $sheet.cells.Item($counter,1) = $_.data1$sheet.cells.Item($counter,2) = $_.data2}
    Refer to:
    PowerShell and Excel: Fast, Safe, and Reliable
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang

  • Personalization Server: Reference session variable in cm:select

    <%=String X=(String)session.getAttribute(y)%>
    How do we get X into a cm:select tag?
    I attempting to do a query and want to pass X into it.
    Tried doing <%=X%> and it's causing a JSP compile error.
    So, I guess I need to know how to pass a session variable into the query of a CM:SELECT
    tag?
    Thanks,
    Mark

    Hello Mark,
    A coworker of mine created a sample that I tested with an in-lined String variable for
    the "query" attribute. It works fine. I suspect that you may have other problems. For
    instance, I don't think <%= String X=(String)session.getAttribute(y)%> is legal. The <%=
    %> is supposed to contain a java expression, like <%= (String) session.getAttribute(y) %>
    Also, double-quotes within an expression can be problematic, such as <%= (String)
    session.getAttribute("y") %>. The best way to handle this would be to assign the session
    attribute to a String and then inline the String with: <%= myValue %>.
    Here is a working sample (that does not use a session variable, but that does not matter
    - it uses a String:
    <!-- Import the content management tag -->
    <%@ taglib uri="cm.tld" prefix="cm" %>
    <%@ taglib uri="es.tld" prefix="es" %>
    <%@ page import="com.beasys.commerce.content.ContentHelper" %>
    <!-- Use the cm:select tag to query the example content files in
    <drive>:\weblogiccommerce3.2\dmsBase for type = news, (see headline1.htm,
    headline2.htm, headline3.htm, headline4.htm, business1.htm, sports1.htm,
    and showbiz1.htm) and display headings -->
    <br>
    <%
    String newsQuery = "type = 'news'";
    %>
    <cm:select contentHome="<%=ContentHelper.DEF_CONTENT_MANAGER_HOME%>"
    query="<%= newsQuery %>"
    sortBy="heading ASC"
    id="newsline" cacheId="news_lines"
    cacheTimeout="300000" useCache="true" />
    <es:forEachInArray array="<%=newsline%>"
    id="newsBL" type="com.beasys.commerce.axiom.content.Content"
    counterId="i">
    <br>
    <% out.println((i.intValue()+1) + ") "); %>
    <cm:printProperty id="newsBL" name="heading" encode="html" default="Error" />
    </es:forEachInArray>
    Mark Mangano wrote:
    <%=String X=(String)session.getAttribute(y)%>
    How do we get X into a cm:select tag?
    I attempting to do a query and want to pass X into it.
    Tried doing <%=X%> and it's causing a JSP compile error.
    So, I guess I need to know how to pass a session variable into the query of a CM:SELECT
    tag?
    Thanks,
    Mark--
    Ture Hoefner
    BEA Systems, Inc.
    2590 Pearl St.
    Suite 110
    Boulder, CO 80302
    www.bea.com
    [att1.html]

  • PLS-00487: Invalid reference to variable ' expression '

    oracle database 10G
    OS unix
    One of procedure is giving error PLS-00487: Invalid reference to variable '<expression>' while compilation in above database while it is compiling
    successfully in other database.
    Is there any database error?

    PLS-00487: Invalid reference to variable "string"
    Cause: A variable was referenced in a way that is inconsistent with its datatype. For example, a scalar variable might have been mistakenly referenced as a record, as follows: DECLARE CURSOR emp_cur IS SELECT empno, ename, sal FROM emp; emp_rec emp_cur%ROWTYPE; my_sal NUMBER(7,2); BEGIN ... total_sal := total_sal + my_sal.sal; -- invalid ...
    Action: Check the spelling of the variable name. Make sure the variable was declared properly and that the declaration and reference are consistent regarding datatype.
    Most probably the compiler "sees" some other type variable with the same name first which in the other database doesn't exist or is out of scope.
    Regards
    Etbin

Maybe you are looking for

  • Sy-index inside a loop

    Hi All, I am trying to enhance a datasource and in that I am writing a loop inside another loop. I am trying to get the loop number of the inner loop by using the sy-index inside the inner loop. But, the sy-index is not being changed and it is always

  • Error SAPMF05A 0700 E - while clearing document in F.13

    Hi All, While running the automatic clearing through t.code F.13. Getting the following error. ScName       Scr. Mtyp Mid Mno  Message text SAPMF05A 0131 S      F5  074  4 items were selected SAPMF05A 0700 E      /DS 310  Please Enter Valid Trading P

  • Plethora of issues with my NEW computer. Apple won't help

    I bought my brand new Apple MacBook Pro in August of 2011. Paying so much for a product manufactured by such a large and notable company, one would expect to get a piece of machinery that was worth the amount of money that I spent. WRONG. Since I bou

  • Web IC Sales Order ERP Integration (Workcentre IC_SLO_ERP)

    System: CRM 2007 s4 and ECC 6 I have integrated ERP Sales Order within my Web IC aplication.  I'm able to create ERP orders from within the CRM based Web IC using the work centre IC_SLO_ERP.  I can save the orders and the orders are saved to SAP ECC

  • How can I split long words to feet the line in JEditorPane

    Hi, Can someone help me ? I'm trying to write long words in JEditorPane, and I want the JEditorPane to split them, so it will feet the line... (something like word wrapping in JTExtArea). How can I fix my code so it will work? import java.awt.*; impo