Read_error

does anyone the reasons why you get a read_error from utl_file.get_line when trying to read a file on a unix server but the file(pdf) was generated on a windows server. i presume it has something to do with encoding but can anyone explain this further

Is this the same problem that is being discussed in Problems with utl_file and reading pdf's? Or are these separate issues?
Justin

Similar Messages

  • Oracle 9i UTL_FILE.FOPEN throwing READ_ERROR

    Hi
    while running the package containg UTL_FILE.FOPEN
    I am getting an error for reading the file on this statement :
    v_file_handler := UTL_FILE.FOPEN(i_directory_path,i_file_name,'R');This happens in UNIX ,LINUX and windows NT server .
    kindly suggest , whether this is an OS error (technical problem) or something else .
    thanx in advance ,
    Ashutosh .

    Hi
    the UTL_FILE.FOPEN only opens an existing flat file on your OS , the UTL_FILE.GET_LINE reads from the file.
    many reasons to generate a read error .
    the file can be corrupted, the file doesn't exists or you havent configured the UTL_FIL_DIR parameter in the init.ora file which should be on the machine where the database is.
    make sure you have the correct file name and the parameter is set.
    also try to handle the exception.
    WHEN UTL_FILE.READ_ERROR THEN
    RAISE_APPLICATION_ERROR (-20204, SQLCODE || ' ' || SQLERRM);
    UTL_FILE.FCLOSE(v_filehandle);
    like this you can get the exact error code and message.
    Regards
    Tony G.

  • (8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR

    제품 : PL/SQL
    작성날짜 : 2002-11-22
    (8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR
    ===================================================
    Problem Description
    PLSQL에서 UTL_FILE package을 사용하여 text file를 read 하고 write할때
    1023 byte 이상의 파일을 읽고 쓰고자 할때 다음의 ERROR을 만나게 된다.
    UTL_FILE.WRITE_ERROR
    UTL_FILE.READ_ERROR
    User-defined exception
    8.0.5 이전에는 UTL_FILE package을 사용하여 file을 다룰때 1023 byte이상의
    데이터를 읽지 못하는 제한이 있었다. 하지만 8.0.5 이후에는 32,767 까지
    사용 가능하다. 디폴트 최대 라인 싸이즈는 1023이지만 이것을 UTL_FILE.FOPEN
    function에 MAX_LINESIZE 파라메터를 이용하여 해결 가능하다.
    Default:
    FUNCTION fopen(location IN VARCHAR2,
    filename IN VARCHAR2,
    open_mode IN VARCHAR2)
    RETURN file_type;
    최대 라인 싸이즈를 지정하고자 할때:
    FUNCTION fopen(location IN VARCHAR2,
    filename IN VARCHAR2,
    open_mode IN VARCHAR2,
    max_linesize IN BINARY_INTEGER)
    RETURN file_type;
    Solution Description:
    MAX_LINESIZE 파라메터를 추가한 예이다.
    CREATE OR REPLACE PROCEDURE file_test IS
    file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
    retrieved_buffer VARCHAR2(32767); -- Line retrieved from flat file
    BEGIN
    -- Open the same file to read from
    file_handle :=
    UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R',32767);
    -- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R'); -- READ_ERROR
    -- Read a line from the file.
    UTL_FILE.GET_LINE (file_handle, retrieved_buffer);
    -- Print fetched line out to the SQL*PLUS prompt.
    DBMS_OUTPUT.PUT_LINE('File size is : '||LENGTH(retrieved_buffer));
    -- CLose the file.
    UTL_FILE.FCLOSE(file_handle);
    file_handle :=
    UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W',32767);
    -- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W'); --WRITE_ERROR
    UTL_FILE.PUT_LINE (file_handle, retrieved_buffer);
    UTL_FILE.FCLOSE(file_handle);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('no_data_found');
    UTL_FILE.FCLOSE(file_handle);
    WHEN UTL_FILE.INVALID_PATH THEN
    DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
    UTL_FILE.FCLOSE(file_handle);
    WHEN UTL_FILE.READ_ERROR THEN
    DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
    UTL_FILE.FCLOSE(file_handle);
    WHEN UTL_FILE.WRITE_ERROR THEN
    DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
    UTL_FILE.FCLOSE(file_handle);
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('other stuff');
    UTL_FILE.FCLOSE(file_handle);
    END;
    아래와 같이 1023 byte 이상의 record임에도 잘 읽히는 것을 볼수 있다.
    SQL> set serveroutput on
    SQL> exec file_test
    File size is : 1921
    PL/SQL procedure successfully completed.
    Reference Ducumment
    <Note:1026951.6>
    KOREAN Bulletin : 11532

    제품 : PL/SQL
    작성날짜 : 2002-11-22
    (8.0.5+) UTL_FILE PACKAGE사용시 READ_ERROR/WRITE_ERROR
    ===================================================
    Problem Description
    PLSQL에서 UTL_FILE package을 사용하여 text file를 read 하고 write할때
    1023 byte 이상의 파일을 읽고 쓰고자 할때 다음의 ERROR을 만나게 된다.
    UTL_FILE.WRITE_ERROR
    UTL_FILE.READ_ERROR
    User-defined exception
    8.0.5 이전에는 UTL_FILE package을 사용하여 file을 다룰때 1023 byte이상의
    데이터를 읽지 못하는 제한이 있었다. 하지만 8.0.5 이후에는 32,767 까지
    사용 가능하다. 디폴트 최대 라인 싸이즈는 1023이지만 이것을 UTL_FILE.FOPEN
    function에 MAX_LINESIZE 파라메터를 이용하여 해결 가능하다.
    Default:
    FUNCTION fopen(location IN VARCHAR2,
    filename IN VARCHAR2,
    open_mode IN VARCHAR2)
    RETURN file_type;
    최대 라인 싸이즈를 지정하고자 할때:
    FUNCTION fopen(location IN VARCHAR2,
    filename IN VARCHAR2,
    open_mode IN VARCHAR2,
    max_linesize IN BINARY_INTEGER)
    RETURN file_type;
    Solution Description:
    MAX_LINESIZE 파라메터를 추가한 예이다.
    CREATE OR REPLACE PROCEDURE file_test IS
    file_handle UTL_FILE.FILE_TYPE; -- file handle of OS flat file
    retrieved_buffer VARCHAR2(32767); -- Line retrieved from flat file
    BEGIN
    -- Open the same file to read from
    file_handle :=
    UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R',32767);
    -- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','myfile.txt','R'); -- READ_ERROR
    -- Read a line from the file.
    UTL_FILE.GET_LINE (file_handle, retrieved_buffer);
    -- Print fetched line out to the SQL*PLUS prompt.
    DBMS_OUTPUT.PUT_LINE('File size is : '||LENGTH(retrieved_buffer));
    -- CLose the file.
    UTL_FILE.FCLOSE(file_handle);
    file_handle :=
    UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W',32767);
    -- UTL_FILE.FOPEN('/home/ora920/product/9.2.0/utldir','out.txt','W'); --WRITE_ERROR
    UTL_FILE.PUT_LINE (file_handle, retrieved_buffer);
    UTL_FILE.FCLOSE(file_handle);
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('no_data_found');
    UTL_FILE.FCLOSE(file_handle);
    WHEN UTL_FILE.INVALID_PATH THEN
    DBMS_OUTPUT.PUT_LINE('UTL_FILE.INVALID_PATH');
    UTL_FILE.FCLOSE(file_handle);
    WHEN UTL_FILE.READ_ERROR THEN
    DBMS_OUTPUT.PUT_LINE(' UTL_FILE.READ_ERROR');
    UTL_FILE.FCLOSE(file_handle);
    WHEN UTL_FILE.WRITE_ERROR THEN
    DBMS_OUTPUT.PUT_LINE('UTL_FILE.WRITE_ERROR');
    UTL_FILE.FCLOSE(file_handle);
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('other stuff');
    UTL_FILE.FCLOSE(file_handle);
    END;
    아래와 같이 1023 byte 이상의 record임에도 잘 읽히는 것을 볼수 있다.
    SQL> set serveroutput on
    SQL> exec file_test
    File size is : 1921
    PL/SQL procedure successfully completed.
    Reference Ducumment
    <Note:1026951.6>
    KOREAN Bulletin : 11532

  • Exception type [READ_ERROR] raised at line 193 of ../nsapi/Reader.cpp

    Hi,
    We are using WebLogic Server 6.1 SP4 and its iisproxy.dll on a Windows 2000 box.
    We kept getting the following READ_ERROR messages randomly and infrequently.
    1. Does anyone have any insightful thoughts about what are the possible causes?
    2. Will upgrading the plug-in to the lastest iisproxy.dll help to fix this issue?
    3. a bonus question: is it true that the KeepAlive flag was set to FALSE by default
    for the iisproxy.dll coming with WebLogic Server 6.1? Looks like that's true by
    running a few tests.
    Any comments will be highly appreciated!
    Joan
    ====== from plug-in log file =======
    Mon Jun 07 08:34:06 2004 ========================== New Request ==========================
    Mon Jun 07 08:34:06 2004 SSL is not being used
    Mon Jun 07 08:34:06 2004 Request URI = [xxx.jsp]
    Mon Jun 07 08:34:06 2004 Going to save the post data in file
    Mon Jun 07 08:34:06 2004 Temp Post File name = [C:\WINNT\TEMP\_wl_proxy\_post_2268_2413]
    Mon Jun 07 08:34:06 2004 Going to readClient [0] bytes
    Mon Jun 07 08:34:06 2004 ReadPostToFile(): Read the file completely 2626 bytes
    Mon Jun 07 08:34:06 2004 attempt #0 out of a max of 5
    Mon Jun 07 08:34:06 2004 general list: trying connect to xxx'/7001/7001 at line
    978 for '/xxx.jsp'
    Mon Jun 07 08:34:06 2004 INFO: New NON-SSL URL
    Mon Jun 07 08:34:06 2004 WLS info in sendRequest: xxx:7001 recycled? 0
    Mon Jun 07 08:34:06 2004 Hdrs from client:[Accept]=[image/gif, image/x-xbitmap,
    image/jpeg, image/pjpeg, */*
    Mon Jun 07 08:34:06 2004 Hdrs from client:[Host]=[xxx
    Mon Jun 07 08:34:06 2004 Hdrs from client:[User-Agent]=[Microsoft URL Control
    - 6.00.8862
    Mon Jun 07 08:34:06 2004 Hdrs from client:[Cookie]=[JSESSIONID=xxx!7001!7002
    Mon Jun 07 08:34:06 2004 Hdrs from client:[Authorization]=[xxx]
    Mon Jun 07 08:34:06 2004 Hdrs from client:[Content-Length]=[2626
    Mon Jun 07 08:34:06 2004 Hdrs from client:[Cache-Control]=[no-cache
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Accept]=[image/gif, image/x-xbitmap, image/jpeg,
    image/pjpeg, */*]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Host]=[xxx.com]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[User-Agent]=[Microsoft URL Control - 6.00.8862]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Cookie]=[JSESSIONID=xxx!7001!7002]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Authorization]=[xxx]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Content-Length]=[2626]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Cache-Control]=[no-cache]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Connection]=[Keep-Alive]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[WL-Proxy-Client-IP]=[xxx]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[X-WebLogic-Request-ClusterInfo]=[true]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[X-WebLogic-Force-JVMID]=[true]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[WL-Proxy-SSL]=[true]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Proxy-Remote-User]=[xxx]
    Mon Jun 07 08:34:06 2004 Hdrs to WLS:[Proxy-Auth-Type]=[xxx]
    Mon Jun 07 08:34:06 2004 INFO: sysSend 784
    Mon Jun 07 08:34:06 2004 INFO: sysSend 2626
    Mon Jun 07 08:37:33 2004 *******Exception type [READ_ERROR] raised at line 193
    of ../nsapi/Reader.cpp
    Mon Jun 07 08:37:33 2004 NOT failing over after sendRequest() due to error 10053
    or 10054.
    Mon Jun 07 08:37:33 2004 URL deleted!
    Mon Jun 07 08:37:33 2004 request [xxx.jsp] did NOT process successfully
    [iisproxy.dll]

    Hi ,
    Have you resolved this problem or still it is pending ?
    Now I am also encountring the same problem.
    Please guid me if you have resolved the problem
    Regards
    Sathish

  • Error while opening a pdf file sent as an attachment in mail

    Dear All,
            We have converted a alv grid into pdf and sent a mail with the attached pdf file. When the attachment is opened in the received mail we get an error " File does not begin with %pdf-". I am pasting the code.
    Select single
      from
        TSP01
      where
        RQIDENT = wa_listident.
      if sy-subrc <> 0.
         exit.
      endif.
      client = tsp01-rqclient.
      name   = tsp01-rqo1name.
    *BREAK-POINT.
      CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
             EXPORTING
                  AUTHORITY     = 'SP01'
                  CLIENT        = client
                  NAME          = name
                  PART          = 1
             IMPORTING
              CHARCO        =
              CREATER       =
              CREDATE       =
              DELDATE       =
              MAX_CREDATE   =
              MAX_DELDATE   =
              NON_UNIQ      =
              NOOF_PARTS    =
              RECTYP        =
              SIZE          =
              STOTYP        =
                  TYPE          = type
                  OBJTYPE       = objtype
             EXCEPTIONS
                  FB_ERROR      = 1
                  FB_RSTS_OTHER = 2
                  NO_OBJECT     = 3
                  NO_PERMISSION = 4.
      if objtype(3) = 'OTF'.
        is_otf = 'X'.
      else.
        is_otf = space.
      endif.
    *BREAK-POINT.
    CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
             EXPORTING
                  rqident              = wa_listident
                  desired_type         = desired_type
             IMPORTING
                  real_type            = real_type
             TABLES
                  buffer               = l_objcont
             EXCEPTIONS
                  no_such_job          = 14
                  type_no_match        = 94
                  job_contains_no_data = 54
                  no_permission        = 21
                  can_not_access       = 21
                  read_error           = 54.
        IF sy-subrc EQ 0.
          attach_type = real_type.
        ENDIF.
    if is_otf = 'X'.
    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
            EXPORTING
              SRC_SPOOLID                    = wa_listident
              NO_DIALOG                      = c_no
          DST_DEVICE                     =
          PDF_DESTINATION                =
            IMPORTING
              PDF_BYTECOUNT                  =  gd_bytecount
              PDF_SPOOLID                    = pdfspoolid
          OTF_PAGECOUNT                  =
              BTC_JOBNAME                    = jobname
              BTC_JOBCOUNT                   = jobcount
            TABLES
              PDF                            = it_pdf_output
            EXCEPTIONS
              ERR_NO_OTF_SPOOLJOB            = 1
              ERR_NO_SPOOLJOB                = 2
              ERR_NO_PERMISSION              = 3
              ERR_CONV_NOT_POSSIBLE          = 4
              ERR_BAD_DSTDEVICE              = 5
              USER_CANCELLED                 = 6
              ERR_SPOOLERROR                 = 7
              ERR_TEMSEERROR                 = 8
              ERR_BTCJOB_OPEN_FAILED         = 9
              ERR_BTCJOB_SUBMIT_FAILED       = 10
              ERR_BTCJOB_CLOSE_FAILED        = 11
      CHECK sy-subrc = 0.
      ENDIF.
    Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    Please guide me to resolve this issue.
    Thanks & Regards,
    Anand

    Hi,
    is the next part of the code correct.
    What i mean is packing of the attachment, finding out the size of pdf file and doc type as PDF.
    You can also try below link..
    Link: [http://wiki.sdn.sap.com/wiki/display/Snippets/SENDALVGRIDASPDFATTACHMENTTOSAPINBOXUSINGCLASSES]
    Hope this helps.
    Regards,
    -Sandeep

  • How can I read, millions of records and write as *.csv file

    I have to return some set of columns values(based on current date) from the database (could be million of record also) The dbms_output can accomodate only 20000 records. (I am retrieving thru a procedure using cursor).
    I should write these values to a file with extn .csv (comma separated file) I thought of using a utl_file. But I heard there is some restriction on the number of records even in utl_file.
    If so, what is the restriction. Is there any other way I can achive it? (BLOB or CLOB ??).
    Please help me in solving this problem.
    I have to write to .csv file, the values from the cursor I have concatinated with "," and now its returning the value to the screen (using dbms_output, temporarily) I have to redirect the output to .csv
    and the .csv should be in some physical directory and I have to upload(ftp) the file from the directory to the website.
    Please help me out.

    Jimmy,
    Make sure that utl_file is properly installed, make sure that the utl_file_dir parameter is set in the init.ora file and that the database has been re-started so that it will take effect, make sure that you have sufficient privileges granted directly, not through roles, including privileges to the file and directory that you are trying to write to, add the exception block below to your procedure to narrow down the source of the exception, then test again. If you still get an error, please post a cut and paste of the exact code that you run and any messages that you received.
    exception
        when utl_file.invalid_path then
            raise_application_error(-20001,
           'INVALID_PATH: File location or filename was invalid.');
        when utl_file.invalid_mode then
            raise_application_error(-20002,
          'INVALID_MODE: The open_mode parameter in FOPEN was
           invalid.');
        when utl_file.invalid_filehandle then
            raise_application_error(-20002,
            'INVALID_FILEHANDLE: The file handle was invalid.');
        when utl_file.invalid_operation then
            raise_application_error(-20003,
           'INVALID_OPERATION: The file could not be opened or
            operated on as requested.');
        when utl_file.read_error then
            raise_application_error(-20004,
           'READ_ERROR: An operating system error occurred during
            the read operation.');
        when utl_file.write_error then
            raise_application_error(-20005,
                'WRITE_ERROR: An operating system error occurred
                 during the write operation.');
        when utl_file.internal_error then
            raise_application_error(-20006,
                'INTERNAL_ERROR: An unspecified error in PL/SQL.');

  • PL/SQL Mail Utility :: Binary/Ascii/Cc/Bcc/FileDump

    I was working on my mail package and decided it was overtly complicated and
    stripped it down to its bare bones. Here is what I came up with. Built on a previous
    foundation of anothers work, I expanded the functionality considerably. You will find all
    the features I think that you will need regarding a mail routine. There is also a nice
    filedump routine included which makes very easy to create flat file dumps that you can
    then attach to your emails. There are a few pre-reqs in using this though :
    - 9iR2+
    - DBA_Directories defined as opposed to utl_file paths
    - Java Virtual Machine. Document can be found in “Note :105472.1 Setup, Configuration,
    and Use of the Java Virtual Machine” on metalink.
    As always, I welcome feedback and suggestions for improvement.
    Barry C
    http://www.myoracleportal.com
    CREATE OR REPLACE PACKAGE mail_tools
    AS
    -- SENDMAIL supports variable message length with/without attachments
    -- QUERY_SERVER allows you to check the status of a mail server to see if it is running
    -- DUMP_FLATFILE allows you to dump flat file data from query submitted
    -- Query Server to verify that the server is up and running.
    -- Connects, Noop Command is executed, Disconnect.
    -- GET_MAIL_ADDRESS is utilized in the SENDMAIL procedure
    -- Table 100-3 SMTP Reply Codes
    -- Reply Code
    -- Meaning
    -- 211 System status, or system help reply
    -- 214 Help message [Information on how to use the receiver or the meaning of a particular non-standard command; this reply is useful only to the human user]
    -- 220 <domain> Service ready
    -- 221 <domain> Service closing transmission channel
    -- 250 Requested mail action okay, completed
    -- 251 User not local; will forward to <forward-path>
    -- 252 OK, pending messages for node <node> started. Cannot VRFY user (e.g., info is not local), but will take message for this user and attempt delivery.
    -- 253 OK, <messages> pending messages for node <node> started
    -- 354 Start mail input; end with <CRLF>.<CRLF>
    -- 355 Octet-offset is the transaction offset
    -- 421 <domain> Service not available, closing transmission channel (This may be a reply to any command if the service knows it must shut down.)
    -- 450 Requested mail action not taken: mailbox unavailable [for example, mailbox busy]
    -- 451 Requested action aborted: local error in processing
    -- 452 Requested action not taken: insufficient system storage
    -- 453 You have no mail.
    -- 454 TLS not available due to temporary reason. Encryption required for requested authentication mechanism.
    -- 458 Unable to queue messages for node <node>
    -- 459 Node <node> not allowed: reason
    -- 500 Syntax error, command unrecognized (This may include errors such as command line too long.)
    -- 501 Syntax error in parameters or arguments
    -- 502 Command not implemented
    -- 503 Bad sequence of commands
    -- 504 Command parameter not implemented
    -- 521 <Machine> does not accept mail.
    -- 530 Must issue a STARTTLS command first. Encryption required for requested authentication mechanism.
    -- 534 Authentication mechanism is too weak.
    -- 538 Encryption required for requested authentication mechanism.
    -- 550 Requested action not taken: mailbox unavailable [for , mailbox not found, no access]
    -- 551 User not local; please try <forward-path>
    -- 552 Requested mail action aborted: exceeded storage allocation
    -- 553 Requested action not taken: mailbox name not allowed [for example, mailbox syntax incorrect]
    -- 554 Transaction failed
    This version allows for a customized seperator value. Using this function will allow you to
    perform fixed width flat files by defining '' for no seperator and then RPAD/LPAD your columns as necessary.
    Or use whatever seperator you wish to use, pipe, space, zeros, etc.
       --  Example : This will generate a flat file which tabbed seperated
    -- DECLARE
    --    l_rows   NUMBER;
    --    l_sql    VARCHAR2(32000);
    -- BEGIN
    --    l_sql := '
    -- SELECT   rpad(hou.NAME,70) udn_desc
    -- ,        rpad(pcak.segment1,6) coid
    -- ,        rpad(pcak.segment2,4) udn
    --     FROM hr_all_organization_units hou, hr.pay_cost_allocation_keyflex pcak
    --    WHERE TRUNC (SYSDATE) BETWEEN hou.date_from
    --                              AND NVL (hou.date_to, ''31-DEC-4712'')
    --      AND pcak.cost_allocation_keyflex_id = hou.cost_allocation_keyflex_id
    -- GROUP BY pcak.segment1, pcak.segment2, hou.NAME
    -- ORDER BY 1, 2, 3
    --    l_rows :=
    --       dump_flatfile
    --          (p_query          =>
    -- ,         p_dir            => 'INTF000_TABLES'
    -- ,         p_filename       => 'test.csv'
    -- ,       p_separator     => '     ' -- <= tabbed 5 spaces between each column
    -- ,       p_max_linesize   => 32000
    -- ,       p_mode       => 'w' -- (w)rite mode or (a)ppend mode
    -- END;
       FUNCTION dump_flatfile (
          p_query                    IN       VARCHAR2
    ,     p_dir                      IN       VARCHAR2
    ,     p_filename                 IN       VARCHAR2
    ,     p_separator                IN       VARCHAR2
    ,     p_headers                  IN       BOOLEAN DEFAULT FALSE
    ,     p_trailing_separator       IN       BOOLEAN DEFAULT FALSE
    ,     p_max_linesize             IN       NUMBER DEFAULT 32000
    ,     p_mode                     IN       VARCHAR2 DEFAULT 'w' )
          RETURN NUMBER;
       FUNCTION get_mail_address (
          addr_list                  IN OUT   VARCHAR2 )
          RETURN VARCHAR2;
       FUNCTION smtp_command (
          command                    IN       VARCHAR2
    ,     ok                         IN       VARCHAR2 DEFAULT '250'
    ,     code                       OUT      VARCHAR2
    ,     DEBUG                               NUMBER DEFAULT 0 )
          RETURN BOOLEAN;
       FUNCTION query_server (
          smtp_server                         VARCHAR2
    ,     smtp_server_port                    PLS_INTEGER DEFAULT 25
    ,     DEBUG                               NUMBER DEFAULT 0 )
          RETURN BOOLEAN;
    This procedure uses the UTL_TCP package to send an email message.
    Up to three file names may be specified as attachments.
    Written: Dave Wotton, 14/6/01 (Cambridge UK)
    This script comes with no warranty or support. You are free to
    modify it as you wish, but please retain an acknowledgement of
    my original authorship.
    Amended: Dave Wotton, 10/7/01
    Now uses the utl_smtp.write_data() method to send the message,
    eliminating the 32Kb message size constraint imposed by the
    utl_smtp.data() procedure.
    Amended: Dave Wotton, 20/7/01
    Increased the v_line variable, which holds the file attachment
    lines from 400 to 1000 bytes. This is the maximum supported
    by RFC2821, The Simple Mail Transfer Protocol specification.
    Amended: Dave Wotton, 24/7/01
    Now inserts a blank line before each MIME boundary line. Some
    mail-clients require this.
    Amended: Dave Wotton, 4/10/01
    Introduced a 'debug' parameter. Defaults to 0. If set to
    non-zero then errors in opening files for attaching are
    reported using dbms_output.put_line.
    Include code to hand MS Windows style pathnames.
    Amended: Barry Chase, 4/29/03
    Added Priority to procedure and also X-Mailer ID.
    Removed restrictions for email size limitation as well.
    Emails are now formatted text messages, meaning you can
    write your message in html format.
    And finally, changed from using UTL_SMTP to UTL_TCP instead.
    Amended: Barry Chase 11/10/2003
    Added session timeout of 4 minutes to prevent hanging server connections
    Amended: Barry Chase 12/04/2003
    Added Date String so that it represents timezone of originating server
    p_datestring
    Amended: Barry Chase 03/01/2004
    Added functionality to support binary attachments and remote attachments.
    Its about 98% complete. Not work perfectly yet. Still trying to figure out
    encoding to base64 or mime. Have a good start on it though.
    04/12/2004
    BCHASE :: Binary Support is fully functional now.
    09/01/2005
    BCHASE :: Modified attachment directories to use DBA_DIRECTORIES instead
    of UTL_DIR in the Oracle initialization file.
    02/22/2006
    BCHASE :: Added variable length message email support (CLOB)
    04/21/2006
    BCHASE :: Expanded functionality to include Cc and Bcc
    Also removed redundant calls from package. The single
    mail_files command will handle flat files and binary files such as zip/pdf/etc.
    SMTP Server and SMTP Server Port are parameters on the sendmail procedure now
    as well.
    Refer to http://home.clara.net/dwotton/dba/oracle_smtp.htm for more
    details on the original source code.
    For information on the enhanced mail_tools package as provided by Barry
    Chase, refer to http://www.myoracleportal.com
       /* Retrieves local binary file from database server.
        * using DBMS_LOB commands and stores into BLOB
        * return BLOB
       FUNCTION get_local_binary_data (
          p_dir                      IN       VARCHAR2
    ,     p_file                     IN       VARCHAR2 )
          RETURN BLOB;
    /* Supports binary attachments and message of variable length. Uses CLOB.*/
    -- DECLARE
    -- t_blob BLOB;
    -- BEGIN
    -- Use the get_local_binary_data to collect your BLOB from the filesystem
    -- or just load from a table where your BLOB is stored at, then just pass
    -- as t_blob on the binaryfile parameter below. Remember to provide an
    -- appropriate filename. Optionally, you can leave filename NULL and pass
    -- the binaryfile parameter as EMPTY_BLOB() to send an email without an
    -- attachment.
    --   t_blob :=
    --    mail_tools.get_local_binary_data
    --                   ( p_dir =>                         'INTF0047_TABLES'
    --,                    p_file =>                        'test_file1.csv' );
    --    mail_tools.sendmail
    --             ( smtp_server =>                   'your.smtp.server'
    -- ,             smtp_server_port =>              25
    -- ,             from_name =>                     'Email Address of Sender'
    -- ,             to_name =>                       'list of TO email addresses separated by commas (,)'
    -- ,             cc_name =>                       'list of CC email addresses separated by commas (,)'
    -- ,             bcc_name =>                      'list of BCC email addresses separated by commas (,)'
    -- ,             subject =>                       'Some brief Subject'
    -- ,             MESSAGE =>                       'Your message goes here. Can include HTML code.'
    -- ,             priority =>                      '1-5 1 being the highest priority and 3 normal priority'
    -- ,             filename =>                      'your.filename.txt or leave NULL'
    -- ,             binaryfile =>                    'your blob is passed here otherwise leave as EMPTY_BLOB()
    -- ,             DEBUG =>                         'Default is DBMS output otherwise pass a 1 to disable );
    -- END;
       PROCEDURE sendmail (
          smtp_server                         VARCHAR2
    ,     smtp_server_port                    PLS_INTEGER DEFAULT 25
    ,     from_name                           VARCHAR2
    ,     to_name                             VARCHAR2
    ,     cc_name                             VARCHAR2 DEFAULT NULL
    ,     bcc_name                            VARCHAR2 DEFAULT NULL
    ,     subject                             VARCHAR2
    ,     MESSAGE                             CLOB
    ,     priority                            PLS_INTEGER DEFAULT NULL
    ,     filename                            VARCHAR2 DEFAULT NULL
    ,     binaryfile                          BLOB DEFAULT EMPTY_BLOB ( )
    ,     DEBUG                               NUMBER DEFAULT 0 );
       v_parm_value                  VARCHAR2 ( 4000 );
       lbok                          BOOLEAN;
       v_smtp_server                 VARCHAR2 ( 50 );
       v_smtp_server_port            NUMBER := 25;
       crlf                          VARCHAR2 ( 10 ) := utl_tcp.crlf;
       conn                          utl_tcp.connection;
       p_debug_marker                PLS_INTEGER := 0;
       rc                            INTEGER;
       p_from_name                   VARCHAR2 ( 100 );
       p_to_name                     VARCHAR2 ( 4000 );
       p_cc_name                     VARCHAR2 ( 4000 );
       p_bcc_name                    VARCHAR2 ( 4000 );
       p_subject                     VARCHAR2 ( 150 );
       tx_timeout                    PLS_INTEGER := 240;
                                                      -- 240 Seconds (4 minutes);
       p_datestring                  VARCHAR2 ( 100 )
          :=    'Date: '
             || TO_CHAR ( SYSDATE, 'MM/DD/RR HH:MI AM' )
             || ' '
             || DBTIMEZONE
             || ' '
             || '(GMT'
             || DBTIMEZONE
             || ')';
       -- Customize the signature that will appear in the email's MIME header.
       -- Useful for versioning.
       mailer_id            CONSTANT VARCHAR2 ( 256 ) := 'Mailer by Oracle UTL_TCP';
       max_base64_line_width CONSTANT PLS_INTEGER := 76 / 4 * 3;
    END;
    CREATE OR REPLACE PACKAGE BODY mail_tools
    IS
       PROCEDURE print_output (
          p_message                  IN       VARCHAR2 )
       IS
       BEGIN
          dbms_output.put_line ( SUBSTR ( p_message
    ,                                     1
    ,                                     250 ));
          IF LENGTH ( p_message ) > 250
          THEN
             dbms_output.put_line ( SUBSTR ( p_message
    ,                                        251
    ,                                        500 ));
          END IF;
          IF LENGTH ( p_message ) > 500
          THEN
             dbms_output.put_line ( SUBSTR ( p_message
    ,                                        501
    ,                                        750 ));
          END IF;
          IF LENGTH ( p_message ) > 750
          THEN
             dbms_output.put_line ( SUBSTR ( p_message
    ,                                        751
    ,                                        1000 ));
          END IF;
       EXCEPTION
          WHEN OTHERS
          THEN
             NULL;               -- Ignore errors... protect buffer overflow's etc.
       END print_output;
       FUNCTION dump_flatfile (
          p_query                    IN       VARCHAR2
    ,     p_dir                      IN       VARCHAR2
    ,     p_filename                 IN       VARCHAR2
    ,     p_separator                IN       VARCHAR2
    ,     p_headers                  IN       BOOLEAN DEFAULT FALSE
    ,     p_trailing_separator       IN       BOOLEAN DEFAULT FALSE
    ,     p_max_linesize             IN       NUMBER DEFAULT 32000
    ,     p_mode                     IN       VARCHAR2 DEFAULT 'w' )
          RETURN NUMBER
       IS
          l_output                      utl_file.file_type;
          l_thecursor                   INTEGER DEFAULT dbms_sql.open_cursor;
          l_columnvalue                 VARCHAR2 ( 4000 );
          l_status                      INTEGER;
          l_colcnt                      NUMBER DEFAULT 0;
          l_cnt                         NUMBER DEFAULT 0;
          l_separator                   VARCHAR2 ( 10 ) DEFAULT '';
          l_line                        LONG;
          l_desctbl                     dbms_sql.desc_tab;
          v_sqlerrm                     VARCHAR2 ( 32000 );
          l_mode                        CHAR ( 1 ) := 'w';
       BEGIN
          IF p_mode NOT IN ( 'w', 'a' )
          THEN
             l_mode := 'w';
          ELSE
             l_mode := p_mode;
          END IF;
          l_output := utl_file.fopen ( p_dir
    ,                                  p_filename
    ,                                  l_mode
    ,                                  p_max_linesize );
          dbms_sql.parse ( l_thecursor
    ,                      p_query
    ,                      dbms_sql.native );
          dbms_sql.describe_columns ( l_thecursor
    ,                                 l_colcnt
    ,                                 l_desctbl );
          FOR i IN 1 .. l_colcnt
          LOOP
             dbms_sql.define_column ( l_thecursor
    ,                                 i
    ,                                 l_columnvalue
    ,                                 4000 );
             IF ( l_desctbl ( i ).col_type = 2 )                   /* number type */
             THEN
                l_desctbl ( i ).col_max_len := l_desctbl ( i ).col_precision + 2;
             ELSIF ( l_desctbl ( i ).col_type = 12 )                 /* date type */
             THEN
    /* length of my date format */
                l_desctbl ( i ).col_max_len := 20;
             ELSIF ( l_desctbl ( i ).col_type = 8 )                  /* LONG type */
             THEN
                l_desctbl ( i ).col_max_len := 2000;
             END IF;
             IF p_headers
             THEN
                utl_file.put ( l_output, l_separator || l_desctbl ( i ).col_name );
                l_separator := p_separator;
             END IF;
          END LOOP;
          IF p_trailing_separator
          THEN
             utl_file.put ( l_output, l_separator );
          END IF;
          IF p_headers
          THEN
             utl_file.new_line ( l_output );
          END IF;
          l_status := dbms_sql.EXECUTE ( l_thecursor );
          LOOP
             EXIT WHEN ( dbms_sql.fetch_rows ( l_thecursor ) <= 0 );
             l_line := NULL;
             l_separator := '';
             FOR i IN 1 .. l_colcnt
             LOOP
                dbms_sql.COLUMN_VALUE ( l_thecursor
    ,                                   i
    ,                                   l_columnvalue );
                IF NVL ( INSTR ( l_columnvalue, ',' ), 0 ) = 0
                THEN
                   NULL;
                ELSE
                   l_columnvalue := '"' || l_columnvalue || '"';
                END IF;
                utl_file.put ( l_output, l_separator || l_columnvalue );
                l_separator := p_separator;
             END LOOP;
             IF p_trailing_separator
             THEN
                utl_file.put ( l_output, l_separator );
             END IF;
             utl_file.new_line ( l_output );
             l_cnt := l_cnt + 1;
          END LOOP;
          dbms_sql.close_cursor ( l_thecursor );
          utl_file.fclose ( l_output );
          RETURN l_cnt;
       EXCEPTION
          WHEN NO_DATA_FOUND
          THEN
             dbms_output.put_line ( 'NO_DATA_FOUND' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN utl_file.invalid_path
          THEN
             dbms_output.put_line ( 'UTL_FILE.INVALID_PATH' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN utl_file.read_error
          THEN
             dbms_output.put_line ( 'UTL_FILE.READ_ERROR' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN utl_file.write_error
          THEN
             dbms_output.put_line ( 'UTL_FILE.WRITE_ERROR' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN utl_file.invalid_mode
          THEN
             dbms_output.put_line ( 'UTL_FILE.INVALID_MODE' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN utl_file.invalid_filehandle
          THEN
             dbms_output.put_line ( 'UTL_FILE.INVALID_FILEHANDLE' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN utl_file.invalid_operation
          THEN
             dbms_output.put_line ( 'UTL_FILE.INVALID_OPERATION' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN utl_file.internal_error
          THEN
             dbms_output.put_line ( 'UTL_FILE.INTERNAL_ERROR' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN utl_file.invalid_maxlinesize
          THEN
             dbms_output.put_line ( 'UTL_FILE.INVALID_MAXLINESIZE' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN VALUE_ERROR
          THEN
             dbms_output.put_line ( 'UTL_FILE.VALUE_ERROR' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
          WHEN OTHERS
          THEN
             hum_do.default_exception ( 'ERROR in dump_csv : ' );
             utl_file.fclose ( l_output );
             RETURN l_cnt;
       END dump_flatfile;
       -- 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_mail_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;
       FUNCTION smtp_command (
          command                    IN       VARCHAR2
    ,     ok                         IN       VARCHAR2 DEFAULT '250'
    ,     code                       OUT      VARCHAR2
    ,     DEBUG                               NUMBER DEFAULT 0 )
          RETURN BOOLEAN
       IS
          response                      VARCHAR2 ( 3 );
          p_output_message              VARCHAR2 ( 255 );
          len                           PLS_INTEGER;
          PRAGMA AUTONOMOUS_TRANSACTION;
       BEGIN
          len := utl_tcp.write_line ( conn, command );
          p_output_message := SUBSTR ( utl_tcp.get_line ( conn, TRUE )
    ,                                  1
    ,                                  255 );
          response := SUBSTR ( p_output_message
    ,                          1
    ,                          3 );
          p_output_message :=
                             SUBSTR ( command || ' - ' || p_output_message
    ,                                 1
    ,                                 255 );
          IF DEBUG = 1
          THEN                                                          -- No Output
             NULL;
          ELSE                                          -- Then DBMS_OUTPUT messages
             print_output ( p_output_message );
          END IF;
          IF ( response <> ok )
          THEN
             code := response;
             RETURN FALSE;
          ELSE
             code := response;
             RETURN TRUE;
          END IF;
       EXCEPTION
          WHEN OTHERS
          THEN
             p_output_message := SQLCODE || ' - ' || SQLERRM;
             code := p_output_message;
             RETURN FALSE;
       END smtp_command;
       FUNCTION query_server (
          smtp_server                         VARCHAR2
    ,     smtp_server_port                    PLS_INTEGER DEFAULT 25
    ,     DEBUG                               NUMBER DEFAULT 0 )
          RETURN BOOLEAN
       IS
          p_output_message              VARCHAR2 ( 255 );
          PRAGMA AUTONOMOUS_TRANSACTION;
          err_noop                      EXCEPTION;    -- SMTP code 250 not received
          err_server_reject             EXCEPTION;
       -- SMTP code 421 means rejected
       BEGIN
          v_smtp_server := smtp_server;
          v_smtp_server_port := smtp_server_port;
    -- Open the SMTP connection ...
          conn :=
             utl_tcp.open_connection ( remote_host =>                   v_smtp_server
    ,                                  remote_port =>                   v_smtp_server_port
    ,                                  tx_timeout =>                    tx_timeout );
          ----- OPEN SMTP PORT CONNECTION
          rc := utl_tcp.write_line ( conn, 'HELO ' || v_smtp_server );
                -- This will return a 250 OK response if your connection is valid
    -- Initial handshaking ...
          ----- PERFORMS HANDSHAKING WITH SMTP SERVER
          p_output_message := utl_tcp.get_line ( conn, TRUE );
          IF DEBUG = 1
          THEN                                                          -- No Output
             NULL;
          ELSE                                          -- Then DBMS_OUTPUT messages
             print_output ( p_output_message );
          END IF;
          IF SUBSTR ( p_output_message
    ,                 1
    ,                 3 ) = '421'
          THEN
             RAISE err_server_reject;
          END IF;
          -- NOOP THE SERVER
          rc := utl_tcp.write_line ( conn, 'NOOP' );
                -- This will return a 250 OK response if your connection is valid
    -- Initial handshaking ...
          ----- PERFORMS NOOP WITH SMTP SERVER
          p_output_message := utl_tcp.get_line ( conn, TRUE );
          IF DEBUG = 1
          THEN                                                          -- No Output
             NULL;
          ELSE                                          -- Then DBMS_OUTPUT messages
             print_output ( p_output_message );
          END IF;
          IF SUBSTR ( p_output_message
    ,                 1
    ,                 3 ) <> '250'
          THEN
             RAISE err_noop;
          END IF;
          rc := utl_tcp.write_line ( conn, 'QUIT' );
          ----- ENDS EMAIL TRANSACTION
          BEGIN
             FOR i_idx IN 1 .. 100
             LOOP
                p_output_message := utl_tcp.get_line ( conn, TRUE );
                IF DEBUG = 1
                THEN                                                   -- No Output
                   NULL;
                ELSE                                    -- Then DBMS_OUTPUT messages
                   print_output ( p_output_message );
                END IF;
             END LOOP;
          EXCEPTION
             WHEN OTHERS
             THEN
                IF DEBUG = 1
                THEN                                                   -- No Output
                   NULL;
                ELSE                                    -- Then DBMS_OUTPUT messages
                   print_output ( p_output_message );
                END IF;
          END;
          utl_tcp.close_connection ( conn );        ----- CLOSE SMTP PORT CONNECTION
          RETURN TRUE;
       EXCEPTION
          WHEN err_server_reject
          THEN
             print_output (    'ERROR -'
                            || ' Server Rejected Connection ::'
                            || ' SERVER_MSG := '
                            || p_output_message );
             RETURN FALSE;
          WHEN err_noop
          THEN
             print_output (    'ERROR -'
                            || ' NOOP Check Failed ::'
                            || ' SERVER_MSG := '
                            || p_output_message );
             utl_tcp.close_connection ( conn );     ----- CLOSE SMTP PORT CONNECTION
             RETURN FALSE;
       END query_server;
       FUNCTION get_local_binary_data (
          p_dir                      IN       VARCHAR2
    ,     p_file                     IN       VARCHAR2 )
          RETURN BLOB
       IS
          l_bfile                       BFILE;
          l_data                        BLOB;
          l_dbdir                       VARCHAR2 ( 100 ) := p_dir;
       BEGIN
          dbms_lob.createtemporary ( lob_loc =>                       l_data
    ,                                CACHE =>                         TRUE
    ,                                dur =>                           dbms_lob.CALL );
          l_bfile := BFILENAME ( l_dbdir, p_file );
          dbms_lob.fileopen ( l_bfile, dbms_lob.file_readonly );
          dbms_lob.loadfromfile ( l_data
    ,                             l_bfile
    ,                             dbms_lob.getlength ( l_bfile ));
          dbms_lob.fileclose ( l_bfile );
          RETURN l_data;
       EXCEPTION
          WHEN OTHERS
          THEN
             print_output (    'Error during GET_LOCAL_BINARY_DATA :: '
                            || SQLCODE
                            || ' - '
                            || SQLERRM );
             dbms_lob.fileclose ( l_bfile );
             RAISE;
       END get_local_binary_data;
       PROCEDURE attach_base64 (
          conn                       IN OUT NOCOPY utl_tcp.connection
    ,     DATA                       IN       BLOB )
       IS
          i                             PLS_INTEGER;
          len                           PLS_INTEGER;
          l_result                      PLS_INTEGER;
          l_buffer                      RAW ( 32767 );
          l_pos                         INTEGER := 1;
          l_blob_len                    INTEGER;
          l_amount                      BINARY_INTEGER := 32767;
          req                           utl_http.req;
          resp                          utl_http.resp;
          pdata                         RAW ( 200 );
       BEGIN
          -- Split the Base64-encoded attachment into multiple lines
          -- 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 MAX_BASE64_LINE_WIDTH
          -- (76 / 4 * 3 = 57) is the maximum length (in bytes) of each chunk
          -- of data before encoding.
          l_blob_len := dbms_lob.getlength ( DATA );
          WHILE l_pos < l_blob_len
          LOOP
             l_amount := max_base64_line_width;
             dbms_lob.READ ( DATA
    ,                        l_amount
    ,                        l_pos
    ,                        l_buffer );
             rc := utl_tcp.write_raw ( conn, utl_encode.base64_encode ( l_buffer ));
             utl_tcp.FLUSH ( conn );
             l_pos := l_pos + max_base64_line_width;
             rc := utl_tcp.write_line ( conn, crlf );
          END LOOP;
       END attach_base64;
       PROCEDURE sendmail (
          smtp_server                         VARCHAR2
    ,     smtp_server_port                    PLS_INTEGER DEFAULT 25
    ,     from_name                           VARCHAR2
    ,     to_name                             VARCHAR2
    ,     cc_name                             VARCHAR2 DEFAULT NULL
    ,     bcc_name                            VARCHAR2 DEFAULT NULL
    ,     subject                             VARCHAR2
    ,     MESSAGE                             CLOB
    ,     priority                            PLS_INTEGER DEFAULT NULL
    ,     filename                            VARCHAR2 DEFAULT NULL
    ,     binaryfile                          BLOB DEFAULT EMPTY_BLOB ( )
    ,     DEBUG                               NUMBER DEFAULT 0 )
       IS
          pos                           PLS_INTEGER := 1;
          bytes_o_data         CONSTANT PLS_INTEGER := 32767;
          offset                        PLS_INTEGER := bytes_o_data;
          msg_length           CONSTANT PLS_INTEGER
                                                  := dbms_lob.getlength ( MESSAGE );
          v_line                        VARCHAR2 ( 32767 );
          i                             BINARY_INTEGER;
          v_slash_pos                   NUMBER;
          my_recipients                 VARCHAR2 ( 32767 );
          p_recipient_count             PLS_INTEGER := 0;
          p_output_message              VARCHAR2 ( 2000 );
          PRAGMA AUTONOMOUS_TRANSACTION;
          err_server_reject             EXCEPTION;
          -- SMTP code 421 means rejected
          err_message_send              EXCEPTION;         -- SMTP code must be 250
          err_end_of_input              EXCEPTION;
       -- Used to signify last line of input retrieved
          l_result                      PLS_INTEGER;
          l_buffer_b                    RAW ( 32767 );
          l_amount                      BINARY_INTEGER := 32767;
          l_pos                         INTEGER := 1;
          l_blob_len                    INTEGER;
          l_blob                        BLOB;
          g_debug                       BOOLEAN := TRUE;
          i_base64                      PLS_INTEGER;
          len_base64                    PLS_INTEGER;
       BEGIN
          v_smtp_server := smtp_server;
          v_smtp_server_port := smtp_server_port;
          l_blob := binaryfile;
    -- Open the SMTP connection ...
          conn :=
             utl_tcp.open_connection ( remote_host =>                   v_smtp_server
    ,                                  remote_port =>                   v_smtp_server_port
    ,                                  tx_timeout =>                    tx_timeout );
          ----- OPEN SMTP PORT CONNECTION
          rc := utl_tcp.write_line ( conn, 'HELO ' || v_smtp_server );
    -- Initial handshaking ...
          ----- PERFORMS HANDSHAKING WITH SMTP SERVER
          p_output_message := utl_tcp.get_line ( conn, TRUE );
          IF DEBUG = 1
          THEN                                                          -- No Output
             NULL;
          ELSE                                          -- Then DBMS_OUTPUT messages
             print_output ( p_output_message );
          END IF;
          IF SUBSTR ( p_output_message
    ,                 1
    ,                 3 ) = '421'
          THEN
             RAISE err_server_reject;
          ELSE
    --      DBMS_OUTPUT.put_line (UTL_TCP.get_line (conn, TRUE));
             rc := utl_tcp.write_line ( conn, 'MAIL FROM: ' || from_name );
             ----- MBOX SENDING THE EMAIL
             p_output_message := utl_tcp.get_line ( conn, TRUE );
             IF DEBUG = 1
             THEN                                                      -- No Output
                NULL;
             ELSE                                       -- Then DBMS_OUTPUT messages
                print_output ( p_output_message );
             END IF;
    --      DBMS_OUTPUT.put_line (UTL_TCP.get_line (conn, TRUE));
             --      rc := UTL_TCP.write_line (conn, 'RCPT TO: ' || to_name);
             -- Specify recipient(s) of the email.
             my_recipients := to_name;
             WHILE ( my_recipients IS NOT NULL )
             LOOP
                BEGIN
                   rc :=
                      utl_tcp.write_line ( conn
    ,                                         'RCPT TO: '
                                           || get_mail_address ( my_recipients ));
                   p_recipient_count := p_recipient_count + 1;
                END;
             END LOOP;
    --         DBMS_OUTPUT.put_line ('RCPT TO: COUNT ' || p_recipient_count);
             ----- MBOX RECV THE EMAIL
             p_output_message := utl_tcp.get_line ( conn, TRUE );
             IF DEBUG = 1
             THEN                                                       -- No Output
                NULL;
             ELSE                                       -- Then DBMS_OUTPUT messages
                print_output ( p_output_message );
             END IF;
    --      DBMS_OUTPUT.put_line (UTL_TCP.get_line (conn, TRUE));
             --      rc := UTL_TCP.write_line (conn, 'RCPT TO: ' || cc_name);
             -- Specify cc recipient(s) of the email.
             my_recipients := cc_name;
             WHILE ( my_recipients IS NOT NULL )
             LOOP
                BEGIN
                   rc :=
                      utl_tcp.write_line ( conn
    ,                                         'RCPT TO: '
                                           || get_mail_address ( my_recipients ));
                   p_recipient_count := p_recipient_count + 1;
                END;
             END LOOP;
    --         DBMS_OUTPUT.put_line ('RCPT TO: COUNT ' || p_recipient_count);
             ----- MBOX RECV THE EMAIL
             p_output_message := utl_tcp.get_line ( conn, TRUE );
             IF DEBUG = 1
             THEN                                                       -- No Output
                NULL;
             ELSE                                       -- Then DBMS_OUTPUT messages
                print_output ( p_output_message );
             END IF;
    --      DBMS_OUTPUT.put_line (UTL_TCP.get_line (conn, TRUE));
             --      rc := UTL_TCP.write_line (conn, 'RCPT TO: ' || bcc_name);
             -- Specify bcc recipient(s) of the email.
             my_recipients := bcc_name;
             WHILE ( my_recipients IS NOT NULL )
             LOOP
                BEGIN
                   rc :=
                      utl_tcp.write_line ( conn
    ,                                         'RCPT TO: '
                                           || get_mail_address ( my_recipients ));
                   p_recipient_count := p_recipient_count + 1;
                END;
             END LOOP;
    --         DBMS_OUTPUT.put_line ('RCPT TO: COUNT ' || p_recipient_count);
             ----- MBOX RECV THE EMAIL
             p_output_message := utl_tcp.get_line ( conn, TRUE );
             IF DEBUG = 1
             THEN                                                       -- No Output
                NULL;
             ELSE                                       -- Then DBMS_OUTPUT messages
                print_output ( p_output_message );
             END IF;
    --      DBMS_OUTPUT.put_line (UTL_TCP.get_line (conn, TRUE));
             rc := utl_tcp.write_line ( conn, 'DATA' );
             ----- EMAIL MSG BODY START
             p_output_message := utl_tcp.get_line ( conn, TRUE );
             IF DEBUG = 1
             THEN                                                       -- No Output
                NULL;
             ELSE                                       -- Then DBMS_OUTPUT messages
                print_output ( p_output_message );
             END IF;
    --      DBMS_OUTPUT.put_line (UTL_TCP.get_line (conn, TRUE));
    -- build the start of the mail message ...
             rc := utl_tcp.write_line ( conn, p_datestring );
             rc := utl_tcp.write_line ( conn, 'From: ' || from_name );
             rc := utl_tcp.write_line ( conn, 'Subject: ' || subject );
             rc := utl_tcp.write_line ( conn, 'To: ' || to_name );
             IF cc_name IS NOT NULL
             THEN
                rc := utl_tcp.write_line ( conn, 'Cc: ' || cc_name );
             END IF;
             IF bcc_name IS NOT NULL
             THEN
                rc := utl_tcp.write_line ( conn, 'Bcc: ' || bcc_name );
             END IF;
             rc := utl_tcp.write_line ( conn, 'Mime-Version: 1.0' );
                  -- Set priority:
             --   High      Normal       Low
             --   1     2     3     4     5
             IF ( priority IS NOT NULL )
             THEN
                rc := utl_tcp.write_line ( conn, 'X-Priority: ' || priority );
             END IF;
             rc := utl_tcp.write_line ( conn, 'X-Mailer: ' || mailer_id );
             rc :=
                utl_tcp.write_line
                   ( conn
    ,                'Content-Type: multipart/mixed; boundary="=_mixed 0052287A85256E75_="' );
             rc := utl_tcp.write_line ( conn, '' );
             rc :=
                utl_tcp.write_line
                   ( conn
    ,                'This is a Mime message, which your current mail reader may not' );
             rc :=
                utl_tcp.write_line
                   ( conn
    ,                'understand. Parts of the message will appear as text. If the remainder' );
             rc :=
                utl_tcp.write_line
                   ( conn
    ,                'appears as random characters in the message body, instead of as' );
             rc :=
                utl_tcp.write_line
                   ( conn
    ,                'attachments, then you''ll have to extract these parts and decode them' );
             rc := utl_tcp.write_line ( conn, 'manually.' );
             rc := utl_tcp.write_line ( conn, '' );
             rc := utl_tcp.write_line ( conn, '--=_mixed 0052287A85256E75_=' );
             rc :=
                utl_tcp.write_line ( conn
    ,                                'Content-Type: text/html; charset=8859-1' );
             rc := utl_tcp.write_line ( conn, '' );
             rc := utl_tcp.write_line ( conn, '<html>' );
             rc := utl_tcp.write_line ( conn, '<head>' );
             rc :=
                utl_tcp.write_line
                   ( conn
    ,                '<meta http-equiv="Content-Type" content="text/html;charset=8859-1">' );
             rc := utl_tcp.write_line ( conn, '<title>' );
             rc := utl_tcp.write_line ( conn, subject );
             rc := utl_tcp.write_line ( conn, '</title>' );
             rc := utl_tcp.write_line ( conn, '</head>' );
             rc := utl_tcp.write_line ( conn, '<body>' );
             WHILE pos < msg_length
             LOOP
                rc :=
                   utl_tcp.write_line ( conn
    ,                                   dbms_lob.SUBSTR ( MESSAGE
    ,                                                     offset
    ,                                                     pos ));
                pos := pos + offset;
                offset := LEAST ( bytes_o_data, msg_length - offset );
             END LOOP;
             rc := utl_tcp.write_line ( conn, '<BR><BR>' );
             rc := utl_tcp.write_line ( conn, '</body></html>' );
             rc := utl_tcp.write_line ( conn, '' );
             rc := utl_tcp.write_line ( conn, crlf );
    -- Append the file BLOB  ...
                -- If the filename has been supplied ... it will fail if the BLOB is empty
             IF filename IS NOT NULL
             THEN
                BEGIN
                   -- generate the MIME boundary line ...
                   rc :=
                        utl_tcp.write_line ( conn, '--=_mixed 0052287A85256E75_=' );
                   rc :=
                      utl_tcp.write_line
                              ( conn
    ,                              'Content-Type: application/octet-stream; name="'
                                || filename
                                || '"' );
                   rc :=
                      utl_tcp.write_line
                                  ( conn
    ,                                  'Content-Disposition: attachment; filename="'
                                    || filename
                                    || '"' );
                   rc :=
                      utl_tcp.write_line ( conn
    ,                                      'Content-Transfer-Encoding: base64' );
                   rc := utl_tcp.write_line ( conn, '' );
                   rc := utl_tcp.write_line ( conn, '' );
                   -- and append the file contents to the end of the message ...
                   -- Go get the file and the loop through blob and attach data
                   -- and append the file contents to the end of the message ...
                   attach_base64 ( conn =>                          conn
    ,                              DATA =>                          l_blob );
                EXCEPTION
                   WHEN OTHERS
                   THEN
                      p_output_message :=
                            'Error in attaching file '
                         || filename
                         || ' :: '
                         || SQLCODE
                         || ' - '
                         || SQLERRM;
                      IF DEBUG = 1
                      THEN                                              -- No Output
                         NULL;
                      ELSE                              -- Then DBMS_OUTPUT messages
                         print_output ( p_output_message );
                      END IF;
                      RAISE err_message_send;
                END;
             END IF;
             rc := utl_tcp.write_line ( conn, '' );
             -- append the final boundary line ...
             rc := utl_tcp.write_line ( conn, '' );
             rc := utl_tcp.write_line ( conn, '--=_mixed 0052287A85256E75_=--' );
             rc := utl_tcp.write_line ( conn, '' );
             -- and close the SMTP connection  ...
             rc := utl_tcp.write_line ( conn, '.' );
             ----- EMAIL MESSAGE BODY END
             p_output_message := utl_tcp.get_line ( conn, TRUE );
             IF DEBUG = 1
             THEN                                                       -- No Output
                NULL;
             ELSE                                       -- Then DBMS_OUTPUT messages
                print_output ( p_output_message );
             END IF;
    --      DBMS_OUTPUT.put_line (UTL_TCP.get_line (conn, TRUE));
             rc := utl_tcp.write_line ( conn, 'QUIT' );
             ----- ENDS EMAIL TRANSACTION
             p_output_message := utl_tcp.get_line ( conn, TRUE );
             -- Capture '.' Message sent dialog
             IF DEBUG = 1
             THEN                                                       -- No Output
                NULL;
             ELSE                                       -- Then DBMS_OUTPUT messages
                print_output ( p_output_message );
             END IF;
             BEGIN
                FOR i_idx IN 1 .. 100
                LOOP
                   p_output_message := utl_tcp.get_line ( conn, TRUE );
                   IF DEBUG = 1
                   THEN                                                -- No Output
                      NULL;
                   ELSE                                 -- Then DBMS_OUTPUT messages
                      print_output ( p_output_message );
                   END IF;
                END LOOP;
             EXCEPTION
                WHEN OTHERS
                THEN
                   IF DEBUG = 1
                   THEN                                                -- No Output
                      NULL;
                   ELSE                                 -- Then DBMS_OUTPUT messages
                      print_output ( p_output_message );
                   END IF;
             END;
          END IF;                                               -- err_server_reject
          utl_tcp.close_connection ( conn );        ----- CLOSE SMTP PORT CONNECTION
       EXCEPTION
          WHEN err_message_send
          THEN
             print_output (    CHR ( 10 )
                            || CHR ( 10 )
                            || 'ERROR -'
                            || ' Message was not submitted for delivery' );
             print_output ( ' [FROM_NAME := ' || from_name || '] ' );
             print_output ( ' [TO_NAME := ' || to_name || '] ' );
             print_output ( ' [CC_NAME := ' || cc_name || '] ' );
             print_output ( ' [BCC_NAME := ' || bcc_name || '] ' );
             print_output ( ' [SUBJECT := ' || subject || '] ' );
             print_output ( ' SERVER_MSG := ' || p_output_message );
             utl_tcp.close_connection ( conn );     ----- CLOSE SMTP PORT CONNECTION
          WHEN err_server_reject
          THEN
             print_output (    CHR ( 10 )
                            || CHR ( 10 )
                            || 'ERROR -'
                            || ' Server Rejected Email' );
             print_output ( ' [FROM_NAME := ' || from_name || '] ' );
             print_output ( ' [TO_NAME := ' || to_name || '] ' );
             print_output ( ' [CC_NAME := ' || cc_name || '] ' );
             print_output ( ' [BCC_NAME := ' || bcc_name || '] ' );
             print_output ( ' [SUBJECT := ' || subject || '] ' );
             print_output ( ' SERVER_MSG := ' || p_output_message );
          WHEN OTHERS
          THEN
             print_output (    CHR ( 10 )
                            || CHR ( 10 )
                            || 'ERROR :: '
                            || SQLCODE
                            || ' - '
                            || SQLERRM );
             print_output ( ' [FROM_NAME := ' || from_name || '] ' );
             print_output ( ' [TO_NAME := ' || to_name || '] ' );
             print_output ( ' [CC_NAME := ' || cc_name || '] ' );
             print_output ( ' [BCC_NAME := ' || bcc_name || '] ' );
             print_output ( ' [SUBJECT := ' || subject || '] ' );
             print_output ( ' SERVER_MSG := ' || p_output_message );
       END sendmail;
    END;
    /

    Perhaps your new SMTP server requires a more secure form of authentication than AUTH LOGIN. If you telnet to this new SMTP server on port 25 you should be issue the HELO or EHLO command to find out what AUTH mechanisms the server supports. You could then alter your code to use one of the supported authentication mechanisms.

  • Start Routine code error of Perform routine 9998

    Hi,
    I have install standard and then migrate to 7.0 all the flow of modeling.
    but after loading data in PSA, while activation i will found following problem (error in routine).
    In PERFORM or CALL FUNCTION ROUTINE_9998, the actual parameter SOURCE_PACKAGE is incompatible with the formal parameter DATA_PACKAGE.
    please suggest me.

    PROGRAM trans_routine.
          CLASS routine DEFINITION
    CLASS lcl_transform DEFINITION.
      PUBLIC SECTION.
    Attributs
        DATA:
          p_check_master_data_exist
                TYPE RSODSOCHECKONLY READ-ONLY,
    *-    Instance for getting request runtime attributs;
        Available information: Refer to methods of
        interface 'if_rsbk_request_admintab_view'
          p_r_request
                TYPE REF TO if_rsbk_request_admintab_view READ-ONLY.
      PRIVATE SECTION.
        TYPE-POOLS: rsd, rstr.
      Rule specific types
        TYPES:
          BEGIN OF tys_SC_1,
         InfoObject: 0MPOINT Measuring point.
            MPOINT           TYPE /BI0/OIMPOINT,
         InfoObject: 0MDOC Measurement Document.
            MDOC           TYPE /BI0/OIMDOC,
         InfoObject: 0MPOBJ Object Number of Measuring Point Object.
            MPOBJ           TYPE /BI0/OIMPOBJ,
         InfoObject: 0MPTYP Type of Measuring Point.
            MPTYP           TYPE /BI0/OIMPTYP,
         InfoObject: 0PSORT Position Number of Measuring Point in Object (
    *Sort Field).
            PSORT           TYPE /BI0/OIPSORT,
         InfoObject: 0ASSEMBLY Assembly.
            ASSEMBLY           TYPE /BI0/OIASSEMBLY,
         InfoObject: 0ATINN Internal Characteristic Number.
            ATINN           TYPE /BI0/OIATINN,
         InfoObject: 0MDATE Date of Measurement.
            MDATE           TYPE /BI0/OIMDATE,
         InfoObject: 0TIME Time.
            TIME           TYPE /BI0/OITIME,
         InfoObject: 0DESIRSI Target Value for Measuring Point in SI Unit.
            DESIRSI           TYPE /BI0/OIDESIRSI,
         InfoObject: 0TVIND Target Value for Measuring Point Is Defined.
            TVIND           TYPE /BI0/OITVIND,
         InfoObject: 0MRMINI Lower Measurement Area Limit Is Defined.
            MRMINI           TYPE /BI0/OIMRMINI,
         InfoObject: 0MRMINSI Lower Meas. Limit or Min. Total Counter Read
    *ing in SI Unit.
            MRMINSI           TYPE /BI0/OIMRMINSI,
         InfoObject: 0MRMAXI Upper Measurement Area Limit Is Defined.
            MRMAXI           TYPE /BI0/OIMRMAXI,
         InfoObject: 0SIUNIT SI unit.
            SIUNIT           TYPE /BI0/OISIUNIT,
         InfoObject: 0CJUMPSI Counter Overflow Reading in SI Unit.
            CJUMPSI           TYPE /BI0/OICJUMPSI,
         InfoObject: 0PYEARSI Annual Performance in SI Unit.
            PYEARSI           TYPE /BI0/OIPYEARSI,
         InfoObject: 0CREATED_BY Created By.
            CREATED_BY           TYPE /BI0/OICREATED_BY,
         InfoObject: 0READSI Measured Value/Total Counter Reading in SI Un
    *it.
            READSI           TYPE /BI0/OIREADSI,
         InfoObject: 0READEU Measured Value in Document Entry Unit.
            READEU           TYPE /BI0/OIREADEU,
         InfoObject: 0RECDU Unit of Measurement for Document Entry.
            RECDU           TYPE /BI0/OIRECDU,
         InfoObject: 0CNTRRSI Counter Reading in SI Unit.
            CNTRRSI           TYPE /BI0/OICNTRRSI,
         InfoObject: 0CDIFFSI Counter Reading Difference in SI Unit.
            CDIFFSI           TYPE /BI0/OICDIFFSI,
         InfoObject: 0CAT_TYPE Catalog.
            CAT_TYPE           TYPE /BI0/OICAT_TYPE,
         InfoObject: 0CAT_GROUP Code group.
            CAT_GROUP           TYPE /BI0/OICAT_GROUP,
         InfoObject: 0FI_STATUS Processing Status.
            FI_STATUS           TYPE /BI0/OIFI_STATUS,
         InfoObject: 0DIM_ID Dimension Key.
            DIM_ID           TYPE /BI0/OIDIM_ID,
         InfoObject: 0CNTIND Measuring Point is Counter.
            CNTIND           TYPE /BI0/OICNTIND,
         InfoObject: 0EQUIPMENT Equipment Number.
            EQUIPMENT           TYPE /BI0/OIEQUIPMENT,
         InfoObject: 0FUNCT_LOC Functional Location.
            FUNCT_LOC           TYPE /BI0/OIFUNCT_LOC,
         InfoObject: 0CAT_CODE Code.
            CAT_CODE           TYPE /BI0/OICAT_CODE,
         InfoObject: 0MRMAXSI Upper Meas. Limit or Max. Total Counter Read
    *ing in SI Unit.
            MRMAXSI           TYPE /BI0/OIMRMAXSI,
         InfoObject: 0DOCAF Measurement Document Included for Associated T
    *ask.
            DOCAF           TYPE /BI0/OIDOCAF,
         InfoObject: 0RECORDMODE BW Delta Process: Update Mode.
            RECORDMODE           TYPE RODMUPDMOD,
         InfoObject: ZSTEXT Object Number Text.
            /BIC/ZSTEXT           TYPE /BIC/OIZSTEXT,
         Field: RECORD.
            RECORD           TYPE RSARECORD,
          END   OF tys_SC_1.
        TYPES:
          tyt_SC_1        TYPE STANDARD TABLE OF tys_SC_1
                            WITH NON-UNIQUE DEFAULT KEY.
    $$ begin of global - insert your declaration only below this line  -
        ... "insert your code here
    $$ end of global - insert your declaration only before this line   -
        METHODS
          start_routine
            IMPORTING
              request                  type rsrequest
              datapackid               type rsdatapid
            EXPORTING
              monitor                  type rstr_ty_t_monitors
            CHANGING
              SOURCE_PACKAGE              type tyt_SC_1
            RAISING
              cx_rsrout_abort.
        METHODS
          inverse_start_routine
            IMPORTING
              i_th_fields_outbound         TYPE rstran_t_field_inv
              i_r_selset_outbound          TYPE REF TO cl_rsmds_set
              i_is_main_selection          TYPE rs_bool
              i_r_selset_outbound_complete TYPE REF TO cl_rsmds_set
              i_r_universe_inbound         TYPE REF TO cl_rsmds_universe
            CHANGING
              c_th_fields_inbound          TYPE rstran_t_field_inv
              c_r_selset_inbound           TYPE REF TO cl_rsmds_set
              c_exact                      TYPE rs_bool.
    ENDCLASS.                    "routine DEFINITION
    $$ begin of 2nd part global - insert your code only below this line  *
    TYPES:
      BEGIN OF tys_SC_1_full,
         InfoObject: 0MPOINT Measuring point.
        MPOINT           TYPE /BI0/OIMPOINT,
         InfoObject: 0MDOC Measurement Document.
        MDOC           TYPE /BI0/OIMDOC,
         InfoObject: 0MPOBJ Object Number of Measuring Point Object.
        MPOBJ           TYPE /BI0/OIMPOBJ,
         InfoObject: 0MPTYP Type of Measuring Point.
        MPTYP           TYPE /BI0/OIMPTYP,
         InfoObject: 0PSORT Position Number of Measuring Point in Object (
    *Sort Field).
        PSORT           TYPE /BI0/OIPSORT,
         InfoObject: 0ASSEMBLY Assembly.
        ASSEMBLY           TYPE /BI0/OIASSEMBLY,
         InfoObject: 0ATINN Internal Characteristic Number.
        ATINN           TYPE /BI0/OIATINN,
         InfoObject: 0MDATE Date of Measurement.
        MDATE           TYPE /BI0/OIMDATE,
         InfoObject: 0TIME Time.
        TIME           TYPE /BI0/OITIME,
         InfoObject: 0DESIRSI Target Value for Measuring Point in SI Unit.
        DESIRSI           TYPE /BI0/OIDESIRSI,
         InfoObject: 0TVIND Target Value for Measuring Point Is Defined.
        TVIND           TYPE /BI0/OITVIND,
         InfoObject: 0MRMINI Lower Measurement Area Limit Is Defined.
        MRMINI           TYPE /BI0/OIMRMINI,
         InfoObject: 0MRMINSI Lower Meas. Limit or Min. Total Counter Read
    *ing in SI Unit.
        MRMINSI           TYPE /BI0/OIMRMINSI,
         InfoObject: 0MRMAXI Upper Measurement Area Limit Is Defined.
        MRMAXI           TYPE /BI0/OIMRMAXI,
         InfoObject: 0SIUNIT SI unit.
        SIUNIT           TYPE /BI0/OISIUNIT,
         InfoObject: 0CJUMPSI Counter Overflow Reading in SI Unit.
        CJUMPSI           TYPE /BI0/OICJUMPSI,
         InfoObject: 0PYEARSI Annual Performance in SI Unit.
        PYEARSI           TYPE /BI0/OIPYEARSI,
         InfoObject: 0CREATED_BY Created By.
        CREATED_BY           TYPE /BI0/OICREATED_BY,
         InfoObject: 0READSI Measured Value/Total Counter Reading in SI Un
    *it.
        READSI           TYPE /BI0/OIREADSI,
         InfoObject: 0READEU Measured Value in Document Entry Unit.
        READEU           TYPE /BI0/OIREADEU,
         InfoObject: 0RECDU Unit of Measurement for Document Entry.
        RECDU           TYPE /BI0/OIRECDU,
         InfoObject: 0CNTRRSI Counter Reading in SI Unit.
        CNTRRSI           TYPE /BI0/OICNTRRSI,
         InfoObject: 0CDIFFSI Counter Reading Difference in SI Unit.
        CDIFFSI           TYPE /BI0/OICDIFFSI,
         InfoObject: 0CAT_TYPE Catalog.
        CAT_TYPE           TYPE /BI0/OICAT_TYPE,
         InfoObject: 0CAT_GROUP Code group.
        CAT_GROUP           TYPE /BI0/OICAT_GROUP,
         InfoObject: 0FI_STATUS Processing Status.
        FI_STATUS           TYPE /BI0/OIFI_STATUS,
         InfoObject: 0DIM_ID Dimension Key.
        DIM_ID           TYPE /BI0/OIDIM_ID,
         InfoObject: 0CNTIND Measuring Point is Counter.
        CNTIND           TYPE /BI0/OICNTIND,
         InfoObject: 0EQUIPMENT Equipment Number.
        EQUIPMENT           TYPE /BI0/OIEQUIPMENT,
         InfoObject: 0FUNCT_LOC Functional Location.
        FUNCT_LOC           TYPE /BI0/OIFUNCT_LOC,
         InfoObject: 0CAT_CODE Code.
        CAT_CODE           TYPE /BI0/OICAT_CODE,
         InfoObject: 0MRMAXSI Upper Meas. Limit or Max. Total Counter Read
    *ing in SI Unit.
        MRMAXSI           TYPE /BI0/OIMRMAXSI,
         InfoObject: 0DOCAF Measurement Document Included for Associated T
    *ask.
        DOCAF           TYPE /BI0/OIDOCAF,
         InfoObject: 0RECORDMODE BW Delta Process: Record Mode.
        RECORDMODE           TYPE RODMUPDMOD,
         Field: RECNO Data record number.
        RECNO           TYPE RSARECORD,
      END   OF tys_SC_1_full.
    TYPES:
      tyt_SC_1_full        TYPE STANDARD TABLE OF tys_SC_1_full
                        WITH NON-UNIQUE DEFAULT KEY.
    TYPES:
      BEGIN OF tys_TG_1_full,
         Field: SID Master data ID.
        SID           TYPE RSSID,
         Field: DATAPAKID Data packet number.
        DATAPAKID           TYPE RSDATAPID,
         Field: RECORD Data record number.
        RECORD           TYPE RSARECORD,
         InfoObject: 0MPOINT Measuring point.
        MPOINT           TYPE /BI0/OIMPOINT,
         InfoObject: 0MDOC Measurement Document.
        MDOC           TYPE /BI0/OIMDOC,
         InfoObject: 0MRMINSI Lower Meas. Limit or Min. Total Counter Read
    *ing in SI Unit.
        MRMINSI           TYPE /BI0/OIMRMINSI,
         InfoObject: 0FI_STATUS Processing Status.
        FI_STATUS           TYPE /BI0/OIFI_STATUS,
         InfoObject: 0DIM_ID Dimension Key.
        DIM_ID           TYPE /BI0/OIDIM_ID,
         InfoObject: 0CNTIND Measuring Point is Counter.
        CNTIND           TYPE /BI0/OICNTIND,
         InfoObject: 0EQUIPMENT Equipment Number.
        EQUIPMENT           TYPE /BI0/OIEQUIPMENT,
         InfoObject: 0FUNCT_LOC Functional Location.
        FUNCT_LOC           TYPE /BI0/OIFUNCT_LOC,
         InfoObject: 0CAT_CODE Code.
        CAT_CODE           TYPE /BI0/OICAT_CODE,
         InfoObject: 0CAT_TYPE Catalog.
        CAT_TYPE           TYPE /BI0/OICAT_TYPE,
         InfoObject: 0CAT_GROUP Code group.
        CAT_GROUP           TYPE /BI0/OICAT_GROUP,
         InfoObject: 0CREATED_BY Created By.
        CREATED_BY           TYPE /BI0/OICREATED_BY,
         InfoObject: 0MPOBJ Object Number of Measuring Point Object.
        MPOBJ           TYPE /BI0/OIMPOBJ,
         InfoObject: 0READEU Measured Value in Document Entry Unit.
        READEU           TYPE /BI0/OIREADEU,
         InfoObject: 0CJUMPSI Counter Overflow Reading in SI Unit.
        CJUMPSI           TYPE /BI0/OICJUMPSI,
         InfoObject: 0PYEARSI Annual Performance in SI Unit.
        PYEARSI           TYPE /BI0/OIPYEARSI,
         InfoObject: 0PSORT Position Number of Measuring Point in Object (
    *Sort Field).
        PSORT           TYPE /BI0/OIPSORT,
         InfoObject: 0ASSEMBLY Assembly.
        ASSEMBLY           TYPE /BI0/OIASSEMBLY,
         InfoObject: 0ATINN Internal Characteristic Number.
        ATINN           TYPE /BI0/OIATINN,
         InfoObject: 0MDATE Date of Measurement.
        MDATE           TYPE /BI0/OIMDATE,
         InfoObject: 0TIME Time.
        TIME           TYPE /BI0/OITIME,
         InfoObject: 0TVIND Target Value for Measuring Point Is Defined.
        TVIND           TYPE /BI0/OITVIND,
         InfoObject: 0MRMINI Lower Measurement Area Limit Is Defined.
        MRMINI           TYPE /BI0/OIMRMINI,
         InfoObject: 0DESIRSI Target Value for Measuring Point in SI Unit.
        DESIRSI           TYPE /BI0/OIDESIRSI,
         InfoObject: 0SIUNIT SI unit.
        SIUNIT           TYPE /BI0/OISIUNIT,
         InfoObject: 0DESIREU Target Value for Measuring Point in Document
    Entry Unit.
        DESIREU           TYPE /BI0/OIDESIREU,
         InfoObject: 0CNTRRSI Counter Reading in SI Unit.
        CNTRRSI           TYPE /BI0/OICNTRRSI,
         InfoObject: 0CDIFFSI Counter Reading Difference in SI Unit.
        CDIFFSI           TYPE /BI0/OICDIFFSI,
         InfoObject: 0RECDU Unit of Measurement for Document Entry.
        RECDU           TYPE /BI0/OIRECDU,
         InfoObject: 0MRMINEU Lower Meas. Limit or Min. Total Counter Read
    *ing Document UoM.
        MRMINEU           TYPE /BI0/OIMRMINEU,
         InfoObject: 0MRMAXEU Upper Meas. Limit or Max. Total Counter Read
    *ing in Doc. M.U..
        MRMAXEU           TYPE /BI0/OIMRMAXEU,
         InfoObject: 0MRMAXI Upper Measurement Area Limit Is Defined.
        MRMAXI           TYPE /BI0/OIMRMAXI,
         InfoObject: 0CNTRREU Counter Reading in Document Entry Unit.
        CNTRREU           TYPE /BI0/OICNTRREU,
         InfoObject: 0CDIFFEU Counter Reading Difference in Document Entry
    Unit.
        CDIFFEU           TYPE /BI0/OICDIFFEU,
         InfoObject: 0RECORDMODE BW Delta Process: Record Mode.
        RECORDMODE           TYPE RODMUPDMOD,
         InfoObject: 0MRMAXSI Upper Meas. Limit or Max. Total Counter Read
    *ing in SI Unit.
        MRMAXSI           TYPE /BI0/OIMRMAXSI,
         InfoObject: 0READSI Measured Value/Total Counter Reading in SI Un
    *it.
        READSI           TYPE /BI0/OIREADSI,
      END   OF tys_TG_1_full.
    TYPES:
      BEGIN OF tys_SC_1__RULE_34,
         InfoObject: 0DESIRSI Target Value for Measuring Point in SI Unit.
        DESIRSI           TYPE /BI0/OIDESIRSI,
         InfoObject: 0TVIND Target Value for Measuring Point Is Defined.
        TVIND           TYPE /BI0/OITVIND,
         InfoObject: 0SIUNIT SI unit.
        SIUNIT           TYPE /BI0/OISIUNIT,
         InfoObject: 0RECDU Unit of Measurement for Document Entry.
        RECDU           TYPE /BI0/OIRECDU,
         Field: RECORD.
        RECORD           TYPE RSARECORD,
      END   OF tys_SC_1__RULE_34.
    TYPES:
      BEGIN OF tys_SC_1__RULE_35,
         InfoObject: 0MRMINI Lower Measurement Area Limit Is Defined.
        MRMINI           TYPE /BI0/OIMRMINI,
         InfoObject: 0MRMINSI Lower Meas. Limit or Min. Total Counter Read
    *ing in SI Unit.
        MRMINSI           TYPE /BI0/OIMRMINSI,
         InfoObject: 0SIUNIT SI unit.
        SIUNIT           TYPE /BI0/OISIUNIT,
         InfoObject: 0RECDU Unit of Measurement for Document Entry.
        RECDU           TYPE /BI0/OIRECDU,
         Field: RECORD.
        RECORD           TYPE RSARECORD,
      END   OF tys_SC_1__RULE_35.
    TYPES:
      BEGIN OF tys_SC_1__RULE_36,
         InfoObject: 0MRMAXI Upper Measurement Area Limit Is Defined.
        MRMAXI           TYPE /BI0/OIMRMAXI,
         InfoObject: 0SIUNIT SI unit.
        SIUNIT           TYPE /BI0/OISIUNIT,
         InfoObject: 0RECDU Unit of Measurement for Document Entry.
        RECDU           TYPE /BI0/OIRECDU,
         InfoObject: 0MRMAXSI Upper Meas. Limit or Max. Total Counter Read
    *ing in SI Unit.
        MRMAXSI           TYPE /BI0/OIMRMAXSI,
         Field: RECORD.
        RECORD           TYPE RSARECORD,
      END   OF tys_SC_1__RULE_36.
    TYPES:
      BEGIN OF tys_SC_1__RULE_37,
         InfoObject: 0SIUNIT SI unit.
        SIUNIT           TYPE /BI0/OISIUNIT,
         InfoObject: 0RECDU Unit of Measurement for Document Entry.
        RECDU           TYPE /BI0/OIRECDU,
         InfoObject: 0CNTRRSI Counter Reading in SI Unit.
        CNTRRSI           TYPE /BI0/OICNTRRSI,
         InfoObject: 0CNTIND Measuring Point is Counter.
        CNTIND           TYPE /BI0/OICNTIND,
         Field: RECORD.
        RECORD           TYPE RSARECORD,
      END   OF tys_SC_1__RULE_37.
    TYPES:
      BEGIN OF tys_SC_1__RULE_38,
         InfoObject: 0SIUNIT SI unit.
        SIUNIT           TYPE /BI0/OISIUNIT,
         InfoObject: 0RECDU Unit of Measurement for Document Entry.
        RECDU           TYPE /BI0/OIRECDU,
         InfoObject: 0CDIFFSI Counter Reading Difference in SI Unit.
        CDIFFSI           TYPE /BI0/OICDIFFSI,
         InfoObject: 0CNTIND Measuring Point is Counter.
        CNTIND           TYPE /BI0/OICNTIND,
         Field: RECORD.
        RECORD           TYPE RSARECORD,
      END   OF tys_SC_1__RULE_38.
    Additional types for start routine interface
    TYPES:
      data_package_structure type tys_SC_1_full.
    Additional declaration for update rule interface
    DATA:
      MONITOR       type standard table of rsmonitor  WITH HEADER LINE,
      MONITOR_RECNO type standard table of rsmonitors WITH HEADER LINE,
      RECORD_NO     LIKE SY-TABIX,
      RECORD_ALL    LIKE SY-TABIX,
      SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS.
    global definitions from update rules
    TABLES: ...
    DATA:   ...
    *******DATA:  G_T_0EQUIPMENT  TYPE STANDARD TABLE OF /BI0/MEQUIPMENT.
    data: lt_data type ref to data.
    data: ls_data type ref to data.
    field-symbols: <G_T_0EQUIPMENT> type standard table.
    field-symbols: <G_S_0EQUIPMENT> type any.
    field-symbols: <FUNCT_LOC> type any.
    field-symbols: <DATEFROM> type any.
    field-symbols: <DATETO> type any.
    constants: c_tabname type rstlogotab value '/BI0/MEQUIPMENT'.
    *&      Form  routine_9998
          text
         -->DATA_PACKAGE            text
         -->ABORT                   text
         -->RAISING                 text
         -->CX_SY_ARITHMETIC_ERROR  text
         -->CX_SY_CONVERSION_ERROR  text
    FORM routine_9998
      TABLES DATA_PACKAGE TYPE tyt_SC_1_full
      CHANGING
        ABORT          LIKE sy-subrc
      RAISING
        cx_sy_arithmetic_error
        cx_sy_conversion_error.
    init variables
    fill the internal tables "MONITOR" and/or "MONITOR_RECNO",
    to make monitor entries
    In this start routine missing functional location for
    an equipment is added to a Data Package record, if it is available
    in the master data of the equipment
      create data lt_data type table of (c_tabname).
      assign lt_data->* to <G_T_0EQUIPMENT>.
      create data ls_data type (c_tabname).
      assign ls_data->* to <G_S_0EQUIPMENT>.
      assign component 'FUNCT_LOC' of structure <G_S_0EQUIPMENT> to
    <FUNCT_LOC>.
      assign component 'DATE_FROM' of structure <G_S_0EQUIPMENT> to
    <DATEFROM>.
      assign component 'DATE_TO' of structure <G_S_0EQUIPMENT> to
    <DATETO>.
      CALL FUNCTION 'RSAU_READ_MASTER_DATA'
        EXPORTING
          I_IOBJNM                = '0EQUIPMENT'
          I_FLG_WHOLE_TABLE       = 'X'
        IMPORTING
          E_TABLE                 = <G_T_0EQUIPMENT>
        EXCEPTIONS
          READ_ERROR              = 1
          NO_SUCH_ATTRIBUTE       = 2
          WRONG_IMPORT_PARAMETERS = 3
          CHAVL_NOT_FOUND         = 4
          OTHERS                  = 5.
      CASE SY-SUBRC.
        WHEN 0.
          LOOP AT <G_T_0EQUIPMENT> INTO <G_S_0EQUIPMENT>.
            IF <FUNCT_LOC> IS INITIAL.
              DELETE <G_T_0EQUIPMENT>.
            ENDIF.
    master data collected and condensed
          ENDLOOP.
          LOOP AT DATA_PACKAGE.
            IF ( DATA_PACKAGE-FUNCT_LOC IS INITIAL ) AND
               ( DATA_PACKAGE-EQUIPMENT IS NOT INITIAL ).
              READ TABLE <G_T_0EQUIPMENT> WITH KEY
                ('EQUIPMENT') = DATA_PACKAGE-EQUIPMENT INTO <G_S_0EQUIPMENT>
              IF SY-SUBRC = 0.
                IF ( DATA_PACKAGE-MDATE >= <DATEFROM> )
                   AND ( DATA_PACKAGE-MDATE <= <DATETO> ).
    record for equipment exists and valid
                  DATA_PACKAGE-FUNCT_LOC = <FUNCT_LOC>.
                  MODIFY DATA_PACKAGE.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDLOOP.
        WHEN 4.
    master data is not (yet) loaded
        WHEN OTHERS.
    problem occured, output as warning
          MONITOR-MSGID = SY-MSGID.
          MONITOR-MSGTY = 'W'.
          MONITOR-MSGNO = SY-MSGNO.
          MONITOR-MSGV1 = SY-MSGV1.
          MONITOR-MSGV2 = SY-MSGV2.
          MONITOR-MSGV3 = SY-MSGV3.
          MONITOR-MSGV4 = SY-MSGV4.
          APPEND MONITOR.
      ENDCASE.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    ENDFORM.                    "routine_9998
    *&      Form  routine_0001
          text
         -->COMM_STRUCTURE          text
         -->RESULT                  text
         -->RETURNCODE              text
         -->ABORT                   text
         -->RAISING                 text
         -->CX_SY_ARITHMETIC_ERROR  text
         -->CX_SY_CONVERSION_ERROR  text
    FORM routine_0001
      USING
        COMM_STRUCTURE type tys_SC_1__RULE_34
      CHANGING
        RESULT         TYPE tys_TG_1_full-DESIREU
        RETURNCODE     LIKE sy-subrc
        ABORT          LIKE sy-subrc
      RAISING
        cx_sy_arithmetic_error
        cx_sy_conversion_error.
    init variables
    fill the internal table "MONITOR", to make monitor entries
      CLEAR RESULT.
      IF COMM_STRUCTURE-TVIND = 'X'.
        CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
          EXPORTING
            INPUT                      = COMM_STRUCTURE-DESIRSI
            NO_TYPE_CHECK              = 'X'
      ROUND_SIGN                 = ' '
            UNIT_IN                    = COMM_STRUCTURE-SIUNIT
            UNIT_OUT                   = COMM_STRUCTURE-RECDU
          IMPORTING
      ADD_CONST                  =
      DECIMALS                   =
      DENOMINATOR                =
      NUMERATOR                  =
            OUTPUT                     = RESULT
       EXCEPTIONS
         CONVERSION_NOT_FOUND       = 1
         DIVISION_BY_ZERO           = 2
         INPUT_INVALID              = 3
         OUTPUT_INVALID             = 4
         OVERFLOW                   = 5
         TYPE_INVALID               = 6
         UNITS_MISSING              = 7
         UNIT_IN_NOT_FOUND          = 8
         UNIT_OUT_NOT_FOUND         = 9
         OTHERS                     = 10
        IF SY-SUBRC <> 0.
          MONITOR-MSGID = SY-MSGID.
          MONITOR-MSGTY = 'W'.
          MONITOR-MSGNO = SY-MSGNO.
          MONITOR-MSGV1 = SY-MSGV1.
          MONITOR-MSGV2 = SY-MSGV2.
          MONITOR-MSGV3 = SY-MSGV3.
          MONITOR-MSGV4 = SY-MSGV4.
          APPEND MONITOR.
        ENDIF.
      ENDIF.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    ENDFORM.                    "routine_0001
    *&      Form  routine_0002
          text
         -->COMM_STRUCTURE          text
         -->RESULT                  text
         -->RETURNCODE              text
         -->ABORT                   text
         -->RAISING                 text
         -->CX_SY_ARITHMETIC_ERROR  text
         -->CX_SY_CONVERSION_ERROR  text
    FORM routine_0002
      USING
        COMM_STRUCTURE type tys_SC_1__RULE_35
      CHANGING
        RESULT         TYPE tys_TG_1_full-MRMINEU
        RETURNCODE     LIKE sy-subrc
        ABORT          LIKE sy-subrc
      RAISING
        cx_sy_arithmetic_error
        cx_sy_conversion_error.
    init variables
    fill the internal table "MONITOR", to make monitor entries
      CLEAR RESULT.
      IF COMM_STRUCTURE-MRMINI = 'X'.
        CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
          EXPORTING
            INPUT                      = COMM_STRUCTURE-MRMINSI
            NO_TYPE_CHECK              = 'X'
      ROUND_SIGN                 = ' '
            UNIT_IN                    = COMM_STRUCTURE-SIUNIT
            UNIT_OUT                   = COMM_STRUCTURE-RECDU
          IMPORTING
      ADD_CONST                  =
      DECIMALS                   =
      DENOMINATOR                =
      NUMERATOR                  =
            OUTPUT                     = RESULT
       EXCEPTIONS
         CONVERSION_NOT_FOUND       = 1
         DIVISION_BY_ZERO           = 2
         INPUT_INVALID              = 3
         OUTPUT_INVALID             = 4
         OVERFLOW                   = 5
         TYPE_INVALID               = 6
         UNITS_MISSING              = 7
         UNIT_IN_NOT_FOUND          = 8
         UNIT_OUT_NOT_FOUND         = 9
         OTHERS                     = 10
        IF SY-SUBRC <> 0.
          MONITOR-MSGID = SY-MSGID.
          MONITOR-MSGTY = 'W'.
          MONITOR-MSGNO = SY-MSGNO.
          MONITOR-MSGV1 = SY-MSGV1.
          MONITOR-MSGV2 = SY-MSGV2.
          MONITOR-MSGV3 = SY-MSGV3.
          MONITOR-MSGV4 = SY-MSGV4.
          APPEND MONITOR.
        ENDIF.
      ENDIF.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    ENDFORM.                    "routine_0002
    *&      Form  routine_0003
          text
         -->COMM_STRUCTURE          text
         -->RESULT                  text
         -->RETURNCODE              text
         -->ABORT                   text
         -->RAISING                 text
         -->CX_SY_ARITHMETIC_ERROR  text
         -->CX_SY_CONVERSION_ERROR  text
    FORM routine_0003
      USING
        COMM_STRUCTURE type tys_SC_1__RULE_36
      CHANGING
        RESULT         TYPE tys_TG_1_full-MRMAXEU
        RETURNCODE     LIKE sy-subrc
        ABORT          LIKE sy-subrc
      RAISING
        cx_sy_arithmetic_error
        cx_sy_conversion_error.
    init variables
    fill the internal table "MONITOR", to make monitor entries
      CLEAR RESULT.
      IF COMM_STRUCTURE-MRMAXI = 'X'.
        CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
          EXPORTING
            INPUT                      = COMM_STRUCTURE-MRMAXSI
            NO_TYPE_CHECK              = 'X'
      ROUND_SIGN                 = ' '
            UNIT_IN                    = COMM_STRUCTURE-SIUNIT
            UNIT_OUT                   = COMM_STRUCTURE-RECDU
          IMPORTING
      ADD_CONST                  =
      DECIMALS                   =
      DENOMINATOR                =
      NUMERATOR                  =
            OUTPUT                     = RESULT
       EXCEPTIONS
         CONVERSION_NOT_FOUND       = 1
         DIVISION_BY_ZERO           = 2
         INPUT_INVALID              = 3
         OUTPUT_INVALID             = 4
         OVERFLOW                   = 5
         TYPE_INVALID               = 6
         UNITS_MISSING              = 7
         UNIT_IN_NOT_FOUND          = 8
         UNIT_OUT_NOT_FOUND         = 9
         OTHERS                     = 10
        IF SY-SUBRC <> 0.
          MONITOR-MSGID = SY-MSGID.
          MONITOR-MSGTY = 'W'.
          MONITOR-MSGNO = SY-MSGNO.
          MONITOR-MSGV1 = SY-MSGV1.
          MONITOR-MSGV2 = SY-MSGV2.
          MONITOR-MSGV3 = SY-MSGV3.
          MONITOR-MSGV4 = SY-MSGV4.
          APPEND MONITOR.
        ENDIF.
      ENDIF.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    ENDFORM.                    "routine_0003
    *&      Form  routine_0004
          text
         -->COMM_STRUCTURE          text
         -->RESULT                  text
         -->RETURNCODE              text
         -->ABORT                   text
         -->RAISING                 text
         -->CX_SY_ARITHMETIC_ERROR  text
         -->CX_SY_CONVERSION_ERROR  text
    FORM routine_0004
      USING
        COMM_STRUCTURE type tys_SC_1__RULE_37
      CHANGING
        RESULT         TYPE tys_TG_1_full-CNTRREU
        RETURNCODE     LIKE sy-subrc
        ABORT          LIKE sy-subrc
      RAISING
        cx_sy_arithmetic_error
        cx_sy_conversion_error.
    init variables
    fill the internal table "MONITOR", to make monitor entries
      CLEAR RESULT.
      IF COMM_STRUCTURE-CNTIND = 'X'.
        CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
          EXPORTING
            INPUT                      = COMM_STRUCTURE-CNTRRSI
            NO_TYPE_CHECK              = 'X'
      ROUND_SIGN                 = ' '
            UNIT_IN                    = COMM_STRUCTURE-SIUNIT
            UNIT_OUT                   = COMM_STRUCTURE-RECDU
          IMPORTING
      ADD_CONST                  =
      DECIMALS                   =
      DENOMINATOR                =
      NUMERATOR                  =
            OUTPUT                     = RESULT
       EXCEPTIONS
         CONVERSION_NOT_FOUND       = 1
         DIVISION_BY_ZERO           = 2
         INPUT_INVALID              = 3
         OUTPUT_INVALID             = 4
         OVERFLOW                   = 5
         TYPE_INVALID               = 6
         UNITS_MISSING              = 7
         UNIT_IN_NOT_FOUND          = 8
         UNIT_OUT_NOT_FOUND         = 9
         OTHERS                     = 10
        IF SY-SUBRC <> 0.
          MONITOR-MSGID = SY-MSGID.
          MONITOR-MSGTY = 'W'.
          MONITOR-MSGNO = SY-MSGNO.
          MONITOR-MSGV1 = SY-MSGV1.
          MONITOR-MSGV2 = SY-MSGV2.
          MONITOR-MSGV3 = SY-MSGV3.
          MONITOR-MSGV4 = SY-MSGV4.
          APPEND MONITOR.
        ENDIF.
      ENDIF.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    ENDFORM.                    "routine_0004
    *&      Form  routine_0005
          text
         -->COMM_STRUCTURE          text
         -->RESULT                  text
         -->RETURNCODE              text
         -->ABORT                   text
         -->RAISING                 text
         -->CX_SY_ARITHMETIC_ERROR  text
         -->CX_SY_CONVERSION_ERROR  text
    FORM routine_0005
      USING
        COMM_STRUCTURE type tys_SC_1__RULE_38
      CHANGING
        RESULT         TYPE tys_TG_1_full-CDIFFEU
        RETURNCODE     LIKE sy-subrc
        ABORT          LIKE sy-subrc
      RAISING
        cx_sy_arithmetic_error
        cx_sy_conversion_error.
    init variables
    fill the internal table "MONITOR", to make monitor entries
      CLEAR RESULT.
      IF COMM_STRUCTURE-CNTIND = 'X'.
        CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
          EXPORTING
            INPUT                      = COMM_STRUCTURE-CDIFFSI
            NO_TYPE_CHECK              = 'X'
      ROUND_SIGN                 = ' '
            UNIT_IN                    = COMM_STRUCTURE-SIUNIT
            UNIT_OUT                   = COMM_STRUCTURE-RECDU
          IMPORTING
      ADD_CONST                  =
      DECIMALS                   =
      DENOMINATOR                =
      NUMERATOR                  =
            OUTPUT                     = RESULT
       EXCEPTIONS
         CONVERSION_NOT_FOUND       = 1
         DIVISION_BY_ZERO           = 2
         INPUT_INVALID              = 3
         OUTPUT_INVALID             = 4
         OVERFLOW                   = 5
         TYPE_INVALID               = 6
         UNITS_MISSING              = 7
         UNIT_IN_NOT_FOUND          = 8
         UNIT_OUT_NOT_FOUND         = 9
         OTHERS                     = 10
        IF SY-SUBRC <> 0.
          MONITOR-MSGID = SY-MSGID.
          MONITOR-MSGTY = 'W'.
          MONITOR-MSGNO = SY-MSGNO.
          MONITOR-MSGV1 = SY-MSGV1.
          MONITOR-MSGV2 = SY-MSGV2.
          MONITOR-MSGV3 = SY-MSGV3.
          MONITOR-MSGV4 = SY-MSGV4.
          APPEND MONITOR.
        ENDIF.
      ENDIF.
    if abort is not equal zero, the update process will be canceled
      ABORT = 0.
    ENDFORM.                    "routine_0005
    TYPES: BEGIN OF TY_/BI0/PMPOINT,
          MPOINT      TYPE /BI0/PMPOINT-MPOINT,
       MRNGU     TYPE /BI0/PMPOINT-MRNGU,
    END of TY_/BI0/PMPOINT.
    DATA: /BI0/PMPOINT_TEMP TYPE STANDARD TABLE OF
    TY_/BI0/PMPOINT,
          W_/BI0/PMPOINT_TEMP like line of /BI0/PMPOINT_TEMP.
    $$ end of 2nd part global - insert your code only before this line   *
          CLASS routine IMPLEMENTATION
    CLASS lcl_transform IMPLEMENTATION.
          Method start_routine
          Calculation of source package via start routine
      <-> source package
      METHOD start_routine.
    *=== Segments ===
        FIELD-SYMBOLS:
          <SOURCE_FIELDS>    TYPE tys_SC_1.
        DATA:
          MONITOR_REC     TYPE rstmonitor.
    *$*$ begin of routine - insert your code only below this line        *-*
        Data:
          l_subrc          type sy-tabix,
          l_abort          type sy-tabix,
          ls_monitor       TYPE rsmonitor,
          ls_monitor_recno TYPE rsmonitors.
        REFRESH:
          MONITOR,
          MONITOR_RECNO.
    Runtime attributs
        SOURCE_SYSTEM  = p_r_request->get_logsys( ).
    Migrated update rule call
        Perform routine_9998
        TABLES
          SOURCE_PACKAGE
        CHANGING
          l_abort.
    *-- Convert Messages in Transformation format
        LOOP AT MONITOR_RECNO INTO ls_monitor_recno.
          move-CORRESPONDING ls_monitor_recno to MONITOR_REC.
          append monitor_rec to MONITOR.
        ENDLOOP.
        LOOP AT MONITOR INTO ls_monitor.
          move-CORRESPONDING ls_monitor to MONITOR_REC.
          append monitor_rec to MONITOR.
        ENDLOOP.
        IF l_abort <> 0.
          RAISE EXCEPTION TYPE CX_RSROUT_ABORT.
        ENDIF.
    $$ end of routine - insert your code only before this line         -
      ENDMETHOD.                    "start_routine
          Method inverse_start_routine
          This subroutine needs to be implemented only for direct access
          (for better performance) and for the Report/Report Interface
          (drill through).
          The inverse routine should transform a projection and
          a selection for the target to a projection and a selection
          for the source, respectively.
          If the implementation remains empty all fields are filled and
          all values are selected.
      METHOD inverse_start_routine.
    $$ begin of inverse routine - insert your code only below this line-
        ... "insert your code here
    $$ end of inverse routine - insert your code only before this line -
      ENDMETHOD.                    "inverse_start_routine
    ENDCLASS.                    "routine IMPLEMENTATION

  • Reg : Issue for Sending of external email using SO_OBJECT_SEND

    There is one issue while sending external email using SO_OBJECT_SEND functional module.
    1. The body of the mail is also included as attachment.
    I want to avoid the same.
    Please anyone can give the solution.

    hi check this example ,
    Sending mail with attachment report in Background
    Content Author: Fernando Faian
    I have read the hint about "Sending mail with attachment report".
    It's great, but how can I make this function work in background??
    I had that needed last year too. See attachment a function group with two functions. The second one has that functionality to send email or fax (SAP office) with attachment objects in background job using SO_ATTACHMENT_INSERT function. 
    Pay attention because it’s working with output list from spool converted to pdf. 
    =================================================================================
    z_send_email_fax_global
    FUNCTION-POOL z_gfaian_mail_fax.            "MESSAGE-ID ..
    WORK TABLE AREAS
    TABLES: tsp01.
    INTERNAL TABLES
    DATA: lt_rec_tab LIKE STANDARD TABLE OF soos1 WITH HEADER LINE,
          lt_note_text   LIKE STANDARD TABLE OF soli  WITH HEADER LINE,
          lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE.
    DATA: lt_objcont LIKE STANDARD TABLE OF soli WITH HEADER LINE,
          lt_objhead LIKE STANDARD TABLE OF soli WITH HEADER LINE.
    DATA: pdf_format LIKE STANDARD TABLE OF tline WITH HEADER LINE.
    TYPES: BEGIN OF y_files,
           file(60) TYPE c,
           END OF y_files.
    DATA: lt_files TYPE STANDARD TABLE OF y_files WITH HEADER LINE.
    DATA: l_objcont     LIKE soli OCCURS 0 WITH HEADER LINE.
    DATA: l_objhead     LIKE soli OCCURS 0 WITH HEADER LINE.
    STRUCTURES
    DATA: folder_id      LIKE soodk,
          object_id      LIKE soodk,
          link_folder_id LIKE soodk,
          g_document     LIKE sood4,
         g_header_data  LIKE sood2,
          g_folmem_data  LIKE sofm2,
          g_header_data  LIKE sood2,
          g_receive_data LIKE soos6,
          g_ref_document LIKE sood4,
          g_new_parent   LIKE soodk,
          l_folder_id    LIKE sofdk,
          v_email(50).
    DATA: hd_dat  like sood1.
    VARIABLES
    DATA: client  LIKE tst01-dclient,
          name    LIKE tst01-dname,
          objtype LIKE rststype-type,
          type    LIKE rststype-type.
    DATA: numbytes TYPE i,
          arc_idx LIKE toa_dara,
          pdfspoolid LIKE tsp01-rqident,
          jobname LIKE tbtcjob-jobname,
          jobcount LIKE tbtcjob-jobcount,
          is_otf.
    DATA: outbox_flag LIKE sonv-flag VALUE 'X',
          store_flag  LIKE sonv-flag,
          delete_flag LIKE sonv-flag,
          owner       LIKE soud-usrnam,
          on          LIKE sonv-flag VALUE 'X',
          sent_to_all LIKE sonv-flag,
          g_authority LIKE sofa-usracc,
          w_objdes    LIKE sood4-objdes.
    DATA: c_file LIKE rlgrap-filename,
          n_spool(6) TYPE n.
    DATA: cancel.
    DATA: desired_type  LIKE sood-objtp,
          real_type LIKE sood-objtp,
          attach_type LIKE sood-objtp,
          otf LIKE sood-objtp VALUE 'OTF', " SAPscript Ausgabeformat
          ali LIKE sood-objtp VALUE 'ALI'. " ABAP lists
    CONSTANTS
    CONSTANTS: ou_fol LIKE sofh-folrg              VALUE 'O',
               c_objtp    LIKE g_document-objtp    VALUE 'RAW',
               c_file_ext LIKE g_document-file_ext VALUE 'TXT'.
    =================================================================================
    z_send_email_fax2
    FUNCTION z_faian_mail_fax2.
    ""Interface local:
    *"  IMPORTING
    *"     REFERENCE(SRC_SPOOLID) LIKE  TSP01-RQIDENT
    *"     REFERENCE(FAX_MAIL_NUMBER) TYPE  SO_NAME
    *"     REFERENCE(HEADER_MAIL) TYPE  SO_OBJ_DES
    *"     REFERENCE(OBJECT_TYPE) TYPE  SO_ESCAPE
    *"  TABLES
    *"      LT_BODY_EMAIL STRUCTURE  SOLI
    *"  EXCEPTIONS
    *"      ERR_NO_ABAP_SPOOLJOB
    Fist part: Verify if the spool really exists
      SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
      IF sy-subrc NE 0.
        RAISE err_no_abap_spooljob. "doesn't exist
      ELSE.
        client = tsp01-rqclient.
        name   = tsp01-rqo1name.
        CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
             EXPORTING
                  authority     = 'SP01'
                  client        = client
                  name          = name
                  part          = 1
             IMPORTING
                  type          = type
                  objtype       = objtype
             EXCEPTIONS
                  fb_error      = 1
                  fb_rsts_other = 2
                  no_object     = 3
                  no_permission = 4
                  OTHERS        = 5.
        IF objtype(3) = 'OTF'.
          desired_type = otf.
        ELSE.
          desired_type = ali.
        ENDIF.
        CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
             EXPORTING
                  rqident              = src_spoolid
                  desired_type         = desired_type
             IMPORTING
                  real_type            = real_type
             TABLES
                  buffer               = l_objcont
             EXCEPTIONS
                  no_such_job          = 14
                  type_no_match        = 94
                  job_contains_no_data = 54
                  no_permission        = 21
                  can_not_access       = 21
                  read_error           = 54.
        IF sy-subrc EQ 0.
          attach_type = real_type.
        ENDIF.
        CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
             EXPORTING
                  owner     = sy-uname
                  region    = ou_fol
             IMPORTING
                  folder_id = l_folder_id
             EXCEPTIONS
                  OTHERS    = 5.
    fill out informations about the header of the email
        CLEAR: g_document.
        g_document-foltp     = l_folder_id-foltp.
        g_document-folyr     = l_folder_id-folyr.
        g_document-folno     = l_folder_id-folno.
        g_document-objtp     = c_objtp.
        g_document-objdes    = header_mail.
        g_document-file_ext  = c_file_ext.
        g_header_data-objdes    = header_mail.
        CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
             EXPORTING
                  method      = 'SAVE'
                  office_user = sy-uname
             IMPORTING
                  authority   = g_authority
             TABLES
                  objcont     = lt_body_email
                  attachments = lt_attachments
             CHANGING
                  document    = g_document
                  header_data = g_header_data
             EXCEPTIONS
                  OTHERS      = 1.
        folder_id-objtp = l_folder_id-foltp.
        folder_id-objyr = l_folder_id-folyr.
        folder_id-objno = l_folder_id-folno.
        object_id-objtp = c_objtp.
        object_id-objyr = g_document-objyr.
        object_id-objno = g_document-objno.
        link_folder_id-objtp = l_folder_id-foltp.
        link_folder_id-objyr = l_folder_id-folyr.
        link_folder_id-objno = l_folder_id-folno.
        REFRESH lt_rec_tab.
       CLEAR lt_rec_tab.
       lt_rec_tab-sel        = 'X'.
       lt_rec_tab-recesc     = object_type.   "This field for FAX/MAIL
       lt_rec_tab-recnam     = 'U-'.
       lt_rec_tab-deliver    = 'X'.
       lt_rec_tab-not_deli   = 'X'.
       lt_rec_tab-read       = 'X'.
       lt_rec_tab-mailstatus = 'E'.
       lt_rec_tab-adr_name   = fax_mail_number.
       lt_rec_tab-sortfield  = fax_mail_number.
       lt_rec_tab-recextnam  = fax_mail_number.
       lt_rec_tab-sortclass  = '5'.
       APPEND lt_rec_tab.
          lt_rec_tab-recextnam = fax_mail_number.
          lt_rec_tab-recesc = object_type.
          lt_rec_tab-sndart = 'INT'.
          lt_rec_tab-sndpri = 1.
          APPEND lt_rec_tab.
        lt_files-file = c_file.
        APPEND lt_files.
    begin of insertion by faianf01
        hd_dat-objdes = header_mail.
        CALL FUNCTION 'SO_ATTACHMENT_INSERT'
             EXPORTING
                  object_id                  = object_id
                  attach_type                = attach_type
                  object_hd_change           = hd_dat
                  owner                      = sy-uname
             TABLES
                  objcont                    = l_objcont
                  objhead                    = l_objhead
             EXCEPTIONS
                  active_user_not_exist      = 35
                  communication_failure      = 71
                  object_type_not_exist      = 17
                  operation_no_authorization = 21
                  owner_not_exist            = 22
                  parameter_error            = 23
                  substitute_not_active      = 31
                  substitute_not_defined     = 32
                  system_failure             = 72
                  x_error                    = 1000.
        IF sy-subrc > 0.
        ENDIF.
    end of insertion by faianf01
    send email from SAPOFFICE
        CALL FUNCTION 'SO_OBJECT_SEND'
             EXPORTING
                  folder_id                  = folder_id
                  object_id                  = object_id
                  outbox_flag                = outbox_flag
                  link_folder_id             = link_folder_id
                  owner                      = sy-uname
                 check_send_authority       = 'X'
             TABLES
                  receivers                  = lt_rec_tab
                 note_text                  = lt_note_text
             EXCEPTIONS
                  active_user_not_exist      = 35
                  communication_failure      = 71
                  component_not_available    = 1
                  folder_no_authorization    = 5
                  folder_not_exist           = 6
                  forwarder_not_exist        = 8
                  object_no_authorization    = 13
                  object_not_exist           = 14
                  object_not_sent            = 15
                  operation_no_authorization = 21
                  owner_not_exist            = 22
                  parameter_error            = 23
                  substitute_not_active      = 31
                  substitute_not_defined     = 32
                  system_failure             = 72
                  too_much_receivers         = 73
                  user_not_exist             = 35.
      ENDIF.
    ENDFUNCTION.
    =================================================================================
    z_send_email_fax
    FUNCTION ZCBFS_SEND_MAIL.
    ""Interface local:
    *"  IMPORTING
    *"     REFERENCE(SRC_SPOOLID) LIKE  TSP01-RQIDENT
    *"     REFERENCE(HEADER_MAIL) TYPE  SO_OBJ_DES
    *"  TABLES
    *"      LIST_FAX_MAIL_NUMBER STRUCTURE  SOLI
    *"  EXCEPTIONS
    *"      ERR_NO_ABAP_SPOOLJOB
      DATA: vg_achou(1) TYPE n.
    Fist part: Verify if the spool really exists
      vg_achou = 1.
      DO 60 TIMES.
        SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
        IF sy-subrc IS INITIAL.
          CLEAR vg_achou.
          EXIT.
        ELSE.
          WAIT UP TO 1 SECONDS.
        ENDIF.
      ENDDO.
      IF vg_achou = 1.
        RAISE err_no_abap_spooljob. "doesn't exist
      ENDIF.
      client = tsp01-rqclient.
      name   = tsp01-rqo1name.
      CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
           EXPORTING
                authority     = 'SP01'
                client        = client
                name          = name
                part          = 1
           IMPORTING
                type          = type
                objtype       = objtype
           EXCEPTIONS
                fb_error      = 1
                fb_rsts_other = 2
                no_object     = 3
                no_permission = 4
                OTHERS        = 5.
      IF objtype(3) = 'OTF'.
        desired_type = otf.
      ELSE.
        desired_type = ali.
      ENDIF.
      CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
           EXPORTING
                rqident              = src_spoolid
                desired_type         = desired_type
           IMPORTING
                real_type            = real_type
           TABLES
                buffer               = l_objcont
           EXCEPTIONS
                no_such_job          = 14
                type_no_match        = 94
                job_contains_no_data = 54
                no_permission        = 21
                can_not_access       = 21
                read_error           = 54.
      IF sy-subrc EQ 0.
        attach_type = real_type.
      ENDIF.
      CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
           EXPORTING
                owner     = sy-uname
                region    = ou_fol
           IMPORTING
                folder_id = l_folder_id
           EXCEPTIONS
                OTHERS    = 5.
    fill out informations about the header of the email
      CLEAR: g_document.
      g_document-foltp     = l_folder_id-foltp.
      g_document-folyr     = l_folder_id-folyr.
      g_document-folno     = l_folder_id-folno.
      g_document-objtp     = c_objtp.
      g_document-objdes    = header_mail.
      g_document-file_ext  = c_file_ext.
      g_header_data-objdes    = header_mail.
      CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
           EXPORTING
                method      = 'SAVE'
                office_user = sy-uname
           IMPORTING
                authority   = g_authority
           TABLES
                attachments = lt_attachments
           CHANGING
                document    = g_document
                header_data = g_header_data
           EXCEPTIONS
                OTHERS      = 1.
      folder_id-objtp = l_folder_id-foltp.
      folder_id-objyr = l_folder_id-folyr.
      folder_id-objno = l_folder_id-folno.
      object_id-objtp = c_objtp.
      object_id-objyr = g_document-objyr.
      object_id-objno = g_document-objno.
      link_folder_id-objtp = l_folder_id-foltp.
      link_folder_id-objyr = l_folder_id-folyr.
      link_folder_id-objno = l_folder_id-folno.
      REFRESH lt_rec_tab.
      LOOP AT LIST_FAX_MAIL_NUMBER.
        lt_rec_tab-recextnam = LIST_FAX_MAIL_NUMBER-LINE.
        lt_rec_tab-recesc = 'U'.
        lt_rec_tab-sndart = 'INT'.
        lt_rec_tab-sndpri = 1.
        APPEND lt_rec_tab.
      ENDLOOP.
      lt_files-file = c_file.
      APPEND lt_files.
      hd_dat-objdes = header_mail.
      CALL FUNCTION 'SO_ATTACHMENT_INSERT'
           EXPORTING
                object_id                  = object_id
                attach_type                = attach_type
                object_hd_change           = hd_dat
                owner                      = sy-uname
           TABLES
                objcont                    = l_objcont
                objhead                    = l_objhead
           EXCEPTIONS
                active_user_not_exist      = 35
                communication_failure      = 71
                object_type_not_exist      = 17
                operation_no_authorization = 21
                owner_not_exist            = 22
                parameter_error            = 23
                substitute_not_active      = 31
                substitute_not_defined     = 32
                system_failure             = 72
                x_error                    = 1000.
      IF sy-subrc > 0.
      ENDIF.
    send email from SAPOFFICE
      CALL FUNCTION 'SO_OBJECT_SEND'
           EXPORTING
                folder_id                  = folder_id
                object_id                  = object_id
                outbox_flag                = outbox_flag
                link_folder_id             = link_folder_id
                owner                      = sy-uname
           TABLES
                receivers                  = lt_rec_tab
                note_text                  = lt_note_text
           EXCEPTIONS
                active_user_not_exist      = 35
                communication_failure      = 71
                component_not_available    = 1
                folder_no_authorization    = 5
                folder_not_exist           = 6
                forwarder_not_exist        = 8
                object_no_authorization    = 13
                object_not_exist           = 14
                object_not_sent            = 15
                operation_no_authorization = 21
                owner_not_exist            = 22
                parameter_error            = 23
                substitute_not_active      = 31
                substitute_not_defined     = 32
                system_failure             = 72
                too_much_receivers         = 73
                user_not_exist             = 35.
    ENDFUNCTION.
    =================================================================================
    regards,
    venkat.

  • Reg sending mail attachment

    Hi,
    im working on sending report output as mail attachment in pdf format..
    but im not getting the required output,,,i.e., even after entering email addresses in the selection screen....im not getting any mail to the respective mail-ids..
    im pasting the code..pls fix the problem..
    pls let me know wat we have to do in SCOT transaction after executing the program....pls respond ..pls ..
    TABLES : t001,                                         "COMPANY CODE
             knb1,                                         "CUSTOMER MASTER(COMPANY CODE)
             cdhdr,                                        "CHANGE DOCUMENT HEADER
             knkk,                                         "CUSTOMER MASTER CREDIT MANAGEMENT: CONTROL AREA DATA
             kna1,                                         "GENERAL DATA IN CUSTOMER MASTER
             adrc,                                         "ADDRESSES (BUSINESS ADDRESS SERVICES)
             t001s,                                        "ACCOUNTING CLERKS
             adrt,                                         "COMMUNICATION DATA TEXT (BUSINESS ADDRESS SERVICES)
             adr6.                                         "E-MAIL ADDRESSES (BUSINESS ADDRESS SERVICES)
    TABLES: itcpo,                                         "SAPscript output interface
            itcpp.                                         "SAPscript output parameters
    TYPES:   BEGIN OF y_t001,
                      bukrs TYPE bukrs,
                      kkber TYPE kkber,
                      adrnr TYPE adrnr,
             END OF y_t001.
    TYPES:   BEGIN OF y_cust,
                      p_objectid TYPE cdobjectv,
             END OF y_cust.
    TYPES:   BEGIN OF y_knkk,
                      kunnr TYPE kunnr,
                      kkber TYPE kkber,
                      dtrev TYPE dtrev_cm,
                      nxtrv TYPE nxtrv_cm,
                      klimk TYPE klimk,
                      dbwae TYPE dbwae_cm,
             END OF y_knkk.
    TYPES:   BEGIN OF y_customer,
                      kunnr TYPE kunnr,
                      adrnr TYPE adrnr,
             END OF y_customer.
    TYPES:   BEGIN OF y_custo ,
                      kunnr TYPE  kunnr,
                      name  TYPE  name1_gp,
                      kkber TYPE kkber,
             END OF y_custo.
    TYPES:   BEGIN OF y_knkk1,
                      kunnr LIKE knkk-kunnr,
                      dtrev LIKE knkk-dtrev,
                      nxtrv LIKE knkk-nxtrv,
                      klimk LIKE knkk-klimk,
             END OF y_knkk1.
    TYPES:   BEGIN OF y_report_display,
                      kunnr TYPE kunnr,
                      name  TYPE name1_gp,
                      dtrev TYPE dtrev_cm,
                      nxtrv TYPE nxtrv_cm,
                      klimk TYPE klimk,
                      dbwae TYPE dbwae_cm,
             END OF y_report_display.
    TYPES:   BEGIN OF y_adrt,
                      addrnumber TYPE adrnr,
                      comm_type  TYPE ad_comm,
                      remark     TYPE ad_remark2,
                      persnumber TYPE ad_persnum,
                      date_from  TYPE ad_date_fr,
                      consnumber TYPE ad_consnum,
                      smtp_addr  TYPE ad_smtpadr,
              END OF y_adrt.
    *TYPES : BEGIN OF y_adr6,
                     addrnumber TYPE ad_addrnum,
                     persnumber TYPE ad_persnum,
                     date_from  TYPE ad_date_fr,
                     consnumber TYPE ad_consnum,
                     smtp_addr  TYPE ad_smtpadr,
           END OF y_adr6.
    *TYPES:   BEGIN OF y_addr,
                     addrnumber TYPE adrnr,
                     name1  TYPE ad_name1,
                     postcode TYPE ad_pstcd1,
                     city1    TYPE ad_city1,
                     street   TYPE ad_street,
                     housenum TYPE ad_hsnm1,
                     telnum   TYPE ad_tlnmbr1,
                     faxnum   TYPE ad_fxnmbr1,
            END OF y_addr.
    TYPES:   BEGIN OF y_custnam,
                      adrnr TYPE adrnr,
                      name2 TYPE ad_name1,
             END OF y_custnam.
    TYPES:   BEGIN OF y_kna1,
                      kunnr TYPE kunnr,
                      adrnr TYPE adrnr,
                      name1 TYPE name1,
                     END OF y_kna1.
    TYPES:   BEGIN OF y_knb1,
                      kunnr TYPE kunnr,
                      bukrs TYPE bukrs,
                      busab TYPE busab,
             END OF y_knb1.
    TYPES:   BEGIN OF y_clv,
                      dtrev TYPE dtrev_cm,
                      nxtrv TYPE nxtrv_cm,
                      klimk TYPE klimk,
             END OF y_clv.
    TYPES:    BEGIN OF y_ccname,
                       sname TYPE t001s-sname,
              END OF y_ccname.
    *TYPES DECLARATION FOR DESIGING SCRIPT
    TYPES : BEGIN OF y_adrc,
               addrnumber LIKE adrc-addrnumber,
               name1 LIKE adrc-name1,
               post_code1 LIKE adrc-post_code1,
               city1 LIKE adrc-city1,
               street LIKE adrc-street,
               house_num1 LIKE adrc-house_num1,
               tel_number LIKE adrc-tel_number,
               nation LIKE adrc-nation ,
               fax_number LIKE adrc-fax_number,
               country LIKE adrc-country,
               END OF y_adrc.
    *TO GET C1 (CUSTOMER NAME IN RUSSIAN
    TYPES : BEGIN OF y_adrc1,
            addrnumber LIKE adrc-addrnumber,
            name1 LIKE adrc-name1,
            nation LIKE adrc-nation,
            END OF y_adrc1.
    *TO GET C7
    TYPES :BEGIN OF y_t001s,
            bukrs LIKE t001s-bukrs,    "Company Code
            busab LIKE t001s-busab,
            sname LIKE t001s-sname,
            END OF y_t001s.
    CONSTANTS:
    c_printer         LIKE itcpp-tddevice VALUE 'PRINTER',
    c_true(1)         TYPE c VALUE 'X',
    c_1(1)            TYPE n VALUE '1',
    c_pdf_format(3)   TYPE c VALUE 'PDF',
    c_u               LIKE soos1-recesc   VALUE 'U',
    c_recipient_name  LIKE soos1-recnam   VALUE 'U-',
    c_english         LIKE sy-langu       VALUE 'E',
    c_f               LIKE sood1-objsns   VALUE 'F',
    c_int(3)          TYPE c VALUE 'INT',
    c_main(4)         TYPE c VALUE 'ITEM',
    c_main_window(4)  TYPE c VALUE 'MAIN',
    c_header(6)       TYPE c VALUE 'HEADER',
    c_minus_sign(1)   TYPE c VALUE '-',
    c_document_type   LIKE sood-objtp     VALUE 'EXT',
    c_space(1)        TYPE c VALUE ' '.
    DATA t_result LIKE itcpp.
    DATA :w_t001      TYPE t001,
          w_custo     TYPE y_custo,
          w_knkk      TYPE y_knkk,
          w_cust      TYPE y_cust,
          w_customer  TYPE y_customer,
          w_report_display TYPE y_report_display,
         w_addr      TYPE y_addr,
          w_custnam   TYPE y_custnam,
          w_adrt      TYPE y_adrt,
         w_adr6      TYPE y_adr6,
          w_kna1      TYPE y_kna1,
          w_knb1      TYPE y_knb1,
          w_clv       TYPE y_clv,
          w_ccname    TYPE y_ccname.
    DATA:    w_error_found(1)       TYPE c,
             w_key_date_text(30)    TYPE c,
             w_total(10)            TYPE p DECIMALS 2,
             w_htddevice            LIKE itcpp-tddevice.
    DATA: E_PROFILE LIKE SOPRD.
    DATA:   t_t001            TYPE STANDARD TABLE OF y_t001,
            t_custo           TYPE STANDARD TABLE OF y_custo,
          t_knkk            TYPE STANDARD TABLE OF y_knkk,
            t_cust            TYPE STANDARD TABLE OF y_cust,
            t_customer        TYPE STANDARD TABLE OF y_customer,
            t_report_display  TYPE STANDARD TABLE OF y_report_display,
           t_addr            TYPE STANDARD TABLE OF y_addr,
            t_custnam         TYPE STANDARD TABLE OF y_custnam,
            t_adrt            TYPE STANDARD TABLE OF y_adrt,
           t_adr6            TYPE STANDARD TABLE OF y_adr6,
            t_kna1            TYPE STANDARD TABLE OF y_kna1,
            t_knb1            TYPE STANDARD TABLE OF y_knb1,
            t_clv             TYPE STANDARD TABLE OF y_clv,
            t_ccname          TYPE STANDARD TABLE OF y_ccname.
    DATA : number LIKE spell,
           amount(1000) TYPE c.
    For storing error log
    DATA: BEGIN OF t_error OCCURS 0,
            kunnr LIKE kna1-kunnr,
            comm(30) TYPE c,
          END OF t_error.
    For storing customer's email address
    DATA: BEGIN OF t_email OCCURS 0,
            smtp_addr LIKE adr6-smtp_addr,
          END OF t_email.
    To be used in the function to send a layout via email
    DATA: t_otfdata LIKE itcoo OCCURS 0 WITH HEADER LINE,
          t_htline  LIKE tline OCCURS 0 WITH HEADER LINE.
    DATA DECLARATIONS FOR DESIGING SCRIPT
    DATA : it_t001 TYPE STANDARD TABLE OF y_t001,
           wa_t001 TYPE y_t001.
    DATA : it_adrc TYPE STANDARD TABLE OF y_adrc,
            wa_adrc type  y_adrc.
    DATA : it_adrc1 TYPE STANDARD TABLE OF y_adrc1,
           wa_adrc1 TYPE y_adrc1.
    DATA : it_knb1 TYPE STANDARD TABLE OF y_knb1,
           wa_knb1 TYPE y_knb1.
    DATA : it_kna1 TYPE STANDARD TABLE OF y_kna1,
           wa_kna1 TYPE y_kna1.
    DATA : it_knkk TYPE STANDARD TABLE OF y_knkk,
           wa_knkk TYPE y_knkk.
    DATA : it_knkk1 TYPE STANDARD TABLE OF y_knkk1,
           wa_knkk1 TYPE y_knkk1.
    DATA : it_t001s TYPE STANDARD TABLE OF y_t001s,
           wa_t001s TYPE y_t001s.
    *DATA STATEMENTS FOR EMAIL ADDRESSES
    DATA : it_adrt TYPE TABLE OF y_adrt,
           wa_adrt TYPE y_adrt,
           wa_email LIKE t_email.
    *DATA : it_adr6 TYPE TABLE OF y_adr6,
          wa_adr6 TYPE y_adr6,
    DATA : counter TYPE i,
           counter1 TYPE i,
           c5 LIKE spell.
    SELECTION-SCREEN BEGIN OF BLOCK clcn WITH FRAME TITLE text-200.
    SELECTION-SCREEN SKIP.
    PARAMETERS:     p_bukrs LIKE t001-bukrs OBLIGATORY,                    "COMPANY CODE
                    p_kkber LIKE t001-kkber OBLIGATORY.                    "CREDIT CONTROL AREA
    SELECT-OPTIONS: s_kunnr FOR knb1-kunnr OBLIGATORY,                     "CUSTOMER NUMBER
                    s_datum FOR sy-datum OBLIGATORY DEFAULT sy-datum.      "DATE OF CREDIT LIMIT UPDATE
    SELECTION-SCREEN SKIP.
    PARAMETERS : p_simul AS CHECKBOX DEFAULT 'X'.                          "RUN IN SIMULATION MODE
    SELECTION-SCREEN SKIP.
    PARAMETERS : p_lemail LIKE adr6-smtp_addr.                             " EMAIL
    SELECTION-SCREEN END OF BLOCK clcn.
    AT SELECTION-SCREEN.
      PERFORM f0100_validate_bukrs.  "*  For Company Code.
      PERFORM f0200_validate_kkber.  "* For Credit Control Area.
      PERFORM f0300_validate_kunnr.  "* For Customer Number
      PERFORM f0400_validate_datum.  "* For Date of Credit Limit Update
      PERFORM f0500_validate_simul.  "* For simulation mode and e-mail address
    *======================================================================
    START-OF-SELECTION.
      PERFORM f1000_get_customer.          "** COLLECT INFO FOR REPORT DISPLAY
      IF p_simul is initial AND NOT P_lemail IS INITIAL.
        PERFORM F1000_CHECK_GATEWAY_CONNECTION.
      ENDIF.
      IF p_simul IS INITIAL AND  NOT p_lemail IS INITIAL.
        PERFORM f3000_process_data_script USING t_report_display.
      ENDIF.
    END-OF-SELECTION.
      IF NOT p_simul IS INITIAL.
        PERFORM f2000_display_customer USING t_report_display.
      ENDIF.
    FORM f0100_validate_bukrs.
      DATA : w_bukrs TYPE bukrs.
    VALIDATION OF P_BUKRS
      SELECT SINGLE bukrs
                    FROM t001
                    INTO w_bukrs
                    WHERE bukrs EQ p_bukrs.
      IF sy-subrc NE 0.
        MESSAGE e999(zf) WITH 'Invalid Company Code' p_bukrs.   "(E01).
    *AUTHORIZATION CHECK
        AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
                            ID 'BUKRS' FIELD p_bukrs
                            ID 'ACTVT' FIELD '03'.
        IF sy-subrc NE 0.
          MESSAGE e999(zf)  WITH 'No Authorization for company code' p_bukrs."(e06).
        ENDIF.
      ENDIF.
    ENDFORM.                    " F0100_VALIDATE_BUKRS
    *Eject
    *&      Form  F0200_VALIDATE_KKBER
         *-> CREDIT CONTROL AREA AUTHORITY CHECK
    FOR CREDIT CONTROL AREA.
    FORM f0200_validate_kkber.
      DATA : w_kkber LIKE t001-kkber.
      SELECT SINGLE kkber
              FROM t001
              INTO w_kkber
              WHERE bukrs EQ p_bukrs
                AND   kkber EQ p_kkber.
      IF sy-subrc NE 0.
        MESSAGE e999(zf) WITH
       'Credit Control Area' p_kkber 'not defined for Company Code' p_bukrs."(e02).
       MESSAGE e999 WITH text-e02 p_kkber .
      ENDIF.
    ENDFORM.                    "F0200_VALIDATE_KKBER
    *&      Form  F0300_VALIDATE_KUNNR
         *-> CUSTOMER NUMBER AUTHORITY CHECK
    FORM f0300_validate_kunnr.
    VALIDATION OF S_KUNNR
      DATA : w_kunnr TYPE kunnr,
             w_bukrs TYPE bukrs.
      IF s_kunnr IS INITIAL .
        MESSAGE e999 WITH 'Enter Customer Number'(e04).
        SUBMIT (sy-cprog) VIA SELECTION-SCREEN.
      ENDIF.
      LOOP AT s_kunnr.
        CLEAR : w_kunnr,
                w_bukrs.
        IF NOT s_kunnr-low IS INITIAL.
          SELECT SINGLE kunnr bukrs
          FROM knb1 INTO (w_kunnr ,w_bukrs)
          WHERE kunnr EQ s_kunnr-low
          AND bukrs EQ p_bukrs.
          IF sy-subrc NE 0.
            MESSAGE e999(zf)  WITH 'Customer S_KUNNR-LOW not defined in company code' p_bukrs."(e03).
          ENDIF.
        ENDIF. "if not s_kunnr-low is initial.
        IF NOT s_kunnr-high IS INITIAL.
          CLEAR : w_kunnr,
                  w_bukrs.
          SELECT SINGLE kunnr bukrs
          FROM knb1 INTO (w_kunnr , w_bukrs)
          WHERE kunnr EQ s_kunnr-high
          AND bukrs EQ p_bukrs.
          IF sy-subrc NE 0.
            MESSAGE e999(zf)  WITH 'Customer S_KUNNR-HIGH not defined in company code' p_bukrs."(e03).
          ENDIF.
        ENDIF. "if not s_kunnr-high is initial.
      ENDLOOP. " loop at s_kunnr
    ENDFORM.                    " F0200_VALIDATE_KUNNR
    *&      Form  F0400_VALIDATE_DATUM
         *-> DATE OF CREDIT LIMIT UPDATE
    FORM f0400_validate_datum.
      IF s_kunnr IS INITIAL AND s_datum IS INITIAL.
        MESSAGE e999 WITH 'Enter either Date of CL update or Customer number.'(e04).
      ENDIF.
    ENDFORM.                    "F0400_VALIDATE_DATUM
    *&      Form  F1000_GET_CUSTOMER
          text
    -->  p1        text
    <--  p2        text
    FORM f1000_get_customer .
      DATA : w_kunnr LIKE knkk-kunnr,
               w_kkber LIKE knkk-kkber.
      IF s_datum IS NOT INITIAL.
        SELECT objectid
               FROM cdhdr
               INTO TABLE t_cust
               WHERE  objectclas IN ('KLIM','DTREV','NXTRV')
               AND  change_ind IN ('U','I')
               AND udate IN s_datum.
              WHERE ( objectclas EQ 'KLIM' OR objectclas EQ 'DTREV' OR  objectclas EQ 'NXTRV')
              AND  ( change_ind EQ 'U' OR change_ind EQ 'I')
              AND udate IN s_datum .
      ENDIF.
      IF sy-subrc NE 0.
        MESSAGE s999 WITH 'There is no data for selected period'(e07).
      ELSE.
        MOVE t_cust TO t_customer.
      ENDIF.
      SORT t_customer BY kunnr.
      IF NOT t_customer[] IS INITIAL.
        SELECT kunnr
               kkber
               dtrev
               nxtrv
               klimk
               dbwae
               FROM knkk
               INTO TABLE t_knkk
               FOR ALL ENTRIES IN t_customer
               WHERE kunnr = t_customer-kunnr
               AND   kkber = p_kkber.
      ELSE.
        MESSAGE e999 WITH text-e07.
      ENDIF.
      IF sy-subrc NE 0.
      ENDIF.
      SORT t_knkk BY kunnr kkber.
      IF NOT t_knkk[] IS INITIAL.
        SELECT   kunnr
                 name1
        FROM kna1
        INTO TABLE t_custo
        FOR ALL ENTRIES IN t_knkk
        WHERE kunnr = t_knkk-kunnr.
      ENDIF.
      IF sy-subrc = 0.
      ENDIF.
      SORT t_custo BY kunnr kkber.
      LOOP AT t_custo INTO w_custo.
        CLEAR w_knkk.
        READ TABLE t_knkk INTO w_knkk WITH KEY kunnr = w_custo-kunnr
                                      BINARY SEARCH.
        IF sy-subrc = 0.
          w_report_display-kunnr = w_custo-kunnr.
          w_report_display-name  = w_custo-name.
          w_report_display-dtrev = w_knkk-dtrev.
          w_report_display-nxtrv = w_knkk-nxtrv.
          w_report_display-klimk = w_knkk-klimk.
          w_report_display-dbwae = w_knkk-dbwae.
          APPEND w_report_display TO t_report_display .
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " F1000_GET_CUSTOMER
    *&      Form  F2000_DISPLAY_CUSTOMER
          text
         -->P_T_REPORT_DISPLAY  text
    FORM f2000_display_customer  USING    p_t_report_display.
      DATA: no  TYPE n  VALUE 1.
      DATA: t_data TYPE STANDARD TABLE OF y_report_display.
      t_data = p_t_report_display.
      DATA : w_data LIKE LINE OF t_data .
      ULINE (118).
      WRITE:/ sy-vline,
              8 'CREDIT LIMIT CHANGE NOTIFICATION REPORT ON',
              sy-datum , 118 sy-vline.
      ULINE (118).
      WRITE:/ sy-vline,'NO'(008) ,
            10 sy-vline, 11 'CUSTOMER NUMBER',
            28 sy-vline, 29 'CUSTOMER NAME', 43 sy-vline,
            44 'CREDIT LIMIT VALID', 63 sy-vline ,
            64 'CREDIT LIMIT AMOUNT', 85 sy-vline, 86 'CURRENCY',
            95 sy-vline , 96 'Notification Status',118 sy-vline.
      ULINE (118).
      WRITE:/ sy-vline,43 sy-vline, 44 'FROM', 53 sy-vline,
      56 'TILL', 63 sy-vline, 118 sy-vline .
      ULINE (118).
      LOOP AT t_data INTO w_data.
        WRITE:/ sy-vline, no,
              10 sy-vline, 11 w_data-kunnr ,
              28 sy-vline, 29 w_data-name, 43 sy-vline, 44 w_data-dtrev,
              53 sy-vline, 56 w_data-nxtrv ,63 sy-vline ,64 w_data-klimk,
              85 sy-vline, 86 w_data-dbwae,
              95 sy-vline , 118 sy-vline.
        no = no + 1.
        ULINE (118).
      ENDLOOP.
    ENDFORM.                    " F2000_DISPLAY_CUSTOMER
    *&      Form  F3000_PROCESS_DATA_SCRIPT
          text
         -->P_T_REPORT_DISPLAY  text
    FORM f3000_process_data_script  USING    p_t_report_display.
      DATA: t_data TYPE STANDARD TABLE OF y_report_display.
      t_data = p_t_report_display.
      DATA : w_data LIKE LINE OF t_data .
      DATA: temp_is_negative(1) TYPE c,
               temp_text(20)       TYPE c,
               temp_sname          LIKE t001s-sname,
               temp_email          LIKE adr6-smtp_addr.
      DATA : number LIKE spell,
             amount(255) TYPE c.
      PERFORM f3100_initialize_settings.
      LOOP AT t_data INTO w_data.
        AT NEW kunnr.
          CLEAR w_error_found.
          IF p_simul IS INITIAL AND  NOT p_lemail IS INITIAL.
            PERFORM f3300_open_form.
           data:  wa_t001 like line of t001
            DATA : begin of wa_t001,
                   adrnr like t001-adrnr,
                   end of wa_t001.
            SELECT SINGLE
                   adrnr FROM t001 INTO wa_t001
                   WHERE bukrs = p_bukrs.
          DATA: BEGIN OF wa_adrc,
                 addrnumber LIKE adrc-addrnumber,
                 name1 LIKE adrc-name1,
                 post_code1 LIKE adrc-post_code1,
                 city1 LIKE adrc-city1,
                 street LIKE adrc-street,
                 house_num1 LIKE adrc-house_num1,
                 tel_number LIKE adrc-tel_number,
                 nation LIKE adrc-nation ,
                 fax_number LIKE adrc-fax_number,
                 country LIKE adrc-country,
               END OF wa_adrc.
       SELECT SINGLE
                addrnumber
                name1
                post_code1
                city1
                street
                house_num1
                tel_number
                nation
                fax_number
                country
                FROM adrc
                INTO corresponding fields of wa_adrc
                WHERE addrnumber EQ wa_t001-adrnr  AND
                      nation EQ ' '.
            PERFORM f3700_write_form.
            DATA: wa_kna1 LIKE LINE OF t_kna1,
                  wa_adrcc LIKE LINE OF it_adrc.
            SELECT SINGLE
                   kunnr
                   adrnr FROM kna1
                   INTO  wa_kna1
                   WHERE kunnr = w_data-kunnr.
            IF sy-subrc EQ 0.
              SELECT SINGLE
                     addrnumber
                     name1
                     FROM adrc
                     INTO wa_adrcc
                     WHERE addrnumber = wa_kna1-adrnr
                     AND nation = ' '.
            ENDIF.
            PERFORM f3701_write_form.
            DATA : wa_knkk LIKE LINE OF t_knkk.
            DATA : counter TYPE i,
                   counter1 TYPE i.
            IF sy-subrc EQ 0.
          SELECT SINGLE KUNNR
                 DTREV
                 NXTRV
                 KLIMK  FROM KNKK INTO WA_KNKK WHERE
                 KUNNR EQ W_DATA-KUNNR.
            ENDIF.
            CALL FUNCTION 'SPELL_AMOUNT'
             EXPORTING
               amount          = w_knkk-klimk
       CURRENCY        = ' '
       FILLER          = ' '
               language        = sy-langu
             IMPORTING
               in_words        = number.
            IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            ENDIF.
            amount = number-word.
            PERFORM f3702_write_form.
            DATA: wa_knb1 LIKE LINE OF t_knb1.
            IF sy-subrc EQ 0.
              SELECT SINGLE
                     busab
                     FROM   knb1
                     INTO   wa_knb1
                     WHERE  kunnr = w_data-kunnr
                     AND    bukrs = p_bukrs.
            ENDIF.
            DATA : wa_t001s LIKE LINE OF it_t001s.
            IF sy-subrc EQ 0.
              SELECT SINGLE bukrs
                 busab
                 sname
                 FROM t001s
                 INTO wa_t001s
                 WHERE bukrs = wa_knb1-bukrs
                 AND busab = wa_knb1-busab.
            ENDIF.
            PERFORM f3703_write_form.
            PERFORM f3704_write_form.
            IF counter1 < counter.
              PERFORM f3705_write_form.
            ENDIF.
            PERFORM f3706_close_form.
          ENDIF.
        ENDAT.
        IF w_error_found EQ c_true.
        ENDIF.
        AT END OF kunnr.
    PERFORM F3400_WRITE_FORM USING C_TOTAL C_MAIN_WINDOW.
         PERFORM F3500_CLOSE_FORM.
          IF p_simul IS INITIAL AND  NOT p_lemail IS INITIAL.       "Email setting
            PERFORM f3200_get_email_addr USING w_data-kunnr.
            PERFORM f3600_send_data_via_email USING w_data-kunnr.
          ENDIF.
        ENDAT.
      ENDLOOP.
      WRITE:/ ' E-Mail is sent to the customer'.
    ENDFORM.                    " F3000_PROCESS_DATA_SCRIPT
    *&      Form  F3100_INITIALIZE_SETTINGS
          text
    -->  p1        text
    <--  p2        text
    FORM f3100_initialize_settings .
      SELECT SINGLE spld
            INTO itcpo-tddest
            FROM usr01
            WHERE bname EQ sy-uname.
      IF sy-subrc NE 0.
        itcpo-tddest = 'LOCAL'.
      ENDIF.
      w_htddevice      = c_printer.
      itcpo-tddest = ''.
      itcpo-tdrdidev = ''.
      itcpo-tdsenddate = sy-datum.
      itcpo-tdsendtime = sy-uzeit.
      itcpo-tdschedule = 'IMM'.
      itcpo-tdimmed = ' '.
    itcpo-tdnewid    = c_true.            "PRINT: New spool request
      itcpo-tdlifetime = c_1.               "PRINT: Spool retention period
      itcpo-tdgetotf   = c_true.
      IF p_simul IS INITIAL AND  NOT p_lemail IS INITIAL.       "Email setting
        itcpo-tdgetotf     = c_true.
      ENDIF.
    ENDFORM.                    " F3100_INITIALIZE_SETTINGS
    *&      Form  f0500_validate_simul
          text
    -->  p1        text
    <--  p2        text
    FORM f0500_validate_simul .
      IF p_simul IS INITIAL AND p_lemail IS INITIAL.       "Email setting
       MESSAGE e999(zf) WITH 'Enter Email address'.            "(e05).
      ENDIF.
    ENDFORM.                    " f0500_validate_simul
    *&      Form  F3600_SEND_DATA_VIA_EMAIL
          text
         -->P_W_DATA_KUNNR  text
    FORM f3600_send_data_via_email  USING p_w_data_kunnr.
      DATA:   fle1(2)       TYPE p,
              fle2(2)       TYPE p,
              off1          TYPE p,
              hltlines      TYPE i,
              temp_filesize TYPE i,
              hfeld(500)    TYPE c,
              header(50)   TYPE c,
              htabix        LIKE sy-tabix,
              x_sent_to_all LIKE sonv-flag.
      DATA: BEGIN OF x_objcont OCCURS 0.
              INCLUDE STRUCTURE soli.
              INCLUDE STRUCTURE SOLISTI1.
      DATA: END OF x_objcont.
      DATA: BEGIN OF x_object_hd_change.
              INCLUDE STRUCTURE sood1.
      DATA: END OF x_object_hd_change.
      DATA: BEGIN OF x_receivers OCCURS 0.
              INCLUDE STRUCTURE soos1.
             INCLUDE STRUCTURE SOMLRECI1.
      DATA: END OF x_receivers.
      DATA: BEGIN OF x_objhead OCCURS 1.
              INCLUDE STRUCTURE soli.
      DATA: END OF x_objhead.
    **Data: begin of objpack occurs 0.
             include structure SOPCKLSTI1.
    **Data: end of objpack.
    **Data: begin of email_data occurs 0.
             include structure SODOCCHGI1.
    **Data: end of email_data.
    Converts the layout set to PDF format
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = c_pdf_format
        IMPORTING
          bin_filesize          = temp_filesize
        TABLES
          otf                   = t_otfdata
          lines                 = t_htline
        EXCEPTIONS
          err_max_linewidth     = 1
          err_format            = 2
          err_conv_not_possible = 3
          OTHERS                = 4.
      IF sy-subrc NE 0.
        w_error_found = c_true.
        t_error-kunnr = p_w_data_kunnr.
        t_error-comm  = 'Error in conversion to PDF format.'(e08).
        APPEND t_error.
        CLEAR t_error.
        EXIT.
      ENDIF.
    Convert the PDF file into an internal table which to be used in the
    function that will send a PDF file to a email address
      DESCRIBE TABLE t_htline LINES hltlines.
    DESCRIBE FIELD T_HTLINE LENGTH FLE1 IN BYTE MODE.
      DESCRIBE FIELD t_htline LENGTH fle1
                                  IN CHARACTER MODE.
    DESCRIBE FIELD X_OBJCONT LENGTH FLE2 IN BYTE MODE.
      DESCRIBE FIELD x_objcont LENGTH fle2
                                   IN CHARACTER MODE.
      CLEAR x_objcont.
      REFRESH x_objcont.
      LOOP AT t_htline.
        htabix = sy-tabix.
        MOVE t_htline TO hfeld+off1.
        IF htabix = hltlines.
          fle1 = STRLEN( t_htline ).
        ENDIF.
        off1 = off1 + fle1.
        IF off1 GE fle2.
          CLEAR x_objcont.
          x_objcont = hfeld(fle2).
          APPEND x_objcont.
          SHIFT hfeld BY fle2 PLACES.
          off1 = off1 - fle2.
        ENDIF.
        IF htabix = hltlines.
          IF off1 GT 0.
            CLEAR x_objcont.
            x_objcont = hfeld(off1).
            APPEND x_objcont.
          ENDIF.
        ENDIF.
      ENDLOOP.
    LOOP AT t_email.
       x_receivers-receiver = t_email-smtp_addr.
       x_receivers-rec_type = c_u.
       APPEND x_receivers.
    ENDLOOP.
    x_receivers-receiver = p_lemail.
    x_receivers-rec_type = c_u.
    APPEND x_receivers.
    DESCRIBE TABLE x_objcont LINES sy-tfill.
    READ TABLE x_objcont INDEX sy-tfill.
    email_data-doc_size = ( sy-tfill - 1 ) * 255 + STRLEN( x_objcont ).
    CLEAR objpack-transf_bin.
    objpack-head_start = 1.
    objpack-head_num = 0.
    objpack-body_start = 1.
    objpack-body_num = sy-tfill.
    objpack-doc_type = 'RAW'.
    APPEND objpack.
    email_data-obj_descr = 'Notification'.
    APPEND email_data.
    IF x_receivers[] IS NOT INITIAL.
       CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
         EXPORTING
           document_data = email_data
           put_in_outbox = 'X'
           commit_work   = 'X' "used from rel. 6.10
         TABLES
           packing_list  = objpack
           object_header = email_fname
           contents_bin  = email_text
           contents_txt  = x_objcont
           receivers     = x_receivers.
    endif.
      CLEAR x_objhead.
      REFRESH x_objhead.
      CLEAR x_object_hd_change.
      x_object_hd_change-objnam = 'EMAIL'(t04).
      header = 'Procter & Gamble'(t05).
      x_object_hd_change-objdes = header.                         "Title
      x_object_hd_change-objla = c_english.                       "Language
      x_object_hd_change-objsns = c_f.
      x_object_hd_change-objlen = temp_filesize.
      x_object_hd_change-file_ext = c_pdf_format.
    Transfer the email address to an internal table which will be used
    in the function that will send a PDF file to a email address
      CLEAR x_receivers.
      REFRESH x_receivers.
      LOOP AT t_email.
        x_receivers-sndex = c_true.
        x_receivers-sndpri = c_1.
        x_receivers-recesc = c_u.
        x_receivers-recnam = c_recipient_name.
    Populate the email address of the customer
        x_receivers-recextnam = t_email-smtp_addr.
        x_receivers-recesc = c_english.
        x_receivers-sndart = c_int.
        APPEND x_receivers.
      ENDLOOP.
      x_receivers-sndex = c_true.
      x_receivers-sndpri = c_1.
      x_receivers-recesc = c_u.
      x_receivers-recnam = c_recipient_name.
    Populate the Local mail address
      x_receivers-recextnam = p_lemail.
      x_receivers-recesc = c_english.
      x_receivers-sndart = c_int.
      APPEND x_receivers.
    Calling a SAP function to send out email with attachment of PDF file
      CALL FUNCTION 'SO_OBJECT_SEND'
        EXPORTING
          object_hd_change           = x_object_hd_change
          object_type                = c_document_type
          outbox_flag                = c_true
        IMPORTING
          sent_to_all                = x_sent_to_all
        TABLES
          objcont                    = x_objcont
          objhead                    = x_objhead
          receivers                  = x_receivers
        EXCEPTIONS
          active_user_not_exist      = 1
          communication_failure      = 2
          component_not_available    = 3
          folder_not_exist           = 4
          folder_no_authorization    = 5
          forwarder_not_exist        = 6
          note_not_exist             = 7
          object_not_exist           = 8
          object_not_sent            = 9
          object_no_authorization    = 10
          object_type_not_exist      = 11
          operation_no_authorization = 12
          owner_not_exist            = 13
          parameter_error            = 14
          substitute_not_active      = 15
          substitute_not_defined     = 16
          system_failure             = 17
          too_much_receivers         = 18
          user_not_exist             = 19
          x_error                    = 20
          OTHERS                     = 21.
      IF sy-subrc NE 0.
        w_error_found = c_true.
        t_error-kunnr = p_w_data_kunnr.
        t_error-comm  = 'Error in sending email.'(e09).
        APPEND t_error.
        CLEAR t_error.
      ELSEIF sy-subrc EQ 0.
        COMMIT WORK.
    *Transmit Mail
        SUBMIT rsconn01 WITH mode = c_int
        WITH output = c_space
        AND RETURN.
      ENDIF.
    ENDFORM.                    " F3600_SEND_DATA_VIA_EMAIL
    *&      Form  F3200_GET_EMAIL_ADDR
          text
         -->P_T_REPORT_DISPLAY  text
    FORM f3200_get_email_addr USING p_w_data_kunnr.
      REFRESH t_customer.
      REFRESH t_adrt.
      REFRESH t_email.
      DATA: t_data TYPE STANDARD TABLE OF y_report_display.
    t_data = p_t_report_display.
      DATA : w_data LIKE LINE OF t_data .

    Sending mail with attachment
    This program will allowed you to send email with attachment.
    First, specify the attachment file from your local hardisk and execute.
    Next, specify the sender email address and click the send button.
    report y_cr17_mail.
    data method1 like sy-ucomm.
    data g_user like soudnamei1.
    data g_user_data like soudatai1.
    data g_owner like soud-usrnam.
    data g_receipients like soos1 occurs 0 with header line.
    data g_document like sood4 .
    data g_header like sood2.
    data g_folmam like sofm2.
    data g_objcnt like soli occurs 0 with header line.
    data g_objhead like soli occurs 0 with header line.
    data g_objpara like selc occurs 0 with header line.
    data g_objparb like soop1 occurs 0 with header line.
    data g_attachments like sood5 occurs 0 with header line.
    data g_references like soxrl occurs 0 with header line.
    data g_authority like sofa-usracc.
    data g_ref_document like sood4.
    data g_new_parent like soodk.
    data: begin of g_files occurs 10 ,
    text(4096) type c,
    end of g_files.
    data : fold_number(12) type c,
    fold_yr(2) type c,
    fold_type(3) type c.
    parameters ws_file(4096) type c default 'c:\debugger.txt'.
    Can me any file fromyour pc ....either xls or word or ppt etc ...
    g_user-sapname = sy-uname.
    call function 'SO_USER_READ_API1'
    exporting
    user = g_user
    PREPARE_FOR_FOLDER_ACCESS = ' '
    importing
    user_data = g_user_data
    EXCEPTIONS
    USER_NOT_EXIST = 1
    PARAMETER_ERROR = 2
    X_ERROR = 3
    OTHERS = 4
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    fold_type = g_user_data-outboxfol+0(3).
    fold_yr = g_user_data-outboxfol+3(2).
    fold_number = g_user_data-outboxfol+5(12).
    clear g_files.
    refresh : g_objcnt,
    g_objhead,
    g_objpara,
    g_objparb,
    g_receipients,
    g_attachments,
    g_references,
    g_files.
    method1 = 'SAVE'.
    g_document-foltp = fold_type.
    g_document-folyr = fold_yr.
    g_document-folno = fold_number.
    g_document-objtp = g_user_data-object_typ.
    *g_document-OBJYR = '27'.
    *g_document-OBJNO = '000000002365'.
    *g_document-OBJNAM = 'MESSAGE'.
    g_document-objdes = 'sap-img.com testing by program'.
    g_document-folrg = 'O'.
    *g_document-okcode = 'CHNG'.
    g_document-objlen = '0'.
    g_document-file_ext = 'TXT'.
    g_header-objdes = 'sap-img.com testing by program'.
    g_header-file_ext = 'TXT'.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = sy-uname
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header
    FOLMEM_DATA =
    RECEIVE_DATA =
    File from the pc to send...
    method1 = 'ATTCREATEFROMPC'.
    g_files-text = ws_file.
    append g_files.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = g_owner
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header
    method1 = 'SEND'.
    g_receipients-recnam = 'MK085'.
    g_receipients-recesc = 'B'.
    g_receipients-sndex = 'X'.
    append g_receipients.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
    exporting
    method = method1
    office_user = g_owner
    ref_document = g_ref_document
    new_parent = g_new_parent
    importing
    authority = g_authority
    tables
    objcont = g_objcnt
    objhead = g_objhead
    objpara = g_objpara
    objparb = g_objparb
    recipients = g_receipients
    attachments = g_attachments
    references = g_references
    files = g_files
    changing
    document = g_document
    header_data = g_header.
    *-- End of Program
    also try this one for background scheduling the same
    Sending mail with attachment report in Background
    Pay attention because it’s working with output list from spool converted to pdf.
    =================================================================================
    z_send_email_fax_global
    FUNCTION-POOL z_gfaian_mail_fax. “MESSAGE-ID ..
    WORK TABLE AREAS
    TABLES: tsp01.
    INTERNAL TABLES
    DATA: lt_rec_tab LIKE STANDARD TABLE OF soos1 WITH HEADER LINE,
    lt_note_text LIKE STANDARD TABLE OF soli WITH HEADER LINE,
    lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE.
    DATA: lt_objcont LIKE STANDARD TABLE OF soli WITH HEADER LINE,
    lt_objhead LIKE STANDARD TABLE OF soli WITH HEADER LINE.
    DATA: pdf_format LIKE STANDARD TABLE OF tline WITH HEADER LINE.
    TYPES: BEGIN OF y_files,
    file(60) TYPE c,
    END OF y_files.
    DATA: lt_files TYPE STANDARD TABLE OF y_files WITH HEADER LINE.
    DATA: l_objcont LIKE soli OCCURS 0 WITH HEADER LINE.
    DATA: l_objhead LIKE soli OCCURS 0 WITH HEADER LINE.
    STRUCTURES
    DATA: folder_id LIKE soodk,
    object_id LIKE soodk,
    link_folder_id LIKE soodk,
    g_document LIKE sood4,
    g_header_data LIKE sood2,
    g_folmem_data LIKE sofm2,
    g_header_data LIKE sood2,
    g_receive_data LIKE soos6,
    g_ref_document LIKE sood4,
    g_new_parent LIKE soodk,
    l_folder_id LIKE sofdk,
    v_email(50).
    DATA: hd_dat like sood1.
    VARIABLES
    DATA: client LIKE tst01-dclient,
    name LIKE tst01-dname,
    objtype LIKE rststype-type,
    type LIKE rststype-type.
    DATA: numbytes TYPE i,
    arc_idx LIKE toa_dara,
    pdfspoolid LIKE tsp01-rqident,
    jobname LIKE tbtcjob-jobname,
    jobcount LIKE tbtcjob-jobcount,
    is_otf.
    DATA: outbox_flag LIKE sonv-flag VALUE ‘X’,
    store_flag LIKE sonv-flag,
    delete_flag LIKE sonv-flag,
    owner LIKE soud-usrnam,
    on LIKE sonv-flag VALUE ‘X’,
    sent_to_all LIKE sonv-flag,
    g_authority LIKE sofa-usracc,
    w_objdes LIKE sood4-objdes.
    DATA: c_file LIKE rlgrap-filename,
    n_spool(6) TYPE n.
    DATA: cancel.
    DATA: desired_type LIKE sood-objtp,
    real_type LIKE sood-objtp,
    attach_type LIKE sood-objtp,
    otf LIKE sood-objtp VALUE ‘OTF’, ” SAPscript Ausgabeformat
    ali LIKE sood-objtp VALUE ‘ALI’. ” ABAP lists
    CONSTANTS
    CONSTANTS: ou_fol LIKE sofh-folrg VALUE ‘O’,
    c_objtp LIKE g_document-objtp VALUE ‘RAW’,
    c_file_ext LIKE g_document-file_ext VALUE ‘TXT’.
    =================================================================================
    z_send_email_fax2
    FUNCTION z_faian_mail_fax2.
    ””Interface local:
    *” IMPORTING
    *” REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT
    *” REFERENCE(FAX_MAIL_NUMBER) TYPE SO_NAME
    *” REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES
    *” REFERENCE(OBJECT_TYPE) TYPE SO_ESCAPE
    *” TABLES
    *” LT_BODY_EMAIL STRUCTURE SOLI
    *” EXCEPTIONS
    *” ERR_NO_ABAP_SPOOLJOB
    Fist part: Verify if the spool really exists
    SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
    IF sy-subrc NE 0.
    RAISE err_no_abap_spooljob. “doesn’t exist
    ELSE.
    client = tsp01-rqclient.
    name = tsp01-rqo1name.
    CALL FUNCTION ‘RSTS_GET_ATTRIBUTES’
    EXPORTING
    authority = ‘SP01&#8242;
    client = client
    name = name
    part = 1
    IMPORTING
    type = type
    objtype = objtype
    EXCEPTIONS
    fb_error = 1
    fb_rsts_other = 2
    no_object = 3
    no_permission = 4
    OTHERS = 5.
    IF objtype(3) = ‘OTF’.
    desired_type = otf.
    ELSE.
    desired_type = ali.
    ENDIF.
    CALL FUNCTION ‘RSPO_RETURN_SPOOLJOB’
    EXPORTING
    rqident = src_spoolid
    desired_type = desired_type
    IMPORTING
    real_type = real_type
    TABLES
    buffer = l_objcont
    EXCEPTIONS
    no_such_job = 14
    type_no_match = 94
    job_contains_no_data = 54
    no_permission = 21
    can_not_access = 21
    read_error = 54.
    IF sy-subrc EQ 0.
    attach_type = real_type.
    ENDIF.
    CALL FUNCTION ‘SO_FOLDER_ROOT_ID_GET’
    EXPORTING
    owner = sy-uname
    region = ou_fol
    IMPORTING
    folder_id = l_folder_id
    EXCEPTIONS
    OTHERS = 5.
    fill out informations about the header of the email
    CLEAR: g_document.
    g_document-foltp = l_folder_id-foltp.
    g_document-folyr = l_folder_id-folyr.
    g_document-folno = l_folder_id-folno.
    g_document-objtp = c_objtp.
    g_document-objdes = header_mail.
    g_document-file_ext = c_file_ext.
    g_header_data-objdes = header_mail.
    CALL FUNCTION ‘SO_DOCUMENT_REPOSITORY_MANAGER’
    EXPORTING
    method = ‘SAVE’
    office_user = sy-uname
    IMPORTING
    authority = g_authority
    TABLES
    objcont = lt_body_email
    attachments = lt_attachments
    CHANGING
    document = g_document
    header_data = g_header_data
    EXCEPTIONS
    OTHERS = 1.
    folder_id-objtp = l_folder_id-foltp.
    folder_id-objyr = l_folder_id-folyr.
    folder_id-objno = l_folder_id-folno.
    object_id-objtp = c_objtp.
    object_id-objyr = g_document-objyr.
    object_id-objno = g_document-objno.
    link_folder_id-objtp = l_folder_id-foltp.
    link_folder_id-objyr = l_folder_id-folyr.
    link_folder_id-objno = l_folder_id-folno.
    REFRESH lt_rec_tab.
    CLEAR lt_rec_tab.
    lt_rec_tab-sel = ‘X’.
    lt_rec_tab-recesc = object_type. “This field for FAX/MAIL
    lt_rec_tab-recnam = ‘U-’.
    lt_rec_tab-deliver = ‘X’.
    lt_rec_tab-not_deli = ‘X’.
    lt_rec_tab-read = ‘X’.
    lt_rec_tab-mailstatus = ‘E’.
    lt_rec_tab-adr_name = fax_mail_number.
    lt_rec_tab-sortfield = fax_mail_number.
    lt_rec_tab-recextnam = fax_mail_number.
    lt_rec_tab-sortclass = ‘5&#8242;.
    APPEND lt_rec_tab.
    lt_rec_tab-recextnam = fax_mail_number.
    lt_rec_tab-recesc = object_type.
    lt_rec_tab-sndart = ‘INT’.
    lt_rec_tab-sndpri = 1.
    APPEND lt_rec_tab.
    lt_files-file = c_file.
    APPEND lt_files.
    begin of insertion by faianf01
    hd_dat-objdes = header_mail.
    CALL FUNCTION ‘SO_ATTACHMENT_INSERT’
    EXPORTING
    object_id = object_id
    attach_type = attach_type
    object_hd_change = hd_dat
    owner = sy-uname
    TABLES
    objcont = l_objcont
    objhead = l_objhead
    EXCEPTIONS
    active_user_not_exist = 35
    communication_failure = 71
    object_type_not_exist = 17
    operation_no_authorization = 21
    owner_not_exist = 22
    parameter_error = 23
    substitute_not_active = 31
    substitute_not_defined = 32
    system_failure = 72
    x_error = 1000.
    IF sy-subrc > 0.
    ENDIF.
    end of insertion by faianf01
    send email from SAPOFFICE
    CALL FUNCTION ‘SO_OBJECT_SEND’
    EXPORTING
    folder_id = folder_id
    object_id = object_id
    outbox_flag = outbox_flag
    link_folder_id = link_folder_id
    owner = sy-uname
    check_send_authority = ‘X’
    TABLES
    receivers = lt_rec_tab
    note_text = lt_note_text
    EXCEPTIONS
    active_user_not_exist = 35
    communication_failure = 71
    component_not_available = 1
    folder_no_authorization = 5
    folder_not_exist = 6
    forwarder_not_exist = 8
    object_no_authorization = 13
    object_not_exist = 14
    object_not_sent = 15
    operation_no_authorization = 21
    owner_not_exist = 22
    parameter_error = 23
    substitute_not_active = 31
    substitute_not_defined = 32
    system_failure = 72
    too_much_receivers = 73
    user_not_exist = 35.
    ENDIF.
    ENDFUNCTION.
    =================================================================================
    z_send_email_fax
    FUNCTION ZCBFS_SEND_MAIL.
    ””Interface local:
    *” IMPORTING
    *” REFERENCE(SRC_SPOOLID) LIKE TSP01-RQIDENT
    *” REFERENCE(HEADER_MAIL) TYPE SO_OBJ_DES
    *” TABLES
    *” LIST_FAX_MAIL_NUMBER STRUCTURE SOLI
    *” EXCEPTIONS
    *” ERR_NO_ABAP_SPOOLJOB
    DATA: vg_achou(1) TYPE n.
    Fist part: Verify if the spool really exists
    vg_achou = 1.
    DO 60 TIMES.
    SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
    IF sy-subrc IS INITIAL.
    CLEAR vg_achou.
    EXIT.
    ELSE.
    WAIT UP TO 1 SECONDS.
    ENDIF.
    ENDDO.
    IF vg_achou = 1.
    RAISE err_no_abap_spooljob. “doesn’t exist
    ENDIF.
    client = tsp01-rqclient.
    name = tsp01-rqo1name.
    CALL FUNCTION ‘RSTS_GET_ATTRIBUTES’
    EXPORTING
    authority = ‘SP01&#8242;
    client = client
    name = name
    part = 1
    IMPORTING
    type = type
    objtype = objtype
    EXCEPTIONS
    fb_error = 1
    fb_rsts_other = 2
    no_object = 3
    no_permission = 4
    OTHERS = 5.
    IF objtype(3) = ‘OTF’.
    desired_type = otf.
    ELSE.
    desired_type = ali.
    ENDIF.
    CALL FUNCTION ‘RSPO_RETURN_SPOOLJOB’
    EXPORTING
    rqident = src_spoolid
    desired_type = desired_type
    IMPORTING
    real_type = real_type
    TABLES
    buffer = l_objcont
    EXCEPTIONS
    no_such_job = 14
    type_no_match = 94
    job_contains_no_data = 54
    no_permission = 21
    can_not_access = 21
    read_error = 54.
    IF sy-subrc EQ 0.
    attach_type = real_type.
    ENDIF.
    CALL FUNCTION ‘SO_FOLDER_ROOT_ID_GET’
    EXPORTING
    owner = sy-uname
    region = ou_fol
    IMPORTING
    folder_id = l_folder_id
    EXCEPTIONS
    OTHERS = 5.
    fill out informations about the header of the email
    CLEAR: g_document.
    g_document-foltp = l_folder_id-foltp.
    g_document-folyr = l_folder_id-folyr.
    g_document-folno = l_folder_id-folno.
    g_document-objtp = c_objtp.
    g_document-objdes = header_mail.
    g_document-file_ext = c_file_ext.
    g_header_data-objdes = header_mail.
    CALL FUNCTION ‘SO_DOCUMENT_REPOSITORY_MANAGER’
    EXPORTING
    method = ‘SAVE’
    office_user = sy-uname
    IMPORTING
    authority = g_authority
    TABLES
    attachments = lt_attachments
    CHANGING
    document = g_document
    header_data = g_header_data
    EXCEPTIONS
    OTHERS = 1.
    folder_id-objtp = l_folder_id-foltp.
    folder_id-objyr = l_folder_id-folyr.
    folder_id-objno = l_folder_id-folno.
    object_id-objtp = c_objtp.
    object_id-objyr = g_document-objyr.
    object_id-objno = g_document-objno.
    link_folder_id-objtp = l_folder_id-foltp.
    link_folder_id-objyr = l_folder_id-folyr.
    link_folder_id-objno = l_folder_id-folno.
    REFRESH lt_rec_tab.
    LOOP AT LIST_FAX_MAIL_NUMBER.
    lt_rec_tab-recextnam = LIST_FAX_MAIL_NUMBER-LINE.
    lt_rec_tab-recesc = ‘U’.
    lt_rec_tab-sndart = ‘INT’.
    lt_rec_tab-sndpri = 1.
    APPEND lt_rec_tab.
    ENDLOOP.
    lt_files-file = c_file.
    APPEND lt_files.
    hd_dat-objdes = header_mail.
    CALL FUNCTION ‘SO_ATTACHMENT_INSERT’
    EXPORTING
    object_id = object_id
    attach_type = attach_type
    object_hd_change = hd_dat
    owner = sy-uname
    TABLES
    objcont = l_objcont
    objhead = l_objhead
    EXCEPTIONS
    active_user_not_exist = 35
    communication_failure = 71
    object_type_not_exist = 17
    operation_no_authorization = 21
    owner_not_exist = 22
    parameter_error = 23
    substitute_not_active = 31
    substitute_not_defined = 32
    system_failure = 72
    x_error = 1000.
    IF sy-subrc > 0.
    ENDIF.
    send email from SAPOFFICE
    CALL FUNCTION ‘SO_OBJECT_SEND’
    EXPORTING
    folder_id = folder_id
    object_id = object_id
    outbox_flag = outbox_flag
    link_folder_id = link_folder_id
    owner = sy-uname
    TABLES
    receivers = lt_rec_tab
    note_text = lt_note_text
    EXCEPTIONS
    active_user_not_exist = 35
    communication_failure = 71
    component_not_available = 1
    folder_no_authorization = 5
    folder_not_exist = 6
    forwarder_not_exist = 8
    object_no_authorization = 13
    object_not_exist = 14
    object_not_sent = 15
    operation_no_authorization = 21
    owner_not_exist = 22
    parameter_error = 23
    substitute_not_active = 31
    substitute_not_defined = 32
    system_failure = 72
    too_much_receivers = 73
    user_not_exist = 35.
    ENDFUNCTION.
    regards,
    srinivas
    <b>*reward for useful answers*</b>

  • 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;
    /

  • Writing to a flat file using UTL in a procedure

    Hello All,
    I am creating a procedure in which I am trying to write data to a flat file using UTL. Code is shown below:
    CREATE OR REPLACE PROCEDURE wrt_lifungduty IS
       sql_stmt             varchar2(200);
       sql_stmt1            varchar2(200);
       sql_stmt2            varchar2(200);
       v_cur_hdl            integer;
       v_rows_processed     BINARY_INTEGER;
       V_file           UTL_FILE.FILE_TYPE;
       V_flatfile_line      VARCHAR2(98) := NULL;
      V_OBLIGATION_KEY    NUMBER(10);
      V_OBLIGATION_LEVEL  VARCHAR2(6);
      V_KEY_VALUE_1       VARCHAR2(20);
      V_KEY_VALUE_2       VARCHAR2(20);
      V_PARTNER_TYPE      VARCHAR2(6);
      V_PARTNER_ID        VARCHAR2(10);
      V_EXT_INVC_NO       VARCHAR2(30);
      V_EXT_INVC_DATE     DATE;
      V_PAID_DATE         DATE;
      V_PAID_AMT          NUMBER(20,4);
      V_COMP_ID           VARCHAR2(10);
      V_RECEIPT_DATE      DATE;
      V_ORDER_QTY         NUMBER(12,4);
      V_RECEIPT_QTY       NUMBER(12,4);
      V_FRT               NUMBER;
      V_DUTY              NUMBER;
      V_SUPPLIER          NUMBER;
      V_FLAG              VARCHAR2(1);
      V_ELC_COST          NUMBER;
      V_ADJ_ELC           NUMBER;
    Cursor x is
          select OBLIGATION_KEY,OBLIGATION_LEVEL,KEY_VALUE_1,KEY_VALUE_2,PARTNER_TYPE,PARTNER_ID,EXT_INVC_NO,EXT_INVC_DATE
                 ,PAID_DATE,PAID_AMT,COMP_ID,RECEIPT_DATE,ORDER_QTY,RECEIPT_QTY,FRT,DUTY,SUPPLIER,FLAG,ELC_COST,ADJ_ELC
          from RMSBIZ.CT_ANALYZE_LIFUNG_DUTY;    
    BEGIN
    if not UTL_FILE.IS_OPEN(V_file) then
          V_file := UTL_FILE.FOPEN('/exchange/biz/rms2lan','sb_duty.dat','w'); --need to give the location for testing
       end if;
    for x1 in x loop
      V_OBLIGATION_KEY    :=1;
      V_OBLIGATION_LEVEL  :='test';
      V_OBLIGATION_KEY    :=x1.OBLIGATION_KEY;
      V_OBLIGATION_LEVEL  :=x1.OBLIGATION_LEVEL;
      V_KEY_VALUE_1       :=x1.KEY_VALUE_1;
      V_KEY_VALUE_2       :=x1.KEY_VALUE_2;
      V_PARTNER_TYPE      :=x1.PARTNER_TYPE;
      V_PARTNER_ID        :=x1.PARTNER_ID;
      V_EXT_INVC_NO       :=x1.EXT_INVC_NO;
      V_EXT_INVC_DATE     :=x1.EXT_INVC_DATE;
      V_PAID_DATE         :=x1.PAID_DATE;
      V_PAID_AMT          :=x1.PAID_AMT;
      V_COMP_ID           :=x1.COMP_ID;
      V_RECEIPT_DATE      :=x1.RECEIPT_DATE;
      V_ORDER_QTY         :=x1.ORDER_QTY;
      V_RECEIPT_QTY       :=x1.RECEIPT_QTY;
      V_FRT               :=x1.FRT;
      V_DUTY              :=x1.DUTY;
      V_SUPPLIER          :=x1.SUPPLIER;
      V_FLAG              :=x1.FLAG;
      V_ELC_COST          :=x1.ELC_COST;
      V_ADJ_ELC           :=x1.ADJ_ELC;
      V_flatfile_line:=  V_OBLIGATION_KEY||','||
      V_OBLIGATION_LEVEL  ||','||
      V_KEY_VALUE_1       ||','||
      V_KEY_VALUE_2       ||','||
      V_PARTNER_TYPE      ||','||
      V_PARTNER_ID        ||','||
      V_EXT_INVC_NO       ||','||
      V_EXT_INVC_DATE     ||','||
      V_PAID_DATE         ||','||
      V_PAID_AMT          ||','||
      V_COMP_ID           ||','||
      V_RECEIPT_DATE      ||','||
      V_ORDER_QTY         ||','||
      V_RECEIPT_QTY       ||','||
      V_FRT               ||','||
      V_DUTY              ||','||
      V_SUPPLIER          ||','||
      V_FLAG              ||','||
      V_ELC_COST          ||','||
      V_ADJ_ELC;
    V_flatfile_line:= V_OBLIGATION_KEY||','|| V_OBLIGATION_LEVEL;
        UTL_FILE.PUT_LINE(V_file, V_flatfile_line);
    end loop
      commit;
       UTL_FILE.fclose(V_file); 
    END;
                Getting the following errors:
    SQL>Welcome-->
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SYS.UTL_FILE", line 98
    ORA-06512: at "SYS.UTL_FILE", line 157
    ORA-06512: at "RMSBIZ.WRT_LIFUNGDUTY", line 39
    ORA-06512: at line 1
    SQL>Welcome-->39
    39* V_file := UTL_FILE.FOPEN('/exchange/biz/rms2lan','sb_duty.dat','w');
    SQL>Welcome-->
    Does any one know why it is erroring out?
    Thanks,
    Chiru

    the code below works if i take out the last 3 columns while writing to the flat file line.
    CREATE OR REPLACE PROCEDURE wrt_lifungduty IS
       sql_stmt             varchar2(200);
       sql_stmt1            varchar2(200);
       sql_stmt2            varchar2(200);
       v_cur_hdl            integer;
       v_rows_processed     BINARY_INTEGER;
       V_file           UTL_FILE.FILE_TYPE;
       V_flatfile_line      VARCHAR2(98) := NULL;
      V_OBLIGATION_KEY    NUMBER(10);
      V_OBLIGATION_LEVEL  VARCHAR2(6);
      V_KEY_VALUE_1       VARCHAR2(20);
      V_KEY_VALUE_2       VARCHAR2(20);
      V_PARTNER_TYPE      VARCHAR2(6);
      V_PARTNER_ID        VARCHAR2(10);
      V_EXT_INVC_NO       VARCHAR2(30);
      V_EXT_INVC_DATE     DATE;
      V_PAID_DATE         DATE;
      V_PAID_AMT          NUMBER(20,4);
      V_COMP_ID           VARCHAR2(10);
      V_RECEIPT_DATE      DATE;
      V_ORDER_QTY         NUMBER(12,4);
      V_RECEIPT_QTY       NUMBER(12,4);
      V_FRT               NUMBER;
      V_DUTY              NUMBER;
      V_SUPPLIER          NUMBER;
      V_FLAG              VARCHAR2(1);
      V_ELC_COST          VARCHAR2(20);
      V_ADJ_ELC           VARCHAR2(20);
    Cursor x is
          select OBLIGATION_KEY,OBLIGATION_LEVEL,KEY_VALUE_1,KEY_VALUE_2,PARTNER_TYPE,PARTNER_ID,EXT_INVC_NO,EXT_INVC_DATE
                 ,PAID_DATE,PAID_AMT,COMP_ID,RECEIPT_DATE,ORDER_QTY,RECEIPT_QTY,FRT,DUTY,SUPPLIER,FLAG,ELC_COST,ADJ_ELC
          from RMSBIZ.CT_ANALYZE_LIFUNG_DUTY;
    BEGIN
    if not UTL_FILE.IS_OPEN(V_file) then
          V_file := UTL_FILE.FOPEN('/rmsapps/rms803/biz/data/utl_files','sb_duty.csv','w'); --need to give the location for testing
       end if;
    for x1 in x loop
      V_OBLIGATION_KEY    :=nvl(x1.OBLIGATION_KEY,null);
      V_OBLIGATION_LEVEL  :=nvl(x1.OBLIGATION_LEVEL,null);
      V_KEY_VALUE_1       :=x1.KEY_VALUE_1;
      V_KEY_VALUE_2       :=x1.KEY_VALUE_2;
      V_PARTNER_TYPE      :=x1.PARTNER_TYPE;
      V_PARTNER_ID        :=x1.PARTNER_ID;
      V_EXT_INVC_NO       :=x1.EXT_INVC_NO;
      V_EXT_INVC_DATE     :=x1.EXT_INVC_DATE;
      V_PAID_DATE         :=x1.PAID_DATE;
      V_PAID_AMT          :=x1.PAID_AMT;
      V_COMP_ID           :=x1.COMP_ID;
      V_RECEIPT_DATE      :=x1.RECEIPT_DATE;
      V_ORDER_QTY         :=x1.ORDER_QTY;
      V_RECEIPT_QTY       :=x1.RECEIPT_QTY;
      V_FRT               :=x1.FRT;
      V_DUTY              :=x1.DUTY;
      V_SUPPLIER          :=x1.SUPPLIER;
      V_FLAG              :=nvl(x1.FLAG,'0');
      V_ELC_COST          :=to_char(nvl(x1.ELC_COST,0));
      V_ADJ_ELC           :=to_char(nvl(x1.ADJ_ELC,0));
      V_flatfile_line:=  V_OBLIGATION_KEY||','||
      V_OBLIGATION_LEVEL  ||','||
      V_KEY_VALUE_1       ||','||
      V_KEY_VALUE_2       ||','||
      V_PARTNER_TYPE      ||','||
      V_PARTNER_ID        ||','||
      V_EXT_INVC_NO       ||','||
      V_EXT_INVC_DATE     ||','||
      V_PAID_DATE         ||','||
      V_PAID_AMT          ||','||
      V_COMP_ID           ||','||
      V_RECEIPT_DATE      ||','||
      V_ORDER_QTY         ||','||
      V_RECEIPT_QTY       ||','||
      V_FRT               ||','||
      V_DUTY              ||','||
      V_SUPPLIER          ||','||
    -- V_FLAG            ||','||
      V_ELC_COST          ||','||
      V_ADJ_ELC;
        UTL_FILE.PUT_LINE(V_file, V_flatfile_line);
    end loop
      commit;
       UTL_FILE.fclose(V_file);
    EXCEPTION
      WHEN UTL_FILE.INVALID_PATH
      THEN
          DBMS_OUTPUT.PUT_LINE ('error: INVALID_PATH');
      WHEN UTL_FILE.INVALID_MODE
      THEN
          DBMS_OUTPUT.PUT_LINE ('error: INVALID_MODE');
      WHEN UTL_FILE.INVALID_FILEHANDLE
      THEN
          DBMS_OUTPUT.PUT_LINE ('error: INVALID_FILEHANDLE');
      WHEN UTL_FILE.INVALID_OPERATION
      THEN
          DBMS_OUTPUT.PUT_LINE ('error: INVALID_OPERATION');
      WHEN UTL_FILE.READ_ERROR
      THEN
          DBMS_OUTPUT.PUT_LINE ('error: READ_ERROR');
      WHEN UTL_FILE.WRITE_ERROR
      THEN
          DBMS_OUTPUT.PUT_LINE ('error: WRITE_ERROR');
      WHEN UTL_FILE.INTERNAL_ERROR
      THEN
          DBMS_OUTPUT.PUT_LINE ('error: INTERNAL_ERROR');
      WHEN OTHERS THEN
         --     v_error_code := SQLCODE;
    --          v_error_message := SQLERRM;
    --         dbms_output.put_line('ERROR: '||v_error_code);
       --       dbms_output.put_line('ERROR: '||v_error_message);
              RAISE_APPLICATION_ERROR(-20003,'sbduty - aborted');  
    END;
    /It fails as soon as it encounters the V_FLAG in the V_flat_file_line. The data in the table has nulls for the FLAG, and some -ve numbers for the ELC_COST,ADJ_ELC..but that should'nt cause any problems does it?
    Whats wrong with those 3 columns?
    Errors that i get are:
    SQL>Welcome-->BEGIN wrt_lifungduty; END;
    ERROR at line 1:
    ORA-20003: sbduty - aborted
    ORA-06512: at "RMSBIZ.WRT_LIFUNGDUTY", line 117
    ORA-06512: at line 1
    SQL>Welcome-->117
    117* RAISE_APPLICATION_ERROR(-20003,'sbduty - aborted');
    SQL>Welcome-->
    Thanks,
    Chiru

  • HELP!! - Need PL/SQL to write to a flat file!!

    I'm trying to query information about a customer's salesrep, and append the results to a flat file. I'm a beginner, and the following pseudocode is the best I have so far. Any advice would be much appreciated.
    Thanks in advance!!
    Paul
    CREATE OR REPLACE PROCEDURE paul IS
    file_handle utl_file.file_type;
    mgrname CHAR;
    mgrphone CHAR;
    mgrext CHAR;
    BEGIN
    utl_file.open('C:\WINNT\Profiles\pking\Desktop\outputfile.txt','w');
    SELECT
    name
    ,attribute7
    ,attribute8
    INTO
    mgrname
    ,mgrphone
    ,mgrext
    FROM
    ra_salesreps_all
    rem WHERE
    rem X-X-X-X-X
    rem
    rem EXCEPTION
    rem WHEN no_data_found THEN
    rem NULL;
    utl_file.putf(file_handle, mgrname, mgrphone, mgrext);
    utl_file.fclose(file_handle);
    END paul;
    null

    Below is a simple one....
    Procedure WRITE2FILE
    id_h in integer,
    matter in varchar2 default null
    IS
    v_FileHandle utl_file.file_type;
    root_dir varchar2(200);
    file_h varchar2(100);
    BEGIN
    file_h := 'msg_'&#0124; &#0124;id_h&#0124; &#0124;'.txt'; -- you can give dynamic file name
    root_dir := 'unix_or_nt/home/file_dir';
    v_FileHandle := utl_file.fopen(root_dir,file_h,'w');
    if matter is not null then
    utl_file.put_line(v_FileHandle,'Additional Information');
    utl_file.put_line(v_FileHandle,'------------------------------------------------------------------');
    utl_file.put(v_FileHandle,matter);
    utl_file.new_line(v_FileHandle,1);
    utl_file.put_line(v_FileHandle,'------------------------------------------------------------------');
    else
    utl_file.put(v_FileHandle,matter);
    end if;
    utl_file.fflush(v_FileHandle);
    utl_file.fclose_all();
    exception
    when utl_file.invalid_path then
    DBMS_OUTPUT.PUT_LINE('Invalid path:');
    when utl_file.invalid_mode then
    DBMS_OUTPUT.PUT_LINE('invalid_mode');
    when utl_file.invalid_filehandle then
    DBMS_OUTPUT.PUT_LINE('invalid_filehandle');
    when utl_file.invalid_operation then
    DBMS_OUTPUT.PUT_LINE('Invalid_operation. ');
    DBMS_OUTPUT.PUT_LINE('The File is not available.');
    when utl_file.read_error then
    DBMS_OUTPUT.PUT_LINE('read_error');
    when utl_file.write_error then
    DBMS_OUTPUT.PUT_LINE('write_error');
    when utl_file.internal_error then
    DBMS_OUTPUT.PUT_LINE('internal_error');
    when others then
    DBMS_OUTPUT.PUT_LINE(4, 'A problem was encountered while writing the document.');
    end ;
    Calling procedure>>>>>>>>>
    execute write2file(100,'Prints the matter in here.');
    will result in a file with name msg_100.txt and the contents of the file will be...
    Additional Information
    Prints the matter in here.
    1)Make sure the directory has write permissions
    2)Initialization parameter UTL_FILE = 'unix_or_nt/home/file_dir' on database server. If not, then put this in init.ora (ask your DBA) and restart the db.
    3)check the syntax for the '/' and '\' depending on your OS
    null

  • Not able to see full output when run in backgroun

    This is a continuation of my question I previously asked:
    I was trying to write a simple list with lot of headings.
    For example:
    WRITE: /6 'TitleA', 29 'TitleB', 55 'TitleC', 80 'TitleD', 106 'TitleE',
    131 'TitleF', 157 'TitleG', 172 'TitleH', 198 'TitleI'.(it goes upto 400 characters)
    I could not see the list titles after a particular length. So, I adjusted the settings to more than 255 in the report title and yes I can see the full output now. But I can not see the full output (and not able to print full) when I run the report in background.
    So what can I do to see (and able to print) the full output even when I run in background or normal mode? I think there should be some solution for this.
    Thanks.

    Hi,
    Execute this report with spool number. this program will increase the width of the spool.it is SAP utility program.
    Laxman
    *& Report  Y_SPOOL_WIDTH_INCRESE                                       *
    REPORT  y_spool_width_increse     LINE-SIZE 80.              .
    This is a SAP utility report to allow display of
    spool request lists with more than 255 columns in
    releases 4.6B and 4.6C (4.6D kernel must be used)
    PARAMETERS: rqident LIKE tsp01-rqident,
                firstl TYPE i DEFAULT 0,
                lastl TYPE i DEFAULT 0.
    global data from LSPOXTOP
    DATA: rc(10) TYPE c,
    errmsg(100) TYPE c,
    status LIKE sy-subrc,
    dsn_type(8) TYPE c.
    DATA: BEGIN OF data_set_line,
    data_length(5),
    precol(1),
    DATA_LINE(1000),
    data_line(5000), "MODAB
    END OF data_set_line,
    data_set_length(5) TYPE c.
    TABLES: tsp01, tst05, tspoptions.
    DATA: temse_name LIKE tst01-dname,
    temse_client LIKE tst01-dclient,
    temse_handle LIKE rststype-handle,
    temse_part LIKE tst01-dpart,
    temse_objtyp LIKE tst01-dtype,
    temse_rectyp LIKE rststype-rectyp,
    temse_charco LIKE tst01-dcharcod.
    DATA: is_otf.
    global data from LSPOCTOP
    DATA: BEGIN OF spoc
    , escape
    , prtctrl
    , first_bytes(4) " collection of the first bytes of the
    " escape sequences, which I am searching for.
    , prtctrl_start_length TYPE i
    , prtctrl_total_length TYPE i
    , prtctrl_start(10)
    , symbol_low_start(10)
    , symbol_hgh_start(10)
    , symbol_start_length TYPE i
    , icon_start(10)
    , icon_start_length TYPE i
    , icon_sel TYPE i VALUE 1
    , frame_start(10)
    , frame_start_length TYPE i
    , END OF spoc.
    FIELD-SYMBOLS:  TYPE c
    copied from RSPO_DISPLAY_ABAP_SPOOLJOB
    DATA: buffer LIKE data_set_line OCCURS 1000.
    TABLES: tsp02l.
    SELECT SINGLE * FROM tsp01 WHERE rqident = rqident.
    IF sy-subrc <> 0.
      WRITE: / 'Spool request does not exist:'(001), rqident.
      EXIT.
    ENDIF.
    CALL FUNCTION 'RSPO_CHECK_JOB_PERMISSION'
      EXPORTING
        access        = 'DISP'
        spoolreq      = tsp01
      EXCEPTIONS
        no_permission = 1
        OTHERS        = 2.
    IF sy-subrc <> 0.
      WRITE: / 'No authorization to display'(002).
      EXIT.
    ENDIF.
    PERFORM read_data TABLES buffer
    USING tsp01 firstl lastl.
    IF sy-subrc <> 0.
      WRITE: / 'Error reading spoolo request'(003).
      EXIT.
    ENDIF.
    IF is_otf = 'X'.
      WRITE: / 'This spool request is not an ABAP list'(004).
      EXIT.
    ENDIF.
    PERFORM display_data TABLES buffer USING tsp01-rqpaper tsp01-rqident.
    FORM get_spool_line.
      DO.
        IF temse_rectyp+1(1) = 'Y'.
          CALL 'C_RSTS_READ'
          ID 'HANDLE' FIELD temse_handle
          ID 'BUFF' FIELD data_set_line
    ID 'BUFFLG' FIELD 1006
          ID 'BUFFLG' FIELD 5006 "MODAB
          ID 'ALLINE' FIELD 'X'
          ID 'BINARY' FIELD ' '
          ID 'SHOWLG' FIELD 'X'
          ID 'RC' FIELD rc
          ID 'ERRMSG' FIELD errmsg.
          status = sy-subrc.
        ELSE.
          CALL 'C_RSTS_READ'
          ID 'HANDLE' FIELD temse_handle
          ID 'BUFF' FIELD data_set_line+1
    ID 'BUFFLG' FIELD 1005
          ID 'BUFFLG' FIELD 5005 "MODAB
          ID 'ALLINE' FIELD 'X'
          ID 'BINARY' FIELD ' '
          ID 'SHOWLG' FIELD 'X'
          ID 'RC' FIELD rc
          ID 'ERRMSG' FIELD errmsg.
          status = sy-subrc.
          data_set_line(5) = data_set_line+1(5).
          data_set_line-precol = ' '.
          ADD 1 TO data_set_line-data_length.
        ENDIF.
        status = sy-subrc.
        IF status <> 6. " EOF, error condition, or got data
          EXIT.
        ENDIF.
    end of this part, try to open next part
        ADD 1 TO temse_part.
        CALL 'C_RSTS_CLOSE'
        ID 'HANDLE' FIELD temse_handle
        ID 'RC' FIELD rc
        ID 'ERRMSG' FIELD errmsg.
        status = sy-subrc.
        IF status = 0.
          CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
          EXPORTING
          authority = 'SP01'
          client = temse_client "hjl
          name = temse_name
          part = temse_part
          IMPORTING
          charco = temse_charco
    CREATER =
    CREDATE =
    DELDATE =
    MAX_CREDATE =
    MAX_DELDATE =
    NON_UNIQ =
    NOOF_PARTS =
          rectyp = temse_rectyp
    SIZE =
    STOTYP =
    type =
          objtype = temse_objtyp
          EXCEPTIONS
          fb_error = 1
          fb_rsts_other = 2
          no_object = 3
          no_permission = 4
          OTHERS = 5.
          status = sy-subrc.
        ENDIF.
        IF status = 0.
          CALL 'C_RSTS_OPEN_READ'
          ID 'HANDLE' FIELD temse_handle
          ID 'CLIENT' FIELD temse_client "hjl
          ID 'NAME' FIELD temse_name
          ID 'PART' FIELD temse_part
          ID 'TYPE' FIELD temse_objtyp
          ID 'CONV' FIELD ' '
          ID 'ALLINE' FIELD 'X'
          ID 'BINARY' FIELD ' '
          ID 'RECTYP' FIELD temse_rectyp
          ID 'CHARCO' FIELD temse_charco
          ID 'PROM' FIELD 'I'
          ID 'RC' FIELD rc
          ID 'ERRMSG' FIELD errmsg.
          status = sy-subrc.
        ENDIF.
      ENDDO.
      IF status = 4.
        status = 12. "EOF
      ENDIF.
      IF status = 8.
        status = 40. "Line too long
      ENDIF.
      data_set_length = data_set_line-data_length.
    ENDFORM.                    "GET_SPOOL_LINE
    *&      Form  READ_DATA
          text
         -->BUFFER     text
         -->TSP01      text
         -->VALUE(FIRSTtext
         -->VALUE(LAST)text
    FORM read_data TABLES buffer
    USING tsp01 LIKE tsp01 value(first) TYPE i
    value(last) TYPE i.
      DATA: lines TYPE i.
      REFRESH buffer.
      CLEAR is_otf.
      temse_client = tsp01-rqclient.
      temse_name = tsp01-rqo1name.
      temse_part = 1.
      CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
      EXPORTING
      authority = 'SP01'
      client = temse_client
      name = temse_name
      part = temse_part
      IMPORTING
      charco = temse_charco
    CREATER =
    CREDATE =
    DELDATE =
    MAX_CREDATE =
    MAX_DELDATE =
    NON_UNIQ =
    NOOF_PARTS =
      rectyp = temse_rectyp
    SIZE =
    STOTYP =
    type =
      objtype = temse_objtyp
      EXCEPTIONS
      fb_error = 1
      fb_rsts_other = 2
      no_object = 3
      no_permission = 4
      OTHERS = 5.
      IF sy-subrc = 0.
        IF temse_objtyp(3) = 'OTF'.
          is_otf = 'X'.
        ENDIF.
      ELSE.
        EXIT.
      ENDIF.
      CLEAR temse_handle.
      CALL 'C_RSTS_OPEN_READ'
      ID 'HANDLE' FIELD temse_handle
      ID 'CLIENT' FIELD temse_client "hjl
      ID 'NAME' FIELD temse_name
      ID 'PART' FIELD temse_part
      ID 'TYPE' FIELD temse_objtyp
      ID 'CONV' FIELD ' '
      ID 'ALLINE' FIELD 'X'
      ID 'BINARY' FIELD ' '
      ID 'RECTYP' FIELD temse_rectyp
      ID 'CHARCO' FIELD temse_charco
      ID 'PROM' FIELD 'I'
      ID 'RC' FIELD rc
      ID 'ERRMSG' FIELD errmsg.
      status = sy-subrc.
      IF status = 0.
        DO.
          PERFORM get_spool_line.
          IF status <> 0 AND status <> 40 AND status <> 12.
            PERFORM close_job.
            EXIT.
          ENDIF.
          IF status <> 12.                                      " 12 = End
            IF NOT ( data_set_length IS INITIAL ).
              data_set_line-data_length = data_set_length - 1.
            ENDIF.
            ADD 1 TO lines.
            IF lines >= first.
              APPEND data_set_line TO buffer.
            ENDIF.
            IF ( NOT last IS INITIAL ) AND ( lines >= last ).
              EXIT.
            ENDIF.
          ELSE.
            IF lines = 0.
              PERFORM close_job.
              EXIT.
            ENDIF.
            IF lines < first .
              PERFORM close_job.
              EXIT.
            ENDIF.
            EXIT.
          ENDIF.
        ENDDO.
        PERFORM close_job.
      ENDIF.
    ENDFORM.                    "READ_DATA
    FORM CLOSE_JOB *
    FORM close_job.
      IF status <> 0 AND status <> 12.
        CALL 'C_RSTS_CLOSE'
        ID 'HANDLE' FIELD temse_handle
        ID 'RC' FIELD rc
        ID 'ERRMSG' FIELD errmsg.
        MESSAGE e112(po) WITH status rc errmsg RAISING read_error.
      ENDIF.
      CALL 'C_RSTS_CLOSE'
      ID 'HANDLE' FIELD temse_handle
      ID 'RC' FIELD rc
      ID 'ERRMSG' FIELD errmsg.
      status = sy-subrc.
      IF status <> 0.
        MESSAGE e112(po) WITH status rc errmsg RAISING read_error.
      ENDIF.
    ENDFORM.                    "CLOSE_JOB
    *&      Form  DISPLAY_DATA
          text
         -->BUFFER     text
         -->RQPAPER    text
         -->RQID       text
    FORM display_data TABLES buffer USING rqpaper LIKE tsp01-rqpaper
    rqid LIKE tsp01-rqident.
      DATA: line_length TYPE i, gcol TYPE i, glines TYPE i,
      line_length2 LIKE rststype-linelength,
      v, v2.
    CALL FUNCTION 'RSPO_SPOOLDATA_WRITE_INIT'.
      PERFORM spooldata_write_init. "MODAB
    select single * from tspoptions where spoption = 'REALWIDTH'.
    if sy-subrc = 0.
      v = 'X'.
    endif.
    select single * from tspoptions where spoption = 'REALHEIGHT'.
    if sy-subrc = 0.
      v2 = 'X'.
    endif.
      IF NOT v IS INITIAL OR NOT v2 IS INITIAL.
        gcol = 0.
        glines = 0.
        SELECT SINGLE * FROM tsp02l WHERE pjident = rqid
        AND pjnummer = 0.
        IF sy-subrc = 0.
          gcol = tsp02l-columns.
          glines = tsp02l-lines.
        ELSE.
          CALL FUNCTION 'RSPO_GET_SIZE_OF_LAYOUT'
          EXPORTING
          layout = rqpaper
          IMPORTING
    ANSWER =
          columns = gcol
          lines = glines
    PFORMAT =
        ENDIF.
      ENDIF.
      IF gcol < 80 OR v IS INITIAL.
        gcol = 255.
      ENDIF.
      IF glines < 5 OR v2 IS INITIAL.
        glines = 0.
      ENDIF.
      IF gcol >= 1024. "MODAB
        gcol = 1023.
      ENDIF.
      NEW-PAGE NO-HEADING NO-TITLE LINE-SIZE gcol
      LINE-COUNT glines. " make a wide list
      SET BLANK LINES ON.
      LOOP AT buffer.
        data_set_line = buffer.
        IF data_set_line-precol = 'P'.
          IF data_set_line(1) = ' '. " Echter Vorschub ?"
            NEW-PAGE.
          ENDIF.
          CONTINUE.
        ENDIF.
    Zeilenlänge berechnen, falls unbekannt.
        IF data_set_line-data_length IS INITIAL.
          line_length = STRLEN( data_set_line-data_line ).
        ELSE.
          line_length = data_set_line-data_length.
        ENDIF.
        IF line_length > 0.
          line_length2 = line_length.
          PERFORM spooldata_write USING data_set_line-data_line "MODAB
          line_length2
          1.
        ELSE.
          " Leerzeile
          SKIP.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    "DISPLAY_DATA
    copied from RSPO_SPOOLDATA_WRITE
    FORM spooldata_write USING value(spool_data)
    value(data_length) LIKE rststype-linelength
    value(start_pos) LIKE sy-colno.
    function globals
      DATA: lpos LIKE sy-colno
            , rest_len TYPE i
            , area_len TYPE i
            , next_hot TYPE i " offset of next special character
            , cols TYPE i " columns used by special character
            , bytes TYPE i " bytes used by special character
            , hot2
            , hot3
            , hot4
            , hot5
            , hot6
            , hot7
            , BEGIN OF escape_trick
            , x1(1) TYPE x
            , END OF escape_trick
            , the_prtctrl(5) TYPE c
    Because of a problem within the ABAP listprocessing, I shall
    never output the same icon side by side with the same color
    and without a gap.
    As I don't know the data, I will use two different variables
    alternatively.
            , icon_id1 LIKE icons-l4
            , icon_id2 LIKE icons-l4.
      FIELD-SYMBOLS:
      IF start_pos < 2.
    write at / ' ' no-gap.
        NEW-LINE.
        lpos = 1.
      ELSE.
        lpos = start_pos.
      ENDIF.
      rest_len = STRLEN( spool_data ).
      DESCRIBE FIELD spool_data LENGTH area_len IN CHARACTER MODE.
      IF data_length = 0.
        " fine.
      ELSEIF data_length .
    MODAB
          PERFORM write_bigfield USING
          next_hot
          lpos.
    WRITE AT LPOS <PLAIN_TEXT> NO-GAP.
          ADD next_hot TO lpos.
          SUBTRACT next_hot FROM rest_len.
          ASSIGN +6(1).
              ELSE.
                hot7 = '?'.
              ENDIF.
            ELSE.
              hot6 = '?'.
            ENDIF.
          ELSE.
            hot5 = '?'.
          ENDIF.
          IF hot5 = space.
            IF hot6 = space.
              IF hot7 = space.
                IF spoc-icon_sel = 1.
                  WRITE AT lpos(4) icon_id1 AS ICON.
    write at lpos icon_id1 as icon no-gap.
                ELSE.
                  WRITE AT lpos(4) icon_id2 AS ICON.
    write at lpos icon_id2 as icon no-gap.
                ENDIF.
                cols = 4.
                bytes = 7.
              ELSE.
                IF spoc-icon_sel = 1.
                  WRITE AT lpos(3) icon_id1 AS ICON.
    write at lpos icon_id1 as icon no-gap.
                ELSE.
                  WRITE AT lpos(3) icon_id2 AS ICON.
    write at lpos icon_id2 as icon no-gap.
                ENDIF.
                cols = 3.
                bytes = 6.
              ENDIF.
            ELSE.
              IF spoc-icon_sel = 1.
                WRITE AT lpos(2) icon_id1 AS ICON.
    write at lpos icon_id1 as icon no-gap.
              ELSE.
                WRITE AT lpos(2) icon_id2 AS ICON.
    write at lpos icon_id2 as icon no-gap.
              ENDIF.
              cols = 2.
              bytes = 5.
            ENDIF.
          ELSE.
            "rite at lpos(1) icon_id as icon.
            WRITE AT lpos(1) '#' NO-GAP. " Not enough space for any icon.
            cols = 1.
            bytes = 4.
          ENDIF.
        ENDIF.
        IF .
        ELSE.
          EXIT.
        ENDIF.
      ENDWHILE.
    MODAB
      IF rest_len > 0.
        ASSIGN
        rest_len
        lpos.
      ENDIF.
    ENDFORM.                    "SPOOLDATA_WRITE
    *&      Form  WRITE_BIGFIELD
          text
         -->VALUE(FIELDtext
         -->VALUE(LEN) text
         -->VALUE(POS) text
    FORM write_bigfield USING value(field) TYPE c
    value(len)
    value(pos).
      FIELD-SYMBOLS
    DATA: chunk TYPE i.
    WHILE len > 0.
    IF len > 255.
    chunk = 255.
    ELSE.
    chunk = len.
    ENDIF.
    WRITE AT pos field(chunk) NO-GAP.
    ADD chunk TO pos.
    len = len - chunk.
    IF len >
    0.
          field = field+chunk.
        ENDIF.
      ENDWHILE.
    ENDFORM.                    "WRITE_BIGFIELD
    *&      Form  SPOOLDATA_WRITE_INIT
          text
    FORM spooldata_write_init.
      DATA: BEGIN OF escape_trick
      , x1(1) TYPE x
      , END OF escape_trick
      FIELD-SYMBOLS: .
      spoc-first_bytes+0(1) = spoc-prtctrl_start(1).
      spoc-first_bytes+1(1) = spoc-frame_start(1).
      spoc-first_bytes+2(1) = spoc-icon_start(1).
      spoc-first_bytes+3(1) = spoc-symbol_low_start(1).
    ENDFORM.                    "SPOOLDATA_WRITE_INIT

  • Report with email

    hi everyone,
    procedure used:
    i am sending an email using the report program.
    i am using the SAPFORM to send the mail..
    first i am sending the outout to the spool and from there i am sending the email.
    problem occured:
      The details are fetched from spool when i run the program..but when i again send the sanme program i getting the details along with the details of the previous mail...
    let me send the code of what i have used..can anyone try and resolve this problem please..
    *& Report  ZMAIL_SEND
    REPORT  ZMAIL_SEND.
    DATA : x_itcpo               TYPE itcpo,   "SAPscript output interface
           x_itcpp1              TYPE itcpp,  "SAPscript output parameters
           x_itcpp2              TYPE itcpp,
           c_std_text(8)         TYPE c VALUE 'STD_TEXT', "variable that is used in SAP SCRIPT
           it_packing_list       TYPE TABLE OF sopcklsti1 INITIAL SIZE 0 WITH HEADER LINE,
           it_objtxt             TYPE TABLE OF solisti1  INITIAL SIZE 0 WITH HEADER LINE,
           s_spool               TYPE tsp01-rqident,
           it_spool_file         TYPE TABLE OF soli      INITIAL SIZE 0 WITH HEADER LINE,
           v_sender              TYpe soextreci1-receiver VALUE '[email protected]',
           c_addr_type           TYPE soextreci1-adr_typ VALUE 'INT',
           it_reclist            TYPE TABLE OF somlreci1 INITIAL SIZE 0 WITH HEADER LINE,
           v_receiver            TYPE somlreci1-receiver VALUE '[email protected]',
           x_docdata             TYPE sodocchgi1,
           tab_lines             TYPE sy-tabix,
           lin1 TYPE i.
    ------ Printer settings structure  -
    x_itcpo-tddest = ''.
    x_itcpo-tdrdidev = ''.
    x_itcpo-tdnewid = 'x'.
    x_itcpo-tdsenddate = sy-datum.
    x_itcpo-tdsendtime = sy-uzeit.
    x_itcpo-tdschedule = 'IMM'.
    x_itcpo-tdimmed = ' '.
    CALL FUNCTION 'OPEN_FORM'
    EXPORTING
      APPLICATION                       = 'TX'
      ARCHIVE_INDEX                     =
      ARCHIVE_PARAMS                    =
       device                            = 'PRINTER'
       dialog                            = 'X'
       form                              = 'ZTEST_FORM '
       language                          = sy-langu
       options                           = x_itcpo
      MAIL_SENDER                       =
      MAIL_RECIPIENT                    =
      MAIL_APPL_OBJECT                  =
      RAW_DATA_INTERFACE                = '*'
      SPONUMIV                          =
    IMPORTING
      LANGUAGE                          =
      NEW_ARCHIVE_PARAMS                =
      RESULT                            =  X_ITCPP1
    EXCEPTIONS
      CANCELED                          = 1
      DEVICE                            = 2
      FORM                              = 3
      OPTIONS                           = 4
      UNCLOSED                          = 5
      MAIL_OPTIONS                      = 6
      ARCHIVE_ERROR                     = 7
      INVALID_FAX_NUMBER                = 8
      MORE_PARAMS_NEEDED_IN_BATCH       = 9
      SPOOL_ERROR                       = 10
      CODEPAGE                          = 11
      OTHERS                            = 12
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    *Assigning the standard text name
    CALL FUNCTION 'TEXT_SYMBOL_SETVALUE'
      EXPORTING
        name            = c_std_text
        value           = 'ZTEST_STD1'
        value_length    = 0
        replace_symbols = 'x'.
    CALL FUNCTION 'WRITE_FORM'
    EXPORTING
       element                        = 'E05_HEADER '
       function                       = 'SET'
       type                           = 'BODY'
       window                         = 'MAIN'
    IMPORTING
      PENDING_LINES                  =
    EXCEPTIONS
      ELEMENT                        = 1
      FUNCTION                       = 2
      TYPE                           = 3
      UNOPENED                       = 4
      UNSTARTED                      = 5
      WINDOW                         = 6
      BAD_PAGEFORMAT_FOR_PRINT       = 7
      SPOOL_ERROR                    = 8
      CODEPAGE                       = 9
      OTHERS                         = 10
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'WRITE_FORM'
    EXPORTING
       element                        = 'ELEMENT1'
       function                       = 'SET'
       type                           = 'BODY'
       window                         = 'MAIN'
    IMPORTING
      PENDING_LINES                  =
    EXCEPTIONS
      ELEMENT                        = 1
      FUNCTION                       = 2
      TYPE                           = 3
      UNOPENED                       = 4
      UNSTARTED                      = 5
      WINDOW                         = 6
      BAD_PAGEFORMAT_FOR_PRINT       = 7
      SPOOL_ERROR                    = 8
      CODEPAGE                       = 9
      OTHERS                         = 10
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'WRITE_FORM'
    EXPORTING
       element                        = 'E05_FOOTER '
       function                       = 'SET'
       type                           = 'BODY'
       window                         = 'MAIN'
    IMPORTING
      PENDING_LINES                  =
    EXCEPTIONS
      ELEMENT                        = 1
      FUNCTION                       = 2
      TYPE                           = 3
      UNOPENED                       = 4
      UNSTARTED                      = 5
      WINDOW                         = 6
      BAD_PAGEFORMAT_FOR_PRINT       = 7
      SPOOL_ERROR                    = 8
      CODEPAGE                       = 9
      OTHERS                         = 10
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'CLOSE_FORM'
    IMPORTING
       RESULT                         =  x_itcpp2
      RDI_RESULT                     =
    TABLES
      OTFDATA                        =
    EXCEPTIONS
       UNOPENED                       = 1
       BAD_PAGEFORMAT_FOR_PRINT       = 2
       SEND_ERROR                     = 3
       SPOOL_ERROR                    = 4
       CODEPAGE                       = 5
       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.
    ***********************EXECUTES SUCCESSFULLY UNTIL THIS*********************************
    ------- spool no. of the spool generated -
    s_spool = x_itcpp2-tdspoolid.
    ------- Fetching of the spool contents -
    IF NOT s_spool IS INITIAL.
      CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
        EXPORTING
          rqident                    = s_spool
         first_line                 = 1
         last_line                  = 1000
         desired_type               = 'RAW'
    IMPORTING
      REAL_TYPE                  =
      SP_LANG                    =
        TABLES
          buffer                     = it_spool_file "mail content
      BUFFER_PDF                 =
    EXCEPTIONS
      NO_SUCH_JOB                = 1
      JOB_CONTAINS_NO_DATA       = 2
      SELECTION_EMPTY            = 3
      NO_PERMISSION              = 4
      CAN_NOT_ACCESS             = 5
      READ_ERROR                 = 6
      TYPE_NO_MATCH              = 7
      OTHERS                     = 8
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDIF.
    CALCULATING THE NO OF RECORDS IN IT_SPOOL_FILE************
    DESCRIBE TABLE it_spool_file LINES lin1.
    *------ Filling the spool contents into internal table obtxt,-----
    *------ whose contents will be displayed as the body of email -
    IF lin1 GT 0.
      LOOP AT it_spool_file.
        it_objtxt-line = it_spool_file-line.
        APPEND it_objtxt.
        CLEAR it_objtxt.
        CLEAR it_spool_file-line.
      ENDLOOP.
    ENDIF.
    DESCRIBE TABLE it_objtxt LINES tab_lines.
    READ TABLE it_objtxt INDEX tab_lines.
    *------ Calculating doc. size which is email -
    x_docdata-obj_name  = 'ZTEST_STD1'.
    x_docdata-obj_descr = 'HAI TEST'.
    x_docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
    *THIS SET OF CODE IS TO UPDATE THE RECEIVER EMAIL ADDRESS
    CLEAR it_reclist.
    REFRESH it_reclist.
    it_reclist-receiver = v_receiver.
    it_reclist-rec_type = 'U'.
    it_reclist-copy = 'x'.
    it_reclist-blind_copy = ' '.
    APPEND it_reclist.
    *contains the document description
    CLEAR it_packing_list.
    REFRESH it_packing_list.
    it_packing_list-transf_bin = space.
    it_packing_list-head_start = 1.
    it_packing_list-head_num = 0.
    it_packing_list-body_start = 1.
    DESCRIBE TABLE it_objtxt LINES it_packing_list-body_num.
    it_packing_list-doc_type = 'RAW'.
    APPEND it_packing_list.
    *this is the function module which sends the mail
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
      EXPORTING
        document_data                   = x_docdata
       put_in_outbox                    = 'X'
       sender_address                   =  v_sender  "senders mail address
       sender_address_type              = 'INT'
       commit_work                      = 'X'
    IMPORTING
      SENT_TO_ALL                      =
      NEW_OBJECT_ID                    =
      SENDER_ID                        =
      TABLES
       packing_list                     = it_packing_list
      OBJECT_HEADER                    =
      CONTENTS_BIN                     =
       contents_txt                     = it_objtxt  "this is the table which contains the content of the mail
      CONTENTS_HEX                     =
      OBJECT_PARA                      =
      OBJECT_PARB                      =
        receivers                        = it_reclist        "contains the receivers mail id
    EXCEPTIONS
      TOO_MANY_RECEIVERS               = 1
      DOCUMENT_NOT_SENT                = 2
      DOCUMENT_TYPE_NOT_EXIST          = 3
      OPERATION_NO_AUTHORIZATION       = 4
      PARAMETER_ERROR                  = 5
      X_ERROR                          = 6
      ENQUEUE_ERROR                    = 7
      OTHERS                           = 8
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    Hi Satheesh,
    <b>1</b>.
    Actually Spool rq no is stored in the table tsp01.If that is giving problem ,try to use this logic.It also works fine.
    CONCATENATE sy-repid0(9) sy-uname0(3) INTO tsp01-rq2name.
      SELECT MAX( rqcretime )
       FROM tsp01
       INTO tsp01-rqcretime
       WHERE rq2name = tsp01-rq2name.
      IF sy-subrc = 0.
        SELECT  SINGLE *
          FROM  tsp01
          WHERE rqcretime = tsp01-rqcretime.
        IF sy-subrc <> 0.
          MESSAGE s000(0k) WITH 'Spool Number does not exist'.
          EXIT.
        ENDIF.
      ENDIF.
    <b>2</b>.
    It gives Latest Spool no for this program .
    <b>Thanks,
    Venkat.O</b>

Maybe you are looking for

  • Move Table Column with AppleScript in Microsoft Word

    Microsoft Word has a flaw (in my opinion) with tables in that it aligns the left and right text with the margins rather than aligning the table columns with the margins. This results in sloppy tables, because the left and right borderlines lie outsid

  • Is it possible to create data control from wsdl when complextype is used

    Getting DCA-40015 error when trying to create a data control from WSDL file. The error clearly says complextype is not supported . just trying to see if there are any workarounds . because creating data control will save time in developing user inter

  • Sun Fire V490 dropping network connnections

    Hi We are having some issues on v490. Network connections are getting drop and users are getting given below error remote host : Connection reset by peer aocdbs02a:root# fmdump -v -u 5b137743-2acf-ceb5-bfde-f4604e3f6d4f TIME UUID SUNW-MSG-ID Nov 02 1

  • 9c error (no usb ports used)

    I tried booting up my pc and I keep getting 9c errors, even though I unplugged and replugged all the wiring in my motherboard (MSI z97 Gaming 5). Even after removing all the usb connectors to my motherboard I keep getting 9c errors, there are no usb

  • Can a location be renamed?

    Can the name of the location associated with a photo/pin be changed without moving the pin? For example I have a pin at my home address.  Mousing over the pin reveals the name of the town nearby. I don't live in that town (nor in any town) and would