Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
yashoratna
Participant
Introduction: In my previous blog, I have demonstrated how to enable Adobe Form printing/preview in SAP CRM actions by creating a proxy to Smart Form.

Requirement: In this blog, I'll explain how to deal with printing multiple copies of an Adobe form in CRM actions and turn on the functionality to preview and print from the CRM WEBUI screen.

We need to apply same config/code from previous article but will modify method EXEC_ADOBE_FORM to establish the solution.

To print multiple copies of the adobe form in a one spool job or combining all the copies in a single document, we will open the PDF JOB (by function module FP_JOB_OPEN), call the Adobe form in a loop (number of times required to print) and close the PDF JOB (by function module FP_JOB_CLOSE). Let's outline the strategy step by step.

Step 1: Before invoking, FP_JOB_OPEN, we need to set some form processing output parameters as follows.

ls_fp_outputparams-dest        ls_output_options-tddest.
ls_fp_outputparams-nodialog is_control_parameters-no_dialog.
ls_fp_outputparams-reqnew   ls_output_options-tdnewid.
ls_fp_outputparams-preview  is_control_parameters-preview.

Furthermore, if we want to print on a physical printer (in a spool), we'll need to set the additional o/p parameter (reqimm) as shown below.

IF is_control_parameters-preview IS INITIAL.
ls_fp_outputparams-reqimm   ls_output_options-tdimmed.             " To print on actuals
ENDIF.

Step 2: The Adobe Function Module must then be invoked repeatedly while being given the control parameters listed below.

ls_control_parameters-langu lv_sf_langu.
ls_control_parameters-no_open abap_true.
ls_control_parameters-no_close abap_true.
ls_control_parameters-getotf abap_true.

Step 3: To finish, execute FP JOB CLOSE to close down the spool job. Next, gather all of the results and give them through to the exporting parameter es job output info.

These three steps will complete the functionality, allowing us to view one document (one print/print preview) with multiple copies of the Adobe form in SAP GUI screen only, not on CRM WEBUI screen. Because WEBUI screen expects data in OTF format, and Adobe FM returns PDF data with type tfpcontent (Table with Multiple XFTs, XFDs, PDFs), so no luck in WEBUI.

In order to accomplish this feature, additional output parameters must be provided, and further steps must involve converting PDF data to OTF data (see to the link).

Step 4: Check first to see if it is not a GUI screen call, and then set two further parameters:

GETPDF as 'M' and BUMODE as '-'

* GUI connection enabled ?
CALL FUNCTION 'RFC_IS_GUI_ON'
EXPORTING
login_check abap_false
IMPORTING
on          lv_gui.

IF lv_gui NE 'Y' AND is_control_parameters-preview IS NOT INITIAL.
ls_fp_outputparams-getpdf   'M'.
ls_fp_outputparams-bumode   '-'.
ENDIF.

Step 5: Call function module FP_GET_PDF_TABLE to get all the PDF data.

IF lv_gui NE 'Y' AND is_control_parameters-preview IS NOT INITIAL.
  CALL FUNCTION 'FP_GET_PDF_TABLE'
   IMPORTING
    e_pdf_table lt_pdf_table.
ENDIF.

Step 6:  Now transform the PDF data to OTF format, then send it as an exporting parameter. To view the code, please click on the method link.

IF lv_gui NE 'Y' AND is_control_parameters-preview IS NOT INITIAL.
LOOP AT lt_pdf_table ASSIGNING FIELD-SYMBOL(<fs_pdf>).
CALL METHOD get_pdf_to_otf(
EXPORTING
iv_pdf      <fs_pdf>
IMPORTING
et_otf_data DATA(li_otf).
ENDLOOP.

es_job_output_info-otfdata[] li_otf.
ENDIF.

For both GUI and WEBUI screens, kindly follow the whole code, which includes multiple copies of PDF in a single document.
DATA: lv_dummy(254)           TYPE c,
ls_printer_profile_data TYPE tsppf_prpr_002,
lv_adobe_fm_name TYPE rs38l_fnam.
TRY .
DATA(lv_adobe_form) = ip_smart_form.
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = lv_adobe_form
IMPORTING
e_funcname = lv_adobe_fm_name.
CATCH cx_fp_api_repository
cx_fp_api_usage
cx_fp_api_internal.
IF sy-subrc <> 0.
* add an error message to processing protocol
MESSAGE i015(sppf_media) WITH lv_adobe_form INTO lv_dummy.
CALL METHOD cl_log_ppf=>add_message
EXPORTING
ip_problemclass = '1'
ip_handle = ip_application_log.
RETURN.
ENDIF.
ENDTRY.
*-----------fill archive parameters for archive link -------------------
IF is_output_options-tdarmod = '2'
OR is_output_options-tdarmod = '3'.

* archive_index_tab
ASSIGN ct_archive_index_tab[ 1 ] TO FIELD-SYMBOL(<fs_archive_index>).
IF sy-subrc EQ 0 AND <fs_archive_index> IS ASSIGNED.
* just fill the id of actual BOR object
<fs_archive_index>-object_id = lv_bea_guid.
IF <fs_archive_index>-object_id IS INITIAL.
DELETE ct_archive_index_tab INDEX 1.
ENDIF.
ENDIF.
ENDIF.
*-----------language of smart form--------------------------------------
* determin here the language of the smart form

DATA(ls_control_parameters) = is_control_parameters.
ls_control_parameters-langu = lv_sf_langu.
ls_control_parameters-no_open = abap_true.
ls_control_parameters-no_close = abap_true.
ls_control_parameters-getotf = abap_true.

DATA(ls_output_options) = is_output_options.

IF NOT ls_printer_profile_data IS INITIAL.
ls_output_options = CORRESPONDING #( ls_printer_profile_data ).
ENDIF.

DATA : ls_fp_outputparams TYPE sfpoutputparams,
lt_pdf_table TYPE tfpcontent,
lv_gui TYPE answer,
ls_result TYPE sfpjoboutput.

ls_fp_outputparams-dest = ls_output_options-tddest.
ls_fp_outputparams-nodialog = is_control_parameters-no_dialog.
ls_fp_outputparams-reqnew = ls_output_options-tdnewid.
ls_fp_outputparams-preview = is_control_parameters-preview.

IF is_control_parameters-preview IS INITIAL.
ls_fp_outputparams-reqimm = ls_output_options-tdimmed. " To print on actuals
ENDIF.

* GUI connection enabled?
CALL FUNCTION 'RFC_IS_GUI_ON'
EXPORTING
login_check = abap_false
IMPORTING
on = lv_gui.
IF lv_gui NE 'Y' AND is_control_parameters-preview IS NOT INITIAL.
ls_fp_outputparams-getpdf = 'M'.
ls_fp_outputparams-bumode = '-'.
ENDIF.

* Sets the output parameters and opens the spool job
CALL FUNCTION 'FP_JOB_OPEN' "& Form Processing: Call Form
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.
RETURN.
ENDIF.

** Logic for all the required exporting parameters (Here bdh, bdi, bdh_cond, bdi_cond : related to CRM billing) will be filled up as per business functionality.

DO ls_output_options-tdcopies TIMES.

CALL FUNCTION lv_adobe_fm_name
EXPORTING
archive_index = is_archive_index
archive_index_tab = ct_archive_index_tab
archive_parameters = is_archive_parameters
control_parameters = ls_control_parameters
mail_appl_obj = is_mail_appl_obj
mail_recipient = is_mail_recipient
mail_sender = is_mail_sender
output_options = ls_output_options
user_settings = ip_user_settings
bdh = <s_bdh>
bdi = <t_bdi>
bdh_cond = lt_bdh_cond
bdi_cond = lt_bdi_cond
IMPORTING
document_output_info = es_document_output_info
job_output_info = es_job_output_info
job_output_options = es_job_output_options
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
* add an error message to processing protocol
CASE sy-subrc.
WHEN 1.
MESSAGE e016(sppf_media) INTO lv_dummy.
WHEN 2.
MESSAGE e017(sppf_media) WITH lv_adobe_fm_name INTO lv_dummy.
WHEN 3.
MESSAGE e018(sppf_media) WITH lv_adobe_fm_name INTO lv_dummy.
ENDCASE.
CALL METHOD cl_log_ppf=>add_message
EXPORTING
ip_problemclass = '1'
ip_handle = ip_application_log.
ENDIF.
ENDDO.

*&---- Close the spool job
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.
es_job_output_info = CORRESPONDING #( ls_result ).
ENDIF.

IF lv_gui NE 'Y' AND is_control_parameters-preview IS NOT INITIAL.
CALL FUNCTION 'FP_GET_PDF_TABLE'
IMPORTING
e_pdf_table = lt_pdf_table.

LOOP AT lt_pdf_table ASSIGNING FIELD-SYMBOL(<fs_pdf>).
CALL METHOD get_pdf_to_otf(
EXPORTING
iv_pdf = <fs_pdf>
IMPORTING
et_otf_data = DATA(li_otf) ).
ENDLOOP.

es_job_output_info-otfdata[] = li_otf.
ENDIF.

* get error table
CALL FUNCTION 'SSF_READ_ERRORS'
IMPORTING
errortab = et_error_tab.

 

Let's see the print preview or process the action (Actions in Billing) to see the outcome with multiple copies (let's say three copies) of the form (In the same way how, we execute smart form).


Here, we can see a printout that was created directly in PDF format with three copies (image showing as Document 1 of 3). To view each of the three copies separately, click Next Document.




And same document in WEBUI screen.


This brings the functionality to a close.

I appreciate you reading the content. I hope you enjoyed reading it. Please feel free to offer your insightful thoughts and recommendations.
4 Comments
Labels in this area