cancel
Showing results for 
Search instead for 
Did you mean: 

Creating Files Dynamically based on Condition

Former Member
0 Kudos

Hi Experts,

I want to create a scenario in which I want to have N number of target files based on some condition.

Suppose I have following Source structure .

<ns0:MT_Employee_Src xmlns:ns0="urn://FileToFile_ERD">
   <Details>
      <EmpId>1</EmpId>
      <Name>Rabi</Name>
      <Designation>ABAP</Designation>
   </Details>

      <EmpId>4</EmpId>
      <Name>Satya</Name>
      <Designation>ABAP</Designation>
   </Details>
</ns0:MT_Employee_Src>

My requirement is I want to have 2 different target files based on EmpId.

And this should be dynamic that means N number of EmpId in my source will create N number of files.

Can anyone help me to solve this?

Any kind of suggestion will be appreciated.

Thanks

Rabi

Accepted Solutions (1)

Accepted Solutions (1)

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi,

Follow those steps

1) in the message Mapping go to Signature T..Outbounded.

2)later go back to main tab . you shoud create a mapping like this:

3)<EmpId>--> change the context to MT_Employee_Src. to do that press right button on the field and go to context menu option.

map this field to the proper header target structure E.X: MT_Employee_Tgt

4) doing this you will create as many target files as <EmpId> you receive.

5) map the rest of the fields

Let me know.

Rgds

RP-.

Former Member
0 Kudos

Hi All,

Thanks for your replies.

I did what ever you said.

But I did not get the target file even 1 file is not getting generated based on empId.

So can anyone please help me to do this?

Thanks

Rabi

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi All,

Thanks for your replies.

This is solved now.

You people are really great.

Thanks

Rabi

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

Rabi,

could you explain how you solved it to share the ack with other guys?

dont forget to asigns points is apply.

Rgds

RP

Former Member
0 Kudos

Hi All,

As my requirement was to create N files dynamically based on some condition so I first used 1:N multimapping without BPM.

Then I followed RP's steps.

Follow those steps
1) in the message Mapping go to Signature T..Outbounded.

2)later go back to main tab . you shoud create a mapping like this:

3)<EmpId>--> change the context to MT_Employee_Src. to do that press right button on the field and go to context menu option.
map this field to the proper header target structure E.X: MT_Employee_Tgt

4) doing this you will create as many target files as <EmpId> you receive.
5) map the rest of the fields

This is great.And this helped me a lot and finally gave solution.

I want to share one thing that I faced.

when you are doing 1:N multi-mapping then you have to change the occurrence of target .

Then your source and target structure will be changed .If you are taking the source schema from mapping then remove the extra tags those got generated due to multi mapping such as

<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">
- <ns0:Message1>

</ns0:Message1>
  </ns0:Messages>

And then use the file and it will work fine.

Thanks

Rabi

Former Member
0 Kudos

content deleted... not the good post.... oups

Former Member
0 Kudos

Hi Rabi,

Create the target structure such as you populate a seperate message payload for each detail of source. You can do it using

Multimapping by changing occurrence of target message to 0..unbounded.

Then use variable substitution for file naming. using

variable value as payload: MT_Target,1,Details,1,EmpId,1

Regards

Raj

Former Member
0 Kudos

Hi Priyanka,

I tried as you said .

But in the UDF it is showing error can't resolve the symbol under "conf".

Again I could not understand how to do configuration.

That means as I am creating files based on EmpId,so how many communication channels,Receiver determination,Interface determination I need to do.?

Any suggestions will be appreciated.

Thanks

Rabi

Former Member
0 Kudos

Hi.

You need one channel , basically if I understood you need multiples files based on XML source , so this requeriment can be solved by UDF to create dynamic files names.

Also in you CC you need to activate Advance Options Adapter Specific Message Attributes - File Name.

About UDF try this


try {
String sFileName ="";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

sFileName = valueName[0] +".txt";
conf.put(key, fileName);
result.addValue(valueName[0]);
 }

catch(Exception e)
{
return "";
}

Regards.

Lucho

PriyankaAnagani
Active Contributor
0 Kudos

Hi Rabi,

Use multimapping, change the occurrence of target message to 0..unbounded and map the target message like

empid>removecontext>sort>splitByvalueChange> UDF-->targetmessage

and write a UDF for creating filename for each empId....try with below logic for UDF. Else you can go for variable substitution as well.

String filename ="";

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

filename = var1[0]+".txt";

conf.put(key, fileName);

result.addValue(var1[0]);

And the execution type of UDF will be AllValues of Context.

Regards,

Priyanka

bhavesh_kantilal
Active Contributor
0 Kudos

Please check the Blog Multi Mapping Without a BPM. That should address your requirement.

Regards,

Bhavesh