Why compress ?
Often we need to transfer heavy files between Java and ABAP applications. This is a very common case when we have Frontend WebDynPro Java application and backend is ABAP (RFCs). Most types of computer files are fairly redundant — they have the same information listed over and over again.
For example in the following XML:
Here the words “AddressBook”, “Contact”, “Name” and “PhoneNumber” are repeated many number of times. File-compression (ex. ZIP) code can help us to remove this redundancy.
How to do this in Java and ABAP?
I faced a similar issue in my application where there was a need to pass a heavy XML Strings as import parameter of an RFC function module. Another RFC FM returned a heavy XML String as an export parameter. Various compression APIs are available for Java and ABAP language. I worked with the classes in “java.util.zip” (Java side) and cl_abap_gzip (ABAP side). The zipped string from java side was passed and accepted as byte and at ABAP side it is of XSTRING data type.
Lets say we wish to transfer heavy XML String ABC from Java to ABAP, we can use the following methods:
Zip method for Java:
Unzip method in ABAP:
Zip method in ABAP: