Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

GZIP compression in ABAP?

Former Member
0 Kudos

Hi all,

does anybody know how to create a GZIP File from

a given text string? We are on SAP_BASIS 6.20.

We saw that there are classes like CL_ABAP_GZIP

which seem to do the job, but the output seems

to be unreadable by GUNZIP.

Thanks for any suggestions.

Regards,

Rüdiger Plantiko

Migros Genossenschaftsbund Zürich

1 ACCEPTED SOLUTION

Former Member
0 Kudos

For this kind of job, I usually use fonction module :

SXPG_COMMAND_EXECUTE, to call a system command which is created by SM69.

I work great ( check permission before both SAP and Unix )

Sincerely

6 REPLIES 6

Former Member
0 Kudos

For this kind of job, I usually use fonction module :

SXPG_COMMAND_EXECUTE, to call a system command which is created by SM69.

I work great ( check permission before both SAP and Unix )

Sincerely

0 Kudos

Hi Christophe,

thanks for the quick reply. To use an operating

system command was my next plan, too. But the

class CL_ABAP_GZIP looks promissing, and, since it

avoids a roundtrip to the OS file system, I

expect a performance advantage when using it.

It seems that the class can code data using the

LZW algorithm. But to be understandable for GUNZIP,

there is a kind of "wrapping" required for the

result (this wrapping e.g. containing the name of

the compressed the file). I am currently looking

for the most simple way to afford this wrapping in

ABAP, since the recipient of my (large) zipped file

can use only the unix command gunzip to decompress

it.

Thanks and regards,

Rüdiger

Former Member
0 Kudos

I am a step forward, but don't have a complete answer yet. From the Gzip RFC http://www.faqs.org/rfcs/rfc1952.html, it is clear how to build the header of a gzip file before the actual compressed data appear. But it seams that there is a kind of trailer in an authentic gzip file which is missing in the output of CL_ABAP_GZIP. Here an example output, comparing the UNIX gzip / gunzip with the ABAP-GZIP.

A comparison shows that CL_ABAP_GZIP produces the intermediate part of the gzipped-file. To produce the header is clear from the spec. But how is the trailer

part produced????

- Rüdiger

Textkompression mit ZIP                                                                                
Komprimieren                                                                  
0000: 1F 8B 08 08  E0 89 08 42  00 03 74 65  6D 70 2E 74   ####à##B##temp.t   
0010: 78 74 00 AB  C8 4E CB 49  2C 4E 4B CC  29 CE 4E CB   xt#«ÈNËI,NKÌ)ÎNË   
0020: 42 21 8B 73  20 64 5A 36  84 4C CC 02  13 40 E5 D9   B!#s dZ6#LÌ##@åÙ   
0030: C5 29 40 99  34 2E 00 ED  71 2F B1 3C  00 00 00      Å)@#4.#íq/±<###                                                                                
Gesamtlänge:         63  Bytes                                                                                
Komprimieren mit ABAP                                                         
0000: AB C8 4E CB  49 2C 4E 4B  CC 29 CE 4E  CB 42 21 8B   «ÈNËI,NKÌ)ÎNËB!#   
0010: 73 20 64 5A  36 84 4C CC  02 13 40 E5  D9 C5 29 40   s dZ6#LÌ##@åÙÅ)@   
0020: 99 34 00                                             #4#                                                                                
Gesamtlänge:         35  Bytes                                                                                
Dekomprimieren                                                                
xkflasfalskfjalskfjalskfjaslkfjaslfkjaslfkajlfkajflaksdfjaf                   
                                                         

Former Member
0 Kudos

In the meantime, this problem has been solved. There is a new class CL_ABAP_ZIP which also computes the missing CRC32 information and therefore produces zip-files which can be processed by gunzip. Thank you Brian!

Former Member
0 Kudos

See this thread for how to do it

Best regards

Otto

0 Kudos

Appreciate how to achieve .DAT.GZ file content to read to Internal table. below is my code.

DATA:rv_file(80) TYPE c,
     v_data TYPE xstring,
     lv_length            TYPE i,
     lv_data_text         TYPE string,
     lv_message_decrypted TYPE xstring,
       lt_binary   TYPE STANDARD TABLE OF x255.


rv_file = '/ecd/evnt/processed/old/evntarz20210402031000odr3.dat.gz'.

OPEN DATASET rv_file FOR INPUT IN BINARY MODE.
IF sy-subrc = 0.
  DO.
    READ DATASET rv_file INTO v_data.
    lv_message_decrypted = v_data.

"Convert xstring to binary
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer        = lv_message_decrypted
      IMPORTING
        output_length = lv_length
      TABLES
        binary_tab    = lt_binary.

    "Binary to string
    CALL FUNCTION 'SCMS_BINARY_TO_STRING'
      EXPORTING
        input_length = lv_length
      IMPORTING
        text_buffer  = lv_data_text
      TABLES
        binary_tab   = lt_binary
      EXCEPTIONS
        failed       = 1
        OTHERS       = 2.

Final result in LV_DATA_TEXT i am seeing .GZ data but not DAT file content.
.GZ content
#####Kh`##evntarz20210402031000odr3.dat#Y#[oUJ##ss#OeyAy#UAaa#YO:1/4E*2|9n##c#Yi#&abmdE#aa#E##ueV5UI&%U##a0q#D#M+
/-?ee(o)u5L#+/-Ve#[AE##Oe#AyJ#UN"xW##o######s##C##q#1/4`p"p(R)##la$#O###3/4A#Eda,AEWpOo#.uniouG#;=;o
:#AE##Qa#aL2(#yue#-'oA##HL#Soe#Aa#,Asso{#{


I need to get below content
45353535|PACKAGING OF NORWAY|2-2-1075|WXYZ|20210345|NDXFGTDTDTDT|P|BOFA|
45353654|PACKAGING OF NORWAY1|2-2-1075|WXYZ|20210345|NDXFGTDTDTDT|P|BOFA|
45353986|PACKAGING OF NORWAY2|2-2-1075|WXYZ|20210345|NDXFGTDTDTDT|P|BOFA|