Skip to Content

Tcode:  SICF

/wp-content/uploads/2012/04/1_94427.png

/wp-content/uploads/2012/04/2_94428.png

Double click on the selected one.

/wp-content/uploads/2012/04/3_94429.png

/wp-content/uploads/2012/04/4_94433.png

/wp-content/uploads/2012/04/5_94434.png

/wp-content/uploads/2012/04/6_94435.png

/wp-content/uploads/2012/04/7_94436.png

In SE24

ZCL_ASP_PREVIEW_PDF is copy from CL_CRM_PREVIEW_PDF.

*****************************************************************************

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,
ls_filename     
TYPE dsvasdocid,
ls_filename_ext 
TYPE dsvasdocid,
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_activity  
TYPE string,
lr_action_ppf   
TYPE REF TO if_action_ppf.

*   Distinguish between Kpro, SAPoffice, and printing
ls_scenario = server->request->get_form_field(
‘scenario’ ).
IF ls_scenario IS INITIAL.
CALL METHOD server->request->get_form_data
EXPORTING
name =
‘scenario’
CHANGING
data = ls_scenario.
ENDIF.

*     Print Scenario
IF ls_scenario = ‘P’.
lv_print_dest =
‘lp01’.                                “#EC NOTEXT

ls_activity = server->request->get_form_field( ‘activity’ ).

IF ls_activity IS NOT INITIAL.
get_pdf(
EXPORTING
iv_guid = ls_activity
IMPORTING
ev_size               = xwa_len
ev_contents           = xwa
et_messages           = lt_objcont
).
ENDIF.

IF sy-subrc <> 0 OR xwa_len <= 0.
REFRESH lt_contents.
ls_objcont = cl_bsp_runtime=>get_otr_text(
‘CRM_KNOWLEDGE/SMARTFORM_ERROR’ ). “#EC NOTEXT
INSERT ls_objcont INTO lt_objcont INDEX 1.

ls_len = LINES( lt_objcont ) * 255.

CALL FUNCTION ‘SCMS_FTEXT_TO_BINARY’
EXPORTING
input_length    = ls_len
append_to_table =
‘X’
IMPORTING
output_length   = ls_len
TABLES
ftext_tab       = lt_objcont
binary_tab      = lt_contents
EXCEPTIONS
failed          =
1
OTHERS          = 2.

lv_file_size = ls_len.
lv_contenttype = ‘text/plain’.                       “#EC NOTEXT
ELSE.
lv_file_size = xwa_len.
lv_contenttype =
‘application/pdf’.                  “#EC NOTEXT

CONCATENATE ls_guid_str ‘.pdf’ INTO lv_filename.
lv_file_name = lv_filename.

server->response->append_data(
data   = xwa
length = xwa_len ).

CLEAR lt_contents. REFRESH lt_contents.
ENDIF.
ENDIF.

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.

*  **********************************************************
*   Content Tabelle (Byte Arrays) rausschreiben
*  **********************************************************
lv_chunksize =
1022.
LOOP AT lt_contents INTO ls_contents.

MOVE ls_contents-line TO xwa.

xwa_len = lv_file_size – ( lv_chunksize * ( sy-tabix – 1 ) ).

IF xwa_len >= lv_chunksize.
xwa_len = lv_chunksize.
ENDIF.

server->response->append_data( data   = xwa
length = xwa_len ).

ENDLOOP.

*  **********************************************************
*   Response beenden
*  **********************************************************

server->response->delete_header_field(
name = ‘Cache-Control’ ).                      “#EC NOTEXT

server->response->delete_header_field(
name = ‘Expires’ ).                            “#EC NOTEXT

ENDMETHOD.                    “IF_HTTP_EXTENSION~HANDLE_REQUEST

*****************************************************************************       ***************************************************************

METHOD GET_PDF.

DATA:   FM_NAME TYPE RS38L_FNAM.

* dck
DATA:      GV_OBJID TYPE CRMD_ORDERADM_H-OBJECT_ID.

* dck
DATA: GT_ORDERADM_H TYPE CRMT_ORDERADM_H_DU_TAB,
GS_ORDERADM_H
TYPE CRMD_ORDERADM_H,
GT_ACTIVITY_H
TYPE CRMT_ACTIVITY_H_WRKT,
GT_SERVICE_OS
TYPE CRMT_SRV_OSSET_WRKT,
GT_TEXT
TYPE CRMT_TEXT_WRKT,
GT_STATUS
TYPE CRMT_STATUS_WRKT,
*      GT_ACTIVITY_H TYPE CRMT_ACTIVITY_H_DU_TAB.
GT_APPOINTMENT
TYPE CRMT_APPOINTMENT_WRKT,
GT_PARTNER
TYPE CRMT_PARTNER_EXTERNAL_WRKT,
GUIDLIST
TYPE CRMT_OBJECT_GUID_TAB,
CV_LOG_HANDLE
TYPE  BALLOGHNDL.

