How to append a file in a trigger?

I'm writing from a table to a file, and have created a trigger that works great...however, I need to append the file so it doesn't overwrite the file every time the trigger fires.
Here's the code...but I can't figure out how to append the file instead of just write to the file:
CREATE OR REPLACE TRIGGER checkout_trg
AFTER UPDATE OF movie_qty ON mm_movie
FOR EACH ROW
DECLARE
fh UTL_FILE.FILE_TYPE;
BEGIN
IF :NEW.movie_qty=0 THEN
  fh:=UTL_FILE.FOPEN('ORA_FILES','chekcout.txt','w');
  UTL_FILE.PUT_LINE(fh, 'Date: '||sysdate||', Movie ID: '||:NEW.movie_id||', Quantity: '||:NEW.movie_qty);
  UTL_FILE.FCLOSE(fh);
END IF;
END;
/

> It's for an assignment...I think thye're just trying to show us what's possible.
Just as it is possible to show a learner driver to jump a red light, drive on the wrong side of the road, or do doughnuts in an intersection...
But none of this will make that learner driver a good driver. Never mind able to correctly handle high performance cars on the professional circuit.
Sorry mate - what they are showing/teaching you is pure bs. A trigger is not the "same thing" as a callback event in client programming.
And feel free to give them this URL and tell them that I think they are full of it. Let's see how they defend their non-real world, totally irrelevant and wrong assignments in this very forum.

