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

File upload from application server

Former Member
0 Likes
484

Hi ,

I am uploading the file from application server,i am using Open dataset...

Read dataset... and close dataset.My question is ,if we donot use the close dataset after reading the file then what will be the effect?Beacuse code is successfully activated and executed without using it in code .

4 REPLIES 4
Read only

Former Member
0 Likes
450

HI..,

<i>Nothing will happen when u dont have any operation on that file after wards..

If u have not closed the file which is opened for READ purpose , but afterwards u have opened the same file for WRITE purpose.. then it OVERWRITES the file or From the line at which the reading has been stopped..!!!</i>

<b>check the below program !!</b>

The following program shows how the system sets the position when you open a file for writing. However, it is better programming style to close files that are already open before you reopen them for a different operation (for further information about closing files, refer to Closing a File).

DATA FNAME(60) VALUE 'myfile'.

DATA NUM TYPE I.

OPEN DATASET FNAME FOR OUTPUT.

DO 10 TIMES.

NUM = NUM + 1.

TRANSFER NUM TO FNAME.

ENDDO.

PERFORM INPUT.

OPEN DATASET FNAME FOR OUTPUT.

NUM = 0.

DO 5 TIMES.

NUM = NUM + 10.

TRANSFER NUM TO FNAME.

ENDDO.

PERFORM INPUT.

CLOSE DATASET FNAME.

OPEN DATASET FNAME FOR OUTPUT.

NUM = 0.

DO 5 TIMES.

NUM = NUM + 20.

TRANSFER NUM TO FNAME.

ENDDO.

PERFORM INPUT.

FORM INPUT.

SKIP.

OPEN DATASET FNAME FOR INPUT.

DO.

READ DATASET FNAME INTO NUM.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

WRITE / NUM.

ENDDO.

ENDFORM.

The output appears as follows:

1

2

3

4

5

6

7

8

9

10

10

20

30

40

50

6

7

8

9

10

20

40

60

80

100

This example performs the following steps using the file "myfile":

==>It is opened for writing

==>It is filled with 10 integers (for information about the TRANSFER statement, refer to Writing Data to Files)

==>It is then opened for reading. The position is reset accordingly to the beginning of the file.

==>It is read into the field NUM. For information about the READ DATASET statement, refer to Reading Data from Files. The values of NUM are displayed on the screen.

==>It is reopened for writing The position is reset to the beginning of the file.

==>It is filled with five integers, which overwrite the previous contents of the file.

==>It is then reopened for reading. The position is reset to the beginning of the file.

==>The file is read into the field NUM. The values of NUM are displayed on the screen.

==>It is closed (for information about the CLOSE DATASET statement, refer to Closing a File).

==>It is then reopened for writing. The system deletes the existing contents of the file.

==>It is filled with 5 integers.

==>It is then opened for reading. The position is reset to the beginning of the file.

==>The file is read into the field NUM. The values of NUM are displayed on the screen.

regards,

sai ramesh

Read only

Former Member
0 Likes
450

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

but when there are multiple files then there may be confusion as to which file is opened , so it is better to close the datasets

Read only

Former Member
0 Likes
450

Even though the code is working

If you do not use close dataset statement, anyone can manipulate the file contents.

So to avoid the file manipuation, use close statement for each open dataset.

Thanks

Sandeep

Reward if helpful

Read only

Former Member
0 Likes
450

If you dont close file using CLOSE DATASET then an opened file that was not explicitly closed using CLOSE DATASET is automatically closed when the program is exited.

close dataset clause is used just to avoid unwanted situations.

Swati.