Application Development and Automation 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: 
Read only

Reading a file in zip folder

Former Member
0 Likes
2,634

Hi Experts,

My requirement is to Unzip a file and to read the files in the folder and save the data to database.  Eg. the zip folder is XYZ.zip and under that X, Y, & Z files available in that I need to read all the 3 files and X, Y & Z files data should be saved in 3 different database tables.

I searched a lot in the sdn as well as in google but couldnt find any except the class CL_ABAP_ZIP(Load & get) i dont know how to use those methods.  There is no much information about reading a file in zip folder.

Every where the information is to about to zipping the file and saving ....

Can anyone plz provide me the same code or example or any links.

Thanks in advance,

Vichu

Hi Experts,

My requirement is to Unzip a file and to read the files in the folder and save the data to database.  Eg. the zip folder is XYZ.zip and under that X, Y, & Z files available in that I need to read all the 3 files and X, Y & Z files data should be saved in 3 different database tables.

I searched a lot in the sdn as well as in google but couldnt find any except the class CL_ABAP_ZIP(Load & get) i dont know how to use those methods.  There is no much information about reading a file in zip folder.

Every where the information is to about to zipping the file and saving ....

Can anyone plz provide me the same code or example or any links.

Thanks in advance,

Vichu

10 REPLIES 10
Read only

Sayan_C
Explorer
0 Likes
2,121

Hi,

Check this out.

http://scn.sap.com/thread/90072

Regards,

Sayan

Read only

Former Member
0 Likes
2,121

Hi Sayan,

Thanks for quick reply as im new im not getting correctly/clearly can you pls explain briefly or can u show any example program. 

Read only

0 Likes
2,121

Hi Vichu,

Which one is your SAP server operating systme UNIX or Windows?

Read only

Former Member
0 Likes
2,121

I have both the system.... Unix and Windows.  I mean my practice system is windows and my client system is unix.

So can you pls explain in both versions, it will be more useful for me then.

Read only

Former Member
0 Likes
2,121

Can you help me with any codes ???

Read only

0 Likes
2,121

Hi Vichu,

Please find the step as below to do unzip .

1. Set up parameter at Server Operating system side (Windows).
  1.1 open command prompt then chosse start->programs->accessories->Command Prompt
  1.2 add the winrar tools to the path then you can exeute comand anywhere.
       (in this example I use WinRar to unzip file you may use others.If it is UNIX please see GUNZIP ).
      c:\> set path="C:\Program Files\WinRAR\";%path%
  1.3 create the directory that you want to extract the files ( will get directory 'ZTARGET_DIR').
      c:\> mkdir ZTARGET_DIR.
2. Set up paramenter at SAP system.
1. Goto tcode SM69 to set external command in this example i will use WinRar to unzip file ( depend on your software).
   1.1 In Comand Box fill a comand name as  'ZUNZIP'.
   1.2 In Definition Box fill Operating system command as 'UNRAR E'.
   1.3 In Definition Box in Parameters for operating system command leave blank.


3. Execute the external command to unzip the zip file to the targert directory .


Example coding.

CONSTANTS c_command TYPE sxpgcolist-name VALUE 'ZUNZIP'.
* Where is your zip file located
data: lv_zip_file TYPE filename VALUE 'C:\ZIPDIR\INBOUND_ZIP.ZIP'.
* Where is unzip files going to be after extraction.
data: lv_unzip_file TYPE filename VALUE 'C:\ZTARGET_DIR'.
DATA lv_add_parameter TYPE sxpgcolist-parameters.
CONCATENATE lv_zip_file lv_unzip_file INTO lv_add_parameter
SEPARATED BY space.
* it will execute command as below patter .If it is UNIX please see GUNZIP command line
* 'UNRAR E  C:\ZIPDIR\INBOUND_ZIP.ZIP C:\ZTARGET_DIR'.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
  EXPORTING
    COMMANDNAME                         = c_command
    ADDITIONAL_PARAMETERS               = lv_add_parameter
*   OPERATINGSYSTEM                     = SY-OPSYS
*   TARGETSYSTEM                        = SY-HOST
*   DESTINATION                         =
*   STDOUT                              = 'X'
*   STDERR                              = 'X'
*   TERMINATIONWAIT                     = 'X'
*   TRACE                               =
*   DIALOG                              =
* IMPORTING
*   STATUS                              =
*   EXITCODE                            =
* TABLES
*   EXEC_PROTOCOL                       =
EXCEPTIONS
   NO_PERMISSION                       = 1
   COMMAND_NOT_FOUND                   = 2
   PARAMETERS_TOO_LONG                 = 3
   SECURITY_RISK                       = 4
   WRONG_CHECK_CALL_INTERFACE          = 5
   PROGRAM_START_ERROR                 = 6
   PROGRAM_TERMINATION_ERROR           = 7
   X_ERROR                             = 8
   PARAMETER_EXPECTED                  = 9
   TOO_MANY_PARAMETERS                 = 10
   ILLEGAL_COMMAND                     = 11
   WRONG_ASYNCHRONOUS_PARAMETERS       = 12
   CANT_ENQ_TBTCO_ENTRY                = 13
   JOBCOUNT_GENERATION_ERROR           = 14
   OTHERS                              = 15
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
* Now you have all uzip files in directory C:\ZTARGET_DIR then
* 1. List all file in there by function module "RZL_READ_DIR_LOCAL"
CALL FUNCTION 'RZL_READ_DIR_LOCAL'
  EXPORTING
    NAME                     = 'C:\ZTARGET_DIR'
  TABLES
    FILE_TBL                 =  IT_FILE_TBL
EXCEPTIONS
   ARGUMENT_ERROR           = 1
   NOT_FOUND                = 2
   NO_ADMIN_AUTHORITY       = 3
   OTHERS                   = 4
          .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

* 2. Loop at your list of files (IT_FILE_TBL) and
*  use command OPEN DATASET to read file to your internal table
* .Now you get them all,please apply above step to your environment.

Hope to it help.

Sayan.

Read only

Former Member
0 Likes
2,121

Hi Sayan,

Actually I will not unzip the files to anywhere through programatically i want to read the files and their contents and want to save the contents to database table.

Read only

Former Member
0 Likes
2,121

Hi Vichu,

pls. check class cl_abap_zip.

Some example could be found here: http://scn.sap.com/message/3011429#3011429

Regards

Hendrik

Read only

Former Member
0 Likes
2,121

Hi Vichu,

Check the below thread, u can have example with sample code. i think it is useful for you.

http://scn.sap.com/thread/3213437.

Read only

0 Likes
2,121

hi srikanth,

I have found the solution and its solved. 

Now the problem i am facing is how to read data in the file of a zipped file which is password enabled ??

How to read data in a password enabled file.