Subir PDF desde FTP a R3

Colapsar
X
 
  • Tiempo
  • Mostrar
Limpiar Todo
nuevos mensajes
  • poketina
    Senior Member
    • jul
    • 105

    #1

    Subir PDF desde FTP a R3

    Hola!!

    Tengo un problema con un programa. Tengo unos archivos en un servidor FTP y tengo que subirlos a SAP. Con los XML no tengo problemas pero con el PDF sí, lo sube pero de forma incorrecta porque luego me da error al abrirlo.
    Esto es lo que he hecho, a ver si alguien sabe en qué me he equivocado, o qué me falta o lo que sea.. mil gracias !!!

    María

    TYPES: BEGIN OF text,
    line(400) TYPE c,
    END OF text.
    TYPES: BEGIN OF ty_xml,
    raw(4000) TYPE c,
    END OF ty_xml.

    DATA: user(30) TYPE c ,
    pwd(30) TYPE c ,
    host(64) TYPE c ,
    slen TYPE i,
    key TYPE i VALUE 26101957,
    hdl TYPE i,
    dest TYPE rfcdes-rfcdest,
    g_str TYPE xstring,
    size TYPE i,
    g_xmldata TYPE xstring,
    l_lin(2048),
    id_factura TYPE string,
    i_info_cab TYPE zfe_st_datoss_factura,
    gv_rectif TYPE char1,
    extension(100).
    DATA: bindata TYPE TABLE OF blob WITH HEADER LINE,
    result TYPE TABLE OF text WITH HEADER LINE,
    chardata TYPE TABLE OF text WITH HEADER LINE,
    g_t_xml_tab TYPE TABLE OF ty_xml INITIAL SIZE 0,
    i_fich TYPE TABLE OF epsfili WITH HEADER LINE,
    blob_length TYPE i,
    l_xstring TYPE xstring,
    fichero_out LIKE rlgrap-filename,"(255),
    carpeta LIKE user_dir-dirname.
    DATA: BEGIN OF tab_bin OCCURS 0.
    INCLUDE STRUCTURE sdokcntbin.
    DATA: END OF tab_bin.

    START-OF-SELECTION.

    pwd = XXXXX.
    user = XXXXXX.
    host = xx.xx.xxx,xx.
    * host = xxxxxxx.

    slen = strlen( pwd ) .
    * SAP Application Server -> FTP Server
    dest = 'SAPFTPA'.

    * La contraseña hay que formatearla
    CALL FUNCTION 'HTTP_SCRAMBLE'
    EXPORTING
    source = pwd
    sourcelen = slen
    key = key
    IMPORTING
    destination = pwd.

    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
    text = 'Connect to FTP Server'.

    * Conectamos al directorio FTP
    CALL FUNCTION 'FTP_CONNECT'
    EXPORTING
    user = user
    password = pwd
    host = host
    rfc_destination = dest
    IMPORTING
    handle = hdl
    EXCEPTIONS
    not_connected = 1
    OTHERS = 2.

    IF sy-subrc = 0.

    * Ponemos modo pasivo
    CALL FUNCTION 'FTP_COMMAND'
    EXPORTING
    handle = hdl
    command = 'set passive off'
    TABLES
    data = result
    EXCEPTIONS
    OTHERS = 1.
    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
    text = 'Create file on FTP Server'.

    CALL FUNCTION 'FTP_COMMAND'
    EXPORTING
    handle = hdl
    command = 'ascii'
    TABLES
    data = result
    EXCEPTIONS
    tcpip_error = 1
    command_error = 2
    data_error = 3.

    * Nos movemos a la carpeta DOWNLOAD
    CALL FUNCTION 'FTP_COMMAND'
    EXPORTING
    handle = hdl
    command = 'cd DOWNLOAD'
    TABLES
    data = result
    EXCEPTIONS
    tcpip_error = 1
    command_error = 2
    data_error = 3.

    CALL FUNCTION 'FTP_COMMAND'
    EXPORTING
    handle = hdl
    command = 'dir'
    TABLES
    data = result
    EXCEPTIONS
    tcpip_error = 1
    command_error = 2
    data_error = 3.

    LOOP AT result.
    IF result CS 'pdf' .
    i_fich-name = result+62(50).
    APPEND i_fich.
    ENDIF.
    ENDLOOP.
    LOOP AT i_fich.
    * Se descarga el archivo del servidor
    CALL FUNCTION 'FTP_SERVER_TO_R3'
    EXPORTING
    handle = hdl
    fname = i_fich-name
    * character_mode = 'X'
    character_mode = abap_false
    IMPORTING
    blob_length = blob_length
    TABLES
    blob = bindata
    * text = g_t_xml_tab
    EXCEPTIONS
    tcpip_error = 1
    command_error = 2
    data_error = 3
    OTHERS = 4.
    LOOP AT bindata.
    CONCATENATE bindata-content l_xstring
    INTO l_xstring IN BYTE MODE.
    ENDLOOP.

    SELECT SINGLE dirname INTO carpeta FROM user_dir
    WHERE aliass = 'EFACTURASPROV'.
    CONCATENATE
    carpeta '\' 'ESB5872858540409928.pdf' INTO fichero_out.
    OPEN DATASET fichero_out FOR OUTPUT IN BINARY MODE.
    TRANSFER l_xstring TO fichero_out.
    CLOSE DATASET fichero_out.

    ENDLOOP.

    ENDIF.
Trabajando...