Huge String Array into smaller different arrays

Hello,
I have an requirement wherein i'll be getting a huge array of Strings (say 10000) elements. This number is variable.
Now i have to break the same into smaller chunks/arrays (say 100 element each).
Thanks,
Piyush

Hi,
try this.
TYPES :
  BEGIN OF type_s_fs,
  field(100) TYPE c,
END OF type_s_fs.
DATA fs TYPE type_s_fs.
DATA itab LIKE STANDARD TABLE OF fs.
DATA itab1 LIKE STANDARD TABLE OF fs.
DATA w_d TYPE i.
w_d = STRLEN( w_c ).-----> ( Declare ur longstring here  with w_c )
DIVIDE w_d BY 100.
add 1 to w_d.
DATA w_t TYPE i.
DO w_d TIMES.
  fs-field = w_c+w_t(100).
  APPEND fs TO itab.
  CLEAR fs.
  ADD 100 TO w_t.
ENDDO.
LOOP AT itab INTO fs.
write :/ fs-field.
ENDLOOP.
With this u can split at 100 characters into single internal table.
Now , loop at this table and assign each record to required internals tables just by reading 1 row.
Or
make use of fieldsymbols.

Similar Messages

  • Copying Multiple Arrays into One Large Array

    I'm currently trying to copy multiple character arrays into one larger character array in a method that prints data gathered from a database. Here is my code:
    private static void printData(String[] data){
            try {
                int totalLengthOfAllStrings = 0;
                for(int i = 0; i < data.length; i++) {
                    data[i] += '\n';
                    totalLengthOfAllStrings += data.length();
    int runningLength = 0;
    char[] printArray = new char[totalLengthOfAllStrings];
    for(int j = 0; j < data.length; j++) {
    char[] tempArray = data[j].toCharArray();
    runningLength += tempArray.length;
    System.arraycopy(tempArray, 0, printArray, runningLength - 1, tempArray.length);
    DocFlavor df = DocFlavor.CHAR_ARRAY.TEXT_PLAIN;
    Doc printDoc = new SimpleDoc(printArray, df, null);
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(1));
    aset.add(MediaSize.NA.LETTER);
    aset.add(Sides.DUPLEX);
    PrintService[] services = PrintServiceLookup.lookupPrintServices(df, aset);
    if (services.length > 0) {
    DocPrintJob job = services[0].createPrintJob();
    try {
    job.print(printDoc, aset);
    System.out.println("Print successful!");
    catch (PrintException pe) {
    catch(Exception e) {
    e.printStackTrace();
    I keep getting an ArrayIndexOutOfBoundsException and for the life of me I can't figure out why.
    Can anyone help with this?
    Thanks!
    -Matt

    I think your problem lies with the second for loop:
    for(int j = 0; j < data.length; j++)  {
        char[] tempArray = data[j].toCharArray();
        runningLength += tempArray.length;
        System.arraycopy(tempArray, 0, printArray, runningLength - 1, tempArray.length);
    }If I am not wrong, you should swap the sequence of the runningLength and System.arraycopy statements, and also move the minus 1 from arraycopy statement to the runningLength statement. The result would look like this:
    for(int j = 0; j < data.length; j++)  {
        char[] tempArray = data[j].toCharArray();
        System.arraycopy(tempArray, 0, printArray, runningLength, tempArray.length);    // swapped and removed the -1
        runningLength += tempArray.length - 1;    // swapped and appended the -1
    }The main reason for these changes is because when j == data.length - 1, the value of runningLength would have already exceeded the size of printArray. Therefore, swapping the position would be able to overcome this problem.

  • 1-D Array into 2-D Array

    Hi: I need help on how to copy contents of a 1-D array into a 2-D array.
    For Example:
    int[] a = {0,1,2,3,4,5,6,7};
    into:
    int[][] b = {{0,1,2,3},{4,5,6,7}};
    Can someone please help me with ideas?
    Thanks

    So, how do I copy the content of an 1-d array ofsize
    say 8 into a 2-d array of size 2x4?By writing the appropriate code of course.
    (I know how to do it, but spoon-feeding it to youdoes you no good actually)
    If you already know how to do it, why re-inventing
    the wheel? If you do not want to suggest me, then
    don't say anything. It is not like I did not try
    anything; I tried it, but it did not work,So post what you tried and what results you saw. (As noted earlier, your previous code and output do NOT go together.)
    And why not try what I suggested--adding print statements so that you can actually unerstand what your code is doing?
    And/or step through the code manually as somebody else suggested?
    then only
    I posted the question on the forum to get some help
    from someone - not for telling me that someone knows
    the answer and he does not want to spoon-feed me.There's nothing to be gained by somebody handing you the answer. Most people come here to help others learn. Handing you the answer when you get stuck will simply stunt your education. You need to work through it yourself as much as possible, with a nudge here and there to get you going again when you get really stuck.

  • Java Programming: Any Ideas for breaking a huge class file into smaller ?

    Hello Java pros,
    I have some very huge class files, some with dozens of methods; each method containing an average of a screen-page full of code.
    Obviously, such huge class files are difficult to maintain inspite of using an IDE, especially when changes have to be made to a bunch of a category of methods scattered all over the class.
    I am wondering if there are ways/best-practices out there to make the core class file smaller/smarter - fr eg.
    <a> by retaining the real core definitions within the core class and moving the detailed implementation outside the core class
    <b> by breaking down the file into more manageable pieces - something to the effect of using 'include' files that some languages support
    etc.
    Thanks for your help in advance.
    Sree Nidhi

    If you have huge class files with dozens of methods, maybe the design of your application is not so sound. You could use all kinds of OO design techniques to design your application so that it is easier to maintain.
    Start by learning about design patterns. The most famous book about design patterns is this one: http://www.amazon.com/exec/obidos/ASIN/0201633612/qid=1029971487/sr=2-1/ref=sr_2_1/102-4299125-5141710
    Here is also a nice book about anti-patterns: http://www.antipatterns.com/
    Jesper

  • Need to convert a 2D array into two 1D arrays to be fed into Build XY Graph

    Hi Need to convert the 2D Output of a sub vI for display on XY Graph. Help!!! I cant find an array function that takes a 2D input and un-builds to 2 * 1D arrays

    Hi Dave,
    if it is working than that's it.
    I'm using the german version of LabView and it is sometimes difficult to translate the names ;-)
    Stephan

  • Variable number of two dimensional arrays into one big array

    I have a variable number of two dimensional arrays.
    The first dimension is variable, the second dimension is always 7.
    i.e.:
    Object[][] array0 = {
    {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
    {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
    Object[][] array1 = {
    {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
    {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
    Object[][] arrayi = ...I'm generating these arrays with a for-loop:
         for (int i = 0; i < filter.length; i++) {
              MyClass c = new MyClass(filter);
              //data = c.getData();
    Where "filter" is another array which is filled with information that tells "MyClass" how to fill the arrays.
    "getData()" gives back one of the i number of arrays.
    Now I just need to have everything in one big two dimensional array.
    i.e.:Object[][] arrayComplete = {
    {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
    {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
    {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
    {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
    Any idea on how to accomplish this? It's blowing my mind right now.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Just brainstorming here:
    Why not put your actual data in a class and store that in a LinkedList (so you know the total number of elements for your multi-dimensional array). Then initalize your multi-dimensional array and populate it? Haven't tested the following, but thinking something along the lines of
    public class MyData {
         //data here
         public Object[] toArray() {
              //something similar to this
              return new Object[] = {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"};
    LinkedList<MyData> data = new LinkedList<MyData>();
    data.add(mydata1);
    //however many times you need
    Object[][] arrayComplete = new Object[data.size()][7];
    for(int i = 0; i < data.size(); i++) {
         arrayComplete[i] = data.removeFirst().toArray();
    }Another option for knowing how many rows you would need might be using something like:
    int rows = 0;
    rows += array1.length;
    rows += array2.length;
    //etc...But is not entirely useful if you don't know how many variable arrays you have (although reflections might help if the name of the array variable is incremented systematically, someone told me earlier to avoid reflections since it could make debugging a LOT more difficult).
    Edited by: bogdana on Apr 1, 2010 10:38 AM

  • Splitting mulit-dime​nsional array into 1-D array

    Hi,
    I am a new user learning fudamentals in labview....
    I have an Numeric Array of 4-columns and many rows,the rows keeps growing...
    I need to read the data by column wise and plot it on the xy-graph.
    plotting should be like this ..........
            2nd column data in x-axis and(should be used as x-scale) ........to plot the y-axis data with reference to x-axis scale
             3rd column and 4th column data in y-axis..
    please give some example vi's to read the array by row-wise...
    Regards
    Rajasekar

    A nice feature of the Index Array that you might not know as a beginner is that it is expandable.  I think the attached code is basically what you are looking for.
    Attachments:
    Example.vi ‏15 KB

  • How to split an array (*not String*) into smaller arrays?

    Hello,
    let's say you have an array of bytes whith length (for example) 5000B. Now you want to split this array into smaller ones, for example 1500B. Then you will have 3 arrays of 1500B and another one of 500B. What I try to do then is the following:
    pointer = 0;
    size = source.length; // For example, size = 5000
    maxsize = 1500;
    while ((size - pointer) > maxsize) {
       byte[] dest = new byte[maxsize];
       System.arraycopy(src, pointer, dest, pointer, maxsize);  // <--- Errors here!
       pointer += maxsize;
       // Do some stuff here with the dest array
    }There's no errors at compile time. But at runtime, the first iteration everything works OK (the 1500 first bytes are copied to the dest array). However, in the second iteration, the java interpreter claims:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
            at java.lang.System.arraycopy(Native Method)And I don't know what I'm doing bad. I guess there's a stupid question I can't see by myself... Help wanted, please!

    > System.arraycopy(src, pointer, dest, pointer, maxsize);should be
    System.arraycopy(src, pointer, dest, 0, maxsize);Since you're copying to the first position in the destination array.

  • Averaging 3D array into 1D array.

    Hi,
    I have a 3D array containing XY points of several loops and
    i am trying to average the data points of my array into a 1D array that should
    contain 1Loop with XY points. Can someone help me out?
    Thanks 
    Mutah
    Qui ose vaincra.
    Solved!
    Go to Solution.

    Hi Mutah,
    it really doesn't help so much...
    There is no 3D array in your VI, just two 2D arrays. You also don't mention what to average in those arrays: rows, columns, or something completely different?
    Also: what do you mean by "loop" ("see a loop", "final loop")? Do you mean FOR loops, WHILE loops? Or rows/columns of an array?
    At least a small hint in the attachment...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    program.vi ‏136 KB

  • Strings adding zero's to arrays

    I have a program that arranges 4 arrays which consist of columns of 10
    data points from each iteration of the program. The final program puts
    these sets of 10 pts into one long column. I converted the array into a
    spreadsheet string. I used the match pattern to find and replace the new
    line characters and returns with tabs. Each column has 10 data
    points, then one zero separating them from the next 10 points. I've
    tried the same idea using backspace, form feed, space characters, etc,
    and I still have one row of zeros separating my data points. Does
    anyone have any idea what this character could be or how to fix this? I
    tried all of the characters in the manuals and none will get rid of this
    problem.
    Heather
    Sent vi
    a Deja.com http://www.deja.com/
    Before you buy.

    The poster who suggested the "zeroes" could be squares- signifying a
    non-printable character, may be on the right track.
    However, it occurs to me that you're using quite an unwieldy way of tackling
    a simple problem- and that the way you're using is unnecessarily platform
    dependent and complicated by the need to handle a return and a linefeed.
    I'm not quite sure how your arrays are arranged- as four discreet arrays?
    If it's four separate arrays with 10 points and you want one big array, you
    can use the "build array" function. If you pop up the right mouse button
    menu over this, you see an option to change an input from an element to an
    array. If you make a "build array" with four array inputs, what you get out
    is one long 1D array with the four sets of data appended one after the
    other. If you then want the output as one long column, a useful trick is to
    feed your new array into another "build array" node, this time with only a
    single "element" input. This promotes the 1D array to a single column 2D
    array, that you can then feed through a "transpose 2D array" and then into a
    "build spreadsheet string" to generate your output string without having to
    do all the search and replace operations. You may or may not need the
    "transpose 2D array", depending on how the file turns out- I tend to simply
    do things like this without thinking them through and then tweak them to
    make them work- which I find quicker than going through all the details in
    advance.
    wrote in message news:[email protected]...
    > I have a program that arranges 4 arrays which consist of columns of 10
    > data points from each iteration of the program. The final program puts
    > these sets of 10 pts into one long column. I converted the array into a
    > spreadsheet string. I used the match pattern to find and replace the new
    > line characters and returns with tabs. Each column has 10 data
    > points, then one zero separating them from the next 10 points. I've
    > tried the same idea using backspace, form feed, space characters, etc,
    > and I still have one row of zeros separating my data points. Does
    > anyone have any idea what this character could be or how to fix this? I
    > tried all of the characters in the manuals and none will get rid of this
    > problem.
    >
    > Heather
    >
    >
    > Sent via Deja.com http://www.deja.com/
    > Before you buy.

  • Pushing array into array

    lets say I have
    var myAr:Array = new Array(value, value2, value3);
    var holdAr:Array = new Array();
    holdAr.push(myAr);
    when I trace out holdAr: value, value2, value3
    however, if I trace out holdAr[0], I get the same as tracing
    holdAr.... how can I push an array into a new array and keep the
    indexes?

    You are only adding one element to the array holdAr. That
    element is an array with three indices. I think you need to add the
    elements one at a time to get what you're looking for.

  • Splitting and type casting huge string into arrays

    Hello,
    I'm developing an application which is supposed to read measurement files. Files contain I16 and SGL data which is type casted into string. I16 data is data from analog input and SGL is from CAN-bus data in channel form. CAN and analog data is recorded using same scan rate.
    For example, if we have 6 analog channels and 2 CAN channels string will be (A represents analog and C represents CAN):
    A1 A2 A3 A4 A5 A6 C1 C2 A1 A2 A3 A4 A5 A6 C1 C2 A1 A2 .... and so on
    Anyway, I have problems reading this data fast enough into arrays. Most obvious solution to me was to use shift registers and split string in for loop. I created a for loop with two inner for loops. Number of scans to read from string is wired to N terminal of the outermost loop. Shift register is initialized with string read from file.
    First of the inner loops reads analog input data. Number of analog channels is wired to its N terminal. It's using split string to read 2 bytes at a time and then type casts data to I16. Rest of the string is wired to shift register. When every I16 channel from scan is read, rest of the string is passed to shift register of the second for loop.
    Second loop is for reading CAN channels. It's similar to first loop except data is read 4 bytes at a time and type casted to SGL. When every CAN channel from scan is read, rest of the string is passed to shift register of the outermost loop. Outputs of type cast functions are tunneled out of loops to produce 2D arrays.
    This way reading about 500 KB of data can take for example tens of seconds depending on PC and number of channels. That's way too long as we want to read several megabytes at a time.
    I created also an example with one inner loop and all data is type casted to I16. That is extremely fast when compared to two inner loops!
    Then I also made a test with two inner loops where I replaced shift register and split string with string subset. That's also faster than two inner loops + shift register, but still not fast enough. Any improvement ideas are highly appreciated. Shift register example attached (LV 7.1)
    Thanks in advance,
    Jakke Palonen
    Attachments:
    String to I16 and SGL arrays.vi ‏39 KB

    OK, there is clearly room for improvement. I did some timing and my two above suggestions are already about 100x faster than yours. A few teeaks led to a version that is now over 500x faster than the original code.
    A few timings on my rather slow computer (1GHz PIII Laptop) are shown on the front panel. For example with 10000 scans (~160kB data as 6+2) my new fastest version (Reshape II) takes 14 ms versus the original 7200ms! It can do 100000 scans (1.6MB data) in under 200 ms and 1000000 scans (15MB data) in under 2 seconds.
    I am sure the code could be further improved. I recommend the Reshape II algoritm. It is fastest and can deal with variable channel counts. Modify as needed.
    Attached is a LabVIEW 7.1 version of the benchmarking code, containing all algorithms. I have verified that all algorithms produce the same result (with the limitation that the cluster version only works for 6*I16+2*SGL data, of course). Remember that the reshape function is extremely efficient, because it does not move the data in memory. I have some ideas for further improvements, but this should get you going.
    Message Edited by altenbach on 08-05-2005 03:06 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    StringI16SGLCastingTimer.png ‏48 KB
    StringtoI16andSGLArraysMODTimer.vi ‏120 KB

  • Write arrays into a text file in different columns at different times

    Hi,
              I have a problem write data into a text file. I want to write 4 1D arrays into a text file. The problem is that I need to write it at different time and in different column (in other word, not only append the arrays).
    Do you have an idea to solve my problem?
    Thank you

    A file is long a linear string of data (text). In order ro insert columns, you need to rewrite the entire file, because colums are interlaced over the entire lenght of the file.
    So:
    read file into 2D array
    insert columns using array operations
    write resulting 2D array to file again.
    (Only if your colums are guaranteed to be fixed width AND you know the final number of colums, you could write the missing columns as spaces and then overwrite later. Still, it will be painful and inefficient, because column data are not adjacent in the file.)
    LabVIEW Champion . Do more with less code and in less time .

  • How to put a String into a byte array

    How can i put a String into a byte array byte[]. So that i can send it to the serial port for output to an LCD display. Cheers David

    javadocs for String
    getBytes
    public byte[] getBytes()
    Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
    Returns:
    The resultant byte arraySince:
    JDK1.1

  • Correlation Between several Different Arrays & Saving Results Into a.CSV file

    Hello Everyone!
    I have 3 arrays from which I initialize a .CSV file when I run my VI (
    as you can see in the example file.)( I use data from other arrays as
    well but it is not important )
    The First array "customer Number" can be from 0 - 15
    The second array "Customer Present" is a Boolean.
    The Third array will contain some fix values like " milk, meat, clothing....." it will have 14 different categories.
    The Fifth array will contain the quantity of the products from each category from the previous array.
    My job is to add in my initialized .CSV file the values from the 4th and 5th array but only for the customers that are present.
    The result should look something like the second part of the doc I give( which sadly, I created by hand)
    If no customer has bought something from a category it should not be mentioned.
    Also it would be nice for me if I separated the file for each customer ( create 16 different files )
    I hope someone has some idea, because I don't.
    I figured out that I should have the bool array into a case structure and if the customer is present then........
    Thank you in advance!
    Attachments:
    Initilized&Data.doc ‏42 KB
    Initialize.GIF ‏21 KB

    I don't understand where correlation fits into this...
    It seems to me that you're trying to write out a file from the values on front panel controls, rather than the other way around, as Bernd was suggesting. I see no actual read functions in your screenshot. What does your front panel look like? Can you post the VI and give a brief description on how it's supposed to be used? You seem to have some front panel arrays that you're indexing out. For this you should be using auto-indexing rather than using a fixed constant. Also, the local variables are completely unnecessary - what I see is text-based programming.

Maybe you are looking for