Similar Messages

  • How to append a file directory and its contents in a jTextArea

    how will i display the contents of this file and file directory in a jTextArea or ...let's say it will display the content of "c:/AutoArchive2007-05-24.csv" in a jTextarea
    say this file "c:/AutoArchive2007-05-24.csv"contains the ff:details
    user:jeff AutoArchive-Process Started at Thu May 24 15:41:54 GMT+08:00 2007
    and ended at Thu May 24 15:41:54 GMT+08:00 2007
    Message was edited by:
    ryshi1264

    use the append(...) to append data to the text area.

  • How to append to files

    Hey all I have made a few custom JS scripts that modify default behavior of a few RoboHelp functions, this works nicely however I have to manually include the JS file on every page. So my question is this; how do I programmatically append my script tags to the bottom of each page ether at build time or as a RoboHelp Scrip?
    Thanks

    There are two ways to do this (depending on your RoboHelp version)
    1. Add the JS to the footer of a master page and assign the master page on generation. (In the SSL settings.)
    2. Use the afterPublish event to run a script automatically whenever an output was generated. See Using the new RoboHelp 10 scripting events | Adobe Developer Connection for an introduction.
    Kind regards,
    Willam

  • How to append recorded files.

    Two questions.
    I am using adobe dvrcast to record my live streams. the problem I am having is when I stop the encode during a live stream, a new file is not created, the existing stream is written over. How can I preventive this from occuring.
    Is there a way to have all vod files that are in one folder to roll over to the next file during play back.

    Thanks for the quick response. I am using FMLE 3 and FMS 3.5. I have changed the code per your suggestion. However, the file still does not append when i press the stop button in FMLE. After pressing stop, when I press start button in FMLE again, the file size starts at zero.
    here is my code: ExDVRStream.asc
    /*----------------------------------------------------------------------------+
    |       ___     _       _                                                    |
    |      /   |   | |     | |                                                   |
    |     / /| | __| | ___ | |__   ___                                           |
    |    / /_| |/ _  |/ _ \|  _ \ / _ \                                          |
    |   / ___  | (_| | (_) | |_) |  __/                                          |
    |  /_/   |_|\__,_|\___/|____/ \___|                                          |
    |                                                                            |
    |                                                                            |
    |  ADOBE CONFIDENTIAL                                                        |
    |  __________________                                                        |
    |                                                                            |
    |  Copyright (c) 2008, Adobe Systems Incorporated. All rights reserved.      |
    |                                                                            |
    |  NOTICE:  All information contained herein is, and remains the property    |
    |  of Adobe Systems Incorporated and its suppliers, if any. The intellectual |
    |  and technical concepts contained herein are proprietary to Adobe Systems  |
    |  Incorporated and its suppliers and may be covered by U.S. and Foreign     |
    |  Patents, patents in process, and are protected by trade secret or         |
    |  copyright law. Dissemination of this information or reproduction of this  |
    |  material is strictly forbidden unless prior written permission is         |
    |  obtained from Adobe Systems Incorporated.                                 |
    |                                                                            |
    |          Adobe Systems Incorporated       415.832.2000                     |
    |          601 Townsend Street              415.832.2020 fax                 |
    |          San Francisco, CA 94103                                           |
    |                                                                            |
    +----------------------------------------------------------------------------*/
    load("ExUtil.asc");
    * An example dvr stream class that handlings requests initiated from the
    * publisher and subscribers.
    * @param name    live streams name as visible to the client subscribers
    * @param numsubscriber  number of subscribers
    * @param subscribers  a map of subscribing client based on the client id
    * @param publisher   publishing client
    * @param streamInfo  holds default DVR stream info or stream info provided
    *       by the publisher
    * @param startRecTimer  Id returned by the scheduler to start recording
    * @param stopRecTimer  Id returned by the scheduler to stop recording
    * @param broadcastTimer Id returned by the scheduler to broadcast stream info
    *       to down stream servers
    * @param broadcastInterval how often to broadcast stream info
    function ExDVRStream( name ) {
    this.name = name;     // clients subscribe to this stream name
    this.numsubscriber = null;   // number of subscribers
    this.subscribers = new Object(); // map of current subscribers
    this.publisher = null;    // client publisher, this is only set in the origin
    this.streamInfo = null;    // streamInfo provided by the publisher
    this.startRecTimer = null;   // scheduler id to start recording
    this.stopRecTimer = null;   // scheduler id to stop recording
    this.broadcastTimer = null;   // scheduler id for broadcasting
    this.broadcastInterval = 5000;  // set the interval to 5 sec by default
    this.isRecording = false;   // flag to indicate if the stream is recording
    // Public interface
    * This function gets call when a client is added as a subcriber of the stream.
    * If the client is already a subscriber, it will be a no-op.
    ExDVRStream.prototype.addSubscriber = function( client )
    if (this.subscribers[client.id] == null)
      this.subscribers[client.id] = client;
      this.numsubscriber++;
    * Removes a client from the subscriber list. 
    ExDVRStream.prototype.removeSubscriber = function( client )
    if (this.subscribers[client.id])
      this.subscribers[client.id] = null;
      delete this.subscribers[client.id];
      this.numsubscriber--;
    * This function broadcast streamInfo to all the subscriber which
    * is acting as a server
    ExDVRStream.prototype.broadcastStreamInfo = function()
    debug("Inside ExDVRStream.broadcastStreamInfo - stream name: " +
      this.name);
    for (i in this.subscribers)
      subscriber = this.subscribers[i];
      if (subscriber.isProxyServer)
       subscriber.call("DVRSetStreamInfo", null, this.getStreamInfo());
    * Set the publishing client
    ExDVRStream.prototype.publish = function( client )
    this.publisher = client;
    * Clear the publishing client
    ExDVRStream.prototype.unpublish = function()
    this.publisher = null;
    * This function returns a boolean to indicate whether the stream is in use
    ExDVRStream.prototype.isInUse = function()
    if (this.numsubscriber > 0 || this.publisher)
      return true;
    return false;
    * This function cleans up all the resources used by this stream
    ExDVRStream.prototype.shutdown = function()
    debug("Inside ExDVRStream.shutdown");
    clearInterval(this.startRecTimer);
    clearInterval(this.stopRecTimer);
    clearInterval(this.broadcastTimer);
    this.startRecTimer = null;
    this.stopRecTimer = null;
    this.broadcastTimer = null;
    * Returns the default streamInfo if no streamInfo has been
    * set by the publisher
    ExDVRStream.prototype.getDefaultStreamInfo = function( DVRStreamInfo )
    //If server restarts and no publisher is coming in, we check
    //the length of the recorded stream and see if we should make
    //the dvr content available.  However, user can customize this
    //function and make an external call.
    streamLen = Stream.length(this.name);
    if (streamLen || this.publisher)
      //found a dvr stream, so return it
      DVRStreamInfo.code = "NetStream.DVRStreamInfo.Success";
      this.streamInfo = new Object();
      //setup default value
      this.streamInfo.streamName = this.name;
      this.streamInfo.callTime = new Date();
      this.streamInfo.startRec = new Date();
      this.streamInfo.stopRec = new Date();
      this.streamInfo.maxLen = Stream.length(this.name);
      this.streamInfo.begOffset = 0;
      this.streamInfo.endOffset = 0;
      this.streamInfo.append = false;
      this.streamInfo.offline = false;
      this.streamInfo.currLen = Stream.length(this.name);
      this.streamInfo.isRec = false;
      DVRStreamInfo.data = this.streamInfo;
    else
      DVRStreamInfo.code = "NetStream.DVRStreamInfo.Failed";
      DVRStreamInfo.data = null;
    * Get streamInfo and create a default one if no streamInfo
    * has been set.
    ExDVRStream.prototype.getStreamInfo = function()
    debug("Inside ExDVRStream.getStreamInfo");
    DVRStreamInfo = new Object();
    if (this.streamInfo == null)
      this.getDefaultStreamInfo(DVRStreamInfo);
    else if (this.streamInfo.offline)
      DVRStreamInfo.code = "NetStream.DVRStreamInfo.Failed";
      DVRStreamInfo.data = null;
    else
      DVRStreamInfo.code = "NetStream.DVRStreamInfo.Success";
      DVRStreamInfo.data = this.streamInfo;
      DVRStreamInfo.data.isRec = this.isRecording;
      DVRStreamInfo.data.currLen = Stream.length(this.name);
    return DVRStreamInfo;
    * Set streamInfo, also handleStreamInfo to start/stop a recording
    ExDVRStream.prototype.setStreamInfo = function( streamInfo )
    debug("Inside ExDVRStream.setStreamInfo");
    //Right now, this only get called from the FMLE when
    //the publisher start/stop a recording
    currDate = new Date();
    currTime = currDate.getTime();
    this.streamInfo = streamInfo;
    this.streamInfo.lastUpdate = currDate;
    startRecTime = 0;
    stopRecTime = 0;
    if (streamInfo.startRec == -1 || streamInfo.startRec == undefined)
      startRecTime = -1000;
    else if (streamInfo.startRec instanceof Date)
      startRecTime = streamInfo.startRec.getTime();
    else
      //invalid startRec format
      return;
    if (streamInfo.stopRec == -1 || streamInfo.stopRec == undefined)
      stopRecTime = -1000;
    else if (streamInfo.stopRec instanceof Date)
      stopRecTime = streamInfo.stopRec.getTime();
    else
      //invalid stopRec format
      return;
    if ( startRecTime == -1000 && stopRecTime == -1000 )
      //broadcast the change to all the downstream server
      this.broadcastStreamInfo(streamInfo);
      return;
    if (stopRecTime != -1000)
      //We are about to stop a recording, so clear the timer
      clearInterval(this.stopRecTimer);
      this.stopRecTimer = null;
      if (currTime < stopRecTime)
       timeDiff = stopRecTime - currTime;
       //we will broadcast the streamInfo to all the downstream server
       //when we actually stop the recording inside onStopRecord
       this.stopRecTimer = setInterval(this, "onStopRecord", timeDiff);
      else
       //stop recording immediately
       this.onStopRecord();
    if (startRecTime != -1000)
      //We are about to start a recording, so clear the timer
      clearInterval(this.startRecTimer);
      this.startRecTimer = null;
      if (currTime < startRecTime)
       timeDiff = startRecTime - currTime;
       //we will broadcast the streamInfo to all the downstream server
       //when we actually start the recording inside onStartRecord
       this.startRecTimer = setInterval(this, "onStartRecord", timeDiff);
      else
       //start recording immediately
       this.onStartRecord();
    * This is called when we are about to stop a recording
    ExDVRStream.prototype.onStopRecord = function()
    this.isRecording = false;
    clearInterval(this.stopRecTimer);
    this.stopRecTimer = null;
    s = Stream.get(this.name);
    s.record(false);
    //notify the downstream server immediately
    this.broadcastStreamInfo(this.streamInfo);
    //also stop the periodic broadcast because the stream is not growing
    this.stopStreamInfoBroadcast();
    * This is called when we are about to start a recording
    ExDVRStream.prototype.onStartRecord = function()
    debug("Inside ExDVRStream.onStartRecord");
    this.isRecording = true;
    clearInterval(this.startRecTimer);
    this.startRecTimer = null;
    s = Stream.get(this.name);
    if (this.streamInfo.append)
      s.record("append");
    else
      s.record("append");
    //notify the downstream server immediately
    this.broadcastStreamInfo(this.streamInfo);
    //also start the periodic broadcast because the stream is growing
    this.startStreamInfoBroadcast();
    * Stop the timer to broadcast streamInfo to downstream servers
    ExDVRStream.prototype.stopStreamInfoBroadcast = function()
    clearInterval(this.broadcastTimer);
    this.broadcastTimer = null;
    * Start the timer to broadcast streamInfo to downstream servers
    ExDVRStream.prototype.startStreamInfoBroadcast = function()
    debug("ExDVRStream.Inside startStreamInfoBroadcast");
    this.stopStreamInfoBroadcast();
    this.broadcastTimer = setInterval( this, "onStreamInfoBroadcast",
      this.broadcastInterval)
    * This is called by scheduler to broadcast streamInfo to the
    * downstream servers
    ExDVRStream.prototype.onStreamInfoBroadcast = function()
    debug("Inside ExDVRStream.onStreamInfoBroadcast");
    this.broadcastStreamInfo();

  • How to append Target File(reciever side) .

    Hi PI Gurus,
    I have a scenario where i need to append the target file. It goes like this:
    files(idoc's) keep coming from the source at any time of the day.
    target file is sent only once in a day. The target file is appended each time a new source file recieved.
    Need to do this without using BPM.
    Pls help me  out.
    Thanks in advance.

    Hi Pankaj,
    Kindly go through the following link which will help you surely:
    http://help.sap.com/saphelp_nwpi711/helpdata/en/44/6830e67f2a6d12e10000000a1553f6/content.htm
    In the receiver file adapter, go to the Processing tab page. Then  Select the File Construction Mode as Append. Look at the link for the other configurations in the adapter.
    You can also take a look at the scenario 2 in the following link:
    http://wiki.sdn.sap.com/wiki/display/XI/MorewiththeFileAdapter
    Hope it helps you!!!!!
    Thanks
    Biswajit
    Edited by: 007biswa on Feb 21, 2011 5:39 PM

  • How to append to file

    i have a file which contains the fomat like this
    <mailbox>
    <mail>
    <from>shankar</from>
    <to>sun</to>
    <subject>help</subject>
    </mail>
    <mail>
    <from>shan</from>
    <to>sun</to>
    <subject>help me</subject>
    </mail>
    </mailbox>
    i want to append the following after </mail> or before<mail>but not between <mail> </mail>
    i.e i want to append a message in the xml file
    please help me
    thanks in advance

    FileOutputStream has a constructor that allows you to open a file for appending:
    FileOutputStream out = new FileOutputStream("myfile.xml", true);But "appending" means that you can only add new data to the end of the file. There is no way to insert new data somewhere in the middle. If that's what you want to do, you need to make a program that opens the original file, copies the data until the point where you want to insert something to a new output file, insert the new data, and copy the rest of the original file.

  • How to append records in a file, through file adapter.

    Hi All,
    How to append records in a file, through file adapter.
    I have to read data from database and need to append all records in a file.
    Thanks in Advance.

    Hi,
    I think you have a while loop to hit the DB in your Process (As you said you have to fetch data from DB 10 times if 1000 rec are there)
    First sopy your DB O/P to one var
    and from second time append to previous data.(Otherwise you can directly use append from starting instead of copy and append)
    When loop completes you can transform to File adapter Var.
    Otherwise you can configure yourFileadapter such that it will aapend current records to previous records.
    You can use 'Append= true' in your file adapter wsdl.
    It will append previous records to current records in the same file.
    Regards
    PavanKumar.M

  • How to merge/append two files in sequence using BPM

    Hi All,
    My senario is to append two files data into a  new file on target system, only if the two files are available on source system. In case one file on the source system, no need to process file. Data in the new file should be in sequence means 1st file data then 2nd file data.
    Please suggest me how can i achieve this functionality using BPM.
    Thanks & Regards
    Sreeni

    For the first part (two files required) design as per Prateek's suggestion
    Data in the new file should be in sequence means 1st file data then 2nd file data.
    create a data structure which will be a combined structure of File1 and File2....target structure should have first reference for File1 and then for FIle2....than having two MTs (File1 and File2) at the source and the target MT at the receiver create your mapping......this will ensure that File1 data occures first and then File2 data.
    Regards,
    Abhishek.

  • How to append timestamp to log file in SQL*Plus ?

    Version: 11.2.0.3
    Platform : RHEL 5.8 (But I am looking for platform independant solution)
    I want to append the timestamp to spooled log file name in SQL*Plus.
    The spooled log filename should look like
    WMS_APP_23-March-2013.logI tried the following 3 methods found in the google. But none of them worked !
    I tried this
    col sysdt noprint new_value sysdt_var
    SELECT TO_CHAR(SYSDATE, 'yyyymmdd_hh24miss') sysdt FROM DUAL;
    spool run_filename_&sysdt_var.Logas suggested in
    http://power2build.wordpress.com/2011/03/11/sqlplus-spool-name-with-embedded-timestamp/
    and this
    spool filename with timestamp
    col sysdt noprint new_value sysdt
    SELECT TO_CHAR(SYSDATE, 'yyyymmdd_hh24miss') sysdt FROM DUAL;
    spool run_filename_&sysdt..Logas suggested in
    http://powerbuildev.wordpress.com/2011/03/11/sqlplus-spool-name-with-embedded-timestamp/
    and this
    column tm new_value file_time noprint
    select to_char(sysdate, 'YYYYMMDD') tm from dual ;
    prompt &file_time
    spool logfile_id&file_time..logas suggested in
    Creating a spool file with date/time appended to file name
    None of the above worked in RHEL or MS DOS. Any workaround ?

    I have tested your suggestions. But I still couldn't append the date to the logfile in RHEL or MS DOS SQL*Plus
    Here are the attempts I've made. I am posting how the logfile looked like after every test.
    #Attempt1 with two dots (&sysdate..log )
    set echo on
    set feedback on
    set define off
    set pages 999
    column dcol new_value SYSDATE noprint
    select to_char(sysdate,'YYYYMMDD') dcol from dual;
    spool testlog.&sysdate..log
    select 'hello' from dual;
    spool off;Log File Name -- > testlog.&sysdate..log
    #Attempt2 with single dot (&sysdate.log)
    set echo on
    set feedback on
    set define off
    set pages 999
    column dcol new_value SYSDATE noprint
    select to_char(sysdate,'YYYYMMDD') dcol from dual;
    spool testlog.&sysdate.log
    select 'hello' from dual;
    spool off;Log File Name ---> testlog.&sysdate.log
    #Attempt3. Replacing first dot with Hyphen (testlog- ) to check if the first dot was causing the issue
    set echo on
    set feedback on
    set define off
    set pages 999
    column dcol new_value SYSDATE noprint
    select to_char(sysdate,'YYYYMMDD') dcol from dual;
    spool testlog-&sysdate.log
    select 'hello' from dual;
    spool off;Log Filename: testlog-&sysdate.log
    #Attempt4: replacing SYSDATE with SDATE
    set echo on
    set feedback on
    set define off
    set pages 999
    column dcol new_value SDATE noprint
    select to_char(sysdate,'YYYYMMDD') dcol from dual;
    spool testlog1.&SDATE..log
    select 'hello' from dual;
    spool off;Log File Name -- > testlog1.&SDATE..log

  • How to append paragraph in text file of TextEdit application using applescript

    how to append paragraph in text file of TextEdit application using applescript and how do i save as different location.

    christian erlinger wrote:
    When you want to print out an escape character in java (java is doing the work in client_text_io ), you'd need to escape it.
    client_text_io.put_line(out_file, replace('your_path', '\','\\'));cheersI tried replacing \ with double slash but it just printed double slash in the bat file. again the path was broken into two lines.
    file output
    chdir C:\\DOCUME~1\
    195969\\LOCALS~1\\Temp\
    Edited by: rivas on Mar 21, 2011 6:03 AM

  • How to append to zip files

    I would like to know how to append to a zip file, I know how to write a zip file and I can put as many entries in the first time but if I run my program again and try to add a file to the same zip file it erases what was already in it. I use ZipOutputStream(new FileOutputStream), I have tried the FileOutputStream append but it does not seem to work for zip files, I have tried RandomAccessFile on my zip file but that just seems to add the bytes to the file that already in the zip file, and makes the file unopenable, corrupt. If you can help, please tell me how.

    You actually have to open the previous zipped file, read it's entries and their data and then rewrite a new zip file with these entries and their data. You can then delete your first file and rename the new one so the effect is that you have "appended" zip files to the existing archive.
    Here is an example which I pieced together from a larger bit of code that I have. This would need to be in a try/catch but this should give you a start.
    /** This method adds a new file to an existing zip file. It * includes all the zipped entries previously written.
    * @param file The old zip archive
    * @param filename The name of the file to be Added
    * @param data The data to go into the zipped file
    * NOTE: This method will write a new file and data to an archive, to
    * write an existing file, we must first read the data frm the file,
    * then you could call this method.
    public void addToArchive(File file, String filename, String data)
         ZipOutputStream zipOutput = null;
    ZipFile zipFile = null;
    Enumeration zippedFiles = null;
    ZipEntry currEntry = null;
    ZipEntry entry = null;
    zipFile = new ZipFile( file.getAbsolutePath() );
         //get an enumeration of all existing entries
    zippedFiles = zipFile.entries();
         //create your output zip file
    zipOutput = new ZipOutputStream( new FileOutputStream ( new File( "NEW" + file.getAbsolutePath() ) ) );
    //Get all the data out of the previously zipped files and write it to a new ZipEntry to go into a new file archive
    while (zippedFiles.hasMoreElements())
    //Retrieve entry of existing files
    currEntry = (ZipEntry)zippedFiles.nextElement();
    //Read data from existing file
    BufferedReader reader = new BufferedReader( new InputStreamReader( zipFile.getInputStream( currEntry ) ) );
    String currentLine = null;
    StringBuffer buffer = new StringBuffer();
    while( (currentLine = reader.readLine() ) != null )
    buffer.append( currentLine);
    //Commit the data
    zipOutput.putNextEntry(new ZipEntry(currEntry.getName()) ) ;
    zipOutput.write (buffer.toString().getBytes() );
    zipOutput.flush();
    zipOutput.closeEntry();
    //Close the old zip file
    zipFile.close();
    //Write the 'new' file to the archive, commit, and close
    entry = new ZipEntry( newFileEntryName );
    zipOutput.putNextEntry( entry );
    zipOutput.write( data.getBytes() );
    zipOutput.flush();
    zipOutput.closeEntry();
    zipOutput.close();
         //delete the old file and rename the new one
    File toBeDeleted = new File ( file.getAbsolutePath() );
    toBeDeleted.delete();
         File toBeRenamed = new File ( "NEW" + file.getAbsolutePath() );
    toBeRenamed.rename( file );
    Like I said I haven't tested this code as it is here but hopefully it can help. Good luck.

  • How to append report to log file?

    Hai,
    how to append the sqlplusw sql query output to a file.
    If we use spool, every time the file will be overwritten with new content and it won't append.
    Note:
    In batch program using >> this we can write content in to a file.
    But in sqlplus how to append the query output to same file.

    hello egyptian god of the sun,
    you didn't mention that you were using 9i. if that is the case, one way i can think of... if you're using unix (which again i assume as you mention batch scripts '>>') is to save your sql script in a .sql file and execute it within a shell script but redirecting output to your log file. you can append as you normally would.

  • How to run batch file using trigger?

    Hi, i am trying run a batch file using a trigger on a table.
    say i have a table XYZ(col_1 varchar2 primary key, col_2 varchar2)
    the values of col_2 keeps changing and col_1 are constant
    whenever the value of col_2 in any row changes from "on" to "off" i want to run a batch file C:\Users\ABC\Desktop\test.bat
    i did some searching but couldn't find any solution. Thanks in advance
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

    >
    the script will be started around 60-70 times a day
    >
    No - as marwim said the script will be executed every time the trigger is fired. And that trigger, depending on how it is written, might be fired several times for the same transaction.
    And if the trigger is fired the script will be executed even if the transaction that caused the trigger to fire issues a ROLLBACK.
    Triggers are non-transactional. You need to clearly define the business rules for when the script should run. Should it run only when the transaction is COMMITTED? Or should it run if the transaction executes even if the transaction performs a ROLLBACK?
    A trigger is the wrong solution for your problem.
    Please clarify what the business rules are that should control the execution of the script.

  • How can I append excel file rather than replace it?

    Hi,
    I have the attached VI set to write data to Excel, One case structure sends the data to cell B6, the other sends the data to cell B7. The problem is, the data is deleted from one cell when new data is added to another.
    I think I want to be able to append the data without deleting other cells. Any ideas?
    Thank you
    Todd
    Attachments:
    Flow meter write to Excel question.vi ‏180 KB

    Toddzilla,
    There are a couple different ways to append to excel files.  A couple links that might get you going are:
    Can I Add New Data to an Existing Excel File Without Erasing Old Data?
    Append Data to an Excel Document Every Iteration Using Report Generation Toolkit
    Are you trying to write over cells B6 or B7, or are you trying to append within the cell itself?  
    Hopefully this can get you on the right track.  When I append to files I tend to insert rows or append to the end of the file.
    Scott A
    SSP Product Manager
    National Instruments

  • How to store multiple files from SAp in to Application server?

    Hi Guys,
                 Can anybody tell me how to store multiple files from SAP into Application server.in my application i have to get the data from SAP tables BSEG , BKPF , BSAK and BSIK that to daily i have to do.
                Any Logic  or Code for how to do is welcomed.
                        plz help me urgently.
    Thanks,
    Gopi

    Hi,
      directories creates basis. If you have task to store data in application server you already should have information into which folder you have to do it. If you don't have this information because it is just for example training for next task then you can use your personal folder into which you have access. To get list of all available folders please look at attached code and form get_directories (you get the list of folders you see in transaction AL11). But don't forget: If you are using open dataset you have to have rights to access application folder!
    Here you are code which I use to upload text files from local disc into application folder
    Regards,
      Karol
    *& Report  FILE_PC_TO_SAP
    REPORT  FILE_PC_TO_SAP.
    DATA: BEGIN OF searchpoints OCCURS 100,
            DIRNAME(200)     TYPE c, " name of directory.
            sp_name(100)     TYPE c," name of entry. (may end with *)
          END OF searchpoints.
    DATA: BEGIN OF isearchpoints OCCURS 10,
            dirname(75) TYPE c,            " name of directory.
            aliass(75)  TYPE c,            " alias for directory.
            svrname(75) TYPE c,            " svr where directory is availabl
            sp_name(75) TYPE c,            " name of entry. (may end with *)
            sp_cs(10)   TYPE c,            " ContainsString pattern for name
          END OF isearchpoints.
    data: l_file type filetable.
    data: l_rc   type i.
    data: itab   type TABLE OF string.
    data: g_tmp_file_path type rlgrap-filename.
    data: wa_itab type string.
    data: h_destin(100) type c.
    data: dat      type string.
    INITIALIZATION.
    perform get_directories.
    START-OF-SELECTION.
    parameters: in_file type string OBLIGATORY LOWER CASE.
    parameters: destin(100) type c OBLIGATORY LOWER CASE.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
       FILENAME                      = in_file
       "FILETYPE                      = 'BIN'
       FILETYPE                      = 'ASC'
       HAS_FIELD_SEPARATOR           = ' '
       HEADER_LENGTH                 = 0
       READ_BY_LINE                  = 'X'
       DAT_MODE                      = ' '
      TABLES
        DATA_TAB                     = itab
    EXCEPTIONS
       FILE_OPEN_ERROR               = 1
       FILE_READ_ERROR               = 2
       NO_BATCH                      = 3
       GUI_REFUSE_FILETRANSFER       = 4
       INVALID_TYPE                  = 5
       NO_AUTHORITY                  = 6
       UNKNOWN_ERROR                 = 7
       BAD_DATA_FORMAT               = 8
       HEADER_NOT_ALLOWED            = 9
       SEPARATOR_NOT_ALLOWED         = 10
       HEADER_TOO_LONG               = 11
       UNKNOWN_DP_ERROR              = 12
       ACCESS_DENIED                 = 13
       DP_OUT_OF_MEMORY              = 14
       DISK_FULL                     = 15
       DP_TIMEOUT                    = 16
       OTHERS                        = 17.
    IF sy-SUBRC <> 0.
      write: / 'Error during loading input file!'.
    ENDIF.
    if h_destin is INITIAL.
      h_destin = in_file.
    endif.
    CONCATENATE destin h_destin into dat SEPARATED BY '/'.
    *TRANSLATE dat TO UPPER CASE.
    OPEN DATASET dat FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-SUBRC = 0.
      loop at itab into wa_itab.
         TRANSFER: wa_itab TO dat.
      endloop.
      CLOSE DATASET dat.
      write: / 'File uploaded!'.
    ELSE.
      write: / 'Not possible to open dataset'.
    ENDIF.
    at selection-screen on value-request for in_file.
      perform select_input_file_name.
      loop at l_file into g_tmp_file_path.
        move g_tmp_file_path to in_file.
        h_destin = ''.
        SPLIT g_tmp_file_path at '\' into table itab.
        loop at itab into g_tmp_file_path.
          h_destin = g_tmp_file_path.
        endloop.
      endloop.
    at selection-screen on value-request for destin.
      DATA: lt_dfies    TYPE TABLE OF dfies.
      DATA: lwa_dfies   TYPE dfies.
      CALL FUNCTION 'DDIF_FIELDINFO_GET'
        EXPORTING
          tabname    = '/BI0/PCO_AREA'
          lfieldname = 'CO_AREA'
        IMPORTING
          dfies_wa   = lwa_dfies.
      lwa_dfies-tabname = 'searchpoints'.
      lwa_dfies-REPTEXT   = 'Destination directory'.
      lwa_dfies-LENG      = 100.
      lwa_dfies-INTLEN    = 100.
      lwa_dfies-OUTPUTLEN = 100.
      lwa_dfies-fieldname = 'SP_NAME'.
      APPEND lwa_dfies TO lt_dfies.
      CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
        EXPORTING
          RETFIELD = 'SP_NAME'
          DYNPPROG = SY-REPID
          DYNPNR = SY-DYNNR
          DYNPROFIELD = 'destin'
          VALUE_ORG = 'S'
        TABLES
          VALUE_TAB = searchpoints
          FIELD_TAB = lt_dfies
        EXCEPTIONS
          PARAMETER_ERROR = 1
          NO_VALUES_FOUND = 2
          OTHERS = 3.
    *&      Form  select_input_file_name
    *       text
    form select_input_file_name.
    *  call function 'F4_FILENAME'
    *       exporting
    *            program_name  = sy-repid
    *            dynpro_number = sy-dynnr
    *            field_name    = 'PATH'
    *       importing
    *            file_name     = g_tmp_file_path.
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
      EXPORTING
      WINDOW_TITLE = 'Please choose a file'
      "default_extension = '*.TXT'
      "default_filename = 'C:\*.txt'
      initial_directory = 'C:\'
      file_filter = '*.*'
      CHANGING
      FILE_TABLE = l_file
      RC = l_RC
      EXCEPTIONS
      FILE_OPEN_DIALOG_FAILED = 1
      CNTL_ERROR = 2
      ERROR_NO_GUI = 3
      NOT_SUPPORTED_BY_GUI = 4
      OTHERS = 5.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    endform.                    "select_input_file_name
    *&      Form  WRITE_DB_HOME
    *       Write DB home directory
    *       no parameters
    FORM write_db_home.
      CASE sy-dbsys(3).
        WHEN 'ORA'.
          CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_ORAHOME'
                             ID 'VALUE' FIELD searchpoints-dirname.
    *--- C5056155 Start of ALV -------------------------------*
    *      PERFORM flip_flop(rsora000) USING cflag.
    *      WRITE: / 'DIR_ORAHOME',       30 searchpoints-dirname.
          MOVE: 'DIR_ORAHOME'        TO searchpoints-sp_name.
          APPEND searchpoints.
    *--- C5056155 End   of ALV -------------------------------*
        WHEN 'ADA'.
          CALL 'C_GETENV' ID 'NAME'  FIELD 'DBROOT'
                          ID 'VALUE' FIELD searchpoints-dirname.
    *--- C5056155 Start of ALV -------------------------------*
    *      PERFORM flip_flop(rsora000) USING cflag.
    *      WRITE: / 'DIR_ADA_DBROOT',    30 searchpoints-dirname.
          MOVE: 'DIR_ADA_DBROOT'     TO searchpoints-sp_name.
          APPEND searchpoints.
    *--- C5056155 End   of ALV -------------------------------*
        WHEN 'INF'.
          CALL 'C_GETENV' ID 'NAME'  FIELD 'INFORMIXDIR'
                          ID 'VALUE' FIELD searchpoints-dirname.
    *--- C5056155 Start of ALV -------------------------------*
    *      PERFORM flip_flop(rsora000) USING cflag.
    *      WRITE: / 'DIR_INF_INFORMIXDIR', 30 searchpoints-dirname.
          MOVE: 'DIR_INF_INFORMIXDIR' TO searchpoints-sp_name.
          APPEND searchpoints..
    *--- C5056155 End   of ALV -------------------------------*
        WHEN 'DB6'.
          CALL 'C_GETENV' ID 'NAME'  FIELD 'INSTHOME'
                          ID 'VALUE' FIELD searchpoints-dirname.
          IF sy-subrc = 0.
    *--- C5056155 Start of ALV -------------------------------*
    *        PERFORM flip_flop(rsora000) USING cflag.
    *        WRITE: / 'DIR_DB2_HOME',    30 searchpoints-dirname.
            MOVE: 'DIR_DB2_HOME'       TO searchpoints-sp_name.
            APPEND searchpoints.
    *--- C5056155 End   of ALV -------------------------------*
          ELSE.
            EXIT.
          ENDIF.
        WHEN OTHERS.
          EXIT.
      ENDCASE.
    ENDFORM.                    " WRITE_DB_HOME
    FORM get_directories.
    * get the name and aliases of ALL userdefined directories
      SELECT * FROM user_dir INTO isearchpoints
        WHERE svrname = sy-uname.
        MOVE isearchpoints-dirname to searchpoints-dirname.
        MOVE isearchpoints-aliass  to searchpoints-sp_name.
        APPEND searchpoints.
      ENDSELECT.
      SELECT * FROM user_dir INTO isearchpoints
        WHERE svrname = 'all'.
        MOVE isearchpoints-dirname to searchpoints-dirname.
        MOVE isearchpoints-aliass  to searchpoints-sp_name.
        APPEND searchpoints.
      ENDSELECT.
    * Get DB home
      IF sy-dbsys(3) = 'ADA'.
        PERFORM write_db_home.
      ENDIF.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_ATRA'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_ATRA'           TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_BINARY'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_BINARY'         TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory $DIR_CCMS
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_CCMS'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_CCMS'           TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_CT_LOGGING'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_CT_LOGGING'     TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_CT_RUN'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_CT_RUN'         TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_DATA'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_DATA'           TO searchpoints-sp_name.
      APPEND searchpoints.
    * Get DB home
      IF sy-dbsys(3) = 'DB6'.
        PERFORM write_db_home.
      ENDIF.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_DBMS'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_DBMS'           TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_EXECUTABLE'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_EXECUTABLE'     TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_EXE_ROOT'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_EXE_ROOT'       TO searchpoints-sp_name.
      APPEND searchpoints.
    *get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_GEN'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_GEN'            TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_GEN_ROOT'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_GEN_ROOT'       TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_GLOBAL'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_GLOBAL'         TO searchpoints-sp_name.
      APPEND searchpoints.
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_GRAPH_EXE'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_GRAPH_EXE'      TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_GRAPH_LIB'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_GRAPH_LIB'      TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_HOME'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_HOME'           TO searchpoints-sp_name.
      APPEND searchpoints.
    * Get DB home
      IF sy-dbsys(3) = 'INF'.
        PERFORM write_db_home.
      ENDIF.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_INSTALL'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_INSTALL'        TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_INSTANCE'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_INSTANCE'       TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_LIBRARY'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_LIBRARY'        TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_LOGGING'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_LOGGING'        TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the files written by the memory inspector
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_MEMORY_INSPECTOR'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_MEMORY_INSPECTOR' TO searchpoints-sp_name.
      APPEND searchpoints.
    * Get DB home
      IF sy-dbsys(3) = 'ORA'.
        PERFORM write_db_home.
      ENDIF.
    *get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_PAGING'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_PAGING'         TO searchpoints-sp_name.
      APPEND searchpoints.
    *get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_PUT'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_PUT'            TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_PERF'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_PERF'           TO searchpoints-sp_name.
      APPEND searchpoints.
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_PROFILE'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_PROFILE'        TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_PROTOKOLLS'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_PROTOKOLLS'     TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_REORG'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_REORG'          TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_ROLL'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_ROLL'           TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_RSYN'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_RSYN'           TO searchpoints-sp_name.
      APPEND searchpoints.
    * calculate directory for saphostagent (no sapparam available...)
      IF ( sy-opsys(3) = 'WIN' ) OR ( sy-opsys(3) = 'Win' ).
        DATA: windir_path(64),  programfiles_path(64).
    *   hoping that ProgramFiles is set in service user environment
        CALL 'C_GETENV' ID 'NAME'  FIELD 'ProgramFiles'
                        ID 'VALUE' FIELD programfiles_path.
        IF programfiles_path IS INITIAL.
    *     %ProgramFiles% not available. guess from windir
          CALL 'C_GETENV' ID 'NAME'  FIELD 'windir'
                          ID 'VALUE' FIELD windir_path.
    *     e.g. S:\WINDOWS ==> S:\Program Files
          CONCATENATE windir_path(3) 'Program Files' INTO programfiles_path.
        ENDIF.
        CONCATENATE programfiles_path '\SAP\hostctrl'
                                                 INTO searchpoints-dirname.
      ELSE.
    *   on UNIX, the path is hard coded
        searchpoints-dirname = '/usr/sap/hostctrl'.
      ENDIF.
      MOVE: 'DIR_SAPHOSTAGENT' TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_SAPUSERS'
                         ID 'VALUE' FIELD searchpoints-dirname.
      IF searchpoints-dirname = '.'.
        IF sy-opsys = 'Windows NT'.
          searchpoints-dirname = '.\'.
        ELSE.
          searchpoints-dirname = './'.
        ENDIF.
      ENDIF.
      MOVE: 'DIR_SAPUSERS'       TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_SETUPS'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_SETUPS'         TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_SORTTMP'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_SORTTMP'        TO searchpoints-sp_name.
      APPEND searchpoints.
    *get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_SOURCE'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_SOURCE'         TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_TEMP'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_TEMP'           TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_TRANS'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_TRANS'          TO searchpoints-sp_name.
      APPEND searchpoints.
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_TRFILES'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_TRFILES'        TO searchpoints-sp_name.
      APPEND searchpoints.
    * get name of directory with the error files
      CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_TRSUB'
                         ID 'VALUE' FIELD searchpoints-dirname.
      MOVE: 'DIR_TRSUB'          TO searchpoints-sp_name.
      APPEND searchpoints.
    *  get the name of the current server.
      CALL 'C_SAPGPARAM' ID 'NAME' FIELD 'rdisp/myname'
                         ID 'VALUE' FIELD searchpoints-dirname.
      data: h_ind type i.
      LOOP AT searchpoints.
        h_ind = sy-tabix.
        IF searchpoints-sp_name IS INITIAL.
          DELETE searchpoints INDEX h_ind.
        ENDIF.
      ENDLOOP.
    ENDFORM.

Maybe you are looking for