Huge headache, ArrayList from Txt File

I'm trying to generate an ArrayList from a text file. But the problem is I have no idea how to go about it properly. This is what I've gotten so far.
import java.io.*;
import java.util.*;
public class reader
          try
               FileReader input = new FileReader("quizscore.txt");
               BufferedReader bufferInput = new BufferedReader(input);
               String line;
               while ((line = bufferInput.readLine ()) !=null )
               String[] result = line.split("\\s");
               for (int x=0; x<result.length; x++)
                    System.out.println(result[x]);
          catch (IOException e)
               System.out.println("Error:" + e);
}That is my data reader which is reading a text file with a buncha numbers like this,
9893 034 009 077 078 020
1947 045 040 088 078 055
2877 055 050 099 078 080
3189 022 070 100 078 077
Now I want to create an ArrayList to put all that data into. I cannot seem to set it up correctly and it's driving me nuts.
class Student
     public int idNum;
     public int quiz1;
     public int quiz2;
     public int quiz3;
     public int quiz4;
     public int quiz5;
     public Student(int id, int q1, int q2, int q3, int q4, int q5)
          this.idNum = id;
          this.quiz1 = q1;
          this.quiz2 = q2;
          this.quiz3 = q3;
          this.quiz4 = q4;
          this.quiz5 = q5;
}Now where would I put the
ArrayList StudentData = new ArrayList();
so that when I read the text file, it automatically writes into the ArrayList formated like the public Student object I have? I was orginally supposed to use the StringTokenizer but after reading the java documentation it suggested I code using the split function. So the question is, how do I get it to write every line's tokens into one array row and so on?

Using turng's code as a sort of guideline, I have created this piece of code. There are some problems though. The array doesn't seem to be writing properly.
import java.io.*;
import java.util.*;
public class getData
     public getData()
     public void load(File file)
          String[][] studentData = new String[40][6];
          try
               FileReader input = new FileReader(file);
               BufferedReader bufferInput = new BufferedReader(input);
               String line;
               while ((line = bufferInput.readLine ()) !=null )
               System.out.println(line);
               //String[] result = line.split("\\s");
               //for (int x=0; x<result.length; x++)
               //     System.out.println(result[x]);
               for (int l = 0; l <40; l++)
                         for (int i = 0; i < 6; i++)
                              String[] tokens = line.split("\\s");
                              for (int x = 0; x<tokens.length; x++)
                                   studentData[l] = tokens[x];
                                   System.out.println("L is:" + l);
                                   //System.out.print("I is:" + i);
                                   System.out.println(studentData[l][i]);
          catch (IOException e)
               System.out.println("Error:" + e);
     public static void main(String arg[])
          (new getData()).load(new File("quizscore.txt"));
Basically what happens when I run through this, it prints this (This is the last portion, I'm assuming it goes from 0-39)
L is:38
6999
L is:38
000
L is:38
098
L is:38
089
L is:38
078
L is:38
020
L is:38
6999
L is:38
000
L is:38
098
L is:38
089
L is:38
078
L is:38
020
L is:38
6999
L is:38
000
L is:38
098
L is:38
089
L is:38
078
L is:38
020
L is:38
6999
L is:38
000
L is:38
098
L is:38
089
L is:38
078
L is:38
020
L is:38
6999
L is:38
000
L is:38
098
L is:38
089
L is:38
078
L is:38
020
L is:38
6999
L is:38
000
L is:38
098
L is:38
089
L is:38
078
L is:38
020
L is:39
6999
L is:39
000
L is:39
098
L is:39
089
L is:39
078
L is:39
020
L is:39
6999
L is:39
000
L is:39
098
L is:39
089
L is:39
078
L is:39
020
L is:39
6999
L is:39
000
L is:39
098
L is:39
089
L is:39
078
L is:39
020
L is:39
6999
L is:39
000
L is:39
098
L is:39
089
L is:39
078
L is:39
020
L is:39
6999
L is:39
000
L is:39
098
L is:39
089
L is:39
078
L is:39
020
L is:39
6999
L is:39
000
L is:39
098
L is:39
089
L is:39
078
L is:39
020The actual text file that is being read,
Stud Qu1 Qu2 Qu3 Qu4 Qu5
1234 052 007 100 078 034
2134 090 036 090 077 030
3124 100 045 020 090 070
4532 011 017 081 032 077
5678 020 012 045 078 034
6134 034 080 055 078 045
7874 060 100 056 078 078
8026 070 010 066 078 056
9893 034 009 077 078 020
1947 045 040 088 078 055
2877 055 050 099 078 080
3189 022 070 100 078 077
4602 089 050 091 078 060
5405 011 011 000 078 010
6999 000 098 089 078 020It's writing the very last line throughout the whole array. Why is this? I know my loop coding is probably the problem, and I'm trying to draw out the flow on a piece of paper, but it's confusing me more and more. And I do apologize in advance if the error that's causing this is some simple coding error I should have learned before but probably haven't.
Edited by: soulesschild on Nov 16, 2007 5:39 PM

Similar Messages

  • How to read data from txt file respectively

    Hi,
    I am triying to form an equation between two known points. I want to do this with the attached VI, the most critical point is that I will read the x1, y1, x2 and y2 coordinates from the same .txt file. They will be written in a .txt file and I will send them to the appropriate channel (x1, y1, x2 and y2) respectively. How can I get data in a rule from a .txt file?
    Could anyone please help me with this issue,
    Best regards. 
    Attachments:
    read from txt file.vi ‏8 KB

    Dear RavensFan,
    Thank you very much for your helps, I am bit new to labview so I usually can not find the appropriate functions easily. And a new problem has rised in my application. I should write the A, B and C numbers in the respective series to the file 2.txt. I am able to write them in a straight forward case but I want to write the next triples (A B C) in the next row. Like this;
    A1 B1 C1
    A2 B2 C2
    A3 B3 C3
    So how can I put new line constant and space constant to my VI? 
    Waiting for your valuable helps,
    Best regards,
    Attachments:
    read_from_txt_fileMOD.vi ‏18 KB

  • Remove string from txt file

    Hello guys,
    I need some help. I have to remove some content of Tolerance "column" (see attach). The string which I wish to remove is "+/- 0s" and replace it with an empty string. I need to remove this for each row where "+/- 0s" appears.  
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    sample.txt ‏3 KB

    Hi Samoth,
    I dont know if I understood your requirement properly, but please check the attached snippet if it helps.
    If this does not satisfy your requirement, then please give some more details.
    Attachments:
    Remove string from txt file.png ‏21 KB

  • How to get Text from (.txt) file to display in the JTextArea ?

    How to get Text from (.txt) file to display in the JTextArea ?
    is there any code please tell me i am begginer and trying to get data from a text file to display in the JTextArea /... please help...

    public static void readText() {
      try {
        File testFile = new File(WorkingDirectory + "ctrlFile.txt");
        if (testFile.exists()){
          BufferedReader br = new BufferedReader(new FileReader("ctrlFile.txt"));
          String s = br.readLine();
          while (s != null)  {
            System.out.println(s);
            s = br.readLine();
          br.close();
      catch (IOException ex){ex.printStackTrace();}
    }rykk

  • How to get string (specified by line and column) from txt file with labview

    Hi everyone
    How to get string (specified by line and column) from txt file with labview
    thx 
    Solved!
    Go to Solution.

    As far as I know, a text file has no columns.  Please be more specific.  Do you mean something like the 5th word on line 4, where words are separated by a space, and lines are separated by a newline character?  You could the Read from Spreadsheet String function and set the delimiter to a space.  This will produce a 2D array of strings.  Then use index array and give the line number and column number.
    - tbob
    Inventor of the WORM Global

  • Apostroph and euro sign not read corectly from txt file

    apostroph and euro sign not read corectly from txt file.
    my code is like this:
    FileInputStream fis= new FileInputStream(x+".html");
    BufferedReader br=new BufferedReader(new InputStreamReader(fis,"UTF-8"));
    String Line="";
    while ((Line = br.readLine()) != null) result+=Line;
    br.close();
    fis.close();
    I use UTF-8 because the file contains also French characters.
    What's the problem?
    THANK YOU!

    apostroph and euro sign not read corectly from txt
    file.
    my code is like this:
    FileInputStream fis= new FileInputStream(x+".html");
    BufferedReader br=new BufferedReader(new
    InputStreamReader(fis,"UTF-8"));
    String Line="";
    while ((Line = br.readLine()) != null) result+=Line;
    br.close();
    fis.close();
    I use UTF-8 because the file contains also French
    characters.
    What's the problem?
    THANK YOU!
    This is from the FileInputStream API documentation:
    FileInputStream is meant for reading streams of raw bytes such as image data. For reading streams of characters, consider using FileReader.

  • Auto delete everything but specified folder contents from txt file

    Hey Guys,
    I am brand new to using Powershell (like 48 hours into using it for work) and I've run into a bit of an issue.  I've only taken a programming concept classes so some of the stuff makes sense to me but a lot of it is new.  Basically I've made a
    script that automatically deletes any files over X amount of days.  My next step is to have an exceptions text that will have a list of folders that should not have its contents deleted.  This is what I have so far.
    $Date= Get-Date 
    $Days = "7"
    $Folder = "C:\publicftp\users"
    $LastWrite = $Now.AddDays(-$Days)
    #----- getting DO NOT DELETE listing from TXT ----#
    $Exceptions = Get-Content "c:\exclude.txt"
    $Files = Get-Childitem $Folder -Recurse -Exclude "c:\exclude.txt" | Where {$_.LastWriteTime -le "$LastWrite"}
    foreach ($File in $Files)
        if ($File -ne $NULL)
            Remove-Item $File.FullName -Exclude $Exceptions | out-null
    I've seen a lot of threads that show how to auto delete contents or how to exclude specific file types but I haven't seen an answer to my particular problem.  Any help would be greatly appreciated!  Thanks!

    Hi Rabbot,
    The script below may be also helpful for you, and uses the -whatif parameter in Remove-Item cmdlet, which doesn’t actually remove anything but simply tells you what would happen if you did call Remove-Item.
    $Exceptions = @()
    Get-Content "c:\exclude.txt" | foreach{
    $Exceptions += $_} #store the exception file to array
    $Folder = "C:\publicftp\users"
    $LastWrite = (get-date).adddays(-7) #over 7 days.
    $Files = Get-Childitem $Folder -Recurse | Where {$_.LastWriteTime -le $LastWrite} #filter files which over 7 days.
    Foreach ($file in $files){
    if ($Exceptions -notcontains $file.fullname){ #if the file is not listed in the exception array.
    Remove-Item $File.FullName -whatif} #use -whatif to test
    I hope this helps.

  • Scenario to read from txt-file and create a sales order

    Hi,
    i have started creating a scenario to read from an txt-file and to create a sales order.
    When i activate my scenario, i get the following message :
        no scenario step (vBIU) associated for this step for the incoming system (SysId)
    When i look into the detailed xml-file i see that all the records are read from the file, but there is no next step to be treated.
    Has somebody any idea how this come ?
    -<Msg MessageLog="true" msglogexcl="false" logmsg="0009" recording="true" BeginTimeStamp="20111202095144" MessageId="11120209514499820828C0A801674F24" xmlns="urn:com.sap.b1i.vplatform:entity">-<Header><msglog b1ifactive="true" always="false" step="Default message log"/>-<Resumption><starter ipo="/vP.0010000138.in_FEAN/com.sap.b1i.vplatform.runtime/INB_FI_EXST_ASYN_NAM/INB_FI_EXST_ASYN_NAM.ipo/proc"/></Resumption><IPO tid="11120205535899820808C0A801678C54" Id="INB_FI_EXST_ASYN_NAM"/><Sender Id="0010000138"/><Inbound file="ORDERS_TEST" ext="csv" path="C:\TEMP\In" pltype="txt" wrap="" deli=";"/></Header>-<Body><Payload Type="File exist" Role="T"/>-<Payload Role="S">-<io xmlns="urn:com.sap.b1i.bizprocessor:bizatoms" pltype="txt">
    -<row>
    <col>OH</col>
    <col>0000087077</col>
    <col>201110041205</col>
    <col>220</col>
    <col>9</col>
    <col>201110191702</col>
    <col>8710624300012</col>
    <col>8714252008609</col>
    <col>8710624300012</col>
    <col>8714252008609</col>
    <col>8710624300012</col>
    <col>N</col>
    <col>N</col>
    <col>N</col>
    </row>
    -<row>
    <col>OL</col>
    <col>1</col>
    <col>8711715844378</col>
    <col>20</col>
    </row>-<row>
    <col>OL</col>
    <col>2</col>
    <col>8711715844392</col>
    <col>60</col>
    </rowrow>
    <col>OL</col>
    <col>16</col>
    <col>8710251791092</col>
    <col>280</col>
    </row>
    </io>
    </Payload>
    </Body>
    </Msg>
    This is my final atom :
    <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:b1e="urn:com.sap.b1i.sim:b1event" xmlns:b1ie="urn:com.sap.b1i.sim:b1ievent" xmlns:bfa="urn:com.sap.b1i.bizprocessor:bizatoms" xmlns:jdbc="urn:com.sap.b1i.adapter:jdbcadapter" xmlns:rfc="urn:sap-com:document:sap:rfc:functions" xmlns:sim="urn:com.sap.b1i.sim:entity" xmlns:utils2="com.sap.b1i.bpc_tools.Utilities" xmlns:vpf="urn:com.sap.b1i.vplatform:entity" xmlns:xci="urn:com.sap.b1i.xcellerator:intdoc" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" bfa:force="" vpf:force="" jdbc:force="" rfc:force="" b1ie:force="" b1e:force="" xci:force="" sim:force="" utils2:force=""><xsl:output method="xml" encoding="UTF-8" indent="yes"></xsl:output><xsl:param name="atom"></xsl:param><xsl:param name="sessionid"></xsl:param><xsl:variable name="msg" select="/vpf:Msg/vpf:Body/vpf:Payload[./@Role=&apos;S&apos;]"></xsl:variable><xsl:variable name="vpSender" select="/vpf:Msg/vpf:Header/vpf:Sender/@Id"></xsl:variable><xsl:variable name="vpObject" select="/vpf:Msg/vpf:Header/vpf:Sender/@ObjId"></xsl:variable><xsl:variable name="vpReceiver" select="/vpf:Msg/vpf:Header/vpf:ReceiverList/vpf:Receiver[./@handover=&apos;P&apos;]/@Id"></xsl:variable><xsl:template match="/">
    <Msg xmlns="urn:com.sap.b1i.vplatform:entity">
    <xsl:copy-of select="/vpf:Msg/@*"></xsl:copy-of>
    <xsl:copy-of select="/vpf:Msg/vpf:Header"></xsl:copy-of>
    <Body>
    <xsl:copy-of select="/vpf:Msg/vpf:Body/*"></xsl:copy-of>
    <Payload Role="R" id="{$atom}">
    <xsl:call-template name="transform"></xsl:call-template>
    </Payload>
    </Body>
    </Msg>
    </xsl:template><xsl:template name="transform">
    <FinalAtomResult xmlns="">
    <BOM>
    <BO>
    <AdmInfo>
    <Object>17</Object>
    <Version>2</Version>
    </AdmInfo>
         <Documents>
         <row>
         <DocDate>
              <xsl:copy-of select="$msg/io/row[0]/col[2]/text()"></xsl:copy-of>
         </DocDate>
         <DocDueDate>
              <xsl:copy-of select="$msg/io/row[0]/col[5]/text()"></xsl:copy-of>
         </DocDueDate>
         <CardCode>KD10251</CardCode>
         <NumAtCard>
              <xsl:copy-of select="$msg/io/row[0]/col[1]/text()"></xsl:copy-of>
         </NumAtCard>
         <U_PMX_JD_COMP>32</U_PMX_JD_COMP>
         </row>
                          </Documents>
         <Document_Lines>
         <xsl:for-each select="$msg/io/row">
         <row>
         <BarCode>
              <xsl:copy-of select="$msg/io/row[*]/col[2]/text()"></xsl:copy-of>
         </BarCode>
         <Quantity>
              <xsl:copy-of select="$msg/io/row[*]/col[3]/text()"></xsl:copy-of>
         </Quantity>
         </row>
         </xsl:for-each>
         </Document_Lines>

    Mike,
    you were right, you may not specify the extension of a file.
    Another thing i detected is that the loop of my data start with the index 1 instead of 0 !!!
    In this scenario, i have to read all the lines of the file and each time i should do a SQL-query,
    so that i can use the result to build my sales document.
    Do you know if it this is possible or have you any idea how to do this ?
    thx,
    Mario

  • SQL Loader problem while loading records from txt file to database table.

    I am getting following error while loading records from flat txt file into database table with the help of 'sqlldr' command. I have executed catldr.sql from RDBMS folder but it is still showing same error. I am setting DIRECT = TRUE while issuing sqlldr command. If I try with DIRECT = FALSE then it works fine. Database is Oracle 8i.
    SQL*Loader-951: Error calling once/load initialization
    ORA-24329: invalid character set identifier
    F1 Please.

    Hello,
    Direct path load, can only be used with SQL*Loader and Database have the same version.
    Care to tell the database version and sql*loader version you are using.
    -Sri

  • Text layers from .txt file for buisness cards

    I have a template for a business card that I created for a company. So  imagine I have a background layer which is the card itself, and above  that a layer for each string of text on the card (name, title, phone,  email). Up until now, I would manually enter all the information using  the Type tool to edit each text layer. However, it has become very  tedious and I know there has to be a much easier way to do this. I'm  looking for a way to automate this process.  So far I have created an Excel database of all the  employees, and I export each employees information to a .txt file that  looks like this:
    John Doe
    Job Title
    123-456-7890
    123-456-7890
    [email protected]
    Each line in the .txt file corresponds to a text layer on the .psd. I've  tried following a tutorial from the web (kirupa.com - Photoshop Scripting) but he is creating  them in batches which is not what I need to do. And quite frankly, it's  a bit over my head. I know scripting must be the way, but unfortunately  I don't know much about JaveScript or any  other language for that matter.
    I know it's a lot to ask for, but if anyone could show me how to write a  simple script for this or point me in the right direction, it would be  much appreciated. And I mean MUCH!

    Hey man, that was spot on! This does exactly what I was looking for, now scripting required. Thanks for the help, I really appreciate it.

  • Read at each new line from .txt file

    Hi guys
    I want to read from a file which I am saving using labview. What I am doing is reading 128 bytes fro VISA port and saving it in .txt file with new line constant. At some later time I want to read 128 bytes from that text file do some processing and display it. The "read from text file" vi has convert EOL but I am not able to configure it. Please help me..
    Thanks in advance
    Niladri

    Hi Newbee_3,
                                                  Do 1 thing, Read the txt file & convert this into string, Then you have all the flexibility to do whatever you want.
    Thanks
    Kudos are always welcome if you got solution to some extent.
    I need my difficulties because they are necessary to enjoy my success.
    --Ranjeet

  • Read from .txt file and output the content as two arrays

    I am using the contoured move to control the x-y stage. The trajectory datas for x and y axis are generated using my interpolation program and it is stored in a .txt file as two columns. What I want to do is read .txt file and output the content of this file as two arrays. Is there anyone has any ideas? Thanks, the .txt file is attached.
    Attachments:
    R.75.txt ‏172 KB

    Hi Awen,
    This is quite easy to do, you can merely use the "read from spreadsheet file" function to get a 2D array (2 columns and n rows) and then use the index array function to get whatever row/colums you want..
    Hope the attached VI helps you
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    read sprdsheet file.vi ‏27 KB

  • Read from txt file and analyse data

    hi,
    i am having a problem for reading data from a text file and checking whether it is a integer or not.
    basically if i have a txt file with the following content:
    12 45 345 500 45.67684 33
    my output should be:
    12 45 345 500 invalid 33
    that means if there is a integer number in the file, the integer number will be printed on the screen BUT if there is anything else like a string or a double number, then "invalid" will be printed.
    how can i check what kind of datatype it is??
    i have the following code to start with:
    try
                BufferedReader in = new BufferedReader(new FileReader(FileName));
                String l = in.readLine();
                in.close();
            catch(IOException e)
                System.out.println("IO error");
                System.exit(0);
            }

    ok i have tried the following code:
            int index = 0;
            String[] arr = null;
            int nb = 0;
            try
                BufferedReader in = new BufferedReader(new FileReader(nameFile));
                String line = in.readLine();
                arr = line.split(" ");
                for(int i=0; i<arr.length; i++)
                    index = i;
                    nb = Integer.parseInt(arr);
    System.out.print(nb+" ");
    in.close();
    catch(IOException e)
    System.out.println("IO error");
    System.exit(0);
    catch(NumberFormatException e)
    System.out.print("invalid ");
    for(int j=index+1; j<arr.length; j++)
    nb = Integer.parseInt(arr[j]);
    System.out.print(nb+" ");
    which works perfectly fine for the following scenario:
    txt-file:
    12 45 345 500 45.67684 33
    output:
    12 45 345 500 invalid 33
    but what, if I have the following data in my txt file:
    12 45 345 500 45.67684 33 23.234 21
    then the output should be:
    12 45 345 500 invalid 33 invalid 21
    how can i solve this???

  • Pulling output data from .txt file

    Hello, I am trying to have a program that allows a user to input shopping items into the program andhave that input go to a .txt file called shoppinglist, then after the user is finished, he/she can type no to stop entering items to the list and the program will then pull all the info entered to the .txt file and output it to the screen, creating a shooping list for the user. My problem is that I am not quite sure how to output the data from the .txt file to the screen. Here is my code.
    import java.io.*; // uses the java io library for the
    import java.util.*; // BufferedReader class
    public class week5
    public static void main(String [] args)
    PrintWriter inputItems = null;
    try
    inputItems = new PrintWriter(new FileOutputStream("shoppinglist.txt"));
    BufferedReader outputItems = null;
    String line = null;
    outputItems = new BufferedReader(new FileReader("shoppinglist.txt"));
    line = outputItems.readLine();
    outputItems.close();
    catch(FileNotFoundException e)
    System.out.println("File file.txt not found");
    System.out.println("or could not be opened.");
    catch(IOException e)
         System.out.println("Error reading from file file.txt.");
    System.out.println("This program will create a shopping list:");
    String keepGoing = "yes";
    String item = null;
    Scanner keyboard = new Scanner(System.in);
    for (int count = 1; count < 999 && keepGoing.equalsIgnoreCase("yes");count++)
    //ask for input, write it to a file
    System.out.print("Please enter item # " + count + ": ");
    System.out.print("");
    item = keyboard.nextLine();
    inputItems.println(count + " " + item);
    //ask if you want to keep going
    System.out.print("Do you wish to enter more items (yes/no): ");
    System.out.print("");
    keepGoing = keyboard.nextLine();
    System.out.println("Your shopping list contains: " + item);
    System.out.print("");
    inputItems.close();
    } All the above does is output the last item entered by the user, not the whole shopping list. Any help is greatly appreciated.

    nim_ramesh wrote:
    outputItems = new BufferedReader(new FileReader("shoppinglist.txt"));
    /* I think u want to print the text here so */
    line = outputItems.readLine(); // Replace this line with that while loop
    outputItems.close();
    He hasn't even read the user input at that point.
    OP, you need to sit down and think about the exact order you want to do things in, and rewrite your code in a logical straightforward manner. It looks like you just threw some code in hoping it would work, instead of coding deliberately. I'm not insulting you or anything, I know you're new to Java. I'm just trying to give you some advice. Look at your code, and ask yourself why the following line of code appears before you've even written anything to your file:
    line = outputItems.readLine();

  • How to initialize Object  Array Data Provider (OADP)with data from txt file

    Hi,
    I want to show in a table some columnar data from a txt file. I ran the creator demo application on OADP successfully. http://blogs.sun.com/divas/entry/using_the_object_array_data
    I created a javabean class to read a txt file.However, I am stuck at how I can fill the data into an OADP array:
    I am familiar with C extensively but not much at java. can anyone help??
    thanks..
    dr.am.mohan rao

    Thanks for that. I changed it a little bit, but when i ran this script, got ORA-06532: Subscript outside of limit.
    declare
    O_voucher_comment SYSADM.AP_COMMENT_COLL := sysadm.ap_comment_coll(null);
    begin
    FAS_AP_EXCEPTIONS.GET_VOUCHER_COMMENTS('FCCAN', '20494753', 0, 'KEHE', O_voucher_comment);
    end;
    PROCEDURE get_voucher_comments (
    v_bu_in IN VARCHAR2,
    v_voucher_in IN VARCHAR2,
    v_line_in IN NUMBER,
    v_userid IN VARCHAR2,
    voucher_comment OUT      sysadm.ap_comment_coll
    IS
    i NUMBER := 1;
    v_comments VARCHAR2 (254) := ' ';
    comment_type sysadm.ap_comment_type;
    v_line_num NUMBER := 0;
    CURSOR get_all_comment
    IS
    SELECT voucher_line_num, descr254_mixed FROM ps_fas_ap_comment
    WHERE business_unit = v_bu_in AND voucher_id = v_voucher_in;
    CURSOR get_line_comment
    IS
    SELECT descr254_mixed FROM ps_fas_ap_comment
    WHERE business_unit = v_bu_in AND voucher_id = v_voucher_in
    AND voucher_line_num = v_line_in;
    BEGIN
    --voucher_comment() := SYSADM.ap_comment_type (NULL, NULL, NULL, NULL, NULL, NULL);
    --' ', ' ', 0, ' ', '', ' ' sysadm.ap_comment_coll
    voucher_comment := sysadm.ap_comment_coll(null);
    IF v_line_in = 0
    THEN
    OPEN get_all_comment;
    LOOP
    FETCH get_all_comment
    INTO v_line_num, v_comments;
              if i > 1
              then
                   voucher_comment.EXTEND;
              end if;
    voucher_comment (i) := ap_comment_type (v_bu_in,
    v_voucher_in, v_line_num, v_userid,
    TO_DATE (TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS'), 'DD-MON-YYYY HH24:MI:SS'), v_comments );
    i := i + 1;
    END LOOP;
    ELSE
    OPEN get_line_comment;
    LOOP
    FETCH get_line_comment
    INTO v_comments;
              voucher_comment.extend(6);
    voucher_comment (i) := ap_comment_type (v_bu_in, v_voucher_in, v_line_num, v_userid, TO_DATE (TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS' ), 'DD-MON-YYYY HH24:MI:SS'), v_comments);
    i := i + 1;
    END LOOP;
    END IF;
    END get_voucher_comments;

Maybe you are looking for