IBM Sterling Transformation Extender

 View Only
  • 1.  WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 3 days ago

    Hello everyone, I am new to WTX. My question is, is it possible with a function to read the last line of an input file, that is, to read the entire last row to extract that information and send it to processdata or somewhere else? ty for ur time   



    ------------------------------
    Rodrigo Ricardo Pérez memije
    ------------------------------


  • 2.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 3 days ago

    It depends on how you define your type tree.  Usually the last line may contain some summary information and it's represented in the type tree.  In this case, you can drag the object to the output card and either use the Sterling adapter to write to ProcessData or write it to a file followed by a FileSystemAdapter service to write it to ProcessData.



    ------------------------------
    Rex Chan
    ------------------------------



  • 3.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 3 days ago

    Thanks for your kind response. In my case, there is a field called 'renglón' that is in a group; that's my type tree.  Is  very simple ,The file comes to me from a primary document, and I put everything into that 'renglón' field. From there, I need to see how I can extract the last line of the file.



    ------------------------------
    Rodrigo Ricardo Pérez memije
    ------------------------------



  • 4.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 3 days ago

    To extract the last line, you have to know the length of the line or you have to identify where it starts (may be some keywords).  There is ITX function to do both.  For example, the length is 80, you would just use the RIGHT function.  Here is the link for more details about the function.

    https://www.ibm.com/docs/en/ste/11.0.0?topic=functions-right



    ------------------------------
    Rex Chan
    ------------------------------



  • 5.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 3 days ago

    If your "file" type tree is just a blob object - a text item of no set length limit or any terminators defined in the type tree...
    Do you have line terminators within this text field?  How would you recognize the "line" as the last line?  This will give you clues as to how to parse with WTX functions.

    For instance, if I have the following in the text field:

    Hello, my name is Inigo Montoya. You killed my father. Prepare to die.

    Here the "delimiter" separator is a period "." and the last line might be considered "Prepare to die."  Whereas in this example:

    Did you know that the first Matrix was designed to be a perfect human world? Where none suffered, where everyone would be happy. It was a disaster. No one would accept the program. Entire crops were lost.

    Some believed we lacked the programming language to describe your perfect world. But I believe that, as a species, human beings define their reality through suffering and misery. The perfect world was a dream that your primitive cerebrum kept trying to wake up from. Which is why the Matrix was redesigned to this: the peak of your civilization. I say your civilization, because as soon as we started thinking for you it really became our civilization, which is of course what this is all about.

    Evolution, Morpheus, evolution. Like the dinosaur. Look out that window. You've had your time. The future is *our* world, Morpheus. The future is our time.

    In this example the last line can be distinguished by 2 things - there is a new line at the beginning (and possibly at the end - you'd have to look at the contents in a HEX Editor to be sure) as well as the period.  The last line here could be defined by the fact that it is it's own paragraph or just "The future is our time." which is the last sentence of the last line the way I see it - but you need to understand the business rule that you are required to replicate. 

    Either way - there are several functions you can use to get to either of these answers.

    • Define a better type tree to parse the data by defining you repeating text items into whatever makes them "lines".
    • If you leave it blob data - make use of the WORD function to make the logical separators.  If you use a negative number it will start from the end vs the beginning of the string .i.e. WORD(renglón, ".", -2) Would get the last sentence (without the trailing .) in either example.
    • You can nest functions as well to make a complex solution using functions like RIGHT, INDEX, FIND or COUNT to get to the data needed.  The functions all have some helpful hints in the designer and Rex has provided the link to online documentation as well.

    Happy mapping!



    ------------------------------
    Lisa Edwards
    Software Engineer / Subject Matter Expert
    Rainbow Data Systems, Inc
    ------------------------------



  • 6.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 3 days ago

    Hello,
    for accessing the last occurrence of the object you can use LAST key word, please refer to attached screen shot from WTX redbook.

    description of how to use LAST keyword in index

     



    ------------------------------
    Bheeshma P
    ------------------------------



  • 7.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 3 days ago

    Great suggestion - but would only work if he updates the type tree to use repeating objects that could be indexed.  He seems to indicate this is a blob text field he needs to parse. This is a handy feature to use when the data is parsed correctly.



    ------------------------------
    Lisa Edwards
    Software Engineer / Subject Matter Expert
    Rainbow Data Systems, Inc
    ------------------------------



  • 8.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 2 days ago

    Thank you for your time and your well-constructed response. In my case, it is a file like the one I have in the image. It is a file that, after some previous mappings, produces a random result, so I don't think I can put a delimiter or a reference value. I think that after the last <CR><LF>, I should extract what follows. 

    typetree
    I have a Java code that extracts the last line without any problem, but I am not sure how I could translate this code into a map: 
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    
    public class LastLineExtractor {
        public static void main(String[] args) {
            String filePath = "my/path/document.txt"; 
    
            try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
                String currentLine;
                String lastLine = "";
    
                while ((currentLine = br.readLine()) != null) {
                    lastLine = currentLine;
                }
    
                System.out.println("last line in ur file : " + lastLine);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    

    ty for the help  



    ------------------------------
    Rodrigo Ricardo Pérez memije
    ------------------------------



  • 9.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 2 days ago
      |   view attached

    A java program such as this is going to be using a line terminator to determine the reading of each line.  WTX has the ability ti set variable terminators so that the same map could be used to parse data sets originating from varying platforms and OS systems.  For example, DOS/Windows based systems typically end lines with a Carriage Return Line Feed combination - in WTX this can be referenced by the syntax shorthand of <CR><LF> or with the characters decimal equivalent in the SYMBOL function such as SYMBOL(13) SYMBOL(10) - in contrast Unix/Linux systems typically/natively just use the <LF> as line terminators. 

    If you change the input type tree to have a group of text fields that are Terminated by Variable syntax and include all possible combinations with the most likely being the default, you can then parse through the file like Java does.  AND you can use that handy LAST keyword to retrieve the last line of the file. 

    By just putting in a little effort into defining the type tree your job becomes so much simpler.

    Line group is a text field with a Variable terminator.  File is a repeating group of Line groups.  There are several ways this could be organized.  You could instead just have repeating text items in the File group and have them in an Explicit, Delimited group with the Variable Terminator as well. I tend organize for additions and enhancements.

    Variable terminator Include list...  Make sure the sub-type of the Item is Syntax.

    With this set up you can use the [LAST] key word on the Line group to get the last line in the map.  I've attached my sample type tree - however it is ITX 10 - not sure if that is compatible with your version.

    Happy mapping!



    ------------------------------
    Lisa Edwards
    Software Engineer / Subject Matter Expert
    Rainbow Data Systems, Inc
    ------------------------------

    Attachment(s)

    mtt
    FileParserByLine.mtt   6 KB 1 version


  • 10.  RE: WTX Transform extender design studio ¿Function that read the last entire row?

    Posted 2 days ago

    thank you very much lisa i gonna try   Thank you for your assistance



    ------------------------------
    Rodrigo Ricardo Pérez memije
    ------------------------------