Wednesday, November 30, 2016

send pdf file to ftp server

REPORT  zpdfsendtoftp.


DATA BEGIN OF t_vbak OCCURS 0,
         vbeln TYPE vbrk-vbeln,
         vkorg TYPE vbak-vkorg,
         vkbur TYPE vbak-vkbur,
       END OF t_vbak.

DATAfm_name TYPE rs38l_fnam,
            p_form  TYPE tdsfname   VALUE 'ZTEST1'.   "smartforms name

DATAcarr_id       TYPE sbook-carrid,
           cparam        TYPE ssfctrlop,
           outop         TYPE ssfcompop,
           tab_otf_data  TYPE ssfcrescl,
           pdf_tab       LIKE tline OCCURS WITH HEADER LINE,
           tab_otf_final TYPE itcoo OCCURS WITH HEADER LINE,
          file_size     TYPE i,
          bin_filesize  TYPE i,
          file_name     TYPE string,
         file_path     TYPE string,
         full_path     TYPE string.


PARAMETERS vbeln TYPE vbak-vbeln.   " input parameter

SELECT vbeln vkorg vkbur FROM vbak INTO TABLE t_vbak WHERE vbeln vbeln.

outop-tddest 'LP01'.
cparam-no_dialog 'X'.
cparam-preview space.
cparam-getotf 'X'.


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

CALL FUNCTION fm_name
  EXPORTING
    control_parameters cparam
    output_options     outop
    user_settings      space
    vbeln              vbeln
  IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
    job_output_info    tab_otf_data
  TABLES
    t_vbak             t_vbak.


tab_otf_final[] tab_otf_data-otfdata[].

CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
    format                'PDF'
    max_linewidth         132
  IMPORTING
    bin_filesize          bin_filesize
  TABLES
    otf                   tab_otf_final
    lines                 pdf_tab
  EXCEPTIONS
    err_max_linewidth     1
    err_format            2
    err_conv_not_possible 3
    err_bad_otf           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.


