12-08-2011 8:35 AM
Hi,
I have been trying to delete an application server XML file using the DELETE DATASET statement in my program.
The sy-subrc is set to 4 after the statement and the file is not deleted.
-> Does the delete statement not work if I dont have sufficient authorization?
( I tried uploading a file to the particular folder in the application server, and it showed up a messgae 'Permission Denied' So I guess I dont have write access to that folder )
-> Or, should XML files in specific be deleted differently?
Any insights on why this is happening and how to correct it?
Thanks in advance,
Nisha
Edited by: Nisha Hariharan on Dec 8, 2011 9:35 AM
12-08-2011 8:39 AM
Welcome to SCN,
Your question itself has the solution.
call function as below before your delete
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING PROGRAM = SY-REPID
ACTIVITY = 'DELETE' "Delete file auth object
FILENAME = pfile
EXCEPTIONS NO_AUTHORITY = 1
ACTIVITY_UNKNOWN = 2.
if sy-subrc ne 0.
write 'No authorization to delete'.
else.
delete dataset pfile.
endif.
12-08-2011 8:39 AM
Welcome to SCN,
Your question itself has the solution.
call function as below before your delete
CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
EXPORTING PROGRAM = SY-REPID
ACTIVITY = 'DELETE' "Delete file auth object
FILENAME = pfile
EXCEPTIONS NO_AUTHORITY = 1
ACTIVITY_UNKNOWN = 2.
if sy-subrc ne 0.
write 'No authorization to delete'.
else.
delete dataset pfile.
endif.
12-08-2011 9:08 AM
Thanks a lot.
Am I right in understanding that this checks if I have delete access to the particular file?
I am facing a new issue here that the entire file name with path is more than 60 characters which is the size of the paramter to be passed here into the FM.
So I used this statement in my program where lv_infile is more than 60 chars.
AUTHORITY-CHECK OBJECT 'S_DATASET'
ID 'PROGRAM' FIELD sy-repid
ID 'ACTVT' FIELD '06'
ID 'FILENAME' FIELD lv_infile.
And this returns SY-SUBRC EQ 0.
So it means I have authorization to delete it. Right?
Then, why doesnt it get deleted?
Any ideas?
12-08-2011 9:13 AM
Inside the function there is a check for special authorization. Check what it returns. You can code it explicitly like
CALL FUNCTION 'SYSTEM_HOOK_OPEN_DATASET'
EXPORTING DATASET = FILENAME
OPENMODE = 'D'
EXCEPTIONS NO_PERMISSION.
12-08-2011 9:16 AM
Yes, I was just about to post a reply. I added that too. That also returns sy-subrc 0.
But immediately after that the delete statement still returns sy-subrc 4.
12-08-2011 9:20 AM
Please make sure that the path and file name is correct , case sensitive and the file exists in server. Other than this I donot have anything to help you
12-08-2011 9:24 AM
12-08-2011 9:27 AM
Check if this helps you to know the reason
DATA:lv_message TYPE string.
DATA:lf_ref TYPE REF TO cx_root.
DATA:p_file TYPE localfile.
TRY.
DELETE DATASET p_file.
CATCH cx_root INTO lf_ref.
lv_message = lf_ref->get_text( ).
WRITE lv_message.
ENDTRY.
12-08-2011 9:38 AM