cancel
Showing results for 
Search instead for 
Did you mean: 

need to generate "n" number of files if value of a field say "B" is "n"

Former Member
0 Kudos

Hi,

I have a Proxy to file scenario,where I need to generate "n" number of files if value of a field say "B" is "n".

My source structure is :

Source

A

B

C

Source

How can I do it,all the rest field values will be same in the all the files ,except 1 filed which will increase from 1 to "n" from 1st file to last file.

Regards,

Sri

Edited by: sriparna on Feb 27, 2012 11:28 AM

Edited by: sriparna on Feb 27, 2012 11:28 AM

Edited by: sriparna on Feb 27, 2012 11:29 AM

Accepted Solutions (0)

Answers (4)

Answers (4)

gagandeep_batra
Active Contributor
0 Kudos

hi,

I think this can be done by OS commands at target System.

First you copy that file on target System using file adapter.

then by batch file copy that file and update file with value of b.

logic is like below

B=read_file(file1); // this function read value from file1 and return to B

for(i=1;i<=B;i++)

{

copy_file(file1,(filei)); // copy the old file with new name filei

update_file((file+i),i); // update with value of i.

}

Regards

Gagan

Former Member
0 Kudos

The simple solution to your problem is create an UDF and pass the input of field B to udf and return the output as many times as the value of B and map the output of this udf to your target field.

e.g. for(int i = 0; i< B ; i++)

return "";

Former Member
0 Kudos

Hi Sarvesh,

The issue is I need two files for value of B=2(in 1st file B=1,in 2nd file B=2 ),three files for B=3.....

And if I put split by value after udf.....it will not create diff files

Former Member
0 Kudos

Map the udf to target's parent node without using split by value function to generate 'n' number of nodes.

it could be something like this..

Source (change the context to higher level) --- UDF --- Parent Node.

Former Member
0 Kudos

Hi Sarvesh,

Even this isn't working.

my target is:

MT_abc

node1

A

B

C

Now I created a udf as u told:

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

return "";

and mapped it to the target node field....but it only created 1 node1....

rajasekhar_reddy14
Active Contributor
0 Kudos

Duplicating traget structure will not work in your case ,as Sourab suggected use 1.n multi mapping and have to write logic to repeat target structure depending on,but it is bit tricky.

Former Member
0 Kudos

Yes,I am not able to make the tricky thing out ..........its a bit new for me!!

Please help me find the solution!

Former Member
0 Kudos

Dear Sriparna

Following is your problem description

You need to create as many files as the number of times the field "B" comes in the source structure

You can create a multimapping (1:n)

Sourabh

Former Member
0 Kudos

Hi Sourab,

But how do I put different values in field "B" on target side.For first file value of B will be 1,for 2nd it willl be 2 ...and so on depending on value of "n" in source field B???

Regards,

Sri

Former Member
0 Kudos

Can it be done without BPM?

rajasekhar_reddy14
Active Contributor
0 Kudos

You dont required BPM,

using UDF we can write this logic(but not sure,trying)will let you if i found solution.

Former Member
0 Kudos

OK...thnx!!

Former Member
0 Kudos

It can be done without BPM, If all you need is to read the inbound structure and based on a filed you need to replicate the structure , you can use java FileStreams .

Regards,

Krishna

Former Member
0 Kudos

Dear Sriparna

Make one thing clear

is it like the number of time field B appears in the source structure, you have to create same number of files

or

It is the value inside the Field B (1,2.....n) that many times you have to create the target file

Option 1 is easy one and you do not need a complex logic for that.

Option 2 you can use the node fucntion Use One As Many, where you pass the value of B to that input whch accepts the number of times a node is required to be repeated.

Let me know if I got your requirement correctly

Sourabh

Former Member
0 Kudos

Hi Sourabh,

Thanks for the reply and help..My case is the second one.

If I use 'use one as many' ...then the value of B wil be same in all the nodes on target side,but I want it to work like below:

if say B=2,

then I need 2 files,

one with all values as in source,and value of B=1

second file with all values as in source,and value of B=2...

As I am using a file adapter,I need these two different files based on B's value...It will change to 3 files,if B's value is 3......

Regards,

Sriparna

Former Member
0 Kudos

Dear Sriparna

In that case create a UDF where you take the input as B

Run a for loop (for i=0;i<=(Value of)B:i++)

{

here create source node of file (something like ouput1.addValue(" ") )

and pass the value of B<i> to the next output which is mapped with the target structure's B

}

Let me know if creating this UDF is solving your problem

Sourabh

Former Member
0 Kudos

Hi Sourabh,

I am sorry ,but didnt get this point:

{

here create source node of file (something like ouput1.addValue(" ") )

and pass the value of B to the next output which is mapped with the target structure's B

}

can u explain it a bit clearly,...better in a graphical step by step way..if u can ..please!

Former Member
0 Kudos

Dear Sriparna

First step is to create a UDF (user defined function). Create One input and create two output varaibles for this UDF.

It will have two objectives

1. to create source node of the target message (output1_

2. to create the node B for the target side

As per your requirement you need to create the Source Node of the target message as per the value of B ( if 2 then two source nodes at target)

In the UDF take B as input

int b = B[0];

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

{

output1.addValue(" "); //you need to map this out put with the source node of your target

output2.addValue(i+1); // this field should be mappoed with the field B of target

}

Hope this clears your confusion

@ gagan: for a requirement like this handling the logic in mapping is the right way to do, I dont think we should go for OS commands

Former Member
0 Kudos

Thanks Sourabh,I will try on this....but another confusion ...if my target strc is like this:

MT_1 (this message type has occurence 1)

abc (it has unbounded occurence)

df

Then,should I map 1st output to MT or my absac field for generating diff messages???

Former Member
0 Kudos

Dear Sriparna

Map first ooutput to MT_1

I hope you have already defined the occurance (1 to unbounded) in the operation mapping

Sourabh

Former Member
0 Kudos

Hi Sourabh,

I have done it,but issue is on sender side I have an idoc.....delvry05....and if I change occurence of sender MT,the source structure also changing with two more node Messages,and Messages1.....

In case of Idoc,how will I get input in such struc from SAP??

and also delvry05 has occurence1...so how do I map a filed B in it to MT,which has become 1 to unbounded,...I tries using "use 1 as many",..but it ddnt work...........

Former Member
0 Kudos

Dear Sriparna

You dont have to worry about the change of structure which you see in your source side, it is just an interpretation in the mapping and will not impact the idoc Delivery05.

You dont have to change the occurence of Sender MT.

Only in operation mapping you need to modify the occurence of target. Please have a llok at the multi mapping done in link below

http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/3115

I think you were using the UDF instead of one-as-many function, as this node function will not solve your purpose.

Sourabh