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

Splitting Flat Files

  • 1.  Splitting Flat Files

    Posted Fri December 02, 2005 08:30 PM

    Hi Experts,

    I hope you can help. :slight_smile: I have a flat file that comes in from the mainframe. The layout looks like this:

    H<header>
    E<email>
    S<subject>
    B<body>
    B<body>
    A<attachment>
    A<attachment>
    A<attachment>
    E<email>
    S<subject>
    B<body>
    B<body>
    A<attachment>
    A<attachment>
    A<attachment>
    T<transid>

    I need to split the file in multiple files so I get something like this:

    File1:
    E<email>
    S<subject>
    B<body>
    B<body>
    A<attachment>
    A<attachment>
    A<attachment>

    File2:
    E<email>
    S<subject>
    B<body>
    B<body>
    A<attachment>
    A<attachment>
    A<attachment>

    And save the files into another directory. Anyone has an idea if this is possible?

    Thank You,
    Sebastian


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


  • 2.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 02:53 PM

    Sebastian,

    After getting the file from mainframe, use pub.string:tokenize and specify the delimiter as ‘E’ and you’ll get a value list.In your case, you’ll have 3 entries in the value list.check the starting character of each entry in the value list and if it starts with ‘E’, write the value list entry to a file.

    HTH
    ramesh.


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


  • 3.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 05:08 PM

    Hmm, it didn’t work too well b/c when I put in “E” as delimiter then if for example the email address has an “E” within then it is not processed correctly. How can I determine the delimiter as this first character only?


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


  • 4.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 06:39 PM

    I don’t think the flat file adapter can accomplish what you want. Why is the email coming as a flat file? Can you not send the email directly to Wm and then use the SMTP services to get the contents and so forth.


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


  • 5.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 07:08 PM

    Actually what Ramesh propose would work great b/c I am trying to divide the content of the flat file into pieces and then save it back into to text file. I guess what I am looking for is a regular expression that I can put in the delimiter that will searche for an “E” in the first string only of each line. Can we use regular expression as delimiter? Any one knows what this Regular Expression should look like? Many THanks!


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


  • 6.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 07:12 PM

    correction: it will search for “E” as the first letter in the first string of the line.


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


  • 7.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 08:15 PM

    I tried: /[1]/ and ^E but these are no good b/c they look into all strings of the given line.


    1. Ee ↩︎


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


  • 8.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 08:26 PM

    This may not be the most elegant approach, but it will work. You will need to fill in the details yourself. Read in the file contents, convert them to a string and tokenize the string. Loop over the resulting list of values and look at the first character of each (you can use pub.string:substring). Do nothing for H and T and append all others to a new string list. If the first character is E, increment a counter. If it’s not the first iteration, use pub.string:makeString on the new list and drop the new list variable. Write the resulting string to a unique file name. Do one more write after your loop to catch the last iteration. Hope this helps,

    Tim


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


  • 9.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 09:14 PM

    you could also try

    E<

    as your expression… It should work


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


  • 10.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 09:30 PM

    I. Monzon,

    That is almost perfect but now what happened: in the valueList the white spaces between the strings were removed and the capitol "E"s were removed from other strings. Other than that that would work perfectly. Should I add something to it?

    Thanks!!
    Sebastian


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


  • 11.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 09:45 PM

    It appears from your original post that the file comes in with some kind of carriage return or newline character between each line. If this is true, you can use the tokenize service without specifying a delimiter and it will give you a string list with each line as a separate element. You can then manipulate this list in a variety of ways to get what you want. If this is not the case, and the lines are not of fixed length, then it will be more difficult to parse the text.

    Tim


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


  • 12.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 09:48 PM

    Tim,

    Yes, the FlatFIle has carriage return on each line. If I tokenize without specifying a delimiter how can I then divide the file?

    Thanks,
    Sebastian


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


  • 13.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 09:50 PM

    Sebastian,

    I think you cannot use regex as a delimiter.sending a sample flow.

    HTH
    ramesh.


    splitFile.zip (5.8 k)


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


  • 14.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 09:56 PM

    Sebastian,

    Forgot to mention a point.edit the psutilities config file and specify the allowed path string.let me know if you have any problems with the flow i sent.

    ramesh.


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


  • 15.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 10:01 PM

    You can loop over the list of values and do several different things. In the service I described earlier, I took the substring of the first character of each value, stored it in a variable and branched on its possible values. I was able to produce the output you require.

    Tim


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


  • 16.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 10:07 PM

    I dont think you can use regular exp as the delimiter for the tokenize service.i tried using E< as Gordon suggested, but that checks for ‘E’ in the middle of the string also.i think what sebastian wanted was to check only at the beginning of the string.
    correct me if i’m wrong.

    ramesh.


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


  • 17.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 10:25 PM

    Any text specified as the delimiter will have all occurrences of this text removed by the tokenize service. If this is undesirable, as appears to be the case here, then it’s better not to specify a delimiter and let tokenize split the file into values that can be manipulated.

    Tim


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


  • 18.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 11:05 PM

    Try this,

    Pub.string.replace - replace E< by ***E<
    Tokenize on ***

    you can use anything like *** as replacement separator.
    Just make sure that you makeit as unique as possible, something like
    SEBASTIANSEPARATOR or SSSSSSEBASTIANSSSSS, you get the Idea
    It is the simpler way even thought It is not very polished.

    You could also try to work with pub.string.indexOf to get position for your ocurrences and then work with a pub.string.substring before writing to file… but I think the above approach is a good workaround.

    hth


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


  • 19.  RE: Splitting Flat Files

    Posted Mon December 05, 2005 11:14 PM

    Try replacing E<email> by ***E<email>

    and then follow as I explained
    This should get rid of your capital letters problem.


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


  • 20.  RE: Splitting Flat Files

    Posted Wed December 07, 2005 02:13 PM

    I put ~E as separator and works perfectly. Thank You guys!


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


  • 21.  RE: Splitting Flat Files

    Posted Wed December 07, 2005 02:25 PM

    Sebastian,

    So, it worked when you changed the delimiter to ~E for the tokenize service.I think it’ll work only if there is no ‘E’ in the middle of the string.I tested it with the following input to tokenize service:
    Hheader
    Etest1@gmail.com
    Ssubject
    Etest2@gmail.com
    SsubEject.
    But it gave 4 valueList entries because there is a ‘E’ in the last S entry.
    Let us know the solution you got so that it’ll help others in future.

    ramesh.


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


  • 22.  RE: Splitting Flat Files

    Posted Wed December 07, 2005 02:42 PM

    I mean yes you are correct. I meant to say I used “~” as the delimiter, updated the mainframe file and I get the tokens correctly. I hope the ~ change gets approved. :slight_smile: If not I will have to look for another solution.


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


  • 23.  RE: Splitting Flat Files

    Posted Wed December 07, 2005 04:41 PM

    If the change to ‘~’ as the delimiter is not approved you can still use the file as it is. When you call the tokenize service you would either not set the input for delimiter or set it to nothing. Ramesh’s service has an example of doing this. Glad you got it working.

    Tim


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


  • 24.  RE: Splitting Flat Files

    Posted Wed December 07, 2005 04:51 PM

    Thank You all for helping me out! I have learned a lot. FYI: This is my first webMethods project. Many thanks again!


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


  • 25.  RE: Splitting Flat Files

    Posted Wed December 07, 2005 09:23 PM

    I ran into one problem I will have to give up the “E” if I want to use the “~”. I would need the E or the ~ after tokenizing. Is it possible to retain the delimiter after split?


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


  • 26.  RE: Splitting Flat Files

    Posted Wed December 07, 2005 09:53 PM

    After all got the ~E approved so I am good to go. Thank You!


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