Loop at internal table

Hi. I am fairly new to ABAP. I have a small doubt which requires your help. I wan to know if the following statement is correct.
loop at g_t_data where matnr in so_matnr.
so_matnr is a select option for mara-matnr.
I want to know if it is correct to use a select option after the where clause. I tried using it, and I didnt get any syntax error. I want to know if it is a right programming practice to do so.

As Suresh had mentioned you can use it.
For ABAP related questions , post them in ABAP forum for better response.
ABAP Development
Regards
Raja

Similar Messages

  • Avoiding performance issue due to loop within loop on internal tables

    Hi Experts,
                    I have a requirement where in i want to check whether each of the programs stored in one internal table are called from any of the programs stored in another internal table. In this case i am looping on two internal tables (Loop within a loop) which is causing a major performance issue. Program is running very very slow.
    Can any one advise how to resolve this performance issue so that program runs faster.
    Thanks in advance.
    Regards,
    Chetan.

    Forget the parallel cursur stuff, it is much to complicated for general usage and helps nearly nothing. I will publish a blog in the next days where this is shown in detail.
    Loop on loop is no problem if the inner table is a hashed or sorted table.
    If it must be a standard table, then you must make a bit more effort and faciliate a binary search (read binary search / loop from index exit)
    see here the exact coding Measurements on internal tables: Reads and Loops:
    /people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables
    And don't forget, the other table must not be sorted, the loop reaches anyway every line. The parallel cursor requires both tables to be sorted. The additional sort
    consumes nearly the whole advantage of the parallel cursor compared to the simple but good loop in loop solutions.
    Siegfried

  • Loop at internal Table inside Script

    Hi
       I am filling a table in a subroutine in a program  and calling it through 'Perform' from my Script,now the main issue is , How to display the table in my script ? 
                I want to loop through an internal table & display its content on my script , but i can't make changes in the calling program by any means.

    Hi Ajitabh ,
    With PERFORM inside SAPSCRIPT you can only pass individual fields and also get back individual fields .
    Check This
    http://help.sap.com//saphelp_470/helpdata/EN/d1/802fd3454211d189710000e8322d00/frameset.htm
    Only "USING" and CHANGING" options are allowed and that too only symbols available / defined in sapscript can be passed .
    Even if you populate an internal table in the program you are calling with "PERFORM" there is no way to pass this internal table back to sapscript , also in SAPSCRIPT there is no way to loop .
    If you are sure about the no of lines you are going to populate and all lines have only one column ( only one field ) you can try something like this .
    /: PERFORM GET_VALUE IN PROGRAM <ZNAME>
    /: USING &VAR1&
    /: USING &VAR2&
    /: CHANGING &ITAB1&
    /: CHANGING &ITAB2&
    /: CHANGING &ITAB3&
    /: CHANGING &ITAB4&
    /: ENDPERFORM
    Anothe way is to loop in the main print program and call WRITE_FORM . But I guess your main print program is a SAP std program which you dont want to copy and change.
    Cheers.

  • Program times out while looping at internal table with huge records - Needs fine tuning suggestions

    Hi,
    I am trying to execute a report. It times out while looping at vbap internal table. This internal table has 140000  records and does the validation within this loop and geenrates data for the output. Due to this huge volume, the program times out when executed foreground.
    There are no nested loops, so I cannot apply 'Parallel Cursor' here.
    Is there any way I can fine tune the program so that it doesn't timeout? Is it possible to apply 'Parallel Processing' . If yes, how?
    Thanks,
    Pavan

    Hi Pavan ,
                  ->sort your internal table by all primary key for vbap.
                  ->Read a Record from the table (use your condition here)
                  ->if record satisfys your where condition ,get that record index .
                  ->loop the table from the index (without condition) .
                  its like parallel cursor only but for single loop .;-)
                  ->use field symbols ,wherever possible .
               if still dump is coming ,contact your basis team .
    regards,
    Krishna.

  • Looping at internal table is taking lots of time

    Hi,
    I have two internal tables IT_1 and IT_2. My requirement is as below:-
    For record in table IT_1 if no record is found in table IT_2 then appned to the third table IT_3.
    I am using the below code for the same.
      LOOP AT tbl_articles INTO tbl_articles.
        READ TABLE tbl_prix_art WITH KEY matnr = tbl_articles-matnr.
        IF sy-subrc <> 0.
          MOVE tbl_articles TO tbl_articles_2.
          APPEND tbl_articles_2.
        ENDIF.
        CLEAR : tbl_articles, tbl_articles_2.
      ENDLOOP.
    But is taking huge amount of time due to larger number of records in tbl_articles .
    Is there any other way through which i can get the same functionality.
    Regards
    Sachin

    Sachin,
    Some food for thought.
    Irrespective of how you define the table it has to go through the n number of rows in tbl_articles because that is the basic functioanlity.
    I think your READ TABLE is what is delaying your process here. So try a Binary Search as below.
    Line 1 of change --> SORT tbl_prix_art asc ASCENDING matnr. 
    LOOP AT tbl_articles INTO tbl_articles.
    Line 2 of change --> READ TABLE tbl_prix_art BINARY SEARCH  WITH KEY matnr = tbl_articles-matnr.
    IF sy-subrc 0.
    MOVE tbl_articles TO tbl_articles_2.
    APPEND tbl_articles_2.
    ENDIF.
    CLEAR : tbl_articles, tbl_articles_2.
    ENDLOOP.
    I am confident this will solve your long run times.
    Thanks
    Mani

  • SAP QUERY LOOPS AND INTERNAL TABLE

    Hi All, I have a query which i have made. It runs from Table EKPO which has PO details and what I want to do is now via ABAP Code pull through the total of goods receipt for the PO and Line Item into a field. Sounds Easy enough..Problem now,
    The table which contains the GR data is EKBE which agains a PO and Line Item can have many 101 movements and 102 movements so what I want is an ABAP Statent to basically sum up the total of 101 for the PO & LINE ITEMS and then minus this from the total of 102 for the PO & LINE ITEMS and post the result in to this new field I have created.
    I am pretty decent with ABAP Code in Querys I.e Select statements etc but from what I can see i need to create an internal table and do a loop and collect statement but I keep on failing due to not enough knowledge. Please can some one help me with this and provide me with the code and explanation as i would like to understand,
    POINTS WILL BE REWARDED
    Thanks
    Kind Regards
    Adeel Sarwar

    Hi,
    This is the full code i have entered but its not working. Any help would be appreciated. If you could rectify the code and internal tables that would be great.
    Thanks
    TABLES: EKBE.
    DATA: PurO LIKE EKPO-EBELN,
          POLI LIKE EKPO-EBELP.
    *New Table and Vars defined
    DATA:   BEGIN OF IT_EKBE,
              IT_EKBE LIKE EKBE,
            END OF IT_EKBE.
    DATA:  BEGIN OF IT_SUM OCCURS 0,
              EBELN TYPE EBELN,
              EBELP TYPE EBELP,
              DMBTR TYPE DMBTR,
              MENGE TYPE MENGE,
          END OF IT_SUM.
    CLEAR: QTYD.
    MOVE: EKPO-EBELN TO PurO,
          EKPO-EBELP TO POLI.
    SELECT * FROM EKBE INTO IT_EKBE
        WHERE EBELN = PurO
        AND   EBELP = POLI
        AND   BEWTP = 'E'
    LOOP AT IT_EKBE.
      MOVE CORRESPOING IT_EKBE TO IT_SUM.
      IF IT_EKBE-BWART = '102'.
        IT_SUM-DMBTR = IT_SUM-DMBTR * -1.
        IT_SUM-MENGE = IT_SUM-MENGE * -1.
      ENIDF.
      COLLECT IT_SUM.
      CLEAR IT_SUM.
    ENDLOOP.
    ENDSELECT.
    If sy-subrc = 0.
      QTYD = IT_SUM.
    ELSE.
      QTYD = 0.
    ENDIF.

  • Smartform loop into internal table problem

    hello experts,
    i am doing an example given in **************** regarding smartforms. I am getting problem which doing the smartforms . please help me.
    http://****************/Tutorials/Smartforms/SFMain.htm
    in that i am doing the program
    Working with loop.
    I have done exactly as the screen shots in the program.
    Now in the main window i created a loop.
    in that loop i am not getting the option internal table.
    But it is showing as operand . It is in the data tab of the loop.
    I searched the all the tabs in the loop but did not find the option  internal table.
    so then i ticked the operand and i did as speified in the screen shots.
    it_tab into fs_tab
    Then i created a text and then placed &fs_tab-vbeln& etc.
    then i executed the smartform now in the output i am not getting the sales order number , item etc.
    The output is showing like
    &fs_tab-vbeln&     &fs_tab-posnr&   etc.
    please guide me how to get the internal table option in  the loop. And also tell me how to rectify this problem

    thanks for all the replies.
    I will give all  at the time of closing my thread.
    Hi Sravanthi -> in loop node i am not getting the internal table insted of that i am getting operand in the data tab.
    This is my main problem.I dont why operand is comming there.
    my version is 4.7e
    Hi Karthik and swati -> i simply hard coded the statements in the text as shown in the example.
    Now i will try with the add field.
    But please tell me why i am not getting internal table option in loop.

  • Error "Screen output are too small" when looping through internal table!

    Hello All:
         I have a huge internal table with some 79000 records and while looping through them and doing some other processing inside the loop, I am getting an error "Screen output are too small"! Could someone please help mw how to fix this issue? I can send the all the code if anyone wants to look at the code. Thanks in advance and rewards are assured.
    Mithun

    Hi,
    Check this
    new-page print off.
    CALL FUNCTION 'GET_PRINT_PARAMETERS'
    EXPORTING
    destination = v_dest
    IMPORTING
    out_parameters = params
    valid = valid.
    * params-linct = '58'.
    * params-linsz = '170'.
    * params-paart = 'X_58_170'.
    * params-prtxt = v_spool_text.
    * params-primm = 'X'.
    * params-prrel = 'X'.
    NEW-PAGE PRINT ON PARAMETERS params NO DIALOG.
    After the call fm GET_PRINT_PARAMETERS params internal table contains all the values for generating spool.
    aRs

  • Loop at internal table and get the right line

    Hi,
    I've a table like this sorted by material1 and date.
    Material 1...Date..........Material 2...Stock 
    A1.............01/01/08........A2..........100
    A1.............01/01/07........A2..........150
    B1.............01/05/08........B1..........50
    B1.............01/03/07........B2..........100
    B1.............01/02/07........B3..........75
    I need to put in another table only the line for material1 which has the highest date.
    For this example, line 1 and 3 should be selected.
    Can anyone tell me how to code this??
    Thanks.

    Hi tarick,
    Try this,,
    Create another internal table  itab2 of type itab1 and copy all entries of itab1 to itab2.
    itab2[] = itab1[].
    Now delete adjacent duplicates from itab2 comparing material1.
    DELETE ADJACENT DUPLICATES FROM itab2 comparing material1.
    Effect
    Deletes adjacent duplicate entries from the internal table itab2. If there are n duplicate entries in succession, the first entry is retained, and the following n-1 entries are deleted.
    Reward Points if Helpful.
    Regards,
    Sachin M M

  • Looping at internal table

    Hi, I work on SAP BW and need guidance on the functionality from the below code:
    l_s_datapak_line[] = datapak[].
        l_s_datapak[] = datapak[].
        sort l_s_datapak_line by pernr endda descending.
    loop at l_s_datapak.
       read table l_s_datapak_line with key pernr = l_s_datapak-pernr
       endda = '99991231'.
       if sy-subrc = 0.
    pernr = l_s_datapak_line-pernr.
            curr_compcode = l_s_datapak_line-bukrs.
            curr_job = l_s_datapak_line-stell.
            curr_mastcctr = l_s_datapak_line-kostl.
            curr_orgunit = l_s_datapak_line-orgeh.
            curr_persarea = l_s_datapak_line-werks.
            curr_perssubarea = l_s_datapak_line-BTRTL.
            curr_position = l_s_datapak_line-plans.
            curr_chief = l_s_datapak_line-zzchiefpernr.
            curr_supervisor = l_s_datapak_line-zzsupervisor.
            modify i_curr index i_index.
           exit.
          endif.
        endloop.
    In the above code, I want the loop to run only once for each pernr. If there are 10 records in l_s_datapak with pernr = 100, then the loop would run 100 times although there would be only one record in l_s_datapak_line with endda = '99991231'. I want the loop to run only once , assign the values and then l_s_datapak-pernr should become 101. How do I do it?
    Any help is highly appreciated and thanks for the help in advance.

    Hi,
    Use Control Break statements i.e. AT NEW....ENDAT as shown below.
    l_s_datapak_line[] = datapak[].
    l_s_datapak[] = datapak[].
    sort l_s_datapak_line by pernr endda descending.
    loop at l_s_datapak.
    <b>AT NEW pernr.</b>
    read table l_s_datapak_line with key pernr = l_s_datapak-pernr
    endda = '99991231'.
    if sy-subrc = 0.
    pernr = l_s_datapak_line-pernr.
    curr_compcode = l_s_datapak_line-bukrs.
    curr_job = l_s_datapak_line-stell.
    curr_mastcctr = l_s_datapak_line-kostl.
    curr_orgunit = l_s_datapak_line-orgeh.
    curr_persarea = l_s_datapak_line-werks.
    curr_perssubarea = l_s_datapak_line-BTRTL.
    curr_position = l_s_datapak_line-plans.
    curr_chief = l_s_datapak_line-zzchiefpernr.
    curr_supervisor = l_s_datapak_line-zzsupervisor.
    modify i_curr index i_index.
    exit.
    endif.
    <b>ENDAT.</b>
    endloop.
    Reward points if the answer is helpful.
    Regards,
    Mukul

  • ABAP Looping in internal tables

    Hi,
    I am working on alv report which fetches matnr with no transaction data by passing in ekpo,mseg,ekko tables and query is working is fine and append matnr in it_final to display.
    But now I want to display matnr & matkx-makt but to get this field I have to compare with it_final-matnr to get the corresponding material description. correct values are fetched but issue is with display.
    Code attached in file below.
    Any help to sort out this would be appreciated.
    Message was edited by: Drashti Amrutia

    You could simplify you report
    - Join MARA and MAKT
    - Check non existence of records in subquery
    Sample :
    TYPES: BEGIN OF record,
              matnr TYPE mara-matnr,
              maktx TYPE makt-maktx,
            END OF record.
    DATA: itab TYPE TABLE OF record,
           lo_table TYPE REF TO cl_salv_table.
    PARAMETERS: p_mtart TYPE mara-mtart.
    START-OF-SELECTION.
       SELECT * INTO CORRESPONDING FIELDS OF TABLE itab
         FROM mara
         JOIN makt
           ON mara~matnr EQ makt~matnr
         WHERE mara~mtart EQ p_mtart
           AND makt~spras EQ sy-langu
           AND NOT EXISTS ( SELECT * FROM ekpo WHERE matnr EQ mara~matnr )
           AND NOT EXISTS ( SELECT * FROM ekbe WHERE matnr EQ mara~matnr )
           AND NOT EXISTS ( SELECT * FROM mseg WHERE matnr EQ mara~matnr ).
    END-OF-SELECTION.
       cl_salv_table=>factory(
         IMPORTING
           r_salv_table   = lo_table
         CHANGING
           t_table        = itab ).
       lo_table->display( ).
    Now execute some performance comparison with your FOR ALL ENTRIES options, and decide yourself.
    (How did you choice the tables to check EKPO & EKBE but no EBAN, no RESB ?)
    Regards,
    Raymond

  • Inner join inside a internal table loop

    Hello to all,
    I have this internal table in which i have selected some records for particular coulms. For  the rest of the colums i need to join 3 tables for the data. I had in mind, of looping the internal table and then having a inner join query and  modifying the internal table(all inside the loop) Just wanted to know, whether its a qood practice performance wise ? IF not, what are the alternatives ..
    Thanks,
    Shehryar Dahar

    shehryar,
      say You have internal table ITAB.Already some columns are updated in internal table.say A,B,C,D.
    To fill rest of the columns(E,F,G) you need inter join.
    write the inner join of the table for all entries of itab where A eq itab-A.
    LOOP ITAB.
        READ TABLE ITAB1  WITH KEY X = ITAB-X.
       IF SY-SUBRC EQ 0.
         move  ITAB record to I_FINAL.
         move itab1 records to i_final.
        append i_final.
       clear i_final.
      ENDIF. 
    ENDLOOP.
    Don't forget to reward if useful...

  • How to process a block for each row in an internal table....

    Hi experts....
    In po approval workflow the scenario is like this.... for each po there may be more than one approver. approvers list i am maintaining in the ztable. list of approvers(no of approvers) is decided by the po value. I have collected these approvers into internal table. now i have to process a block ( approving or rejecting the po... )in the workflow for each row in the internal table.
    how can i do this. based on the decision of the 1st approver  approves the po then it should go to next approver in the internal table...otherwise end the workflow.....
    Please help me......

    i have created an internal table in the workflow container in which i am getting the list of approvers....
    how can i loop the internal table in the workflow...?
    how can i know the index of the loop in the workflow.....(will sy-index work here....? so that i can use loop until step in the main workflow to call the subworkflow..so that if sy-index is greater than no of entires in the itab then i can come out of the loop)

  • Invoice: How to use more than one Internal Table's info in one Table

    Hi ,
    I am doing an invoice, and have the info from internal table wa_itgen showing - Matnr, material description and quantity.
    I want to also invlude the info Unit Price and Total price on the table line, but can't seem to do it.
    I know that someone I must fill an internal table as I did on the Table itself : is_bil_invoice-it_gen INTO wa_ITGEN.
                     ( TYPE IBBIL_INVOICE).
    So now I need to insert:
    IS_BIL_INVOICE-IT_PRICE    INTO      WA_ITPRICE.
    Do I insert Program Lines, or do it via a LOOP.  Obviously it needs to go under the same Table's cells to incluce it.
    I tried a LOOP, Program lines under the CELL of the table where I want it displayed, and even a Second table.
    If I have the first table's info, the page displays under VF03, but as soon as I try to insert the 2nd Table's info, under VF03 the screen just not show anymore.
    Please help - I've started looking at local maps for bridges... yes, to jump from...

    Hi try this,
    in the program lines fetch unit price and total price based on ur invoice number(as u are already in main loop which fetches invoice no material no etc).
    now loop that internal table with condition inv no = current invoice no and item no = item number
    and display those values on a new text field accordingly.
    sample code...
    select vbeln
           posnr
           j_3asize
           FKIMG
           KZWI1
           from vbrp
           into table itab
           where vbeln = GS_IT_GEN-BIL_NUMBER.
    loop at itab into wa where vbeln = GS_IT_GEN-BIL_NUMBER and
                               posnr = GS_IT_GEN-ITM_NUMBER .
    move : wa-j_3asize to v_grid,
           WA-FKIMG TO V_QTY,
           wa-KZWI1 to v_val.
           v_up = v_val / v_qty.
    endloop.---->like this

  • Create XML file on application server (unix directory) from internal table

    Hallo everybody,
    I have got the following problem:
    I am working with <u><b>release 4.6C</b></u> and have got to create XML files from HR master data and organizational data respectively.
    This takes place in 3 steps:
    1.     Collect the data in an internal table
    2.     Convert the data to XML format using the function module 'SAP_CONVERT_TO_XML_FORMAT'
    3.     Download the data
    If I download the converted data, which are in an internal table, to the presentation server via the function module ‘WS_DOWNLOAD’ and open it with the Internet Explorer, everything is ok.
    If I download the converted data to the application server, i.e. into a unix directory via
    ‘open dataset’, ‘loop at internal table, ‘transfer working area to file’, ‘close dataset’
    and then try to open it, this is not possible, because after the last tag some unreadable characters, e.g. a square, appear that aren’t supposed to be there. That’s what my colleagues told me, for I haven’t got access to the server.
    I have no idea where these characters come from and how I can get rid of them. I guess that either I have to modify (how?) the table with the converted data before the download or I have to use another way to convert the data. For the second way I would probably have to work with an XML class or an XML interface. Unfortunately I’I am not an expert in working with classes so sample coding would have to be rather detailed.
    Here’s some more information about how I work with the conversion function module:
      call function 'SAP_CONVERT_TO_XML_FORMAT'
           exporting
                i_field_seperator    = lv_field_seperator
               i_line_header        = lv_line_header
               i_filename           = lv_xml_file
               i_appl_keep          = ' '
                i_xml_doc_name       = lv_xml_doc_name
           importing
                pe_bin_filesize      = lv_result
           tables
                i_tab_sap_data       = gt_data
           changing
                i_tab_converted_data = lt_tab_converted_data
           exceptions
                conversion_failed    = 1
                others               = 2.
    lv_field_seperator = ‘X’.
    lv_xml_doc_name = ‘Personalstammdaten Publikation’
    lv_result: type i
    gt_data: fields: PERNR, PERSG, PERSK etc.
      types:
      begin of truxs_xml_line,
        data(256) type x,
      end of truxs_xml_line.
      types:
      truxs_xml_table type table of truxs_xml_line.
    data:
    lv_tab_converted_data type truxs_xml_line,
    lt_tab_converted_data type truxs_xml_table
    open dataset lv_xml_file for output in binary mode.
    loop at lt_tab_converted_data into lv_tab_converted_data.
      transfer lv_tab_converted_data to lv_xml_file.
    endloop.
    close dataset lv_xml_file
    lv_xml_file: /usr/users/.../.../Personendaten_2004-11-02.xml
    Hope the information is detailed enough! Otherwise let me know. Thank you in advance.
    Message was edited by: Johannes Schwehm

    Hi Raja,
    tried the "TEXT" mode, but that didn't help.
    There are still characters after the last tag, that are not supposed to be there including a date that is not
    the creation date of the file.
    Thank you for your help.
    Regards
    Johannes

