Requirement: Multiple text files are created in a folder accessible to SAP and the files need to be periodically archived as a zipped folder.

Solution: The problem can be divided into three steps – get the files, zip into a folder and delete the files.

  1. Get the files – Call FM OCS_GET_FILE_INFO with file name and directory path and collect the data into internal table dir_list.
  2. Zip into the folder – Create an object of Class CL_ABAP_ZIP. Read data string data using READ DATASET into xstring data. The string data will refer to the source path and filename present in dir_list using OPEN DATASET.
  3. Call method ADD and move content from string into a zip folder. After all the files are added to zip folder, call SAVE method.
  4. Next step would be to convert the xstring data into binary data by calling FM SCMS_XSTRING_TO_BINARY and then save into destination by opening the file using OPEN DATASET and TRANSFER data one line at a time.
  5. Delete the files – Delete the original file by DELETE DATASET.

 

~S