cancel
Showing results for 
Search instead for 
Did you mean: 

Query for 1:N mapping

Former Member
0 Kudos

Hi Experts,

I have a scenario where first I create a single file form IDoc and then this single file has to copied to 10 different folders on the same server. There is no change in data, I just have to copy the source file. I have issues with the second phase.

The requirement is:

1) The target directories are different with country code as part of path "/server1/appl1/<country code>"

2) the final target filename also contains the country code i.e. materialmaster_<country code>_<current year>.txt

The challenges are :

1) I don't have country code and year as part of my target structure, so can't use variable substitution

2) Since the source file doesnot have the country code I cannot use ASMA in sender and receiver channel.

3) My server is PI 7.1 so I tried to use Integrated configuration, but I cannot add multiple interfaces in reciever.

The simplest way out I know is to create 10 files with country code as part of filename in the 1st phase. In 2nd phase have 10 different sender channels and 10 reciever channels and use ASMA in both.

Is there any other way by which we can achieve this.Please suggest.

Thanks,

Pragati

Accepted Solutions (0)

Answers (3)

Answers (3)

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Pragati Divekar,

I understand your scenario as; 1) IDOC to file 2) that file has to be copied into 10 different folders.

1) You can split it into 11 scenarios, First scenario will be IDOC to file (to TargetLocation1 folder), rest of the scenarios will copy that file 10 folders (but catch here is; only one file should be there in TargetLocation1). Monitoring and alerting infrastructure of PI can be leveraged using this method.

2) As suggested by Raveen Gujjeti, it can be done using "Run Operating System Commands After Message Processing". If script fails for some reason, SAP PI infrastructure will not come to know. [Link1|http://help.sap.com/saphelp_nwpi711/helpdata/en/44/556cb799c93677e10000000a114a6b/frameset.htm] [Link2|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/10392] [original link is broken]; [Link3|http://wiki.sdn.sap.com/wiki/display/XI/SAPXIFileAdapterOSCommandLine+Feature]

The logic in script (.bat file on Windows system / .sh file on UNIX system / .class file OS independent(I recomend this)) should be like below code. You may tweak below code, compile it and place the .class file in com/script (create a "com" folder in it "script" folder) in TargetLocation1 folder. Note: Java Path should be set in target server. In receiver file channel in "Run Operating System Commands After Message Processing" type like this java com.script.CopyTo10Loations %F

package com.script;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CopyTo10Loations {

    public static void main(String[] args) {
        FileInputStream fileInputStream = null;
        FileOutputStream fileOutputStream = null;
        try {
            //Declaration
            String[] Folders = {"c:/desktop/raghu/India", "c:/desktop/raghu/Pakistan", "c:/desktop/raghu/USA"};
            String[] CountryCode = {"IND", "PAK", "USA"};
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");
            String strYear = dateFormat.format(new Date());

            //Getting file content into a String
            fileInputStream = new FileInputStream(args[0]);
            byte[] b = new byte[fileInputStream.available()];
            fileInputStream.read(b);
            String strFileContent = new String(b);

            //Coping strFileContent to 10 different locations
            for (int i = 0; i < Folders.length; i++) {
                fileOutputStream = new FileOutputStream(Folders<i> + "materialmaster_" + CountryCode<i> + strYear + ".txt");
                fileOutputStream.write(strFileContent.getBytes());
            }
            fileInputStream.close();
            fileOutputStream.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Regards,

Raghu_Vamsee

Former Member
0 Kudos

Hi Pragati,

Can be done using multi mapping or split mapping -

1) In message mapping change the occurence of target structure to recieve multiple messages.

2) Define a global array or a hashMap and populete the array with 10 country codes.

3) Write an UDF to get the values of the Array (In your case 10 times).

4) Call this UDF in top root node of your message mapping.

5) With above stpes you will create 10 messages at receiver end.

6) Now since you have the values of country code in each receiver message, try to do variable substituion (Not sure about this)

Regards

Amol

former_member181985
Active Contributor
0 Kudos

Use script (for copying the files to different folders) in the receiver file channel.

Former Member
0 Kudos

Hi Praveen,

Thanks for the input. Can we also rename the file while copying and and you provide me some input on the script code as i have never done this before.

Thanks,

Pragati