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: 
amal_aravind123
Explorer

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.

  • Go to the TCode : BSP_WD_CMPWB and create a component (say ZCOMP_PRINT) by clicking the create button.
  • Input values for Description and Window Name.
  • Select the package and save all the requests that follows( 3-4 Create Object entry(Selection of Package) and transport request selection will be there ) Save it all under same TR .
  • Create a View named ‘Print’ inside the component Under the Component structure browser.
  • Click Continue.

  • Give the view a name (lets say Print) and press continue till the Add value node tab comes, skipping ‘Add Model Node’ tab.

  • Add the value node name in the ‘Add value node’ tab (say Print) and press continue till   ‘Add Value Attributes’ tab.

  • Enter the value attributes as shown below.

  • Press continue till Select View type and select Form View with configurable check box checked as shown below.

  • Press continue and then complete button which looks like the one given below.

  • Save all the requests that follows in to the previous package and transport requests where the component was stored initially.
  • Double click on the print view on Component Structure Browser as shown to get the View Structure of the Print view which we created in above steps.
  • Write the code for creating a button on the editor as shown below(You can insert code going to edit mode by clicking the Edit pencil button) and activate it by .

<thtmlb:button
id       = "PRINT"
onClick  = "PRINT"
design  =
"EMPHASIZED"
text     = "Rrint"
tooltip  =
"Rrint"
enabled =
"TRUE"
/>

  • Create an event named ‘PRINT’(Case sensitive with the ‘PRINT’ given for onClick in the above code) .

  • Double click on the Print event and write the following code and activate it.

METHOD eh_onprint.
 
DATAlr_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.

  • Go to the configuration tab of the Print View and click on ‘Edit’ button to get the editable window and click the button ‘Show Available Fields’, which will give you the field  ‘Number’ of type INT4 which was added in context node PRINT at time of view creation.

  • Select the button and add to the screen as shown and SAVE the changes by clicking save button.

  • Go to Runtime Repository editor on the side bar of screen and add the view to the main window and make it default.

  • Select View ‘Print’ from the F4 Pop Up.

  • Flag the View as default.

  • Add the component GSURLPOPUP to component Usage for the pop up window under ID: CUGSURLPopup, Component : GSURLPOPUP and save the Runtime Repository Editor from the save button below the tab .

Step 2: Create a simple SMART-FORM to display the input data entered . 

  • Goto the TCode SMARTFORMS and create a sample smart-form (Say ZPRINT).

  • Save the SMART_FORM to the package and the transport request that follows.
  • Go to Form Interface and add the import parameter PRINT of type INT4 as shown.

  • Create a Text box in the main window.

  • Insert the import parameter Print in to the text field added and activate the smart form.

  • Save, Activate and test the smart-form, you should be getting similar kind of output.

Step 3: Create SICF service to call the smart form, convert it to *.PDF, create url and return it to Web UI layer.

  • Go to the TCode SICF and enter the service path as /sap/crm/ , Service name: CRM_PDF_PRINT and execute.

  • Double click the service CRM_PDF_PRINT and see the handler class.

  • Come back and copy the service and paste it in different name (say zcrm_pdf).

  • Now the service is copied in clipboard, rename the current service ‘CRM_PDF_PRINT’ to a custom service (say ZCRM_PDF) and then paste the original service stored in clipboard under the same tree at same place(as shown in step 5 below).

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.

  • Now paste the service crm_pdf_print stored in clipboard at the same place so that both the services(zcrm_pdf and crm_pdf_print) are available at same place.Activate both services.

  • Clear the service name field from the Filter Details block and click apply to see all the services. The service zcrm_pdf will be available in the path default_host > sap > crm.

  • Go to TCode SE24 and make a copy of the handler class (CL_CRM_PREVIEW_PDF), which in the handler class for the standard service crm_pdf_print.

  • Go to the method IF_HTTP_EXTENSION~HANDLE_REQUEST of the class and replace the current code with the below code.

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

  • Now in the method GET_PDF of the same class(ZCL_CRM_PREVIEW_PDF) paste the below code.

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.................*

  • Rename the handler class in SICF service we created (zcrm_pdf) from CL_CRM_PREVIEW_PDF to ZCL_CRM_PREVIEW_PDF (Path : zcrm_pdf>Handler List tab ).

  • The development is complete now you may go to the component and test the same. Go to the T-CODE : BSP_WD_CMPWB type the component name in the space provided and execute it.

  • You will be getting the browser opened with the component as shown below. Type some input number in the space provided and press the ‘Print’ button to display the SMARTFORM in a popup.

OUTPUT

9 Comments
Labels in this area