Showing posts with label Call Smartform from Driver program in ABAP. Show all posts
Showing posts with label Call Smartform from Driver program in ABAP. Show all posts

Thursday, March 3, 2022

How to call a smartform from a driver program

Below Code Snippet shows how to call a smartform from a driver program. 


DATA:   f_name        TYPE rs38l_fnam,
        gwa_ssfcompop TYPE ssfcompop,
        gwa_control   TYPE ssfctrlop,
        gv_job_output TYPE ssfcrescl,
        gv_devtype    TYPE rspoptype,
        i_otf         TYPE  tsfotf.

* Every Smartform is a function module, generated by SAP. Each time the form is modified a new FM is created. Therefore to get the name of the FM of Smartform we have to use the below FM - SSF_FUNCTION_MODULE_NAME

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname 'SMARTFORM_NAME'
      IMPORTING
        fm_name  f_name.

* Get Device Type 

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
      EXPORTING
        i_language             sy-langu
*       I_APPLICATION          = 'SAPDEFAULT'
      IMPORTING
        e_devtype              gv_devtype
      EXCEPTIONS
        no_language            1
        language_not_installed 2
        no_devtype_found       3
        system_error           4
        OTHERS                 5.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

* Control parameters for print window
    gwa_control-preview 'X'.
    gwa_control-no_dialog 'X'.
    gwa_ssfcompop-tdprinter gv_devtype.
    gwa_ssfcompop-tdcopies 1.
    gwa_control-getotf 'X'.

* Smartform Call 

    CALL FUNCTION f_name
      EXPORTING
*       ARCHIVE_INDEX      =
*       ARCHIVE_INDEX_TAB  =
*       ARCHIVE_PARAMETERS =
        control_parameters gwa_control
*       MAIL_APPL_OBJ      =
*       MAIL_RECIPIENT     =
*       MAIL_SENDER        =
        output_options     gwa_ssfcompop
*       USER_SETTINGS      = 'X'
        itab               tab_name
      IMPORTING
*       DOCUMENT_OUTPUT_INFO       =
        job_output_info    gv_job_output
*       JOB_OUTPUT_OPTIONS =
      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.

    APPEND LINES OF gv_job_output-otfdata TO i_otf.

    CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
      EXPORTING
        i_otf                    i_otf
      EXCEPTIONS
        convert_otf_to_pdf_error 1
        cntl_error               2
        OTHERS                   3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.



How to Find Implemented BADIs for a Tcode in SAP

  Simple way to find implemented BADI for a TCode in SAP  First We have to find the Package for the transaction. 1.      Go to that par...