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

delete file in Appln server

Former Member
0 Likes
830

Hi all,

Iam using following FM to retrive files in Aplln server.

OCS_GET_FILE_INFO.

Now my requirement if the length of file is 0 then i should delete the file.And Iam also submitting these files to another program for batchinput.

Kndly help me.

My code :


CALL FUNCTION 'OCS_GET_FILE_INFO'
       EXPORTING
            dir_name                  = p_path
            file_name                 = gv_filter
       TABLES
            dir_list                  = gt_files
       EXCEPTIONS
            no_authority              = 1
            activity_unknown          = 2
            not_a_directory           = 3
            no_media_in_drive         = 4
            too_many_errors           = 5
            too_many_files            = 6
            bracket_error_in_filename = 7
            no_such_parameter         = 8
            OTHERS                    = 9.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    SORT gt_files BY name.
    REFRESH gr_name.
    CLEAR   gr_name.
    gr_name-sign   = 'I'.
    gr_name-option = 'CP'.
    gr_name-low    = p_file.
    APPEND  gr_name.
      
    LOOP AT gt_files WHERE type <> 'directory file'
                       AND name in  gr_name.                      
      IF p_withp = 'X'.
        CONCATENATE p_path gt_files-name INTO gv_file.
      ELSE.
        gv_file = gt_files-name.
      ENDIF.
      REFRESH gt_params.
      CLEAR   gt_params.
      gt_params-selname = p_sfile.
      gt_params-kind    = 'P'.
      gt_params-low     = gv_file.
      APPEND gt_params.
      IF NOT p_spath IS INITIAL.
        CLEAR   gt_params.
        gt_params-selname = p_spath.
        gt_params-kind    = 'P'.
        gt_params-low     = p_path.
        APPEND gt_params.
      ENDIF.
      IF p_repid = 'Y_WM_EINLAGERN_PRODUKTION'.
        SUBMIT (p_repid) USING SELECTION-SET p_varid
                          WITH p_filn = p_path
                          WITH p_fil1 = gv_file
                    AND RETURN.
      ELSE.
        SUBMIT (p_repid) USING SELECTION-SET p_varid
                          WITH SELECTION-TABLE gt_params
                    AND RETURN.
      ENDIF.
    ENDLOOP.
In gt_files i have all the files.
  ENDIF.

6 REPLIES 6
Read only

hymavathi_oruganti
Active Contributor
0 Likes
792

delete dataset filename

Read only

0 Likes
792

Hi,

I treid with that but its not workong

loop at gt_files where len eq 0.

delete dataset gt_files-name.

endloop.

and iam getting return code 4.

Message was edited by: Sai Chand Pullepu

Read only

0 Likes
792

for delete dataset to work, the important point is the file should be of character type.

convert the file to character type and try deleting

Read only

0 Likes
792

Hi,

gt_files-name is character type only.

But the gt_files contain the following structure

NAME

TYPE

LEN

OWNER

MTIME

ACC_MODE

MOD_DATE

MOD_TIME

Read only

0 Likes
792

convert all the fields to character type and try

Read only

0 Likes
792

hi,

Thanks for spending ur time.

anyway i solved with the following code.

Thanks anyway.

LOOP AT gt_files WHERE type <> 'directory file'

AND len EQ 0.

CONCATENATE p_path gt_files-name INTO test.

CONDENSE test NO-GAPS.

OPEN DATASET test.

IF sy-subrc EQ 0.

DELETE DATASET test.

IF sy-subrc EQ 0.

MESSAGE i000(0) WITH 'file deleted'.

ENDIF.

ENDIF.

ENDLOOP.