FUNCTION so_get_pdf_value.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IV_VBELN) TYPE VBELN
*" EXPORTING
*" VALUE(EV_VALUE) TYPE FPCONTENT
*"----------------------------------------------------------------------
DATA: ls_printout TYPE so_proforma_st5,
ls_fp_outputparams TYPE sfpoutputparams,
lv_form_name TYPE fpname,
lv_fm_name TYPE rs38l_fnam,
ls_fp_docparams TYPE sfpdocparams,
ls_formoutput TYPE fpformoutput,
ls_result TYPE sfpjoboutput.
" Function where I Get Data to fill my PDF.
CALL FUNCTION 'SO_PROFORMA_GET_DATA'
EXPORTING
iv_vbeln = lv_vbeln
IMPORTING
es_printout = ls_printout.
" Print data
IF sy-cprog EQ 'RS_TESTFRAME_CALL'.
sy-cprog = sy-repid.
ENDIF.
* Do not forget to set your variables ! ! !
ls_fp_outputparams-dest = 'LP01'.
ls_fp_outputparams-getpdf = abap_true.
ls_fp_outputparams-nodialog = abap_true.
lv_form_name = 'SO_AF003'.
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = ls_fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = lv_form_name
IMPORTING
e_funcname = lv_fm_name.
CATCH cx_fp_api_repository.
CATCH cx_fp_api_internal.
CATCH cx_fp_api_usage.
ENDTRY.
ls_fp_docparams-langu = sy-langu.
IF lv_fm_name IS NOT INITIAL.
CALL FUNCTION lv_fm_name
EXPORTING
/1bcdwb/docparams = ls_fp_docparams
is_general = ls_printout
IMPORTING
/1bcdwb/formoutput = ls_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
ev_value = ls_formoutput-pdf. " PDF as xstring variable
ENDIF.
ENDIF.
CALL FUNCTION 'FP_JOB_CLOSE'
IMPORTING
e_result = ls_result
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFUNCTION.
FUNCTION so_proforma_zip.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IV_STRING) TYPE STRING
*" EXPORTING
*" VALUE(EV_ZIPSTRING) TYPE XSTRING
*"----------------------------------------------------------------------
DATA: lo_zip TYPE REF TO cl_abap_zip,
lv_value TYPE fpcontent,
lv_filename TYPE string,
lt_vbeln TYPE TABLE OF vbeln.
SPLIT iv_string AT ',' INTO TABLE lt_vbeln.
CREATE OBJECT lo_zip.
LOOP AT lt_vbeln INTO DATA(lv_vbeln).
CLEAR: lv_filename, lv_value.
lv_filename = |{ lv_vbeln }.pdf|. " Name of the PDF File
CALL FUNCTION 'SO_GET_PDF_VALUE' " Function where I get PDF as xstring value.
EXPORTING
iv_vbeln = lv_vbeln
IMPORTING
ev_value = lv_value.
IF lv_value IS NOT INITIAL.
*Add PDF Files into ZIP File.
lo_zip->add( EXPORTING name = lv_filename
content = lv_value ).
ENDIF.
ENDLOOP.
ev_zipxstring = lo_zip->save( ). " the final ZIP File.
ENDIF.
ENDFUNCTION.
METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.
CASE iv_entity_set_name.
WHEN 'printSalesSet'.
*In our scenario we are using VBELN numbers seperated by ' , ' in a string variable.
DATA(lv_string) = VALUE #( it_key_tab[ 1 ]-value OPTIONAL ). " VBELN numbers seperated via ' , '
DATA(stream) = VALUE ty_s_media_resource( mime_type = 'application/zip' ). " Media Source
DATA(filename) ='SalesOrders.zip'.
CALL FUNCTION 'SO_PROFORMA_ZIP' "Function to get ZIP FILE content as a xstring value.
EXPORTING
iv_string = lv_string
IMPORTING
ev_zipxstring = stream-value .
set_header( VALUE #( name = 'Content-Disposition' value = |inline; filename="{ escape( val = filename format = cl_abap_format=>e_url ) }"| ) ).
copy_data_to_ref( EXPORTING is_data = stream CHANGING cr_data = er_stream ).
ENDCASE.
ENDMETHOD.
If you followed the blog well you will be seeing this screen with ~status_code = 200 and ~status_reason = OK . This means our service worked well and we did get our response , which is the ZIP File we created. You can also see your settings from here such as your mime_type which is content_type and your File Name which is ~content_filename.
- Metehan Dülger
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 | |
3 |