2016 Aug 04 6:25 AM
Hi Friends,
We are getting file from SFTP folder to SAP through sproxy and creating file in application server using OPEN DATASET and passing to some standard program for updating data into sap(Infotype). Please find the below code.
It is working fine when file is coming one by one. But here problem is "At a time so many files are coming". Files are coming in parallel, open dataset is not locking the file. so files are overwritten and same data has been updated many times into SAP system instead some other file data.
Is any other way to lock the file?.
TRY.
lv_file = '/usr/sap/tmp'/Filename.txt'.
OPEN DATASET lv_file FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
LOOP AT gt_final INTO gs_final.
TRANSFER gs_final-string TO lv_file.
ENDLOOP.
CLOSE DATASET lv_file.
CATCH cx_sy_file_open.
MESSAGE 'File is already open in another program. Parallel process not possible' TYPE 'E'.
ENDTRY.
Note: We can add timestamp to file name to resolve this problem. But this will increase the data load in application server.
Thanks,
Chella
2016 Aug 04 7:05 AM
Hello Chella,
As per ABAP documentation, CX_SY_FILE_OPEN exception is thrown by runtime if the file is already open in the same program. Here I think from SPROXY your program is called in different sessions and therefore the said exception won't come.
Alternatively to ensure a file is locked, you can create a custom lock object by creating a custom table and you lock the entire table just before you open the file open dataset and deque it once processing is done. This way you can ensure, no parallal program is trying to open the same file.
Thanks,
Mainak
Hello Chella,
As per ABAP documentation, CX_SY_FILE_OPEN exception is thrown by runtime if the file is already open in the same program. Here I think from SPROXY your program is called in different sessions and therefore the said exception won't come.
Alternatively to ensure a file is locked, you can create a custom lock object by creating a custom table and you lock the entire table just before you open the file open dataset and deque it once processing is done. This way you can ensure, no parallal program is trying to open the same file.
Thanks,
Mainak
2016 Aug 04 7:05 AM
Hello Chella,
As per ABAP documentation, CX_SY_FILE_OPEN exception is thrown by runtime if the file is already open in the same program. Here I think from SPROXY your program is called in different sessions and therefore the said exception won't come.
Alternatively to ensure a file is locked, you can create a custom lock object by creating a custom table and you lock the entire table just before you open the file open dataset and deque it once processing is done. This way you can ensure, no parallal program is trying to open the same file.
Thanks,
Mainak
2016 Aug 04 8:22 AM
Hi Mainak,
Thanks for suggestion.
I have executed the program parallel in debug mode, Open data set is not throwing any exception. It is simply overwriting.
I don't have any custom table to update. updating standard infotype through standard program.
you mean to say i need to create some dummy custom table and lock object?
Thanks,
Chella
2016 Aug 04 8:30 AM
Hi Chella,
As I said, the excption won't be thrown during parallal processing.
Yes, to ensure the locking you can create one dummy custom table and lock object. Please let me know if this works for you after implementation.
Thanks,
Mainak
2016 Aug 30 7:30 AM
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |