Gyan Factory

Gyan Factory
SAP Technical Project Support
Showing posts with label Smart Forms. Show all posts
Showing posts with label Smart Forms. Show all posts

Monday, December 28, 2015

Convert Smartform into PDF

Here I’m trying to explain how to convert a smartform into a PDF and download.
All the below steps contains only sample codes and are self explanatory, so I’m not going into details of every step.

Prerequisites: You need to know how to call the smartform FM from ur driver program and all. Although you can find the same from the step 1.

If u r running out of time then u can go through the step 3 only.

Step 1.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    
EXPORTING
      formname           
'Z_SMARTFORM_NAME'   
    IMPORTING
      fm_name            
v_fm_name
    
EXCEPTIONS
      no_form            
1
      no_function_module 
2
      
OTHERS             3.

Step 2.

  CALL FUNCTION lc_fm_name
    
EXPORTING
      control_parameters 
s_control_par
    .
    .
    IMPORTING
      job_output_info    
s_job_output
    
TABLES
    .
    .
    EXCEPTIONS
      formatting_error   
1
      internal_error     
2
      send_error         
3
      user_canceled      
4
      
OTHERS             5.

Step 3.

Use the s_job_output-otfdata[] from the previous step into the OTF table parameter in the FM'CONVERT_OTF_2_PDF'.

    CALL FUNCTION 'CONVERT_OTF_2_PDF'
      
IMPORTING
        bin_filesize           
bin_filesize
      
TABLES
        otf                    
s_job_output-otfdata[]
        doctab_archive         
doctab_archive
        
lines                  t_file_pdf
      
EXCEPTIONS
        err_conv_not_possible  
1
        err_otf_mc_noendmarker 
2
        
OTHERS                 3.

Step 4.

      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        
EXPORTING
          window_title            
'Open file'
          default_extension       
'*.pdf'
        
CHANGING
          file_table              
file_table[]
          rc                      
rc
          user_action             
user_action
        
EXCEPTIONS
          file_open_dialog_failed 
1
          cntl_error              
2
          error_no_gui            
3
          
OTHERS                  4.



Step 5.

      IF user_action 9EXITENDIF.
      
IF rc 1.
        
READ TABLE file_table INDEX 1.
      
ENDIF.

     MOVE file_table-filename TO filename.

      CALL METHOD cl_gui_frontend_services=>gui_download
        
EXPORTING
          bin_filesize            
bin_filesize
          filename                
filename
          filetype                
'BIN'
        
CHANGING
          data_tab                
t_file_pdf
        
EXCEPTIONS
          file_write_error        
1
          no_batch                
2
          gui_refuse_filetransfer 
3
          invalid_type            
4
          no_authority            
5
          unknown_error           
6
          header_not_allowed      
7
          separator_not_allowed   
8
          filesize_not_allowed    
9
          header_too_long         
10
          dp_error_create         
11
          dp_error_send           
12
          dp_error_write          
13
          unknown_dp_error        
14
          access_denied           
15
          dp_out_of_memory        
16
          disk_full               
17
          dp_timeout              
18
          file_not_found          
19
          dataprovider_exception  
20
          control_flush_error     
21
          
OTHERS                  22.