Loopping in an String array
How to loop in a String array in ABAP?
when you talk about loop....a loop is meant to traverse multiple entries....for example in a table...we can loop on rows...
what exactly do you mean by looping on a string array (As such there are no arrays in ABAP).
if you have multiple strings, you can put each string in an internal table and then loop through this internal table using the LOOP AT....ENDLOOP statements.
in case of a single string, you can traverse it using offsets
eg : STR+0(10) ---> which means start from position 0 and read 10 characters.
please clarify a bit more on your requirement.
Similar Messages
-
Remove null values from string array
Hi ,
I have a string array in a jsp page which I save some values inside. After I store the values I want to print only those who are not null. How can I do this? Is there a way to delete the null values?Thank you but because I am new in programming what do you mean to use continue. Can you explain it a little bit further?<%
//go through the array to check all the values
for(int i=0; i<array.length();i++) {
//If array is null, nothing happen
if(array==null){
//leave here blank; instead use continue like:
//this will skip the statements next to it, and increments the value of i in for loop and continues to execute the body of for loop.
//The same will be repeated till the last iteration.
continue;
//If array not null, then print value in a new line
else{
out.print(array+"<br>"); //don't change the logic here
%> -
Newbie trying to sort 2D string array
Dear all,
After read some book chapters, web sites including this, I still don't get the point.
If I have a file like,
1 aaa 213 0.9
3 cbb 514 0.1
2 abc 219 1.3
9 bbc 417 10.4
8 dee 887 2.1
9 bba 111 7.1
and I load into memory as a String[][]
here comes the problem, I sort by column 1 (aaa,...,bba) using an adaptation of the Quicksort algorithm for 2D arrays
* Sort for a 2D String array
* @param a an String 2D array
* @param column column to be sort
public static void sort(String[][] a, int column) throws Exception {
QuickSort(a, 0, a.length - 1, column);
/** Sort elements using QuickSort algorithm
static void QuickSort(String[][] a, int lo0, int hi0, int column) throws Exception {
int lo = lo0;
int hi = hi0;
int mid;
String mitad;
if ( hi0 > lo0) {
/* Arbitrarily establishing partition element as the midpoint of
* the array.
mid = ( lo0 + hi0 ) / 2 ;
mitad = a[mid][column];
// loop through the array until indices cross
while( lo <= hi ) {
/* find the first element that is greater than or equal to
* the partition element starting from the left Index.
while( ( lo < hi0 ) && ( a[lo][column].compareTo(mitad)<0))
++lo;
/* find an element that is smaller than or equal to
* the partition element starting from the right Index.
while( ( hi > lo0 ) && ( a[hi][column].compareTo(mitad)>0))
--hi;
// if the indexes have not crossed, swap
if( lo <= hi )
swap(a, lo, hi);
++lo;
--hi;
/* If the right index has not reached the left side of array
* must now sort the left partition.
if( lo0 < hi )
QuickSort( a, lo0, hi, column );
/* If the left index has not reached the right side of array
* must now sort the right partition.
if( lo < hi0 )
QuickSort( a, lo, hi0, column );
* swap 2D String column
private static void swap(String[][] array, int k1, int k2){
String[] temp = array[k1];
array[k1] = array[k2];
array[k2] = temp;
----- end of the code --------
if I call this from the main module like this
import MyUtil.*;
public class kaka
public static void main(String[] args) throws Exception
String[][]a = MyUtil.fileToArray("array.txt");
MyMatrix.printf(a);
System.out.println("");
MyMatrix.sort(a,1);
MyMatrix.printf(a);
System.out.println("");
MyMatrix.sort(a,3);
MyMatrix.printf(a);
for the first sorting I get
1 aaa 213 0.9
2 abc 219 1.3
9 bba 111 7.1
9 bbc 417 10.4
3 cbb 514 0.1
8 dee 887 2.1
(lexicographic)
but for the second one (column 3) I get
3 cbb 514 0.1
1 aaa 213 0.9
2 abc 219 1.3
9 bbc 417 10.4
8 dee 887 2.1
9 bba 111 7.1
this is not the order I want to apply to this sorting, I would like to create my own one. but or I can't or I don't know how to use a comparator on this case.
I don't know if I am rediscovering the wheel with my (Sort String[][], but I think that has be an easy way to sort arrays of arrays better than this one.
I've been trying to understand the Question of the week 106 (http://developer.java.sun.com/developer/qow/archive/106/) that sounds similar, and perfect for my case. But I don't know how to pass my arrays values to the class Fred().
Any help will be deeply appreciated
Thanks for your help and your attention
Pedropublic class StringArrayComparator implements Comparator {
int sortColumn = 0;
public int setSortColumn(c) { sortColumn = c; }
public int compareTo(Object o1, Object o2) {
if (o1 == null && o2 == null)
return 0;
if (o1 == null)
return -1;
if (o2 == null)
return 1;
String[] s1 = (String[])o1;
String[] s2 = (String[])o2;
// I assume the elements at position sortColumn is
// not null nor out of bounds.
return s1[sortColumn].compareTo(s2[sortColumn]);
// Then you can use this to sort the 2D array:
Comparator comparator = new StringArrayComparator();
comparator.setSortColumn(0); // sort by first column
String[][] array = ...
Arrays.sort(array, comparator);I haven't tested the code, so there might be some compiler errors, or an error in the logic. -
How to Pass String array from Java to PL/SQL and this use in CURSOR
hi,
I cant understand how to pass Array String as Input Parameter to the Procedure and this array use in Cursor for where condition like where SYMPTOM in( ** Array String **).
This array containing like (SYMPTOM ) to be returned from the java to the
pl/sql (I am not querying the database to retrieve the information).
I cannot find an example on this. I will give the PL/SQL block
create or replace procedure DISEASE_DTL<*** String Array ***> as
v_SYMPTOM number(5);
CURSOR C1 is
select distinct a.DISEASE_NAME from SYMPTOM_DISEASE_RD a
where ltrim(rtrim(a.SYMPTOM)) in ('Fever','COUGH','Headache','Rash') ------- ***** Here use this array element(like n1,n2,n3,n4,n5..) ******
group by a.DISEASE_NAME having count(a.DISEASE_NAME) > 3 ----------- ***** 3 is no of array element - 1 (i.e( n - 1))*****
order by a.DISEASE_NAME ;
begin
for C1rec IN C1 loop
select count(distinct(A.SYMPTOM)) into v_SYMPTOM from SYMPTOM_DISEASE_RD a where A.DISEASE_NAME = C1rec.DISEASE_NAME;
insert into TEMP_DISEASE_DTLS_SYMPTOM_RD
values (SL_ID_SEQ.nextval,
C1rec.DISEASE_NAME,
(4/v_SYMPTOM), --------**** 4 is no of array element (n)************
(1-(4/v_SYMPTOM)));
end loop;
commit;
end DISEASE_DTL;
Please give the proper solution and step ..
Thanking you,
AsishI've haven't properly read through your code but here's an artificial example based on a sql collection of object types - you don't need that, you just need a type table of varchar2 rather than a type table of oracle object type:
http://orastory.wordpress.com/2007/05/01/upscaling-your-jdbc-app/ -
Help! Inserting a 1-D comment array into a 2-D string array at specified row AND column
Hello everyone,
I am writing a 2-D string array to excel and i need a way to add comments to my file like this:
SLAM NAME G Level Comments
1 RALF 26
1 RALF 26
1 RALF 26
1 RALF 26
For some reason, i cannot specify a row AND column to write because:
When i use replace array subset it only replaces 1 element at my index.
When i use replace array subset with a loop, it creates empty spaces until it reaches the end of the array it is replacing.
When i use Insert into array: i cannot wire 2 inputs for row and column.
In my complete VI i will need to write from row 1-1001, a different comment from 2-2002, a different comment from 3-3003, etc until a stop condition is met so i need to figure out how to do this programatically and not have it replace any elements outside of the range or it will override previous commetns.
I am at a loss of what to do. Any and all suggestions are greatly appreciated.
Thanks!
Solved!
Go to Solution.
Attachments:
array.vi 13 KBHi proph,
I made a small subtile change to yur VI and now it replaces all values of the 4th column…
THINK DATAFLOW!
Use shift registers when you need to propagate values from one loop iteration to the next!
USE/LEARN DEBUGGING TECHNIQUES!
There are tools like probes and highlight to understand your VI execution and to find problems…
Go through all those free online courses offered by NI!
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome
Attachments:
array.vit 12 KB -
Help with a store function that takes string array
Hi All,
I have a function that takes in two string arrays, status_array, and gender_array. You can see the partial code below. Somehow if the value for the string array is null, the code doesn't execute properly. It should return all employees, but instead it returns nothing. Any thoughts? THANKS.
for iii in 1 .. status_array.count loop
v_a_list := v_a_list || '''' || status_array(iii) || ''',';
end loop;
v_a_list := substr(v_a_list, 1, length(trim(v_a_list)) - 1);
for iii in 1 .. gender_array.count loop
v_b_list := v_b_list || '''' || gender_array(iii) || ''',';
end loop;
v_b_list := substr(v_b_list, 1, length(trim(v_b_list)) - 1);
IF v_a_list IS NOT NULL and v_b_list IS NOT NULL THEN
v_sql_stmt := 'select distinct full_name from t_employee where status in (' || v_a_list || ') and gender in (' || v_b_list || ')';
ELSIF v_a_list IS NOT NULL and v_b_list IS NULL THEN
v_sql_stmt := 'select distinct full_name from t_employee where status in (' || v_a_list || ') ';
ELSIF v_a_list IS NULL and v_b_list is not null THEN
v_sql_stmt := 'select distinct full_name from t_employee where gender in (' || v_b_list || ')';
ELSE
v_sql_stmt := 'select distinct full_name from t_employee';
END IF;
OPEN v_fullname_list FOR v_sql_stmt;
RETURN v_fullname_list;I'd first recommend trying to avoid the dynamic sql.
use an approach like
[http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425] or
[http://stackoverflow.com/questions/1625649/oracle-parameters-with-in-statement/1655743#1655743] or [http://stackoverflow.com/questions/1715978/how-to-use-an-oracle-associative-array-in-a-sql-query]
but if that isn't in scope, do a
dbms_output.putline(v_a_list) ;
dbms_output.putline(v_b_list) ;
dbms_output.putline(v_sql_stmt) ;around and see what it emits -
Saving String-Array in mySQL DB
Hello.
How can I save an dynamic array in a DB, without looping over
the content.
I think serialization is the key word. Can anybody give me
further information, pls?
Thx an lot.
Regards, PhilippI am working with 3-dimensional string arrays, which have
differet sizes.
I think enum-Cols can't solve my problem. -
Text file convert to string array
I tried to convert text file to string array. But it is not successful.
text file :
SD, 1,2,3,4
GD, 3,4,5,6
I use spreadsheet string to Array function but ALL characters is become to zero.
my result:
0,1,2,3,4
0,3,4,5,6
Solved!
Go to Solution.
Attachments:
convert.vi 18 KBHi,
indeed the solution of GerdW is the way to do it, except for the fact that the while loop isn't needed in this case
Have fun using LabVIEW
Kind regards,
- Bjorn -
Have fun using LabVIEW... and if you like my answer, please pay me back in Kudo's
LabVIEW 5.1 - LabVIEW 2012
Attachments:
Speadsheet_to_array.JPG 27 KB -
Hello everybody,
if I have a string array of say 10 elements, how would I go about shifting those elements to the right or left by one place, ensuring that what had shifted off either end of the array would "wrap around" to the other end of the array?
Thank you for your help in this.
regards,
THE_TH1NGYou could use Arrays.asList() to wrap your array in a list.
To rotate to the right, remove the last element of the list, and add it to the front of the list.
To rotate to the left remove the first element, and add it to the end.
The changes made via the list are written through to the original array you had.
Alternatively write a couple of methods that will do it by hand.
1) store a reference to the array element that will wrap.
2) loop through the elements in the array, copying them into the next element up/down as appropriate.
3) put the stored element back at the start/end of the array as appropriate. -
Combining string array elements into one string
Right, I have an string array called str which stores 1 character in each of its 16 elements. It gets this character from another array, strArray. Now, what I want to be able to do is to take all 16 elements and combine them into one string called keyString. Using the code below keyString only prints out the last character. The code is shown below:
for (x=0; x<16; x++) {
str = new String[16];
str[x] = "";
str[x] += (strArray[(index+x)%16].charAt(strChar[x]));
keyString = str[x];
System.out.print(keyString);
}Any help would be very much appreciated.
Edited by: Paragon96 on May 20, 2008 7:32 AMyour logic is wrong ; if you want to concatenate the content of the array, you have to loop (what you did), and concatenate keyString for each index, meaning:
keyString += str[x];you can also use a StringBuilder for such kind of operations -
labview 6i. Using sr785 instrument.
Two ways. Use Fract/Exp to Number function on the Strin>Strin Number Conversion palette. It accepts both individual or strin array inputs. Wire your string array in an get an array of doubles out. You can also use Scan From String on the String palette inside of a for loop. The for loop will autoindex the string array in and autoindex an array of doubles out.
Attachments:
string_to_double.jpg 10 KB -
I need to make a dynamic string array.
Deeper explanation:
I am trying to use a FOR loop to send a series of commands to an 8-channel device. Each channel requires 7 (actually, 1/2 need only 5, the other 1/2 need 7) strings to set them up and the entire sequence needs to be performed 8 times. I started a test .vi by simply using a constant array of type sting. I can sequentially pick each string and program my device perfectly. Now I'd like to do things like add the channel # somewhere in the mix, use variable values based on other controls in my .vi to set the parameters of the channel.
EXAMPLE:
The user sets certain values that determine delays and width for an 8-channel DDG (Digital Delay Generator, to some, a pulse generator). These values then need to be loaded into the DDG. The Strings will look something like this:
ULSE1TATE 1
ULSE1:WIDTH 0.009 000 *NOTEpaces behind decimal are for better viewability only
ULSE1ELAY 0.000 000
ULSE1YNC T0
ULSE1:CMODE DUTY
ULSE1COUNTER 1
ULSE1:BCOUNTER 1
ULSE2TATE 1
ULSE2:WIDTH 0.000 300
ULSE2ELAY 0.008 700
ULSE2YNC T0
ULSE2:CMODE NORMAL
So widith and delay params change, the pulse# changes, and whether it's on certain channels decides if the mode is duty or normal and duty comes with the subsequent params pcount and bcount.
help?
PS - I am going to move the state, sync, and cmode to a common, initialize loop run only at program start, but I still need to use width, delay, and (variably) pcount and bcount.
PPS - I am trying to edit post to diable smilies. Commands should read:"colon, P (or D)" not ,
PPPS - Success, at least for me. I disabled smilies in my settings, I don't know if that means my posts won't show smilies or if just what I am looking at won't show smilies, any responders let me know how it's showing for you.
Message Edited by Radiance_Jon on 07-16-2007 01:48 PM
Message Edited by Radiance_Jon on 07-16-2007 01:52 PMsmercurio_fc wrote:
Well, in my experience I have found that dealing with errors early on is the best course of action as it leads to less headaches down the road...
Auto-indexing is one of the more powerful features of LabVIEW. If you're familiar with text-based languages it's equivalent to the "foreach" statement. Basically it allows you to wire an array into a for-loop and the size of the array tells LabVIEW how many times the loop needs to execute. Inside the loop LabVIEW peels of each element of the array in order for each iteration of the loop. Looks like this:
My comment regarding not needing the sequence frame was related to using the error cluster since that wire would allow you enforce data dependency like so:
Note that the VISA resource wire does the same thing.
"I got a little aggravated at how NI seemed to handle the loops in those two frames concurrently". That's because LabVIEW is a data-flow language, and not a sequenced language like C or VB. In fact, that's one of the things that makes LabVIEW so powerful.
Message Edited by smercurio_fc on 07-16-2007 04:48 PM
MAN! I KNEW that!!!! GGRRRRR!!! That makes sense. Actually that's WHY I connected the error lines in the first place was to aide in flow control. OH!!! Still getting used to LabVIEW.
But I still have a question related to flow control. Check out the pic below. LabVIEW runs everything in a seemingly random order... well at least where it STARTS each chain of data. It obviously starts with the static constants or the earliest data in each chain, but I can't figure out how in the world it's deciding WHICH chain to start first. It kind of seems to go with the lower right and work it's way to top-left, but it doesn't exactly do that either. I dunno if it's worth you answering this concern or not, but if you got one for me I'd be much obliged.
I should take a LabVIEW class! Yeah right, as if they'd let me... R&D means I won't need it tomorrow ;( which stinks cause I'm liking LabVIEW the more I learn it. (I was not fond of it in the beginning, but that was my stubborness).
thanks again so much for all your help!!!!
Also, I am using all those strings to make my display appear as I want it to... I wonder if there is another way? I am aware of system labels, but I like the look of the recessed, grayed control boxes better.
Message Edited by Radiance_Jon on 07-16-2007 05:06 PM -
How can I write a 3D string array to file?
sascha:
You could do this a lot of different ways.
The first and most obvious thing that comes to my mind is that you can
think about a 3D array as an array of 2D arrays. (For that matter a
2D array is an array of 1D arrays.)
Thus you could use a for loop to index your 3D array down to 2D and
then perform multiple writes to write each 2D array "element" of this
array of 2D arrays to disk. You would probably want to write some
sort of header which defines how many dimensions there are in the
array so that whatever reads it back later will have an easier time
reading it back. (Otherwise you'd have to implement EOF handling for
the read back portion.)
To read it back you just use the same logic but build a 3D array using
a 2D read inside a for loop.
Dou
glas De Clue
LabVIEW developer (looking for a job...
[email protected]
[email protected] (SaschaS) wrote in message news:...
> How can I write a 3D string array to file? -
Searching two dimensional string arrays
Hello, I'm very new to Java. I would like some advice on the code below. What I'm trying to do is: I want the user to enter a 9 digit number which is already stored in an two dimensional array. The array is to be searched and the 9 digit number and corresponding name is to be printed and stored for future reference. Something is wrong with my array checking. If I enter the nine digit number, the program errors and asks me again for the number. If I enter 0-4, I receive an output. I just don't know how to compare string array values. Could someone please help me with this?
import java.io.*;
import java.util.*;
public class SocialSn2
public static void main(String args[]) throws Exception
boolean validSSAN = false;
Ssn(validSSAN);
if (validSSAN)
//Ssn(false);//write the code here to continue processing
}//end main
public static void Ssn(boolean Validated)
String[][] employees =
{{"333333333", "Jeff"},
{"222222222", "Keith"},
{"444444444", "Sally"},
{"555555555", "Kaylen"},
{"111111111", "Sheriden"} };
boolean found = false;
while (!found)
System.out.println("Enter the employee's Social Security number.");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try
String line = in.readLine();
int input = Integer.parseInt(line); //added
found = false;
for(int j = 0; j < 5; j++)
if(input >= 0 && input <= employees.length)
//if(employees[j][0].equals(input))
//System.out.println(employees[input][0] + employees[input][1]);
found = true;
System.out.println(employees[input][0] + " " + employees[input][1]);
catch (Exception exc)
System.out.println("error");
found = false;
Validated = found;
}//end Ssn
}//end classThere seems to be some problem with your loop for checking those values
if you had used System.err.println() in your catch block you would see that you were getting an ArrayIndexOutOfBoundsException
The following works for me.
import java.io.*;
import java.util.*;
public class SocialSn2
public static void main(String args[]) throws Exception
boolean validSSAN = false;
Ssn(validSSAN);
if (validSSAN)
//Ssn(false);//write the code here to continue processing
}//end main
public static void Ssn(boolean Validated)
String[][] employees =
{{"333333333", "Jeff"},
{"222222222", "Keith"},
{"444444444", "Sally"},
{"555555555", "Kaylen"},
{"111111111", "Sheriden"} };
boolean found = false;
System.out.println(employees.length);
System.out.println(employees[0].length);
while (!found)
System.out.println("Enter the employee's Social Security number.");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try
String line = in.readLine();
//int input = Integer.parseInt(line); //added
found = false;
for (int i=0; i< employees.length;i++)
if(employees[0].equals(line))
System.out.println(employees[i][0]+" "+employees[i][1]);
found = true;
catch (Exception exc)
System.err.println(exc);
found = false;
Validated = found;
}//end Ssn
}//end class -
How to check string array elements with a string with in one forEach tag ?
Hi All,
I am new to JSTL and EL. I need to change the following Java code into JSTL and EL.. I struggled to change this code into JSTL.
How can i change the if loop which tests the string array element with one bean property ?
-------------------------------------------------------------------------------------------------------------for(int j=0 ; j < iSelectedCount; j++)
if(strSelectedRoleId[j].equals(lineRole.getRoleID()))
isAvailable = true;
Please help me on this.
It is very urgent......
Thank you for ur help,
Natrajimport java.util.Calendar;
Calendar rightNow = Calendar.getInstance(); // gets the current date and time to millisec
Calendar earlyTime = Calendar.getInstance().set(Calendar.HOUR_OF_DAY, 6).set(Calendar.MINUTE, 30);
Calendar lateTime = Calendar.getInstance().set(Calendar.HOUR_OF_DAY, 8).set(Calendar.MINUTE, 0);
if (rightNow.compareTo(earlyTime)> 0 && rightNow.compareTo(lateTime) < 0){
// do something
}Try this.
Maybe you are looking for
-
Preview Folder - Big Size of Pictures
I've just started to add photos to my Library on iphoto, but I decided to keep the originals in an external disk, as I don't want my mac book pro completly full of photos. So I selected under preferences -->Advanced -->no copy elements to Iphoto libr
-
How can you minimize or (turn) off the "side panel" in Web Intelligence in the view mode. It is possible to turn on/off options within the Side Panel by Customization of Groups. But it seems You cannot influence the way Web Intelligence present (mini
-
Hello, i was wondering if you can help me figure out how to edit a video to zoom in and out with the beat of the music?
-
Hello Fiori und SMP experts, cann somebody answer mir the following questions please Since which version of SMP is the integration of Fiori possible? Is it possible to integrate a Fiori-App with SMP directly without SAP Fiori Client? Thanks a lot in
-
Why is Acrobat 11 NOT showing colored backgrounds I have in my ID files?
Why is Acrobat 11 NOT showing colored backgrounds I have in my ID files? I can see them in Acrobat 10 just fine but I would prefer to switch up to 11...