Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Open Powerpoint Presentation from ABAP program

cuky
Participant
0 Kudos
2,123

Hello,

I'm writing a program that dynamically generates a PowerPoint presentation with changing details. The empty presentation is a generic XML file saved in the MIME repository, which has placeholders for my data. I replace those placeholders with my real data, save the final XML file to the local PC and then open it in PowerPoint.

I tried using method EXECUTE of class CL_FRONTEND_GUI_SERVICES to open powerpoint from its install folder, but it returns with sy-subrc = 3 ("bad parameter").

Could you please advise what can I do?

Here is my code:

METHOD open_presentation_in_pwrpoint.

  CONSTANTS: gc_local_xml_filename TYPE string VALUE 'Temp_Presentation',
             gc_xml_file_extension TYPE string VALUE '.xml',
             gc_underscore         TYPE c LENGTH 1 VALUE '_'.

  DATA: lv_error_code             TYPE sysubrc,
        lv_timecode               TYPE timestampl,
        lv_timecode_str           TYPE c LENGTH 30,
        lv_local_temp_folder      TYPE string,
        lv_local_xml_filename     TYPE rlgrap-filename,
        lv_local_xml_filename_str TYPE string,
        lv_local_xml_parameters   TYPE string,
        lv_application_name       TYPE string,
        lt_local_xml_file_data    TYPE ztthr_binary_docs.

  CHECK iv_presentation_xml IS INITIAL.

  " Getting the default local sap folder:
  CALL METHOD cl_gui_frontend_services=>get_sapgui_workdir
    CHANGING
      sapworkdir            = lv_local_temp_folder
    EXCEPTIONS
      get_sapworkdir_failed = 1
      cntl_error            = 2
      error_no_gui          = 3
      not_supported_by_gui  = 4
      OTHERS                = 5.

  "$. Region Building the filename with data-time-stamp

  GET TIME STAMP FIELD lv_timecode. "    'YYYYMMDDhhmmss.mmmuuun'
  UNPACK lv_timecode TO lv_timecode_str.

  CONCATENATE lv_timecode_str(4)      "  'YYYY'
              gc_underscore       "  '_'
              lv_timecode_str+4(2)    "  'MM'
              gc_underscore       "  '_'
              lv_timecode_str+6(2)    "  'DD'
              gc_underscore       "  '_'
              lv_timecode_str+8(2)    "  'hh'
              gc_underscore       "  '_'
              lv_timecode_str+10(2)   "  'mm'
              gc_underscore       "  '_'
              lv_timecode_str+12(2)   "  'ss'
              gc_underscore       "  '_'
              lv_timecode_str+15(3)   "  'mmm'
              gc_underscore       "  '_'
              lv_timecode_str+17(3)   "  'uuu'
              gc_underscore       "  '_'
              lv_timecode_str+20(1)   "  'n'
         INTO lv_timecode_str.

  CONCATENATE  lv_local_temp_folder
               '\'
               gc_local_xml_filename
               lv_timecode_str
               gc_xml_file_extension
               INTO lv_local_xml_filename.

  "$. Endregion Building the filename with data-time-stamp

  lv_local_xml_filename_str = lv_local_xml_filename.

  " Saving the generated XML file to the local computer:
  CALL METHOD cl_gui_frontend_services=>gui_download
    EXPORTING
*    bin_filesize              = bin_filesize
      filename                  = lv_local_xml_filename_str
      filetype                  = 'ASC'