* Standard structures
DATA: LS_ACTIVITY_H TYPE CRMT_ACTIVITY_H_WRK.
DATA: LS_ORDERADM_H TYPE CRMT_ORDERADM_H_WRK.
DATA: LS_PARTNER TYPE CRMT_PARTNER_EXTERNAL_WRK.
DATA: LS_STATUS TYPE CRMT_STATUS_WRK.
DATA: LS_SERVICE_OS TYPE CRMT_SRV_OSSET_WRK.
DATA: LS_TEXT TYPE CRMT_TEXT_WRK.
DATA: LS_APPOINTMENT TYPE CRMT_APPOINTMENT_WRK.

* Enhanced communication structures
DATA: LS_APPOINTMENT_COM TYPE CRMT_APPOINTMENT_COM.

* BAPI data structures
DATA:
GUID
TYPE TABLE OF BAPIBUS20001_GUID_DIS INITIAL SIZE 0,
HEADER TYPE TABLE OF BAPIBUS2000110_HEADER_DIS INITIAL SIZE 0,
PARTNER
TYPE TABLE OF BAPIBUS20001_PARTNER_DIS INITIAL SIZE 0,
ORGANISATION
TYPE TABLE OF BAPIBUS20001_ORGMAN_DIS INITIAL SIZE 0,
APPOINTMENT
TYPE TABLE OF BAPIBUS20001_APPOINTMENT_DIS INITIAL SIZE 0,
TEXT TYPE TABLE OF BAPIBUS20001_TEXT_DIS INITIAL SIZE 0,
SERVICEOS
TYPE TABLE OF BAPIBUS20001_SERVICE_OS_DIS INITIAL SIZE 0,
STATUS
TYPE TABLE OF BAPIBUS20001_STATUS_DIS INITIAL SIZE 0,
RETURN TYPE TABLE OF BAPIRET2 INITIAL SIZE 0,
WA_CTRLOP
TYPE SSFCTRLOP,       ” Smart Forms: Control structure
WA_OUTOPT
TYPE SSFCOMPOP,       ” SAP Smart Forms: Smart Composer (transfer) options.
LT_OTFDATA
TYPE SSFCRESCL,       ” Smart Forms: Return value at end of form printing
Lt_pdf_tab
type table of tline,  ” SAPscript: Text Lines
Lt_otf
TYPE table of itcoo.      ” OTF Structure
* Variables used to pass to GUI_DOWNLOAD
DATA: w_bin_filesize TYPE i.

GV_OBJID = IV_GUID.
*****select staement and get data

*REFRESH GUIDLIST.
*APPEND LS_ORDERADM_H-GUID TO GUIDLIST.
APPEND LS_ORDERADM_H-GUID TO GUID.

CALL FUNCTION ‘BAPI_ACTIVITYCRM_GETDETAILMULT’
TABLES
RETURN       = RETURN
STATUS       = STATUS
*     SERVICE_OS   = SERVICEOS
TEXT         = TEXT
*     APPOINTMENT  = APPOINTMENT
ORGANISATION = ORGANISATION
PARTNER      = PARTNER
HEADER       = HEADER
GUID         = GUID
EXCEPTIONS
OTHERS       = 01.
CASE SY-SUBRC.
WHEN 0.            ” OK
WHEN OTHERS.       ” to be implemented
ENDCASE.

READ TABLE GT_ORDERADM_HINDEX 1 INTO LS_ORDERADM_H.
READ TABLE GT_ACTIVITY_H INDEX 1 INTO LS_ACTIVITY_H.
READ TABLE GT_PARTNER INDEX 1 INTO LS_PARTNER.
READ TABLE GT_STATUS INDEX 1 INTO LS_STATUS.
READ TABLE GT_SERVICE_OS INDEX 1 INTO LS_SERVICE_OS.
READ TABLE GT_APPOINTMENT INDEX 1 INTO LS_APPOINTMENT.
* mehrere Texte handhaben können
READ TABLE GT_TEXT INDEX 1 INTO LS_TEXT.

