Document Name:
CRM Web UI – Smart-Form call from a Z-Component
Objective:
To call a Smart-Form from Web UI layer of a Z-Component on click of a button.
Description:
This document will guide through the steps for calling a smart-form from a Z-Component from WEB UI layer on click of a button, where the input of the smart-form is entered by user at runtime.
Detailed Steps: Creating a component that calls a Smart-Form
Step 1: Create a simple component with an input field and button.
<thtmlb:button
id = "PRINT"
onClick = "PRINT"
design = "EMPHASIZED"
text = "Rrint"
tooltip = "Rrint"
enabled = "TRUE"
/>
METHOD eh_onprint.
DATA: lr_entity TYPE REF TO if_bol_bo_property_access,
lr_col TYPE REF TO if_bol_bo_col,
lv_lot TYPE string,
lv_query TYPE string,
lv_url TYPE string,
lv_title TYPE string,
lr_obj TYPE REF TO if_bol_bo_property_access,
lr_cn TYPE REF TO cl_bsp_wd_context_node,
ls_params TYPE crmt_gsurlpopup_params,
lr_popup TYPE REF TO if_bsp_wd_popup.
lr_entity ?= me->typed_context->print->collection_wrapper->get_current( ).
IF lr_entity IS BOUND.
lv_lot = lr_entity->get_property_as_string( ‘PRINT’ ).
IF lv_lot IS NOT INITIAL.
CONCATENATE ‘scenario=P&guid=’ lv_lot INTO lv_query.
lv_url = cl_crm_web_utility=>create_url(
iv_path = ‘/sap/crm/zcrm_pdf’
iv_query = lv_query
iv_in_same_session = ‘X’ ).
IF lv_url IS NOT INITIAL.
lv_title = cl_wd_utilities=>get_otr_text_by_alias( ‘CRM_UIU_BT_GEN/PRINT_PREVIEW_POPUP_TITLE’ ). “#EC NOTEXT
lr_popup = me->comp_controller->window_manager->create_popup(
iv_interface_view_name = ‘GSURLPOPUP/MainWindow’
iv_usage_name = ‘CUGSURLPopup’
iv_title = lv_title ).
lr_cn = lr_popup->get_context_node( ‘PARAMS’ ).
lr_obj = lr_cn->collection_wrapper->get_current( ).
ls_params-url = lv_url.
ls_params-height = ‘700’. “#EC NOTEXT
lr_obj->set_properties( ls_params ).
lr_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_plain ).
lr_popup->set_window_width( 700 ).
lr_popup->set_window_height( 700 ).
lr_popup->open( ).
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
Step 2: Create a simple SMART-FORM to display the input data entered .
Step 3: Create SICF service to call the smart form, convert it to *.PDF, create url and return it to Web UI layer.
Note : Be careful on this steps else you may resulting in deletion of standard service. If in doubt you may create a service from Create Host/Service from the button above at the same place with the configuration in the crm_pdf_print service.
Code :
method if_http_extension~handle_request.
data: ls_phio type skwf_io,
lt_file_info type sdokfilacis,
ls_file_info like line of lt_file_info,
lv_file_name type sdok_filnm,
lv_mime_type type w3conttype,
lv_file_size type sdok_fsize,
lt_contents type sdokcntbins,
ls_contents type sdokcntbin,
ls_error type skwf_error,
lv_error_msg type string,
lv_chunksize type sybin2,
xwa type xstring,
xwa_len type i,
lv_contenttype type string,
lv_filename type string,
lv_contentdisposition type string,
lv_appl_ns type string,
lt_header_fields type tihttpnvp,
lt_form_fields type tihttpnvp,
lv_qry_string type string,
ls_scenario type string,
lv_devtype type rspoptype,
lv_print_dest type rspopname,
begin of ls_attach_key,
object_id type soodk,
attach_id type soodk,
end of ls_attach_key,
ls_attach_header type sood2,
lt_objcont type standard table of soli,
ls_objcont like line of lt_objcont,
ls_size type sood-objlen,
ls_lines type i,
ls_len type i,
lv_fn_length type i,
lv_fe_length type i,
ls_guid type crmt_object_guid,
ls_guid_str type string,
ls_smart_form type tdsfname,
ls_class type seoclsname,
ls_method type seocmpname,
ls_action_guid type string,
lr_action_ppf type ref to if_action_ppf.
data xwa_str type string.
data : ls_header_guid type string,
lv_pdf_xstring type xstring,
lv_pdf_length type i,
l_bin type standard table of sdokcntbin.
ls_header_guid = server->request->get_form_field( 'guid' ).
call method me->get_pdf
exporting
iv_guid = ls_header_guid
importing
ev_contents = lv_pdf_xstring.
call function 'SCMS_XSTRING_TO_BINARY'
exporting
buffer = lv_pdf_xstring
importing
output_length = lv_pdf_length
tables
binary_tab = l_bin.
lv_file_size = lv_pdf_length.
lv_contenttype = 'application/pdf'.
ls_guid_str = ls_header_guid.
concatenate ls_guid_str '.pdf' into lv_filename.
lv_file_name = lv_filename.
server->response->append_data(
data = lv_pdf_xstring
length = lv_pdf_length ).concatenate 'inline; filename=' lv_filename
into lv_contentdisposition.
call method server->response->set_header_field
exporting
name = 'content-disposition'
value = lv_contentdisposition.
call method server->response->set_header_field
exporting
name = 'content-type'
value = lv_contenttype.
call method server->response->set_header_field
exporting
name = 'content-filename'
value = lv_filename.
server->response->delete_header_field(
name = 'Cache-Control' ). "#EC NOTEXT
server->response->delete_header_field(
name = 'Expires' ).
endmethod. "IF_HTTP_EXTENSION~HANDLE_REQUEST
Code:
method get_pdf.
data lt_otfdata type tsfotf.
data lt_pdf_lines type standard table of tline.
data: it_otf type standard table of itcoo,
it_docs type standard table of docs,
it_lines type standard table of tline.
data:
st_job_output_info type ssfcrescl,
st_document_output_info type ssfcrespd,
st_job_output_options type ssfcresop,
st_output_options type ssfcompop,
st_control_parameters type ssfctrlop,
v_len_in type so_obj_len,
v_language type sflangu value 'E',
v_e_devtype type rspoptype,
v_bin_filesize type i,
v_name type string,
v_path type string,
v_fullpath type string,
v_filter type string,
v_uact type i,
v_guiobj type ref to cl_gui_frontend_services,
v_filename type string,
v_fm_name type rs38l_fnam,
c_formname type tdsfname ,
lv_st_job_output_info type ssfcrescl-otfdata,
lv_pdf type xstring ,* pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE,
ls_print type int4.
c_formname = 'ZPRINT' .
call function 'SSF_GET_DEVICE_TYPE'
exporting
i_language = v_language
i_application = 'SAPDEFAULT'
importing
e_devtype = v_e_devtype.
st_output_options-tdprinter = v_e_devtype.
st_control_parameters-no_dialog = 'X'.
st_control_parameters-getotf = 'X'.*.................GET SMARTFORM FUNCTION MODULE NAME.................*
OUTPUT
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |