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

Delete Dataset from flat file.

Former Member
0 Likes
888

Hi

I have requirement to delete Data from Dataset for some records , is it possible to do. ?

Scenerio, is I have text file on application server , according to that file , records are getting uploaded in my Ztables. some times due to some errors records are not getting updated in Ztable. since I am clearing the file before close dataset... Text (flat) file gets deleted from Application server.

requirement is , I want, if data has been updated in my ztables only those records should get deleted from my Text file of application server,remaining which are having errors or not updated in Ztable should remain in TEXT file..

How should , I right code for this. any idea ?

Thanks in advance

.

5 REPLIES 5
Read only

Former Member
0 Likes
667

Hi,

Try OPEN DATASET p_file FOR UPDATE

Read only

Former Member
0 Likes
667

hi purnima,

compare the records with the primary key..if they match delete that record...

regds

Read only

0 Likes
667

Hi, sudheer

Thanks for reply.

But I wanted code (syntax) to delete the records from Flat file.

e.g.

I have written code in the beginning

ie.

OPEN DATASET v_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

.

IF sy-subrc EQ 0.

DO.

READ DATASET v_file INTO wa_file.

IF sy-subrc EQ 0.

APPEND wa_file TO ifile.

ELSE.

EXIT.

ENDIF.

ENDDO.

At the end of my processing : given like this . Which is clearing the Flat file and closing it.

MODIFY Ztable FROM TABLE internal tab.

IF sy-subrc EQ 0.

CLEAR wa_file.

CLOSE DATASET v_file.

OPEN DATASET v_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

TRANSFER wa_file TO v_file.

CLOSE DATASET v_file.

ENDIF.

Now , I don't want to Deleting the whole file.. but if records are not gone properly..should Keep those records in flat file.

what wud be the code for that. ?

Thanks in advance.

Read only

Former Member
0 Likes
667

Hi,

There is no statement to delete records from an application file. Check the below logic to solve your problem.

(1) Assume FILE1 contains the actual data.

(2) Copy the contents of FILE1 to FILE2.

(3) Delete FILE1 from the application server ( optional)

(4) Read the records from FILE2 except those you want to delete

(5) Write these records into FILE1.

When the file is already opened, SAP triggers an exception of the type CX_SY_FILE_OPEN.

Best Regards,

Raj.

Read only

0 Likes
667

Thanks everyone,

I have got solution. Not as I wanted, but My purpose has got solved.

Regards

purnima