IBM Sterling Transformation Extender

Sterling Transformation Extender

Come for answers, stay for best practices. All we're missing is you.


#Sterling
#Supplychain
 View Only
  • 1.  How do I count record in WTX

    Posted 11/01/09 04:52 AM

    Originally posted by: Murari Singh


    Hi All,

    I am facing problem to implement counter in WTX. I am trying to include counter number in every output record. Like COUNT function only count number of records but I want a counter function or variable to count every record even in case of group of records and put to a field in every records. Like :1,2,3,4...... and so on
    B010000001
    B020000002
    B030000003
    C010000004
    C020000005
    C030000006
    C040000007
    C050000008
    C060000009
    C0100000010
    C0200000011
    C0300000012
    C0400000013
    C0500000014
    C0600000015
    Your great help could solve my problem..
    So please reply with possible solution.
    Thanks in advance for your help.

    Regards,
    Murari
    #IBM-Websphere-Transformation-Extender
    #IBMSterlingTransformationExtender
    #DataExchange


  • 2.  Re: How do I count record in WTX

    Posted 11/02/09 07:34 AM

    Originally posted by: SystemAdmin


    Murari,

    The first part is to check or modify your type tree. Your type tree probably already has a Group defined for your records - called "Record" (or whatever, the name is not important). If you have this group partitioned into record types or if you have multiple child record types that is okay as long as you have a single "Record".

    In your map, if your output card was called "Out", your rule would be something like:
    =COUNT(Record:.:Out) + 1

    Or if your Group "Record" is partitioned into multiple child record types you would use:
    =COUNT(Record IN Out) + 1

    COUNT only gives you the count of all previous "Record"s, so you need to add 1 to include the current record.
    #IBM-Websphere-Transformation-Extender
    #IBMSterlingTransformationExtender
    #DataExchange


  • 3.  Re: How do I count record in WTX

    Posted 11/02/09 08:09 AM

    Originally posted by: NancyR


    If you are using a functional map to create these records, pass INDEX($) as a parameter. The INDEX function will pass an integer that represents the index of an object relative to its nearest contained object, counting only valid objects. So the first time the funtional map runs its value will be 1, the second time, 2, etc.

    You'll need to create an input card in your functional map that represents an integer of unlimited length. If none of your type trees has such a type you can add one. Or you can pass TEXT(INDEX($)) and use a card in your functional map that represents a text type of unlimited length. If you know the maximum number of records to be created you can use a text or integer type with a maximum size to accommodate that number.
    #IBMSterlingTransformationExtender
    #IBM-Websphere-Transformation-Extender
    #DataExchange


  • 4.  Re: How do I count record in WTX

    Posted 11/02/09 09:09 AM

    Originally posted by: Murari Singh


    Thanks for your reply...
    I tried this option INDEX($) before posting this thred and its not working in my case, bcz as I know INDEX($) only works on same level repetitive group. But in my case having many groups at different levels and repeating many times. If there is any alternative plz reply...
    #IBMSterlingTransformationExtender
    #DataExchange
    #IBM-Websphere-Transformation-Extender


  • 5.  Re: How do I count record in WTX

    Posted 11/02/09 09:54 AM

    Originally posted by: Murari Singh


    Hi Mike,

    Do you have any idea to create custom function in C for counter and use it in WTX. Actually your logic given is correct but its not working in mine case... Bcz in my case many groups repeating at various levels. So I wanted to create a custom function and use it in my project, bcz this need to be also used in different maps.

    Thanks in advance for your help...
    #IBM-Websphere-Transformation-Extender
    #DataExchange
    #IBMSterlingTransformationExtender


  • 6.  Re: How do I count record in WTX

    Posted 11/02/09 04:00 PM

    Originally posted by: SystemAdmin


    One of the things I've always liked about Mercator/DataStage TX/WTX is that it was a complete tool and I didn't have to rely on building functions in C or anything other language to make it work the way I wanted to. (That can't be said for BizTalk, which I've had to do some work in for a client recently.)

    If your type tree is organized as I suggested earlier you can easily accomplish what you want using the built-in COUNT() function or the INDEX() function as NancyR mentioned or a combination of the two - COUNT() + INDEX(). If your type tree structure really does not allow you use COUNT() or INDEX(), you could even process the output after it was generated using the RUN() command to run another map that adds your record count.

    But, if you really feel like you want to mess with creating an external C function, you can call that using the EXIT() function. Have fun!
    #DataExchange
    #IBM-Websphere-Transformation-Extender
    #IBMSterlingTransformationExtender


  • 7.  Re: How do I count record in WTX

    Posted 11/02/09 04:14 PM

    Originally posted by: Rich_McFate


    Let's assume you have two kinds of records -- B and C. Each has, as it's last element, an item called RowCount. You can probably get what you want as follows:

    BRecord = F_Map1(<arglist>, RowCountLast IN <outputcardname> + 1)

    CRecord = F_Map2(<arglist>, RowCountLast IN <outputcardname> + 1)

    (Note: assumes that RowCount is numeric.)

    If the items in each record are different, then simply change the second rule:

    Crecord = F_Map2(<arglist>, Count(Brecord:cardname) + Index($) )

    Your mileage may vary depending upon your target structure, but...

    I'm confident you won't need to mess around with custom functions. And don't even think about trying to use the GETANDSET function to maintain an external counter. It's theoretically possible, but I've never seen it work as well as alternative approaches.
    #IBM-Websphere-Transformation-Extender
    #IBMSterlingTransformationExtender
    #DataExchange