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

Open data set problem with binary mode

david_fryda2
Participant
0 Likes
4,175

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

4 REPLIES 4
Read only

Former Member
0 Likes
1,331

hi David,

Check out this way ..

 OPEN DATASET lv_file_name FOR INPUT IN BINARY MODE <b>ENCODING DEFAULT</b>.

Regards,

Santosh

Read only

Former Member
0 Likes
1,331

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

Read only

anversha_s
Active Contributor
0 Likes
1,331

hi,

try with ENCODING DEFAULT

rgds

Anver

Read only

1,331

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.