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: 

Deleting Application Server XML file

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

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.

8 REPLIES 8

kesavadas_thekkillath
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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?

0 Kudos

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.

Former Member
0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

Yes, I checked them all.

Thanks for your help Keshav.

Nisha

0 Kudos

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.

Former Member
0 Kudos

Tried.

It doesnt even enter the CATCH block.

Thanks anyway.