Spend Management Blogs by Members
Check out community member blog posts about spend management and SAP Ariba, SAP Fieldglass, and SAP Concur solutions. Post or comment about your experiences.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

report  z_download_docx.

parameters: p_docid like /ipro/tdocmnt-docmnt_id.

parameters: p_cntnt like /ipro/tdocmnt-content.

parameters: p_outdf like /ipro/toutdef-otype.

* implicit constant definition for context node content

types:

   begin of element_content,

     content  type /ipro/tcontent-content,

     content_object  type ref to /ipro/if_content,

     content_lbl  type string,

   end of element_content,

   elements_content type

      standard table of element_content

      with default key.

data:

   lt_content      type elements_content,

   lt_contents     type /ipro/tt_contents,

   lo_content      type ref to /ipro/if_content,

   ls_sel_content  like line of lt_content,

   lr_docb_factory type ref to /ipro/if_docb_factory,

   lr_model        type ref to /ipro/if_model,

   lx_notfound     type ref to /ipro/cx_serializer_failed_at,

   lo_output               type ref to /ipro/if_output.

data: piv_name type string.

move p_cntnt to piv_name.

call function '/IPRO/CONTENT_FACTORY'

   exporting

     piv_name     = piv_name

   importing

     pet_contents = lt_contents.

read table lt_contents into lo_content index 1.

lr_docb_factory = lo_content->get_docb_factory( ).

check lr_docb_factory is not initial.

lr_model = lr_docb_factory->lookup( piv_docmnt_id = p_docid

                                     piv_version = 1 ).

if lr_model is initial.

   try.

       lr_model ?=

         lr_docb_factory->open( piv_docmnt_id = p_docid

                                piv_docmnt_version = 1 ).

     catch /ipro/cx_serializer_failed_at into lx_notfound.

       exit.

     catch /ipro/cx_action_noauth

           /ipro/cx_action_illegal.

       exit.

   endtry.

endif.

if lr_model is bound.

   lo_output ?= lr_model.

endif.

data: ls_doc                  type /ipro/s_output.

if lo_output is bound.

   try.

       lo_output->enable( p_outdf ).

       ls_doc = lo_output->generate( p_outdf ).

     catch /ipro/cx_output_otype_invalid.

     catch /ipro/cx_output_gen_failed.

   endtry.

endif.

data:

   lv_file_len type i,

   out_tab     type standard table of tbl1024.

call function 'SCMS_XSTRING_TO_BINARY'

   exporting

     buffer          = ls_doc-data

*   APPEND_TO_TABLE = ' '

   importing

     output_length   = lv_file_len

   tables

     binary_tab      = out_tab.

call function 'GUI_DOWNLOAD'

   exporting

     bin_filesize = lv_file_len

     filename     = 'd:\1.docx.'

     filetype     = 'BIN'

   tables

     data_tab     = out_tab

   exceptions

     others       = 22.

if sy-subrc <> 0.

* Implement suitable error handling here

endif.