*    append                    = SPACE
*    write_field_separator     = SPACE
*    header                    = '00'
*    trunc_trailing_blanks     = SPACE
*    write_lf                  = 'X'
*    col_select                = SPACE
*    col_select_mask           = SPACE
*    dat_mode                  = SPACE
*    confirm_overwrite         = SPACE
*    no_auth_check             = SPACE
*    codepage                  = SPACE
*    ignore_cerr               = ABAP_TRUE
*    replacement               = '#'
*    write_bom                 = SPACE
*    trunc_trailing_blanks_eol = 'X'
*    wk1_n_format              = SPACE
*    wk1_n_size                = SPACE
*    wk1_t_format              = SPACE
*    wk1_t_size                = SPACE
*    show_transfer_status      = 'X'
*    fieldnames                = fieldnames
*    virus_scan_profile        = '/SCET/GUI_DOWNLOAD'
*    write_lf_after_last_line  = 'X'
*  IMPORTING
*    filelength                = filelength
    CHANGING
      data_tab                  = lt_local_xml_file_data[]
    EXCEPTIONS
      file_write_error          = 1
      no_batch                  = 2
      gui_refuse_filetransfer   = 3
      invalid_type              = 4
      no_authority              = 5
      unknown_error             = 6
      header_not_allowed        = 7
      separator_not_allowed     = 8
      filesize_not_allowed      = 9
      header_too_long           = 10
      dp_error_create           = 11
      dp_error_send             = 12
      dp_error_write            = 13
      unknown_dp_error          = 14
      access_denied             = 15
      dp_out_of_memory          = 16
      disk_full                 = 17
      dp_timeout                = 18
      file_not_found            = 19
      dataprovider_exception    = 20
      control_flush_error       = 21
      not_supported_by_gui      = 22
      error_no_gui              = 23
      OTHERS                    = 24
          .
  IF sy-subrc <> 0.    
    EXIT.

  ENDIF.

  WAIT UP TO 2 SECONDS.

*  " I tried using 'parameters' but with no success:
*  CONCATENATE '"'
*              lv_local_xml_filename_str
*              '"'
*         INTO lv_local_xml_parameters.

  lv_application_name = 'C:\Program Files (x86)\Microsoft Office\Office12\POWERPNT.EXE'.
* " I also tried those variations:
* " lv_application_name = '"C:\Program Files (x86)\Microsoft Office\Office12\POWERPNT.EXE"'.
* " lv_application_name = '''C:\Program Files (x86)\Microsoft Office\Office12\POWERPNT.EXE'''.
* " lv_application_name = 'POWERPNT.EXE'.

  CALL METHOD cl_gui_frontend_services=>execute
    EXPORTING
      document               = lv_local_xml_filename_str
      application            = lv_application_name
*      parameter              = lv_local_xml_parameters
*      default_directory      = default_directory
*      maximized              = 'X'
*      minimized              = minimized
      synchronous            = 'X'    
      operation              = 'OPEN'
    EXCEPTIONS
      cntl_error             = 1
      error_no_gui           = 2
      bad_parameter          = 3
      file_not_found         = 4
      path_not_found         = 5
      file_extension_unknown = 6
      error_execute_failed   = 7
      synchronous_failed     = 8
      not_supported_by_gui   = 9
      OTHERS                 = 10
          .

  IF sy-subrc <> 0.
    EXIT.

  ENDIF.

  CALL FUNCTION 'GUI_DELETE_FILE'
    EXPORTING
      file_name = lv_local_xml_filename
    EXCEPTIONS
      failed    = 1
      OTHERS    = 2.

  IF sy-subrc <> 0.
    " No treatment.

  ENDIF.

ENDMETHOD.

Thanks for helping!

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos
768

Just debug the first line of method EXECUTE of CL_GUI_FRONTEND_SERVICES, you'll see the valid combinations (i.e. the APPLICATION parameter shouldn't be used if you pass the DOCUMENT parameter)

2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos
769

Just debug the first line of method EXECUTE of CL_GUI_FRONTEND_SERVICES, you'll see the valid combinations (i.e. the APPLICATION parameter shouldn't be used if you pass the DOCUMENT parameter)

0 Kudos
768

Thank you! I tried to enter the method while debugging and it didn't enter, and afterwards I forgot to try to check it in the ABAP editor.

I restored the concatenating of lv_local_xml_parameters, commented out the 'DOCUMENT' parameter and sent only 'APPLICATION' and 'PARAMETER' and it worked. This launches Powerpoint itself with the desired filename as a launch parameter, rather than opening the file itself "by" Powerpoint.