Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata
Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT  ZPDF_G.
DATA: FORM_NAME TYPE RS38L_FNAM,      " Used to get the function module of Smartform
      WA_CTRLOP TYPE SSFCTRLOP,       " Smart Forms: Control structure
      WA_OUTOPT TYPE SSFCOMPOP,       " SAP Smart Forms: Smart Composer (transfer) options
      T_OTFDATA TYPE SSFCRESCL.       " Smart Forms: Return value at end of form printing
DATA: T_PDF_TAB TYPE TABLE OF TLINE,  " SAPscript: Text Lines
      T_OTF TYPE TABLE OF ITCOO.      " OTF Structure
* Variables used to pass to GUI_DOWNLOAD
DATA: W_FILESIZE TYPE I,
      W_BIN_FILESIZE TYPE I.
* Variables used for Save Dialog Box
DATA : FILE_NAME TYPE STRING,
       FILE_PATH TYPE STRING,
       FULL_PATH TYPE STRING.
START-OF-SELECTION.
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      FORMNAME           = 'ZPDF_G'      "p_name
    IMPORTING
      FM_NAME            = FORM_NAME
    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.
  WA_CTRLOP-GETOTF = 'X'.
  WA_CTRLOP-NO_DIALOG = 'X'.
  WA_OUTOPT-TDNOPREV = 'X'.
  CALL FUNCTION FORM_NAME
    EXPORTING
      CONTROL_PARAMETERS = WA_CTRLOP
      OUTPUT_OPTIONS     = WA_OUTOPT
      USER_SETTINGS      = 'X'
    IMPORTING
      JOB_OUTPUT_INFO    = T_OTFDATA
    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.
END-OF-SELECTION.
  T_OTF[] = T_OTFDATA-OTFDATA[].
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      FORMAT                = 'PDF'
      MAX_LINEWIDTH         = 132
    IMPORTING
      BIN_FILESIZE          = W_BIN_FILESIZE
    TABLES
      OTF                   = T_OTF
      LINES                 = T_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.
*---------------TAKING THE DOWNLOAD FILE PATH AS USER INPUT**
  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    CHANGING
      FILENAME             = FILE_NAME
      PATH                 = FILE_PATH
      FULLPATH             = FULL_PATH
    EXCEPTIONS
      CNTL_ERROR           = 1
      ERROR_NO_GUI         = 2
      NOT_SUPPORTED_BY_GUI = 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.
* Download the file to the selected path
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      BIN_FILESIZE            = W_BIN_FILESIZE
      FILENAME                = FULL_PATH                   "fname1
      FILETYPE                = 'BIN'
    IMPORTING
      FILELENGTH              = W_FILESIZE
    TABLES
      DATA_TAB                = T_PDF_TAB
    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.
  IF SY-SUBRC <> 0.
    MESSAGE 'File not downloaded' TYPE 'I'.
  ELSE.
    MESSAGE 'File downloaded' TYPE 'I'.
  ENDIF.