TYPES: BEGIN OF lty_forms,
form TYPE fpname,
END OF lty_forms,
lty_t_forms TYPE STANDARD TABLE OF lty_forms WITH EMPTY KEY.
*&&-- Below are the 5 different Adobe form names created for Contract
CONSTANTS: lc_form_cover TYPE fpname VALUE 'ZFI_CP_COVER_LETTER',
lc_form_agreement TYPE fpname VALUE 'ZFI_CP_LOAN_AGREEMENT',
lc_form_debit TYPE fpname VALUE 'ZFI_CP_DIRECT_DEBIT',
lc_form_third_party TYPE fpname VALUE 'ZFI_CP_THIRD_PARTY',
lc_form_terms TYPE fpname VALUE 'ZFI_CP_TERMS_CONDITION'.
DATA: lwa_outputparams TYPE sfpoutputparams,
lv_fm_name TYPE rs38l_fnam,
lwa_docparams TYPE sfpdocparams,
lwa_formoutput TYPE fpformoutput,
lt_pdfcontent TYPE TABLE OF solix,
lt_formoutput TYPE tfpcontent,
lv_merged_document TYPE xstring,
lv_rc TYPE i,
lv_file_name TYPE string,
lwa_final TYPE zsfi_int_sub.
DATA: lo_pdf_merger TYPE REF TO cl_rspo_pdf_merge.
*&&-- Populate the multiple form names into an internal table
DATA(lt_forms) = VALUE lty_t_forms( ( form = lc_form_cover )
( form = lc_form_agreement )
( form = lc_form_debit )
( form = lc_form_third_party )
( form = lc_form_terms ) ).
lwa_outputparams-nodialog = abap_true.
lwa_outputparams-dest = 'LOCL'.
lwa_outputparams-getpdf = 'M'.
lwa_outputparams-bumode = 'M'. " Bundle Mode Multiple
*&---------------------------------------------------------------------*
*& Form Processing: Call Form - Open
*&---------------------------------------------------------------------*
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = lwa_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
" Suitable Error Handling
ENDIF.
LOOP AT lt_forms INTO DATA(lwa_forms).
TRY.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = lwa_forms-form
IMPORTING
e_funcname = lv_fm_name.
CATCH cx_fp_api.
ENDTRY.
CALL FUNCTION lv_fm_name
EXPORTING
/1bcdwb/docparams = lwa_docparams
iv_final = lwa_final
IMPORTING
/1bcdwb/formoutput = lwa_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
ENDIF.
CLEAR: lwa_forms, lwa_formoutput, lv_fm_name.
ENDLOOP.
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*&&-- Merging different PDF files into one
CREATE OBJECT lo_pdf_merger.
CALL FUNCTION 'FP_GET_PDF_TABLE'
IMPORTING
e_pdf_table = lt_formoutput.
* Add documents to attribute table of PDF merger
LOOP AT lt_formoutput INTO DATA(lwa_form).
lo_pdf_merger->add_document( lwa_form ).
ENDLOOP.
* Call kernel method to do the merge of the specified files.
lo_pdf_merger->merge_documents( IMPORTING merged_document = lv_merged_document
rc = lv_rc ).
CONCATENATE 'Loan_Contract' sy-datum sy-uzeit INTO DATA(lv_name) SEPARATED BY '_'.
CONCATENATE lv_name '.pdf' INTO lv_name.
REFRESH: lt_formoutput.
lwa_formoutput-pdf = lv_merged_document.
CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
EXPORTING
client = sy-mandt
logical_path = 'ZFI_CUSTSTMT_PATH'
file_name = lv_name
IMPORTING
file_name_with_path = lv_file_name
EXCEPTIONS
path_not_found = 1
missing_parameter = 2
operating_system_not_found = 3
file_system_not_found = 4
OTHERS = 5.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*PDF Upload
IF lwa_formoutput-pdf IS NOT INITIAL.
lt_pdfcontent = cl_document_bcs=>xstring_to_solix( ip_xstring = lwa_formoutput-pdf ).
OPEN DATASET lv_file_name FOR OUTPUT IN BINARY MODE .
IF sy-subrc = 0.
LOOP AT lt_pdfcontent INTO DATA(lwa_pdfcontent).
TRANSFER lwa_pdfcontent-line TO lv_file_name.
ENDLOOP.
CLOSE DATASET lv_file_name.
REFRESH lt_pdfcontent.
ENDIF.
ENDIF.
lwa_outputparams-nodialog = abap_true.
lwa_outputparams-device = 'PRINTER'.
lwa_outputparams-reqnew = abap_true.
lwa_outputparams-dest = 'LOCL'.
lwa_outputparams-bumode = 'M'. " Bundle Mode Multiple
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |