Business requirement is like:

  • While triggering SAP-PI’s SOAP web-service from client system, zip attachments will be send along with SOAP Request Payload. Here, please note, one zip per web-service call is in scope.
  • This zip attachments has multiple CSV files, which needs to be extracted in SAP’s application directory
  • Once unzip is successful, return unzipped zip-File in SOAP-Response Message

To accomplish above business requirements, one Java UDF will be written in Request Message Mapping of SAP-PI’s respective (SOAP-to-File Synchronous Inbound) interface

Here, given example of SAP PI Java UDF (user defined function), has below functionalities:

  • To read zip attachment from Request Payload
  • Unzip attachment to one SAP application server directory
  • Using Dynamic-configuration, return unzipped zip file name

UDF Imports:

public String UnZip(String upzipPath, Container container) throws StreamTransformationException{ /* UDF to: 1. Get ZipFile Attachment (i.e. get the input attachment from the source message) 2. Unzip/extract ZipFile to SAP-Application directory 3. Set unzipped attachment name to "FileName" variable using 'DynamicConfiguration' */ //File destDir = new File("/folde1/folde2/folde3/"); File destDir = new File(upzipPath); String resultStr = ""; //To add trace info AbstractTrace trace; trace = container.getTrace(); trace.addInfo("UDF to unzip ZipFile atatchment to the directory " + destDir ); //Get the input attachment from the source message) GlobalContainer globalContainer = container.getGlobalContainer(); InputAttachments inputAttachments = globalContainer.getInputAttachments(); try { //checks for the availability of attachments in the input message if(inputAttachments.areAttachmentsAvailable()){ trace.addInfo("Attachments Available"); //Get the attachmentIds and store it in an Object array Collection CollectionIDs = inputAttachments.getAllContentIds(true); Object[] arrayObj = CollectionIDs.toArray(); String attachmentID = null; String contentIDS = ""; //Loops at the input attachments to get the content of the attachment for(int i =0;i 0) { output.write(buffer, 0, len); } output.flush(); output.close(); // End of Write each file into directory ------------------------ } zipIs.close(); } catch (FileNotFoundException e) { //e.printStackTrace(); trace.addInfo(" UnZip UDF Error: " + e.getMessage()); } catch (IOException e) { //e.printStackTrace(); trace.addInfo(" UnZip UDF Error: " + e.getMessage()); } //============================================= } } } catch (Exception e) { //e.printStackTrace(); trace.addInfo(" UnZip UDF Error: " + e.getMessage()); } //===================================================================== //Return original name of unzipped attachment (zipFile name) try { DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey key = DynamicConfigurationKey.create("","FileName"); conf.put(key, resultStr); } catch (Exception e) { //e.getMessage(); trace.addInfo(" StoreAttachment UDF Error: " + e.getMessage()); } //===================================================================== return resultStr; }//end of fn UnZip


New NetWeaver Information at

Very Helpfull

User Rating: Be the first one !