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

Is it require to use CLOSE data set when I am using Delete data set

Former Member
0 Likes
3,025

Hi All,

I am opening a file using OPEN DATASET command and after that i am deleting that file using DELETE DATA SET.

In this case is it require to use CLOSE DATASET also?

Ex: OPEN DATASET file_name IN TEXT MODE.

if sy-subrc = 0.

do.

Read data set ...................

-


-


endo

DELETE DATASET file_name

endif.

In the above is it require to use CLOSE DATASET after / before DELETE DATASET command.

Thanks,

Vijay

1 ACCEPTED SOLUTION
Read only

GauthamV
Active Contributor
0 Likes
2,768

Every open dataset should be closed with close dataset.

21 REPLIES 21
Read only

GauthamV
Active Contributor
0 Likes
2,769

Every open dataset should be closed with close dataset.

Read only

Former Member
0 Likes
2,768

Is it compulsary to use Close Data set when we are using Delete data set

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,768

Hello,

I agree with Gautham on this 99%

I would have agreed 100% if i did not read this SAP documentation :

An opened file that was not explicitly closed using CLOSE DATASET is automatically closed when the program is exited

But it is a good practice to CLOSE DATASET for every OPEN DATASET.

BR,

Suhas

Read only

Former Member
0 Likes
2,768

@ Gautham and Suhas,

But does it make sense to use CLOSE DATASET after using DELETE DATASET? DELETE dataset will delete the file but then whats there to close after this?

Vikranth

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,768

Hello Vik,

Suppose you donot have the auth. to delete a file in the app. server.

So your DELETE DATASET will return SY-SUBRC NE 0. So your file is not deleted & still is OPEN !!

I hope you get the catch

BR,

Suhas

Read only

Former Member
0 Likes
2,767

Hello Suhas,

Yes i agree with that. But for the scenario when the file is deleted successfully, and if i use a CLOSE dataset after that, it's still showing sy-subrc = 0. I was atleast expecting a sy-subrc other than 0 if not a dump. Not sure what the system is closing after the DELETE dataset

Vikranth

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,767

>

> But for the scenario when the file is deleted successfully, and if i use a CLOSE dataset after that, it's still showing sy-subrc = > 0. I was atleast expecting a sy-subrc other than 0 if not a dump. Not sure what the system is closing after the DELETE dataset.

Hello Vik,

That's standard SAP functionality.

See Nitwick's post. He has added further info on CLOSE DATASET for ready reference.

BR,

Suhas

Read only

Former Member
0 Likes
2,767

Aah now i got it. I dint check Nitwick's post properly.

Read only

Former Member
0 Likes
2,767

Hi Suhas,

I second your views on this.

P.S. Not 'He' by the way. I'm a 'She'

Read only

GauthamV
Active Contributor
0 Likes
2,767

Some more additional information for close dataset ( from SAP docu )

You only need to close a file if you want to delete its contents the next time you open it for write access. For further information and an example, refer to Opening a File for Write Access.

http://help.sap.com/saphelp_erp2004/helpdata/EN/fc/eb3d1b358411d1829f0000e829fbfe/frameset.htm

Read only

Former Member
0 Likes
2,767

Thanks for all for ur reply..

One more ...How many files can be opened with out using Close data set..

I am using OPEN DATASET to read a input file but I am not using CLOSE DATASET command to close the file..

How many files can be opened successfully with out using CLOSE DATASET command....

I heard that after opening some files program will goto DUMP if we dont use CLOSE DATASET command...

Thanks,

Vijay

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,767

Hello Vijay,

Do not beleive in what you hear !!

If any doubts write a small piece of code, read SAP documentation, search forums.

A simple F1 on OPEN DATASET gives you this info:

You can open up to 100 files per internal session. The actual maximum number of simultaneously open files may be less, depending on the platform

Enough spoonfeeding for today !!

Good luck,

Suhas

Read only

Former Member
0 Likes
2,767

Hello Suhas,

Thanks for your advice, I know that...I am not forcing you to reply...

But you are not at all telling straightforward answer to my questions..

Thanks,

Vijay

Read only

Former Member
0 Likes
2,767

Thanks Gautham i got it now.

@Nitwick- Even i mistook you for a HE

When i was new to the forums i thought Julius was a SHE from the name. But came to know i was wrong when i checked Julius's business card

Hope he doesnt check this post

Read only

Former Member
0 Likes
2,767

Hi Vijay,

No offence meant by anybody here to your questions.

All of us have been reading through the F1 documentation to answer your question. You could probably check it out for yourself. That's the intention.

Happy working.

@Vikranth

Well, 'Nitwick' is just a display name. Dumbledore's favourite word

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,767

Hello Vik,

I am sure if Julius checks this he will hatch another "over-the-top-of-your-head" comment

BR,

Suhas

Read only

Former Member
0 Likes
2,767

Now i get 10 points for considering Julius as a SHE before. I think even Vijay was expecting Julius to be a SHE

Read only

GauthamV
Active Contributor
0 Likes
2,767

>

> Now i get 10 points for considering Julius as a SHE before. I think even Vijay was expecting Julius to be a SHE

But how does that solve his problem ?

Read only

Former Member
0 Likes
2,767

LOL am not exactly sure of the intention of the OP to assign p0ints to me Would be nice if he can clarify.

Read only

Former Member
0 Likes
2,767

Hi,

Adding on to Suhas, (courtesy: SAP docu)


If the file is already closed or does not exist, the statement is ignored and the return value sy-subrc is set to 0. 

Read only

Former Member
0 Likes
2,767

Hi Vijay,

It is not required to use CLOSE DATASET with DELETE DATASET. But logically speaking if you want to delete, it is better to first open the file using OPEN DATASET and then proceed with you delete operation using DELETE DATASET then close the file using CLOSE DATSET.

Edited by: Harini Gopinath on Nov 6, 2009 2:49 PM