How to Open files from the presentation server using Microsoft Word?

*---------------------------------------------------------------------
* 17.02.2003 |Initial Author - | This program is used to open word
*            |                 | on the presentation server. Excel,
*            |                 | notepad, calculator etc could also
*            |Uma anandhi s    | be opened
*---------------------------------------------------------------------
REPORT ZUM_OPEN_WORD .

* The internal table is declared of size 3
DATA: BEGIN OF ITAB OCCURS 3,
      LINE(50),
      END OF ITAB.

PARAMETERS: PROG(70) DEFAULT
            'C:\Program Files\Microsoft Office\Office\WINWORD.EXE'.
PARAMETERS: FILE1(70) DEFAULT 'C:\TEMP\TEST.TXT'.
* Tick to print the Text file after saving from MS WORDS
PARAMETERS: S_UP  AS CHECKBOX.
* Tick to create new or overwrite Text file
PARAMETERS: S_NEW AS CHECKBOX.

IF S_UP = 'X'.
   CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
             FILENAME        = 'FILE1'
        TABLES
             DATA_TAB        = ITAB
        EXCEPTIONS
             FILE_OPEN_ERROR = 1.

   IF SY-SUBRC = 0.
     LOOP AT ITAB.
       WRITE: / ITAB.
     ENDLOOP.
   ELSE.
     WRITE: / 'File open error.'.
   ENDIF.
ELSE.
IF S_NEW = 'X'.
   CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
             FILENAME = 'FILE1'
        TABLES
             DATA_TAB = ITAB
        EXCEPTIONS
             FILE_WRITE_ERROR              = 1
             NO_BATCH                      = 2
             GUI_REFUSE_FILETRANSFER       = 3
             INVALID_TYPE                  = 4
             OTHERS                        = 5.
ENDIF.
CASE SY-SUBRC.
     WHEN 1.
          WRITE: / 'GUI DOWNLOAD FILE WRITE ERROR'.
     WHEN 2.
          WRITE: / 'GUI DOWNLOAD NO BATCH'.
     WHEN 3.
          WRITE: / 'GUI DOWNLOAD GUI REFUSE FILETRANSFER'.
     WHEN 4.
          WRITE: / 'GUI DOWNLOAD INVALID TYPE'.
     WHEN 5.
          WRITE: / 'GUI DOWNLOAD OTHERS'.
ENDCASE.

CALL FUNCTION 'WS_EXECUTE'
  EXPORTING
     PROGRAM       = PROG
     COMMANDLINE   = 'FILE1'
     INFORM        = ' '
  EXCEPTIONS
     FRONTEND_ERROR           = 1
     NO_BATCH                 = 2
     PROG_NOT_FOUND           = 3
     ILLEGAL_OPTION           = 4
     GUI_REFUSE_EXECUTE       = 5
     OTHERS                   = 6.

CASE SY-SUBRC.
   WHEN 1.
     WRITE: / 'FRONTEND ERROR'.
   WHEN 2.
     WRITE: / 'NO BATCH'.
   WHEN 3.
     WRITE: / 'PROGRAM NOT FOUND'.
   WHEN 4.
     WRITE: / 'ILLEGA OPTION'.
   WHEN 5.
     WRITE: / 'GUI REFUSE EXECUTE'.
   WHEN 6.
     WRITE: / 'OTHERS'.
ENDCASE.
ENDIF.

Read Also
Simple Program that Create Internal Table Dynamically

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.