cancel
Showing results for 
Search instead for 
Did you mean: 

Populating Header based on counter

former_member193466
Participant
0 Kudos

Hi,

I have a requirement that I have to populate the Header and LineItem based on the LineId.

example :

<Header>

<Id> 1 </Id>

<Desc>T12</Desc>

<LineItem>

  <LineId>001</LineId>

  <Value>123</LineId>

</LineItem>

<LineItem>

  <LineId>002</LineId>

  <Value>456</LineId>

</LineItem>

<LineItem>

  <LineId>003</LineId>

  <Value>789</LineId>

</LineItem>

     ....

     ....

<LineItem>

  <LineId>050</LineId>

  <Value>123</LineId>

</LineItem>

</Header>

<Header>

<Id> 1 </Id>

<Desc>T12</Desc>

<LineItem>

  <LineId>051</LineId>

  <Value>223</LineId>

</LineItem>

<LineItem>

  <LineId>052</LineId>

  <Value>451</LineId>

</LineItem>

<LineItem>

  <LineId>053</LineId>

  <Value>872</LineId>

</LineItem>

     ....

     ....

<LineItem>

  <LineId>100</LineId>

  <Value>120</LineId>

</LineItem>

</Header>

In the above sttrucure, I should populate Header again after the LineId reaches to 50.

Can some one please suggest on how we can achieve this.

Accepted Solutions (1)

Accepted Solutions (1)

former_member191435
Contributor
0 Kudos

Hi VR,

Please follow below links...

http://scn.sap.com/thread/3351104

Thanks,

Sreenivas

Answers (1)

Answers (1)

gagandeep_batra
Active Contributor
0 Kudos

You can right a UDF which add The context change after 50

you can use following logic

len= LineId.lenght;

j=0;

for(i=0;i<len;i++)

{

If(j==50)

{

add vaulue

add context change

j=0;

}

else

add vaulue

j++;

}

Regard

GB

former_member193466
Participant
0 Kudos

Hi GB,

I dont understand the above UDF..it looks like we are capturing the length of the LineId? but I am generating this value using counter.

If i dont need to use the counter, let me know if I can write a UDF where in I can store the sequence or LineId for whole mapping and populate based on the value of the same?

.

gagandeep_batra
Active Contributor
0 Kudos

Hi VR can You provide your source XML structure

former_member193466
Participant
0 Kudos

Hi GB,

below is the structure:

<Details>

<Type>abc</Type>

<amount>123</amount>

</Details>

<Details>

<Type>abc</Type>

<amount>456</amount>

</Details>

<Details>

<Type>abc</Type>

<amount>789</amount>

</Details>

<Details>

<Type>abc</Type>

<amount>281</amount>

</Details>

  .

  .

  .

  .

<Details>

<Type>abc</Type>

<amount>123</amount>

</Details>

<Details>

<Type>abc</Type>

<amount>223</amount>

</Details>

<Details>

<Type>abc</Type>

<amount>451</amount>

</Details>

<Details>

<Type>abc</Type>

<amount>872</amount>

</Details>

Here we are populating the Header based on Type and LineTem-Value is being populated from amount field.My requirement is I have to populate one Header for every 50 line items and another heder for every 50 items and so on...based on the number of the Type = abc.

can you please suggest on this.

gagandeep_batra
Active Contributor
0 Kudos

Hi VR

int len,j=0,tl;

len= var1.length;

tl=var2[0]-1;

for(int i=0;i<len;i++)

{

if (j == tl )

{

result.addValue(var1[i]);

result.addValue(result.CC);

j=0;

}

else

{

result.addValue(var1[i]);

j++;

}

}

Regards

GB

Former Member
0 Kudos

Hello,

If i understood u corectly, u want to create multiple header and its corresponding line items if type = abc??

iF YES, then check below mapping (u can ignore Record node under LineItem):

Note - In ur case change the context of Type and Amount and set it to "MT***" Name.

UDF:

Exceution type all values of a context

Input: var1 and var2

int k=0;

int j = 0;

int len = var1.length;

for(int i=0;i<len;i++)

{

if(var1[i].equals("abc"))

{

if(j==50 && k>=50)

{

j=0;

result.addContextChange();

}

result.addValue(var2[i]);

j=j+1;

k=k+1;

}

}

output of UDF: For testing purpose i am splitting header after every 2 line items.

Thanks

Amit Srivastava