Skip to Content
Author's profile photo Gaurav Kant

PI/PO: how to get csv data from web page(via.UDF) in PI/PO

Summery:

One of the popular requirement in SDN is to download csv data from web page. For this purpose, i have written code(UDF) to download csv content from web page to SAP.

Introduction:

This blog will give you clear view how to write java code(UDF) in PI.

At sender side Customer team is updating file in their web page then PI will pick the data and send to ECC.

Business Scenario: We need to retrieve daily files from the web page and upload them into
SAP ECC using Proxy communication
.

Pre-Requisites:

Basic knowledge of PI/PO, Java etc…

Create the one more RFC Destination to connect to ECC to PI and viceversa. And specify the below details

  • Connection type: G
  • Target Host: SAP PI host
  • Service No  : SAP PI Service No
  • Path perfix : /sap/xi/adapter_plain?namespace=XXXXXXXXX&interface=XXXX&service=XXXX&qos=EO


IR Steps:

  • Create DT, MT, and SI  for the String field (having Data here).
  • Create MM and create new UDF as per the below code.

Code:

public void getDataFromCNB(String var, ResultList result, Container container) throws StreamTransformationException

{

AbstractTrace trace = container.getTrace();

String var1 = null;

try

      URL url = new URL(“http://www.abc.com/xyz.txt“);

     URLConnection uc = url.openConnection();

     BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));

     String line = null;

     while ((var1 = in.readLine()) != null)

{

result.addValue(var1);

                                   

}

in.close();

}       

catch(Exception e)

{

trace.addInfo(e.getMessage());

}

}

          Map the UDF to a data String field.


Mapping details given below in screenshot(Just for reference purpose).

Capture2.PNG


  • Create Operation mapping.

Save and activate IR part.

ID:

Go to ID part and create the Scenario name and create the sender agreement, Receiver Agreement, Receiver Determination and Interface Determination and both the channels.

Store the data in local folder and then Use file adapter to process the same as per your requirement to ECC.

Go to change list and activate all the ID objects.

Assigned tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Manoj Kh
      Manoj Kh

      Gaurav,

      Nice One.

      But i wonder why there is need of RFC destination to connect to Webpage as you are fetching the CSV file in UDF using URLConnection class. And also blog heading speaks about "Single Stack" where as RFC screenshots are of ABAP stack.

      And also try to format the UDF and also put screenshots of the mapping after the UDF execution.

      Br,

      Manoj

      Author's profile photo Gaurav Kant
      Gaurav Kant
      Blog Post Author

      Hi Manoj,

      Thanks!

      I have added the RFC destination here to avoid security breach as per our company policy. we have enabled port for the web and checked connection through RFC destination.

      Yes, Using URLConnection class it is not required as we are fetching data directly through class.

      Author's profile photo Iliya Kuznetsov
      Iliya Kuznetsov

      +1 for question about RFC destination.

      Also, the use of ad-hoc URLConnection without parametrized channels adds much of spagetti-style integration. Best practice is to use communication channels as parameters of mappings.

      Author's profile photo Julian Baldner
      Julian Baldner

      How can I do it with PDF from URL and also to convert it to BASE64 ? Thanks