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: 

Delete a file into sap directory

Former Member
0 Kudos

Hi, expert

I posted , wich was answered, but I want to know how can I delete a file into sap directory after saved throuh T/C CG3Z?

Thanks in advance!!!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

DATA: i_physical LIKE rlgrap-filename.

  • Check file exists

i_physical = "Your File Name '.

OPEN DATASET i_physical.

IF sy-subrc <> 0.

  • File does not exist so we don't care

ELSE.

CLOSE DATASET i_physical.

DELETE DATASET i_physical.

IF sy-subrc <> 0.

MESSAGE e016(rp) WITH 'Problem deleting file: ' i_physical.

ELSE.

WRITE: 'File: - ',

i_physical,

' deleted successfully'.

ENDIF.

ENDIF.

11 REPLIES 11

former_member188685
Active Contributor
0 Kudos

using DELETE DATASET you can delete the file.

0 Kudos

Thanks for answering... Is there a FM or T/C for deleting?

0 Kudos

try Fm: EPS_DELETE_FILE

0 Kudos

Thanks Erick, I will check it and let you know.

0 Kudos

I check FM EPS_DELETE_FILE, but returns "DELETE_FAILED", what must be missing?

*FILE_NAME* T1C001
*DIR_NAME* /usr/sap/ETD/DEVG00/work

Thanks in advance!!!

Former Member
0 Kudos

DATA: i_physical LIKE rlgrap-filename.

  • Check file exists

i_physical = "Your File Name '.

OPEN DATASET i_physical.

IF sy-subrc <> 0.

  • File does not exist so we don't care

ELSE.

CLOSE DATASET i_physical.

DELETE DATASET i_physical.

IF sy-subrc <> 0.

MESSAGE e016(rp) WITH 'Problem deleting file: ' i_physical.

ELSE.

WRITE: 'File: - ',

i_physical,

' deleted successfully'.

ENDIF.

ENDIF.

0 Kudos

Thanks karthik

I've already test code lines similar yours and work, but I need to use FM because I need to make some test on QA, and we don't want to transport a program only for this.

Thank you very much for answering

0 Kudos

Did you check if you have the authorization to delete a file from that folder?

Also UNIX is case sensitive.

0 Kudos

Try this FM : FMCT_DELETE_UNIXFILE

0 Kudos

Thanks karthik, I will check and let you know.

0 Kudos

karthik thanks for your answer that solved my problem