Removing Logic / Dynamic logic

Hello all... this is something I have been thinking about for a few weeks and every once and a while I get inspired to see if I can find a simple solution to a rather annoying (but not critical) problem I am having with a bit of code... and in fact... I run into this more than a few times a year (so hell... maybe there's a design pattern out there somewhere...)
Anyway... here's the deal.
I have an EJB that accepts a WDDX string, which I deserialize into a Hashtable (very basic)...
Then I loop through the Hashtable looking at the keys and in this case I build a dynamic SQL statement based on the keys that are present in the Hashtable.
So I have a bit of code that looks like this:
if (key.equalsIgnoreCase("foo")) {
    if (sqlStatement.length() == 0)
        sqlStatement.append("where foo = '" + hash.get(key) + "' ");
    else
        sqlStatement.append("and foo = '" + hash.get(key) + "' ");
}Of course the above is a very simple example... sometimes I have to look at the value as well...
Basically... my code gets HUGE! I mean... if I have to check for 20 or so keys... that gets to be a bit crazy... and I hate having to scroll through that much code :)
So, what I am wondering is... is there a design pattern... technique... method... black magic/black box trick to make this logic more dynamic? What I have been thinking is if I could have a configuration file-like construct... almost like a rules file or something similar to that.
Any hints, tips, tricks, advice, swift kick in the backside for asking something that is probably very obvious... would be greatly appreciate.
./dave

If you know the keys that you're looking for can't you
use an array? For Example - put the keys into a
string[] :
private String[] keys = new String[] {"aaa", "bbb",
"ccc", "ddd", "eee", "foo", "ggg", "hhh", "iii"};
... snipped ...
Heh.. thanks! I actually started doing that, but it became as big of a mess as my original concept because... and I know I didn't state this in my example... that I may have to do a bit more complex logic on a key I have in a hash... like if a key is of a certain value... i have to append a String variable so that I can do a certain outter-right join as part of the query I'm building...
Here's an actual example (snipped from my EJB)
else if (key.equals("SELECTYEAR")) {
    if (criteria.length() == 0)
        criteria.append("WHERE v.model_yr = '"+value+"' ");
    else
        criteria.append("AND v.model_yr = '"+value+"' ");
    ordIDJoin = "AND o.ord_id = oi.ord_id";
    configIDJoin = "AND oi.veh_config_id = v.veh_config_id";
else if (key.equals("ORD_STAT_CD"))
    if (value.indexOf(LIST_SEPARATOR) > 0)
        if (criteria.length() == 0)
            criteria.append("WHERE o.ord_stat_cd IN ("+value+") ");
        else
            criteria.append("AND o.ord_stat_cd IN ("+value+") ");
    else
         if (criteria.length() == 0)
            criteria.append("WHERE o.ord_stat_cd = "+value+" ");
         else
            criteria.append("AND o.ord_stat_cd = "+value+" ");So... now (I think) you can see why I need something that can handle a bit more complexity when deciding how to append my sql statement StringBuffer
Thanks for responding! :)
./dave

