Efficient looping over strings

ABAPers,
I need to loop over all the characters in a string. Here is the pseudo code:
data: myData TYPE string.
data: n TYPE i.
data: ch TYPE char1.
n = STRLEN( myData).
DO n TIMES.
  ch = myData(sy-index).
ENDDO.
While this code would work, the problem is that I am actually iterating over myData two times. STRLEN itself is internally iterating over myData to compute the length.
Is there a more efficient looping mechanism without going through STRLEN?
Thank you in advance for your help.
Pradeep

Hi,
You can try this when it comes to converting things
    WHILE myData IS NOT INITIAL.
do something
    ENDIF.
    myData = myData+1(*).
Eddy
PS.
Put yourself on the SDN world map (http://sdn.idizaai.be/sdn_world/sdn_world.html) and earn 25 points.
Spread the wor(l)d!

Similar Messages

  • How use c:forEach to loop over a String[][]

    Hello,
    Is there anyone that can tell me how to use the c:forEach tag to loop over a double String[][]? I can find examples for resultsets etc....but whatever I try with my String[][], I never can get the results on the screen.
    Thanx,
    debeumers

    You need to set up a double c:forEach loop.
    ie
    <%
    // initialisation of string[][]
    String[][] sValues = new String[5][5];
    for (int i=0; i<sValues.length; i++){
      for (int j=0; j<sValues.length; j++){
         sValues[i][j] = "" + (i + j);
    pageContext.setAttribute("arrayValues", sValues);
    %>
    // And now to test print out the values
    <c:forEach var="row" items="${arrayValues}">
    <c:forEach var="col" items="${row}">
    <c:out value="${col}"/>
    </c:forEach>
    <br>
    </c:forEach>
    Hope this helps
    Cheers, evnafets

  • Loop over a list of string separated by ;

    Hello,
    i have a list of string in a varchar2 separated by ;
    i wanna make a loop over this list and extract all string inside
    any one has an idea ?
    Thanks
    Regards
    Sallemel

    user10393090 wrote:
    Hello,
    i tried it, i got this error :
    PL/SQL: ORA-00904: "REGEXP_REPLACE": invalid identifierWell we have to assume you've got 10g or 11g unless you specify otherwise as lower versions are unsupported.
    SQL> select substr( the_string
      2                , decode( level, 1, 1, instr(the_string,',',1,level-1)+1)
      3                , decode( instr(the_string,',',1,level), 0, length(the_string), instr(the_string,',',1,level) - decode( level, 1, 0, instr(the_string,',',1,level-1))-1)
      4                ) the_value
      5                from ( select '10,12,20,30,30,3,12,12,56' the_string
      6                       from dual
      7                     )
      8                connect by level < length(replace(translate(the_string,'01234567890','00000000000'),'0')) + 2;
    THE_VALUE
    10
    12
    20
    30
    30
    3
    12
    12
    56
    9 rows selected.
    SQL>

  • Problem with Message-Mapping: Loop over Elements possible?

    Hi all,
    I want do create a Message-Mapping for an IDoc-to-File Scenario. In the Source Structure there are some Elements which can appear more than once (1..unbounded). I need a mechanism which loops over these elements and search for specified values. From the Element which contains an element with this specified value the mapping should write a value in the target structure.
    Here a simple example (source structure) for better understanding:
    <root>
       <invoice>
          <number> 10 </number>
          <sum> 200.00 </sum>
       </invoice>
       <invoice>
          <number> 20 </number>
          <sum> 150.00 </sum>
       </invoice>
       <invoice>
          <number> 30 </number>
          <sum> 120.00 </sum>
       </invoice>
    </root>
    Now the duty of the Mapping should be to search in the elements <invoice> for the number 30. And then the sum of the invoice with the number 30 should be written in a field of the target structure.
    I tried it out with a constant togehter with an equalsS-function and an ifWithoutElse-function, but it is working only then, if the invoice with the number 30 has the first position in the root context.
    Can anybody help me? Thanks
    With kind regards
    Christopher

    Hi,
    Write a UDF to sum the required values and map to target node.
    See while writing the UDF select the type as queue.
    number -- removecontext-UDF targetnode
    sum----removecontext--/
    number abd sum or the two inputs
    in UDF
    int nsum = 0;
    for(int i;i < number.length;i++){
      if number(i).equals("30") then
         nsum = nsum + valueOf(sum(i));
    result.addValue(nsum); // convert the nsum into string
    Regsrds
    Chilla

  • Why optimizer prefers nested loop over hash join?

    What do I look for if I want to find out why the server prefers a nested loop over hash join?
    The server is 10.2.0.4.0.
    The query is:
    SELECT p.*
        FROM t1 p, t2 d
        WHERE d.emplid = p.id_psoft
          AND p.flag_processed = 'N'
          AND p.desc_pool = :b1
          AND NOT d.name LIKE '%DUPLICATE%'
          AND ROWNUM < 2tkprof output is:
    Production
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          4           0
    Execute      1      0.00       0.01          0          4          0           0
    Fetch        1    228.83     223.48          0    4264533          0           1
    total        3    228.84     223.50          0    4264537          4           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 108  (SANJEEV)
    Rows     Row Source Operation
          1  COUNT STOPKEY (cr=4264533 pr=0 pw=0 time=223484076 us)
          1   NESTED LOOPS  (cr=4264533 pr=0 pw=0 time=223484031 us)
      10401    TABLE ACCESS FULL T1 (cr=192 pr=0 pw=0 time=228969 us)
          1    TABLE ACCESS FULL T2 (cr=4264341 pr=0 pw=0 time=223182508 us)Development
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.00       0.01          0          4          0           0
    Fetch        1      0.05       0.03          0        512          0           1
    total        3      0.06       0.06          0        516          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 113  (SANJEEV)
    Rows     Row Source Operation
          1  COUNT STOPKEY (cr=512 pr=0 pw=0 time=38876 us)
          1   HASH JOIN  (cr=512 pr=0 pw=0 time=38846 us)
         51    TABLE ACCESS FULL T2 (cr=492 pr=0 pw=0 time=30230 us)
        861    TABLE ACCESS FULL T1 (cr=20 pr=0 pw=0 time=2746 us)

    sanjeevchauhan wrote:
    What do I look for if I want to find out why the server prefers a nested loop over hash join?
    The server is 10.2.0.4.0.
    The query is:
    SELECT p.*
    FROM t1 p, t2 d
    WHERE d.emplid = p.id_psoft
    AND p.flag_processed = 'N'
    AND p.desc_pool = :b1
    AND NOT d.name LIKE '%DUPLICATE%'
    AND ROWNUM < 2
    You've got already some suggestions, but the most straightforward way is to run the unhinted statement in both environments and then force the join and access methods you would like to see using hints, in your case probably "USE_HASH(P D)" in your production environment and "FULL(P) FULL(D) USE_NL(P D)" in your development environment should be sufficient to see the costs and estimates returned by the optimizer when using the alternate access and join patterns.
    This give you a first indication why the optimizer thinks that the chosen access path seems to be cheaper than the obviously less efficient plan selected in production.
    As already mentioned by Hemant using bind variables complicates things a bit since EXPLAIN PLAN is not reliable due to bind variable peeking performed when executing the statement, but not when explaining.
    Since you're already on 10g you can get the actual execution plan used for all four variants using DBMS_XPLAN.DISPLAY_CURSOR which tells you more than the TKPROF output in the "Row Source Operation" section regarding the estimates and costs assigned.
    Of course the result of your whole exercise might be highly dependent on the actual bind variable value used.
    By the way, your statement is questionable in principle since you're querying for the first row of an indeterministic result set. It's not deterministic since you've defined no particular order so depending on the way Oracle executes the statement and the physical storage of your data this query might return different results on different runs.
    This is either an indication of a bad design (If the query is supposed to return exactly one row then you don't need the ROWNUM restriction) or an incorrect attempt of a Top 1 query which requires you to specify somehow an order, either by adding a ORDER BY to the statement and wrapping it into an inline view, or e.g. using some analytic functions that allow you specify a RANK by a defined ORDER.
    This is an example of how a deterministic Top N query could look like:
    SELECT
    FROM
    SELECT p.*
        FROM t1 p, t2 d
        WHERE d.emplid = p.id_psoft
          AND p.flag_processed = 'N'
          AND p.desc_pool = :b1
          AND NOT d.name LIKE '%DUPLICATE%'
    ORDER BY <order_criteria>
    WHERE ROWNUM <= 1;Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Looping over a structure of arrays

    Hi Guys, I am trying to loop over a structure of simple
    arrays. The structure's second column contains a 1 dimentional
    array.
    I can't seem to get the proper syntax for my loop.

    I want to be able to dynamically loop over my query and
    decrypt it as I pass it into my structure. I have figured the code
    out to loop over the query and pass it to the structure. My problem
    now is whn I go to decrypt it I get this Error.
    There has been an error while trying to encrypt or decrypt
    your input string: Input length (with padding) not multiple of 16
    bytes.
    How can I fix this?
    Here is my code could it be because my varchar columns were
    not long enough. Here is my code.

  • Value Mapping: how to loop over a nested context in a adv. user function

    Hello,
    i have the following source structure:
    <rec> (1:1)
    <field1>aaa</field1> (1:1)
    <field2>bbb</field2> (1:1)
    <b><struc> <u>(1:unbounded)</u>
      <name>myName</name>
      <value>myValue</value>
    </struc></b>
    </rec>
    Destination structure:
    <rec> (1:1)
    <field1>aaa</field1> (1:1)
    <field2>bbb</field2> (1:1)
    <b><field3>bbb</field2> (1:1)</b>
    </rec>
    In order to fill the destination field3 i have to loop over the input-structure struc.
    My problem is, that i don't know how to get access to the name/value pair with a
    extended user-defined function. Since each occurrence in struc i not a simple string but consists of 2 fields, i guess it is not enough simply to loop over input String Array.
    Please help.

    just like u have a loop stmt in java prgm. a simple code:
    Here a and b are the strings that comes to the udf
    for(int i=0;i<a.length;i++)
         boolean found = false;
         int j = 0;
         for(j=0;j<b.length;j++)
              if (a<i>.equals(b[j]))
                   found = true;
                   break;
         if (found == true)
              result.addValue(c[j]);
         else
              result.addValue("");
    Message was edited by:
            Prabhu  S

  • Looping over a TreeMap with for|foreach

    I am a student programmer and am impressed how the APIs for the different collections are very similar if not completely identical.
    I used treemap.keySet() to loop over TreeMap<String, MyVeryOwnClass> successfully with a while loop. But it seems impossible to do the same with the newish for-each loop. Or have I missed the point somewhere?
    Regards,
    Hedley

    Okay, I've got the for/each loop working its way through my Applicant TreeMap as follows:
        public String findApprovedApplcnt()
            String applicantKey = "";
            for (Map.Entry<String, Applicant> entry : applicantList.entrySet())
                Applicant applicant = entry.getValue();
                boolean approved = applicant.isApproved();
                if (approved);
                    applicantKey = applicant.getApplcntKey();
                    // The String key is hashed and stored in an instance variable when object created.
                    // It is subsequently retrieved and used when the object is added to the tree map.
                    break;
            return applicantKey;
        } // findApprovedApplcnt(..)In the Applicant class is the flag 'private boolean approved = false;' (initially), accessed by the method .isApproved(). What the loop is supposed to do is examine each Applicant object applicant in turn, skip over those where approved = false, and grab the key of the first applicant where approved = true, then break out of the loop and return the key.
    Trouble is, it is grabbing the key of the first applicant it encounters regardless of whether approved is either true or false! I have gone nuts over this, stepping through in the debugger, inserting println statements to check the value of approved when it is retrieved, attempting to desk check, etc.
    So what is the obvious error to which I am completely blind?
    Regards,
    Sleepless in Melbourne

  • Looping over a structure

    How do I loop over this structure to populate it with a Query
    Recordset?
    <cfset myStruct =
    objImage.getSize("images/products/largeImages/#Recordset1.elink#")>
    I really appreciate your help.

    I would like to populate the structure with the image file
    names that are coming from the query. The structure is built from a
    java object. Here is the function to create it.
    <cfcomponent>
    <cffunction name="getSize" returntype="struct"
    access="public" output="No">
    <cfargument name="Image" required="Yes" type="string">
    <cfset myImage = createObject("java",
    "javax.swing.ImageIcon")>
    <cfset myImage.init(expandpath(arguments.Image))>
    <cfset myStruct = StructNew()>
    <cfset myStruct.width = myImage.getIconWidth()>
    <cfset myStruct.height = myImage.getIconHeight()>
    <cfreturn myStruct>
    </cffunction>
    </cfcomponent>
    <cfobject component="imageSize" name="objImage">
    <cfset myStruct =
    objImage.getSize("/images/someimage.jpg")>
    <cfoutput>
    width: #myStruct.width#
    height: #myStruct.height#
    </cfoutput>
    Right now the structure only gives me the first row of the
    query. I have tried using the cfquery loop to populate the
    structure with now results. I suspect I am using the wrong
    syntac.

  • How can i loop over treeview selected nodes and then to delete each node if it's a directory or a file ?

    I have this code:
    if (s == "file")
    file = false;
    for (int i = 0; i < treeViewMS1.SelectedNodes.Count; i++)
    DeleteFile(treeViewMS1.SelectedNode.FullPath, file);
    I know it's a file and it is working if it's a single file.
    On the treeView i click on a file right click in the menu i select delete and it's doing the line:
    DeleteFile(treeViewMS1.SelectedNode.FullPath, file);
    And it's working no problems.
    But i want to do that if i selected some files togeather multiple selection then to delete each file.
    So i added the FOR loop but then how do i delete from the SelectedNodes each node ?
    The treeView SelectedNodes dosen't have FullPath like SelectedNode also doing SelectedNodes[i] dosen't have the FullPath property.
    Same as for if i want to delete a single directory or multiple selected directories:
    This is the continue of the code if it"s not a "file" (else) it's null i know it's a directory and doing:
    else
    file = true;
    RemoveDirectoriesRecursive(treeViewMS1.SelectedNode, treeViewMS1.SelectedNode.FullPath);
    Also here i'm using SelectedNode but if i marked multiple directories then i how do i loop over the SelectedNodes and send each SelectedNode to the RemoveDirectoriesRecrusive method ?
    My problem is how to loop over SelectedNode(multiple selection of files/directories) and send each selected file/directory to it's method like i'm doing now ?

    foreach (TreeNode n in treeViewMS1.SelectedNodes)
    // Remove everything associated with TreeNode n here
    I don't think it's any harder than that, is it?
    If you can multi-select both an item and one of its descendents in the tree, then you'll have the situation that you may have deleted the parent folder and all of its children by the time you get around to deleting the descendent.  But that's not such
    a big deal.  A file can get deleted externally to your program too - so you'll just have to deal with it having been deleted already (or externally) when you get around to deleting it yourself.

  • [Solved] Foreach loop that loops over all files in a folder does not consider first file found

    Hello,
    I have a foreach loop in SSIS (as part of Visual Studio 10 and with SQL Server 2012).
    It loops over all files in a folder (ForEach File Enumerator).
    I set the folder: OK
    Traverse Sub folders: OK
    I have set up a Variable in Variable Mappings called FileName so it shows User::FileName: OK
    Index of variable is 0: OK
    It almost works ok. Except that the first file it finds is never considered.
    I set a breakpoint then and the first file it finds, is shown in black in the watch variable window. All subsequent files found are shown in red font. When I change the names of the files so another file is the first file found then it skips the other one
    which now is the first file.
    What is going on here? Why does SSIS skip the first file it finds in a foreach file loop?
    Any suggestions highly appreciated.
    Thank you
    Andi
    Andreas

    "red font - interesting, any example to show us (image)
    It would be interesting to share with us whether you use any file masks or expressions.
    Arthur
    MyBlog
    Twitter
    It appears a variable value turns red when it changes between breakpoints. It started black for the first value (the first file, obtained BEFORE the execution reached the breakpoint), and then turned red. I was able to reproduce this behavior on a test environment.
    However, it did not skip any files.
    OP, please set up the test shown in the image below. Create a breakpoint in the sequence container for the "OnPreExecute" event.

  • Message-Mapping: nested Loops over Elements

    Hi Experts,
    I have problems with my Message-Mapping in the IR. I have a source and a target structure. In the following I will give you easy examples of these structures:
    <u>source structure:</u>
       <E1EDP01>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
       </E1EDP01>
       <E1EDP01>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
          <E1EDP19>
             <QUALF> ... </QUALF>
             <IDTNR> ... </IDTNR>
          </E1EDP19>
       </E1EDP01>
    <u>target structure:</u>
    <LineItem>
       <IDTNR></IDTNR>
    </LineItem>
    <LineItem>
       <IDTNR></IDTNR>
    </LineItem>
    That means:
    For every <E1EDP01> in the source structure I create one <LineItem> in the target structure. One E1EDP01-Element can contain more than one E1EDP19-Elements. I have to loop over these E1EDP19-Elements, because I have to locate the Element <QUALF> with a given (fixed) value. The Mapping should put the value from the Element <IDTNR> from the source structure - where the QUALF-Element has this given value - in the IDTNR-Element of the target structure.
    I tried it with a UDF, but only the first <IDTNR> in the target structure got filled.
    Thanks for your help
    Christopher

    Thank you,
    but how I can set the Elements IDTNR and QUALF to the context E1EDP01?
    In the splitByValue-Function do I need "each value"?
    best regards
    Christopher

  • Looping over cfset tag

    Hey Guys,
    I am having a problem with cfloop. What I am trying to do is
    calculate points on an Oline March Madness Pool. I need to evaluate
    if the user picks are equal to the game winners. I can do it if I
    manually type each pick # and each game # but I would much rather
    loop over a cfset tag since there are 63 picks and games. You can
    check out my code below to get a better idea of what I am trying to
    do. While I know I can't include the #'s on the right side of the
    cfset tag in this way I included them anyways to better illustrate
    where I would like to loop it. Is there a way to do this, or will I
    have to manually set each pick?

    <cfif getGames.game#l# EQ
    userPoints[#userID#]["pick#l#"]>
    I'm going to guess this is line 27 or very near it.
    Your actual <cfset> line looks fine to me assuming all
    the relevant keys
    exist when they need to exist. I would have written it
    something like:
    <cfset userPoints[userID]["pick" & i] =
    variables["pick" & i]>
    The if statement should probably look like this:
    <cfif getGames["game" & i] EQ
    userPoints[userID]["pick" & i]>
    All your index variables are the letter "i" and not the
    number "1"
    aren't they? I don't believe a singe number is a valid CF
    variable name.

  • Looping over fields from internal table

    In a FM I have to check records of two ITABs against each other. Most fields can be checked 1:1 but some must be checked according to some business logic.
    I first want to check field-by-field and then I want to deal with exceptions.
    Question: How can I loop over fields in an ITAB in such a manner that I can compare fields?

    Hi, you can loop thru the columns(fields) of an internal table like so.
    field-symbols: <fs>.
    loop at itab.
    do.
    * Here you can use the field name instead of SY-INDEX
       assign component sy-index of structure itab to <fs>.
       if sy-subrc <>.
       exit.
       endif.
    * Now that you have access to the field via field symbol, you can compare
    * this value.
    Write:/ <fs>.
    enddo. 
    endloop.
    Regards,
    Rich Heilman

  • Looping over QoQ Where Clause

    I have two queries. One is a main query that we pull from a form submission. The second is a small query resultset that lists different subgroups in my company and what main group they belong to. I pull several QoQ from the main query. In the main query results, there is a column that holds the subgroup information. I am trying to do a Q0Q where I group the data from the main query into the main groups for analysis. Here is an example...
    Main Query
    record 1 - subgroup 1
    record 2 - subgroup 2
    record 3 - subgroup 3
    Second Query
    Subgroup 1 - Main Group 1
    Subgroup 2 - Main Group 2
    Subgroup 3 - Main Group 1
    So I am trying to loop over a QoQ on the main query where the result set would contain the information only from Main Group 1. So record 2 would be eliminated. I have tried using an IN clause with a cfloop, but I run into syntax trouble with the comma. I also tried looping over the QoQ as a whole and the resulting dump is only the last record.
    If there is anything else you need, let me know.
    Any thoughts?
    Clay
    P.S. Here is a code sampling...
        <cfquery name="rsGroup" datasource="nps">
        SELECT *
        FROM "GROUP"
        WHERE GROUP.PrimaryGroup = '#form.primarygroup#'
        </cfquery>
        rsGroup - <cfdump var="#rsGroup#">
        <cfloop query="rsGroup" startrow="1" endrow="#rsGroup.RecordCount#">
            <cfquery name="rsGroupQoQ" dbtype="query">
            SELECT *
            FROM rsNPS
            WHERE rsNPS.grp = '#rsGroup.group#'
            </cfquery>
        </cfloop>
        rsGroupQoQ - <cfdump var="#rsGroupQoQ#"><cfabort>

    ok...I figured it out. I thought I would post my solution in case anyone else runs into this. Also, if anyone out there has a better way, let me know.
    <!---Dummy array to house 'blank' value for adding of column to main query--->
    <cfset GroupArray = ArrayNew(1)>
    <!---Variable that adds mainGroup column to main query with blank data from dummy array--->
    <cfset addMainGroup = QueryAddColumn(rsNPS,'mainGroup',GroupArray)>
    <!---Loop that sets value on added mainGroup column based off of main query grp column value--->
    <cfloop query="rsNPS" startrow="1" endrow="#rsNPS.RecordCount#">
        <cfif rsNPS.GRP EQ "xxxxx"><cfset rsNPS.mainGroup = "yyyyy"></cfif>
        <cfif rsNPS.GRP EQ "xxxxxxxxxx"><cfset rsNPS.mainGroup = "yyyyyyyyyy"></cfif>
        <cfif ...etc. ...
    </cfloop>

Maybe you are looking for

  • Errors in system log?

    OK, so I'm relatively new to Mac OS X, but that's on the back of some 20 years of working with UNIX, so I'm well placed to handle Mac OS X.... or so I thought! In fact, compared to generic UNIX systems, there's so much added to Mac OS X that it might

  • Slow apps due to several calendar applications

    Morning. I use several applications they are using calendar data: iCal, MenuCalendarClock, iBiz, MailTags, iSync (Nokia E65), several subscribed calendars, several published calendars (on .mac and on private servers). Some of them are very slow at st

  • My email is locked on one message that I can't remove.....help?

    Need help with my mail

  • Can i delegate more than 1object

    hi , im working on Document management systems.i have created ZDRAW1 by copying the standard DRAW object. i have delegated the standard DRAW to my  ZDRAW1. the workflow is working. now i got another scenario to create new workflow. shall i have to cr

  • $50 Unlimited Prepay plan

    Does unlimited nationwide and unlimited domestic mean the same thing.