IF SY-LANGU EQ ‘F’.


ELSE.
* print data
CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
EXPORTING
FORMNAME           = L_FORMNAME

*       variant            = ‘ ‘
*       direct_call        = ‘ ‘
IMPORTING
FM_NAME            = FM_NAME
EXCEPTIONS
NO_FORM            =
1
NO_FUNCTION_MODULE =
2
OTHERS             = 3.
IF SY-SUBRC <> 0.
*   error handling
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
EXIT.
ENDIF.
ENDIF.
WA_CTRLOP-GETOTF =
‘X’.
WA_CTRLOP-NO_DIALOG =
‘X’.
WA_OUTOPT-TDNOPREV =
‘X’.
CALL FUNCTION FM_NAME
EXPORTING
*     archive_index        =
*     archive_parameters   =
CONTROL_PARAMETERS   = WA_CTRLOP
*     mail_appl_obj        =
*     mail_recipient       =
*     mail_sender          =
OUTPUT_OPTIONS       = WA_OUTOPT
USER_SETTINGS        =
‘X’
*     ACTIVITY_H           = LS_ACTIVITY_H
*     ORDERADM_H           = LS_ORDERADM_H
*     ACTIVITY_H           = GT_ACTIVITY_H
*     APPOINTMENT          = LS_APPOINTMENT
*     PARTNER              = GT_PARTNER
*     STATUS               = LS_STATUS
*     SERVICE_OS           = LS_SERVICE_OS
*     TEXTKEY              = LS_TEXT
IMPORTING
*     document_output_info =
JOB_OUTPUT_INFO      = LT_OTFDATA
*     job_output_options   =
TABLES
RETURN               = RETURN
STATUS               = STATUS
SERVICE_OS           = SERVICEOS
TEXT                 = TEXT
APPOINTMENT          = APPOINTMENT
ORGANISATION         = ORGANISATION
PARTNER              = PARTNER
HEADER               = HEADER
GUID                 = GUID
EXCEPTIONS
FORMATTING_ERROR     =
1
INTERNAL_ERROR       =
2
SEND_ERROR           =
3
USER_CANCELED        =
4
OTHERS               = 5.
IF SY-SUBRC <> 0.
*   error handling
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Lt_otf[] = Lt_otfdata-otfdata[].
CALL FUNCTION ‘CONVERT_OTF’
EXPORTING
format                = ‘PDF’
*      max_linewidth         = 132
IMPORTING
bin_filesize          = ev_size
BIN_FILE              = ev_contents
TABLES
otf                   = Lt_otf
lines                 = Lt_pdf_tab
EXCEPTIONS
err_max_linewidth     =
1
err_format            =
2
err_conv_not_possible =
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.
ENDMETHOD.

***************************************************************

Print Functionality we need to write logic in event handler of the print method.

********************************************************************

METHOD EH_PRINT.
DATA L_SPLD TYPE RSPOPNAME.

SELECT SINGLE SPLD FROM USR01 INTO L_SPLD WHERE BNAME = SY-UNAME.
IF L_SPLD IS INITIAL.
LV_MSGSRV = CL_BSP_WD_MESSAGE_SERVICE=>GET_INSTANCE( ).
LV_MSGSRV->ADD_MESSAGE( IV_MSG_TYPE       =
‘I’
IV_MSG_ID         =
‘ZCRM’
IV_MSG_NUMBER     =
‘000’
IV_MSG_V1     =
‘Printer not defined in your user master’ ).
ELSE.
*    SUBMIT ZCRM_BUSACTFORM_ASP_REFFERAL
*              WITH GV_OBJID = GT_KING-ACTIVITY AND RETURN.
DATA :LV_QUERY TYPE STRING,
LV_TITLE
TYPE STRING,
LV_URL
TYPE STRING,
LR_CN
TYPE REF TO CL_BSP_WD_CONTEXT_NODE,
LR_OBJ
TYPE REF TO IF_BOL_BO_PROPERTY_ACCESS,
LR_POPUP
TYPE REF TO IF_BSP_WD_POPUP,
LS_PARAMS
TYPE CRMT_GSURLPOPUP_PARAMS.

CONCATENATE ‘scenario=P&activity=’ GT_KING-ACTIVITY INTO LV_QUERY.

* get URL
LV_URL = CL_CRM_WEB_UTILITY=>CREATE_URL(            IV_PATH            =
‘/sap/crm/zasp_pdf_print’
IV_QUERY           = LV_QUERY
IV_IN_SAME_SESSION =
‘X’ ).
*URL will have to set up in the ICF service, this we will see in further steps.

