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.

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.

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).

In1 = DUMMY
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)

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:

Code:

=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:

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