Maybe you are looking for

  • Need help on IPD file recovery

    Hi i have bb  8520 model( s/w version 4.5). i took baack up in dec 2010 in .ipd format  and  in may 2011 i took another back up in .ipd format.   then  i did a wipe out  of data from my phone (this was required as a IT policy in my new company). when

  • Screen changes made through JavaScript are not rendered

    Hello, What I have done first: 1) Download <a href="http://www.adobe.com/devnet/livecycle/articles/AddingRemovingTableRows.pdf">http://www.adobe.com/devnet/livecycle/articles/AddingRemovingTableRows.pdf</a> 2) Open it with Adobe Designer 3) Save as x

  • Cancel invoce

    I created an excise invice for purchase return using J1IS. But for some reason it was wronly prepared and now I want to cancel it. How do we cancel it along with reversing its accounting entries? Also, can I et a list of cancelled invoices? VS

  • Config Tool connection error

    Hi I have created a system migration copy of an NW04 XI system running on Windows 32 bit migrated to Windows 64 bit, the system starts ok and works fine, but when I try and connect to the config tool to set 64 bit Java parameters by the default setti

  • Can flash3d effect font size in some browsers?

    hello; I have an swf that has many dynamic textfields; a couple of them are inside of an mc that has been rotated in xyz-space via the properties panel; these particular tf's are not displaying correctly in some browsers. tf's are embedded. any thoug