Application Development 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: 

How to save DOI Excel file to application server or BDS

Former Member
0 Kudos

Hi all,

i´m developing a cockpit using Desktop Office Integration. A Excel Template file is loaded to the cockpit, changed and should after this saved to the application server. I´m using following method:

Url has following value: "SAPR3://H:RKDATENABLAGE_INTERNHOCHRECHNUNGINPLACEZHV_REP_HB_63_SRM_GM_TEST_CM.xls"

CALL METHOD akt_document->save_document_to_url

EXPORTING

url = url

no_flush = ''

IMPORTING

error = error

retcode = retcode

CHANGING

document_size = document_size.

CALL METHOD c_oi_errors=>show_message

EXPORTING

type = 'I'.

I do not get any error after the save_document_to_url. So it seems ok. But the file isn´t physical in the file system and I´m not able to open the file with following method:

CALL METHOD akt_document->open_document

EXPORTING "document_title = u_zhv_t_rep-bez_text

document_url = l_url

open_inplace = 'X'

open_readonly = l_readonly

* onsave_macro = onsave_macro

* startup_macro = startup_macro

protect_document = l_schutz

* user_info = user_info

* no_flush = no_flush

IMPORTING "error = error

retcode = retcode.

Any idea about my problem. Is there a other solution to save DOI Excel Files. I´m also happy, if someone could give me links to tutorials concerning this topic, etc.

thx in advance,

Christian

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

You should not use SAPR3 to refer to a drive on your local computer or network disk. SAPR3 is only for SAP internal locations (BDS, SAP HTML viewer, etc.)

If you want to save to a disk, you should use method SAVE_AS, don't use "SAPR3", just the normal path.

See demo programs, like SAPRDEMOOFFICEINTEGRATION, or SAPRDEMOEXCEL_EXPORT.

5 REPLIES 5

Sandra_Rossi
Active Contributor
0 Kudos

You should not use SAPR3 to refer to a drive on your local computer or network disk. SAPR3 is only for SAP internal locations (BDS, SAP HTML viewer, etc.)

If you want to save to a disk, you should use method SAVE_AS, don't use "SAPR3", just the normal path.

See demo programs, like SAPRDEMOOFFICEINTEGRATION, or SAPRDEMOEXCEL_EXPORT.

0 Kudos

Hi, thank you. I know these demo programs. But I would like to save the excel files on the application server. I tried it also with the method save_document_to_url using URL for local file system like "FILE://
LS-SRV-T04\H$\RKDATEN\ABLAGE_INTERN\HOCHRECHNUNG\INPLACE\TEST.XLS" but the user working with this cockpit have no direct access to this path.

0 Kudos

You may use SAVE_DOCUMENT_TO_TABLE method and save it directly to application server file system, using a SOLIX_TAB type internal table I think, and then executing OPEN DATASET FOR OUTPUT IN BINARY MODE, LOOP AT, TRANSFER, ENDLOOP, CLOSE DATASET ABAP statements.

PS: there's also some documentation in [sap library - DOI programming|http://help.sap.com/saphelp_nw70ehp2/helpdata/en/49/173519a2e314d3e10000000a42189b/frameset.htm]

0 Kudos

thx, this way works!

here the coding for others:

FORM save_doc_to_appserver.

  DATA: document_table TYPE solix_tab,
        wa_doc TYPE LINE OF solix_tab,
        document_size TYPE i.

  CALL METHOD akt_document->save_document_to_table
    EXPORTING
      no_flush       = ''
    IMPORTING
      error          = error
      retcode        = retcode
    CHANGING
      document_table = document_table
      document_size  = document_size.

  CALL METHOD c_oi_errors=>show_message
    EXPORTING
      type = 'I'.

  IF retcode <> 'OK'.
    PERFORM close_instances.
  ENDIF.


  OPEN DATASET g_akt_filename FOR OUTPUT IN BINARY MODE.

  LOOP AT document_table INTO wa_doc.

    TRANSFER wa_doc TO g_akt_filename.

  ENDLOOP.

  CLOSE DATASET g_akt_filename.


ENDFORM.                    "save_doc_to_appserver

and to load the file again:

FORM open_doc_from_appserver
  USING u_zhv_t_rep TYPE zhv_t_rep
        l_offen TYPE char1
        l_readonly TYPE char1 "'X' = ohne Blattschutz
  CHANGING c_retcode TYPE char256.

  DATA: document_table TYPE solix_tab,
        wa_doc TYPE LINE OF solix_tab,
        document_size TYPE i,
        l_schutz(1).

  IF l_offen = ''.
    l_schutz = 'X'.
  ELSE.
    l_schutz = ''.
  ENDIF.

  "url bilden
  CONCATENATE u_zhv_t_rep-pfad u_zhv_t_rep-datei INTO g_akt_filename.

  OPEN DATASET g_akt_filename FOR INPUT IN BINARY MODE.

  WHILE sy-subrc = 0.

    READ DATASET g_akt_filename INTO wa_doc.
    APPEND wa_doc TO document_table.

  ENDWHILE.

  CLOSE DATASET g_akt_filename.

  CALL METHOD akt_document->open_document_from_table
     EXPORTING document_table   = document_table
               document_size    = document_size
*               document_title   = document_title
               open_inplace     = 'X'
*               open_readonly    = open_readonly
*               onsave_macro     = onsave_macro
*               startup_macro    = startup_macro
               protect_document = l_schutz
               no_flush         = ''
     IMPORTING error            = error
               retcode          = retcode.

  CALL METHOD c_oi_errors=>show_message
    EXPORTING
      type = 'I'.


ENDFORM.                    "open_doc_from_appserver

0 Kudos

Thx for the feedback, and for the code, and for the good formatting

Be careful when you write the dataset, you have to take care of the number of bytes. If the excel file is 25501 bytes (document_size = 25501), then it means that you'd get 101 lines in document_table internal table because solix_tab is a table of 255 bytes for each line: 100 lines * 255 bytes + 1 line where only the first byte should be written.

Your way, you currently write 25755 bytes instead of 25501.

Use this code to write the exact number of bytes:


  DATA bytes_count TYPE i.
  DESCRIBE FIELD wa_doc LENGTH bytes_count IN BYTE MODE.
  LOOP AT document_table INTO wa_doc.

    TRANSFER wa_doc TO g_akt_filename LENGTH bytes_count.

    SUBTRACT bytes_count FROM document_size.
    IF document_size < bytes_count.
      bytes_count = document_size.
    ENDIF.
  ENDLOOP.

PS: I'm nitpicking because some applications don't support extra bytes, and consider that the file is corrupted