cancel
Showing results for 
Search instead for 
Did you mean: 

Number of Target segments to be created based on source field length

Former Member
0 Kudos

Hi Gurus,

I have a special requirement .

The number of target segments should be created based on the source field length .

To be more precise on the requirement I have the source segment S and under that I have the field S1 . On the target side I have segment T and under that I have the target field T1 . Occurence of T segment is 0 to unbounded.

If the length of S1 is < 50 then only one T segment should be created and the S1 value should be appeared in T1 .

For eg. If the length of S1 is 110 characters long then T segment should be created 3 times and first occurence of T1 should have the first 50 characters and second occurence of T1 should have the characters from 51 to 100 and the third T1 should have the characters from 101 to 110 . Also the min length of S1 is 0 and max length is 500 . Can anyone help me out .

Thanks & Regards,

Sarat

Accepted Solutions (1)

Accepted Solutions (1)

former_member187339
Active Contributor
0 Kudos

Hi Sarat,

You need a udf for this.


inputfield --> UDF--> outputfield



Advanced udf on queue mode

String output =null;

for (int i=0;input.length;i++) {
  if (input<i>.length()>0){
     if (input<i>.length()<50)
      result.addValue(input<i>);
     else{
         for (int j =0; j<input<i>.length();j++) {
            result.addValue(input<i>.substring(0,50);
            input<i>= input<i>.substring(50, input<i>.length());
         }
        result.addValue(input<i>);
     }
  }
}

PS: I have not tested the code there might be some syntax error

Regards

Suraj

Former Member
0 Kudos

Hi Suraj,

Thanks for the reply . But S1 occurs only once and the key here is to create the T segments based on the length of the S1 field . Can you please tell me how can we acheive this .

I used the mapping -

S1-length---divide (constant[50] given as 2nd argument) -


> output value number of times I have to create the T segment . How can we achieve this ? And in each corresponding T segment I should have the corresponding values in T1 , T2 , . . . depending on the length of S1 .

Regards,

Sarat

former_member187339
Active Contributor
0 Kudos

Hi Sarat

IF your target like this:

Tsegment

-T1

-T1

-T1

then use a mapping like this

S1> myUDF> T1

Regards

Suraj

Former Member
0 Kudos

Hi Suraj,

My Source structure is

S 0..unbounded

S1 1..1

My Target Structure is

T 0..unbounded

T1 0..1

How can I generate T segment based on S1 value . Eg. How can I generate T segment 3 times when the S1 field is of length 110 ?

former_member187339
Active Contributor
0 Kudos

Hi Sarat,

You can use the same udf to create both T and T1, so do the mappign like this:

S1>UDF>T

S1>UDF>Splitbyvalu-->T1

Try this it should work

Regards

Suraj

Former Member
0 Kudos

Hi Suraj,

Thanks its working!!!

Regards,

Sarat

Former Member
0 Kudos

Hi Suraj,

A small correction in the udf that you gave -

for (int i=0;i<input.length;i++) {

if (input<i>.length()>0){

if (input<i>.length()<50)

result.addValue(input<i>);

else{

for (int j =input<i>.length()/50; j>0;j--) {

result.addValue(input<i>.substring(0,50));

input<i>= input<i>.substring(50,input<i>.length());

}

//result.addValue(input<i>);

}

}

}

This is working correctly !!! Thanks once again for the help.

Regards,

Sarat

Answers (0)