‎2006 Nov 28 8:01 AM
Hi everyone,
I am trying to read into a buffer the content of a binary file (like Excel) and to write that content file using open data set into a folder destination.
The file destination has a size diferent than from the original one and cannot be open.
Here is the code.
DATA: lv_file_name(100),
lt_content LIKE sdokcntbin OCCURS 0 WITH HEADER LINE.
MOVE '\computerTestA1.xls' TO lv_file_name.
OPEN DATASET lv_file_name FOR INPUT IN BINARY MODE.
IF sy-subrc NE 0.
EXIT.
ENDIF.
DO.
READ DATASET lv_file_name INTO lt_content-line.
IF sy-subrc NE 0.
EXIT.
ENDIF.
APPEND lt_content.
ENDDO.
CLOSE DATASET lv_file_name.
* DELETE DATASET lv_file_name.
*****************************************************
CLEAR: lv_file_name.
MOVE '\computerTestB2.xls' TO lv_file_name.
OPEN DATASET lv_file_name FOR OUTPUT IN BINARY MODE.
IF sy-subrc NE 0.
EXIT.
ENDIF.
LOOP AT lt_content.
TRANSFER lt_content-line TO lv_file_name.
ENDLOOP.
CLOSE DATASET lv_file_name.
THanks in advance.
Regards.
Message was edited by:
David Fryda
‎2006 Nov 28 8:04 AM
hi David,
Check out this way ..
OPEN DATASET lv_file_name FOR INPUT IN BINARY MODE <b>ENCODING DEFAULT</b>.Regards,
Santosh
‎2006 Nov 28 8:08 AM
Hi David,
First check the authorization for that folder on application server using the F.M.
Authorization_Check_dataset.
if sy-subrc Eq 0.
Then try to open the destination file.
if the size is different from source & target try with to open the dataset in TEXT MODE.
Messages Mess for finding the error message in the open statement.
Message was edited by:
Ashok Damaraju
‎2006 Nov 28 8:08 AM
‎2006 Nov 28 9:50 AM
Hi,
I solve the problem.
In fact, when I try to write the last line of lt_content, it does write all the line even if this line is not full of data.
Solution :
DATA: lv_file_name(100),
lt_content LIKE sdokcntbin OCCURS 0 WITH HEADER LINE,
alen TYPE i,
pos TYPE i.
MOVE '\mr0221TestA1.xls' TO lv_file_name.
OPEN DATASET lv_file_name FOR INPUT IN BINARY MODE.
IF sy-subrc NE 0.
EXIT.
ENDIF.
*--------------
SET DATASET lv_file_name POSITION END OF FILE.
GET DATASET lv_file_name POSITION pos.
SET DATASET lv_file_name POSITION 0.
*--------------
DO.
CLEAR lt_content.
READ DATASET lv_file_name INTO lt_content-line ACTUAL LENGTH alen .
IF sy-subrc NE 0.
APPEND lt_content.
EXIT.
ENDIF.
APPEND lt_content.
ENDDO.
CLOSE DATASET lv_file_name.
* DELETE DATASET lv_file_name.
*****************************************************
CLEAR: lv_file_name.
MOVE '\mr0221TestB2.xls' TO lv_file_name.
OPEN DATASET lv_file_name FOR OUTPUT IN BINARY MODE.
IF sy-subrc NE 0.
EXIT.
ENDIF.
LOOP AT lt_content.
AT LAST.
TRANSFER lt_content-line TO lv_file_name LENGTH alen.
EXIT.
ENDAT.
TRANSFER lt_content-line TO lv_file_name.
ENDLOOP.
CLOSE DATASET lv_file_name.
Thanks.