Processing Zip Files in SAP PI/PO

This article illustrates how to handle zip files in SAP PI/PO. We will go through a demo integration scenario where zip files should be extracted and processed via an Asynchronous interface. To unzip the compressed payload, we will use the adapter module “PayloadZipBean”.

In this article, we will discuss,

  • The design of the demo integration scenario
  • Properties of adapter module “PayloadZipBean”
  • Zip file handling interface development steps in ESR
  • End-to-end iFlow configuration in Eclipse NWDS
  • Zip file processing pipeline in PRO message monitor and end-to-end interface testing

Demo Interface Scenario Overview

Each zip file contains an XML file and a PDF file; zip files are located in an SFTP server. XML file contains invoice data and the PDF is the corresponding PDF of the invoice. We need to extract each zip file from the input SFTP folder, map the invoice XML to a target XML format, and save the PDF to the target folder.

Demo scenario illustrated to show the design of the interface that processors zip files and attachments in SAP PI PO.
Zip file processing integration scenario overview

The integration strategy is to map the invoice XML to the target structure using a graphical mapping program and copy the PDF attachment to target using a Java Mapping program. I have written a separate post on how to implement the Java Mapping to handle the PDF as an attachment.

In this article, we will focus mainly on how to unzip the incoming zip file and on the integration strategy to process the different types of files included in it.

Refer to the linked article if you are interested in learning how to attach a file to an SAP business document using an ABAP processing logic.


How to Unzip Files in SAP PI/PO

The most common way to unzip incoming zip files in SAP PI/PO is using the adapter module “AF_Modules/PayloadZipBean”. You can use “AF_Modules/PayloadZipBean” to either extract the individual payloads of a zipped file or to compress multiple payloads to a zip file.

Unzip File using “AF_Modules/PayloadZipBean”

This adapter module can be used with any adapter type in SAP PI/PO, if the adapter is extendable, i.e. adapter type allows the use of adapter modules. Here is a list of adapter types in SAP PI/PO where the module chain can be implemented.

To use this adapter module for purposes of compressing and uncompressing files, we need to utilize several parameters.

Here is a list of parameters of the adapter module PayloadZipBean with their functionality and permitted values.

ParameterValuesFunctionality
zip.modezip or zipOnezip or compress the main payload
zipALLzip all payloads of the message
unzipunzip the incoming message and extract the payloads
zip.filenameKeypayloadName, payloadType, contentDescription, contentDispositionDefine how the files inside the zip file should be named. Only required for zip.mode zip.

How to Configure the Communication Channel with PayloadZipBean

To Unzip files through the sender adapter, PayloadZipBean should be assigned to the Communication Channel as shown below.

Parameter “mode” should be configured as “unzip”.


Zip File Handling Interface Implementation Guide

Now we will look at how to implement the interface that unzips files and routes the payloads to desired locations step by step.

We will first go through ESR development steps and then understand how to bring those objects together as an iFlow. To implement the iFlow, you need to have Eclipse NWDS installed.

The steps on how to implement the PDF processing part of the interface is illustrated in my previous article on attachment handling in SAP PI/PO. In this article, we will look at the remaining configuration steps.

Implementation Steps in ESR

Create Source Message Type

This will be the source Message Type for invoice XML and attachment.

Source message type for main payload and attachment
Invoice XML Source Data Type and Message Type

Build an Outbound Service Interface

Using the sender Message Type created in the previous step, develop the sender Service Interface for zip file sender.

Outbound Service interface that send the main payload with the attachment
Outbound Service Interface for Input message with an attachment

Define Target Message Types

We will create two target message types, one for invoice XML receiver and the other one for the PDF. Check out my previous post on attachment handling to learn the Message Type strategy for PDF payload.

Message Type for invoice XML: InvoiceXML

Message mapping program for main payload of the input message

Configure Two Inbound Service Interfaces

We will build two Inbound Service interfaces, one for invoice XML receiver and the other one for the PDF receiver.

Inbound Service Interface for invoice XML: InvoiceXML_Inb_Async

Inbound Service Interface for the mail payload
Inbound Service Interface for invoice XML

Inbound Service Interface of the PDF receiver is illustrated in the article on attachment processing.

Configure the Invoice XML Message Mapping and Operation Mapping

We will build a graphical mapping in the usual way to map the sender invoice XML format to the target invoice XML format. In this example, the message formats at the sender and receiver are exactly the same, therefore, the mapping is one-to-one.

Message Mapping: InvoiceXML_to_InvoiceXML

This Message Mapping program will map the main payload which is the invoice XML to target message format. In this example, it is a one-to-one map between source structure and target structure.

Graphical message mapping program for invoice XML (main payload).
Message Mapping for invoice XML

Operation Mapping: InvoiceXML_to_InvoiceXML

Operation Mapping for Invoice XML

Java Mapping I have created to handle the PDF as an attachment and its Operation Mapping configuration are illustrated in the attachment processing post.

iFlow and Integrated Configuration Development

Now that we have designed all the necessary objects in ESR, let’s configure the end-to-end iFlow in NWDS Eclipse.

Zip File Processing iFlow

end-to-end iflow in Eclipse NWDS.
iFlow Overview

Here we have the end-to-end zip file handling interface implemented as an iFlow via Eclipse NWDS.

Sender System and Sender Service Interface

The sender system is BC_TEST_SENDER and the Inbound Service Interface name is InvoiceXMLwithAttachment_Out_Async.

Sender System in attachment handling iFlow
Sender System
Outbound service interface in attachment handling iFlow
Outbound Service Interface

Zip File Sender SFTP Adapter

Sender Communication Channel is of adapter type SFTP and its name is SFTP_s_ZIP. This Channel picks up zip files from SFTP server.

Attachment sender communication channel in iFlow
Zip file sender Communication Channel

Here is how you need to configure the adapter module ZippayloadBean in the sender Communication Channel.

Payloadzipbean configured in sender adapter. parameter, mode set as unzip
PayloadzipBean adapter module configuration

Invoice XML Receiver Service Interface

Receiver inbound service interface configured in iFlow
Main payload receiver Service Interface

PDF Receiver Service Interface

PDF attachment receiver Inbound Service Interface in iFlow
Inbound Service Interface for PDF Attachment

Attachment PDF Receiver Communication Channel

SFTP_r_PDF is the SFTP receiver Communication channel that writes PDF files to the specified folder.

Receiver Communication Channel that receives the attachment configured in iFlow
PDF receiver SFTP Communication Channel

Tips and Tricks: Make sure to deactivate the option “Store attachments” in the receiver Communication Channels. Since we have two payloads in the XI message, both will be passed to the receiver Channels. By deactivating option “Store attachments” we suppress the unnecessary payload at the receiver.

Store attachments option deactivated at receiver adapter to make sure unnecessary payload is not transferred.
“Store attachments” option deactivated at receiver adapter

Operation Mapping – Main Payload (invoice XML)

Operation mapping that process the main payload configured in the iFlow
Invoice XML processing Operation Mapping

Operation Mapping – PDF

Receiver communication channel for PDF
PDF Receiver Communication Channel
PDF attachment processing Operation Mapping assigned to the iFlow in NWDS
PDF Attachment Processing Operation Mapping

Testing the Zip File Processing Interface and Its Processing Pipeline

Let’s place a zip file with invoice XML and PDF in zip file sender SFTP folder.

Sender zip file in SFTP Server

First, invoice.zip will be unzipped by the sender SFTP adapter using the adapter module “AF_Modules/PayloadZipBean”. invoice.xml will be assigned as the main payload of the XI message and PDF will be assigned to the message as the first attachment.

Content of the sender message, invoice XML and PDF attachment in SFTP sever location
Content of ZIP file: Invoice XML and PDF Attachment

Zip File Interface Processing Pipeline

Let’s look at the message processing pipeline of the Zip file processing interface in SAP PI/PO. We will go through the message processing steps using the SAP PI/PO message monitor.

Message Processing Overview in Message Monitor

zip file processing status in message monitor. one message for main payload and other one for attachment.
Zip file processing status

File Unzipped from Sender Adapter

adapter module payloadzipbean unzip the zipped content. shown in the message log of the message monitor
Adapter Module unzip the input zip file

Main Payload and Attachment in XI Message Content

Message content of the zip file in message monitor. Showing the content of the message. Main payload and attachment
XI Message content

Inbound Message Split into Two

Input zip file message split into two. one for first operation and the other for 2nd operation.
Input message split into two

Main Payload Mapping

The main payload, invoice XML, is mapped to the target invoice format by a graphical Message Mapping program.

Message Mapping program of the main payload executed. Showing in the message log of the message monitor
Main payload Message Mapping executed

Main Payload Sent to Receiver Adapter

invoice main payload receiver adapter executed and showing in the message log.
Invoice XML receiver Communication Channel

Main Payload File Created

Invoice XML created

Attachment Processed by Java Mapping

attachment processing Java Mapping executed and showing in the message log
Attachment processed by Java Mapping

PDF Payload Delivered to Attachment Receiver Communication Channel

PDF attachment receiver Communication Channel executed

Attachment PDF Saved in Receiver SFTP Location

PDF file is written to target

Now you know how to handle zip files in PI/PO interfaces, as well as understand the importance of the adapter module “PayloadZipBean” and its parameters. If you have any questions or if you implemented zip file handling interfaces in a different way, please leave a comment below.

TECH GADGETS I USE EVERY DAY

These are some of the tech gadgets I use every day. If you make a purchase through these links I will earn a small comission at absolutely no extra cost to you.

Leave a Reply

Your email address will not be published. Required fields are marked *