Similar Messages

  • Dynamic logic expression

    Hi Experts, 
    Iu2019m trying to build a routine with dynamic logical expressions but it's now working...
    Basically Iu2019m building a string with the expression, a and after the string it's completed Iu2019m calling a macro that consist in a if.
    if expression eq true
    return true value
    but the value returned by the macro it's always false, even when the logical expression it's true...
    i already tried the logical function BOOLC but apparently my version, ECC 6, doesnu2019t recognize it....
    Below goes the code, if anyone could help me Iu2019ll be appreciated.
    "Macro definition
    DEFINE check_condition.
    IF &1 EQ ABAP_TRUE.
        move 'X' to &2.
      endif.
    END-OF-DEFINITION.
    LOOP AT tab_regras."Rules
        CLEAR: str_cond, lv_result.
        LOOP AT dfies_tab WHERE fieldname CS 'ARGUMENTO'.
          CLEAR: lw_string, str_1, str_2, str_3.
          ASSIGN COMPONENT dfies_tab-fieldname OF STRUCTURE tab_regras TO <fs_field>.
          CHECK <fs_field> IS NOT INITIAL.
          SPLIT <fs_field> AT '/' INTO  str_1 str_2 str_3.
          ASSIGN (str_1) TO <fs_value1>.
    "     ASSIGN (str_2) TO <fs_value2>.
    "      ASSIGN (str_3) TO <fs_value3>.
          IF str_cond IS INITIAL..
            CONCATENATE <fs_value1> str_2 str_3 INTO str_cond SEPARATED BY space.
            CONTINUE.
          ENDIF.
          CONCATENATE str_cond 'and' <fs_value1> str_2 str_3 INTO str_cond SEPARATED BY space."string condition
        ENDLOOP.
        check_condition str_cond lv_result.
        CHECK lv_result EQ 'X'.
    Thanks in advance,
    Best Regards
    João Martins

    It would be helpful if you show us what is the example content of str_cond .
    Anyhow your check looks like you want to compare some condition with value X which abap_true denotes i.e.
    if field_1 = 10 and field_2 = 20 EQ 'X'. 
    endif.
    This doesn't make sense for me or maybe I am missing something which is hidden behid this str_cond . Your left hand side expression value must however be equal to right hand side value. So the conditon will only be true if
    if 'X' = 'X'.
    endif.
    Regards
    Marcin
    PS: please note that in ABAP there is no real boolean value, so you can't have condition like in JAVA or C
    if (true_condition)
    //do something
    you always have to compare two values (here abap_true which is X if fact).
    Edited by: Marcin Pciak on May 24, 2011 3:59 PM

  • A dynamic logic

    Hello friends,
    How can sort below weekdays meaningfully like
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    instaed.
    There must be a dynamic logic .
    This is the output in the ALV-Grid-Output.
    WD        Nr-Accidents
    Monday        1
    Saturday      2
    Tuesday       4
    Friday       5
    Thursday   3
    Wednesday  4

    WD Nr-Accidents  dayno
    Monday 1       1
    Saturday 2      6
    Tuesday 4       2
    Friday 5          5
    Thursday 3      4
    Wednesday 4  3
    take one extra field in your table (Final internal table).
    when you are populating the Day name that time you fill the DAY no.
    now sort internal table with the DAYNO.
    DAy no<-- you can hide this using no_out = 'X'. when you are filling the catalog.
    WD Nr-Accidents 
    Monday 1      
    Tuesday 4      
    Wednesday 4 
    Thursday 3   
    Friday 5      
    Saturday 2

  • How to master audio file handling? Where is the logic of Logic?

    1. How can I master where to save my logic project files including audio?
    2. I want to save a project as a template WITHOUT the recorded track files. When I open the new template I dont want to have all old audio in my "media"browser inside Logic! How?
    3. I have one old project with a lot of audio of which only a few are used, yet when I try the cleanup function only a few are erased. Why?
    4. How to save a project so that ALL the files used are saved inside that project folder. In Protools and Cubase you can erase all material you  dont use.
    5. I want to have all my audio saved in ONE project folder but they end up scattered somewhere else, what to do?
    I can never get used to the apple/logic sense of file structure. Crazy! Where is the logic of Logic?  /Helpless to the logic of Logic 8

    Hi
    If I understand the problem correctly?
    jrm1 wrote:
    The possible issue concerns the start of the audio files.
    I recorded the tracks down to a stereo file, a region, that appears to start in the arrange at the correct point. But when you record, Logic includes some recording before the start of the region, before the Anchor, correct?
    This can depend on how you did the "record down to a stereo file".
    If you routed tracks to bus channels, then recorded the bus to another track, Logic will include the count-in in the audio file. As you say, the region in the Arrange will be correctly "trimmed".
    One solution would be to convert these bounced regions to new audio files (Audio Menu), another to use Bounce Region (or track) in Place.
    Alternatively, use a manually placed "2 pop" 2 seconds before the start of each cue.
    CCT

  • Usage of logical name, logical path name, physical name of a file

    Hi all,
    I have to write to a file on the application server. I had been given the logical name, logical path name and physical name. Suggest how to use these parameters and get the path where to store the file.
    Thanks & Regards,
    Kasinath.

    Open Dataset
      catch system-exceptions DATASET_CANT_OPEN = 8.
        open dataset UNIX_FILE for output in text mode encoding default.
      endcatch.
    Write to Dataset
      loop at IT_STR into IS_STR.
        catch system-exceptions DATASET_NOT_OPEN = 0  .
          transfer IS_STR-STR to UNIX_FILE.
        endcatch.
      endloop.
      if SY-SUBRC eq 0.
        message S138(ZSM) with 'Data Downloaded to Unix File'.
      endif.
    Close Dataset
      close dataset UNIX_FILE.
    Regards
    - Gopi

  • Removing the dynamic attributes from view context

    Hi,
    I have added an attribute dynamically using the following line of code in wdDoModifyView():
    wdThis.wdGetContext().getContext().getRootNodeInfo ().addAttribute(<attributename>, <datatype>);
    Now I want to remove the dynamically created attribute from the context.
    Pls suggest me in this regard.
    Regards,
    Ramesh.

    Hi Ramesh,
    You can use the following code to remove the attribute dynamically:
    Iterator itr = wdContext.node<NodeName>().getNodeInfo().iterateAttributes();
    <i>// If the node where you are making these attributes is a context node then just do:</i>
    // <b>wdContext.getNodeInfo().iterateAttributes()</b>, <i>for iterator</i>
    while(itr.hasNext()){
         IWDAttributeInfo attrInfo = (IWDAttributeInfo)itr.next();
         attrInfo.remove();
    This will solve your problem.
    Regards
    Pravesh
    PS: Please consider rewarding points if helpful and solved.

  • Rename Logical Schema / Logical Agent

    Hi,
    is it possible to rename a logical schema / logical agent?
    Thanks in advance & kr
    Michael

    Hi,
    Yes it is possible to rename logical schema/agent in ODI topology .
    While renaming you will get a warning saying this is used in work repository and if you rename you need to make sure all code/objects using this logical schema are pointing to the new name . Else you may find issue during execution.
    It is not a good practice to change logical schema name.
    Thanks,
    Sutirtha

  • Remove a dynamic where clause

    Hi,
    Is it possible to remove a dynamic where clause ?
    If possible whats the way to do it ..
    Thanks and Regards,
    Dean.

    Dean,
    What do u mean by " remove a dynamic where clause"?Its applied in VOimpl class init query method.So, if u don't call that and directly do execute query, dynamic where clause will not be applied.
    Also u can change the VO query, using setQuery.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Adding and removing tabs dynamically as in explorer

    adding and removing tabs dynamically as in explorer or firefox

    Think about how many translations are required to move your avatar, then think how many translations are required to move everything else in the entire world. Depending on whether there is more to translate in your avatar or in the rest of the world, you have your solution.
    Not knowing how your system works I can't really suggest anything further but could the collision avoidance be interacting with everything in the world as well? That would increase the workload somewhat.

  • ACS 4.2 - automate removal of dynamic users

    Is it possible to automate the removal of dynamic users to a preset schedule, say once a month?
    thanks
    Bob

    No its not possible to automate the removal of dynamic users to a preset schedule. The only option is to use the "Remove Dynamic Users" button manually in the User Setup.

  • Logic Pro, Logic Studio and Logic Express

    Can someone explain the difference between Logic Pro, Logic Studio and Logic Express?

    Hi,
    I don't think your friend is right on this. When you install Logic X, only the most essential part will be downloaded. After that you open Logic X, and from within the program  you can download all the other content. Logic will look if you already have Logic 9 content on your harddisk, so it won't download files that are already present. So, after all is downloaded, all files are on your harddisk, just like Logic 9. By the way, Logic 9 will still be available after installing Logic X.
    Whether you will experience crashes will be very hard to prodect, because these will be caused by unforeseen combinations of your computer, audio interfaces, maybe even other hardware, kernel extensions etcetera. If you wait for a couple of months, updates of Logic X will probably have less crashes. As said, on my computer it's just as solid as Logic 9.
    Garittan will probably advise a fast harddisk to prevent complaints when people are pushing the plugin to the edge. I would expect that it's not a black/white story.
    The AUMatrixreverb can be found in any audio plugin slot completely at the bottom: Audio Units > Apple > AUMatrixReverb.
    About the Epiano: in Logic Express there is only the Garageband Epiano, I think. Logic Pro 9 had a great ePiano that they gave a new name and changed a bit in Logic X. Both very nice.
    Yes, you may be right, not too many drums with brushes in Logic X, I think. Or does anybody else know where to look??
    Kind regards,
    Jaap

  • Can I upgrade from Logic 7 to Logic Studio (Logic 9)?

    Can I upgrade from Logic 7 to the new Logic Studio (Logic 9)? Or do I need to purchase the Logic 8 upgrade first?
    Thanks in advance.

    Get the 9 upgrade, no need for 8 first.

  • Dynamic Logical Expressions in ABAP: IF (lt_cond)...

    is it possible to have a dynamically constructured logical expression?
    I have a condition I need to use in an IF, but I want to avoid hard-coding, so I dynamicallybuild it.
    for a simple example:
    CONCATENATE ITAB-f1
               'EQ'
               varValue
               INTO lt_cond SEPARATED BY SPACE.
    IF (lt_cond).
      WRITE:/ 'Success'.
    ENDIF.
    Is it possible to do this?
    NL

    I am trying to use the macro to check an IF (cond).
    cond is a dynamically constructed condition.
    The bold part of my code way below is my problem area.
    I'm having no trouble getting COND constructed. But I am having trouble between my macro and the processing as my error always tells me I'm calling my macro without 2 actual parameters. Or when I DEFINE my macro with &1 instead of &1 &2, I get 'incorrect logical expression'.
    I've read all the documentation I can find on this, but i still cannot figure out why my macro is not processing.
    Code is lengthy, but if you can, please help.
    I'm anticipating the output to be 'FAILURE' at this point. I just want the condition COND to be processed.
    data: tabfield(20) type c,
          orcheck type I,
          cond type string.
    DATA: BEGIN OF ITAB_NOTIDX OCCURS 0,
          FIELD LIKE ZDOLTARC02-SEARCHFLD,
          VALUE LIKE ZDOLTARC03-VALUE,
          STRUCTURE LIKE ZDOLTARC02-STRUCTURE,
          AOBJ LIKE ZDOLTARC02-A_OBJ,
          END OF ITAB_NOTIDX.
    DATA: BEGIN OF ITAB_AOBJ OCCURS 0,
          AOBJ LIKE ZDOLTARC02-A_OBJ,
          END OF ITAB_AOBJ.
    DATA: ITAB_AOBJF LIKE ITAB_AOBJ.
    DATA: ITAB_NOTIDXF LIKE ITAB_NOTIDX.
    DATA: varAOBJ LIKE ZDOLTARC02-A_OBJ.
    ITAB_NOTIDXF-FIELD = 'LIFNR'.
    ITAB_NOTIDXF-VALUE = '123'.
    ITAB_NOTIDXF-STRUCTURE = 'BKPF'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'LIFNR'.
    ITAB_NOTIDXF-VALUE = 'ABC'.
    ITAB_NOTIDXF-STRUCTURE = 'BKPF'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'LIFNR'.
    ITAB_NOTIDXF-VALUE = '001'.
    ITAB_NOTIDXF-STRUCTURE = 'BKPF'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'SAKNR'.
    ITAB_NOTIDXF-VALUE = '111'.
    ITAB_NOTIDXF-STRUCTURE = 'BSEG'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'SAKNR'.
    ITAB_NOTIDXF-VALUE = '222'.
    ITAB_NOTIDXF-STRUCTURE = 'BSEG'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'KUNNR'.
    ITAB_NOTIDXF-VALUE = 'CCC'.
    ITAB_NOTIDXF-STRUCTURE = 'BSEG'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    ITAB_NOTIDXF-FIELD = 'KUNNR'.
    ITAB_NOTIDXF-VALUE = 'DDD'.
    ITAB_NOTIDXF-STRUCTURE = 'BSEG'.
    ITAB_NOTIDXF-AOBJ = 'FI_DOCUMNT'.
    APPEND ITAB_NOTIDXF TO ITAB_NOTIDX.
    LOOP AT ITAB_NOTIDX.
      WRITE:/ ITAB_NOTIDX-FIELD, ITAB_NOTIDX-VALUE, ITAB_NOTIDX-STRUCTURE, ITAB_NOTIDX-AOBJ.
    ENDLOOP.
    DATA: VARFIELDNAME LIKE ZDOLTARC02-FIELD.
    CONCATENATE cond
               INTO Cond.
    SORT ITAB_NOTIDX BY AOBJ FIELD.
    varFieldName = Itab_NOTIDX-FIELD.
    ORCHECK = 0.
    ITAB_AOBJF = 'FI_DOCUMNT'.
    APPEND ITAB_AOBJF TO ITAB_AOBJ.
    LOOP AT ITAB_AOBJ.
       MOVE ITAB_AOBJ-AOBJ TO varAOBJ.
       WRITE:/ varAOBJ.
       LOOP AT ITAB_NOTIDX WHERE AOBJ EQ varAOBJ.
               WRITE:/ 'LOOP TEST'.
            IF ITAB_NOTIDX-FIELD EQ varFieldName.
                 WRITE:/ VARFIELDNAME.
                 IF ORCHECK <> 0.
                 CONCATENATE cond
                                'OR'
                                INTO cond SEPARATED BY SPACE.
                 ENDIF.
                 CONCATENATE ITAB_NOTIDX-STRUCTURE
                        ITAB_NOTIDX-FIELD
                        INTO tabfield.
                 CONCATENATE cond
                        tabfield
                        'EQ'
                        '''' ITAB_NOTIDX-value ''''
                        INTO cond SEPARATED BY SPACE.
                 ORCHECK = ORCHECK + 1.
            ELSE.
                MOVE ITAB_NOTIDX-FIELD TO varFieldName.
              WRITE:/ '2', VARFIELDNAME.
                CLEAR TABFIELD.
              ORCHECK = 0.
              CONCATENATE ITAB_NOTIDX-STRUCTURE
                    varFieldName
                    INTO TABFIELD.
                 CONCATENATE cond
                        'AND'
                        TABFIELD
                    'EQ'
                    '''' ITAB_NOTIDX-VALUE ''''
                        INTO cond SEPARATED BY SPACE.
                    ORCHECK = ORCHECK + 1.
            ENDIF.
       ENDLOOP.
    ENDLOOP.
    CONCATENATE COND
                INTO COND.
    write:/ COND. "constructed properly
    <b>DEFINE my_dynamic_check.
    if &1, &2.
      write:/ 'Success'.
    else.
      write:/ 'Failed'.
    endif.
    END-OF-DEFINITION.
    my_dynamic_check (cond).</b>

  • Dynamic Logical Port for Web Service Client

    Hi *!
    We want to use the same Web Service Client code with different Web Service instances running on different systems. So I need to configure the logical port (especially the URL of the endpoint) dynamically at runtime.
    Please give me a hint, how this is done.
    (we are using WebAS 6.40 SP7)...
    Thanks in advance,
         Frank

    Hi Frank,
    I hope you were able to solve your issue on you own in the meantime.
    I was looking for the answer to this question today. This was the only thread I found on SDN. Unfortunately, it did not contain an answer yet. I was able to figure out a way to set the endpoint address dynamically after searching help.sap.com and after examining the interfaces offered by the Stub (logical port in this case) classes.
    Here's an extract from my code:
    // Connect to JNDI context
    InitialContext ic = new InitialContext();
    // Get reference to web service proxy from JNDI context
    Z_MSC_GET_SCHEDULE_WSDService service =
         (Z_MSC_GET_SCHEDULE_WSDService) ic.lookup("wsclients/proxies/iot-online.de/msc~srv_ejb~proxy/de.iot_online.msc.proxy.ScheduleReaderProxy");
    // Get reference to logical port from web service proxy
    Z_MSC_GET_SCHEDULE_WSD logicalPort = service.getLogicalPort();
    // Set URL of web service Endpoint
    logicalPort._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, "http://<FQDN>:8010/sap/bc/srt/rfc/sap/Z_MSC_GET_SCHEDULE_WSD?sap-client=100");
    This is explained on
    http://help.sap.com/saphelp_nwce10/helpdata/en/45/113a1221337249e10000000a155369/frameset.htm
    You can also set the credentials (username / password) with the method _setProperty.
    Best regards
    Christian

  • Dynamical logical port creation

    Hi
    Is it possible to generate a logical port dynamically at runtime. I only need a logical port once for executing a web service, so I'm looking for a way to minimize administration work.
    Regards, Mathias

    hi gourav,
    thanks for a very helpful.. answer..
    but i am still getting the error Uninstantiated object "subject sidl service" in method IF_SRT_WSP_CONFIG_SIDL~CREATE_CLNT_CFG_FROM_WSDL_D of class CL_SRT_WSP_CONFIG_SIDL'.
    while creating the logical port....i am using endpoint URL from the wsdl ...i also tried seleting the wsdl file while cerating port..
    Also when i tried creting port for another consumer proxy it is working....so this is not a system issue
    what could be the problem

Maybe you are looking for

  • Tiling a rectangle with arbitrary number of rectangles

    I'm trying to figure out how to tile a rectangle (the stage) with an arbitrary number of rectangles. Simple tiling where all the tiles are the same size and simply stacked in a grid. I'm doing this with a resizable layout and a number of tiles that i

  • ITunes reopens automatically after quiting

    This problem has been happening through the last few updates. I quit (or even force quit) iTunes, and it reopens automatically. It's a real problem now because it's actually preventing me from shutting down my Mac. I have no programs running with it

  • FEBA - electronic bank statement - change posting rule

    Hi Experts, When processing the electronic bank statement in FEBA, there was an error in one of the lines. The status of the line is ' To be posted'. I need to change the posting rule (internal transaction) but i hit this error - Item would not be po

  • Displaying the drive letters of another PC connected through Ethernet

    Am using two PC's connected in a network via ethernet. I want to read the drive letters (a:\, c:\, d:\, e:\, etc.....) of one PC and display in the LabVIEW application running in another PC. I searched the forum and found an example posted by tst (i

  • Typing around for far.

    Whenever i have a list of text and i have to add extra type double click just will open a new text box. It also very annoying when i have a circle in color (a bullet) with some number in it...it is sometimes difficult to write text fast specially if