"""""""""""" send pdf file to server """""""""""
DATA i_tab_converted_data  TYPE STANDARD TABLE OF char200 WITH HEADER LINE.

TYPES:
  BEGIN OF ty_ftp,
    zcountry  TYPE zftpi-zcountry,
    zuser     TYPE zftpi-zuser,
    zpasswd   TYPE zftpi-zpasswd,
    zhost     TYPE zftpi-zhost,
    zrfc_dest TYPE zftpi-zrfc_dest,
    zapp      TYPE zftpi-zapp,
    zftp      TYPE zftpi-zftp,
  END OF ty_ftp,
  BEGIN OF xml_line,
    data(256TYPE x,
  END OF xml_line.

DATAlt_xml_table      TYPE TABLE OF xml_line,
      l_xml_size        TYPE i,
      l_rc              TYPE i,
      lv_success        TYPE VALUE 1,
      l_element_package TYPE REF TO if_ixml_element,
      l_element_details TYPE REF TO if_ixml_element,
      l_value           TYPE string.


DATAresult   TYPE TABLE OF text WITH HEADER LINE,
      commands TYPE TABLE OF text WITH HEADER LINE.

DATATYPE likp-ablad.
DATAcountry TYPE char2.
DATA :rec                          TYPE xml_line."Adjust as per requirement/OS limits
DATA filepath(128)                TYPE c.

DATAw_hdl         TYPE i,
      c_key         TYPE VALUE 26101957,
      l_slen        TYPE i,
      command_index TYPE i.
DATA l_interface_key TYPE char30,
       l_filename      TYPE char200,
       l_content_type  TYPE char10,
       lv_command(200TYPE c.

DATAt_time  TYPE sy-uzeit,
      lv_move TYPE c,
      lv_pick TYPE c,
      lv_pack TYPE c.


DATA:  l_user(30TYPE VALUE 'ftptest123'"user name of ftp server
       l_pwd(30)  TYPE VALUE 'pass123'"password of ftp server

       l_host(64TYPE VALUE 'enter host'"ip address of FTP server
       l_dest     LIKE rfcdes-rfcdest VALUE 'SAPFTPA'"Background RFC destination

filepath '/home'.
OPEN DATASET filepath FOR OUTPUT IN BINARY MODE.
IF sy-subrc 0.
  LOOP AT lt_xml_table INTO rec.
    TRANSFER rec TO filepath.
  ENDLOOP.
ENDIF.
CLOSE DATASET filepath.

CONCATENATE '/' 'test' '.pdf' INTO l_filename.  " file name

CONCATENATE 'put' filepath l_filename INTO lv_command SEPARATED BY space.
*HTTP_SCRAMBLE: used to scramble the password provided in a format recognized by SAP.
SET EXTENDED CHECK OFF.
l_slen strlenl_pwd ).

CALL FUNCTION 'HTTP_SCRAMBLE'
  EXPORTING
    source      l_pwd
    sourcelen   l_slen
    key         c_key
  IMPORTING
    destination l_pwd.

* To Connect to the Server using FTP
CALL FUNCTION 'FTP_CONNECT'
  EXPORTING
    user            l_user
    password        l_pwd
    host            l_host
    rfc_destination l_dest
  IMPORTING
    handle          w_hdl
  EXCEPTIONS
    OTHERS          1.

IF sy-subrc <> 0.
  lv_success 0.
  EXIT.
ENDIF.


REFRESH commands.

*  ***connecting to the ftp server
CALL FUNCTION 'FTP_R3_TO_SERVER'
  EXPORTING
    handle        w_hdl
    fname         l_filename
    blob_length   bin_filesize
  TABLES
    blob          pdf_tab
  EXCEPTIONS
    tcpip_error   1
    command_error 2
    data_error    3
    OTHERS        4.

* To disconnect the FTP
CALL FUNCTION 'FTP_DISCONNECT'
  EXPORTING
    handle w_hdl.

*RFC_CONNECTION_CLOSE:This is used to disconnect the RFC connection between SAP and other system.

CALL FUNCTION 'RFC_CONNECTION_CLOSE'
  EXPORTING
    destination l_dest
  EXCEPTIONS
    OTHERS      1.


WRITE'pdf file send successfully'.

57 comments:

  1. Thank you. It is such a wonderful post. it has great information it is very useful for sap videos.

    ReplyDelete
  2. I get a lot of great information from this blog on sap video tutorials

    ReplyDelete
  3. Thank you it is really such a wonderful blogpost on sap training videos Please Share More Information.

    ReplyDelete
  4. I am planning to join sap abap with them after reading your blog.
    Hope the best will turn out.
    Call them at 8122241286 in chennai.
    www.thecreatingexperts.com

    ReplyDelete
  5. We provide sap abap technical course, call us to know more about us and join with us.
    Call them at 8122241286 in chennai.
    www.thecreatingexperts.com

    ReplyDelete

  6. It was so nice article Thank you for valuable information sap video tutorials

    ReplyDelete
  7. It was so nice article.I was really satisified by seeing this article. It has great information on.. sap video tutorials

    ReplyDelete
  8. Thank you.This article is really contains lot more information about This Topic on sap video tutorials

    ReplyDelete
  9. Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    Hadoop Training in Chennai
    Dotnet Training in Chennai

    ReplyDelete
  10. Thank you sir.Thank you for giving this best information. It’s a very nice topicsap video

    ReplyDelete
  11. Thanks for the great information in your blog on It was so nice article sap video tutorials

    ReplyDelete
  12. Thank you sir.Thanks for Nice and Informative Post on sap video

    ReplyDelete
  13. Thank you sir.It was so nice article Thank you for valuable information sap video

    ReplyDelete
  14. Well it Was Very Good Information. Thanks for sharing this Information. sap video tutorials

    ReplyDelete
  15. Thanks for the great information in your blog on It was so nice article Thank you for valuable informationsap video tutorials

    ReplyDelete
  16. Thank you for giving this best information. It’s a very nice topic on sap video tutorials

    ReplyDelete
  17. Thankyou for information excellent blog have a great possible sap video tutorials

    ReplyDelete
  18. Thank you. sir, Really I like your post on sap videos.

    ReplyDelete
  19. I have been a blogger too but you post much technical details. Thank you for sharing your knowledge. The creating experts was my first trainer in SAP ABAP got in depth learning from them

    http://thecreatingexperts.com/sap-abap-training-in-chennai/


    contact +91-08122241286

    ReplyDelete
  20. SAP ABAP training is provided in CHENNAI.

    THE CREATING EXPERTS is one of the leading trainer in SAP who provides real time training

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    contact 8122241286

    ReplyDelete
  21. Thank you. It is such a wonderful post. it has great information it is very useful Post. sap video tutorials

    ReplyDelete
  22. Thank you for Wonderful information.

    SAP ABAP training in CHENNAI BY THE CREATING EXPERTS

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    CONTACT 8122241286

    ReplyDelete
  23. Thank you for Wonderful information.

    SAP ABAP training in CHENNAI BY THE CREATING EXPERTS

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    CONTACT 8122241286

    ReplyDelete

  24. This article is really contains lot more information sap video tutorials

    ReplyDelete

  25. Thanks for sharing this informative blog..Your blog is really useful for me. sap video tutorials

    ReplyDelete

  26. Thank you for giving this best information. It’s a very nice topic..sap video tutorials

    ReplyDelete
  27. Good post! Thanks for sharing this Information.The information you Provided is much useful on sap video

    ReplyDelete

  28. Well it Was Very Good Information. Thanks for sharing this Information. sap video

    ReplyDelete
  29. Thank you for giving this best information. It’s a very nice topic.sap videos tutorials

    ReplyDelete
  30. Fabulous..!!! The information you Provided is much useful.sap video

    ReplyDelete
  31. This article is really contains lot more information.sap video tutorials

    ReplyDelete

  32. Fabulous..!!! The information you Provided is much useful. sap videos tutorials

    ReplyDelete

  33. Thanks for the great information in your blog on It was so nice article. sap video

    ReplyDelete
  34. This article is really contains lot more information. sap video tutorials

    ReplyDelete
  35. Thanks for Sharing this Information.You are providing very valuable information. sap video

    ReplyDelete

  36. I get a lot of great information from this blog on sap video

    ReplyDelete
  37. Thank you for Sharing Great Information. It is Very Helpful Information onsap video tutorials

    ReplyDelete
  38. Hi, thanks, but this dont work for me....
    can help?

    ReplyDelete
  39. I get a lot of great information from this blog. sap video tutorials

    ReplyDelete

  40. The information you have given here is truly helpful to me. sap video tutorials

    ReplyDelete

  41. Thank you for Sharing Great Information. It is Very Helpful Information on.sap video tutorials

    ReplyDelete

  42. The information you have given here is truly helpful to me. sap video

    ReplyDelete
  43. Thank you for giving this best information. It’s a very nice topic. sap video tutorials

    ReplyDelete
  44. I am very grateful to you that you share very informative post with ussap video tutorials

    ReplyDelete
  45. Thanks for sharing this informative blog..Your blog is really useful for me. sap video tutorials

    ReplyDelete
  46. It was so nice article Thank you for valuable information. sap training videos

    ReplyDelete
  47. Thanks for Nice and Informative Post on. sap video tutorials

    ReplyDelete

  48. This article is really contains lot more information sap videos tutorials

    ReplyDelete
  49. Good blog post.I want to thank you for interesting and helpful information and my website some Information Hire This is one program that's effective in helping other interested data entry operators to do the job. Such billing uses optical character technology that recognizes and reads data on medical bills, instantly, electronically and automatically..If you want to know more.I will suggest you check out this link pdf data entry services

    ReplyDelete
  50. { Otherwise, {you can|you are able to|it is possible to|you'll be able to} directly ask Pay - Pal {or other|or any other|or another|and other} {methods to|techniques to|solutions to|ways to} {help you|assist you to|enable you to|allow you to} on phone or through remote desktop software| Some things {to look|to appear|to check|to take a look} out for {are the|would be the|will be the|include the} {availability of|accessibility to|option of|use of} direct {phone numbers|telephone numbers|cell phone numbers|numbers}, instant messaging support, and direct emails| You will never {know exactly|know precisely|understand specifically|specifically} that {what type of|which kind of|what sort of|which} client {you are|you're|you might be|you happen to be} handling {and you have|and you've got|plus you've got|along with} to be prepared {and have|and also have|and possess|and still have} some {bunch of|couple of|few|lot of} {ideas to|suggestions to|tips to|tricks to} {make out|write out|find out|figure out} the solutionspdf data entry services

    ReplyDelete
  51. hi , tried your steps, it's not working for me

    ReplyDelete