Erzeugen von Adobe PDF Formularen im WebUI des SAP CRM
Das SAP CRM System ist im Formulardruck im Gegensatz zu anderen SAP Systemen, wie z.B. SAP EWM, z.Zt. ausschließlich auf den Druck von Formularen mit Smart Forms ausgerichtet. Im Customizing kann man im SAP CRM Standard auch nur Formulare und Methoden für den Druck von Smart Forms hinterlegen.
Problemstellung
Will man auch in SAP Adobe Formulare anstatt von Smart Forms verwenden, dann sind folgende Aufgaben zu meistern
- Anstatt eines Smart Forms muss in der im Customizing hinterlegten Methode ein Adobe Form erzeugt werden.
- Zur Anzeige des Formulars im WebUI ist das erzeugte Formular im OTF-Format an die Methode zur Druckbildansicht weiterzureichen.
Im folgenden Tutorial wird erklärt, wie man im SAP CRM Formulare mit einem Adobe Form erzeugen kann.
Szenario
Im SAP CRM wird ein Servicevorgang als Ticket erfasst. Ist das Ticket abgeschlossen, wird dem Kunden ein Abschlussbericht übermittelt. Der Abschlussbericht soll als PDF Formular mit den Werkzeugen der SAP Adobe Forms erzeugt werden. Sowohl Druck als auch eine Druckbildansicht des Formulars im SAP CRM WebUI sollen möglich sein.
Anlegen einer Klasse und einer Methode zum Erzeugen des Adobe Forms
Im Customizing sucht man in den Aktionen zum Vorgang die Klasse, die den Formulardruck abbildet. In unserem Fall war dies die Klasse CL_DOC_PROCESSING_CRM_ORDER mit Methode CRM_SRVORDER_EXEC_SMART_FORM.
Nun kopiert man die Klasse CL_DOC_PROCESSING_CRM_ORDER in eine Z-Klasse bzw. leitet eine eigene Z-Klasse als Unterklasse zur Oberklasse CL_DOC_PROCESSING_CRM_ORDER ab. Anschließend kopiert man Methode CRM_SRVORDER_EXEC_SMART_FORM in Methode CRM_SRVORDER_EXEC_PDF_FORM.
Anlegen eines Funktionsbausteins zum Erzeugen des Adobe Formulars
Im Funktionsbaustein Z_FRM_PRINT_FINAL_REPORT wird nun das Coding untergebracht, um das Adobe Form (PDF Formular) zu erzeugen. Die Schnittstelle wird 1 : 1 aus der Schnittstelle zum Smart Form aus der Methode CRM_SRVORDER_EXEC_SMART_FORM übernommen.
FUNCTION z_frm_print_final_report. *"---------------------------------------------------------------------- *"*"Lokale Schnittstelle: *" IMPORTING *" VALUE(PV_FONAM) TYPE FPNAME OPTIONAL *" VALUE(IS_OUTPUT_OPTIONS) TYPE SSFCOMPOP OPTIONAL *" VALUE(IS_CONTROL_PARAMS) TYPE SSFCTRLOP OPTIONAL *" VALUE(ORDERADM_H) TYPE CRMT_OUTPUT_ORDERADM_H_COM OPTIONAL *" VALUE(ACTIVITY_H) TYPE CRMT_OUTPUT_ACTIVITY_H_COM OPTIONAL *" VALUE(OPPORT_H) TYPE CRMT_OUTPUT_OPPORT_H_COM OPTIONAL *" VALUE(ORGMAN_H) TYPE CRMT_OUTPUT_ORGMAN_H_COM OPTIONAL *" VALUE(PARTNER_H) TYPE CRMT_OUTPUT_PARTNER_H_COMT OPTIONAL *" VALUE(PRICINGDATA_H) TYPE CRMT_OUTPUT_PRICINGDATA_H_COM *" OPTIONAL *" VALUE(SALES_H) TYPE CRMT_OUTPUT_SALES_H_COM OPTIONAL *" VALUE(SHIPPING_H) TYPE CRMT_OUTPUT_SHIPPING_H_COM OPTIONAL *" VALUE(PAYPLAN_D_H) TYPE CRMT_OUTPUT_PAYPLAN_D_H_COMT OPTIONAL *" VALUE(CUMULAT_H) TYPE CRMT_OUTPUT_CUMULAT_H_COM OPTIONAL *" VALUE(CUSTOMER_H) TYPE CRMT_OUTPUT_CUSTOMER_H_COM OPTIONAL *" VALUE(ACS_H) TYPE CRMT_ACS_H_COM OPTIONAL *" VALUE(BILLING_H) TYPE CRMT_OUTPUT_BILLING_H_COMT OPTIONAL *" VALUE(CANCEL_H) TYPE CRMT_OUTPUT_CANCEL_H_COMT OPTIONAL *" VALUE(APPOINTMENT_H) TYPE CRMT_OUTPUT_APPOINTMENT_H_COMT *" OPTIONAL *" VALUE(BILLPLAN_D_H) TYPE CRMT_OUTPUT_BILLPLAN_D_H_COMT OPTIONAL *" VALUE(BILLPLAN_H) TYPE CRMT_OUTPUT_BILLPLAN_H_COMT OPTIONAL *" VALUE(STATUS_D_H) TYPE CRMT_OUTPUT_STATUS_D_H_COMT OPTIONAL *" VALUE(STATUS_H) TYPE CRMT_OUTPUT_STATUS_H_COMT OPTIONAL *" VALUE(SRV_SUBJECT_H) TYPE CRMT_OUTPUT_SRV_SUBJECT_H_COMT *" OPTIONAL *" VALUE(SRV_SUBJECT_I) TYPE CRMT_OUTPUT_SRV_SUBJECT_H_COMT *" OPTIONAL *" VALUE(SRV_REASON_H) TYPE CRMT_OUTPUT_SRV_REASON_H_COMT OPTIONAL *" VALUE(SRV_RESULT_H) TYPE CRMT_OUTPUT_SRV_RESULT_H_COMT OPTIONAL *" VALUE(SRV_REFOBJ_H) TYPE CRMT_OUTPUT_SRV_REFOBJ_H_COMT OPTIONAL *" VALUE(SRV_REFOBJ_I) TYPE CRMT_OUTPUT_SRV_REFOBJ_H_COMT OPTIONAL *" VALUE(ORDERADM_I) TYPE CRMT_OUTPUT_ORDERADM_I_COMT OPTIONAL *" VALUE(ORDERADM_I_IN) TYPE CRMT_OUTPUT_ORDERADM_I_IN_COMT *" OPTIONAL *" VALUE(ORDERADM_I_QT) TYPE CRMT_OUTPUT_ORDERADM_I_QT_COMT *" OPTIONAL *" VALUE(ORGMAN_I) TYPE CRMT_OUTPUT_ORGMAN_I_COMT OPTIONAL *" VALUE(PRICINGDATA_I) TYPE CRMT_OUTPUT_PRICINGDATA_I_COMT *" OPTIONAL *" VALUE(PRICING_I) TYPE CRMT_OUTPUT_PRICING_I_COMT OPTIONAL *" VALUE(PRODUCT_I) TYPE CRMT_OUTPUT_PRODUCT_I_COMT OPTIONAL *" VALUE(SALES_I) TYPE CRMT_OUTPUT_SALES_I_COMT OPTIONAL *" VALUE(SERVICE_I) TYPE CRMT_OUTPUT_SERVICE_I_COMT OPTIONAL *" VALUE(SCHEDLIN_I) TYPE CRMT_OUTPUT_SCHEDLIN_I_COMT OPTIONAL *" VALUE(SCHEDLIN_I_CF) TYPE CRMT_OUTPUT_SCHEDLIN_I_CF_COMT *" OPTIONAL *" VALUE(SHIPPING_I) TYPE CRMT_OUTPUT_SHIPPING_I_COMT OPTIONAL *" VALUE(PARTNER_I) TYPE CRMT_OUTPUT_PARTNER_I_COMT OPTIONAL *" VALUE(ITEM_CSTICS_I) TYPE CRMT_ITEM_CSTICS_TAB OPTIONAL *" VALUE(CUSTOMER_I) TYPE CRMT_OUTPUT_CUSTOMER_I_COMT OPTIONAL *" VALUE(BILLING_I) TYPE CRMT_OUTPUT_BILLING_I_COMT OPTIONAL *" VALUE(CANCEL_I) TYPE CRMT_OUTPUT_CANCEL_I_COMT OPTIONAL *" VALUE(FINPROD_I) TYPE CRMT_OUTPUT_FINPROD_I_COMT OPTIONAL *" VALUE(ORDPRP_I) TYPE CRMT_OUTPUT_ORDPRP_I_COMT OPTIONAL *" VALUE(APPOINTMENT_I) TYPE CRMT_OUTPUT_APPOINTMENT_I_COMT *" OPTIONAL *" VALUE(BILLPLAN_D_I) TYPE CRMT_OUTPUT_BILLPLAN_D_I_COMT OPTIONAL *" VALUE(BILLPLAN_I) TYPE CRMT_OUTPUT_BILLPLAN_I_COMT OPTIONAL *" VALUE(STATUS_I) TYPE CRMT_OUTPUT_STATUS_I_COMT OPTIONAL *" VALUE(WORKING_SET_E_S_BBP) TYPE /1CN/WORKING_SET_E_S_BBP_T *" OPTIONAL *" VALUE(LANGUAGE) TYPE SY-LANGU OPTIONAL *" VALUE(SERVICE_I_ASSI) TYPE CRMT_OUTPUT_SERVICE_I_ASS_COMT *" OPTIONAL *" EXPORTING *" VALUE(ES_RESULT) TYPE SFPJOBOUTPUT *" VALUE(ES_OUTPUT) TYPE FPFORMOUTPUT *" VALUE(ET_OTFDATA) TYPE TT_ITCOO *"---------------------------------------------------------------------- IF pv_fonam IS INITIAL. pv_fonam = 'ZFRM_SRV_ORD_FINAL_REPORT'. ENDIF. * Get function module ------------------------------------------------ * PERFORM get_fm_name USING pv_fonam CHANGING gv_fm_name gv_if_type. * JOP_OPEN ----------------------------------------------------------- * PERFORM job_open USING is_output_options. * Print form --------------------------------------------------------- * PERFORM print_form USING gv_fm_name pv_fonam is_output_options is_control_params orderadm_h activity_h opport_h orgman_h partner_h pricingdata_h sales_h shipping_h payplan_d_h cumulat_h customer_h acs_h billing_h cancel_h appointment_h billplan_d_h billplan_h status_d_h status_h srv_subject_h srv_subject_i srv_reason_h srv_result_h srv_refobj_h srv_refobj_i orderadm_i orderadm_i_in orderadm_i_qt orgman_i pricingdata_i pricing_i product_i sales_i service_i schedlin_i schedlin_i_cf shipping_i partner_i item_cstics_i customer_i billing_i cancel_i finprod_i ordprp_i appointment_i billplan_d_i billplan_i status_i working_set_e_s_bbp language service_i_assi CHANGING es_output. * JOB_CLOSE ---------------------------------------------------------- * PERFORM job_close CHANGING es_result. * Pdf-Daten noch in OTF für Druckansicht konvertieren ---------------- * PERFORM convert_pdf_2_otf USING es_output CHANGING et_otfdata. ENDFUNCTION. ***INCLUDE LZFRM_PRINT_FINAL_REPORTF01. *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form GET_FM_NAME *&---------------------------------------------------------------------* FORM get_fm_name USING pv_fonam TYPE fpname CHANGING gv_fm_name TYPE funcname gv_if_type TYPE fpinterfacetype. CALL FUNCTION 'FP_FUNCTION_MODULE_NAME' EXPORTING i_name = pv_fonam IMPORTING e_funcname = gv_fm_name e_interface_type = gv_if_type. ENDFORM. *&---------------------------------------------------------------------* *& Form JOB_OPEN *&---------------------------------------------------------------------* FORM job_open USING ps_output_options TYPE ssfcompop. gs_outparam-preview = ''. gs_outparam-nodialog = 'X'. gs_outparam-reqnew = 'X'. gs_outparam-getpdf = 'X'. gs_outparam-dest = 'LOCA'. CALL FUNCTION 'FP_JOB_OPEN' CHANGING ie_outputparams = gs_outparam EXCEPTIONS cancel = 1 usage_error = 2 system_error = 3 internal_error = 4 OTHERS = 5. IF sy-subrc <> 0. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form PRINT_FORM *&---------------------------------------------------------------------* FORM print_form USING gv_fm_name TYPE funcname pv_fonam TYPE fpname is_output_options TYPE ssfcompop is_control_params TYPE ssfctrlop orderadm_h TYPE crmt_output_orderadm_h_com activity_h TYPE crmt_output_activity_h_com opport_h TYPE crmt_output_opport_h_com orgman_h TYPE crmt_output_orgman_h_com partner_h TYPE crmt_output_partner_h_comt pricingdata_h TYPE crmt_output_pricingdata_h_com sales_h TYPE crmt_output_sales_h_com shipping_h TYPE crmt_output_shipping_h_com payplan_d_h TYPE crmt_output_payplan_d_h_comt cumulat_h TYPE crmt_output_cumulat_h_com customer_h TYPE crmt_output_customer_h_com acs_h TYPE crmt_acs_h_com billing_h TYPE crmt_output_billing_h_comt cancel_h TYPE crmt_output_cancel_h_comt appointment_h TYPE crmt_output_appointment_h_comt billplan_d_h TYPE crmt_output_billplan_d_h_comt billplan_h TYPE crmt_output_billplan_h_comt status_d_h TYPE crmt_output_status_d_h_comt status_h TYPE crmt_output_status_h_comt srv_subject_h TYPE crmt_output_srv_subject_h_comt srv_subject_i TYPE crmt_output_srv_subject_h_comt srv_reason_h TYPE crmt_output_srv_reason_h_comt srv_result_h TYPE crmt_output_srv_result_h_comt srv_refobj_h TYPE crmt_output_srv_refobj_h_comt srv_refobj_i TYPE crmt_output_srv_refobj_h_comt orderadm_i TYPE crmt_output_orderadm_i_comt orderadm_i_in TYPE crmt_output_orderadm_i_in_comt orderadm_i_qt TYPE crmt_output_orderadm_i_qt_comt orgman_i TYPE crmt_output_orgman_i_comt pricingdata_i TYPE crmt_output_pricingdata_i_comt pricing_i TYPE crmt_output_pricing_i_comt product_i TYPE crmt_output_product_i_comt sales_i TYPE crmt_output_sales_i_comt service_i TYPE crmt_output_service_i_comt schedlin_i TYPE crmt_output_schedlin_i_comt schedlin_i_cf TYPE crmt_output_schedlin_i_cf_comt shipping_i TYPE crmt_output_shipping_i_comt partner_i TYPE crmt_output_partner_i_comt item_cstics_i TYPE crmt_item_cstics_tab customer_i TYPE crmt_output_customer_i_comt billing_i TYPE crmt_output_billing_i_comt cancel_i TYPE crmt_output_cancel_i_comt finprod_i TYPE crmt_output_finprod_i_comt ordprp_i TYPE crmt_output_ordprp_i_comt appointment_i TYPE crmt_output_appointment_i_comt billplan_d_i TYPE crmt_output_billplan_d_i_comt billplan_i TYPE crmt_output_billplan_i_comt status_i TYPE crmt_output_status_i_comt working_set_e_s_bbp TYPE /1cn/working_set_e_s_bbp_t language TYPE sy-langu service_i_assi TYPE crmt_output_service_i_ass_comt CHANGING gs_output TYPE fpformoutput. * gs_docparms-country = ps_control_parameters-country. gs_docparms-langu = is_control_params-langu. CALL FUNCTION gv_fm_name EXPORTING /1bcdwb/docparams = gs_docparms iv_fonam = pv_fonam is_output_options = is_output_options is_control_params = is_control_params orderadm_h = orderadm_h activity_h = activity_h opport_h = opport_h orgman_h = orgman_h partner_h = partner_h pricingdata_h = pricingdata_h sales_h = sales_h shipping_h = shipping_h payplan_d_h = payplan_d_h cumulat_h = cumulat_h customer_h = customer_h acs_h = acs_h billing_h = billing_h cancel_h = cancel_h appointment_h = appointment_h billplan_d_h = billplan_d_h billplan_h = billplan_h status_d_h = status_d_h status_h = status_h srv_subject_h = srv_subject_h srv_reason_h = srv_reason_h srv_result_h = srv_result_h srv_subject_i = srv_subject_i srv_refobj_h = srv_refobj_h srv_refobj_i = srv_refobj_i orderadm_i = orderadm_i orderadm_i_qt = orderadm_i_qt orderadm_i_in = orderadm_i_in orgman_i = orgman_i pricingdata_i = pricingdata_i pricing_i = pricing_i product_i = product_i sales_i = sales_i service_i = service_i schedlin_i = schedlin_i schedlin_i_cf = schedlin_i_cf shipping_i = shipping_i partner_i = partner_i item_cstics_i = item_cstics_i customer_i = customer_i billing_i = billing_i cancel_i = cancel_i finprod_i = finprod_i ordprp_i = ordprp_i appointment_i = appointment_i billplan_d_i = billplan_d_i billplan_i = billplan_i status_i = status_i working_set_e_s_bbp = working_set_e_s_bbp language = language service_i_assi = service_i_assi IMPORTING /1bcdwb/formoutput = gs_output 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. ENDFORM. *&---------------------------------------------------------------------* *& Form JOB_CLOSE *&---------------------------------------------------------------------* FORM job_close CHANGING es_result TYPE sfpjoboutput. CALL FUNCTION 'FP_JOB_CLOSE' IMPORTING e_result = es_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. ENDFORM.
Wichtig ist, dass beim Erzeugen der Druckbildansicht wird vor JOB_OPEN der Parameter GETPDF = X gesetzt wird.
Der Funktionsbaustein wird in Methode CRM_SRVORDER_EXEC_PDF_FORM dort eingebaut, wo sonst das Erzeugen des Smart Forms angestoßen wird. Das Coding für das Erzeugen des Smart Forms wird entfernt bzw. auskommentiert.
Formatieren der PDF-Datei für die Anzeige im SAP CRM WebUI
Zum Anzeigen des Adobe Forms im SAP CRM WebUI wird der Funktionsbaustein CONVERT_PDF verwendet, wo das Formular im OTF-Format in das Format PDF gewandelt wird. Da wir jedoch das Adobe Form bereits als fertige PDF-Datei bekommen, muss die PDF-Datei so aufbereitet werden, dass der Funktionsbaustein CONVERT_PDF die Datei bereits als fertige PDF-Datei erkennt und nicht weiter konvertiert. Geschieht dies nicht, bekommt man im SAP CRM WebUI eine Fehlermeldung.
In Routine CONVERT_PDF_2_OTF wird die PDF-Datei als binäres Objekt in eine interne Tabelle vom Format ITCOO überführt.
*&---------------------------------------------------------------------* *& Form CONVERT_PDF_2_OTF *&---------------------------------------------------------------------* FORM convert_pdf_2_otf USING es_output TYPE fpformoutput CHANGING et_otfdata TYPE tt_itcoo. types: begin of ty_tab, line(72) type c, end of ty_tab. DATA: lt_lines TYPE TABLE OF tline, ls_lines TYPE tline, ls_otfdata TYPE itcoo, lv_filesize TYPE i, ls_tab type ty_tab, lt_tab type table of ty_tab. DATA: xcontent TYPE xstring . DATA: content TYPE string . DATA: rows TYPE STANDARD TABLE OF string, wa_rows TYPE string. DATA: conv TYPE REF TO cl_abap_conv_in_ce. DATA: lt_content TYPE string_table . CALL FUNCTION 'SCMS_XSTRING_TO_BINARY' EXPORTING buffer = es_output-pdf * APPEND_TO_TABLE = ' ' IMPORTING OUTPUT_LENGTH = lv_filesize tables binary_tab = lt_tab. loop at lt_tab into ls_tab. move ls_tab to ls_otfdata. append ls_otfdata to et_otfdata. endloop. exit. REFRESH lt_lines. CALL FUNCTION 'CONVERT_OTF' EXPORTING format = 'PDF' * MAX_LINEWIDTH = 132 * ARCHIVE_INDEX = ' ' * COPYNUMBER = 0 * ASCII_BIDI_VIS2LOG = ' ' * PDF_DELETE_OTFTAB = ' ' * PDF_USERNAME = ' ' * PDF_PREVIEW = ' ' * USE_CASCADING = ' ' * MODIFIED_PARAM_TABLE = IMPORTING bin_filesize = lv_filesize * bin_file = es_output-pdf TABLES otf = et_otfdata lines = lt_lines EXCEPTIONS err_max_linewidth = 1 err_format = 2 err_conv_not_possible = 3 err_bad_otf = 4 OTHERS = 5. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDFORM.
Ergebnis
Das Adobe Formular wird jetzt im SAP CRM WebUI in der Druckbildansicht korrekt angezeigt.
Weitere Informationen