Table to file

Hi everybody...
I want to extract data from database table and insert into a file. What is the best method performance wise. I am writing this in Proc.
Thanks in advance....

You can make use of the utility UTL_FILE_DIR.
Demo:-Read/Write
CREATE OR REPLACE PROCEDURE rw_demo IS
InFile utl_file.file_type;
OutFile utl_file.file_type;
vNewLine VARCHAR2(4000);
i PLS_INTEGER;
j PLS_INTEGER := 0;
SeekFlag BOOLEAN := TRUE;
BEGIN
InFile := utl_file.fopen('CTEMP', 'in.txt','r');
OutFile := utl_file.fopen('CTEMP', 'out.txt', 'w');
IF utl_file.is_open(InFile) THEN
LOOP
BEGIN
utl_file.get_line(InFile, vNewLine);
i := utl_file.fgetpos(InFile);
dbms_output.put_line(TO_CHAR(i));
utl_file.put_line(OutFile, vNewLine, FALSE);
utl_file.fflush(OutFile);
IF SeekFlag = TRUE THEN
utl_file.fseek(InFile, NULL, -30);
SeekFlag := FALSE;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
END LOOP;
COMMIT;
END IF;
utl_file.fclose(InFile);
utl_file.fclose(OutFile);
EXCEPTION
WHEN others THEN
RAISE_APPLICATION_ERROR (-20099, 'Unknown UTL_FILE Error');
END rw_demo;
/

