IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

String concatenation questions

  • 1.  String concatenation questions

    Posted Fri October 21, 2005 04:43 PM

    Hello,
    i have data in customer field
    1)address1 2)address2 3)city 4)state 5)zip code…

    i need to concatenation into partner field with single name like
    1)Mailing Address
    above all customer address fields must me appear into one form;

    i try to worked with -pub.string.concat,
    and also using java service but i am getting error,
    any one can help above problem ,and send me please the related steps or code.

    how to do ?
    please make it clearly
    Thanks


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 2.  RE: String concatenation questions

    Posted Fri October 21, 2005 05:23 PM

    APG,

    The PSUtilities package has a multiConcat service (which is available from webMethods advantage portal).
    I think it will solve your problem.

    HTH,
    Maldonado


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: String concatenation questions

    Posted Fri October 21, 2005 07:09 PM

    Hi Maldonado,
    Thanx for your reply,is there any other way to concat using pub.string.concat;we can add to strings using cocat …if we use multiple concats(pub.string.concat’s) to get the result.
    some people given idea using java services but ,i dont know i am getting error.
    Thank you very much for reply.
    bye
    APG


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 4.  RE: String concatenation questions

    Posted Fri October 21, 2005 07:26 PM

    APG,

    What is the error that you are getting?so that someone can help to debug.

    HTH,
    RMG


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 5.  RE: String concatenation questions

    Posted Fri October 21, 2005 10:05 PM

    Try pub.string:makeString. When mapping the inputs, use the index to map each individual input string to positions in the elementList variable. There is no need to write a Java service to perform this–you can easily use what’s already built and tested.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 6.  RE: String concatenation questions

    Posted Fri October 21, 2005 10:48 PM

    Hello,

    Yemi Bedu


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 7.  RE: String concatenation questions

    Posted Sat October 22, 2005 12:02 AM

    Hi Seniors,
    while adding more elements to makestrig i am getting bellow errors.i used in the add element lists all fields on that time i may not add more than one field.
    may be i approched in wrong way ,please can u people clarify me.

    I got the following ERROR.
    [ISC.0049.9018] The path has been used: /elementList(0)


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 8.  RE: String concatenation questions

    Posted Sat October 22, 2005 02:43 AM

    Click on the variable being mapped to the list. On the Properties pane you’ll see an Index (or Indices) button. Click it. Set the index for each of the mapped strings to be unique, starting at 0.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 9.  RE: String concatenation questions

    Posted Mon October 24, 2005 11:33 AM

    My quick and not so dirty multi concat:

    ==== start code

    // pipeline in
    IDataCursor pipelineCursor = pipeline.getCursor();

    String delimiter = IDataUtil.getString(pipelineCursor, “delimiter”);
    //default to empty string for delimiter
    if (delimiter == null)
    {
    delimiter = “”;
    }

    StringBuffer strBuff = new StringBuffer();

    boolean hasHadFirstString = false;

    for (int i=0; i<= CONCAT_MAX_INPUT_STRINGS_NUMBER; i++)
    {
    String currentString = IDataUtil.getString( pipelineCursor, “inString”+i );
    if (currentString!= null)
    {
    if (hasHadFirstString)
    {
    strBuff.append(delimiter);
    }
    else
    {
    hasHadFirstString = true;
    }
    strBuff.append(currentString);
    }
    }

    IDataUtil.put( pipelineCursor, “value”, strBuff.toString() );
    pipelineCursor.destroy();

    ==== end code

    In the shared tab simply declare a variable:

    private static int CONCAT_MAX_INPUT_STRINGS_NUMBER=10;

    and create inputs:
    delimiter
    inString1
    inString2
    inString3

    inStringN

    where N is up to whatever number you set CONCAT_MAX_INPUT_STRINGS_NUMBER

    that way if you need more later on, just create new inStringN inputs and bump up the number.
    Never bump it DOWN however unless you’re sure that noone has used the extra inStringN pipeline variables.

    Output will be the good old “value” output.

    regards,
    Nathan Lee
    PS apologies about the formatting, couldn’t work out how to get spacing correct, pre tag doesn’t work, neither does nbsp’s… If I do certain combinations of “enable html code” and auto activate urls it breaks my code (chops off closing curly braces!)


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 10.  RE: String concatenation questions

    Posted Mon October 24, 2005 01:52 PM

    Why not just use pub.string:makeString? It provides the same functionality (though setting the inputs takes a few more clicks) and doesn’t need to be modified when the max number of strings exceeds the max number the service will accept. And it’s available on every IS.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 11.  RE: String concatenation questions

    Posted Tue October 25, 2005 02:48 AM

    Aah, I tend to find that too much use of indexed array inputs is hard to visually see what’s going on (they’re all blue links going into a single element).
    Generally you don’t need to stick more than a handful of things together, so the updating the number is only really a once or twice thing, can always set it up to be 20 and be done with it…

    I find it a lot quicker to setup and readjust if you need to change the order or something(by quicker I mean less typing, more mouse arm RSI). I find the process of map, type index, click ok, map, type index, click ok is a bit slow compared to map map map done…

    Anyhow, it’s just something I dump in the common package for whatever company I’m at and then it’s a reusable chunk.

    Nath


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 12.  RE: String concatenation questions

    Posted Tue October 25, 2005 08:31 AM

    When using such multiconcat service with many inputs or even makeString be ready for sizable performace hit. If you need to concat several strings say 3-5 in a long nested loops do not try to use Flow loop operation. It is best to write Java service that does such operations for performance. As an example on loop of 10000 elements with such concat services you can loose about 5-10 min of processing time.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 13.  RE: String concatenation questions

    Posted Wed October 26, 2005 12:10 AM

    Hello,

    Yemi Bedu


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 14.  RE: String concatenation questions

    Posted Wed October 26, 2005 02:11 AM

    The pub.string:makeString and pub.string.conat both are Java services as well as previosly discussed code is also Java. There is no problem with Java service itself although there are use cases of String + concatination vs StringBuffer.append that are faster depending on JVM and JIT optimizations. That is all well known Java programming stuff.
    Specificaly pub.string:makeString may be more efficient than concat or custome Java concat service because it uses list as input instead of individual strings.

    But I was talking about specific cases where these java services are used inside nested Flow loops. In that case replacenig Flow loop logic with direct Java loop logic that includes efficient java concatination provides significant performance gain at least in JVM 1.4.2. To start with just flow loop operation exec will account for about 40% of time. Bottom line is if you call even Java service you willl have to build PIPELINE objects and IS context to invoke these services. Also with 10 or 20 input fields there is compunded time to read and test each one even if you do not use most of them. These are perormance hits that accumulate on large loop itterations.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 15.  RE: String concatenation questions

    Posted Wed October 26, 2005 02:22 AM

    Yemi:
    Not to put a dampener on your performance claims: but why is that of utmost importance (or really: any importance)? It is fairly unlikely you’ll be able by hand to physically supply enough inputs to see any performance difference between makestring/my multiconcat/your multi concat. Perhaps if you have 100,000 strings, but realistically: this is a convenience wrapper instead of calling concat a few times.

    The solution you provide does indeed concatenate things together, but you’re comparing apples and oranges (and not explaining anything of your “preformance test”, sample data etc). The code is not equivilent for a start: yours has no ability to set a delimiter and also no ability to be used as a standalone service (as it iterates through the entire pipeline). Mine requires creation of a java service (and is thus a piece of custom code so is not out of the box, so requires more effort than makeString to get it written) and makeString is included functionality out of the box (thus development time “perfomance” beats yours and my solution).

    Also: the focus on performance of something that sticks a few strings together: it’s micro optimising at best. There are far greater performance increases to be found by examining the macro-optimisations e.g. like reducing network round trips, allowing concurrent execution etc.

    Igor does make a valid point about performance in loops: regardless of whether you have the most optimised “concat service” in the universe, if you output a new string and then concatenate something else to that next iteration of the loop it will make so little difference overall that the 0.000000001 of a nanosecond you shaved off by optimising your java service is lost by the cost of memory allocation over and over again. This is a problem in java as well as pretty much any language really. The solution for Strings and loop concatenation in java is StringBuffers.

    So if you wanted to get good performance while still using loops rather than java services, try creating a couple of StringBuffer services, one to create an empty one, another to append, another to call toString on it. Just leave a StringBuffer sitting on the pipeline and keep passing it into the services as you go.

    Reason I even bothered posting is that obsession with performance for learning developers is a bad idea, it encourages hacking over clean design, java services over flow (for no reason, leading to a maintenance nightmare).

    Nathan Lee


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 16.  RE: String concatenation questions

    Posted Wed October 26, 2005 05:00 AM

    Interesting points all.

    To Nathan’s point about optimizing too soon, there’s a fairly well circulated notion about the 3 rules of optimization:

    1. Don’t optimize yet.
    2. Don’t optimize yet.
    3. Don’t optimize yet.

    Some random thoughts spurred by the thread:

    • My original reason for posting “why not just use makeString?” is in sync with Nathan’s “…obsession with performance…encourages…java services over flow” where my knee-jerk reaction was “a service already exists, why do another one?” But Nathan rightly pointed out the
      the better readability and modifiability of the multi-concatservice. Though I think I would still use makeString rather than a custom multi-concat just to be ornery. :wink:

    • Igor’s point about performance in loops is good to keep in mind–once one determines that the loop is a meaningful bottleneck.

    • The biggest time killer in loops? Allocating objects, as both Igor and Nathan allude to.

    • One thing intriguing about Yemi’s approach to iterate over the pipeline is if the call to the service was scoped. This would let one control what variables are concat’d but I’d worry about the order.

    Interesting thread.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 17.  RE: String concatenation questions

    Posted Wed October 26, 2005 05:22 AM

    Has been an interesting thread considering the fairly plain topic (e.g. concatenation)…

    Optimisation rule: I always liked the magic saying (thanks to my first boss):
    “the biggest performance increase you’ll EVER get is to go from the non-working state to the working state”

    I treat that one as the golden rule, because at the end of the day you gotta get it working first, then worry about the details. So ease of development (realisability), understandability, clarity, maintainability tend to rate higher for me than raw-byte-code optimisations… As you go along you instinctively avoid any performance traps you’ve come across in the past and sit down and design things well to start with…

    The scoped invoke, yeah, but then you need 3 flow operations (map to setup, invoke with scope, map to map out result) which starts looking a bit messy if you do it too much (I had to do a bunch of dynamic invoking of other services which needed this a handful of times, so I wrapped it up in a sequence to tidy things up).

    Could also invoke it as a transformer service and add the variables by hand, but then you get to what mine (+/- a bit of key lookup expense) except that you have to add the variables each time/can choose whatever names you like.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 18.  RE: String concatenation questions

    Posted Wed April 05, 2006 04:55 PM

    Hi…How would i concatinate two string but appended to something…
    Like i have STRING1 and STRING2

    i need the ouput as STRING1+++STRING2

    I need “+++” in between…
    Please some one help me how to do that…
    I didnt want 2 use append to string list, coz i want the ouput as string itself.

    Thanx for ur help


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 19.  RE: String concatenation questions

    Posted Wed April 05, 2006 05:07 PM

    use a map and in the map use pub.string.concat transform give input as string1 and +++, map the output to string1. use another map and again use pub.string.concat transform and give input as string1 and string2. you will get the desired string as output.
    Thanks,
    Jay


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 20.  RE: String concatenation questions

    Posted Wed April 05, 2006 05:16 PM

    Basically rigid solution is to use 2 concat services
    in concat1(STRING1,++++) map to concatString
    in concat2(concatString,STRING2) map to multiConcat --this holds STRING1+++STRING2.

    Or create a java service utility with the code below

    Service Inputs (inString1,instring2,inString3)
    Service Output(outStr)

    String str1 = checkNull(in.getString(“inString1”));
    String str2 = checkNull(in.getString(“inString2”));
    String str3 = checkNull(in.getString(“inString3”));

    String outStr = str1 + str2 + str3;

    out.put( “outStr”, outStr );

    Also put this code in Shared tab of Javaservice,to check for null values.

    private static String checkNull(String inputString)
    {
    if( inputString == null )
    return “”;
    else
    return inputString;
    }

    Save JS and test the service.

    HTH,
    RMG


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 21.  RE: String concatenation questions

    Posted Wed April 05, 2006 05:24 PM

    Thank you so much for ur instant reply…I appreciate it.
    Thank you


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 22.  RE: String concatenation questions

    Posted Thu April 06, 2006 08:36 PM

    Stepheny,

    As you probably noticed from going through this thread, there are different ways that you can accomplish concatenation and you will find that different people will defend different approaches based on factors like readability, performance, maintanance, etc.

    I, for one, believe in trying to stick as much as possible to existing buit-in services rather than creating new services. Why?
    (1) because it’s one less service that I need to worry about maintaining
    (2) because it keeps my folders and packages cleaner
    (3) because what is more likely to be true: for a new developer to understand how to use my service OR for him/her to know how to use a built-in service that exists and is documented in every IS installation?
    (4) similarly, what is more likely to be bug free: a service that is fully tested by webMethods (I hope) and is used in several IS environments OR a service that you/me/whoever creates for a single integration environment?

    Having said that, here are MY PREFERENCES:

    1. For concatenating 2 strings: use pub.string:concat
    2. For concatenating 2 strings with a delimiter in the middle or 3+ strings with or without delimiters: use pub.string:makeString
    3. For concatenating multiple strings in a more complex format: use pub.string:messageFormat

    Good luck!

    • Percio

    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 23.  RE: String concatenation questions

    Posted Thu April 06, 2006 08:39 PM

    All,

    I noticed in this entire thread, no one suggested that concatenation can also be done via variable substitution. Ie. setting the value of a string variable to %strVar1%%strVar2%%strVar3%, for example, then checking the “Perform Variable substitution” box.

    I am NOT saying this is the way to go, but I figured I’d bring it up just to see what you guys thought of this approach.

    • Percio

    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 24.  RE: String concatenation questions

    Posted Thu April 06, 2006 08:46 PM

    Thankyou so much for ur response, I will do this.
    Bye and have a gr8 day


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 25.  RE: String concatenation questions

    Posted Thu April 06, 2006 08:49 PM

    Percio, a very good point. We can even do the string concatination using variable substitution. This even reduces the steps in the service.
    Jay.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 26.  RE: String concatenation questions

    Posted Thu April 06, 2006 08:49 PM

    Stepheny,

    I meant to tell you: for your scenario I’d use pub.string:makeString and map string1 to elementList[0], string2 to elementList[1], and set separator to +++. Please note that this will only place +++ after string1 if string2 exists, and vice-versa. I’m not sure if you always want the +++ to appear or not. Let me know if you do. :wink:

    • Percio

    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 27.  RE: String concatenation questions

    Posted Thu April 06, 2006 09:03 PM

    Percio,

    Thanks for jumping in…

    Ofcourse we can do using with variable substitution but what if the string has null or empty value,so sometmes to avoid this risk we have to go with conditional mapping and use built-in or custom services for a successful map.

    Please ignore if my statement is not valid.

    Also with 2 concat services or makeString can do the job in this case.

    PS:PSUtilities package also provides multiConcat java service,which serves the purpose.

    HTH,
    RMG


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 28.  RE: String concatenation questions

    Posted Thu April 06, 2006 09:14 PM


  • 29.  RE: String concatenation questions

    Posted Thu April 06, 2006 09:44 PM

    RMG,

    I was not suggesting that variable substitution was the way to go. I was just bringing it up because I was surprised I hadn’t seen anyone mention it in this long, long thread. Personally, however, I greatly prefer the use of built-in services such as concat, makeString, and messageFormat, as indicated in my initial post.

    • Percio

    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 30.  RE: String concatenation questions

    Posted Thu April 06, 2006 10:03 PM

    Thanks Percio,got it.
    Actually variable substitution has some disadv as metioned above,so i thought its not worth in this muticoncat case and avoided posting it initially.

    RMG.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 31.  RE: String concatenation questions

    Posted Fri April 07, 2006 02:23 PM

    WOWWWWWW…This is really great. I tried it and worked and its so simple and just one step.Thank you for ur suggestions.
    Have a gr8 day.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 32.  RE: String concatenation questions

    Posted Fri April 07, 2006 02:36 PM


  • 33.  RE: String concatenation questions

    Posted Fri April 07, 2006 02:41 PM

    Actually i can put any operator i want to.
    Just something in between 2 strings. Might be +++ or — or anything.
    So in in place of string1 i put %string1%+++
    and string 2 i put %string2%
    and concatinated that.
    And i have string1 and string2 definitely.
    Thank you


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 34.  RE: String concatenation questions

    Posted Mon March 26, 2007 09:14 AM

    A one more approach for concatenating many no. of string variable is writing java service which accepts an document as input. You should create a document in the flow service and create the input variables required to concatenate. The java service will read the variables from the document and then concatenate it.

    I created the custome service which also trims and uses a separator also. It is not dependent on fix no. of inputs.

    Please find the code snippet below for the service.

    IDataCursor idcPipeline = null; // cursor for accessing service pipeline
    IDataCursor idcConcatDoc = null; // cursor for accessing service pipeline
    //-----------------------------------------------------------------------

    IData concatData = null;
    String separator = null;
    String trimRequired = null;
    String keyName = null;
    String value = “”;
    String output = “”;
    int size = 0;
    int count = 1;

    boolean sizeFlag = false;

    try {
    // reading input and initialization begins
    idcPipeline = pipeline.getCursor(); // accessing pipeline

    if (idcPipeline.first("concatData")) {
    concatData = (IData) idcPipeline.getValue();  // retriving actual document from pipeline
    } else {
    output = "";
    idcPipeline.insertAfter("value", output);
    idcPipeline.destroy();
    return;
    }
    if (idcPipeline.first("separator")) {
    separator = (String) idcPipeline.getValue();  		
    }
    
    if (separator != null) {
    separator = separator.trim();
    } else {
    separator = "";
    }
    if (idcPipeline.first("trimRequired")) {
    trimRequired = (String) idcPipeline.getValue();  				
    }
    
    if (trimRequired != null) {
    trimRequired = trimRequired.trim().toUpperCase();
    } else {
    trimRequired = "FALSE";
    }
    idcPipeline.destroy();	
    idcConcatDoc = concatData.getCursor();	// cursor to concat document	
    
    // Main Logic
    while (idcConcatDoc.next()) {
    
    if (!sizeFlag) {		// Issue with size method is that, it puts cursor at 
    // last and also if we use idcConcatDoc.first() and then idcConcatDoc.next()
    // cursor will skip to position 2. Hence we are maintaining a flag for this.
    size = IDataUtil.size(idcConcatDoc);	
    idcConcatDoc.first();
    sizeFlag = true;
    }
    
    value = IDataUtil.getString(idcConcatDoc);	     // get the value for the current key as String	
    if (value == null)
    value = "";		
    
    if (trimRequired.equals("TRUE") && value != null) {
    value = value.trim();
    } 
    if ((separator != null || separator != "")){
    if (count < size) {
    
    value = value + separator;
    }
    }		
    output = output + value;
    value = null;	
    count++;
    }
    idcPipeline.insertAfter("value", output);
    

    } catch(Exception e) { // main try catch

    	idcPipeline.destroy();		
    throw new ServiceException("Error in concatAll service " + e.toString());
    
    }  // end catch
    

    //-------------------------------------------------------------------------


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services