SFTP cleanup job is done by the Infrastructure team in most of the organization, I have implemented an interface in SAP PO to automate the manual task.
I have developed an asynchronous loop back interface in SAP PO and written a java function to open SFTP connection and look for files, delete them and return the deleted file names to the source system.
Here the source and target are same that is why i call it Loop back interface. Also, interface acts like synchronous even though i will be creating Asynchronous service interface.
SAP ECC will make a call to SAP PO via Proxy so we will be developing 2 Asynchronous service interface in SAP PO. Also, the same is generated in SPROXY and used in the ABAP class.
data type and message type is created with below fields in SAP PO
In the SAP ECC we have created a custom table and generated table maintenance so that anyone can add, modify data in the ECC
Below are the description of each column name for the above table.
SFTP Server ID: in the SAP PO value mapping we will be maintaining SFTP server connection parameters
Sequence: Order in which ABAP program will process
Active indicator: if we do not want to delete file from the directory then set to “N”, ABAP will ignore the row.
FileName: it’s like filename mask in SAP PO file and SFTP adapter, i.e. only files starting with the name has to be deleted leaving other as it is.
Retain days: This parameter says only files older than n days must be deleted no new file should to be deleted.
Min no of files: this parameter says if there are 200 old (7 days old) files in the SFTP server then only 190 files must delete keeping 10(that too the new one among 200 files) in the sftp directory
Account name: SFTP account name
SFTP Server ID(ZESERVERID) is the key element here. with the key value, value mapping api is called in the java program and the SFTP connection parameters are retrieved.
We can add multiple parameter details here.
As in the screenshot above, create a value mapping for SFTPConnection with server and Value. In my scenario, Request coming for SFTPconnection from ECC has got server ID as 1 and will fetch subsequent parameters maintained for the mentioned ServerID.
server_1_xxxpart, xxxpart is SFTP username, this has to be hardcoded and the JAVA program will pick the password for the user name to establish connection.
Below is an example on how to add additional connection parameters.
Source agency value for the value mapping table is all taken care by the java program.
strKeyValue is holding server id coming from ECC which is being passed as a source agency & source scheme to fetch target agency & target scheme value.
An ABAP program is developed which access the custom table, forms the source XML structure with the table value and invokes service consumer (SI_SFTP_Hsekp_Async_Out) proxy.
When the report is executed Service Consumer is invoked and the request XML can be viewed in SXI_MONITOR.
Once the request reaches SAP PO, JAVA mapping will execute and based on the request value SFTP connection will establish during mapping runtime, finally files will be deleted and the response structure will be created with the deleted file names.
When the response is generated by the java program it invokes Inbound Service Interface (SI_SFTP_Hsekp_Async_In) proxy and the result is sent back to SAP ECC, Again the ABAP program will read response and log the results in the SLG1 log.
- ZECRDT is file creation date in the SFTP server
Finally entire log is displayed in the SLG1, anyone can view SLG1 logs in SAP ECC.
We have created a batch job to run the report everyday at certain time, the entire process is now automated and the deleted files are visible in the logs.
The entire java mapping program can be found in my GitHub repository.
If you are creating exactly same source and target data type (as described in this blog) in the ESR, make sure you maintain the correct namespace (highlighted in the above screenshot).
Below are some of the benefits of developing interface in SAP PO.
- Major benefit of this interface is, it deleted 309 files and logged them in just 42 seconds that too from different directories and without configuring SFTP adapter in SAP PO.
- Multiple server path can be maintained in the SAP custom table.
- Any number of servers can be configured without changing java program.
Note: I have not added ID objects configuration in this blog post because they are simple ones with 2 SOAP adapter(XI protocol) and only one business system so no configuration is needed.