Call Microsoft Word from ABAP

4.6x

* Let user type in the text file with Microsoft Word
* Use WS_EXECUTE to activate Microsoft Word from ABAP
* After saving, exit from Microsoft Word and upload the files to
* Internal Table for printing.

REPORT ZWSEXECUTE.

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.

More Function Module
Functions / SAP Script / ALV

Tables
Database Table

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.