*Create a popup with the help of window controller and make use of standard URL POPUP Interface View.

LR_POPUP =  ME->COMP_CONTROLLER->WINDOW_MANAGER->CREATE_POPUP(
IV_INTERFACE_VIEW_NAME = ‘GSURLPOPUP/MainWindow’
IV_USAGE_NAME          =
‘CUGSURLPopup’
IV_TITLE               = LV_TITLE ).

*Set the URL paramaters like Header_guid which will be retrived in the service handler class later.

LR_CN = LR_POPUP->GET_CONTEXT_NODE( ‘PARAMS’ ).
LR_OBJ = LR_CN->COLLECTION_WRAPPER->GET_CURRENT( ).

* Set up Popup configuration Settings like

LS_PARAMS-URL = LV_URL.
LS_PARAMS-HEIGHT = ‘800’.
LS_PARAMS-WIDTH =
‘800’.
LR_OBJ->SET_PROPERTIES( LS_PARAMS ).
LR_POPUP->SET_DISPLAY_MODE( IF_BSP_WD_POPUP=>C_DISPLAY_MODE_PLAIN ).
LR_POPUP->SET_WINDOW_WIDTH(
820 ).
LR_POPUP->SET_WINDOW_HEIGHT(
800 ).
LR_POPUP->OPEN( ).

ENDIF.

ENDMETHOD.

place the code in Get_PDF method as shown above.


To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Carsten Kasper

    So why exactly would I want to develop all this? SAP already has a “Print preview” button in most transactions in WebClient. All I have to do is define an action of type print.

    Oh yes and it works with Adobe Print Forms as well. Just format the XSTRING output of the ADS to an OTF format.

    (0) 
    1. Savaridasan P

      Greetings  Roman,

      in below function module , for L_FORMNAME where the value comes from?

      and the declaration,  L_FORMNAME type fpname is it correct?

      CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
      EXPORTING
      FORMNAME           = L_FORMNAME

      *       variant            = ‘ ‘
      *       direct_call        = ‘ ‘
      IMPORTING
      FM_NAME            = FM_NAME
      EXCEPTIONS
      NO_FORM            =
      1
      NO_FUNCTION_MODULE =
      2
      OTHERS             = 3.

      thanks


      (0) 
      1. Roman Beketov

        Hello, I did it so:

        data: lv_form_name  type fpname.

        *  get adobe form name

        lv_form_name = server->request->get_form_field( ‘form’ ).

        try.

              call function ‘FP_FUNCTION_MODULE_NAME’

                exporting

                  i_name     = lv_form_name

                importing

                  e_funcname = fm_name.

          catch cx_fp_api.

              assert 1 = 2.

        endtry.

        (0) 
        1. Savaridasan P

          Greetings Roman,

          Thank you for your great help.

          still am getting null reference error.. what the ‘form’ mean in the get_form_field( ‘form’ )

          where we actually calling the adobe form?

          thanking you

          (0) 
          1. Roman Beketov

            in method – DO_HANDLE_EVENT

            I wrote –

            data: lv_form type string.

            lv_form = ‘ZSERVISELIST2’.

            concatenate ‘scenario=P&guid=’ lv_object_id ‘&form=’ lv_form into lv_query.

             

            * get URL

            lv_url = cl_crm_web_utility=>create_url(

                    iv_path            = ‘/sap/crm/zcrm_pdf_print’

                    iv_query           = lv_query

                    iv_in_same_session = ‘X’

            ).

            lr_popup =  me->comp_controller->window_manager->create_popup(

                    iv_interface_view_name = ‘GSURLPOPUP/MainWindow’

                    iv_usage_name          = ‘CUGSURLPopup’

                    iv_title               = ‘PDF’

            ).

            (0) 
  2. Savaridasan P

    Greetings Subrahmanyam Anantagiri,

    in below function module , for L_FORMNAME where the value comes from?

    and the declaration,  L_FORMNAME type fpname is it correct?

    CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
    EXPORTING
    FORMNAME           = L_FORMNAME

    *       variant            = ‘ ‘
    *       direct_call        = ‘ ‘
    IMPORTING
    FM_NAME            = FM_NAME
    EXCEPTIONS
    NO_FORM            =
    1
    NO_FUNCTION_MODULE =
    2
    OTHERS             = 3.

    thanks

    (0) 

Leave a Reply