How to Display Smart form in PDF Format Using SSFCOMP_PDF_PREVIEW

In sap abap, If you execute the smart form, one pop up screen is open and ask to you, put the output device name or number and show one print preview button and one print button. If you click print preview button, Then show the output. But this output is not PDF format output, this is standard form output screen. 

If you want to display, smart form output is PDF formatted. Then follow the below example.

display-smartform-PDF-format-SSFCOMP_PDF_PREVIEW-sap-abap-decoderp


Example :

We want to show only one text in smart form and output of this form show in PDF format.

Step: 1

First write your required select query and loop table or read table statement. In this example can not required any select query and read table, Only required one text field. So, We write only text field. 

DATA : DISPLAY_TEXT type char200.

DISPLAY_TEXT = 'Show smart form in pdf format.'.

Explanation:

DISPLAY_TEXT is variable, that store the output text.

Step: 2

After all data are coming, you can call SSF_FUNCTION_MODULE_NAME function module. This function module convert smartform name to smartform function module.

DATA: LV_FM_NAME TYPE RS38L_FNAM.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
 EXPORTING
  FORMNAME   = 'ZR_PDF'
 IMPORTING
  FM_NAME      = LV_FM_NAME
 EXCEPTIONS
  NO_FORM                             1
  NO_FUNCTION_MODULE     2
OTHERS                                    3.

IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Explanation:

ZR_PDF is the form name. LV_FM_NAME is the variable, that store the smart form function module name. After call SSF_FUNCTION_MODULE_NAME function module, get the data in LV_FM_NAME field.

Step: 3

Call smart form using the smart form function module name. After call, remove or comment this function module name ( /BCDWB/SF00000045 ) and instead of this function module name use SSF_FUNCTION_MODULE_NAME  importing parameter FM_NAME passing variable ( LV_FM_NAME ). In this function module, put exporting CONTROL_PARAMETERS and put other exporting parameter as per your required and get importing parameter JOB_OUTPUT_INFO.

DATA: JOB_OUTPUT_INFO TYPE SSFCRESCL,
           CONTROL_PARAMETERS TYPE SSFCTRLOP.

CONTROL_PARAMETERS-GETOTF          'X'.
CONTROL_PARAMETERS-NO_DIALOG 'X'.

CALL FUNCTION  LV_FM_NAME   ""   '/BCDWB/SF00000045'

 EXPORTING
   CONTROL_PARAMETERS =   CONTROL_PARAMETERS
   display_text                     =    DISPLAY_TEXT
 IMPORTING
   JOB_OUTPUT_INFO       = JOB_OUTPUT_INFO
 EXCEPTIONS 
   FORMATTING_ERROR    =   1
   INTERNAL_ERROR           2
   SEND_ERROR                 =   3
   USER_CANCELED             4
 OTHERS                            =   5.

IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Step: 4

After call smart form function module name, call another function module that name is SSFCOMP_PDF_PREVIEW. This function module use to convert normal smart form print view to pdf view.

   
CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
 EXPORTING
   I_OTF            =  JOB_OUTPUT_INFO-OTFDATA
 EXCEPTIONS
   CONVERT_OTF_TO_PDF_ERROR  =   1
   CNTL_ERROR                                =   2
 OTHERS                                          =   3.

IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Explanation:

In this function module, use importing parameter field JOB_OUTPUT_INFO of smart form function module and this field put into the exporting parameter  I_OTF field of SSFCOMP_PDF_PREVIEW .


If you have a any query then comment that or contact me through the contact page. Thank you .

Post a Comment

0 Comments