Similar Messages

  • Error when opening table container file keydb read only

    Hi Guys,
    We are installing solution manager 4.0 on windows/sql but we are getting following error and couldnt continue the installation
    FKD-00070  Error when opening table container file C:\PROGRA1\SAPINS1\SOLMAN\SYSTEM\MSS\CENTRAL\AS\keydb.xml for writing. Possible reason: "read-only"
    ERROR 2008-06-04 20:10:56.843
    FKD-00049  XML - Parser error: error: no DTD specified, can't validate in line 1, 1
    in file C:\Program Files\sapinst_instdir\SOLMAN\SYSTEM\MSS\CENTRAL\AS\keydb.xml.
    Please help
    Regards,
    Santosh

    Further info
    keydb.xml is empty and the directory has got write access for everyone
    regards
    Edited by: Santosh Keerti on Jun 4, 2008 1:29 PM

  • Transfer intenal table to file

    Hi abaers,
    i need to transfer the internal table data to file,,this file to create in application server.
    internal table lineitems contains 100 fields...
    i tried in the following method: but 100 fields i have to move each and evry field to t_output-data.. so it is becoming complex.
    data: begin of t_output occurs 0,
         data(800),
       end of t_output.
    loop at lineitems.
    t_output-data(4) = lineitems-COMP_CODE.
    t_output-data+4(10) = lineitems-VENDOR.
    append t_output.
    clear t_output.
    endloop.
       open dataset filename for output in text mode encoding default.
       loop at t_output.
          transfer t_output-data to filename.
         clear t_outpu-data.
       endloop.
       close dataset filename.
    endif.
    is there any other method to do direct transfer from internal table to file..

    Hi,
    I think FM: GET_COMPONENT_LIST would be very useful to u.
    i have attached the complete code and it's working absolutely fine with me.
    Code **********
    types: begin of type_item,
            f1(3),
            f2(3),
            f3(3),
            f4(3),
           end of type_item.
    types: begin of type_data,
            data(800),
           end of type_data.
    data : lineitems type table of type_item with header line,
           t_output type table of type_data with header line,
           fieldlist type table of RSTRUCINFO with header line.
    lineitems-f1 = 'a1'.
    lineitems-f2 = 'a2'.
    lineitems-f3 = 'a3'.
    lineitems-f4 = 'a4'.
    append lineitems.
    lineitems-f1 = 'b1'.
    lineitems-f2 = 'b2'.
    lineitems-f3 = 'b3'.
    lineitems-f4 = 'b4'.
    append lineitems.
    lineitems-f1 = 'c1'.
    lineitems-f2 = 'c2'.
    lineitems-f3 = 'c3'.
    lineitems-f4 = 'c4'.
    append lineitems.
    lineitems-f1 = 'd1'.
    lineitems-f2 = 'd2'.
    lineitems-f3 = 'd3'.
    lineitems-f4 = 'd4'.
    append lineitems.
    field-symbols : <fs> type any.
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        PROGRAM    = sy-repid
        FIELDNAME  = 'lineitems'
      TABLES
        COMPONENTS = fieldlist.
    data : fieldname like fieldlist-compname,data_line type type_data,dref
    type ref to data.
    format color 3.
    loop at lineitems REFERENCE INTO dref. .
    loop at fieldlist.
        fieldname =  fieldlist-compname .
        assign dref->(fieldname) to <fs>.
      concatenate data_line <fs> into data_line .
    endloop.
    append data_line to t_output.
    clear data_line.
    endloop.
    loop at t_output.
      write:/ t_output.
    endloop.
    Code *************
    If u still have any issues please revert back.
    Hope it'll help u.
    Regards,
    Ankur

  • Deployed components in table or file

    Hi,
    I'm looking for a table or file where the level of my j2ee components is stored.
    It should have the contents of the systeminfo->'all componnents', but I want to read it with a script so I need a file oder table.
    Thanks
    Jan

    I have used the following link as a reference while doing coding for GOS. may this will give you some hint.
    http://it.toolbox.com/wiki/index.php/Downloading_attachments_of_services_for_objects

  • Oracle 11g - External Table/Remote File Issue?

    Oracle 11g - External Table/Remote File Issue?
    =============================
    I hope this is the right forum for this issue, if not let me, where to go.
    We are using Oracle 11g (11.2.0.1.0) on (Platform : solaris[tm] oe (64-bit)), Sql Developer 3.0.04
    We are not allowed to put files on the CSV file system (Server A), where DB instance is running. We are able place CSV files on another server(Server B), where DB instance is not running.
    We are trying to use oracle external table to load text files in .CSV format.
    How do we create a Directory (Create Directory) on Server A DB to point to File system of Server B?
    Is it feasible?
    Any idea?
    Thanks in helping.

    The Solaris DBA should be able to mount the filesystem for you. Either that or you have to get creative transferring the file like this;
    http://www.linkedin.com/groups/Getting-creative-external-table-preprocessor-140609.S.50474382?qid=ba673ce4-c4bb-40c5-8367-52bd2a2dfc80&trk=group_search_item_list-0-b-ttl&goback=%2Egmp_140609
    Cheers
    David

  • Dynamicall​y Changing Table to File - Advice?

    My current setup for logging data selected by the user has been to a simple csv file with each read going to a new line.
    This has proved to be very annoying as the user must then reformat this file to their liking.  An example would be that the user requested a voltage and current at the same time and would like them to be in separate columns on the same row.
    Example:
    Before
    Time,Measurement,Value
    0:10:00,Voltage Measure,5.1
    0:10:00,Current Measure,.12
    0:20:00,Voltage Measure,4.2
    0:20:00,Current Measure,.23
    After
    Time,Voltage Measure,Current Measure
    0:10:00,5.1,.12
    0:20:00,4.2,.23
    and so on...
    So I have decided to allow the user to assign Measurements to a certain "column" in a table.  And for every measurment at that time (1 second intervals), it gets put into the apropriate column.  Then if a measurement comes at a different time, go to the next row and keep going.
    My issue is if there is an efficient way to go from a table to file??  I know there is ArrayToFile but didn't see any TableToArray or TableToFile (csv type) (may add that as a request).
    Code replies are appreciated since I would want this to be as efficient as possible.
    Dependent on people's replies would indicate how often I should flush to the output.  
    Thanks

    Never tested it against efficiency, but the easiest way of passing data table to a file is using the clipboard: the following code reads an entire table into the clipboard and creates a file with table content; columns are tab-separated, rows are ended with usual CRLF termination, empty cells are honoured; the file can be read next with notepad.
        int        avail, fH = 0;
        char    *txt = NULL;
            ClipboardPutTableVals (panel, control, VAL_TABLE_ENTIRE_RANGE);
            ClipboardGetText (&txt, &avail);
            if (avail) {
                fH = OpenFile ("table.txt", VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_ASCII);
                WriteFile (fH, txt, strlen (txt));
                CloseFile (fH);
            if (txt) free (txt);
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Open Hub Destination Table Vs File

    Hello Experts,
    We have a requirement to send data from BW to 3rd party system every day. In the Open hub destination we have two options for the target.
    1. Table
    2. File
    ETL tool like Informatica will extract the data from table or file into 3rd party sytem.
    Which way is the best in performance and maintenance?
    Thanks in advance
    Sree

    Hi,
    If you follow the delta mechanism then table is good. You can also go for File not a problem. See the both eamples in the following articles.
    If you use Fiels then go for Application Server option, i.e. AL11 becasue no one can change teh files in this location, you can restrict the authorizations.
    Open Hub Destination: Part 1
    http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/business-intelligence/m-o/open%20hub%20destination%3a%20part%201.pdf
    Open Hub Destination: Part 2
    http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/business-intelligence/m-o/open%20hub%20destination%3a%20part%202.pdf
    Thanks
    Reddy

  • Getting the Datatype error data into a table or file

    Hi experts,
    I have a scenario where I need to capture the datatype mismatch records between source & target or the data length error records into a table or file.
    For example.
    1. I have source table column of datatype varchar which is mapped to a target table column of datatype Integer.
    2. I have source table column of datatype varchar2(2000) is mapped to a target table column of datatype varchar2(200).
    I know that while interface execution, if any of the above scenario comes an error occurs respectively and execution stops.
    My question is whether is there anyway to capture those types of records and insert into a table or file. If yes kindly suggest me how to do it.
    Thanks in advance

    Hi Siva,
    Use SqlUnload tool to capture error out records in excel file.
    Hope this will helps you
    Thanks,
    Phani

  • Export of IMG tables to files

    Hello !
    I'm a forum newbie so please forgive me if this post should be in another group, but it seems to me like kind of "general" question though :).
    I have to make a backup of all configuration made by IMG. Actually I have to export all tables to files.
    I can't find any nice solution so I'm using S_CUS_IMG_SELECT_NODES function to get all IMG nodes and I analyze them to see where are the data related.
    By reading activities and references in most cases I can get names of maintenance views or cluster tables views.
    For now I have the following problems:
    - how to read data from maintenance view to a internal table?
      I guess I have to analyze how this view is build, make a genuine select with joins which will select the same data as the view and then store this data to a file. Any other solutions?
    - how can I read and store data from cluster tables views?
    This seems to be quite complicated problem so maybe any other solutions to solve it?
    Thank You in advance for any insights on this matter and I would appreciate any help You can give me.
    Saturnin Swedrak

    In the new SQL Developer Early Adopter the export feature (now renamed to unload) has been vastly reworked and improved, and has the option to export to multiple files, you can give this a try.
    Mind there is a missing feature (export to clipboard) that has been removed by mistake in the EA, it will be restored for the production release, and for the next EA's.

  • Table to File using ODI Procedure

    Pls help me ...describing what are the steps in ODI need for loading a RDBMS table to File using ODI Procedure....not using Interface and OdiSqlUnload
    Thanks in Advance

    You can use Java Beanshell or Jython to load data in to a file. The only thing is that you need to create a connection so that you can run the select query and get the resultset. Now write it using your rest code.
    If i would have been in your situtation i would prefer Java Beanshell ( not good in jython ;) . Dev can help you on this.). The readymade query is already here
    http://odiexperts.com/generate-column_name-header-for-odisqlunload/
    Thanks.

  • What happens to table when file is transfering ?

    There is code in Z-program which puts a 'Z' in the blocked field of ZCCOD whenever a file is transmitted.
    I mean file is transfering from SAP to mainframes
    Can anybody tell what happens if the table is in <b>edit mode</b> (e.g., via SM30) at the time of transmit?  Do the changes get lost or do they get queued up or what?
    Could you please you please explan in detail. You correct(no guessings please ) explanation is highly appreciated.

    The Z-Program will update the database irrespective of the table being edited in SM30. The user won’t see the updated data until he comes out of the existing transaction and goes back again.
    <b>Nothing is queued up.</b>
    Also if the program updates the data and if the user editing the table in SM30 saves his changes, the changes made by the Z-program will be overwritten.
    The best way to avoid this problem is to add a check in your Z-program. Use the function ENQUEUE_READ to check if the table key the program is trying to update is locked and perform further processing.
    -Kiran

  • Write Table to file (Excel or otherwise) in background

    Hello All,
    I am new the ABAP programming with only self training (two weeks).  I have searched forums for 4 days trying to find usable solutions.  I am writing directly to see if someone can point me in the correct direction.
    I have to output data from multiple tables into a file for transmission to another site.  My first attempt used the OPEN DATASET and a TRANSFER.  This works in interactive and in background mode, but the lines in file are truncated at 255 characters, this was true for both TEXT mode and BINARY mode.
    My second attempt used the GUI_DOWNLOAD to put the file into a tab delimited excel type format.  This gets all the fields and all the characters, but can't be run in background mode.
    How can I get a file that has a  line lenth of about 600 characters into a file for FTP?
    Thanks for assistance,
    Steven M Engel
    Attempt 1 - Problem is that the lines in p_file are limited to 255 characters.
        OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
       OPEN DATASET p_file FOR OUTPUT IN BINARY MODE.
        IF sy-subrc = 0.
          LOOP AT gt_delivery.
            TRANSFER txt_delivery     TO p_file.
          ENDLOOP.
        ENDIF.
        WRITE: 'File has been generated'.
    Attempt 2 - Problem is that can't be run in background mode.
    Export the file
    call function 'GUI_DOWNLOAD'
       exporting
         FILENAME                = LV_FILE
         FILETYPE                = 'DBF'
       tables
         DATA_TAB                = gt_delivery
         FIELDNAMES              = LT_FIELDNAMES
       exceptions
         FILE_WRITE_ERROR        = 1
         NO_BATCH                = 2
         GUI_REFUSE_FILETRANSFER = 3
         INVALID_TYPE            = 4
         NO_AUTHORITY            = 5
         UNKNOWN_ERROR           = 6
         HEADER_NOT_ALLOWED      = 7
         SEPARATOR_NOT_ALLOWED   = 8
         FILESIZE_NOT_ALLOWED    = 9
         HEADER_TOO_LONG         = 10
         DP_ERROR_CREATE         = 11
         DP_ERROR_SEND           = 12
         DP_ERROR_WRITE          = 13
         UNKNOWN_DP_ERROR        = 14
         ACCESS_DENIED           = 15
         DP_OUT_OF_MEMORY        = 16
         DISK_FULL               = 17
         DP_TIMEOUT              = 18
         FILE_NOT_FOUND          = 19
         DATAPROVIDER_EXCEPTION  = 20
         CONTROL_FLUSH_ERROR     = 21
         not_supported_by_gui    = 22
         error_no_gui            = 23
         others                  = 24.

    It is very difficult to get FM GUI_DOWNLOAD to run in the background. There is a white paper out there that describes how to do it, but I never heard of it actually being done successfully.
    The TRANSFER statement should work for wider records. You can check that it does by reading the file back in and then looking at an offset (rec+255).
    Rob

  • EPMA 11.1.2.2, EPMA Interface tables, .ADS File

    DRM Gurus!
    I'm looking for recommendations for updating EPMA with DRM. Thoughts about loading the EPMA interface tables vs using the new EPMA interface that comes with DRM 11.1.2.2 (creates the .ads file)? This client is going to have a large number of attributes... in case that matters. Recommendations are appreciated!
    Cheers!

    Use the DRM to EPMA templates to create .ADS files.  I tend to be a late adopter of new software, i.e., DRM to EPMA using the DRM Web Services API.  Wait until the bugs have been ironed out and then try the new adapter on your next gig perhaps.

  • Transfering data from bsis table to file on application server

    Hi Gurus,
    In my program iam selecting data from bsis table and transferring to file on the application server.
    Code:
    Tables: BSIS.
    data: file type rlgrap-filename.
    Select * from BSIS into BSIS.
    Open dataset output in text mode encoding default.
    Transfer bsis to file.
    closesdataset.
    1, Issue when transferring iam getting dump due to type conflict.
    2, Here I cant create a structure like bsis and define type c  
        varialbles as its an upgrade project.
    3, I tried field-symbols using type casting but data in the
        application server is showing junk data with ##### in currncy
        fields.
    4, In earlier program there is no internal table defined for bsis,
        Directly passing to work area and transferring to file on
        application server.
    Please let me know any feasble solution to approach.
    If need i can post the complete code.
    Regards
    Bhaskar

    Hi Robert,
    Here is my code....in ECC. While executing program is going to dump saying character type error.
    tables: bsis.
    data: begin of i_tab occurs 100.
            include structure bsis.
            end of i_tab.
    parameters: outfile(1000) lower case.
    open dataset outfile for output in text mode encoding default
    ignoring conversion errors..
    select * from bsis into table i_tab
    where bukrs = bukrs.
       loop at i_tab.
          transfer i_tab to outfile.
       endloop.
      close dataset.
    Please let me know if any soluton.
    regards
    Bhaskar

  • Reading internal table into File Adapter

    Hi,
    I would like to read an internal table from RFC function (sender), and write all the rows into the file by using File Adapter. Here is the scenerio;
    RFC Adapter -> XI -> File adapter
    Internal table content, below;
    FLD1  FLD2   FLD3
    1        A        B
    2        X        Y
    I expect the result, below;
    <?xml version="1.0" encoding="UTF8" ?>
    <rfc:Z_RFC xmlns:rfc="urn:sapcom:document:sap:rfc:functions">
    <ITAB_ZSUBS001>
      <item>
       <FLD1>1</FLD1>
       <FLD2>A</FLD2>
       <FLD3>B</FLD3>
      </item>
      <item>
       <FLD1>2</FLD1>
       <FLD2>X</FLD2>
       <FLD3>Y</FLD3>
      </item>
    </ITAB_ZSUBS001>
    </rfc:Z_RFC>
    I see all the records in payload, but cannot write into file. Anybody have any suggestion? Thank you.
    Regards,
    Orkun Gedik
    Message was edited by:
            Orkun GEDIK

    Hi,
    Thank you for the feedback. From now on I am getting the error, below;
    Error> occured [1] >Thu Apr 05 09:24:21,046<   
    RfcException:
        message: Commit fault: com.sap.aii.af.rfc.afcommunication.RfcChannelMismatchException: Wrong Sender Agreement:The Sender agreement does not have channel Rfc_Fiyat_Sender configured for the functionmodule Z_RFC
        Return code: RFC_CLOSED(6)
        error group: 108
        key: RFC_ERROR_INTERNAL
    Please see the last configuration, below;
    Message mappings:
    RFC Message:
    Messages 1..1
    Message1 1..1
    Z_RFC 1..1
    ITAB_ZSUBS001 1..1
    item 0..unbounded
    TXTKOD 0..1
    TXTAD 0..1
    TXTADDR 0..1
    Message Type: Malzeme
    Messages 1..1
    Message1 1..1
    Malzeme 0..unbounded
    TXTKOD 1..1
    TXTAD 1..1
    TXTADDR 1..1
    Interface mappings:
    Source Interface: Z_RFC Occurrence 1
    Target Interface: MI_MAlzeme_In_Asyn Occurrence 0..unbounded
    I bound the items below;
    item -> Malzeme
    TXTKOD -> TXTKOD
    TXTAD -> TXTAD
    TXTADDR -> TXTADDR
    Also,I refreshed the adapter cache and full cache by using SXI_CACHE and restart the RFC adapter thorugh Visual Admin in order to solve the problem, but it couldn't be a solution for the problem. Do you have any suggestion about it?
    Regards
    Message was edited by:
            Orkun GEDIK

  • How to load data dynamically into target tables using files as a source

    Hi ,
    My scenario needs a single interface to load the data of 5 different files into five target tables using a single interface. All target tables have the same structure. It is possible to point to variable source files using ODI. But the same approach is not working with Database tables. I am getting errors while trying to make my target /source table as a dynamic one.
    Can anybody suggest anything. The last option would be writing a dynamic PL/SQL block in the KM. Any other suggestions friends ?
    Regards,
    Atish

    After creating a pair of identical source and target tables, I have carried out the following steps:
    I am trying just keeping the target as variable
    a)created a one to one interface,
    b)tested that it is running.
    c)created a variable(type =text),
    d)used the variable as #v_name in the resource of the target table datastore.
    e)in a package used the variable in a set variable step (first step).
    f) used the interface as the second step.
    g)executed the same in my context.
    the <project_code>.variable_name is not getting substituted in the sql_code that is generated by the KM. My KM is SQL Control Append and following is the code that it generates in the Insert into I$ step:
    /* DETECTION_STRATEGY = NOT_EXISTS */
    insert /*+ APPEND */ into HR.I$_JOBS_COPY1
         JOB_ID,
         JOB_TITLE,
         MIN_SALARY,
         MAX_SALARY,
         IND_UPDATE
    select      
         JOBS.JOB_ID     JOB_ID,
         JOBS.JOB_TITLE     JOB_TITLE,
         JOBS.MIN_SALARY     MIN_SALARY,
         JOBS.MAX_SALARY     MAX_SALARY,
         'I' IND_UPDATE
    from     HR.JOBS JOBS
    where     (1=1)
    and not exists (
         select     'X'
         from     HR.#PLAYGROUND."v_tab_name" T
         where     T.JOB_ID     = JOBS.JOB_ID
              and     ((JOBS.JOB_TITLE = T.JOB_TITLE) or (JOBS.JOB_TITLE IS NULL and T.JOB_TITLE IS NULL))
              and     ((JOBS.MIN_SALARY = T.MIN_SALARY) or (JOBS.MIN_SALARY IS NULL and T.MIN_SALARY IS NULL))
              and     ((JOBS.MAX_SALARY = T.MAX_SALARY) or (JOBS.MAX_SALARY IS NULL and T.MAX_SALARY IS NULL))
         )

Maybe you are looking for