WS_EXECUTE to called External Program

How to work with ws_execute function module to call an external program?

ws_execute used for Calling  Microsoft Word from ABAP

 =>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.
ABAP Tips by: Anshu Kumar

I have a tool in my desktop. Its in D drive. The file created should get stored in the d drive in the mentioned folder. The tool I am using is of exe mode.  What parameters do I need to pass in the function module i.e for command line and program. Where should I mention the path of the tool and where (in which parameter) should I mention the input file path and the output file path.

  CALL FUNCTION 'C13Z_FRONTEND_FILENAME_GET'   " File_name
   IMPORTING
     e_filename                 = w_filename.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

* Function to execute the Bar-Code batch file.
  CALL FUNCTION 'WS_EXECUTE'
    EXPORTING
      cd                 = 'C:\'
      program            = 'C:\BARCODE2\BCIL.BAT'
    EXCEPTIONS
      frontend_error     = 1
      no_batch           = 2
      prog_not_found     = 3
      illegal_option     = 4
      gui_refuse_execute = 5
      OTHERS             = 6.
By this function you can take location & name from end user & then use this w_filename to save the file.

ABAP Tips by: Anil Khandelwal

ABAP Tips

Related ABAP Topics:
Table CDHDR and CDPOS Usage

Get help for your ABAP problems
Do you have a ABAP Question?

SAP Books
SAP Certification, Interview Questions, Functional, Basis Administration and ABAP Programming 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.