SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Проблема open dataset



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
Garik
Специалист
Специалист



Joined: 11 Oct 2007
Posts: 60

PostPosted: Thu Jan 17, 2008 4:08 pm    Post subject: Проблема open dataset Reply with quote

Доброго денёчка,
пытаюсь прочитать в буфер содержимое бинарного файла (Excel) и сохранить в другой директории. Создаваемый файл получается большей длины и при открытии возникает ошибка. Вот код, можете подсказать, в чем проблема?

Code:
DATA: ls_filename TYPE rlgrap-filename,
      lt_content  TYPE sdokcntbin OCCURS 0 WITH HEADER LINE.

MOVE '1.xls' TO ls_filename.
OPEN DATASET ls_filename FOR INPUT IN BINARY MODE.
CHECK sy-subrc IS INITIAL.

DO.
  READ DATASET ls_filename INTO lt_content-line.
  IF NOT sy-subrc IS INITIAL.
    EXIT.
  ENDIF.
  APPEND lt_content.
ENDDO.

CLOSE DATASET ls_filename.
*DELETE DATASET ls_filename.

*****************************************************

CLEAR: ls_filename.
MOVE '2.xls' TO ls_filename.
OPEN DATASET ls_filename FOR OUTPUT IN BINARY MODE.
CHECK sy-subrc IS INITIAL.

LOOP AT lt_content.
  TRANSFER lt_content-line TO ls_filename.
ENDLOOP.
CLOSE DATASET ls_filename.
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 170
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Thu Jan 17, 2008 5:52 pm    Post subject: Reply with quote

Судя по коду, вы записываете содержимое последней линии в таблице полностью, хотя она может быть заполнена частично.
Back to top
View user's profile Send private message Blog Visit poster's website
Garik
Специалист
Специалист



Joined: 11 Oct 2007
Posts: 60

PostPosted: Fri Jan 18, 2008 12:37 pm    Post subject: Reply with quote

Спасибо, рабочий вариант:

Code:
REPORT z_rename_file.

DATA: ls_filename TYPE rlgrap-filename,
      lt_content  TYPE sdokcntbin OCCURS 0 WITH HEADER LINE,
      len TYPE i,
      pos TYPE i.

MOVE '1.xls' TO ls_filename.
OPEN DATASET ls_filename FOR INPUT IN BINARY MODE.
CHECK sy-subrc IS INITIAL.

*vvvvvvvvvvv
* Get length of the file
SET DATASET ls_filename POSITION END-OF-FILE.
GET DATASET ls_filename POSITION pos.
SET DATASET ls_filename POSITION 0.
*^^^^^^^^^^^

DO.
  READ DATASET ls_filename INTO lt_content-line ACTUAL LENGTH len.
  IF NOT sy-subrc IS INITIAL.
    EXIT.
  ENDIF.
  APPEND lt_content.
ENDDO.

CLOSE DATASET ls_filename.
DELETE DATASET ls_filename.

*****************************************************

CLEAR: ls_filename.
MOVE '2.xls' TO ls_filename.
OPEN DATASET ls_filename FOR OUTPUT IN BINARY MODE.
CHECK sy-subrc IS INITIAL.

LOOP AT lt_content.
  AT LAST.
    TRANSFER lt_content-line TO ls_filename LENGTH len.
    EXIT.
  ENDAT.
  TRANSFER lt_content-line TO ls_filename.
ENDLOOP.
CLOSE DATASET ls_filename.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.