Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

Create a PDF from Spool and Transfer to Client server Using FTP .

$
0
0

Hello All ,

 

I found a lot of questions being raised on transferring the PDF file through FTP. Please use the code below i have developed for my project it works! .

 

 

 

START-OF-SELECTION.

 

   IF ftp EQ 'X'.

 

*subroutine for ftp transfer

     PERFORM : spool_pdf_conversion.

*              ftp_transfer .

   ELSE.

 

*subroutine for local transfer

     PERFORM : spool_pdf_conversion,

               local_transfer .

 

   ENDIF.

 

 

 

 

*&---------------------------------------------------------------------*

*&      Form  spool_pdf_conversion

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM spool_pdf_conversion.

***convert spool to pdf

  CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

    EXPORTING

      src_spoolid              = spoolno

      no_dialog                = 'X'

      pdf_destination          = 'X'

      no_background            = 'X'

    IMPORTING

      pdf_bytecount            = bin_size

      bin_file                 = pdf_xstring

    EXCEPTIONS

      err_no_otf_spooljob      = 1

      err_no_spooljob          = 2

      err_no_permission        = 3

      err_conv_not_possible    = 4

      err_bad_dstdevice        = 5

      user_cancelled           = 6

      err_spoolerror           = 7

      err_temseerror           = 8

      err_btcjob_open_failed   = 9

      err_btcjob_submit_failed = 10

      err_btcjob_close_failed  = 11

      OTHERS                   = 12.

  IF sy-subrc <> 0.

    MESSAGE e712(po) WITH sy-subrc 'CONVERT_OTFSPOOLJOB_2_PDF'.

  ENDIF.

 

 

***converting xstring to the binary format

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

    EXPORTING

      buffer                = pdf_xstring

*       APPEND_TO_TABLE       = ' '

*     IMPORTING

*       OUTPUT_LENGTH         =

    TABLES

      binary_tab            = bindata

            .

 

 

ENDFORM.                    "spool_pdf_conversion

 

 

 

 

*&---------------------------------------------------------------------*

*&      Form  Desktop_transfer

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM LOCAL_transfer.

 

 

  CALL FUNCTION 'FTP_R3_TO_CLIENT'

EXPORTING

   fname                 = 'C:\Documents and Settings\GSS\Desktop\Script_d.PDF'

   rfc_destination       = 'SAPFTP'

  blob_length           =  bin_size

*     CHARACTER_MODE        = 'X'

TABLES

   blob                = bindata

*    TEXT                  =  datatab

EXCEPTIONS

  command_error         = 1

  data_error            = 2

  OTHERS                = 3.

 

 

 

 

ENDFORM.                    "Desktop_transfer

 

 

 

 

 

 

*&---------------------------------------------------------------------*

*&      Form  ftp_trasfer

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM ftp_transfer.

 

 

***ftp connection logic

  slen = STRLEN( l_pwd ).

 

 

  CALL FUNCTION 'HTTP_SCRAMBLE'

    EXPORTING

      SOURCE      = l_pwd

      sourcelen   = slen

      key         = key

    IMPORTING

      destination = l_pwd.

 

 

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

    EXPORTING

      text = 'Connect to FTP Server'.

 

 

  CALL FUNCTION 'FTP_CONNECT'

    EXPORTING

      user            = l_user

      password        = l_pwd

      host            = l_host

      rfc_destination = 'SAPFTPA'

    IMPORTING

      handle          = hdl.

 

 

  IF NOT pasv IS INITIAL.

    REFRESH result.

 

 

    CALL FUNCTION 'FTP_COMMAND'

      EXPORTING

        handle        = hdl

        command       = 'set passive on'

      TABLES

        data          = result

      EXCEPTIONS

        tcpip_error   = 1

        command_error = 2

        data_error    = 3.

 

 

    IF sy-subrc EQ 0.

      WRITE: / 'Set passive mode'.

      SKIP 1.

    ENDIF.

 

 

  ENDIF.

 

 

***passing the file name

  docid = 'Script.pdf'.

 

 

***connecting to the ftp server

  CALL FUNCTION 'FTP_R3_TO_SERVER'

    EXPORTING

      handle        = hdl

      fname         = docid

      blob_length   = bin_size

    TABLES

      blob          = bindata

    EXCEPTIONS

      tcpip_error   = 1

      command_error = 2

      data_error    = 3

      OTHERS        = 4.

 

 

***ftp disconnection

  CALL FUNCTION 'FTP_DISCONNECT'

    EXPORTING

      handle = hdl.

 

 

  CALL FUNCTION 'RFC_CONNECTION_CLOSE'

    EXPORTING

      destination = dest

    EXCEPTIONS

      OTHERS      = 1.

 

 

ENDFORM.                    "

 

 

******* Declarations.

 

TYPES: BEGIN OF blob,

       line(80) TYPE x,

       END OF blob.

 

 

*** PDF conversion Declaration .

DATA: pdf_size      TYPE so_obj_len,

      pdf_content   TYPE solix_tab,

      pdf_xstring   TYPE xstring,

      v_xstring     TYPE xstring,

      v_text      TYPE localfile,

      rq       TYPE tsp01,

      bin_size TYPE i,

      dummy    TYPE TABLE OF rspoattr,

      otf LIKE itcoo OCCURS 100 WITH HEADER LINE,

      cancel,

      pdf LIKE tline OCCURS 100 WITH HEADER LINE,

      doctab LIKE docs OCCURS 1 WITH HEADER LINE,

      numbytes TYPE i,

      arc_idx LIKE toa_dara,

      pdfspoolid LIKE tsp01-rqident,

      jobname LIKE tbtcjob-jobname,

      jobcount LIKE tbtcjob-jobcount,

      is_otf,

      client LIKE tst01-dclient,

      name LIKE tst01-dname,

      objtype LIKE rststype-type,

      type LIKE rststype-type,

      get_size_from_format,

      bindata TYPE TABLE OF blob WITH HEADER LINE,

      result TYPE TABLE OF text WITH HEADER LINE,

      filesize TYPE i,

      convcount TYPE i,

      lines LIKE tline OCCURS 100 WITH HEADER LINE,

      textlines LIKE tline OCCURS 100 WITH HEADER LINE,

 

 

***FTP declarations

      v_file     TYPE char40,

      w_hdl      TYPE i,

      c_key      TYPE i VALUE 26101957,

      l_slen     TYPE i,

      l_user(30) TYPE c VALUE 'USERNAME',                    "user name of ftp server

      l_pwd(30)  TYPE c VALUE 'PASSWORD',              "password of ftp server

      l_host(64) TYPE c VALUE 'IP_ADDRESS',      "ip address of FTP server

      pasv,

      key TYPE i VALUE 26101957,

      hdl TYPE i,

      slen TYPE i,

      x TYPE i,

      docid LIKE sysuuid-c,

      cmd(120),

      error,

      bline(120) TYPE x,

      dest LIKE rfcdes-rfcdest.

 

 

***Selection Screen

PARAMETERS: spoolno LIKE tsp01-rqident.

 

 

SELECTION-SCREEN BEGIN OF LINE .

SELECTION-SCREEN POSITION 2.

PARAMETERS: ftp RADIOBUTTON GROUP rb.

SELECTION-SCREEN COMMENT 5(45) text-005.

SELECTION-SCREEN END OF LINE.

 

 

SELECTION-SCREEN BEGIN OF LINE .

SELECTION-SCREEN POSITION 2.

PARAMETERS: local RADIOBUTTON GROUP rb .

SELECTION-SCREEN COMMENT 5(45) text-006.

SELECTION-SCREEN END OF LINE.

 

Thank you .


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>