WRITE_TEXT

Using READ_TEXT we can read the sapscript text. Is there a function to write text to sapscript text. I want to replace the existing text.

Hi Megan,
You have to use SAVE_TEXT.
Here you have to pass THEAD & IT_LINES
thead-tdid = <Object ID>.
thead-tdobject = <Object>.
thead-tdspras = 'EN'.
thead-tdname = <Object Name>.
IT_LINES is the internal table like TLINE, through this you can pass the text which you want to save.
CALL FUNCTION 'SAVE_TEXT'
  EXPORTING
   CLIENT                = SY-MANDT
    HEADER                = thead
   SAVEMODE_DIRECT       = 'X'
   insert                = ' '
  OWNER_SPECIFIED       = ' '
  LOCAL_CAT             = ' '
IMPORTING
  FUNCTION              =
  NEWHEADER             =
  TABLES
    LINES                 = it_lines
EXCEPTIONS
   ID                    = 1
   LANGUAGE              = 2
   NAME                  = 3
   OBJECT                = 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.
Regards,
Satish
Message was edited by:
        Satish Panakala

Similar Messages

  • Utl_http.write_text using CLOB of data

    Hi
    I need to send a CLOB of data using PL/SQL Web Services. It seems as though the utl_http.write_text procedure only handles VARCHAR2(32767).
    Oracle returns the error message:
    ORA-06502: PL/SQL: numeric or value error
    Is there a work around for this?

    Hi paul
    I had a problem that look like that one. Htp.p also handles with varchar2(32767) so what i did was a function that return chunks (32767) of my clob. so then i only had to loop trough all chunks and sent them to htp.p.
    Hope it helps

  • Issue in calling a web service from Apps instance

    Hi ,
    I have created a procedure to call a function which gives response by calling a web service URL.
    Requirement is,
    While calling this procedure , the response data has been stored in the table. This is working fine in the back end.
    Now , i call the same through concurrenet program . It is also getting stored but partially.. The exact data is missing ..other default tags are displayed in the column.
    PROCEUDRE:
    create or replace procedure cv_test_GetCityWeather_PROC(cityName in varchar2, country in varchar2 ,errbuf OUT nocopy VARCHAR2,retcode OUT nocopy VARCHAR2) is
    xmlResponse XmlType;
    begin
    xmlResponse := CV_Test_GetCityWeather(cityName,country);
    insert into xx_cv_test values(xmlResponse);
    fnd_file.put_line(fnd_file.log, 'hghghgh');
    EXCEPTION
    WHEN OTHERS THEN
    retcode := 'insert failed';
    fnd_file.put_line(fnd_file.log, 'response of the request is ' );
    --dbms_output.put_line('xmlResponse ' ||xmlResponse);
    end cv_test_getCityweather_proc;
    FUNCTION
    /*<TOAD_FILE_CHUNK>*/
    CREATE OR REPLACE function APPS.CV_Test_GetCityWeather( cityName varchar2, country varchar2 ) return XmlType is
    --// URL to call
    SOAP_URL constant varchar2(1000) := 'http://www.webservicex.net/globalweather.asmx';
    --// SOAP envelope template, containing $ substitution variables
    SOAP_ENVELOPE constant varchar2(32767) :=
    '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
    <soapenv:Header/>
    <soapenv:Body>
    <web:GetWeather>
    <web:CityName>$CITY</web:CityName>
    <web:CountryName>$COUNTRY</web:CountryName>
    </web:GetWeather>
    </soapenv:Body>
    </soapenv:Envelope>';
    --// we'll identify ourselves using an IE9/Windows7 generic browser signature
    C_USER_AGENT constant varchar2(4000) := 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
    --// these variables need to be set if web access
    --// is via a proxy server
    proxyServer varchar2(20) default null;
    proxyUser varchar2(20) default null;
    proxyPass varchar2(20) default null;
    --// our local variables
    soapEnvelope varchar2(32767);
    proxyURL varchar2(4000);
    request utl_http.req;
    response utl_http.resp;
    buffer varchar2(32767);
    soapResponse clob;
    xmlResponse XmlType;
    eof boolean;
    begin
    --// create the SOAP envelope
    soapEnvelope := replace( SOAP_ENVELOPE, '$CITY', cityName );
    soapEnvelope := replace( soapEnvelope, '$COUNTRY', country );
    --// our "browser" settings
    utl_http.set_response_error_check( true );
    utl_http.set_detailed_excp_support( true );
    utl_http.set_cookie_support( true );
    utl_http.set_transfer_timeout( 10 );
    utl_http.set_follow_redirect( 3 );
    utl_http.set_persistent_conn_support( true );
    --// configure for web proxy access if applicable
    if proxyServer is not null then
    proxyURL := 'http://'||proxyServer;
    if (proxyUser is not null) and (proxyPass is not null) then
    proxyURL := Replace( proxyURL, 'http://', 'http://'||proxyUser||':'||proxyPass||'@' );
    end if;
    utl_http.set_proxy( proxyURL, null );
    end if;
    --// make the POST call to the web service
    request := utl_http.begin_request( SOAP_URL, 'POST', utl_http.HTTP_VERSION_1_1 );
    utl_http.set_header( request, 'User-Agent', C_USER_AGENT );
    utl_http.set_header( request, 'Content-Type', 'text/xml; charset=utf-8' );
    utl_http.set_header( request, 'Content-Length', length(soapEnvelope) );
    utl_http.set_header( request, 'SoapAction', 'http://www.webserviceX.NET/GetWeather' );
    utl_http.write_text( request, soapEnvelope );
    --// read the web service HTTP response
    response := utl_http.get_response( request );
    dbms_lob.CreateTemporary( soapResponse, true );
    eof := false;
    loop
    exit when eof;
    begin
    utl_http.read_line( response, buffer, true );
    if length(buffer) > 0 then
    dbms_lob.WriteAppend(
    soapResponse,
    length(buffer),
    buffer
    end if;
    exception when utl_http.END_OF_BODY then
    eof := true;
    end;
    end loop;
    utl_http.end_response( response );
    --// as the SOAP responds with XML, we convert
    --// the response to XML
    xmlResponse := XmlType( soapResponse );
    --dbms_lob.FreeTemporary( soapResponse );
    --insert into xx_cv_test values(xmlResponse);
    return( xmlResponse );
    exception when OTHERS then
    if soapResponse is not null then
    dbms_lob.FreeTemporary( soapResponse );
    end if;
    raise;
    end;
    EXECUTION:
    select cv_test_GetCityWeather( 'Cape Town', 'South Africa' ) from dual
    Result is,
    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <GetWeatherResponse xmlns="http://www.webserviceX.NET">
    <GetWeatherResult><?xml version="1.0" encoding="utf-16"?><CurrentWeather> <Location>Cape Town, Cape Town International Airport, South Africa (FACT) 33-59S 018-36E 0M</Location> <Time>May 28, 2013 - 03:00 AM EDT / 2013.05.28 0700 UTC</Time> <Wind> from the NNW (330 degrees) at 7 MPH (6 KT) (direction variable):0</Wind> <Visibility> 4 mile(s):0</Visibility> <SkyConditions> mostly cloudy</SkyConditions> <Temperature> 57 F (14 C)</Temperature> <DewPoint> 53 F (12 C)</DewPoint> <RelativeHumidity> 87%</RelativeHumidity> <Pressure> 30.03 in. Hg (1017 hPa)</Pressure> <Status>Success</Status></CurrentWeather></GetWeatherResult>
    </GetWeatherResponse>
    </soap:Body>
    </soap:Envelope>
    While running Concurrent Program, by providing PARAMETERS : Cape Town, South Africa,
    the result is ,
    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <GetWeatherResponse xmlns="http://www.webserviceX.NET">
    <GetWeatherResult>Data Not Found</GetWeatherResult>
    </GetWeatherResponse>
    </soap:Body>
    </soap:Envelope>
    Why the outputs are different for the same procedure..
    Anybody , Please help me to fix this issue.
    Thanks
    Winsky

    duplicate post
    Please see
    Calling webservice from PLSQL
    Please confirm are you the one who post the above thread
    ;) AppsMAsti :)
    sharing is Caring

  • Question: How to call a BPEL process from a PL/SQL procedure

    Hi All,
    Greetings to all BPEL people. I have a question on how can we call a BPEL process from a PLSQL procedure. It might be a stupid question but i wanted to know whether this fetaure is available in BPEL as our scenario requires us to explore if this functionality is available in BPEL.
    Please let me know and also if possible please send me the links for the tutorials if it is available.
    Thanks In Advance,
    Dibya

    Yes u can do it. there are two ways.
    1) First one is using utl_http package of PL/SQL
    In this case u can create SOAP request message & send it as Http request to your deployed BPEL process.
    This package provides some methods like
    set_header,write_text,get_response,read_text etc..
    Following is part of code which may be helpful to you.
    create or replace package body test_book_order_sub_pkg
    is
    FUNCTION test_book_order_sub(p_subscription_guid IN RAW,
    p_event IN OUT WF_EVENT_T
                                            Return VARCHAR2 IS
    soap_request varchar2(30000);
    soap_respond varchar2(30000);
    http_req utl_http.req;
    http_resp utl_http.resp;
    launch_url varchar2(240) ;
         begin
         DBMS_OUTPUT.Put_Line('Subscription : Order has been booked');
         soap_request:='<?xml version="1.0" encoding="UTF-8"?>
         <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header/>
    <soap:Body xmlns:ns1="http://xmlns.oracle.com/BES_BookOrder">
    <ns1:BES_BookOrderProcessRequest>
    <ns1:input>725</ns1:input>
    </ns1:BES_BookOrderProcessRequest>
    </soap:Body>
    </soap:Envelope>';
    http_req:= utl_http.begin_request
    ('http://172.28.5.191:8888/orabpel/default/BES_BookOrder/1.0',
    'POST',
    'HTTP/1.1'
    utl_http.set_header(http_req, 'Content-Type', 'text/xml') ;
    utl_http.set_header(http_req, 'Content-Length', length(soap_request)) ;
    utl_http.set_header(http_req, 'SOAPAction', 'initiate');
         utl_http.write_text(http_req, soap_request) ;
    http_resp:= utl_http.get_response(http_req) ;
    utl_http.read_text(http_resp, soap_respond) ;
    utl_http.end_response(http_resp) ;
    DBMS_OUTPUT.Put_Line(soap_respond);
    return('SUCCESS');
    end test_book_order_sub;
    end test_book_order_sub_pkg;
    2) Second way is make your BPEL process listening to some database Queue(use AQ Adapter). & then put some message in tht queue from ur Pl/SQL code . This will also initiate BPEL instance. Check out AQAdapter tutorials.
    /mishit

  • Post to a servlet from a PL/SQL procedure

    I would like to know if it's possible to post a form from pl/sql. There is this servlet that does stuff but it doesn't have any api i can call so i can only post the parameters to the servlet using an html form. Each form element is added to the http header so i just have to create a header and send it to the servlet but i don't really know how to do this using pl/sql.

    Meanwhile i have found the solution myself.
    This is the snippet that sends a post form to a webpage:
    declare
    v_url varchar2(400) := 'myUrl';
    v_post varchar2(4000);
    HTTP_REQ    utl_http.REQ;
    HTTP_RESP   utl_http.RESP;
    begin
    v_post := 'param1=value1&param2=value2';
    HTTP_REQ := utl_http.BEGIN_REQUEST(v_URL, 'POST', 'HTTP/1.1');
    utl_http.SET_HEADER(HTTP_REQ, 'Content-Type', 'application/x-www-form-urlencoded');
    utl_http.SET_HEADER(HTTP_REQ, 'Content-Length', length(v_post));
    utl_http.WRITE_TEXT(HTTP_REQ, v_post);
    HTTP_RESP := utl_http.GET_RESPONSE(HTTP_REQ);
    end;This post the parameters and values from v_post to the url. In the HTTP_RESP i get the status_code so i can check if it's ok or there was a server error (code 500).

  • HOW TO SEND A HEBREW EMAIL WITH ATTACHMENT USING DEMO_MAIL

    Hello All,
    This is Not a question , just attaching something I've implemented and might be interesting for few of us,
    This package I'm attaching allows to send Hebrew Language email + attaching files to it.
    This package is based on demo_mail package (combined here but you can search at google for more example information if needed).
    My Package is supplied as is , for any specific information regarding it , please contact me directly at : [email protected] or POST here.
    * Please also note , that this package allow file to be attach via URL (meaning you will have to define a link to this file, if you would like to implement a link to a local file , e.g : c:\temp\myfile , you will have to customize the package your self with database directories option etc ...)
    First I will attach an example of how to use it :
    ==================================
    begin
    demo_mail_heb.send_html_mail_attach(p_sender => '[email protected]',
    p_recipients => '[email protected]',
    p_subject => 'שלום וברכה עולם',
    p_data => '<hr><b>בוקר טוב</b><hr>',
    p_file_name => 'but_choose_file.gif',
    p_file_mime_type => 'application/pdf',
    p_file_URL => 'http://10.172.246.160:7777/i/but_choose_file.gif');
    end;
    Second Here is the Package (please note you will have to modify few settings in order to enable it , such as mail server address ..etc)
    ======================================================================================
    CREATE OR REPLACE PACKAGE demo_mail_heb IS
    ----------------------- Customizable Section -----------------------
    -- Customize the SMTP host, port and your domain name below.
    smtp_host VARCHAR2(256) := 'mail.oracle.com';
    smtp_port PLS_INTEGER := 25;
    smtp_domain VARCHAR2(256) := 'oracle.com';
    -- Customize the signature that will appear in the email's MIME header.
    -- Useful for versioning.
    MAILER_ID CONSTANT VARCHAR2(256) := 'Mailer by Oracle UTL_SMTP';
    --------------------- End Customizable Section ---------------------
    -- A unique string that demarcates boundaries of parts in a multi-part email
    -- The string should not appear inside the body of any part of the email.
    -- Customize this if needed or generate this randomly dynamically.
    BOUNDARY CONSTANT VARCHAR2(256) := '-----7D81B75CCC90D2974F7A1CBD';
    FIRST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || utl_tcp.CRLF;
    LAST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || '--' ||
    utl_tcp.CRLF;
    -- A MIME type that denotes multi-part email (MIME) messages.
    MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) := 'multipart/mixed; boundary="'||
    BOUNDARY || '"';
    MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER := 76 / 4 * 3;
    -- Sent clear Html Email
    procedure send_html_mail (p_sender in varchar2 default null,
    p_recipients in varchar2 default null,
    p_subject in varchar2 default null,
    p_data in varchar2 default null,
    p_mime_type in varchar2 default 'text/html; charset=windows-1255');
    -- Sent Html Email with Attachment
    procedure send_html_mail_attach (p_sender in varchar2 default null,
    p_recipients in varchar2 default null,
    p_subject in varchar2 default null,
    p_data in varchar2 default '<b>áå÷ø èåá òåìí - áãé÷ä</b',
    p_mime_type in varchar2 default demo_mail_heb.MULTIPART_MIME_TYPE,
    p_file_name in varchar2 default 'but_choose_file.gif',
    p_file_mime_type in varchar2 default 'application/pdf',
    p_file_URL in varchar2 default 'http://10.172.246.160:7777/i/but_choose_file.gif');
    -- A simple email API for sending email in plain text in a single call.
    -- The format of an email address is one of these:
    -- someone@some-domain
    -- "Someone at some domain" <someone@some-domain>
    -- Someone at some domain <someone@some-domain>
    -- The recipients is a list of email addresses separated by
    -- either a "," or a ";"
    PROCEDURE mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              message IN VARCHAR2);
    -- Extended email API to send email in HTML or plain text with no size limit.
    -- First, begin the email by begin_mail(). Then, call write_text() repeatedly
    -- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
    -- email in non-ASCII or multi-byte character set. End the email with
    -- end_mail().
    FUNCTION begin_mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              mime_type IN VARCHAR2 DEFAULT 'text/plain',
              priority IN PLS_INTEGER DEFAULT NULL)
              RETURN utl_smtp.connection;
    -- Write email body in ASCII
    PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
              message IN VARCHAR2);
    -- Write email body in non-ASCII (including multi-byte). The email body
    -- will be sent in the database character set.
    PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
                   message IN VARCHAR2);
    -- Write email body in binary
    PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
              message IN RAW);
    -- APIs to send email with attachments. Attachments are sent by sending
    -- emails in "multipart/mixed" MIME format. Specify that MIME format when
    -- beginning an email with begin_mail().
    -- Send a single text attachment.
    PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN VARCHAR2,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
              last IN BOOLEAN DEFAULT FALSE);
    -- Send a binary attachment. The attachment will be encoded in Base-64
    -- encoding format.
    PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN RAW,
                   mime_type IN VARCHAR2 DEFAULT 'application/octet',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   last IN BOOLEAN DEFAULT FALSE);
    -- Send an attachment with no size limit. First, begin the attachment
    -- with begin_attachment(). Then, call write_text repeatedly to send
    -- the attachment piece-by-piece. If the attachment is text-based but
    -- in non-ASCII or multi-byte character set, use write_mb_text() instead.
    -- To send binary attachment, the binary content should first be
    -- encoded in Base-64 encoding format using the demo package for 8i,
    -- or the native one in 9i. End the attachment with end_attachment.
    PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   transfer_enc IN VARCHAR2 DEFAULT NULL);
    -- End the attachment.
    PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   last IN BOOLEAN DEFAULT FALSE);
    -- End the email.
    PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);
    -- Extended email API to send multiple emails in a session for better
    -- performance. First, begin an email session with begin_session.
    -- Then, begin each email with a session by calling begin_mail_in_session
    -- instead of begin_mail. End the email with end_mail_in_session instead
    -- of end_mail. End the email session by end_session.
    FUNCTION begin_session RETURN utl_smtp.connection;
    -- Begin an email in a session.
    PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
                        sender IN VARCHAR2,
                        recipients IN VARCHAR2,
                        subject IN VARCHAR2,
    --                     mime_type IN VARCHAR2 DEFAULT 'text/plain; charset=windows-1255',
              mime_type IN VARCHAR2 DEFAULT 'text/plain',
                        priority IN PLS_INTEGER DEFAULT NULL);
    -- End an email in a session.
    PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);
    -- End an email session.
    PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);
    END;
    CREATE OR REPLACE PACKAGE BODY demo_mail_heb IS
    -- Sent clear Html Email
    procedure send_html_mail (p_sender in varchar2 default null,
    p_recipients in varchar2 default null,
    p_subject in varchar2 default null,
    p_data in varchar2 default null,
    p_mime_type in varchar2 default 'text/html; charset=windows-1255')
    Is
    conn utl_smtp.connection;
    BEGIN
    conn := demo_mail_heb.begin_mail(
    sender => p_sender,
    recipients => p_recipients,
    subject => p_subject,
    mime_type => p_mime_type);
    demo_mail_heb.write_text(
    conn => conn,
    message => p_data);
    demo_mail_heb.end_mail( conn => conn );
    END;
    -- Sent Html Email with Attachment
    procedure send_html_mail_attach (p_sender in varchar2 default null,
    p_recipients in varchar2 default null,
    p_subject in varchar2 default null,
    p_data in varchar2 default '<b>áå÷ø èåá òåìí - áãé÷ä</b',
    p_mime_type in varchar2 default demo_mail_heb.MULTIPART_MIME_TYPE,
    p_file_name in varchar2 default 'but_choose_file.gif',
    p_file_mime_type in varchar2 default 'application/pdf',
    p_file_URL in varchar2 default 'http://10.172.246.160:7777/i/but_choose_file.gif')
    is
    conn utl_smtp.connection;
    req utl_http.req;
    resp utl_http.resp;
    data RAW(200);
    begin
    conn := demo_mail_heb.begin_mail(
    sender => p_sender,
    recipients => p_recipients,
    subject => p_subject,
    mime_type => p_mime_type);
    demo_mail_heb.attach_text(
    conn => conn,
    data => p_data,
    mime_type => 'text/html');
    demo_mail_heb.begin_attachment(
    conn => conn,
    mime_type => p_file_mime_type,
    inline => TRUE,
    filename => p_file_name,
    transfer_enc => 'base64');
    -- In writing Base-64 encoded text following the MIME format below,
    -- the MIME format requires that a long piece of data must be splitted
    -- into multiple lines and each line of encoded data cannot exceed
    -- 80 characters, including the new-line characters. Also, when
    -- splitting the original data into pieces, the length of each chunk
    -- of data before encoding must be a multiple of 3, except for the
    -- last chunk. The constant demo_mail_heb.MAX_BASE64_LINE_WIDTH
    -- (76 / 4 * 3 = 57) is the maximum length (in bytes) of each chunk
    -- of data before encoding.
    Utl_Http.set_proxy('www-proxy.us.oracle.com', 'oracle.com');
    req := utl_http.begin_request(p_file_URL);
    resp := utl_http.get_response(req);
    BEGIN
    LOOP
    utl_http.read_raw(resp, data, demo_mail_heb.MAX_BASE64_LINE_WIDTH);
    demo_mail_heb.write_raw(
    conn => conn,
    message => utl_encode.base64_encode(data));
    END LOOP;
    EXCEPTION
    WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
    END;
    demo_mail_heb.end_attachment( conn => conn );
    demo_mail_heb.end_mail( conn => conn );
    end;
    -- Return the next email address in the list of email addresses, separated
    -- by either a "," or a ";". The format of mailbox may be in one of these:
    -- someone@some-domain
    -- "Someone at some domain" <someone@some-domain>
    -- Someone at some domain <someone@some-domain>
    FUNCTION get_address(addr_list IN OUT VARCHAR2) RETURN VARCHAR2 IS
    addr VARCHAR2(256);
    i pls_integer;
    FUNCTION lookup_unquoted_char(str IN VARCHAR2,
                        chrs IN VARCHAR2) RETURN pls_integer AS
    c VARCHAR2(5);
    i pls_integer;
    len pls_integer;
    inside_quote BOOLEAN;
    BEGIN
    inside_quote := false;
    i := 1;
    len := length(str);
    WHILE (i <= len) LOOP
         c := substr(str, i, 1);
         IF (inside_quote) THEN
         IF (c = '"') THEN
         inside_quote := false;
         ELSIF (c = '\') THEN
         i := i + 1; -- Skip the quote character
         END IF;
         GOTO next_char;
         END IF;
         IF (c = '"') THEN
         inside_quote := true;
         GOTO next_char;
         END IF;
         IF (instr(chrs, c) >= 1) THEN
         RETURN i;
         END IF;
         <<next_char>>
         i := i + 1;
    END LOOP;
    RETURN 0;
    END;
    BEGIN
    addr_list := ltrim(addr_list);
    i := lookup_unquoted_char(addr_list, ',;');
    IF (i >= 1) THEN
    addr := substr(addr_list, 1, i - 1);
    addr_list := substr(addr_list, i + 1);
    ELSE
    addr := addr_list;
    addr_list := '';
    END IF;
    i := lookup_unquoted_char(addr, '<');
    IF (i >= 1) THEN
    addr := substr(addr, i + 1);
    i := instr(addr, '>');
    IF (i >= 1) THEN
         addr := substr(addr, 1, i - 1);
    END IF;
    END IF;
    RETURN addr;
    END;
    -- Write a MIME header
    PROCEDURE write_mime_header(conn IN OUT NOCOPY utl_smtp.connection,
                   name IN VARCHAR2,
                   value IN VARCHAR2) IS
    BEGIN
    -- utl_smtp.write_data(conn, name || ': ' || value || utl_tcp.CRLF);
    utl_smtp.write_raw_data(conn, UTL_RAW.CAST_TO_RAW(name || ': ' ||value || utl_tcp.CRLF));
    END;
    -- Mark a message-part boundary. Set <last> to TRUE for the last boundary.
    PROCEDURE write_boundary(conn IN OUT NOCOPY utl_smtp.connection,
                   last IN BOOLEAN DEFAULT FALSE) AS
    BEGIN
    IF (last) THEN
    utl_smtp.write_data(conn, LAST_BOUNDARY);
    ELSE
    utl_smtp.write_data(conn, FIRST_BOUNDARY);
    END IF;
    END;
    PROCEDURE mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              message IN VARCHAR2) IS
    conn utl_smtp.connection;
    BEGIN
    conn := begin_mail(sender, recipients, subject);
    write_text(conn, message);
    end_mail(conn);
    END;
    FUNCTION begin_mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              mime_type IN VARCHAR2 DEFAULT 'text/plain',
              priority IN PLS_INTEGER DEFAULT NULL)
              RETURN utl_smtp.connection IS
    conn utl_smtp.connection;
    BEGIN
    conn := begin_session;
    begin_mail_in_session(conn, sender, recipients, subject, mime_type,
    priority);
    RETURN conn;
    END;
    PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
              message IN VARCHAR2) IS
    BEGIN
    utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(CONVERT(message,'IW8ISO8859P8')));
    END;
    PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
                   message IN VARCHAR2) IS
    BEGIN
    utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
    END;
    PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
              message IN RAW) IS
    BEGIN
    utl_smtp.write_raw_data(conn, message);
    END;
    PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN VARCHAR2,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
              last IN BOOLEAN DEFAULT FALSE) IS
    BEGIN
    begin_attachment(conn, mime_type, inline, filename);
    write_text(conn, data);
    end_attachment(conn, last);
    END;
    PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN RAW,
                   mime_type IN VARCHAR2 DEFAULT 'application/octet',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   last IN BOOLEAN DEFAULT FALSE) IS
    i PLS_INTEGER;
    len PLS_INTEGER;
    BEGIN
    begin_attachment(conn, mime_type, inline, filename, 'base64');
    -- Split the Base64-encoded attachment into multiple lines
    i := 1;
    len := utl_raw.length(data);
    WHILE (i < len) LOOP
    IF (i + MAX_BASE64_LINE_WIDTH < len) THEN
         utl_smtp.write_raw_data(conn,
         utl_encode.base64_encode(utl_raw.substr(data, i,
         MAX_BASE64_LINE_WIDTH)));
    ELSE
         utl_smtp.write_raw_data(conn,
         utl_encode.base64_encode(utl_raw.substr(data, i)));
    END IF;
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    i := i + MAX_BASE64_LINE_WIDTH;
    END LOOP;
    end_attachment(conn, last);
    END;
    PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   transfer_enc IN VARCHAR2 DEFAULT NULL) IS
    BEGIN
    write_boundary(conn);
    write_mime_header(conn, 'Content-Type', mime_type);
    IF (filename IS NOT NULL) THEN
    IF (inline) THEN
         write_mime_header(conn, 'Content-Disposition',
         'inline; filename="'||filename||'"');
    ELSE
         write_mime_header(conn, 'Content-Disposition',
         'attachment; filename="'||filename||'"');
    END IF;
    END IF;
    IF (transfer_enc IS NOT NULL) THEN
    write_mime_header(conn, 'Content-Transfer-Encoding', transfer_enc);
    END IF;
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    END;
    PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   last IN BOOLEAN DEFAULT FALSE) IS
    BEGIN
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    IF (last) THEN
    write_boundary(conn, last);
    END IF;
    END;
    PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    end_mail_in_session(conn);
    end_session(conn);
    END;
    FUNCTION begin_session RETURN utl_smtp.connection IS
    conn utl_smtp.connection;
    BEGIN
    -- open SMTP connection
    conn := utl_smtp.open_connection(smtp_host, smtp_port);
    utl_smtp.helo(conn, smtp_domain);
    RETURN conn;
    END;
    PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
                        sender IN VARCHAR2,
                        recipients IN VARCHAR2,
                        subject IN VARCHAR2,
                        mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   --     mime_type IN VARCHAR2 DEFAULT 'text/plain; charset=windows-1255',
                        priority IN PLS_INTEGER DEFAULT NULL) IS
    my_recipients VARCHAR2(32767) := recipients;
    my_sender VARCHAR2(32767) := sender;
    BEGIN
    -- Specify sender's address (our server allows bogus address
    -- as long as it is a full email address ([email protected]).
    utl_smtp.mail(conn, get_address(my_sender));
    -- Specify recipient(s) of the email.
    WHILE (my_recipients IS NOT NULL) LOOP
    utl_smtp.rcpt(conn, get_address(my_recipients));
    END LOOP;
    -- Start body of email
    utl_smtp.open_data(conn);
    -- Set "From" MIME header
    write_mime_header(conn, 'From', sender);
    -- Set "To" MIME header
    write_mime_header(conn, 'To', recipients);
    -- Set "Subject" MIME header
    write_mime_header(conn, 'Subject', subject);
    -- Set "Content-Type" MIME header
    write_mime_header(conn, 'Content-Type', mime_type);
    -- Set "X-Mailer" MIME header
    write_mime_header(conn, 'X-Mailer', MAILER_ID);
    -- Set priority:
    -- High Normal Low
    -- 1 2 3 4 5
    IF (priority IS NOT NULL) THEN
    write_mime_header(conn, 'X-Priority', priority);
    END IF;
    -- Send an empty line to denotes end of MIME headers and
    -- beginning of message body.
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    IF (mime_type LIKE 'multipart/mixed%') THEN
    write_text(conn, 'This is a multi-part message in MIME format.' ||
         utl_tcp.crlf);
    END IF;
    END;
    PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    utl_smtp.close_data(conn);
    END;
    PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    utl_smtp.quit(conn);
    END;
    END;

    Hello All,
    Small modification - use this package and not the above
    HERE IS A WORKING CODE FOR SENDING HEBREW MESSAGES (INCLUDING SUBJECT IN UTF-8 APPEAR IN ALL EMAIL CLIENTS I HAVE CHECKED) + ATTACHMENTS
    Code attached below is supplied as is with no support. anyhow if help is needed , please contact me via [email protected]
    ============================================================================
    CREATE OR REPLACE PACKAGE demo_mail_heb IS
    ----------------------- Customizable Section -----------------------
    -- Customize the SMTP host, port and your domain name below.
    smtp_host VARCHAR2(256) := pst_ajax.getParameter('EMAIL_SMTP_HOST');
    smtp_port PLS_INTEGER := pst_ajax.getParameter('EMAIL_SMTP_PORT');
    smtp_domain VARCHAR2(256) := pst_ajax.getParameter('EMAIL_SMTP_DOMAIN');
    -- Customize the signature that will appear in the email's MIME header.
    -- Useful for versioning.
    MAILER_ID CONSTANT VARCHAR2(256) := 'Mailer by Oracle UTL_SMTP';
    --------------------- End Customizable Section ---------------------
    -- A unique string that demarcates boundaries of parts in a multi-part email
    -- The string should not appear inside the body of any part of the email.
    -- Customize this if needed or generate this randomly dynamically.
    BOUNDARY CONSTANT VARCHAR2(256) := '-----7D81B75CCC90D2974F7A1CBD';
    FIRST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || utl_tcp.CRLF;
    LAST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || '--' ||
    utl_tcp.CRLF;
    -- A MIME type that denotes multi-part email (MIME) messages.
    MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) := 'multipart/mixed; boundary="'||
    BOUNDARY || '"';
    MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER := 76 / 4 * 3;
    -- Sent clear Html Email
    procedure send_html_mail (p_sender in varchar2 default null,
    p_recipients in varchar2 default null,
    p_subject in varchar2 default null,
    p_data in varchar2 default null,
    p_mime_type in varchar2 default 'text/html; charset=windows-1255');
    -- Sent Html Email with Attachment
    procedure send_html_mail_attach (p_sender in varchar2 default null,
    p_recipients in varchar2 default null,
    p_subject in varchar2 default null,
    p_data in varchar2 default '<b>áå÷ø èåá òåìí - áãé÷ä</b',
    p_mime_type in varchar2 default 'text/html; charset=windows-1255',
    p_file_name in varchar2 default 'but_choose_file.gif',
    p_file_mime_type in varchar2 default 'application/pdf',
    p_file_URL in varchar2 default 'http://10.172.246.160:7777/i/but_choose_file.gif');
    -- A simple email API for sending email in plain text in a single call.
    -- The format of an email address is one of these:
    -- someone@some-domain
    -- "Someone at some domain" <someone@some-domain>
    -- Someone at some domain <someone@some-domain>
    -- The recipients is a list of email addresses separated by
    -- either a "," or a ";"
    PROCEDURE mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              message IN VARCHAR2);
    -- Extended email API to send email in HTML or plain text with no size limit.
    -- First, begin the email by begin_mail(). Then, call write_text() repeatedly
    -- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
    -- email in non-ASCII or multi-byte character set. End the email with
    -- end_mail().
    FUNCTION begin_mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              mime_type IN VARCHAR2 DEFAULT 'text/plain',
              priority IN PLS_INTEGER DEFAULT NULL)
              RETURN utl_smtp.connection;
    -- Write email body in ASCII
    PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
              message IN VARCHAR2);
    -- Write email body in non-ASCII (including multi-byte). The email body
    -- will be sent in the database character set.
    PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
                   message IN VARCHAR2);
    -- Write email body in binary
    PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
              message IN RAW);
    -- APIs to send email with attachments. Attachments are sent by sending
    -- emails in "multipart/mixed" MIME format. Specify that MIME format when
    -- beginning an email with begin_mail().
    -- Send a single text attachment.
    PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN VARCHAR2,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
              last IN BOOLEAN DEFAULT FALSE);
    -- Send a binary attachment. The attachment will be encoded in Base-64
    -- encoding format.
    PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN RAW,
                   mime_type IN VARCHAR2 DEFAULT 'application/octet',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   last IN BOOLEAN DEFAULT FALSE);
    -- Send an attachment with no size limit. First, begin the attachment
    -- with begin_attachment(). Then, call write_text repeatedly to send
    -- the attachment piece-by-piece. If the attachment is text-based but
    -- in non-ASCII or multi-byte character set, use write_mb_text() instead.
    -- To send binary attachment, the binary content should first be
    -- encoded in Base-64 encoding format using the demo package for 8i,
    -- or the native one in 9i. End the attachment with end_attachment.
    PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   transfer_enc IN VARCHAR2 DEFAULT NULL);
    -- End the attachment.
    PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   last IN BOOLEAN DEFAULT FALSE);
    -- End the email.
    PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);
    -- Extended email API to send multiple emails in a session for better
    -- performance. First, begin an email session with begin_session.
    -- Then, begin each email with a session by calling begin_mail_in_session
    -- instead of begin_mail. End the email with end_mail_in_session instead
    -- of end_mail. End the email session by end_session.
    FUNCTION begin_session RETURN utl_smtp.connection;
    -- Handling the Email Subject Line
    function mimeheader_encode(
    p_str varchar2
    , p_charset varchar2 := 'UTF-8') return varchar2;
    -- Begin an email in a session.
    PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
                        sender IN VARCHAR2,
                        recipients IN VARCHAR2,
                        subject IN VARCHAR2,
    --                     mime_type IN VARCHAR2 DEFAULT 'text/plain; charset=windows-1255',
              mime_type IN VARCHAR2 DEFAULT 'text/plain',
                        priority IN PLS_INTEGER DEFAULT NULL);
    -- End an email in a session.
    PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);
    -- End an email session.
    PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);
    END;
    CREATE OR REPLACE PACKAGE BODY demo_mail_heb IS
    -- Sent clear Html Email
    procedure send_html_mail (p_sender in varchar2 default null,
    p_recipients in varchar2 default null,
    p_subject in varchar2 default null,
    p_data in varchar2 default null,
    p_mime_type in varchar2 default 'text/html; charset=windows-1255')
    Is
    conn utl_smtp.connection;
    BEGIN
    conn := demo_mail_heb.begin_mail(
    sender => p_sender,
    recipients => p_recipients,
    subject => p_subject,
    mime_type => 'text/html; charset=UTF-8');--p_mime_type);
    demo_mail_heb.write_text(
    conn => conn,
    message => p_data);
    demo_mail_heb.end_mail( conn => conn );
    END;
    -- Sent Html Email with Attachment
    procedure send_html_mail_attach (p_sender in varchar2 default null,
    p_recipients in varchar2 default null,
    p_subject in varchar2 default null,
    p_data in varchar2 default '<b>áå÷ø èåá òåìí - áãé÷ä</b',
    p_mime_type in varchar2 default 'text/html; charset=windows-1255',
    p_file_name in varchar2 default 'but_choose_file.gif',
    p_file_mime_type in varchar2 default 'application/pdf',
    p_file_URL in varchar2 default 'http://10.172.246.160:7777/i/but_choose_file.gif')
    is
    conn utl_smtp.connection;
    req utl_http.req;
    resp utl_http.resp;
    data RAW(200);
    v_mime_type varchar2(32767):=demo_mail.MULTIPART_MIME_TYPE;
    begin
    conn := demo_mail_heb.begin_mail(
    sender => p_sender,
    recipients => p_recipients,
    subject => p_subject,
    mime_type => v_mime_type);
    demo_mail_heb.attach_text(
    conn => conn,
    data => p_data,
    mime_type => 'text/html');
    demo_mail_heb.begin_attachment(
    conn => conn,
    mime_type => p_file_mime_type,
    inline => TRUE,
    filename => p_file_name,
    transfer_enc => 'base64');
    -- In writing Base-64 encoded text following the MIME format below,
    -- the MIME format requires that a long piece of data must be splitted
    -- into multiple lines and each line of encoded data cannot exceed
    -- 80 characters, including the new-line characters. Also, when
    -- splitting the original data into pieces, the length of each chunk
    -- of data before encoding must be a multiple of 3, except for the
    -- last chunk. The constant demo_mail_heb.MAX_BASE64_LINE_WIDTH
    -- (76 / 4 * 3 = 57) is the maximum length (in bytes) of each chunk
    -- of data before encoding.
    req := utl_http.begin_request(p_file_URL);
    resp := utl_http.get_response(req);
    BEGIN
    LOOP
    utl_http.read_raw(resp, data, demo_mail_heb.MAX_BASE64_LINE_WIDTH);
    demo_mail_heb.write_raw(
    conn => conn,
    message => utl_encode.base64_encode(data));
    END LOOP;
    EXCEPTION
    WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
    END;
    demo_mail_heb.end_attachment( conn => conn );
    demo_mail_heb.end_mail( conn => conn );
    end;
    -- Return the next email address in the list of email addresses, separated
    -- by either a "," or a ";". The format of mailbox may be in one of these:
    -- someone@some-domain
    -- "Someone at some domain" <someone@some-domain>
    -- Someone at some domain <someone@some-domain>
    FUNCTION get_address(addr_list IN OUT VARCHAR2) RETURN VARCHAR2 IS
    addr VARCHAR2(256);
    i pls_integer;
    FUNCTION lookup_unquoted_char(str IN VARCHAR2,
    chrs IN VARCHAR2) RETURN pls_integer AS
    c VARCHAR2(5);
    i pls_integer;
    len pls_integer;
    inside_quote BOOLEAN;
    BEGIN
    inside_quote := false;
    i := 1;
    len := length(str);
    WHILE (i <= len) LOOP
    c := substr(str, i, 1);
    IF (inside_quote) THEN
    IF (c = '"') THEN
    inside_quote := false;
    ELSIF (c = '\') THEN
    i := i + 1; -- Skip the quote character
    END IF;
    GOTO next_char;
    END IF;
    IF (c = '"') THEN
    inside_quote := true;
    GOTO next_char;
    END IF;
    IF (instr(chrs, c) >= 1) THEN
    RETURN i;
    END IF;
    <<next_char>>
    i := i + 1;
    END LOOP;
    RETURN 0;
    END;
    BEGIN
    addr_list := ltrim(addr_list);
    i := lookup_unquoted_char(addr_list, ',;');
    IF (i >= 1) THEN
    addr := substr(addr_list, 1, i - 1);
    addr_list := substr(addr_list, i + 1);
    ELSE
    addr := addr_list;
    addr_list := '';
    END IF;
    i := lookup_unquoted_char(addr, '<');
    IF (i >= 1) THEN
    addr := substr(addr, i + 1);
    i := instr(addr, '>');
    IF (i >= 1) THEN
    addr := substr(addr, 1, i - 1);
    END IF;
    END IF;
    RETURN addr;
    END;
    -- Write a MIME header
    PROCEDURE write_mime_header(conn IN OUT NOCOPY utl_smtp.connection,
    name IN VARCHAR2,
    value IN VARCHAR2) IS
    BEGIN
    -- utl_smtp.write_data(conn, name || ': ' || value || utl_tcp.CRLF);
    utl_smtp.write_raw_data(conn, UTL_RAW.CAST_TO_RAW(name || ': ' ||value || utl_tcp.CRLF));
    END;
    -- Mark a message-part boundary. Set <last> to TRUE for the last boundary.
    PROCEDURE write_boundary(conn IN OUT NOCOPY utl_smtp.connection,
    last IN BOOLEAN DEFAULT FALSE) AS
    BEGIN
    IF (last) THEN
    utl_smtp.write_data(conn, LAST_BOUNDARY);
    ELSE
    utl_smtp.write_data(conn, FIRST_BOUNDARY);
    END IF;
    END;
    PROCEDURE mail(sender IN VARCHAR2,
    recipients IN VARCHAR2,
    subject IN VARCHAR2,
    message IN VARCHAR2) IS
    conn utl_smtp.connection;
    BEGIN
    conn := begin_mail(sender, recipients, subject);
    write_text(conn, message);
    end_mail(conn);
    END;
    FUNCTION begin_mail(sender IN VARCHAR2,
    recipients IN VARCHAR2,
    subject IN VARCHAR2,
    mime_type IN VARCHAR2 DEFAULT 'text/plain',
    priority IN PLS_INTEGER DEFAULT NULL)
    RETURN utl_smtp.connection IS
    conn utl_smtp.connection;
    BEGIN
    conn := begin_session;
    begin_mail_in_session(conn, sender, recipients, subject, mime_type,
    priority);
    RETURN conn;
    END;
    PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
    message IN VARCHAR2) IS
    BEGIN
    utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(CONVERT(message,'IW8ISO8859P8')));
    -- utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
    END;
    PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
    message IN VARCHAR2) IS
    BEGIN
    utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
    END;
    PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
    message IN RAW) IS
    BEGIN
    utl_smtp.write_raw_data(conn, message);
    END;
    PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
    data IN VARCHAR2,
    mime_type IN VARCHAR2 DEFAULT 'text/plain',
    inline IN BOOLEAN DEFAULT TRUE,
    filename IN VARCHAR2 DEFAULT NULL,
    last IN BOOLEAN DEFAULT FALSE) IS
    BEGIN
    begin_attachment(conn, mime_type, inline, filename);
    write_text(conn, data);
    end_attachment(conn, last);
    END;
    PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
    data IN RAW,
    mime_type IN VARCHAR2 DEFAULT 'application/octet',
    inline IN BOOLEAN DEFAULT TRUE,
    filename IN VARCHAR2 DEFAULT NULL,
    last IN BOOLEAN DEFAULT FALSE) IS
    i PLS_INTEGER;
    len PLS_INTEGER;
    BEGIN
    begin_attachment(conn, mime_type, inline, filename, 'base64');
    -- Split the Base64-encoded attachment into multiple lines
    i := 1;
    len := utl_raw.length(data);
    WHILE (i < len) LOOP
    IF (i + MAX_BASE64_LINE_WIDTH < len) THEN
    utl_smtp.write_raw_data(conn,
    utl_encode.base64_encode(utl_raw.substr(data, i,
    MAX_BASE64_LINE_WIDTH)));
    ELSE
    utl_smtp.write_raw_data(conn,
    utl_encode.base64_encode(utl_raw.substr(data, i)));
    END IF;
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    i := i + MAX_BASE64_LINE_WIDTH;
    END LOOP;
    end_attachment(conn, last);
    END;
    PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
    mime_type IN VARCHAR2 DEFAULT 'text/plain',
    inline IN BOOLEAN DEFAULT TRUE,
    filename IN VARCHAR2 DEFAULT NULL,
    transfer_enc IN VARCHAR2 DEFAULT NULL) IS
    BEGIN
    write_boundary(conn);
    write_mime_header(conn, 'Content-Type', mime_type);
    IF (filename IS NOT NULL) THEN
    IF (inline) THEN
    write_mime_header(conn, 'Content-Disposition',
    'inline; filename="'||filename||'"');
    ELSE
    write_mime_header(conn, 'Content-Disposition',
    'attachment; filename="'||filename||'"');
    END IF;
    END IF;
    IF (transfer_enc IS NOT NULL) THEN
    write_mime_header(conn, 'Content-Transfer-Encoding', transfer_enc);
    END IF;
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    END;
    PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
    last IN BOOLEAN DEFAULT FALSE) IS
    BEGIN
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    IF (last) THEN
    write_boundary(conn, last);
    END IF;
    END;
    PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    end_mail_in_session(conn);
    end_session(conn);
    END;
    FUNCTION begin_session RETURN utl_smtp.connection IS
    conn utl_smtp.connection;
    BEGIN
    -- open SMTP connection
    conn := utl_smtp.open_connection(smtp_host, smtp_port);
    utl_smtp.helo(conn, smtp_domain);
    RETURN conn;
    END;
    -- Handling the Email Subject Line
    function mimeheader_encode(
    p_str varchar2
    , p_charset varchar2 := 'UTF-8') return varchar2 is
    l_str varchar2(2000);
    begin
    l_str:=utl_raw.cast_to_varchar2(utl_encode.quoted_printable_encode(utl_raw.cast_to_raw(p_str)));
    l_str:=replace(l_str,'='||chr(13)||chr(10),''); --unfold the data
    l_str:=replace(l_str,'?','=3f'); --quote question marks
    l_str:=replace(l_str,' ','=20'); --quote spaces
    l_str:='=?'||p_charset||'?Q?'||l_str||'?='; -- add prefix and suffix
    return l_str;
    end;
    PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
    sender IN VARCHAR2,
    recipients IN VARCHAR2,
    subject IN VARCHAR2,
    mime_type IN VARCHAR2 DEFAULT 'text/plain',
    -- mime_type IN VARCHAR2 DEFAULT 'text/plain; charset=windows-1255',
    priority IN PLS_INTEGER DEFAULT NULL) IS
    my_recipients VARCHAR2(32767) := recipients;
    my_sender VARCHAR2(32767) := sender;
    BEGIN
    -- Specify sender's address (our server allows bogus address
    -- as long as it is a full email address ([email protected]).
    utl_smtp.mail(conn, get_address(my_sender));
    -- Specify recipient(s) of the email.
    WHILE (my_recipients IS NOT NULL) LOOP
    utl_smtp.rcpt(conn, get_address(my_recipients));
    END LOOP;
    -- Start body of email
    utl_smtp.open_data(conn);
    -- Set "From" MIME header
    write_mime_header(conn, 'From', sender);
    -- Set "To" MIME header
    write_mime_header(conn, 'To', recipients);
    -- Set "Content-Type" MIME header
    write_mime_header(conn, 'Content-Type', mime_type);
    -- write_mime_header(conn, 'Content-Type', 'text/html; charset=UTF-8');
    -- Set "Subject" MIME header
    -- write_mime_header(conn, 'Subject', subject);
    -- write_mime_header(conn, 'Subject', CONVERT(subject,'IW8ISO8859P8'));
    write_mime_header(conn, 'Subject',mimeheader_encode(p_str => subject,p_charset => 'UTF-8'));
    -- write_mime_header(conn, 'Subject',CONVERT(subject,'IW8MSWIN1255'));
    -- Set "X-Mailer" MIME header
    write_mime_header(conn, 'X-Mailer', MAILER_ID);
    -- Set priority:
    -- High Normal Low
    -- 1 2 3 4 5
    IF (priority IS NOT NULL) THEN
    write_mime_header(conn, 'X-Priority', priority);
    END IF;
    -- Send an empty line to denotes end of MIME headers and
    -- beginning of message body.
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    IF (mime_type LIKE 'multipart/mixed%') THEN
    write_text(conn, 'This is a multi-part message in MIME format.' ||
    utl_tcp.crlf);
    END IF;
    END;
    PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    utl_smtp.close_data(conn);
    END;
    PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    utl_smtp.quit(conn);
    END;
    END;

  • Sending email using UTL_SMTP

    Dear experts,
    I am trying to send an email using UTL_SMTP (i switched from UTL_MAIL to UTL_SMTP since i need to send mails with large attachments - BLOB). I am using the demo_mail package given here:
    http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
    While running the program I am getting an error message (from the error.log) saying:
    [Mon Aug 04 14:00:21 2008] [error] [client 192.168.0.7] mod_plsql: /ns/email_p.send HTTP-404 ORA-29279: SMTP permanent error: 530 5.7.0 Must issue a STARTTLS command first. 9sm12723808qbw.6\nORA-06512: at "SYS.UTL_SMTP", line 20\nORA-06512: at "SYS.UTL_SMTP", line 98\nORA-06512: at "SYS.UTL_SMTP", line 221\nORA-06512: at "NEXTSTEP.SEND_EMAIL_HELPER", line 258\nORA-06512: at "NEXTSTEP.SEND_EMAIL_HELPER", line 119\nORA-06512: at "NEXTSTEP.EMAIL_P", line 33\nORA-06512: at line 31\n, referer: file:///C:/Documents and Settings/Mayank/My Documents/Flex Builder 3/ns5/bin-debug/main.swf
    My code is as follows:
    PACKAGE DECLARATION. This is the DEMO_MAIL package posted under above link (I have renamed it).
    CREATE OR REPLACE PACKAGE NEXTSTEP.send_email_helper IS
      ----------------------- Customizable Section -----------------------
      -- Customize the SMTP host, port and your domain name below.
        smtp_host   VARCHAR2(256) := 'smtp.gmail.com';
        smtp_port   PLS_INTEGER   := 587;
        smtp_domain VARCHAR2(256) := null;
      -- Customize the signature that will appear in the email's MIME header.
      -- Useful for versioning.
      MAILER_ID   CONSTANT VARCHAR2(256) := 'Mailer by Oracle UTL_SMTP';
      --------------------- End Customizable Section ---------------------
      -- A unique string that demarcates boundaries of parts in a multi-part email
      -- The string should not appear inside the body of any part of the email.
      -- Customize this if needed or generate this randomly dynamically.
      BOUNDARY        CONSTANT VARCHAR2(256) := '-----7D81B75CCC90D2974F7A1CBD';
      FIRST_BOUNDARY  CONSTANT VARCHAR2(256) := '--' || BOUNDARY || utl_tcp.CRLF;
      LAST_BOUNDARY   CONSTANT VARCHAR2(256) := '--' || BOUNDARY || '--' ||
                                                  utl_tcp.CRLF;
      -- A MIME type that denotes multi-part email (MIME) messages.
      MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) := 'multipart/mixed; boundary="'||
                                                      BOUNDARY || '"';
      MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER   := 76 / 4 * 3;
      -- A simple email API for sending email in plain text in a single call.
      -- The format of an email address is one of these:
      --   someone@some-domain
      --   "Someone at some domain" <someone@some-domain>
      --   Someone at some domain <someone@some-domain>
      -- The recipients is a list of email addresses  separated by
      -- either a "," or a ";"
      PROCEDURE mail(sender     IN VARCHAR2,
             recipients IN VARCHAR2,
             subject    IN VARCHAR2,
             message    IN VARCHAR2);
      -- Extended email API to send email in HTML or plain text with no size limit.
      -- First, begin the email by begin_mail(). Then, call write_text() repeatedly
      -- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
      -- email in non-ASCII or multi-byte character set. End the email with
      -- end_mail().
      FUNCTION begin_mail(sender     IN VARCHAR2,
                  recipients IN VARCHAR2,
                  subject    IN VARCHAR2,
                  mime_type  IN VARCHAR2    DEFAULT 'text/plain',
                  priority   IN PLS_INTEGER DEFAULT NULL)
                  RETURN utl_smtp.connection;
      -- Write email body in ASCII
      PROCEDURE write_text(conn    IN OUT NOCOPY utl_smtp.connection,
                   message IN VARCHAR2);
      -- Write email body in non-ASCII (including multi-byte). The email body
      -- will be sent in the database character set.
      PROCEDURE write_mb_text(conn    IN OUT NOCOPY utl_smtp.connection,
                  message IN            VARCHAR2);
      -- Write email body in binary
      PROCEDURE write_raw(conn    IN OUT NOCOPY utl_smtp.connection,
                  message IN RAW);
      -- APIs to send email with attachments. Attachments are sent by sending
      -- emails in "multipart/mixed" MIME format. Specify that MIME format when
      -- beginning an email with begin_mail().
      -- Send a single text attachment.
      PROCEDURE attach_text(conn         IN OUT NOCOPY utl_smtp.connection,
                data         IN VARCHAR2,
                mime_type    IN VARCHAR2 DEFAULT 'text/plain',
                inline       IN BOOLEAN  DEFAULT TRUE,
                filename     IN VARCHAR2 DEFAULT NULL,
                    last         IN BOOLEAN  DEFAULT FALSE);
      -- Send a binary attachment. The attachment will be encoded in Base-64
      -- encoding format.
      PROCEDURE attach_base64(conn         IN OUT NOCOPY utl_smtp.connection,
                  data         IN RAW,
                  mime_type    IN VARCHAR2 DEFAULT 'application/octet',
                  inline       IN BOOLEAN  DEFAULT TRUE,
                  filename     IN VARCHAR2 DEFAULT NULL,
                  last         IN BOOLEAN  DEFAULT FALSE);
      -- Send an attachment with no size limit. First, begin the attachment
      -- with begin_attachment(). Then, call write_text repeatedly to send
      -- the attachment piece-by-piece. If the attachment is text-based but
      -- in non-ASCII or multi-byte character set, use write_mb_text() instead.
      -- To send binary attachment, the binary content should first be
      -- encoded in Base-64 encoding format using the demo package for 8i,
      -- or the native one in 9i. End the attachment with end_attachment.
      PROCEDURE begin_attachment(conn         IN OUT NOCOPY utl_smtp.connection,
                     mime_type    IN VARCHAR2 DEFAULT 'text/plain',
                     inline       IN BOOLEAN  DEFAULT TRUE,
                     filename     IN VARCHAR2 DEFAULT NULL,
                     transfer_enc IN VARCHAR2 DEFAULT NULL);
      -- End the attachment.
      PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   last IN BOOLEAN DEFAULT FALSE);
      -- End the email.
      PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);
      -- Extended email API to send multiple emails in a session for better
      -- performance. First, begin an email session with begin_session.
      -- Then, begin each email with a session by calling begin_mail_in_session
      -- instead of begin_mail. End the email with end_mail_in_session instead
      -- of end_mail. End the email session by end_session.
      FUNCTION begin_session RETURN utl_smtp.connection;
      -- Begin an email in a session.
      PROCEDURE begin_mail_in_session(conn       IN OUT NOCOPY utl_smtp.connection,
                      sender     IN VARCHAR2,
                      recipients IN VARCHAR2,
                      subject    IN VARCHAR2,
                      mime_type  IN VARCHAR2  DEFAULT 'text/plain',
                      priority   IN PLS_INTEGER DEFAULT NULL);
      -- End an email in a session.
      PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);
      -- End an email session.
      PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);
    END;How should I solve the above error? Can anyone help me with my query please?
    If I add the code to start TLS it still gives me an error. If I add the code
    utl_smtp.command(conn,'STARTTLS');
    utl_smtp.helo(conn, smtp_domain);
    under email_sender_help package just before under begin_session function, it gives me an error saying:
    ORA-29279: SMTP permanent error: 503 5.5.1 EHLO/HELO first. s27sm2097329qbs.12
    So then if i enter the same code after:
    utl_smtp.command(conn,'STARTTLS');
    utl_smtp.helo(conn, smtp_domain);
    It gives me an error:
    ORA-29278: SMTP transient error: 421 Service not available
    Message was edited by:
    Monk
    Message was edited by:
    Monk

    look like rely turned off on the server..
    check this.. or ask your network guys..
    Go to Control Panel->Add or Remove Programs->Click on
    Add/Remove Wndows Components
    Check IIS check box.
    Select Internet Information Service (IIS) option and click on Details button
    Check whether SMTP Service is checked or not.
    If not selected then select SMTP check box.
    This process should be done on server.
    It will help out from ORA-29278: SMTP transient error: 421 Service not available problem.
    thanks

  • Upload Purchase order text tab using BDC

    Is it possible to upload Purchase order text tab in material master (tcode mm01) using a BDC.
    If so pls tell me how to upload the same, what is the field name of the box.
    Regards,
    Senthil

    u need to use READ_TEXT or SAVE_TEXT or WRITE_TEXT or COMMIT_TEXT to upload text into SAP.

  • If you need to FTP with PL/SQL...

    If you need to perform FTP from within PL/SQL and your database version has the UTL_TCP package, here is a free package you can use. The source code is hopefully documented well enough for you to tell what's going on and how to use the functions. Suggestions on improving the code are welcome, and I can provide limited support via email for what I've written, but I would encourage anyone who uses the code to modify/fix it according to their needs. If you modify the code, I respectfully request that you leave intact the authorship and note comments at the beginning of the package.
    Please note that I have not rigorously tested this code, but it has successfully transferred files in both directions in the limited tests that I have performed.
    -- Copy the code below and run it in your favorite SQL editor --
    CREATE OR REPLACE PACKAGE FTP IS
    Simplified FTP client API using UTL_TCP package
    Author: Alan Wessman, Brigham Young University
    Note: This FTP client attempts to adhere to the protocol and advice found at:
    http://cr.yp.to/ftp.html
    No warranties are made regarding the correctness of this code.
    Notes:
    1. Most of these functions will raise UTL_TCP.NETWORK_ERROR if the connection
    is not open or is reset during the network transaction. They will also
    raise VALUE_ERROR if the server response is ill-formed or a buffer is
    too small to hold data. (Most buffers in this package are defined as
    VARCHAR2(32767) to avoid size limitations; reduce this if memory overhead
    is a concern.)
    2. "Verbose mode" can be enabled/disabled by changing the default value of
    the vDebug variable in the package body. Setting vDebug to TRUE will
    cause a session transcript to be output to DBMS_OUTPUT.
    3. The following is an example of how this package might be used:
    declare
    c utl_tcp.connection;
    vresp varchar2(32767);
    vbuf varchar2(32767);
    vresp_code number;
    vremote_host varchar2(32) := 'some.hostname.com';
    vusername varchar2(8) := 'username';
    vpassword varchar2(8) := 'password';
    begin
    dbms_output.put_line( 'Opening session...' );
    vresp_code := ftp.open_session( c,
    vremote_host,
    vusername,
    vpassword,
    vresp,
    5 );
    vresp_code := ftp.put( c,
    '/home/somebody',
    'local.test',
    'remote.test',
    vresp );
    vresp_code := ftp.remote_command( c, 'CHMOD 660 remote.test' );
    vresp_code := ftp.chdir( c, '/home/somebody/subdir' );
    vresp_code := ftp.pwd( c );
    vresp_code := ftp.get( c,
    '/home/somebody',
    'new_file.test',
    'another_remote_file.test',
    vresp );
    vresp_code := ftp.close_session( c );
    dbms_output.put_line( 'Closed session.' );
    exception
    when others then dbms_output.put_line( sqlcode || ':' || sqlerrm );
    end;
    Function: Open_Session
    Description: Begins an FTP session with the remote server.
    Parameters:
    conn OUT parameter that contains the connection info; to be passed
    in to subsequent commands to maintain session state.
    host Name or IP address of remote server
    username User ID to use for login
    password Password to use for login
    response OUT parameter; buffer for server replies
    timeout_secs Number of seconds for TCP timeout. Pass in NULL to disable
    timeout (wait forever for responses). Pass in 0 (zero) for
    no wait.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if host parameter is incorrect or if
    some other networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed.
    FUNCTION Open_Session( conn OUT NOCOPY UTL_TCP.Connection,
    host IN VARCHAR2,
    username IN VARCHAR2,
    password IN VARCHAR2,
    response OUT VARCHAR2,
    timeout_secs IN NUMBER DEFAULT 60 ) RETURN NUMBER;
    Function: Get
    Description: Retrieves a file on the remote server and stores its contents in
    a VARCHAR2 buffer.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    buf OUT parameter; buffer for retrieved file contents
    remote_path Pathname (including file name) indicating location of remote
    file to be retrieved
    response OUT parameter; buffer for server replies.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed or buf is
    too small for file contents.
    FUNCTION Get( conn IN OUT NOCOPY UTL_TCP.Connection,
    buf OUT VARCHAR2,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER;
    Function: Get
    Description: Retrieves a file on the remote server and stores its contents in
    a local file. Assumes an open file handle and does not close it.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    local_file IN OUT parameter; UTL_FILE file handle for input file. File
    is assumed to be open for writing.
    remote_path Pathname (including file name) indicating location of remote
    file to be retrieved
    response OUT parameter; buffer for server replies.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed or buf is
    too small for file contents.
    May raise any of the UTL_FILE exceptions if file write operations
    fail. See UTL_FILE documentation for additional details.
    FUNCTION Get( conn IN OUT NOCOPY UTL_TCP.Connection,
    local_file IN OUT UTL_FILE.File_Type,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER;
    Function: Get
    Description: Retrieves a file on the remote server and stores its contents in
    a local file. Opens and closes local file automatically.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    local_path Pathname of local directory in which to store the retrieved
    file's contents
    local_filename Name of local file in which to store retrieved file's contents
    (creates new file or overwrites existing file)
    remote_path Pathname (including file name) indicating location of remote
    file to be retrieved
    response OUT parameter; buffer for server replies.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed or buf is
    too small for file contents.
    May raise any of the UTL_FILE exceptions if file open, write, or
    close operations fail. See UTL_FILE documentation for additional
    details.
    FUNCTION Get( conn IN OUT NOCOPY UTL_TCP.Connection,
    local_path IN VARCHAR2,
    local_filename IN VARCHAR2,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER;
    Function: Put
    Description: Stores data as a file on the remote server
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    buf IN parameter; contains data to upload
    remote_path Pathname (including file name) indicating location of remote
    file to be created/overwritten
    response OUT parameter; buffer for server replies.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed.
    FUNCTION Put( conn IN OUT NOCOPY UTL_TCP.Connection,
    buf IN VARCHAR2,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER;
    Function: Put
    Description: Uploads a local file to the remote server. Assumes an open file
    handle and does not close it.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    local_file IN OUT parameter; UTL_FILE file handle for input file. File
    is assumed to be open for reading.
    remote_path Pathname (including file name) indicating location of remote
    file to be created/overwritten.
    response OUT parameter; buffer for server replies.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed.
    May raise any of the UTL_FILE exceptions if file read operations
    fail. See UTL_FILE documentation for additional details.
    FUNCTION Put( conn IN OUT NOCOPY UTL_TCP.Connection,
    local_file IN OUT UTL_FILE.File_Type,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER;
    Function: Put
    Description: Uploads a local file to the remote server. Opens and closes local
    file automatically.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    local_path Pathname of local directory in which file to upload exists.
    local_filename Name of local file to upload.
    remote_path Pathname (including file name) indicating location of remote
    file to be created/overwritten.
    response OUT parameter; buffer for server replies.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed.
    May raise any of the UTL_FILE exceptions if file open, read, or
    close operations fail. See UTL_FILE documentation for additional
    details.
    FUNCTION Put( conn IN OUT NOCOPY UTL_TCP.Connection,
    local_path IN VARCHAR2,
    local_filename IN VARCHAR2,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER;
    Function: Remote_Command
    Description: Sends an arbitrary command to the server via the SITE command.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    command Command and parameter(s) to send to the server, e.g.
    'CHMOD 600 foo.txt'
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed.
    FUNCTION Remote_Command( conn IN OUT NOCOPY UTL_TCP.Connection,
    command IN VARCHAR2 ) RETURN NUMBER;
    Function: Chdir
    Description: Changes current working directory on remote server to specified
    path.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    remote_path Path on remote server to change to.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed.
    FUNCTION Chdir( conn IN OUT NOCOPY UTL_TCP.Connection,
    remote_path IN VARCHAR2 ) RETURN NUMBER;
    Function: Pwd
    Description: Prints current working directory (on remote server) to debugging
    output if debugging is turned on.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    Return value: 0 (zero) if operation is successful; FTP error code if operation
    is not successful.
    Exceptions: May raise UTL_TCP.NETWORK_ERROR if some networking error occurs.
    May raise VALUE_ERROR if server response is ill-formed.
    FUNCTION Pwd( conn IN OUT NOCOPY UTL_TCP.Connection ) RETURN NUMBER;
    Function: Close_Session
    Description: Closes the TCP connection to the remote server.
    Parameters:
    conn IN OUT parameter that contains the connection info; to be
    passed in to subsequent commands to maintain session state.
    Return value: 0 (zero)
    Exceptions: None raised.
    FUNCTION Close_Session( conn IN OUT NOCOPY UTL_TCP.Connection ) RETURN NUMBER;
    Function: Close_All_Sessions
    Description: Closes all currently open TCP connections.
    Parameters: None.
    Return value: 0 (zero)
    Exceptions: None raised.
    FUNCTION Close_All_Sessions RETURN NUMBER;
    END FTP;
    CREATE OR REPLACE PACKAGE BODY FTP IS
    vDebug BOOLEAN := TRUE;
    FATAL_ERROR EXCEPTION;
    PROCEDURE Debug( msg IN VARCHAR2 ) IS
    BEGIN
    IF vDebug THEN
    DBMS_OUTPUT.Put_Line( msg );
    END IF;
    END Debug;
    FUNCTION Get_Response( conn IN OUT NOCOPY UTL_TCP.Connection,
    buf IN OUT VARCHAR2 ) RETURN NUMBER IS
    vLen NUMBER;
    vCode NUMBER;
    vResp VARCHAR2(32767);
    BEGIN
    vLen := UTL_TCP.READ_LINE( conn, vResp );
    Debug( vResp );
    -- If TO_NUMBER below fails, let the exception propagate to calling proc
    vCode := TO_NUMBER( SUBSTR( vResp, 1, 3 ) );
    vResp := SUBSTR( vResp, 4 );
    buf := buf || SUBSTR( vResp, 2 );
    IF SUBSTR( vResp, 1, 1 ) = '-' THEN
    LOOP
    vLen := UTL_TCP.READ_LINE( conn, vResp );
    Debug( vResp );
    <<Get_Code>>
    BEGIN
    vCode := TO_NUMBER( SUBSTR( vResp, 1, 3 ) );
    vResp := SUBSTR( vResp, 4 );
    IF SUBSTR( vResp, 1, 1 ) = ' ' THEN
    buf := buf || SUBSTR( vResp, 2 );
    EXIT;
    END IF;
    EXCEPTION WHEN VALUE_ERROR THEN NULL;
    END Get_Code;
    buf := buf || vResp;
    END LOOP;
    END IF;
    RETURN vCode;
    END Get_Response;
    FUNCTION Do_Command( conn IN OUT NOCOPY UTL_TCP.Connection,
    cmd IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER IS
    vResult NUMBER := 0;
    BEGIN
    vResult := UTL_TCP.WRITE_LINE( conn, cmd );
    vResult := Get_Response( conn, response );
    RETURN vResult;
    END Do_Command;
    FUNCTION Parse_Port_Number( port_string IN VARCHAR2 ) RETURN NUMBER IS
    vResult NUMBER;
    vNew_Port_String VARCHAR2(32767);
    BEGIN
    -- This stuff parses out the port number encoding from the server reply
    -- Reply is in the format xyzh1,h2,h3,h4,p1,p2xyz
    -- xyz = possible character data (server-dependent, may not exist)
    -- h1-h4 = server IP elements; ignore since we know the host already
    -- p1,p2 = port number encoding (port number = p1 * 256 + p2 )
    vNew_Port_String := TRANSLATE( port_string, '0123456789', '0000000000' );
    vNew_Port_String := SUBSTR( port_string,
    INSTR( vNew_Port_String, '0' ),
    INSTR( vNew_Port_String, '0', -1 ) -
    INSTR( vNew_Port_String, '0' ) + 1 );
    vNew_Port_String := SUBSTR( vNew_Port_String,
    INSTR( vNew_Port_String, ',', 1, 4 ) + 1 );
    vResult := 256 * TO_NUMBER( SUBSTR( vNew_Port_String,
    1,
    INSTR( vNew_Port_String, ',' ) - 1 ) );
    vResult := vResult + TO_NUMBER( SUBSTR( vNew_Port_String,
    INSTR( vNew_Port_String, ',' ) + 1 ) );
    RETURN vResult;
    -- Allow VALUE_ERROR to propagate
    END Parse_Port_Number;
    FUNCTION Open_Session( conn OUT NOCOPY UTL_TCP.Connection,
    host IN VARCHAR2,
    username IN VARCHAR2,
    password IN VARCHAR2,
    response OUT VARCHAR2,
    timeout_secs IN NUMBER DEFAULT 60 ) RETURN NUMBER IS
    vResp_Code NUMBER;
    vGarbage NUMBER; -- For calling functions when we don't care about return val
    BEGIN
    conn := UTL_TCP.OPEN_CONNECTION( host,
    21,
    tx_timeout => timeout_secs );
    vResp_Code := Get_Response( conn, response );
    IF vResp_Code = 220 THEN
    vResp_Code := Do_Command( conn, 'USER ' || username, response );
    IF vResp_Code IN ( 331, 332 ) THEN
    vResp_Code := Do_Command( conn, 'PASS ' || password, response );
    IF vResp_Code NOT IN ( 202, 230 ) THEN
    RAISE FATAL_ERROR;
    END IF;
    ELSE
    RAISE FATAL_ERROR;
    END IF;
    END IF;
    vResp_Code := Do_Command( conn, 'TYPE I', response );
    Debug( 'Logged into ' || conn.remote_host || ' at port ' || conn.remote_port );
    RETURN 0;
    EXCEPTION
    WHEN FATAL_ERROR THEN
    Debug( 'Fatal error opening session:' );
    Debug( ' Code: ' || vResp_Code );
    Debug( ' Response: ' || response );
    vGarbage := Close_Session( conn );
    RETURN vResp_Code;
    END Open_Session;
    FUNCTION Get( conn IN OUT NOCOPY UTL_TCP.Connection,
    buf OUT VARCHAR2,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER IS
    vResp VARCHAR2(32767);
    vResp_Code NUMBER;
    vNew_Conn UTL_TCP.Connection;
    vNew_Port NUMBER;
    BEGIN
    -- do PASV
    vResp_Code := Do_Command( conn, 'PASV', response );
    IF vResp_Code = 227 THEN
    <<Switch_Port>>
    BEGIN
    vNew_Port := Parse_Port_Number( response );
    vNew_Conn := UTL_TCP.OPEN_CONNECTION( conn.remote_host,
    vNew_Port,
    tx_timeout => conn.tx_timeout );
    Debug( 'Data connection: ' || vNew_Conn.remote_host || ':' || vNew_Conn.remote_port );
    vResp_Code := Do_Command( conn, 'RETR ' || REPLACE( remote_path, CHR(12), CHR(0) ), response );
    IF vResp_Code <> 150 THEN
    RAISE FATAL_ERROR;
    END IF;
    <<Get_Download>>
    BEGIN
    LOOP
    vResp := vResp || UTL_TCP.GET_LINE( vNew_Conn, FALSE );
    END LOOP;
    EXCEPTION
    WHEN UTL_TCP.END_OF_INPUT THEN NULL;
    END Get_Download;
    vResp_Code := Close_Session( vNew_Conn );
    vResp_Code := Get_Response( conn, response );
    IF vResp_Code BETWEEN 400 AND 599 THEN
    RAISE FATAL_ERROR;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    Debug( SQLERRM );
    RAISE FATAL_ERROR;
    END Switch_Port;
    ELSE
    RAISE FATAL_ERROR;
    END IF;
    vResp_Code := Close_Session( vNew_Conn );
    buf := vResp;
    RETURN 0;
    EXCEPTION
    WHEN FATAL_ERROR THEN
    Debug( 'Fatal error getting ' || remote_path || ':' );
    Debug( ' Code: ' || vResp_Code );
    Debug( ' Response: ' || response );
    vResp_Code := Close_Session( vNew_Conn );
    RETURN vResp_Code;
    WHEN OTHERS THEN
    Debug( vResp_Code || ': ' || SQLERRM );
    RETURN vResp_Code;
    END Get;
    FUNCTION Get( conn IN OUT NOCOPY UTL_TCP.Connection,
    local_file IN OUT UTL_FILE.File_Type,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER IS
    vResp VARCHAR2(32767);
    vResp_Code NUMBER := -1;
    vNew_Conn UTL_TCP.Connection;
    vNew_Port NUMBER;
    BEGIN
    -- do PASV
    vResp_Code := Do_Command( conn, 'PASV', response );
    IF vResp_Code = 227 THEN
    <<Switch_Port>>
    BEGIN
    vNew_Port := Parse_Port_Number( response );
    vNew_Conn := UTL_TCP.OPEN_CONNECTION( conn.remote_host,
    vNew_Port,
    tx_timeout => conn.tx_timeout );
    Debug( 'Data connection: ' || vNew_Conn.remote_host || ':' || vNew_Conn.remote_port );
    vResp_Code := Do_Command( conn, 'RETR ' || REPLACE( remote_path, CHR(12), CHR(0) ), response );
    IF vResp_Code <> 150 THEN
    RAISE FATAL_ERROR;
    END IF;
    <<Get_Download>>
    BEGIN
    LOOP
    vResp := UTL_TCP.GET_LINE( vNew_Conn, FALSE );
    UTL_FILE.Put( local_file, vResp );
    END LOOP;
    EXCEPTION
    WHEN UTL_TCP.END_OF_INPUT THEN NULL;
    END Get_Download;
    vResp_Code := Close_Session( vNew_Conn );
    vResp_Code := Get_Response( conn, response );
    IF vResp_Code BETWEEN 400 AND 599 THEN
    RAISE FATAL_ERROR;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    Debug( SQLERRM );
    RAISE FATAL_ERROR;
    END Switch_Port;
    ELSE
    RAISE FATAL_ERROR;
    END IF;
    vResp_Code := Close_Session( vNew_Conn );
    RETURN 0;
    EXCEPTION
    WHEN FATAL_ERROR THEN
    Debug( 'Fatal error getting ' || remote_path || ':' );
    Debug( ' Code: ' || vResp_Code );
    Debug( ' Response: ' || response );
    vResp_Code := Close_Session( vNew_Conn );
    RETURN vResp_Code;
    WHEN OTHERS THEN
    Debug( vResp_Code || ': ' || SQLERRM );
    RETURN vResp_Code;
    END Get;
    FUNCTION Get( conn IN OUT NOCOPY UTL_TCP.Connection,
    local_path IN VARCHAR2,
    local_filename IN VARCHAR2,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER IS
    vFile UTL_FILE.File_Type;
    vResult NUMBER := -1;
    BEGIN
    vFile := UTL_FILE.FOPEN( local_path, local_filename, 'w' );
    vResult := Get( conn, vFile, remote_path, response );
    UTL_FILE.FCLOSE( vFile );
    RETURN vResult;
    EXCEPTION WHEN OTHERS THEN
    IF UTL_FILE.IS_OPEN( vFile ) THEN
    UTL_FILE.FCLOSE( vFile );
    END IF;
    RAISE;
    END Get;
    FUNCTION Put( conn IN OUT NOCOPY UTL_TCP.Connection,
    buf IN VARCHAR2,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER IS
    vResp VARCHAR2(32767);
    vResp_Code NUMBER;
    vNew_Conn UTL_TCP.Connection;
    vNew_Port NUMBER;
    BEGIN
    -- do PASV
    vResp_Code := Do_Command( conn, 'PASV', response );
    IF vResp_Code = 227 THEN
    <<Switch_Port>>
    BEGIN
    vNew_Port := Parse_Port_Number( response );
    vNew_Conn := UTL_TCP.OPEN_CONNECTION( conn.remote_host,
    vNew_Port,
    tx_timeout => conn.tx_timeout );
    Debug( 'Data connection: ' || vNew_Conn.remote_host || ':' || vNew_Conn.remote_port );
    vResp_Code := Do_Command( conn, 'STOR ' || REPLACE( remote_path, CHR(12), CHR(0) ), response );
    IF vResp_Code <> 150 THEN
    RAISE FATAL_ERROR;
    END IF;
    vResp_Code := UTL_TCP.WRITE_TEXT( vNew_Conn, buf );
    UTL_TCP.FLUSH( vNew_Conn );
    vResp_Code := Close_Session( vNew_Conn );
    vResp_Code := Get_Response( conn, response );
    IF vResp_Code BETWEEN 400 AND 599 THEN
    RAISE FATAL_ERROR;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    Debug( SQLERRM );
    RAISE FATAL_ERROR;
    END Switch_Port;
    ELSE
    RAISE FATAL_ERROR;
    END IF;
    vResp_Code := Close_Session( vNew_Conn );
    response := vResp;
    RETURN 0;
    EXCEPTION
    WHEN FATAL_ERROR THEN
    Debug( 'Fatal error putting ' || remote_path || ':' );
    Debug( ' Code: ' || vResp_Code );
    Debug( ' Response: ' || response );
    vResp_Code := Close_Session( vNew_Conn );
    RETURN vResp_Code;
    WHEN OTHERS THEN
    Debug( vResp_Code || ': ' || SQLERRM );
    RETURN vResp_Code;
    END Put;
    FUNCTION Put( conn IN OUT NOCOPY UTL_TCP.Connection,
    local_file IN OUT UTL_FILE.File_Type,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER IS
    vResp VARCHAR2(32767);
    vResp_Code NUMBER;
    vNew_Conn UTL_TCP.Connection;
    vNew_Port NUMBER;
    vNew_Port_String VARCHAR2(32767);
    BEGIN
    -- do PASV
    vResp_Code := Do_Command( conn, 'PASV', response );
    IF vResp_Code = 227 THEN
    <<Switch_Port>>
    BEGIN
    vNew_Port := Parse_Port_Number( response );
    vNew_Conn := UTL_TCP.OPEN_CONNECTION( conn.remote_host,
    vNew_Port,
    tx_timeout => conn.tx_timeout );
    Debug( 'Data connection: ' || vNew_Conn.remote_host || ':' || vNew_Conn.remote_port );
    vResp_Code := Do_Command( conn, 'STOR ' || REPLACE( remote_path, CHR(12), CHR(0) ), response );
    IF vResp_Code <> 150 THEN
    RAISE FATAL_ERROR;
    END IF;
    <<Get_Download>>
    BEGIN
    LOOP
    UTL_FILE.Get_Line( local_file, vResp );
    vResp_Code := UTL_TCP.WRITE_LINE( vNew_Conn, vResp );
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN NULL;
    END Get_Download;
    vResp_Code := Close_Session( vNew_Conn );
    vResp_Code := Get_Response( conn, response );
    IF vResp_Code BETWEEN 400 AND 599 THEN
    RAISE FATAL_ERROR;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    Debug( SQLERRM );
    RAISE FATAL_ERROR;
    END Switch_Port;
    ELSE
    RAISE FATAL_ERROR;
    END IF;
    vResp_Code := Close_Session( vNew_Conn );
    RETURN 0;
    EXCEPTION
    WHEN FATAL_ERROR THEN
    Debug( 'Fatal error putting ' || remote_path || ':' );
    Debug( ' Code: ' || vResp_Code );
    Debug( ' Response: ' || response );
    vResp_Code := Close_Session( vNew_Conn );
    RETURN vResp_Code;
    WHEN OTHERS THEN
    Debug( vResp_Code || ': ' || SQLERRM );
    RETURN vResp_Code;
    END Put;
    FUNCTION Put( conn IN OUT NOCOPY UTL_TCP.Connection,
    local_path IN VARCHAR2,
    local_filename IN VARCHAR2,
    remote_path IN VARCHAR2,
    response OUT VARCHAR2 ) RETURN NUMBER IS
    vFile UTL_FILE.File_Type;
    vResult NUMBER;
    BEGIN
    vFile := UTL_FILE.FOPEN( local_path, local_filename, 'r' );
    vResult := Put( conn, vFile, remote_path, response );
    UTL_FILE.FCLOSE( vFile );
    RETURN vResult;
    EXCEPTION WHEN OTHERS THEN
    IF UTL_FILE.IS_OPEN( vFile ) THEN
    UTL_FILE.FCLOSE( vFile );
    END IF;
    RAISE;
    END Put;
    FUNCTION Remote_Command( conn IN OUT NOCOPY UTL_TCP.Connection,
    command IN VARCHAR2 ) RETURN NUMBER IS
    vResp_Code NUMBER;
    vResponse VARCHAR2(32767);
    BEGIN
    vResp_Code := Do_Command( conn, 'SITE ' || command, vResponse );
    IF vResp_Code BETWEEN 500 AND 599 THEN
    RETURN vResp_Code;
    END IF;
    RETURN 0;
    END Remote_Command;
    FUNCTION Chdir( conn IN OUT NOCOPY UTL_TCP.Connection,
    remote_path IN VARCHAR2 ) RETURN NUMBER IS
    vResp_Code NUMBER;
    vResponse VARCHAR2(32767);
    BEGIN
    vResp_Code := Do_Command( conn, 'CWD ' || REPLACE( remote_path, CHR(12), CHR(0) ), vResponse );
    IF vResp_Code BETWEEN 500 AND 599 THEN
    RETURN vResp_Code;
    END IF;
    RETURN 0;
    END Chdir;
    FUNCTION Pwd( conn IN OUT NOCOPY UTL_TCP.Connection ) RETURN NUMBER IS
    vResp_Code NUMBER;
    vResponse VARCHAR2(32767);
    BEGIN
    vResp_Code := Do_Command( conn, 'PWD', vResponse );
    IF vResp_Code BETWEEN 500 AND 599 THEN
    RETURN vResp_Code;
    END IF;
    RETURN 0;
    END Pwd;
    FUNCTION Close_Session( conn IN OUT NOCOPY UTL_TCP.Connection ) RETURN NUMBER IS
    BEGIN
    IF conn.remote_host IS NULL THEN
    RETURN 0;
    END IF;
    Debug( 'Closing connection on ' || conn.remote_host || ':' || conn.remote_port );
    UTL_TCP.Close_Connection( conn );
    RETURN 0;
    EXCEPTION
    WHEN UTL_TCP.NETWORK_ERROR THEN RETURN 0;
    END Close_Session;
    FUNCTION Close_All_Sessions RETURN NUMBER IS
    BEGIN
    UTL_TCP.Close_All_Connections;
    RETURN 0;
    END Close_All_Sessions;
    END FTP;

    Here's another PL/SQL package that will FTP ASCII text files. It assumes that you have proper permissions on the remote host and simply want to transfer one or more text files, not perform any other miscellaneous commands.
    Also, from what I have read, in 9i UTL_FILE supports reading and writing of binary data so an FTP client could be written to transfer either ASCII or BINARY files.
    Regards,
    Russ
    CREATE OR REPLACE PACKAGE BRNC_FTP_PKG
    AS
    * PL/SQL FTP Client
    * Created by: Russ Johnson, Braun Consulting
    * www.braunconsult.com
    * OVERVIEW
    * This package uses the standard packages UTL_FILE and UTL_TCP to perform
    * client-side FTP functionality (PUT and GET) for text files as defined in
    * the World Wide Web Consortium's RFC 959 document - http://www.w3.org/Protocols/rfc959/
    * The procedures and functions in this package allow single or multiple file transfer using
    * standard TCP/IP connections.
    * LIMITATIONS
    * Currently the API is limited to transfer of ASCII text files only. This is
    * primarily because UTL_FILE only supports text I/O, but also because the original
    * design was for creating text files from data in the Oracle database, then transferring the file to a remote host.
    * Furthermore, the API does not support SSH/Secure FTP or connection through a proxy server.
    * Keep in mind that FTP passes the username/password combo in plain text over TCP/IP.
    * DB versions - 8i (8.1.x) and above. 8.0.x may work if it has the SYS.UTL_TCP package.
    * Note: Since UTL_FILE is used for the client-side I/O, this package is also limited to
    * transfer of files that exist in directories available to UTL_FILE for read/write.
    * These directories are defined by the UTL_FILE_DIR parameter in the init.ora file.
    * USAGE
    * Three functions are available for FTP - PUT, GET, and FTP_MULTIPLE. FTP_MULTIPLE takes
    * a table of records that define the files to be transferred (filename, directory, etc.).
    * That table can have 1 record or multiple records. The PUT and GET functions are included
    * for convenience to FTP one file at a time. PUT and GET return true if the file is transferred
    * successfully and false if it fails. FTP_MULTIPLE returns true if no batch-level errors occur
    * (such as an invalid host, refused connection, or invalid login information). It also takes the
    * table of file records IN and passes it back OUT. Each record contains individual error information.
    * EXAMPLE
    * Transfer multiple files - 1 GET and 2 PUT from a Windows machine to a host (assuming UNIX here).
    * Display any errors that occur.
    * DECLARE
    *      v_username      VARCHAR2(40) := 'rjohnson';
    * v_password      VARCHAR2(40) := 'password';
    * v_hostname      VARCHAR2(255) := 'ftp.oracle.com';
    * v_error_message      VARCHAR2(1000);
    * b_put           BOOLEAN;
    * t_files      BRNC_FTP_PKG.t_ftp_rec; -- Declare our table of file records
    * BEGIN
    * t_files(1).localpath           := 'd:\oracle\utl_file\outbound';
    * t_files(1).filename           := 'myfile1.txt';
    * t_files(1).remotepath           := '/home/oracle/text_files';
    * t_files(1).transfer_mode      := 'PUT';
    * t_files(2).localpath           := 'd:\oracle\utl_file\inbound';
    * t_files(2).filename           := 'incoming_file.xml';
    * t_files(2).remotepath           := '/home/oracle/xml_files';
    * t_files(2).transfer_mode      := 'GET';
    * t_files(3).localpath           := 'd:\oracle\utl_file\outbound';
    * t_files(3).filename           := 'myfile2.txt';
    * t_files(3).remotepath      := '/home';
    * t_files(3).transfer_mode      := 'PUT';
    * b_put := BRNC_FTP_PKG.FTP_MULTIPLE(v_error_message,
    * t_files,
    * v_username,
    * v_password,
    * v_hostname);
    * IF b_put = TRUE
    * THEN
    *     FOR i IN t_files.FIRST..t_files.LAST
    *     LOOP
    * IF t_files.EXISTS(i)
    * THEN
    *      DBMS_OUTPUT.PUT_LINE(t_files(i).status||' | '||
    * t_files(i).error_message||' | '||
    * to_char(t_files(i).bytes_transmitted)||' | '||
    * to_char(t_files(i).trans_start,'YYYY-MM-DD HH:MI:SS')||' | '||
    * to_char(t_files(i).trans_end,'YYYY-MM-DD HH:MI:SS'));
    * END IF;
    *      END LOOP;
    * ELSE
    *      DBMS_OUTPUT.PUT_LINE(v_error_message);
    * END IF;
    * EXCEPTION
    * WHEN OTHERS
    * THEN
    * DBMS_OUTPUT.PUT_LINE(SQLERRM);
    * END;
    * CREDITS
    * The W3C's RFC 959 that describes the FTP process.
    * http://www.w3c.org
    * Much of the PL/SQL code in this package was based on Java code written by
    * Bruce Blackshaw of Enterprise Distributed Technologies Ltd. None of that code
    * was copied, but the objects and methods greatly helped my understanding of the
    * FTP Client process.
    * http://www.enterprisedt.com
    *     VERSION HISTORY
    * 1.0 11/19/2002 Unit-tested single and multiple transfers between disparate hosts.                                    
    * Exceptions
    ctrl_exception     EXCEPTION;
    data_exception     EXCEPTION;
    * Constants - FTP valid response codes
    CONNECT_CODE     CONSTANT PLS_INTEGER := 220;
    USER_CODE          CONSTANT PLS_INTEGER := 331;
    LOGIN_CODE          CONSTANT PLS_INTEGER := 230;
    PWD_CODE          CONSTANT PLS_INTEGER := 257;
    PASV_CODE          CONSTANT PLS_INTEGER := 227;
    CWD_CODE          CONSTANT PLS_INTEGER := 250;
    TSFR_START_CODE1     CONSTANT PLS_INTEGER := 125;
    TSFR_START_CODE2     CONSTANT PLS_INTEGER := 150;
    TSFR_END_CODE     CONSTANT PLS_INTEGER := 226;
    QUIT_CODE          CONSTANT PLS_INTEGER := 221;
    SYST_CODE          CONSTANT PLS_INTEGER := 215;
    TYPE_CODE          CONSTANT PLS_INTEGER := 200;
    * FTP File record datatype
    * Elements:
    * localpath - full directory name in which the local file resides or will reside
    * Windows: 'd:\oracle\utl_file'
    * UNIX: '/home/oracle/utl_file'
    * filename - filename and extension for the file to be received or sent
    * changing the filename for the PUT or GET is currently not allowed
    * Examples: 'myfile.dat' 'myfile20021119.xml'
    * remotepath - full directory name in which the local file will be sent or the
    * remote file exists. Should be in UNIX format regardless of FTP server - '/one/two/three'
    * filetype - reserved for future use, ignored in code
    * transfer_mode - 'PUT' or 'GET'
    * status - status of the transfer. 'ERROR' or 'SUCCESS'
    * error_message - meaningful (hopefully) error message explaining the reason for failure
    * bytes_transmitted - how many bytes were sent/received
    * trans_start - date/time the transmission started
    * trans_end - date/time the transmission ended
    TYPE r_ftp_rec IS RECORD(localpath           VARCHAR2(255),
                   filename           VARCHAR2(255),
                   remotepath      VARCHAR2(255),
                   filetype           VARCHAR2(20),
                   transfer_mode      VARCHAR2(5),
                   status           VARCHAR2(40),
                   error_message      VARCHAR2(255),
                   bytes_transmitted      NUMBER,
                   trans_start     DATE,
                   trans_end          DATE);
    * FTP File Table - used to store many files for transfer
    TYPE t_ftp_rec IS TABLE of r_ftp_rec INDEX BY BINARY_INTEGER;
    * Internal convenience procedure for creating passive host IP address
    * and port number.
    PROCEDURE CREATE_PASV(p_pasv_cmd IN VARCHAR2,
                   p_pasv_host OUT VARCHAR2,
                   p_pasv_port OUT NUMBER);
    * Function used to validate FTP server responses based on the
    * code passed in p_code. Reads single or multi-line responses.
    FUNCTION VALIDATE_REPLY(p_ctrl_con      IN OUT UTL_TCP.CONNECTION,
                   p_code      IN PLS_INTEGER,
                   p_reply      OUT VARCHAR2)
         RETURN BOOLEAN;
    * Function used to validate FTP server responses based on the
    * code passed in p_code. Reads single or multi-line responses.
    * Overloaded because some responses can have 2 valid codes.
    FUNCTION VALIDATE_REPLY(p_ctrl_con      IN OUT UTL_TCP.CONNECTION,
                   p_code1      IN PLS_INTEGER,
                   p_code2     IN PLS_INTEGER,
                   p_reply      OUT VARCHAR2)
         RETURN BOOLEAN;
    * Procedure that handles the actual data transfer. Meant
    * for internal package use. Returns information about the
    * actual transfer.
    PROCEDURE TRANSFER_ASCII(u_ctrl_con IN OUT UTL_TCP.CONNECTION,
                   p_localpath IN VARCHAR2,
                   p_filename IN VARCHAR2,
                   p_pasv_host IN VARCHAR2,
                   p_pasv_port IN PLS_INTEGER,
                   p_transfer_mode IN VARCHAR2,
                   v_status OUT VARCHAR2,
                   v_error_message OUT VARCHAR2,
                   n_bytes_transmitted OUT NUMBER,
                   d_trans_start OUT DATE,
    d_trans_end OUT DATE);
    * Function to handle FTP of many files.
    * Returns TRUE if no batch-level errors occur.
    * Returns FALSE if a batch-level error occurs.
    * Parameters:
    * p_error_msg - error message for batch level errors
    * p_files - BRNC_FTP_PKG.t_ftp_rec table type. Accepts
    * list of files to be transferred (may be any combination of PUT or GET)
    * returns the table updated with transfer status, error message,
    * bytes_transmitted, transmission start date/time and transmission end
    * date/time
    * p_username - username for FTP server
    * p_password - password for FTP server
    * p_hostname - hostname or IP address of server Ex: 'ftp.oracle.com' or '127.0.0.1'
    * p_port - port number to connect on. FTP is usually on 21, but this may be overridden
    * if the server is configured differently.
    FUNCTION FTP_MULTIPLE(p_error_msg OUT VARCHAR2,
                   p_files IN OUT t_ftp_rec,
                   p_username IN VARCHAR2,
                   p_password IN VARCHAR2,
                   p_hostname IN VARCHAR2,
                   p_port IN PLS_INTEGER DEFAULT 21)
         RETURN BOOLEAN;
    * Convenience function for single-file PUT
    * Parameters:
    * p_localpath - full directory name in which the local file resides or will reside
    * Windows: 'd:\oracle\utl_file'
    * UNIX: '/home/oracle/utl_file'
    * p_filename - filename and extension for the file to be received or sent
    * changing the filename for the PUT or GET is currently not allowed
    * Examples: 'myfile.dat' 'myfile20021119.xml'
    * p_remotepath - full directory name in which the local file will be sent or the
    * remote file exists. Should be in UNIX format regardless of FTP server - '/one/two/three'
    * p_username - username for FTP server
    * p_password - password for FTP server
    * p_hostname - FTP server IP address or host name Ex: 'ftp.oracle.com' or '127.0.0.1'
    * v_status - status of the transfer. 'ERROR' or 'SUCCESS'
    * v_error_message - meaningful (hopefully) error message explaining the reason for failure
    * n_bytes_transmitted - how many bytes were sent/received
    * d_trans_start - date/time the transmission started
    * d_trans_end - date/time the transmission ended
    * p_port - port number to connect to, default is 21
    * p_filetype - always set to 'ASCII', reserved for future use, ignored in code
    FUNCTION PUT(p_localpath IN VARCHAR2,
              p_filename IN VARCHAR2,
              p_remotepath IN VARCHAR2,
              p_username IN VARCHAR2,
              p_password IN VARCHAR2,
              p_hostname IN VARCHAR2,
              v_status OUT VARCHAR2,
              v_error_message OUT VARCHAR2,
              n_bytes_transmitted OUT NUMBER,
              d_trans_start OUT DATE,
    d_trans_end OUT DATE,
              p_port     IN PLS_INTEGER DEFAULT 21,
              p_filetype IN VARCHAR2 := 'ASCII')
         RETURN BOOLEAN;
    * Convenience function for single-file GET
    * Parameters:
    * p_localpath - full directory name in which the local file resides or will reside
    * Windows: 'd:\oracle\utl_file'
    * UNIX: '/home/oracle/utl_file'
    * p_filename - filename and extension for the file to be received or sent
    * changing the filename for the PUT or GET is currently not allowed
    * Examples: 'myfile.dat' 'myfile20021119.xml'
    * p_remotepath - full directory name in which the local file will be sent or the
    * remote file exists. Should be in UNIX format regardless of FTP server - '/one/two/three'
    * p_username - username for FTP server
    * p_password - password for FTP server
    * p_hostname - FTP server IP address or host name Ex: 'ftp.oracle.com' or '127.0.0.1'
    * v_status - status of the transfer. 'ERROR' or 'SUCCESS'
    * v_error_message - meaningful (hopefully) error message explaining the reason for failure
    * n_bytes_transmitted - how many bytes were sent/received
    * d_trans_start - date/time the transmission started
    * d_trans_end - date/time the transmission ended
    * p_port - port number to connect to, default is 21
    * p_filetype - always set to 'ASCII', reserved for future use, ignored in code
    FUNCTION GET(p_localpath IN VARCHAR2,
              p_filename IN VARCHAR2,
              p_remotepath IN VARCHAR2,
              p_username IN VARCHAR2,
              p_password IN VARCHAR2,
              p_hostname IN VARCHAR2,
              v_status OUT VARCHAR2,
              v_error_message OUT VARCHAR2,
              n_bytes_transmitted OUT NUMBER,
              d_trans_start OUT DATE,
    d_trans_end OUT DATE,
              p_port     IN PLS_INTEGER DEFAULT 21,
              p_filetype IN VARCHAR2 := 'ASCII')
         RETURN BOOLEAN;
    END BRNC_FTP_PKG;
    CREATE OR REPLACE PACKAGE BODY BRNC_FTP_PKG
    AS
    ** Create the passive host IP and port number to connect to
    PROCEDURE CREATE_PASV(p_pasv_cmd IN VARCHAR2,
                   p_pasv_host OUT VARCHAR2,
                   p_pasv_port OUT NUMBER)
    IS
         v_pasv_cmd     VARCHAR2(30) := p_pasv_cmd; --Host and port to connect to for data transfer
    n_port_dec     NUMBER;
         n_port_add     NUMBER;
    BEGIN
         p_pasv_host := REPLACE(SUBSTR(v_pasv_cmd,1,INSTR(v_pasv_cmd,',',1,4)-1),',','.');
         n_port_dec := TO_NUMBER(SUBSTR(v_pasv_cmd,INSTR(v_pasv_cmd,',',1,4)+1,(INSTR(v_pasv_cmd,',',1,5)-(INSTR(v_pasv_cmd,',',1,4)+1))));
         n_port_add := TO_NUMBER(SUBSTR(v_pasv_cmd,INSTR(v_pasv_cmd,',',1,5)+1,LENGTH(v_pasv_cmd)-INSTR(v_pasv_cmd,',',1,5)));
         p_pasv_port := (n_port_dec*256) + n_port_add;
    EXCEPTION
    WHEN OTHERS
    THEN
         --DBMS_OUTPUT.PUT_LINE(SQLERRM);
         RAISE;
    END CREATE_PASV;
    ** Read a single or multi-line reply from the FTP server and validate
    ** it against the code passed in p_code.
    ** Return TRUE if reply code matches p_code, FALSE if it doesn't or error
    ** occurs
    ** Send full server response back to calling procedure
    FUNCTION VALIDATE_REPLY(p_ctrl_con      IN OUT UTL_TCP.CONNECTION,
                   p_code      IN PLS_INTEGER,
                   p_reply      OUT VARCHAR2)
    RETURN BOOLEAN
    IS
         n_code           VARCHAR2(3) := p_code;
         n_byte_count      PLS_INTEGER;
         v_msg          VARCHAR2(255);
         n_line_count     PLS_INTEGER := 0;
    BEGIN
         LOOP
         v_msg := UTL_TCP.GET_LINE(p_ctrl_con);
         n_line_count := n_line_count + 1;
         IF n_line_count = 1
         THEN
              p_reply := v_msg;
         ELSE
              p_reply := p_reply || SUBSTR(v_msg,4);
         END IF;
         EXIT WHEN INSTR(v_msg,'-',1,1) <> 4;
         END LOOP;
    IF to_number(SUBSTR(p_reply,1,3)) = n_code
         THEN
         RETURN TRUE;
         ELSE
         RETURN FALSE;
         END IF;
    EXCEPTION
    WHEN OTHERS
    THEN
    p_reply := SQLERRM;
    RETURN FALSE;
    END VALIDATE_REPLY;
    ** Reads a single or multi-line reply from the FTP server
    ** Return TRUE if reply code matches p_code1 or p_code2,
    ** FALSE if it doesn't or error occurs
    ** Send full server response back to calling procedure
    FUNCTION VALIDATE_REPLY(p_ctrl_con      IN OUT UTL_TCP.CONNECTION,
                   p_code1      IN PLS_INTEGER,
                   p_code2     IN PLS_INTEGER,
                   p_reply      OUT VARCHAR2)
    RETURN BOOLEAN
    IS
         v_code1      VARCHAR2(3) := to_char(p_code1);
         v_code2      VARCHAR2(3) := to_char(p_code2);
         v_msg          VARCHAR2(255);
         n_line_count     PLS_INTEGER := 0;
    BEGIN
         LOOP
         v_msg := UTL_TCP.GET_LINE(p_ctrl_con);
         n_line_count := n_line_count + 1;
         IF n_line_count = 1
         THEN
              p_reply := v_msg;
         ELSE
              p_reply := p_reply || SUBSTR(v_msg,4);
         END IF;
         EXIT WHEN INSTR(v_msg,'-',1,1) <> 4;
         END LOOP;
    IF to_number(SUBSTR(p_reply,1,3)) IN(v_code1,v_code2)
         THEN
         RETURN TRUE;
         ELSE
         RETURN FALSE;
         END IF;
    EXCEPTION
    WHEN OTHERS
    THEN
    p_reply := SQLERRM;
    RETURN FALSE;
    END VALIDATE_REPLY;
    ** Handles actual data transfer. Responds with status, error message, and
    ** transfer statistics.
    ** Potential errors could be with connection or file i/o
    PROCEDURE TRANSFER_ASCII(u_ctrl_con IN OUT UTL_TCP.CONNECTION,
                   p_localpath IN VARCHAR2,
                   p_filename IN VARCHAR2,
                   p_pasv_host IN VARCHAR2,
                   p_pasv_port IN PLS_INTEGER,
                   p_transfer_mode IN VARCHAR2,
                   v_status OUT VARCHAR2,
                   v_error_message OUT VARCHAR2,
                   n_bytes_transmitted OUT NUMBER,
                   d_trans_start OUT DATE,
    d_trans_end OUT DATE)
    IS
         u_data_con          UTL_TCP.CONNECTION;
         u_filehandle          UTL_FILE.FILE_TYPE;
    v_tsfr_mode          VARCHAR2(3) := p_transfer_mode;
         v_mode               VARCHAR2(1);
    v_tsfr_cmd          VARCHAR2(10);
         v_buffer          VARCHAR2(32767);
         v_localpath          VARCHAR2(255)      := p_localpath;
         v_filename          VARCHAR2(255)      := p_filename;
         v_host               VARCHAR2(20)      := p_pasv_host;
         n_port               PLS_INTEGER      := p_pasv_port;
         n_bytes               NUMBER;
         v_msg               VARCHAR2(255);
         v_reply               VARCHAR2(1000);
         v_err_status          VARCHAR2(20) := 'ERROR';
    BEGIN
         /** Initialize some of our OUT variables **/
         v_status          := 'SUCCESS';
         v_error_message          := ' ';
         n_bytes_transmitted     := 0;
         IF UPPER(v_tsfr_mode) = 'PUT'
    THEN
         v_mode      := 'r';
         v_tsfr_cmd      := 'STOR ';
         ELSIF UPPER(v_tsfr_mode) = 'GET'
         THEN
         v_mode     := 'w';
         v_tsfr_cmd := 'RETR ';
    END IF;
         /** Open data connection on Passive host and port **/
         u_data_con := UTL_TCP.OPEN_CONNECTION(v_host,n_port);
         /** Open the local file to read and transfer data **/
         u_filehandle := UTL_FILE.FOPEN(v_localpath,v_filename,v_mode);
         /** Send the STOR command to tell the server we're going to upload a file **/
         n_bytes := UTL_TCP.WRITE_LINE(u_ctrl_con,v_tsfr_cmd||v_filename);
         IF VALIDATE_REPLY(u_ctrl_con,TSFR_START_CODE1,TSFR_START_CODE2,v_reply) = FALSE
         THEN
         RAISE ctrl_exception;
         END IF;
         d_trans_start := SYSDATE;
         IF UPPER(v_tsfr_mode) = 'PUT'
         THEN
         LOOP
              BEGIN
              UTL_FILE.GET_LINE(u_filehandle,v_buffer);
              EXCEPTION
              WHEN NO_DATA_FOUND
              THEN
              EXIT;
              END;
              n_bytes := UTL_TCP.WRITE_LINE(u_data_con,v_buffer);
              n_bytes_transmitted := n_bytes_transmitted + n_bytes;
         END LOOP;
         ELSIF UPPER(v_tsfr_mode) = 'GET'
         THEN
         LOOP
              BEGIN
              v_buffer := UTL_TCP.GET_LINE(u_data_con,TRUE);
              /** Sometimes the TCP/IP buffer sends null data **/
    /** we only want to receive the actual data **/
              IF v_buffer IS NOT NULL
              THEN
              UTL_FILE.PUT_LINE(u_filehandle,v_buffer);
              n_bytes := LENGTH(v_buffer);
              n_bytes_transmitted := n_bytes_transmitted + n_bytes;
              END IF;
              EXCEPTION
              WHEN UTL_TCP.END_OF_INPUT
              THEN
              EXIT;
              END;
         END LOOP;
         END IF;
         /** Flush the buffer on the data connection **/
         --UTL_TCP.FLUSH(u_data_con);
         d_trans_end := SYSDATE;
         /** Close the file **/
         UTL_FILE.FCLOSE(u_filehandle);
         /** Close the Data Connection **/
         UTL_TCP.CLOSE_CONNECTION(u_data_con);
         /** Verify the transfer succeeded **/
         IF VALIDATE_REPLY(u_ctrl_con,TSFR_END_CODE,v_reply) = FALSE
         THEN
         RAISE ctrl_exception;
         END IF;
    EXCEPTION
    WHEN ctrl_exception
    THEN
         v_status := v_err_status;
         v_error_message := v_reply;
         IF UTL_FILE.IS_OPEN(u_filehandle)
         THEN
         UTL_FILE.FCLOSE(u_filehandle);
         END IF;
         UTL_TCP.CLOSE_CONNECTION(u_data_con);
    WHEN UTL_FILE.invalid_path
    THEN
         v_status      := v_err_status;
         v_error_message := 'Directory '||v_localpath||' is not available to UTL_FILE. Check the init.ora file for valid UTL_FILE directories.';
         UTL_TCP.CLOSE_CONNECTION(u_data_con);
    WHEN UTL_FILE.invalid_operation
    THEN
         v_status := v_err_status;
         IF UPPER(v_tsfr_mode) = 'PUT'
         THEN
         v_error_message := 'The file '||V_filename||' in the directory '||v_localpath||' could not be opened for reading.';
         ELSIF UPPER(v_tsfr_mode) = 'GET'
         THEN
         v_error_message := 'The file '||V_filename||' in the directory '||v_localpath||' could not be opened for writing.';
         END IF;     
         IF UTL_FILE.IS_OPEN(u_filehandle)
         THEN
         UTL_FILE.FCLOSE(u_filehandle);
         END IF;
         UTL_TCP.CLOSE_CONNECTION(u_data_con);
    WHEN UTL_FILE.read_error
    THEN
         v_status := v_err_status;
         v_error_message := 'The system encountered an error while trying to read '||v_filename||' in the directory '||v_localpath;
         IF UTL_FILE.IS_OPEN(u_filehandle)
         THEN
         UTL_FILE.FCLOSE(u_filehandle);
         END IF;
         UTL_TCP.CLOSE_CONNECTION(u_data_con);
    WHEN UTL_FILE.write_error
    THEN
         v_status := v_err_status;
         v_error_message := 'The system encountered an error while trying to write to '||v_filename||' in the directory '||v_localpath;
         IF UTL_FILE.IS_OPEN(u_filehandle)
         THEN
         UTL_FILE.FCLOSE(u_filehandle);
         END IF;
         UTL_TCP.CLOSE_CONNECTION(u_data_con);
    WHEN UTL_FILE.internal_error
    THEN
         v_status := v_err_status;
         v_error_message := 'The UTL_FILE package encountered an unexpected internal system error.';
         IF UTL_FILE.IS_OPEN(u_filehandle)
         THEN
         UTL_FILE.FCLOSE(u_filehandle);
         END IF;
         UTL_TCP.CLOSE_CONNECTION(u_data_con);
    WHEN OTHERS
    THEN
         v_status := v_err_status;
         v_error_message := SQLERRM;
         IF UTL_FILE.IS_OPEN(u_filehandle)
         THEN
         UTL_FILE.FCLOSE(u_filehandle);
         END IF;
         UTL_TCP.CLOSE_CONNECTION(u_data_con);
    END TRANSFER_ASCII;
    ** Handles connection to host and FTP of multiple files
    ** Files can be any combination of PUT and GET
    FUNCTION FTP_MULTIPLE(p_error_msg OUT VARCHAR2,
                   p_files IN OUT t_ftp_rec,
                   p_username IN VARCHAR2,
                   p_password IN VARCHAR2,
                   p_hostname IN VARCHAR2,
                   p_port IN PLS_INTEGER DEFAULT 21)
    RETURN BOOLEAN
    IS
         v_username           VARCHAR2(30)      := p_username;
         v_password           VARCHAR2(30)      := p_password;
         v_hostname           VARCHAR2(30)      := p_hostname;
         n_port               PLS_INTEGER      := p_port;
         u_ctrl_con          UTL_TCP.CONNECTION;
         n_byte_count          PLS_INTEGER;
         n_first_index          NUMBER;
         v_msg               VARCHAR2(250);
         v_reply               VARCHAR2(1000);
    v_pasv_host          VARCHAR2(20);
    n_pasv_port          NUMBER;
         invalid_transfer     EXCEPTION;
    BEGIN
         p_error_msg := 'FTP Successful'; --Assume the overall transfer will succeed
         /** Attempt to connect to the host machine **/
         u_ctrl_con := UTL_TCP.OPEN_CONNECTION(v_hostname,n_port);
         IF VALIDATE_REPLY(u_ctrl_con,CONNECT_CODE,v_reply) = FALSE
         THEN
         RAISE ctrl_exception;
         END IF;
         /** Send username **/
         n_byte_count := UTL_TCP.WRITE_LINE(u_ctrl_con,'USER '||v_username);
         IF VALIDATE_REPLY(u_ctrl_con,USER_CODE,v_reply) = FALSE
         THEN
         RAISE ctrl_exception;
         END IF;
         /** Send password **/
         n_byte_count := UTL_TCP.WRITE_LINE(u_ctrl_con,'PASS '||v_password);
         IF VALIDATE_REPLY(u_ctrl_con,LOGIN_CODE,v_reply) = FALSE
         THEN
         RAISE ctrl_exception;
         END IF;
         /** We should be logged in, time to transfer all files **/
         FOR i IN p_files.FIRST..p_files.LAST
    LOOP
         IF p_files.EXISTS(i)
         THEN
              BEGIN
              /** Change to the remotepath directory **/
              n_byte_count := UTL_TCP.WRITE_LINE(u_ctrl_con,'CWD '||p_files(i).remotepath);
              IF VALIDATE_REPLY(u_ctrl_con,CWD_CODE,v_reply) = FALSE
              THEN
                   RAISE ctrl_exception;
              END IF;
              /** Switch to IMAGE mode **/
              n_byte_count := UTL_TCP.WRITE_LINE(u_ctrl_con,'TYPE I');
              IF VALIDATE_REPLY(u_ctrl_con,TYPE_CODE,v_reply) = FALSE
              THEN
                   RAISE ctrl_exception;
              END IF;
              /** Get a Passive connection to use for data transfer **/
              n_byte_count := UTL_TCP.WRITE_LINE(u_ctrl_con,'PASV');
              IF VALIDATE_REPLY(u_ctrl_con,PASV_CODE,v_reply) = FALSE
              THEN
                   RAISE ctrl_exception;
              END IF;
              CREATE_PASV(SUBSTR(v_reply,INSTR(v_reply,'(',1,1)+1,INSTR(v_reply,')',1,1)-INSTR(v_reply,'(',1,1)-1),v_pasv_host,n_pasv_port);
              /** Transfer Data **/
              IF UPPER(p_files(i).transfer_mode) = 'PUT'
              THEN
                   TRANSFER_ASCII(u_ctrl_con,
                        p_files(i).localpath,
                        p_files(i).filename,
                        v_pasv_host,
                        n_pasv_port,
                        p_files(i).transfer_mode,
                        p_files(i).status,
                        p_files(i).error_message,
                        p_files(i).bytes_transmitted,
                        p_files(i).trans_start,
         p_files(i).trans_end);
              ELSIF UPPER(p_files(i).transfer_mode) = 'GET'
              THEN
                   TRANSFER_ASCII(u_ctrl_con,
                        p_files(i).localpath,
                        p_files(i).filename,
                        v_pasv_host,
                        n_pasv_port,
                        p_files(i).transfer_mode,
                        p_files(i).status,
                        p_files(i).error_message,
                        p_files(i).bytes_transmitted,
                        p_files(i).trans_start,
         p_files(i).trans_end);
              ELSE
                   RAISE invalid_transfer; -- Raise an exception here
              END IF;
              EXCEPTION
              WHEN ctrl_exception
              THEN
              p_files(i).status := 'ERROR';
              p_files(i).error_message := v_reply;
              WHEN invalid_transfer
              THEN
              p_files(i).status := 'ERROR';
              p_files(i).error_message := 'Invalid transfer method. Use PUT or GET.';
              END;
         END IF;
         END LOOP;
         /** Send QUIT command **/
         n_byte_count := UTL_TCP.WRITE_LINE(u_ctrl_con,'QUIT');
         /** Don't need to validate QUIT, just close the connection **/
         UTL_TCP.CLOSE_CONNECTION(u_ctrl_con);
         RETURN TRUE;
    EXCEPTION
    WHEN ctrl_exception
    THEN
         p_error_msg := v_reply;
         UTL_TCP.CLOSE_ALL_CONNECTIONS;
         RETURN FALSE;
    WHEN OTHERS
    THEN
         p_error_msg := SQLERRM;
         UTL_TCP.CLOSE_ALL_CONNECTIONS;
         RETURN FALSE;
    END FTP_MULTIPLE;
    ** Convenience function for single-file PUT
    ** Formats file information for FTP_MULTIPLE function and calls it.
    FUNCTION PUT(p_localpath IN VARCHAR2,
              p_filename IN VARCHAR2,
              p_remotepath IN VARCHAR2,
              p_username IN VARCHAR2,
              p_password IN VARCHAR2,
              p_hostname IN VARCHAR2,
              v_status OUT VARCHAR2,
              v_error_message OUT VARCHAR2,
              n_bytes_transmitted OUT NUMBER,
              d_trans_start OUT DATE,
    d_trans_end OUT DATE,
              p_port     IN PLS_INTEGER DEFAULT 21,
              p_filetype IN VARCHAR2 := 'ASCII')
    RETURN BOOLEAN
    IS
         t_files      t_ftp_rec;
         v_username     VARCHAR2(30)      := p_username;
         v_password     VARCHAR2(50)      := p_password;
         v_hostname     VARCHAR2(100)      := p_hostname;
         n_port          PLS_INTEGER      := p_port;
    v_err_msg     VARCHAR2(255);
         b_ftp          BOOLEAN;
    BEGIN
         t_files(1).localpath          := p_localpath;
         t_files(1).filename           := p_filename;
         t_files(1).remotepath          := p_remotepath;
         t_files(1).filetype          := p_filetype;
         t_files(1).transfer_mode     := 'PUT';
         b_ftp := FTP_MULTIPLE(v_err_msg,
                   t_files,
                   v_username,
                   v_password,
                   v_hostname,
                   n_port);
         IF b_ftp = FALSE
         THEN
         v_status := 'ERROR';
         v_error_message := v_err_msg;
         RETURN FALSE;
         ELSIF b_ftp = TRUE
         THEN
         v_status                := t_files(1).status;
         v_error_message           := t_files(1).error_message;
         n_bytes_transmitted      := t_files(1).bytes_transmitted;
         d_trans_start           := t_files(1).trans_start;
         d_trans_end           := t_files(1).trans_end;
         RETURN TRUE;
         END IF;
    EXCEPTION
    WHEN OTHERS
    THEN
         v_status      := 'ERROR';
         v_error_message := SQLERRM;
         RETURN FALSE;
         --DBMS_OUTPUT.PUT_LINE(SQLERRM);
    END PUT;
    ** Convenience function for single-file GET
    ** Formats file information for FTP_MULTIPLE function and calls it.
    FUNCTION GET(p_localpath IN VARCHAR2,
              p_filename IN VARCHAR2,
              p_remotepath IN VARCHAR2,
              p_username IN VARCHAR2,
              p_password IN VARCHAR2,
              p_hostname IN VARCHAR2,
              v_status OUT VARCHAR2,
              v_error_message OUT VARCHAR2,
              n_bytes_transmitted OUT NUMBER,
              d_trans_start OUT DATE,
    d_trans_end OUT DATE,
              p_port     IN PLS_INTEGER DEFAULT 21,
              p_filetype IN VARCHAR2 := 'ASCII')
    RETURN BOOLEAN
    IS
         t_files      t_ftp_rec;
         v_username     VARCHAR2(30)      := p_username;
         v_password     VARCHAR2(50)      := p_password;
         v_hostname     VARCHAR2(100)      := p_hostname;
         n_port          PLS_INTEGER      := p_port;
    v_err_msg     VARCHAR2(255);
         b_ftp          BOOLEAN;
    BEGIN
         t_files(1).localpath          := p_localpath;
         t_files(1).filename           := p_filename;
         t_files(1).remotepath          := p_remotepath;
         t_files(1).filetype          := p_filetype;
         t_files(1).transfer_mode     := 'GET';
         b_ftp := FTP_MULTIPLE(v_err_msg,
                   t_files,
                   v_username,
                   v_password,
                   v_hostname,
                   n_port);
         IF b_ftp = FALSE
         THEN
         v_status := 'ERROR';
         v_error_message := v_err_msg;
         RETURN FALSE;
         ELSIF b_ftp = TRUE
         THEN
         v_status           := t_files(1).status;
         v_error_message      := t_files(1).error_message;
         n_bytes_transmitted := t_files(1).bytes_transmitted;
         d_trans_start      := t_files(1).trans_start;
         d_trans_end      := t_files(1).trans_end;
         RETURN TRUE;
         END IF;
    EXCEPTION
    WHEN OTHERS
    THEN
         v_status      := 'ERROR';
         v_error_message := SQLERRM;
         RETURN FALSE;
         --DBMS_OUTPUT.PUT_LINE(SQLERRM);
    END GET;
    END BRNC_FTP_PKG;
    /

  • Doubt in calltransaction in ALV

    Hi, i have doubt in calltransction in alv..In my report am using ALV grid display to display purchase order number , material docu number ..If i click on purchasing docu number it has to call transaction ME23N for the purchase order number that i have clicked and if i click material document number it has to  call trainsaction MIGO for the corresponding material document number..Here i have done some coding plz correct me if iam wrong..
    *& Report  YCALLTRANSACTIONALV                                         *
    REPORT  YCALLTRANSACTIONALV                     .
    TYPE-POOLS: icon.
    TYPE-POOLS: slis.
    TABLES: vbak,vbap,vbep, makt,lips.
    DATA: BEGIN OF gt_vbak OCCURS 0,
    vbeln LIKE vbak-vbeln,
    audat LIKE vbak-audat,
    vdatu LIKE vbak-vdatu,
    kunnr LIKE vbak-kunnr,
    posnr LIKE vbap-posnr,
    matnr LIKE vbap-matnr,
    kwmeng LIKE vbap-kwmeng,
    END OF gt_vbak.
    DATA: BEGIN OF gt_vbep OCCURS 0,
    vbeln LIKE vbep-vbeln,
    wadat LIKE vbep-wadat,
    END OF gt_vbep.
    DATA: BEGIN OF gt_lips OCCURS 0,
    vbeln LIKE lips-vbeln,
    posnr LIKE lips-posnr,
    lfimg LIKE lips-lfimg,
    vgbel LIKE lips-vgbel,
    vgpos LIKE lips-vgpos,
    END OF gt_lips.
    DATA: BEGIN OF gt_makt OCCURS 0,
    matnr LIKE makt-matnr,
    maktx LIKE makt-maktx,
    END OF gt_makt.
    DATA: gv_tab TYPE slis_tabname VALUE 'GT_REPORT'.
    DATA: BEGIN OF gt_report OCCURS 0,
    vbeln LIKE vbak-vbeln,
    posnr LIKE vbep-posnr,
    matnr LIKE vbap-matnr,
    maktx LIKE makt-maktx,
    kwmeng LIKE vbap-kwmeng,
    vdatu LIKE vbak-vdatu,
    lfimg LIKE lips-lfimg,
    wadat LIKE vbep-wadat,
    vgbel LIKE lips-vgbel,
    icon TYPE icon-id,
    tabcolor TYPE lvc_t_scol,
    END OF gt_report.
    DATA: gt_fieldcat TYPE slis_t_fieldcat_ alv,
             gs_fieldcat TYPE slis_fieldcat_ alv,
                gs_layout TYPE slis_layout_ alv,
                gt_events TYPE slis_t_event,
                  gs_events TYPE slis_alv_event,
    repid LIKE sy-repid.
    DATA: gt_lines TYPE TABLE OF tline WITH HEADER LINE,
    gv_name LIKE thead-tdname,
    gv_fld(40),gv_ fval(50).
    DATA: BEGIN OF gt_outlines OCCURS 0,
    text TYPE tdline,
    END OF gt_outlines.
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-006.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS: p_cust RADIOBUTTON GROUP rad1 USER-COMMAND ch DEFAULT 'X'.
    SELECTION-SCREEN COMMENT 5(20) text-001.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS: p_date RADIOBUTTON GROUP rad1 .
    SELECTION-SCREEN COMMENT 5(10) text-002 .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-005.
    SELECT-OPTIONS: s_sale FOR vbak-vbeln MODIF ID cus,
    s_cust FOR vbak-kunnr MODIF ID cus.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-005.
    SELECT-OPTIONS: s_sale1 FOR vbak-vbeln MODIF ID dat,
    s_dat FOR vbak-audat MODIF ID dat.
    SELECTION-SCREEN END OF BLOCK b2.
    SELECTION-SCREEN END OF BLOCK b3.
    SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-007.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS: p_clas RADIOBUTTON GROUP rad2 ."USER-COMMAND ch DEFAULT'X'.
    SELECTION-SCREEN COMMENT 5(20) text-003.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS: p_alv RADIOBUTTON GROUP rad2 ."USER-COMMAND ch DEFAULT'X'.
    SELECTION-SCREEN COMMENT 5(20) text-004.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b4.
    AT SELECTION-SCREEN.
    CHECK sy-ucomm = 'CH'.
    AT SELECTION-SCREEN OUTPUT.
    IF p_cust = 'X'.
    LOOP AT SCREEN.
    IF screen-group1 = 'DAT'.
    screen-active = 0.
    ELSE.
    screen-active = 1.
    ENDIF.
    MODIFY SCREEN.
    ENDLOOP.
    ELSE.
    LOOP AT SCREEN.
    IF screen-group1 = 'CUS'.
    screen-active = 0.
    ELSE.
    screen-active = 1.
    ENDIF.
    MODIFY SCREEN.
    ENDLOOP.
    ENDIF.
    START-OF-SELECTION.
    IF p_cust = 'X' .
    CLEAR gt_vbak.
    REFRESH gt_vbak.
    SELECT avbeln aaudat avdatu akunnr bposnr bmatnr b~kwmeng
    INTO TABLE gt_vbak
    FROM vbak AS a INNER JOIN vbap AS b
    ON avbeln = bvbeln
    WHERE a~vbeln IN s_sale
    AND a~kunnr IN s_cust.
    ELSEIF p_date = 'X'.
    CLEAR gt_vbak.
    REFRESH gt_vbak.
    SELECT avbeln aaudat avdatu akunnr bposnr bmatnr b~kwmeng
    INTO TABLE gt_vbak
    FROM vbak AS a INNER JOIN vbap AS b
    ON avbeln = bvbeln
    WHERE a~vbeln IN s_sale1
    AND a~audat IN s_dat.
    ENDIF.
    PERFORM sel_data.
    IF p_alv = 'X'.
    PERFORM disp_data1.
    ELSE.
    PERFORM disp_data.
    ENDIF.
    AT LINE-SELECTION.
    GET CURSOR FIELD gv_fld .
    CASE gv_fld.
    WHEN 'ICON_DISPLAY_ TEXT'.
    PERFORM concate_text.
    CLEAR gv_name.
    CONCATENATE gt_report-vbeln gt_report-posnr INTO gv_name.
    PERFORM read_text.
    PERFORM write_text.
    PERFORM disp_text.
    WHEN 'GT_REPORT-VBELN' .
    SET PARAMETER ID 'AUN' FIELD gt_report-vbeln.
    CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
    ENDCASE.
    *& Form sel_data
    FORM sel_data .
    CLEAR gt_vbep.
    REFRESH gt_vbep.
    IF NOT gt_vbak[] IS INITIAL.
    SELECT vbeln wadat FROM vbep INTO TABLE gt_vbep
    FOR ALL ENTRIES IN gt_vbak
    WHERE vbeln = gt_vbak-vbeln.
    CLEAR gt_lips.
    REFRESH gt_lips.
    SELECT vbeln posnr lfimg vgbel vgpos FROM lips INTO TABLE gt_lips
    FOR ALL ENTRIES IN gt_vbak
    WHERE vgbel = gt_vbak-vbeln
    AND vgpos = gt_vbak-posnr.
    CLEAR gt_makt.
    REFRESH gt_makt.
    SELECT matnr maktx FROM makt INTO TABLE gt_makt
    FOR ALL ENTRIES IN gt_vbak
    WHERE matnr = gt_vbak-matnr.
    ENDIF.
    REFRESH gt_report.
    CLEAR gt_report.
    LOOP AT gt_vbak.
    gt_report-vbeln = gt_vbak-vbeln.
    gt_report-vdatu = gt_vbak-vdatu.
    gt_report-posnr = gt_vbak-posnr.
    gt_report-matnr = gt_vbak-matnr.
    gt_report-kwmeng = gt_vbak-kwmeng.
    CLEAR gt_vbep.
    READ TABLE gt_vbep WITH KEY vbeln = gt_vbak-vbeln.
    gt_report-wadat = gt_vbep-wadat.
    CLEAR gt_lips.
    READ TABLE gt_lips WITH KEY vgbel = gt_vbak-vbeln
    vgpos = gt_vbak-posnr.
    gt_report-lfimg = gt_lips-lfimg.
    gt_report-vgbel = gt_lips-vbeln.
    CLEAR gt_makt.
    READ TABLE gt_makt WITH KEY matnr = gt_vbak-matnr.
    gt_report-maktx = gt_makt-maktx.
    CLEAR gt_report-icon.
    PERFORM concate_text.
    CLEAR gv_name.
    CONCATENATE gt_report-vbeln gt_report-posnr INTO gv_name.
    PERFORM read_text.
    IF gt_lines[] IS NOT INITIAL.
    gt_report-icon = '@0P@'.
    ENDIF.
    APPEND gt_report.
    ENDLOOP.
    ENDFORM. " sel_data
    *& Form disp_data
    FORM disp_data .
    WRITE:/(8) 'orderno.',
    (8) 'lineno.',
    (11) 'mat.',
    (27) 'matdes.',
    (10) 'ord.qty',
    (12) 'req.del.',
    (10) 'del.qty',
    (10) 'gidate',
    (10) 'delno.'.
    ULINE.
    LOOP AT gt_report.
    WRITE:/(8) gt_report-vbeln COLOR 6 HOTSPOT,
    (8) gt_report-posnr ,
    (8) gt_report-matnr,
    (25) gt_report-maktx,
    (11) gt_report-kwmeng,
    (15) gt_report-vdatu,
    (7) gt_report-lfimg,
    (10) gt_report-wadat,
    (10) gt_report-vgbel.
    PERFORM concate_text.
    CLEAR gv_name.
    CONCATENATE gt_report-vbeln gt_report-posnr INTO gv_name.
    PERFORM read_text.
    IF gt_lines[] IS NOT INITIAL.
    WRITE:120 icon_display_ text AS ICON HOTSPOT.
    HIDE: gt_report-vbeln, gt_report- posnr.
    ENDIF.
    ENDLOOP.
    ENDFORM. " disp_data
    *& Form disp_data1
    FORM disp_data1 .
    DATA :
    ls_tabcolor TYPE lvc_s_scol.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'VBELN'.
    gs_fieldcat- hotspot = 'X'.
    gs_fieldcat- seltext_l = 'ORDERNO'.
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'POSNR'.
    gs_fieldcat- seltext_l = 'LINENO'.
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'MATNR'.
    gs_fieldcat- seltext_l = 'MATNO'.
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'MAKTX'.
    gs_fieldcat- seltext_l = 'MATDESCR'.
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'KWMENG'.
    gs_fieldcat- seltext_l = 'ORDERQTY'.
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'VDATU'.
    gs_fieldcat- seltext_l = 'REQ.DEL.DAT' .
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'LFIMG'.
    gs_fieldcat- seltext_l = 'QTY.DEL'.
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'WADAT'.
    gs_fieldcat- seltext_l = 'ISS.DATE'.
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'VGBEL'.
    gs_fieldcat- seltext_l = 'DOUC.NO'.
    APPEND gs_fieldcat TO gt_fieldcat.
    CLEAR gs_fieldcat.
    gs_fieldcat- tabname = gv_tab.
    gs_fieldcat- fieldname = 'ICON'.
    gs_fieldcat- seltext_l = 'TEXT'.
    gs_fieldcat- icon = 'X'.
    gs_fieldcat- hotspot = 'X'.
    APPEND gs_fieldcat TO gt_fieldcat.
    gs_layout-coltab_ fieldname = 'TABCOLOR'.
    gs_events-name = 'USER_COMMAND' .
    gs_events-form = 'VAL'.
    APPEND gs_events TO gt_events.
    LOOP AT gt_report.
    ls_tabcolor- fname = 'VBELN'.
    ls_tabcolor- color-col = 4.
    ls_tabcolor- color-int = 1.
    ls_tabcolor- color-inv = 0.
    INSERT ls_tabcolor INTO TABLE gt_report-tabcolor.
    MODIFY gt_report.
    ENDLOOP.
    CALL FUNCTION 'REUSE_ALV_GRID_ DISPLAY'
    EXPORTING
    i_callback_program = sy-repid
    is_layout = gs_layout
    it_fieldcat = gt_fieldcat
    it_events = gt_events
    TABLES
    t_outtab = gt_report.
    ENDFORM. " disp_data1
    *& Form READ_TEXT .
    FORM read_text .
    CLEAR gt_lines.
    REFRESH gt_lines.
    CALL FUNCTION 'READ_TEXT'
    EXPORTING
    id = '0002'
    language = sy-langu
    name = gv_name
    object = 'VBBP'
    TABLES
    lines = gt_lines
    EXCEPTIONS
    id = 1
    language = 2
    name = 3
    not_found = 4
    object = 5
    reference_check = 6
    wrong_access_ to_archive = 7
    OTHERS = 8.
    IF sy-subrc <> 0.
    ENDIF.
    ENDFORM. " READ_TEXT
    *& Form WRITE_TEXT.
    FORM write_text.
    REFRESH gt_outlines.
    CLEAR gt_outlines.
    CLEAR gt_lines.
    LOOP AT gt_lines .
    MOVE gt_lines-tdline TO gt_outlines- text .
    APPEND gt_outlines.
    ENDLOOP.
    CLEAR gt_outlines.
    ENDFORM. "WRITE_TEXT
    *& Form VAL .
    FORM val USING
    user_command LIKE sy-ucomm
    sel TYPE slis_selfield.
    IF sel-fieldname = 'VBELN'.
    SET PARAMETER ID 'AUN' FIELD gt_report-vbeln.
    CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
    ENDIF.
    IF sel-fieldname = 'ICON'.
    CLEAR gt_report.
    READ TABLE gt_report INDEX sel-tabindex.
    perform concate_text.
    CLEAR gv_name.
    CONCATENATE gt_report-vbeln gt_report-posnr INTO gv_name.
    PERFORM read_text.
    PERFORM write_text.
    PERFORM disp_text1.
    ENDIF.
    ENDFORM. "val
    *& Form disp_text
    FORM disp_text .
    CALL FUNCTION 'POPUP_WITH_ TABLE_DISPLAY_ OK'
    EXPORTING
    endpos_col = 50
    endpos_row = 30
    startpos_col = 20
    startpos_row = 20
    titletext = 'TEXT'
    TABLES
    valuetab = gt_outlines.
    ENDFORM. " disp_text
    *& Form disp_text1
    FORM disp_text1 .
    DATA: lt_fieldcat TYPE slis_t_fieldcat_ alv,
    ls_fieldcat TYPE slis_fieldcat_ alv.
    ls_fieldcat- fieldname = 'TEXT'.
    ls_fieldcat- outputlen = 40.
    ls_fieldcat- tabname = gt_outlines.
    APPEND ls_fieldcat TO lt_fieldcat.
    CALL FUNCTION 'REUSE_ALV_POPUP_ TO_SELECT'
    EXPORTING
    i_title = 'TEXT'
    i_tabname = 'TLINE'
    it_fieldcat = lt_fieldcat
    i_callback_program = sy-repid
    TABLES
    t_outtab = gt_outlines.
    ENDFORM. " disp_text1
    *& Form concate_text
    FORM concate_text .
    CLEAR gv_name.
    CONCATENATE gt_report-vbeln gt_report-posnr INTO gv_name.
    PERFORM read_text.
    ENDFORM. " concate_text
    Thanks

    Hello skk
    Here is a sample report performing the required task using OO-means. I think you will agree that the OO-based approach is much simpler and easier to understand than the FM-based approach.
    The screen '0100' has the following flow logic without any dynpro elements:
    PROCESS BEFORE OUTPUT.
      MODULE STATUS_0100.
    PROCESS AFTER INPUT.
      MODULE USER_COMMAND_0100.
    *& Report  ZUS_SDN_ALVGRID_EVENTS
    REPORT  zus_sdn_alvgrid_events.
    DATA:
      gd_okcode        TYPE ui_func,
      gt_fcat          TYPE lvc_t_fcat,
      go_docking       TYPE REF TO cl_gui_docking_container,
      go_grid1         TYPE REF TO cl_gui_alv_grid.
    DATA:
      gt_knb1          TYPE STANDARD TABLE OF knb1.
    PARAMETERS:
      p_bukrs      TYPE bukrs  DEFAULT '1000'  OBLIGATORY.
    *       CLASS lcl_eventhandler DEFINITION
    CLASS lcl_eventhandler DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS:
          handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
            IMPORTING
              e_row_id
              e_column_id
              es_row_no
              sender.
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    *       CLASS lcl_eventhandler IMPLEMENTATION
    CLASS lcl_eventhandler IMPLEMENTATION.
      METHOD handle_hotspot_click.
    *   define local data
        DATA:
          ls_knb1     TYPE knb1,
          ls_col_id   TYPE lvc_s_col.
        READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row_id-index.
        CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
        CASE e_column_id-fieldname.
          WHEN 'KUNNR'.
            SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
            SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
            CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
          WHEN 'ERNAM'.
    *        SET PARAMETER ID 'USR' FIELD ls_knb1-ernam.
    *        NOTE: no parameter id available, yet simply show the priciple
            CALL TRANSACTION 'SU01' AND SKIP FIRST SCREEN.
          WHEN OTHERS.
    *       do nothing
        ENDCASE.
    *   Set active cell to field BUKRS otherwise the focus is still on
    *   field KUNNR which will always raise event HOTSPOT_CLICK
        ls_col_id-fieldname = 'BUKRS'.
        CALL METHOD go_grid1->set_current_cell_via_id
          EXPORTING
            is_row_id    = e_row_id
            is_column_id = ls_col_id.
      ENDMETHOD.                    "handle_hotspot_click
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    START-OF-SELECTION.
      SELECT        * FROM  knb1 INTO TABLE gt_knb1
             WHERE  bukrs  = p_bukrs.
    * Create docking container
      CREATE OBJECT go_docking
        EXPORTING
          parent                      = cl_gui_container=>screen0
          ratio                       = 90
        EXCEPTIONS
          OTHERS                      = 6.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    * Create ALV grid
      CREATE OBJECT go_grid1
        EXPORTING
          i_parent          = go_docking
        EXCEPTIONS
          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.
    * Set event handler
      SET HANDLER:
        lcl_eventhandler=>handle_hotspot_click FOR go_grid1.
    * Build fieldcatalog and set hotspot for field KUNNR
      PERFORM build_fieldcatalog_knb1.
    * Display data
      CALL METHOD go_grid1->set_table_for_first_display
        CHANGING
          it_outtab       = gt_knb1
          it_fieldcatalog = gt_fcat
        EXCEPTIONS
          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.
    * Link the docking container to the target dynpro
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = syst-repid
          dynnr                       = '0100'
    *      CONTAINER                   =
        EXCEPTIONS
          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.
    * ok-code field = GD_OKCODE
      CALL SCREEN '0100'.
    END-OF-SELECTION.
    *&      Module  STATUS_0100  OUTPUT
    *       text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.
    *  SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    *       text
    MODULE user_command_0100 INPUT.
      CASE gd_okcode.
        WHEN 'BACK' OR
             'END'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
        WHEN OTHERS.
      ENDCASE.
      CLEAR: gd_okcode.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  BUILD_FIELDCATALOG_KNB1
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM build_fieldcatalog_knb1 .
    * define local data
      DATA:
        ls_fcat        TYPE lvc_s_fcat.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
    *     I_BUFFER_ACTIVE              =
          i_structure_name             = 'KNB1'
    *     I_CLIENT_NEVER_DISPLAY       = 'X'
    *     I_BYPASSING_BUFFER           =
    *     I_INTERNAL_TABNAME           =
        CHANGING
          ct_fieldcat                  = gt_fcat
        EXCEPTIONS
          inconsistent_interface       = 1
          program_error                = 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.
      LOOP AT gt_fcat INTO ls_fcat
              WHERE ( fieldname = 'KUNNR'  OR
                      fieldname = 'ERNAM' ).
        ls_fcat-hotspot = abap_true.
        MODIFY gt_fcat FROM ls_fcat.
      ENDLOOP.
    ENDFORM.                    " BUILD_FIELDCATALOG_KNB1
    Regards
      Uwe

  • Urgent - How to call a Web Services from PLSQL - Please help

    Hello,
    I am very much new to WebServices, need to call web services through PLSQL. I have a urgent requirement, where i need to call the web services by passing from some paramters to it and the web services will return a varchar values as 'PASSED' or 'FAILED'.
    Can you please approch me the best way to start with.
    Thanks,
    Srikanth.

    Hi,
    I need to do it from PLSQL API's not from JAVA.
    I have started developing the code through UTIL_HTTP. Getting lots of error.
    Can you please guide me through these error.
    Below is the wsdl and a blcok where i am trying to retrive the value from webservice.
    Hope this will help you.
    Code:
    declare
    soap_request varchar2(30000);
    soap_respond varchar2(30000);
    http_req utl_http.req;
    http_resp utl_http.resp;
    resp XMLType;
    i integer;
    begin
    soap_request:= '<?xml version = "1.0" encoding = "UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Body>
    <ns1:soapCheckRequest1 wsdl:ns1="https://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <FirstName xsi:type="xsd:string">saddam</FirstName>
    <LastName xsi:type="xsd:string">hussein</LastName>
              <companyName xsi:type="xsd:string">samueladams</companyName>
              <address1 xsi:type="xsd:string">123 APT</address1>
              <address3 xsi:type="xsd:string">Atlanta</address3>
              <city xsi:type="xsd:string">uk</city>
              <stateOrRegion xsi:type="xsd:string">GA</stateOrRegion>
              <postalCode xsi:type="xsd:string">30338</postalCode>
              <email xsi:type="xsd:string">sj@samueladams</email>
              <isoCountryCode xsi:type="xsd:string">US</isoCountryCode>
              <endUserIP xsi:type="xsd:string">209.134.168.203</endUserIP>
    </ns1:soapCheckRequest1>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    http_req:= utl_http.begin_request
    ( 'http://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService'
    , 'POST'
    , 'HTTP/1.1'
    utl_http.set_header(http_req, 'Content-Type', 'text/xml'); -- since we are dealing with plain text in XML documents
    utl_http.set_header(http_req, 'Content-Length', length(soap_request));
    utl_http.set_header(http_req, 'SOAPAction', ''); -- required to specify this is a SOAP communication
    utl_http.write_text(http_req, soap_request);
    http_resp:= utl_http.get_response(http_req);
    DBMS_OUTPUT.PUT_LINE('-------utl_http.get_response---------------------');
    DBMS_OUTPUT.PUT_LINE('http_resp.status_code is :'||http_resp.status_code );
    DBMS_OUTPUT.PUT_LINE('http_resp.reason_phrase is :'||http_resp.reason_phrase);
    DBMS_OUTPUT.PUT_LINE('http_resp.http_version is :'||http_resp.http_version);
    DBMS_OUTPUT.PUT_LINE('http_resp.private_hndl is :'||http_resp.private_hndl);
    DBMS_OUTPUT.PUT_LINE('-------utl_http.get_response----------------------');
    utl_http.read_text(http_resp, soap_respond);
    utl_http.end_response(http_resp);
    resp:= XMLType.createXML(soap_respond);
    resp:= resp.extract('/soap:Envelop/soap:Body/child::node()'
    , 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'
    i:=0;
    loop
    dbms_output.put_line(substr(soap_respond,1+ i*255,250));
    i:= i+1;
    if i*250> length(soap_respond)
    then
    exit;
    end if;
    end loop;
    end;
    Error Message
    http_resp.reason_phrase is :Internal Server Error
    http_resp.http_version is :HTTP/1.1
    http_resp.private_hndl is :0
    -------utl_http.get_response----------------------
    <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultco
    apenv:Server.userException</faultcode><faultstring>org.xml.sax.SAXParseException: The prefix &quot;ns1&quot; for element &quot;ns1:soapCheckRequest1&quot; is not bound.</faultstring><detail><ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">atlcms
    2.iss.net</ns1:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
    <?xml version="1.0" encoding="UTF-8" ?>
    - <wsdl:definitions targetNamespace="https://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="https://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService" xmlns:intf="https://isportal-qa.iss.net/exportcompliancemanager/services/ExportCheckService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    - <!--
    WSDL created by Apache Axis version: 1.3
    Built on Oct 05, 2005 (05:23:37 EDT)
    -->
    - <wsdl:message name="soapCheckResponse1">
    <wsdl:part name="soapCheckReturn" type="soapenc:string" />
    </wsdl:message>
    - <wsdl:message name="soapCheckRequest1">
    <wsdl:part name="firstName" type="soapenc:string" />
    <wsdl:part name="lastName" type="soapenc:string" />
    <wsdl:part name="companyName" type="soapenc:string" />
    <wsdl:part name="address1" type="soapenc:string" />
    <wsdl:part name="address2" type="soapenc:string" />
    <wsdl:part name="address3" type="soapenc:string" />
    <wsdl:part name="city" type="soapenc:string" />
    <wsdl:part name="stateOrRegion" type="soapenc:string" />
    <wsdl:part name="postalCode" type="soapenc:string" />
    <wsdl:part name="email" type="soapenc:string" />
    <wsdl:part name="phone" type="soapenc:string" />
    <wsdl:part name="isoCountryCode" type="soapenc:string" />
    <wsdl:part name="endUserId" type="soapenc:string" />
    <wsdl:part name="endUserIP" type="soapenc:string" />
    <wsdl:part name="endUserSession" type="soapenc:string" />
    <wsdl:part name="performGovCheck" type="xsd:boolean" />
    <wsdl:part name="sendEmailNotification" type="xsd:boolean" />
    <wsdl:part name="screeningLevelBasedOnSuppliedCountryCode" type="xsd:boolean" />
    <wsdl:part name="screeningLevelBasedOnEndUserIP" type="xsd:boolean" />
    <wsdl:part name="soundexMatch" type="xsd:boolean" />
    </wsdl:message>
    - <wsdl:message name="soapCheckRequest">
    <wsdl:part name="firstName" type="soapenc:string" />
    <wsdl:part name="lastName" type="soapenc:string" />
    <wsdl:part name="companyName" type="soapenc:string" />
    <wsdl:part name="address1" type="soapenc:string" />
    <wsdl:part name="address2" type="soapenc:string" />
    <wsdl:part name="address3" type="soapenc:string" />
    <wsdl:part name="city" type="soapenc:string" />
    <wsdl:part name="stateOrRegion" type="soapenc:string" />
    <wsdl:part name="postalCode" type="soapenc:string" />
    <wsdl:part name="email" type="soapenc:string" />
    <wsdl:part name="phone" type="soapenc:string" />
    <wsdl:part name="isoCountryCode" type="soapenc:string" />
    <wsdl:part name="endUserId" type="soapenc:string" />
    <wsdl:part name="endUserIP" type="soapenc:string" />
    <wsdl:part name="endUserSession" type="soapenc:string" />
    <wsdl:part name="performGovCheck" type="xsd:boolean" />
    <wsdl:part name="sendEmailNotification" type="xsd:boolean" />
    <wsdl:part name="screeningLevelBasedOnEndUserIP" type="xsd:boolean" />
    <wsdl:part name="soundexMatch" type="xsd:boolean" />
    </wsdl:message>
    - <wsdl:message name="soapCheckResponse">
    Thanks and Regard,
    Srikanth

  • Read values from html response

    Hi,
    I am trying to make a call to an API using UTL_HTTP POST method over SSL and read the response html page and extract the values from the reponse.
    I am able to call and get a response back in html format. I have stored the html response in a clob variable.
    Now i want to parse this html and extract values from the form input items and send them out through OUT parameters.
    For example, from below reponse i want to extract the value '1111d7nhcwse30wq' from 'I4GO_UNIQUEID'
    Can anyone help me with the code to parse this html response and extract the values.
    Any help is greatly appreciated.
    Thanks
    Sharath
    sample Code:
    PROCEDURE get_token (
    p_requesterreference IN VARCHAR2,
    p_cardnumber IN VARCHAR2,
    p_cardtype IN VARCHAR2,
    p_cardholdername IN VARCHAR2,
    p_expirationmonth IN VARCHAR2,
    p_expirationyear IN VARCHAR2,
    p_streetaddress IN VARCHAR2,
    p_postalcode IN VARCHAR2,
    p_cvv2code IN VARCHAR2,
    po_uniqueid OUT VARCHAR2,
    po_errorindicator OUT VARCHAR2,
    po_primaryerrorcode OUT VARCHAR2,
    po_response OUT VARCHAR2,
    po_status_code OUT VARCHAR2,
    po_reason_phrase OUT VARCHAR2
    IS
    v_url VARCHAR2 (200);
    v_url_params VARCHAR2 (32767);
    v_resp_str VARCHAR2 (32767);
    l_http_req UTL_HTTP.req;
    l_http_resp UTL_HTTP.resp;
    v_requesterreference VARCHAR2 (12) := p_requesterreference;
    v_i4go_cardnumber VARCHAR2 (32) := p_cardnumber;
    v_i4go_streetaddress VARCHAR2 (30) := p_streetaddress;
    v_i4go_postalcode VARCHAR2 (9) := p_postalcode;
    v_i4go_expirationmonth VARCHAR2 (2) := p_expirationmonth; -- MM format
    v_i4go_expirationyear VARCHAR2 (2) := p_expirationyear; -- yy format
    v_i4go_cvv2code VARCHAR2 (3) := p_cvv2code;
    v_name VARCHAR2 (256);
    v_value VARCHAR2 (1024);
    l_clob CLOB;
    pv_amp CONSTANT CHAR (1) := CHR (38);
    CURSOR setup_cur
    IS
    SELECT interface_id, interface_name, interface_url, account_id, site_id
    FROM rsv.shift4_setup
    WHERE interface_name = 'I4GO';
    v_setup_rec setup_cur%ROWTYPE;
    BEGIN
    OPEN setup_cur;
    FETCH setup_cur
    INTO v_setup_rec;
    CLOSE setup_cur;
    v_url := 'https://certify.i4go.com//index.cfm?fuseaction=account.PostCardEntry';
    v_url_params :=
    pv_amp
    || 'i4GO_AccountID='
    || v_setup_rec.account_id
    || pv_amp
    || 'i4Go_SiteID='
    || v_setup_rec.site_id
    || pv_amp
    || 'i4Go_CardNumber='
    || v_i4go_cardnumber
    || pv_amp
    || 'i4Go_ExpirationMonth='
    || v_i4go_expirationmonth
    || pv_amp
    || 'i4Go_ExpirationYear='
    || v_i4go_expirationyear
    || pv_amp
    || 'i4Go_CVV2Code='
    || v_i4go_cvv2code
    || pv_amp
    || 'i4Go_PostalCode='
    || v_i4go_postalcode;
    -- begin request using POST method
    UTL_HTTP.set_response_error_check (FALSE);
    UTL_HTTP.set_transfer_timeout (180);
    UTL_HTTP.set_wallet ('file:/etc/ORACLE/WALLETS/oracle', 'welcome1');
    l_http_req := UTL_HTTP.begin_request (v_url, 'POST');
    UTL_HTTP.set_header (l_http_req, 'User-Agent', 'Mozilla/4.0');
    UTL_HTTP.set_header (l_http_req, 'Content-Type', 'application/x-www-form-urlencoded');
    UTL_HTTP.set_header (l_http_req, 'content-length', LENGTH (v_url_params));
    UTL_HTTP.write_text (l_http_req, v_url_params);
    -- get response
    l_http_resp := UTL_HTTP.get_response (l_http_req);
    po_status_code := l_http_resp.status_code;
    po_reason_phrase := l_http_resp.reason_phrase;
    -- read response into a clob
    DBMS_LOB.createtemporary (l_clob, FALSE);
    BEGIN
    LOOP
    UTL_HTTP.read_text (l_http_resp, v_resp_str, 32767);
    DBMS_LOB.writeappend (l_clob, LENGTH (v_resp_str), v_resp_str);
    END LOOP;
    EXCEPTION
    WHEN UTL_HTTP.end_of_body
    THEN
    -- end response
    UTL_HTTP.end_response (l_http_resp);
    END;
    -- Fre resources
    DBMS_LOB.freetemporary (l_clob);
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_LOB.freetemporary (l_clob);
    DBMS_OUTPUT.put_line (UTL_HTTP.get_detailed_sqlerrm);
    RAISE;
    END;
    sample response:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
         <title>Return With Payment Token</title>
         <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
         <script type="text/javascript"><!--
              picSpinner= new Image(40,40);
              picSpinner.src="images/loading040.gif";
              bodyOnLoad = function() {
                   $("#noScriptDiv").hide();
                   $("#scriptDiv").show();
                   $("#i4GoMainForm").submit();
         //--></script>
    </head>
    <body onload="bodyOnLoad();">
         <form name="i4GoMainForm" id="i4GoMainForm" action="http://google.com" method="POST" onsubmit="$('#i4Go_submit').attr('disabled','disabled');">
                   <input name="I4GO_RESPONSE" type="hidden" value="SUCCESS" />
                   <input name="I4GO_RESPONSECODE" type="hidden" value="1" />
                   <input name="I4GO_CARDTYPE" type="hidden" value="VS" />
                   <input name="I4GO_UNIQUEID" type="hidden" value="1111d7nhcwse30wq" />
                   <input name="I4GO_EXPIRATIONMONTH" type="hidden" value="12" />
                   <input name="I4GO_EXPIRATIONYEAR" type="hidden" value="2012" />
                   <input name="I4GO_CARDHOLDERNAME" type="hidden" value="" />
                   <input name="I4GO_STREETADDRESS" type="hidden" value="" />
                   <input name="I4GO_POSTALCODE" type="hidden" value="65000" />
              <div id="scriptDiv" style="font-family:Arial, Helvetica, sans-serif;font-size:18px;visibility:hidden;">
                   <img src="images/loading040.gif" alt="Spinner..." />  Loading...
              </div>
              <div id="noScriptDiv" style="font-family:Arial, Helvetica, sans-serif;">
                   <noscript>
                                       <h1>Statement of Tokenization</h1>
                                       <p>The payment information you have submitted has been securely stored in the Shift4 PCI-DSS certified data center and a token representing this information will be sent to the merchant for processing. Below is the information that will be returning to the originating merchant:</p>
                                       <ul>
                                            <li>Response: <strong>SUCCESS</strong></li>
                                            <li>Response Code: <strong>1</strong></li>
                                            <li>Card Type: <strong>VS</strong></li>
                                            <li>Token: <strong>1111d7nhcwse30wq</strong></li>
                                       </ul>
                   </noscript>
    <input type="submit" name="i4Go_submit" id="i4Go_submit" value="Continue" />
              </div>
         </form>
    </body>
    </html>
    Edited by: sgudipat on Apr 24, 2012 1:20 PM

    Here is working example for your HTML using xpath to extract values from html
    You can store your html response in clob variable and then extract the value with xpath
    declare
       l_clob clob;
       l_value varchar2(100);
       l_xml xmltype;
      begin
         l_clob :='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Return With Payment Token</title>
      <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
      <script type="text/javascript"><!--
       picSpinner= new Image(40,40);
       picSpinner.src="images/loading040.gif";
       bodyOnLoad = function() {
       $("#noScriptDiv").hide();
       $("#scriptDiv").show();
       $("#i4GoMainForm").submit();
      //--></script>
       </head>
       <body onload="bodyOnLoad();">
       <form name="i4GoMainForm" id="i4GoMainForm" action="http://google.com" method="POST" onsubmit="$(''#i4Go_submit'').attr(''disabled'',''disabled'');">
       <input name="I4GO_RESPONSE" type="hidden" value="SUCCESS" />
       <input name="I4GO_RESPONSECODE" type="hidden" value="1" />
       <input name="I4GO_CARDTYPE" type="hidden" value="VS" />
       <input name="I4GO_UNIQUEID" type="hidden" value="1111d7nhcwse30wq" />
       <input name="I4GO_EXPIRATIONMONTH" type="hidden" value="12" />
       <input name="I4GO_EXPIRATIONYEAR" type="hidden" value="2012" />
       <input name="I4GO_CARDHOLDERNAME" type="hidden" value="" />
       <input name="I4GO_STREETADDRESS" type="hidden" value="" />
       <input name="I4GO_POSTALCODE" type="hidden" value="65000" />
      <img src="images/loading040.gif" alt="Spinner..." />  Loading...
       <noscript>
       Statement of Tokenization
       The payment information you have submitted has been securely stored in the Shift4 PCI-DSS certified data center and a token representing this information will be sent to the merchant for processing. Below is the information that will be returning to the originating merchant:
           Response: SUCCESS
           Response Code: 1
           Card Type: VS
           Token: 1111d7nhcwse30wq
       </noscript>
       <input type="submit" name="i4Go_submit" id="i4Go_submit" value="Continue" />
       </form>
       </body>
       </html>';
         execute immediate 'alter session set events =''31156 trace name context forever, level 2''';
         l_xml := xmltype(l_clob);
         execute immediate 'alter session set events =''31156 trace name context off''';
         select extractvalue( l_xml
                            , '/html/body/form/input[@name="I4GO_CARDTYPE"]/@value'
                            , 'xmlns="http://www.w3.org/1999/xhtml"' )
         into l_value
         from dual;
         dbms_output.put_line(l_value);
       end;
    Problem when parsing html with xpath and xmltype
    Edited by: peterv6i.blogspot.com on Apr 26, 2012 9:38 AM

  • How to access web service from Oracle ?

    Database version: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
    I am trying to make a call to a web service through a procedure/function...
    I tried to use
    CREATE OR REPLACE PROCEDURE Call_Rest_Webservice
    AS
      t_Http_Req Utl_Http.Req;
      t_Http_Resp Utl_Http.Resp;
      t_Request_Body VARCHAR2(30000);
      t_Respond VARCHAR2(30000);
      t_Start_Pos INTEGER := 1;
      t_Output VARCHAR2(2000);
    BEGIN
      /*Construct the information you want to send to the webservice.
      Normally this would be in a xml structure. But for a REST-
      webservice this is not mandatory. The webservice i needed to
      call excepts plain test.*/
      t_Request_Body := 'the data you want to send to the webservice';
      /*Telling Oracle where the webservice can be found, what kind of request is made
      and the version of the HTTP*/
      t_Http_Req := Utl_Http.Begin_Request('**webservice address**',
                                           'GET',
                                           'HTTP/1.1');
      /*In my case the webservice used authentication with a username an password
      that was provided to me. You can skip this line if it's a public webservice.*/
      --Utl_Http.Set_Authentication(t_Http_Req, 'username', 'password');
      /*Describe in the request-header what kind of data is send*/
      Utl_Http.Set_Header(t_Http_Req, 'Content-Type', 'text/xml charset=UTF-8');
      /*Describe in the request-header the lengt of the data*/
      Utl_Http.Set_Header(t_Http_Req, 'Content-Length', Length(t_Request_Body));
      /*Put the data in de body of the request*/
      Utl_Http.Write_Text(t_Http_Req, t_Request_Body);
      /*make the actual request to the webservice en catch the responce in a
      variable*/
      t_Http_Resp := Utl_Http.Get_Response(t_Http_Req);
      /*Read the body of the response, so you can find out if the information was
        received ok by the webservice.
        Go to the documentation of the webservice for what kind of responce you
        should expect. In my case it was:
        <responce>
          <status>ok</status>
        </responce>
      Utl_Http.Read_Text(t_Http_Resp, t_Respond);
      /*Some closing?1 Releasing some memory, i think....*/
      Utl_Http.End_Response(t_Http_Resp);
    END;But it gave me ORA-29272: HTTP request failed
    ORA-06512: at "SYS.UTL_HTTP", line 1029
    ORA-12545: Connect failed because target host or object does not exist
    But I can link to the web server by going to **webservice address** through my browser.
    Is there any ACL should be open in order to have this capability? I asked my DBA but she asked me I will need to give her username/password/ip in order to open an ACL...
    however there is no username/password required while visiting the web service...
    Any help would be highly appreciated..
    Thanks,
    Edited by: 986006 on Mar 4, 2013 8:38 AM

    Y.L wrote:
    That is because the database was unable to connect to the specified server. Wrong hostname or IP specified. Failure to resolve the hostname into an IP. Firewall blocking. Etc.The hostname I put there can be visit through my browser. I think it should not be the host server's issue... So it could be a firewall on my database side that needs to be open in order to visit the hostserver?The "web browser" code (your PL/SQL code using UTL_HTTP) runs on the Oracle database server. It needs the same type of network access that your browser on your PC enjoys. (firewalls opened, proxy authentication if required, etc).
    On 11g. Not on 10g.I saw the example code you post through the link you provided... will those only work on 11g?
    If it can work on 10g, what package or what steps I need to follow in order to have that working on me?The code I've posted will work on both versions. My comment was regards to ACLs. No ACLs existed on 10g. So you only need execute privs on the relevant packages (e.g. UTL_HTTP, etc).
    ACLs were introduced with 11g - so on 11g you also need the DBA to create an ACL for you that will allow UTL_HTTP access to the network.

  • Restful service unable to insert data using PL/SQL.

    Hi all,
    Am running: AL 2.01 standalone mode on OEL 4.8 in VM box A.
    Oracle database 10.2.0.4 with Apex 4.2.0.00.27 on OEL4.8 in VM box B.
    Able to performed oracle.example.hr Restful services with no problem.
    Unable to insert data using AL 2.0.1 but works on AL 1.1.4.
    which uses the following table (under schema: scott):
    create table json_demo ( title varchar2(20), description varchar2(1000) );
    grant all on json_demo to apex_public_user; and below procedure ( scott's schema ):
    CREATE OR REPLACE
    PROCEDURE post(
        p_url     IN VARCHAR2,
        p_message IN VARCHAR2,
        p_response OUT VARCHAR2)
    IS
      l_end_loop BOOLEAN := false;
      l_http_req utl_http.req;
      l_http_resp utl_http.resp;
      l_buffer CLOB;
      l_data       VARCHAR2(20000); 
      C_USER_AGENT CONSTANT VARCHAR2(4000) := 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
    BEGIN
      -- source: http://awads.net/wp/2005/11/30/http-post-from-inside-oracle/
      -- Ask UTL_HTTP not to raise an exception for 4xx and 5xx status codes,
      -- rather than just returning the text of the error page.
      utl_http.set_response_error_check(false);
      -- Begin the post request
      l_http_req := utl_http.begin_request (p_url, 'POST', utl_http.HTTP_VERSION_1_1);
      -- Set the HTTP request headers
      utl_http.set_header(l_http_req, 'User-Agent', C_USER_AGENT);
      utl_http.set_header(l_http_req, 'content-type', 'application/json;charset=UTF-8');
      utl_http.set_header(l_http_req, 'content-length', LENGTH(p_message));
      -- Write the data to the body of the HTTP request
      utl_http.write_text(l_http_req, p_message);
      -- Process the request and get the response.
      l_http_resp := utl_http.get_response (l_http_req);
      dbms_output.put_line ('status code: ' || l_http_resp.status_code);
      dbms_output.put_line ('reason phrase: ' || l_http_resp.reason_phrase);
      LOOP
        EXIT
      WHEN l_end_loop;
        BEGIN
          utl_http.read_line(l_http_resp, l_buffer, true);
          IF(l_buffer IS NOT NULL AND (LENGTH(l_buffer)>0)) THEN
            l_data    := l_data||l_buffer;
          END IF;
        EXCEPTION
        WHEN utl_http.end_of_body THEN
          l_end_loop := true;
        END;
      END LOOP;
      dbms_output.put_line(l_data);
      p_response:= l_data;
      -- Look for client-side error and report it.
      IF (l_http_resp.status_code >= 400) AND (l_http_resp.status_code <= 499) THEN
        dbms_output.put_line('Check the URL.');
        utl_http.end_response(l_http_resp);
        -- Look for server-side error and report it.
      elsif (l_http_resp.status_code >= 500) AND (l_http_resp.status_code <= 599) THEN
        dbms_output.put_line('Check if the Web site is up.');
        utl_http.end_response(l_http_resp);
        RETURN;
      END IF;
      utl_http.end_response (l_http_resp);
    EXCEPTION
    WHEN OTHERS THEN
      dbms_output.put_line (sqlerrm);
      raise;
    END; and executing in sqldeveloper 3.2.20.09 when connecting directly to box B as scott:
    SET serveroutput ON
    DECLARE
      l_url      VARCHAR2(200)   :='http://MY_IP:8585/apex/demo';
      l_json     VARCHAR2(20000) := '{"title":"thetitle","description":"thedescription"}';
      l_response VARCHAR2(30000);
    BEGIN
      post( p_url => l_url, p_message =>l_json, p_response => l_response);
    END;which resulted in :
    anonymous block completed
    status code: 200
    reason phrase: OK
    with data inserted. Setup using 2.0.1
       Workspace : wsdemo
    RESTful Service Module:  demo/
              URI Template:      test
                    Method:  POST
               Source Type:  PL/SQLand executing in sqldeveloper 3.2.20.09 when connecting directly to box B as scott:
    SET serveroutput ON
    DECLARE
      l_url      VARCHAR2(200)   :='http://MY_IP:8585//apex/wsdemo/demo/test';
      l_json     VARCHAR2(20000) := '{"title":"thetitle","description":"thedescription"}';
      l_response VARCHAR2(30000);
    BEGIN
      post( p_url => l_url, p_message =>l_json, p_response => l_response);
    END;which resulted in :
    status code: 500
    reason phrase: Internal Server Error
    Listener's log:
    Request Path passes syntax validation
    Mapping request to database pool: PoolMap [_poolName=apex, _regex=null, _workspaceIdentifier=WSDEMO, _failed=false, _lastUpdate=1364313600000, _template=/wsdemo/, _type=BASE_PATH]
    Applied database connection info
    Attempting to process with PL/SQL Gateway
    Not processed as PL/SQL Gateway request
    Attempting to process as a RESTful Service
    demo/test matches: demo/test score: 0
    Choosing: oracle.dbtools.rt.resource.templates.jdbc.JDBCResourceTemplateDispatcher as current candidate with score: Score [handle=JDBCURITemplate [scopeId=null, templateId=2648625079503782|2797815111031405, uriTemplate=demo/test], score=0, scope=SecurityConfig [constraint=none, realm=NONE, logonConfig=LogonConfig [logonForm=null, logonFailed=null]], originsAllowed=[], corsEnabled=true]
    Determining if request can be dispatched as a Tenanted RESTful Service
    Request path has one path segment, continuing processing
    Tenant Principal already established, cannot dispatch
    Chose oracle.dbtools.rt.resource.templates.jdbc.JDBCResourceTemplateDispatcher as the final candidate with score: Score [handle=JDBCURITemplate [scopeId=null, templateId=2648625079503782|2797815111031405, uriTemplate=demo/test], score=0, scope=SecurityConfig [constraint=none, realm=NONE, logonConfig=LogonConfig [logonForm=null, logonFailed=null]], originsAllowed=[], corsEnabled=true] for: POST demo/test
    demo/test is a public resource
    Using generator: oracle.dbtools.rt.plsql.AnonymousBlockGenerator
    Performing JDBC request as: SCOTT
    Mar 28, 2013 1:29:28 PM oracle.dbtools.common.jdbc.JDBCCallImpl execute
    INFO: Error occurred during execution of: [CALL, begin
    insert into scott.json_demo values(/*in:title*/?,/*in:description*/?);
    end;, [title, in, class oracle.dbtools.common.stmt.UnknownParameterType], [description, in, class oracle.dbtools.common.stmt.UnknownParameterType]]with values: [thetitle, thedescription]
    Mar 28, 2013 1:29:28 PM oracle.dbtools.common.jdbc.JDBCCallImpl execute
    INFO: ORA-06550: line 1, column 6:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
       begin case declare exit for goto if loop mod null pragma
       raise return select update while with <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> <<
       close current delete fetch lock insert open rollback
       savepoint set sql execute commit forall merge pipe
    The symbol "" was ignored.
    ORA-06550: line 2, column 74:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
       begin case declare end exception exit for goto if loop mod
       null pragma raise return select update while with
       <an identifier> <a double-quoted delimited-id
    java.sql.SQLException: ORA-06550: line 1, column 6:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
       begin case declare exit for goto if loop mod null pragma
       raise return select update while with <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> <<
       close current delete fetch lock insert open rollback
       savepoint set sql execute commit forall merge pipe
    The symbol "" was ignored.
    ORA-06550: line 2, column 74:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
       begin case declare end exception exit for goto if loop mod
       null pragma raise return select update while with
       <an identifier> <a double-quoted delimited-id
            at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
            at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
            at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
            at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:505)
            at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:223)
            at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
            at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:205)
            at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1043)
            at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
            at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3612)
            at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3713)
            at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4755)
            at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at oracle.ucp.jdbc.proxy.StatementProxyFactory.invoke(StatementProxyFactory.java:242)
            at oracle.ucp.jdbc.proxy.PreparedStatementProxyFactory.invoke(PreparedStatementProxyFactory.java:124)
            at oracle.ucp.jdbc.proxy.CallableStatementProxyFactory.invoke(CallableStatementProxyFactory.java:101)
            at $Proxy46.execute(Unknown Source)
            at oracle.dbtools.common.jdbc.JDBCCallImpl.execute(JDBCCallImpl.java:44)
            at oracle.dbtools.rt.plsql.AnonymousBlockGenerator.generate(AnonymousBlockGenerator.java:176)
            at oracle.dbtools.rt.resource.templates.v2.ResourceTemplatesDispatcher$HttpResourceGenerator.response(ResourceTemplatesDispatcher.java:309)
            at oracle.dbtools.rt.web.RequestDispatchers.dispatch(RequestDispatchers.java:88)
            at oracle.dbtools.rt.web.HttpEndpointBase.restfulServices(HttpEndpointBase.java:412)
            at oracle.dbtools.rt.web.HttpEndpointBase.service(HttpEndpointBase.java:162)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
            at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.doFilter(ServletAdapter.java:1059)
            at com.sun.grizzly.http.servlet.ServletAdapter$FilterChainImpl.invokeFilterChain(ServletAdapter.java:999)
            at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:434)
            at oracle.dbtools.standalone.SecureServletAdapter.doService(SecureServletAdapter.java:65)
            at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:379)
            at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
            at com.sun.grizzly.tcp.http11.GrizzlyAdapterChain.service(GrizzlyAdapterChain.java:196)
            at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
            at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
            at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
            at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
            at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
            at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
            at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
            at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
            at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
            at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
            at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
            at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
            at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
            at java.lang.Thread.run(Thread.java:662)
    Error during evaluation of resource template: ORA-06550: line 1, column 6:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
       begin case declare exit for goto if loop mod null pragma
       raise return select update while with <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> <<
       close current delete fetch lock insert open rollback
       savepoint set sql execute commit forall merge pipe
    The symbol "" was ignored.
    ORA-06550: line 2, column 74:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
       begin case declare end exception exit for goto if loop mod
       null pragma raise return select update while with
       <an identifier> <a double-quoted delimited-idPlease advise.
    Regards
    Zack

    Zack.L wrote:
    Hi Andy,
    Sorry, forgot to post the Source that's use by both AL1.1.4 and AL2.0.1.
    Source
    begin
    insert into scott.json_demo values(:title,:description);
    end;
    it's failing during the insert?
    Yes, it failed during insert using AL2.0.1.
    So the above statement produces the following error message:
    The symbol "" was ignored.
    ORA-06550: line 2, column 74:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
    begin case declare end exception exit for goto if loop mod
    null pragma raise return select update while with
    <an identifier> <a double-quoted delimited-idThis suggests to me that an unprintable character (notice how there is nothing between the double quotes - "") has worked its way into your PL/SQL Handler. Note how the error is reported to be a column 74 on line 2, yet line 2 of the above block should only have 58 characters, so at a pure guess somehow there's extra whitespace on line 2, that is confusing the PL/SQL compiler, I suggest re-typing the PL/SQL handler manually and seeing if that cures the problem.

  • How to send XML using UTL_HTTP

    I am trying to workout how to send XML data to a webserver using UTL_HTTP but am not getting any reply
    I need to submit the following XML document to a server "http://api.fastsms.co.uk/api/xmlapi.php"  Their instructions are "The XML Document should be posted unencoded, with a UTF-8 character set as parameter 'xml'"
    If I submit the following XML on their test form
    <?xml version="1.0"?>
    <apirequest version="1">
    <user>
      <username>**USER**</username>
      <password>**PASSWORD**</password>
    </user>
    <application>
      <name>Example Application</name>
      <version>1.0</version>
    </application>
    <inboundcheck lastid="10711399"/>
    </apirequest>
    I get an XML response back with the messages in my inbox. 
    This is the code I am trying to use to accomplish the same from PL/SQL : I know a response is coming back as there is header information - just no content.  What am I doing wrong ?
      l_xml VARCHAR2(5000);
      req utl_http.req;
      resp utl_http.resp;
      header_name VARCHAR2(256); -- Response header name
      header_value VARCHAR2(1024); -- Response header value
      response_text VARCHAR2(4000); -- Response body
      l_url VARCHAR2(100);
    BEGIN
      l_xml := 'xml=<?xml version="1.0"?>';
      l_xml := '<apirequest version="1">';
      l_xml := '<user>';
      l_xml := '<username>**USER**</username>';
      l_xml := '<password>**PASSWORD**</password>';
      l_xml := '</user>';
      l_xml := '<application>';
      l_xml := '<name>Example Application</name>';
      l_xml := '<version>1.0</version>';
      l_xml := '</application>';
      l_xml := '<inboundcheck lastid="10711399"/>';
      l_xml := '</apirequest>';
      -- Open HTTP connection
      l_url := 'http://api.fastsms.co.uk/api/xmlapi.php';
      req := utl_http.begin_request(l_url,'POST',utl_http.HTTP_VERSION_1_1);
      -- Set headers for type and length
      utl_http.set_header(req,'Content-Type','application/x-www-form-urlencoded');
      utl_http.set_header(req,'Content-Length',to_char(length(l_xml)));
      -- Write parameter
      utl_http.write_text(req,l_xml);
      -- Read response file
      resp := utl_http.get_response(req);
      -- Print out the response headers
      FOR i IN 1 .. utl_http.get_header_count(resp) LOOP
        utl_http.get_header(resp,i,header_name,header_value);
        logging_pkg.info(header_name || ': ' || header_value);
      END LOOP;
      -- Print out the response body
      BEGIN
        LOOP
          utl_http.read_text(resp,response_text);
          logging_pkg.info(response_text);
        END LOOP;
      EXCEPTION
        WHEN utl_http.end_of_body THEN
          logging_pkg.info('End of body');
      END;
      -- close http connection
      utl_http.end_response(resp);
      EXCEPTION
        WHEN utl_http.end_of_body THEN
          utl_http.end_response(resp);
    END;
    Cheers,
    Brent

    Hi Billy
    Yikes - how embarassing !  Thanks for pointing out my beginners mistake there.  I've fixed my code - and also implemented the substitutions of parameters like you suggested - I like that approach.
    Unfortunately the end result is no better - the line
    utl_http.read_text(resp,response_text);
    Still returns nothing back
    The headers that are coming back are
    Date: Thu, 04 Jul 2013 08:31:56 GMT
    Server: Apache/2.2.16 (Ubuntu)
    X-Powered-By: PHP/5.3.3-1ubuntu9.3
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Pragma: no-cache
    Vary: Accept-Encoding
    Content-Length: 0
    Content-Type: text/html; charset=UTF-8
    Connection: close
    I guess I will need to try chasing it with the fastsms vendor so see if they can check my incoming request and see if there are any glaring problems. I know the xml is correct as I am now logging the xml string just before I send it and when I take that string and put it in their test form it works perfectly - something else in the puzzle is missing. I've had no experience using utl_http before - perhaps it's no possible to read the xml repsonse using this ?
    Anyway, thanks for your help Billy.
    ps - How do you paste your code into your message to get that formatting ?
    Cheers,
    Brent

Maybe you are looking for

  • Error while configuring - Proportion of New Customers

    Hi All, I was Creating a Start Routine on the Update Rule for a DSO - N_CSTORD (Step 2.1.2 BB8 - Proportion of New Customers) I got an error while trying to check the ABAP routine E:A target area must be declared either explicitly with an INTO clause

  • Lack of communication from the, so-say, world lead...

    ever had to eat your words? We are moving to a new property in Devon.  Booked BT well in advance.  Also booked 9 other tradesmen fro mAerial installer, plumber, electrician Intruder alarm installation - all turned up when they said they would, did an

  • Problem in WAD (The requested query / does not exist on the current server)

    Dear Guru's When i execute a Web Application in WAD in the selection screen suppose if i give Key product  as 86000 then check and execute i get correct data. Then if i come to  backpage (Selection screen again using backspace) and change Key product

  • Export file to PDF - where is the"background activity" in InDesign CS6?

    Export file to PDF - where is the "background activity" in InDesign CS6? i´ve been told that I can solve the problem by clicking in to "background activity", but I cant even find it? Where is it? I have never ever had this problem, and I cant do my w

  • Can't loging to Oracle service

    Hi, I've created new service like this: srvctl add service -d racdb -s SNAME -r racdb1,racdb2 srvctl start service -d racdb -s SNAME crs_stat shows that service is correct (ONLINE). But right know I can't login to service... What I should do? Add SNA