File programming

REPORT ZZBGS010 .
*----------------------------------------------------------------------*
* Example: Interface between Microsoft Excel and ABAP/4 with up- and *
* downloading of data plus executing Microsoft Excel. *
*----------------------------------------------------------------------*
TABLES: USR04.
DATA: SIZE TYPE I.

DATA: BEGIN OF USER OCCURS 100.
INCLUDE STRUCTURE USR04.
DATA: END OF USER.

* ---------------------------------------------------------------------*
* Example: Select some data into an internal table. *
* ---------------------------------------------------------------------*

SELECT * FROM USR04 INTO TABLE USER .

* ---------------------------------------------------------------------*
* Example: Downloading data in Microsoft Excel Format with automatic *
* prompt popup dialog. *
* ---------------------------------------------------------------------*
CALL FUNCTION 'DOWNLOAD'
EXPORTING
FILENAME = 'C:\tmp\SAPEXL1.XLS'
FILETYPE = 'WK1' "ASC, WK1, DBF, DAT, bin
MODE = ' ' "Mode ' ' = Rewrite Mode 'A' = Appending
TABLES
DATA_TAB = USER.

* ---------------------------------------------------------------------*
* Example: Downloading data in Microsoft Excel Format without automatic*
* prompt popup. *
* ---------------------------------------------------------------------*
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = 'C:\tmp\SAPEXL2.XLS'
FILETYPE = 'WK1' "ASC, WK1, DBF, DAT, bin
MODE = ' ' "Mode ' ' = Rewrite Mode 'A' = Appending
TABLES
DATA_TAB = USER.


CLEAR USER. "Clear buffer
REFRESH USER. "Refresh, empty internal table

*----------------------------------------------------------------------*
* Example: Uploading Microsoft Excel to ABAP/4 internal table. *
*----------------------------------------------------------------------*
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = 'C:\tmp\SAPEXL.prn'
FILETYPE = 'ASC'
IMPORTING
FILESIZE = SIZE
TABLES
DATA_TAB = USER.

*----------------------------------------------------------------------*
* Example: Starting Microsoft Excel and load sheet. *
*----------------------------------------------------------------------*
CALL FUNCTION 'WS_EXECUTE'
EXPORTING
COMMANDLINE = 'C:\tmp\SAPEXL1.XLS'
PROGRAM = 'F:\APPL\WINDOWS\EXCEL5DK\EXCEL.EXE'
.

*----------------------------------------------------------------------*
* Example: Starting Microsoft Excel and load internal table as sheet *
*----------------------------------------------------------------------*
CALL FUNCTION 'WS_EXCEL'
EXPORTING
FILENAME = 'C:\tmp\SAPEXL.XLS'
SYNCHRON = ' '
TABLES
DATA = USER.
--------------------------------------------------------------------------------

0 comments: