Wednesday, May 9, 2012

Smartform - New Page for each record in table

Tcode: smartforms

Create Smart form say: ZABC_SF
Create Smart style: ZDEF_SS

In main window: Loop at first table as shown in below.

In output options assign Style.
In CODE2: Add following as shown, No condition required here.

In Command Line add following as Shown. This will responsible for creating new page for each record in first Internal table.

Design another table in the list as below.  In Output options mention Style.

Display data of table as below. You are done. Code is to calculate values, dont forget to pass input output values as well
SOST* - Check email if send out from system
NACE*- Conditions for output control > Select output looking for (ie. Billing)
Press 'Output Types' > select output type > double click on processing routine in left.
ADRC -  contains address for address no, which can be configured in smart form
customer table KNA1 have adrc no field in ADRNR.
VA03  - Sales Order > Enter Sales Order No > Issue Output to
VF03 -  Billing > Enter Billing No > Issue Output to

To configure a output :
VA02 > Extras > Output > Header > Edit
To configure the output Following needs to be done in Billing, In VF02 > Enter a Billing doc details, > go to header > Output > Enter details using 'communication details' and 'Further Data'. Request processing set to send immediately i.e. 4
Same for Sales Order > VA02 > Extras > Output > Header > Edit ....

Sample Code - Download Smartform as PDF doc
********
FORM download_smartform_as_pdf .
  DATA : fmname                  TYPE rs38l_fnam,
         st_job_output_info      TYPE ssfcrescl,
         st_document_output_info TYPE ssfcrespd,
         st_job_output_options   TYPE ssfcresop,
         v_e_devtype             TYPE rspoptype,
         st_output_options       TYPE ssfcompop,
         st_control_parameters   TYPE ssfctrlop,
         v_bin_filesize          TYPE i.
  CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
    EXPORTING
      i_language    = 'E'
      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'.
  IF gt_final IS NOT INITIAL.
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname           = 'ZABC_SF'
      IMPORTING
        fm_name            = fmname
      EXCEPTIONS
        no_form            = 1
        no_function_module = 2
        OTHERS             = 3.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION fmname
EXPORTING
  control_parameters         = st_control_parameters
  output_options             = st_output_options
IMPORTING
   document_output_info  = st_document_output_info
   job_output_info       = st_job_output_info
   job_output_options    = st_job_output_options
     TABLES
       gt_final                   = gt_final
       gt_graph                   = gt_graph
    EXCEPTIONS
      formatting_error           = 1
      internal_error             = 2
      send_error                 = 3
      user_canceled              = 4
      OTHERS                     = 5.
    IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.
*.........................CONVERT TO OTF TO PDF.......................*
* Internal table declaration
  DATA: it_otf      TYPE STANDARD TABLE OF itcoo,
        it_docs     TYPE STANDARD TABLE OF docs,
        it_lines    TYPE STANDARD TABLE OF tline,
        v_guiobj                 TYPE REF TO cl_gui_frontend_services,
        v_uact                   TYPE i,
        v_name                   TYPE string,
        v_path                   TYPE string,
        v_fullpath               TYPE string,
        v_filter                 TYPE string,
        v_filename               TYPE string.

  CALL FUNCTION 'CONVERT_OTF_2_PDF'
    IMPORTING
      bin_filesize           = v_bin_filesize
    TABLES
      otf                    = st_job_output_info-otfdata
      doctab_archive         = it_docs
      lines                  = it_lines
    EXCEPTIONS
      err_conv_not_possible  = 1
      err_otf_mc_noendmarker = 2
      OTHERS                 = 3.
*........................GET THE FILE NAME TO STORE....................*
  CONCATENATE 'smrt' '.pdf' INTO v_name.
  CREATE OBJECT v_guiobj.
  CALL METHOD v_guiobj->file_save_dialog
    EXPORTING
      default_extension = 'pdf'
      default_file_name = v_name
      file_filter       = v_filter
    CHANGING
      filename          = v_name
      path              = v_path
      fullpath          = v_fullpath
      user_action       = v_uact.
  IF v_uact = v_guiobj->action_cancel.
    EXIT.
  ENDIF.
*..................................DOWNLOAD AS FILE....................*
  MOVE v_fullpath TO v_filename.
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize            = v_bin_filesize
      filename                = v_filename
      filetype                = 'BIN'
    TABLES
      data_tab                = it_lines.
ENDFORM.
******

1 comment: