DSXchange: DataStage and IBM Websphere Data Integration Forum
View next topic
View previous topic
Add To Favorites
Author Message

Joined: 18 Apr 2006
Posts: 56

Points: 586

Post Posted: Mon Aug 02, 2010 7:00 am Reply with quote    Back to top    

DataStage® Release: 8x
Job Type: TX
OS: Windows

I am new to WTX, need help in implementing a simple recursive logic. Input 1 is a plain text and input 2 is an integer number which is fixed length. Requirement is to get an output file with lines of fixed length given in input2.

e.g. Input 1 = abcdefgh Input2= 3

I am thinking of using LEFT function recursively.. but not sure how to store the intermediate values and use it again. i.e. if I do LEFT (Input1, Input2) it gives "abc" but after tht Input1 should be "defgh".. I am not able to achieve this.


Joined: 31 Aug 2010
Posts: 1

Points: 22

Post Posted: Tue Aug 31, 2010 10:23 am Reply with quote    Back to top    

I would use the CLONE function for this.

This is quite advanced stuff, but I will try and describe how I would do this...

Your output card would need a type tree that has multiple data items in, i.e.


In the Map, you need to call a functional map at the Item(s) level with the CLONE command:

e.g. =F_create_recs ( CLONE ( "DUMMY" , 1 + (SIZE ( Input1 ) / Input2 ) ) , Input1, Input2, INDEX($) )

Your functional map will then have 4 input cards - some wont be automatically resolved and you should in the functional map wizard set it to a suitable type tree and item (must already be used in the map somewhere else).

In2 = Input1's data
In3 = Input2's data
In4 = Sequence No

In the functional map set the output as follows:

=MID (In2,1+(In3 * (In4-1)), In3)

I have assumed Input1 is a text based item and Input2 is a number based item else you may need to use TEXTTONUMBER in the CLONE/MID rules.

You may need to play with the CLONE command to ensure you get the last bit of data from the end of the file that doesnt match the record size supplied in Input2 - I have added 1 to the 'SIZE' calculation but this will be a problem for an exact number. You could use the MOD function on the SIZE of Input1 and if an exact number then dont add 1 else add 1 or use the ROUNDUP function in some way.

Basically for your example the CLONE command will run the functional map based on Input1 size and the value of Input2 - for your example it would be 1 + ( 8 / 3 ) = 3 times

The INDEX($) will pass an incrementing number for each time the function map runs i.e. 1 then 2 then 3.

DUMMY is ignored in the functional map - and can be any text you like

The MID function will then essentially do the following:
1st run of functional map
=MID (In2,1,3)
2nd run of functional map
=MID (In2,4,3)
3rd run of functional map
=MID (In2,7,3)

Hope this helps.
Rate this response:  
Not yet rated

Joined: 16 Dec 2004
Posts: 42

Points: 445

Post Posted: Tue Dec 14, 2010 12:05 pm Reply with quote    Back to top    

I haven't been on here for a while, and I know this thread isn't that new. However, I think this can be accomplish without recursion or functional maps, no offense intended at all to JorgeCox. It looks as if his solution will work, I just wanted to offer a different one.

Given that Input1 is a string "abcdefgh" and Input2 is number 3, create an output card that uses a text object in a series. In the formula for the series text field, use the following formula:

=CLONE("*" ,1 + INT( SIZE(Input1) / Input2 ) )

Now create a second output card of the same type as the first, series text object and in the series text field formula enter this:

=MID( Input1 ,1+( Input2 * ( INDEX(TextField:Output1) - 1) ) ,Input2 )

It worked successfully on my end so let me know if it works for you.

John Gibby

"Artificial intelligience is no match for natural stupidity."
Rate this response:  
Not yet rated
Display posts from previous:       

Add To Favorites
View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group
Theme & Graphics by Daz :: Portal by Smartor
All times are GMT - 6 Hours