cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Folder with File to File (XML) without Mapping

Former Member
0 Kudos

Dear Experts,

I have received a new requirement on File to File scenario.

PI has to pick a file from one network directory and place it on specific directory. Please note that there will not be any mapping as client does't want to change the file content...

File Names will be:

Partner1_001_Invoice.xml

Partner1_002_Invoice.xml

.........


Partner2_001_Invoice.xml

Partner2_002_Invoice.xml

.....


In Target System, the directories will be like following....

Partner1

---001

---002

Partner2

---001

---002

In this case, PI has pick the file 'Partner1_001_Invoice.xml' file and it should place file on following directory...

Partner1

---001

and so on...

Need help to configure the above interface....

Thanks-
Rams

Accepted Solutions (1)

Accepted Solutions (1)

praveen_sutra
Active Contributor
0 Kudos

Hi Rams,

Similar concept can be used.

hope this helps.

thanks and regards,

Praveen T

Former Member
0 Kudos

Dear Praveen,

I am trying to create java code by copying your code, however i am getting many errors. (shown on below screenshot). Could you please check and help me to resolve these?

For Instance the error is like...the import com.sap.aii.mapping.api.AbstractTransformation cannot be resolved

waiting for your feedback...

thanks-
Rams

praveen_sutra
Active Contributor
0 Kudos

Hi Rams,

you would require to perform step 3 mentioned in the blog.

  • Step 3: Right Click on Project-> Properties -> Java Build Path -> Add External Jars.

this should resolve your issue.

thanks and regards,

Praveen T

Former Member
0 Kudos

Thanks Praveen,

Now i am trying to change the java code as per my requirement. However I am unable to do it.

Is it possible to you to help me to build the java code as per my requirement? I have to pick the Root and Subdirectory from the file name and place the file with same name as it picks from the source field.

It would be very thankful if you could help me in this case.

Best Regards,
Rams

Former Member
0 Kudos

Dear Praveen,

I am able to complete the JAVA mapping.

I am using File Adapters both ends and enabled 'Adapter-Specific Attributes' with 'File Name'. Also in the receiver File Adapter i mention * in the target Directory and also on Target File Name.

I ran the interface and it is failed on receiver file adapter with following error...


File processing failed with Target directory 'T:\usr\sap\XD1\DVEBMGS68\j2ee\cluster\server0\*' does not exist and cannot be created


However in the Java Code, for time being i have passed constant Target Directory name.


Following is the code....Could you please check and help me to resolve....


String targetDir= "//intsap/intpi/XD1";

  // set the target root directory ends

  String subDir ="/";

  try {

  InputStream inputstream = transformationInput.getInputPayload()

  .getInputStream();

  OutputStream outputstream = transformationOutput.getOutputPayload()

  .getOutputStream();

  Map mapParameters = (Map) transformationInput.getInputHeader()

  .getAll();

  mapParameters.put(DynamicConfigurationKey.create("http://sap.com/xi/XI/Dynamic",StreamTransformationConstants.DYNAMIC_CONFIGURATION), "");

  DynamicConfiguration conf = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

  DynamicConfiguration conf1 = (DynamicConfiguration) mapParameters.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

  String filename=conf.get(key);

  // Setting the Directory and Filename

  conf.put(key,filename);

  conf1.put(key1,targetDir);

  // Copying Input file and writing it as Output file

  byte[] b = new byte[inputstream.available()];

  inputstream.read(b);

  outputstream.write(b);

  } catch (Exception exception) {

  getTrace().addDebugMessage(exception.getMessage());

  throw new StreamTransformationException(exception.toString());

Former Member
0 Kudos

Hi Praveen,

It's strange, i could see the directory name on Message but it is trying to put it on different folder...

however in the Audit Log...

Adapter Framework caught exception: Target directory 'T:\usr\sap\XD1\DVEBMGS68\j2ee\cluster\server0\*' does not exist and cannot be created

Please help me...

regards,
Rams

Former Member
0 Kudos

Target directory can not be '*', that is the reason why it is failing.

former_member184720
Active Contributor
0 Kudos

>>>File processing failed with Target directory 'T:\usr\sap\XD1\DVEBMGS68\j2ee\cluster\server0\*' does not exist and cannot be created


Did you also select the check box for Directory name under adapter specific message attributes in your receiver channel.


I see that you are trying to create the files under "//intsap/intpi/XD1" ? Are you sure if this directory path exists?


is it a shared drive? "//intsap" ?

Former Member
0 Kudos

Dear Kedar,

In this case, what should be there on Target Directory?

I am passing dynamic target directory from Java Mapping...

Thanks-
Rams

Former Member
0 Kudos

Dear Hareesh,

I didn't select the 'Directory' on Adapter-specific attributes.

Yes, the target directory is exists and its been using for other interfaces also...

Thanks-
Rams

former_member184720
Active Contributor
0 Kudos

>>>I didn't select the 'Directory' on Adapter-specific attributes.


Please select it. In order to use the dynamic configuration that you set in java mapping, you should select the checkboc for directory as well

Former Member
0 Kudos

From where you are getting this 'T:\usr\sap\XD1\DVEBMGS68\j2ee\cluster\server0\*' path?

What do you want in your target directory? Is there any condition based on which you will choose particular target directory out of multiple option??

Former Member
0 Kudos

Thanks Hareesh,

After choosing the 'Directory' i could see that the correct directory name on channel.

regards,

Rams

former_member184720
Active Contributor
0 Kudos

Hmm.. You may close the thread if your issue has resolved.

Former Member
0 Kudos

Hi Hareesh,

As of now, I have passed the target Directory as a constant. However as per the requirement I have get the Directory/SubDirectory names from the File Name and place the file on it...

As i am not JAVA resource, I am unable to write the logic on JAVA. It would be thankful if you could provide me some code to get the directory names from the file name....

After this i will close the thread...

Thanks-
Rams

former_member184720
Active Contributor
0 Kudos

What is your logic? You can simply add if then logic.. below for your reference.

if(filename.equals("Partner2_001_Invoice.xml") {

targetDir = "//configure your directory";

}

else if

{

}

Former Member
0 Kudos

Dears,

I have used array operation along with string operations to retrieve the target directory names from File Name...

String[] splitted = filename.split("_");

String Part1 = splitted[0];

String Part2 = splitted[1];

targetDirectory = "//" + Part1 + "/" + Part2;

config1.put(key1,targetDirectory);

thanks-

Rams

Answers (3)

Answers (3)

RaghuVamseedhar
Active Contributor
0 Kudos
0 Kudos
Former Member
0 Kudos

Here you go.

Dynamic file name in a File to File pass through scenario - Code Gallery - SCN Wiki

You can create a java mapping as per this blog. Using this option, you can create both dynamic file name and dynamic folder with some manipulations in this java code.

Regards,

Kedar