ABAP:File = Write Up to 300 Records in file

HI friends,
One quick question on ABAP file handling
Can you let me know the logic , When user writes 300 Records in a file and when he tries to write 301 records the select screen should through an error message saying "only 300 records can be downloaded in a file for one run'
I have added below loop in the code,  but in the below loop i have given the values of "MATNR, TEXTID, TEXT_A,  SPRA,cTEST_T" as some dummy values.....
but i dont want this dummy vaules , it shuld pick whatever user is given
wa_out-matnr = 'C100'.
wa_out-textid = '100'.
wa_out-text_A = 'sssssssssssssssssssssssssssss'.
wa_out-spras = 'RU'.
wa_out-text_t = 'ddddddddddddddddddddddddddddd'.
do 300 times.
wa_out-sno = sy-index + 1.
append wa_out to t_out.
enddo.
clear wa_out.
Can you help

Hi
When you are writing into a file based on the content of an internal table, you can use sy-tabix to check if its <= 300, then exit the loop and close the file.
For eg:
loop at itab.
if sy-tabix <= 300.
transfer itab to lf_file.
endif.
endloop.
close lf_file.
Regards
Raj

Similar Messages

  • To write to a particular position in file

    I have to write objects involved with the diagram in to a XML file.as new components are drawn in the diagram corresponding objects will get added to XML file.For the Object to xml conversion i am using Xstream API.
    In have to insert this portion
    *<Rstmain.gui.TextRectangle>*
      *<x>15</x>*
      *<y>2350</y>*
      *<width>110</width>*
      *<height>63</height>*
      *<rectNo>0</rectNo>*
      *<text__Rectangle>With its distant orbit-50 percent farther from the sun </text__Rectangle>*
    *</Rstmain.gui.TextRectangle>*
    above </temp>
    *<temp>*
    <string-array>
      <string>With its distant orbit-50 percent farther from the sun </string>
      <string>than earth-and slim atmospheric blanket,mars experiences frigid weather conditions.Surface temperatures typically average about -60 d</string>
      <string>egrees Celsius(-76 degrees Fahrenheit)at the equator and can dip to -123 degrees C nea</string>
      <string>r the poles.Only the midday sun at tropic</string>
      <string>al lattitudes is warm enough to thaw ice on occasion,but any liquid water formed in </string>
      <string>this way would evaporate almost </string>
      <string>instantly because of low atmospheric pressure. </string>
    </string-array>
    <int-array>
      <int>55</int>
      <int>189</int>
      <int>276</int>
      <int>318</int>
      <int>403</int>
      <int>436</int>
      <int>485</int>
    </int-array>
    *</temp>*
    <Rstmain.gui.TextRectangle>
      <x>15</x>
      <y>2350</y>
      <width>110</width>
      <height>63</height>
      <rectNo>0</rectNo>
      <text__Rectangle>With its distant orbit-50 percent farther from the sun </text__Rectangle>
    </Rstmain.gui.TextRectangle>I cant use random access file for this because the lines in xml file are not of equal length.
    currently i am using this approach.convert each object separately to xml and then write to a file.
    tempOut = new BufferedWriter(new FileWriter(tempFileXML, true));
                         tempOut.newLine();
                        String txtRectXml = stream.toXML(textRectangle);
                        tempOut.write(txtRectXml);
                        tempOut.close();please suggest some method for solving my problem...

    Thanks...I could solve it by another approach...
    Hope it will be helpful for others
    create Root Node first.tempFileXML is the fileName here.
    String root="temp";
            documentBuilderFactory = DocumentBuilderFactory.newInstance();
            documentBuilder = documentBuilderFactory.newDocumentBuilder();
            document = documentBuilder.newDocument();
            rootElement = document.createElement(root);
            document.appendChild(rootElement);
            writeXmlFile(document,tempFileXML);//writing document to file...
             For appending one document to another
    txtXml is string Object comprising a xml document
    txtXml is
    <string-array>
      <string>With its distant orbit-50 percent farther from the sun than</string>
      <string> earth-and slim atmospheric blanket,mars experiences frigid weather conditions.Surface temperatures typically average</string>
      <string> about -60 degrees Celsius(-76 degrees Fahrenheit)at the equator and can dip to -123 degrees C near the poles.</string>
      <string>Only the midday sun at tropical lattitudes is warm </string>
      <string>enough to thaw ice on occasion,but any liquid water formed in this way</string>
      <string> would evaporate almost instantly because of low atmospheric pressure. </string>
    </string-array>
    //Creating new instances of document builder factory
                documentBuilderFactory2 = DocumentBuilderFactory.newInstance();
                documentBuilder2 = documentBuilderFactory.newDocumentBuilder();
               inStream = new InputSource();
               inStream.setCharacterStream(new StringReader(txtXml)); 
               document2=documentBuilder2.parse(inStream);
               document=documentBuilder.parse(tempFileXML);
               document.getFirstChild().appendChild(document.importNode(document2.getDocumentElement(),true));
               writeXmlFile(document,tempFileXML);
                writeXmlFile I got from another forum posting
    public static void writeXmlFile(Document doc, String filename) {
            try {
                // Prepare the DOM document for writing
                Source source = new DOMSource(doc);
                // Prepare the output file
                File file = new File(filename);
                Result result = new StreamResult(file);
                // Write the DOM document to the file
                Transformer xformer = TransformerFactory.newInstance().newTransformer();
                xformer.transform(source, result);
            } catch (TransformerConfigurationException e) {
            } catch (TransformerException e) {
        }

  • File Write Keyword Tag don't create a xmp file

    Hi,
    I use PSE 8 with WIN7 64 Ultimate.
    When I used the  File > Write Keyword Tag command, no xmp file is created. I saw, that the filename was renamed to xxx_edTMP-1.NEF for a short time and than the original name is show. The changedate of the file is not changed Sometimes the file is not renamed the new name is xxxx_edTMP-1.NEF.
    Why?
    Nils

    I assume that you are trying to write tags assigned to a Raw original.
    There is a bug that sometimes PSE does not write tags (or other metadata) to .xmp for Raw files. This usually depends on the type of file; this command never seems to work for .NEF files.
    A workaround is to use John R Ellis's psedbtool

  • File Write Adapter, First record as a Column Header

    Hi,
    Using File adapter of type WRITE i m creating a file.
    I want to include the column header also as a first record in File.
    One way i can think of Creating one record manually and append as a first record in the File write variable.
    Is there any other simple way or standard way to do it??

    To have fixed header every time before it writes the data, i think you should have file with header and data, then use it to configure file write in JCA adapter.
    This will create a schema with static header and dynamic results to the schema file.
    So that everytime you will have the header then it write the data below that.
    Note: I have done this some years back, i wrote here with from my memory.
    Let me know if you still have problem, wll try to create a simple example and share.
    Thanks,
    Vijay

  • Write records to file???

    i know how to write lines of information to a file and output them but how do you go about writing records in one file and then retrieving them for use within a program, if someone could help by posting some simple code, or explain where i could find this id appreciate it
    Thx

    If you are refering to Records as objects, then you could serialize them into a file. You would create an ObjectOutputStream object, then call writeObject() for each object you want to write out. Then, using ObjectInputStream you would read them back in with readObject(). You can also write the number of objects in the file first by calling writeInt() before calling writeObject() in a loop. Reading would then be the exact opposite, call readInt() to determine the # of objects in the file, then calling readObject() x number of times.

  • How to Import .txt files in ORACLE having 300 thousand records

    How to Import .txt files in ORACLE having 300 thousand records. Kindly help me in that context

    You can make use of Sql*Loader utility and You can also use External table technique for this puspose.
    For external table go through this link.
    http://www.oracle-base.com/articles/9i/ExternalTables9i.php
    Regards

  • Write Record to File

    Hi all
    I am now doing a java program to query result from SQL Server and write the result to a file.
    My problem is that our SQL Server stores Chinese wordings with unicode, after the program query the result and it fails to write those Chinese wordings in the file. I have tried to use ObjectOutputStream or DataOutPutStream with method like writeBytes, writeChars or WriteObject, but all are failed to create a ASCII file that can view the Chinese wordings. Although those words can be viewed by using Sytem.out.print().
    I think the problem is related to write the result to file or create the file, can any one help?
    Thanks
    Shek

    Hi all
    I am now doing a java program to query result from SQL
    Server and write the result to a file.
    My problem is that our SQL Server stores Chinese
    wordings with unicode, after the program query the
    result and it fails to write those Chinese wordings in
    the file. I have tried to use ObjectOutputStream or
    DataOutPutStream with method like writeBytes,
    writeChars or WriteObject, but all are failed to
    create a ASCII file that can view the Chinese
    wordings. Although those words can be viewed by using
    Sytem.out.print().
    I think the problem is related to write the result to
    file or create the file, can any one help?
    Thanks
    ShekWhich editor are you using to view these files ? It might be possible that not the file but the editor could be the problem.
    You might also want to investigate OutputStreamWriter and related classes.

  • Mailing Error records in file-to-file Sp14

    Hi All,
    Can anyone suggest me how to send error records to the concerned person when I'm doing File-to-File scenario.
    According my understanding I should configure SMTP adapter.but if anyone confirms this and suggest any process would be a great help for me.
    Regards,
    Venu

    Hi Venu,
            Great to know that my answers helped you.
    well what i may suggest that this was one of the many solutions but not the only one, if you go through sdn you will see other approaches as using a DOM structure
    /people/swaroopa.vishwanath/blog/2005/06/29/generic-approach-for-validating-incoming-flat-file-in-sap-xi--part-ii (part 1 and part 2).This i am sending not to confuse you with many validation approaches but to help you understsnad that it can be done in many ways.
    what i would request you to do is:
    1. Generally files are validated from 3rd party systems like banking servers , legacy etc. So if your client asks you to validate the incoming file and if the existing landscape does not do any data validation and there is no standard data validation tools within the system lanscape, then one should go for these validations.
    2.Upto a certain level you can generlise these validations after that you need to take it as a case to case basis, as how can you generise you source and target.
    3.I strongly suggest you to consult your Team members/Architects if this is really required to be validated in SAP XI.
    NOW BOTH YOUR QUESTIONS,
    <i>Issue for 1.
    They have mentioned in a document by using Java Mapping program we can segrigate Valid and Invalid messages, here do we need to write any Function modules ?
    </i>
    look here the author wants to say that he picks up the file as Record
              |
            Row
    so that he picks all files and none is rejected in content conversion because of bad structure.The file after being processed as record-row goes to the module chain of file adapter and the EJB is called(page 8), after being validated it is passed or rejected.So
    we need a java module to be written which will do this validations, but ejb was not within the scope of that document. No Its a ejb module and not a Function module.
    <i>Issue for 2.
    How to handle this bcz if we get an error while processing the records(Idocs) at sap side do we need to handle in XI as a different scenario or direct from ABAP end we send a mail to legacy people</i>
    No, i think abap can and should handle this, as they are sending the data, so if an idoc is coming in sap xi it should be validated and send.So you need to take a call on this and discuss with abap consultants, if a validations is needed for the objects send by them.
    This is what happened in my last implementaion wherein data from R3 was handled by abap.
    Hope i have helped you again and have a great day!
    Regards,
    Anirban.

  • HELP: Appending new records to File containing 1 Record

    Hi, im transferring records to a file, the first line of the file contains the headers (used 'NO END OF LINE'). The problem is that when I write the data records to the file, the first record continues from the end of the Headers line, hence i have a record missing in my statement. I want to append the records below the Headers line. I tried opening the dataset 'for appending' instead of 'for output' but I get the same result.
    lv_ds_name_ex  = Filename
    Code:
    Getting field descriptions to use as headers and tranferring to file
      open the dataset
      OPEN DATASET lv_ds_name_ex FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    CLEAR: lt_dfies.
      " Get field descriptions from settlement table
      CALL FUNCTION 'DDIF_FIELDINFO_GET'
        EXPORTING
          tabname   = 'zrl_generic_record'
        TABLES
          dfies_tab = lt_dfies.
    write column headers to the file
      LOOP AT lt_dfies.
        IF lt_dfies-scrtext_m = 'Char15'.
          IF lv_counter < 1.
            lt_dfies-scrtext_m = 'Remuneration Amount'.
            lv_counter = lv_counter + 1.
          ELSE.
            lt_dfies-scrtext_m = 'Commission Amount'.
          ENDIF.
        ENDIF.
        TRANSFER lt_dfies-scrtext_m  TO lv_ds_name_ex NO END OF LINE.
        TRANSFER ';' TO lv_ds_name_ex NO END OF LINE.
      ENDLOOP.
    Close  DATASET lv_ds_name_ex.
    Transferring data records to file
    open the dataset
      OPEN DATASET lv_ds_name_ex FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
    write records to the file
      LOOP AT lt_generic_record_csv INTO ls_generic_record_csv.
            TRANSFER ls_generic_record_csv TO lv_ds_name_ex.
      ENDLOOP.
      "close the dataset
      CLOSE DATASET lv_ds_name_ex.

    Solution: TRANSFER " " TO lv_ds_name_ex. (This simply adds an empty line/record with an end of line) see code before closing the dataset 
    open the dataset
    OPEN DATASET lv_ds_name_ex FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    CLEAR: lt_dfies.
    " Get field descriptions from settlement table
    CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
    tabname = 'zrl_generic_record'
    TABLES
    dfies_tab = lt_dfies.
    write column headers to the file
    LOOP AT lt_dfies.
    IF lt_dfies-scrtext_m = 'Char15'.
    IF lv_counter < 1.
    lt_dfies-scrtext_m = 'Remuneration Amount'.
    lv_counter = lv_counter + 1.
    ELSE.
    lt_dfies-scrtext_m = 'Commission Amount'.
    ENDIF.
    ENDIF.
    TRANSFER lt_dfies-scrtext_m TO lv_ds_name_ex NO END OF LINE.
    TRANSFER ';' TO lv_ds_name_ex NO END OF LINE.
    ENDLOOP.
    TRANSFER " " TO lv_ds_name_ex.
    Close DATASET lv_ds_name_ex.
    open the dataset
    OPEN DATASET lv_ds_name_ex FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
    write records to the file
    LOOP AT lt_generic_record_csv INTO ls_generic_record_csv.
    TRANSFER ls_generic_record_csv TO lv_ds_name_ex.
    ENDLOOP.
    "close the dataset
    CLOSE DATASET lv_ds_name_ex.
    Edited by: Daniel Lebotse on May 15, 2008 5:42 PM

  • ORA-29285: file write error

    Hi,
    We are getting this error ORA-29285: file write error while writing to a text file using utl_file.putf package.
    Using fopen funtion in code to open file as below:
    V_FILEHANDLE:=UTL_FILE.FOPEN(v_file_path,'ABC','W', max_linesize);
    Here max linesize = 32000, so as far as I think, limitation on length of records while writing the file is not an issue.
    Further code is written as:
    UTL_FILE.PUTF(V_FILEHANDLE, v_text1||'|'||v_text2||'|');
    UTL_FILE.NEW_LINE(V_FILEHANDLE);
    UTL_FILE.FFLUSH(V_FILEHANDLE); -- This is called after every 500 lines are written to the file.
    UTL_FILE.FCLOSE(V_FILEHANDLE);
    We are encountering this error every now and then, and strangely this gets resolved when we re-run the program and file gets written successfully.
    Can someone please help on this please?
    Oracle database 11g, version: 11.1.0.7.0
    Thanks,
    Sonam

    Not enough information.
    964643 wrote:
    Hi,
    We are getting this error ORA-29285: file write error while writing to a text file using utl_file.putf package.
    Using fopen funtion in code to open file as below:
    V_FILEHANDLE:=UTL_FILE.FOPEN(v_file_path,'ABC','W', max_linesize);And what value has v_file_path got? Is this the name of an Oracle Directory Object as it should be?
    Here max linesize = 32000, so as far as I think, limitation on length of records while writing the file is not an issue.
    Further code is written as:
    UTL_FILE.PUTF(V_FILEHANDLE, v_text1||'|'||v_text2||'|');
    UTL_FILE.NEW_LINE(V_FILEHANDLE);
    UTL_FILE.FFLUSH(V_FILEHANDLE); -- This is called after every 500 lines are written to the file.
    UTL_FILE.FCLOSE(V_FILEHANDLE);
    We are encountering this error every now and then, and strangely this gets resolved when we re-run the program and file gets written successfully.
    Can someone please help on this please?Not without seeing complete code so that we can try and reproduce the problem or spot where you may be going wrong.

  • UDF - Removing Header Record from File

    Hi Team,
    In my file(File Content Conversion) to ABAP server proxy scenario...
    The source File structure is like this...
    KUNNR|Matnr|Description----->(This is Hearder Record.Each File contains this header record.)
    1001|0077321|Special Materials
    1002|0077323|Raw Material
    File adapter will picks the file , In Message Mapping The first record is the Header Record from the above file structure.So I need to remove the Header Record.
    Can we handle  this requirement with any FCC parameter ;I think we can do it with the help of UDF in MessageMapping?
    Can anybody ghelp me the sample code for this.
    Thanks.
    Drumi

    Hi,
    You can use Document Offset in FCC to  specify the number of lines that are to be ignored at the beginning of the document.
    Regards,
    Priyanka

  • Linking Records to Files on a Server

    I work for an engineering firm and I have a table in my Access 2002 database that holds data regarding engineering drawings (i.e, drawing #, drawing size, project #, etc.).
    I have a .PDF file for each drawing and these .PDF files are located on one of the servers at work. Each record in my table (each drawing) has an associated .PDF fle, or each record could have more than one .PDF file associated with it.
    I need to link each record in my table (each drawing) to its .PDF file, which is on a server. I've added a 'text' column to my table and I also have the full path to where the actual .PDF files are.
    I need help on how I can get the .PDF file name for each record and insert it into my table.
    Can anyone please help????
    Thanks in advance.

    The connection between a record and its file is that each record (each engineering drawing data) has it's associated electronic file in a .PDF format. So for example, if there's a record, let's say drawing number 123, there's a .PDF file for it on the server called 123.PDF.
    When I say I need to grab the file name, I need to actually get the text '123.PDF' and insert it into a column in the table for the record that has 123 as the drawing number.
    So for example, I have a table that has data about all engineering drawings. One of the columns in this table is called 'pathToFile'. I have a folder on a server that has all of the electronic files for each actual drawing in a folder. I need help with syntax and algorithm to write code to loop through each record in my table, get the drawing number and based on the drawing number, go to the folder on the server and get it's .PDF file and insert in into my 'pathToFile' column. So for the example above, if the drawing number is 123, then the entry in my 'pathToFile' column for that record would be '\\server_name\folder_name\123.pdf'.
    I hope this makes sense.

  • File with 3 types of  record

    I've a entry file with 3 types of record. The first field of each record tell the type. When XI receive this file it must be validate some fields. It's possible management this file in XI? how?
    very thanks

    Validating the field write some UDF.
    If valid then map & if not valid you can raise some exception in Mapping
    in case PI 7.1 this feature is provided using the XML Validation which compares with the XSD.
    You need to create the FCC structure that will generate the XML before sending to XI.  You create the Mapping and define the UDF which will do the validation and call the SAP using Lookup (search the sdn for RFC Lookup or DB Lookup ).

  • Import info record from file.

    the client require a programm to import info record from file.especially regard the price. can anyone give me clue about the development. use BDC programm, or import to a table directly?

    hi,
    Ask your ABAPer, he will develope the BDC program for data uploading. or else you can use LSMW also to upload  condition data in Info. Records. in LSMW we dont required any ABAP code.
    hope it helps...
    manoj singh

  • How to  open the file writer for next entry after stream is close?

    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.Scanner;
    public class TryOut {
         public static void main(String args[]) throws IOException{
              int inputQuestionnAireNum = 0;
              int inputPostCode = 0;
              int inputGender = 0;
              int inputAge = 0;
              int x=0;
              Scanner input = new Scanner(System.in);
              FileWriter fwrite = new FileWriter("tryout.txt", true);
              BufferedWriter out = new BufferedWriter(fwrite);
              boolean invalidNum = false;           
              do{
                   System.out.print("1 new entry or 0 print");
                   x = Integer.parseInt(input.nextLine());  
                   if(x == 1)
                      //Questionnaire Number
                        System.out.print("Enter Questionnaire Number [ ] ");
                        inputQuestionnAireNum = Integer.parseInt(input.nextLine());
                        out.write("NumBER OF Q: "+inputQuestionnAireNum+", ");
                        //Postal code
                        System.out.print("Enter Postal Code [ ] ");     
                        inputPostCode = Integer.parseInt(input.nextLine());
                        out.write("PostCode: "+inputPostCode+", ");
                        //Age
                        System.out.print("Enter Age [ ] ");
                        inputAge = Integer.parseInt(input.nextLine());
                        out.write("Age: "+inputAge+", ");
                        //Gender
                        System.out.print("Enter Gender '1' for Male and '2' for for female [ ] ");
                        inputGender = Integer.parseInt(input.nextLine());
                        out.write("Gender: "+inputGender+", \n");
                        out.close();          
                           } while(x != 0);
         Result:
    1 new entry or 0 print1
    Enter Questionnaire Number [ ] 2
    Enter Postal Code [ ] 1
    Enter Age [ ] 3
    Enter Gender '1' for Male and '2' for for female [ ] 4
    1 new entry or 0 print1
    Enter Questionnaire Number [ ] 2
    Exception in thread "main" java.io.IOException: Stream closed
         at java.io.BufferedWriter.ensureOpen(BufferedWriter.java:98)
         at java.io.BufferedWriter.write(BufferedWriter.java:203)
         at java.io.Writer.write(Writer.java:126)
         at TryOut.main(TryOut.java:31)
    Hi, how can i open the file writer stream again for next entry after it is has been closed? if i do not close(); all my entry will not be recorded to the text file. how can i solve this ?
    Edited by: metaroot on Feb 18, 2008 6:39 PM

    The short answer to your question: use out=new BufferedWriter(fwrite) inside the do loop as well.The only difference that would make would be to make the problem worse. It is poor practice. Stream stacks should be constructed once for the life of the stream.
    What he needs to do is close his stream outside the loop, possibly calling flush() where he presently has close().
    The more relevant answer is: Why are you not wrapping the user-friendly PrintWriter class, wrapping it around the BufferedWriter?Possibly because he doesn't like the fact that PrintWriter swallows exceptions? which makes it less user-friendly IMO.
    The println and print methods are very useful, and do not need closing between loop iterations.Neither does anything else.
    By the way,you say that without a close() the BufferedWriter doesn't output to the file.I don't know: I never used/tried it.Even if it doesn't, it will surely output after you come out of the loop.If you don't want to use a PrintWriter, why don't you investigate this?Posting guesses here isn' t really much help, especially about something you've never used. A BufferedWriter has a buffer and it doesn't write anything until the buffer is full, you flush it, or your close it.

Maybe you are looking for

  • Help (Timed program)

    I�ve done this game, that if the user takes more than 30 sec. to answer, the program, when the user answer, tells that the time has been more that 30 sec. so the answer is not valid; I would like that the program, during the time the user is answerin

  • Internal table name which hide statement uses

    Hi, To hide several variables, use chain HIDE statement. As soon as the user selects a line for which you stored HIDE fields, the system fills the variables in the program with the values stored.  A line can be selected. ¨      By an interactive even

  • Wireless strength weaker in clamshell mode- any way to remedy?

    Why is my wireless connection (via Time Capsule) much weaker when my MacBookPro is in clamshell mode? Is there a way to strengthen this other than opening the notebook? We already have an Airport Express very close to strengthen the signal. When open

  • Fscommand - window placement

    Is there any way to tell the window to justify (top, center of the screen) when opening the executable ? Mine keeps opening up at the bottom of the screen and half cut-off. Thanks. Rob Childress

  • Initialising constants using text-element

    hiii, I want to initialize the constant data object used in my ABAP program with the value of text element, Can anybody plz tell me how to do so?