Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Zipping in IZArc with ABAP directly on PC

$
0
0

From time to time you have to work on files that are stored in user PC, like when you're working with SOI (SAP Office Integration) for example. All operations that are done are save directly to a file which is stored on PC so if you would like to zip it with cl_abap_zip class then you would need to copy file to ABAP memory, then zip it using cl_abap_zip and then save back file to PC. Sometimes this is not the best solution, especially when working on slow connections via VPN or similar. So with help there goes cl_gui_frontend_services=>execute. This method allows you to run every file on PC directly - also a program with proper parameters. In my example I will use IZArc (it's free and fast).

So what I'm doing here is:
- passing full path to the file which will be zipped
- call cl_gui_frontend_services=>environment_get_variable to check program files directories
- concatenate file path with parameter of IZArc "-ad"
- concatenate program files directories with 'IZArc\IZArc.exe'
- check if IZArc exists with  cl_gui_frontend_services=>file_exist
- if yes then I'm executing it with cl_gui_frontend_services=>execute.

Here is the full code for such function:

 

form zip_file_on_pc using f_path type csequence
                          f_synchro
type string
                   
changing f_ziped type c.


  data: f_apppath type string.
  data: f_apppath64 type string.
  data: f_parameter type string.
  data: f_pathloc type string.
  data: f_result type abap_bool.

  f_pathloc = f_path.
  clear f_ziped.

  check f_path is not initial.

  clear f_apppath.
  f_parameter = '-ad'. "parameter for IZArc to add file
"check sytem variables for program files

  cl_gui_frontend_services=>environment_get_variable(
        exporting
          variable             = 'PROGRAMFILES'
        changing
          value                f_apppath
       
exceptions
         cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          others               = 4
          ).
  if sy-subrc eq 0.
     cl_gui_cfw=>flush(
            exceptions
              cntl_system_error = 1
              cntl_error        = 2
              others            = 3
                 ).
     if sy-subrc eq 0 and f_apppath is not initial.
"add IZArc folder and exe file to path
        concatenate f_apppath '\IZArc\IZArc.exe' into f_apppath.
     endif.
   endif.

clear f_apppath64.
"check sytem variables for program files in 64 bit
  cl_gui_frontend_services=>environment_get_variable(
        exporting
          variable             = 'PROGRAMW6432'
        changing
          value                f_apppath64
       
exceptions
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          others               = 4
          ).
  if sy-subrc eq 0.
     cl_gui_cfw=>flush(
          exceptions
            cntl_system_error = 1
            cntl_error        = 2
            others            = 3
            ).
      if sy-subrc eq 0 and f_apppath64 is not initial.
"add IZArc folder and exe file to path
        concatenate f_apppath64 '\IZArc\IZArc.exe' into f_apppath64.
      endif.
  endif.

  if f_parameter is not initial and f_apppath is not initial.
    concatenate '"' f_pathloc '"' into f_pathloc.
"add full path of file to zip to parameter -ad
    concatenate f_parameter f_pathloc into f_parameter
                                              
separated by space.
"check if program IZArc exists in first directory
    cl_gui_frontend_services=>file_exist(
      exporting
        file                 = f_apppath
      receiving
        result              
= f_result
     
exceptions
        cntl_error           = 1
        error_no_gui         = 2
        wrong_parameter      = 3
        not_supported_by_gui = 4
        others               = 5
           ).
    if sy-subrc eq 0 and f_result = abap_true.
      "if yes then execute compression
cl_gui_frontend_services=>execute(
      exporting
*        document = f_path
        application = f_apppath
       
parameter   = f_parameter
        synchronous
= f_synchro
     
exceptions
        cntl_error = 1
        error_no_gui = 2
        bad_parameter = 3
        file_not_found = 4
        path_not_found = 5
        file_extension_unknown = 6
        error_execute_failed = 7
        synchronous_failed = 8
        not_supported_by_gui = 9
        others = 10
        ).
      if sy-subrc eq 0.
        f_ziped = 'X'.
      endif.
    Else.
"if not the we check second directory
      cl_gui_frontend_services=>file_exist(
      exporting
        file                 = f_apppath64
        receiving
        result              
= f_result
     
exceptions
        cntl_error           = 1
        error_no_gui         = 2
        wrong_parameter      = 3
        not_supported_by_gui = 4
        others               = 5
        ).
      if sy-subrc eq 0 and f_result = abap_true.
        cl_gui_frontend_services=>execute(
        exporting
*        document = f_path
          application = f_apppath64
         
parameter   = f_parameter
          synchronous
= f_synchro
       
exceptions
          cntl_error = 1
          error_no_gui = 2
          bad_parameter = 3
          file_not_found = 4
          path_not_found = 5
          file_extension_unknown = 6
          error_execute_failed = 7
          synchronous_failed = 8
          not_supported_by_gui = 9
          others = 10
          ).
        if sy-subrc eq 0.
          f_ziped = 'X'.
        endif.
      endif.
    endif.
  endif.

endform.     

Article from http://abapblog.com by Łukasz Pęgiel


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>