For all entries with 2 internal table

HI experts.
How to use  2 for all entries in a select statement.
Below refer to my below code.
select vbeln matnr lfimg vgbel posnr from lips into corresponding fields of table
  it_lips for all entries in  it_likp   where
              vbeln = it_likp-vbeln and
              matnr = it_mara-matnr.
I want to add another for all entries it_mara.
Please help me .Thanks in advanced.

hi,
it is possible....
use this query...
declare another internal table of the same type as it_lips.
data : it_lips_final like it_lips.
select vbeln matnr lfimg vgbel posnr from lips into corresponding fields of table
it_lips for all entries in it_likp where
vbeln = it_likp-vbeln .
loop at it_lips.
  read table it_mara into it_mara with key matnr = it_lips-matnr.
  if sy-subrc = 0.
    append it_lips to it_lips_final.
  endif.
endloop.
refresh it_lips[].
it_lips[] = it_lips_final[]
what the above code does is selects all the entries of vbeln from lips and filters it in the loop reading it from mara checking for matnr value and finally
all the entries according to your requirement is there in it_lips_final which we move it to it_lips again...
this is something similar to writing a for all entries for 2 table.... but in another fashion
Regards
Siddarth

Similar Messages

  • For All Entries with two tables

    Hi All,
             Can we use FOR ALL ENTRIES with two tables. for example
    SELECT * FROM MKPF INTO TABLE T_MKPF
             WHERE BUDAT IN S_BUDAT.
    SELECT * FROM MARA INTO TABLE T_MARA
             WHERE MTART IN S_MTART AND
                            MAKTL IN S_MAKTL.
    SELECT * FROM MSEG INTO TABLE T_MSEG
           FOR ALL ENTRIES IN  "T_MKPF AND T_MARA"
                  WHERE MBLNR EQ T_MKPF-MBLNR AND
                                 MATNR EQ T_MARA-MATNR.
    can we do it like this or any other way to do this plz tell. I waitting for your responce.
    Thanks
    Jitendra

    Hi,
    u cannot do like this....chek some documentation on it..
    1. duplicate rows are automatically removed
    2. if the itab used in the clause is empty , all the rows in the source table will be selected .
    3. performance degradation when using the clause on big tables.
    Say for example you have the following abap code:
    Select * from mara
    For all entries in itab
    Where matnr = itab-matnr.
    If the actual source of the material list (represented here by itab) is actually another database table, like:
    select matnr from mseg
    into corresponding fields of table itab
    where ….
    Then you could have used one sql statement that joins both tables.
    Select t1.*
    From mara t1, mseg t2
    Where t1.matnr = t2.matnr
    And T2…..
    So what are the drawbacks of using the "for all entires" instead of a join ?
    At run time , in order to fulfill the "for all entries " request, the abap engine will generate several sql statements (for detailed information on this refer to note 48230). Regardless of which method the engine uses (union all, "or" or "in" predicates) If the itab is bigger then a few records, the abap engine will break the itab into parts, and rerun an sql statement several times in a loop. This rerun of the same sql statement , each time with different host values, is a source of resource waste because it may lead to re-reading of data pages.
    returing to the above example , lets say that our itab contains 500 records and that the abap engine will be forced to run the following sql statement 50 times with a list of 10 values each time.
    Select * from mara
    Where matnr in ( ...)
    Db2 will be able to perform this sql statement cheaply all 50 times, using one of sap standard indexes that contain the matnr column. But in actuality, if you consider the wider picture (all 50 executions of the statement), you will see that some of the data pages, especially the root and middle-tire index pages have been re-read each execution.
    Even though db2 has mechanisms like buffer pools and sequential detection to try to minimize the i/o cost of such cases, those mechanisms can only minimize the actual i/o operations , not the cpu cost of re-reading them once they are in memory. Had you coded the join, db2 would have known that you actually need 500 rows from mara, it would have been able to use other access methods, and potentially consume less getpages i/o and cpu.
    In other words , when you use the "for all entries " clause instead of coding a join , you are depriving the database of important information needed to select the best access path for your application. Moreover, you are depriving your DBA of the same vital information. When the DBA monitors & tunes the system, he (or she) is less likely to recognize this kind of resource waste. The DBA will see a simple statement that uses an index , he is less likely to realize that this statement is executed in a loop unnecessarily.
    Beore using the "for all entries" clause and to evaluate the use of database views as a means to:
    a. simplify sql
    b. simplify abap code
    c. get around open sql limitations.
    check the links
    http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_ForAllEntries.asp
    The specified item was not found.
    Regards,
    Nagaraj

  • For all entries with inner join

    Hi All,
    I found some unusual thing.
    i have written INNERJOIN along with FOR ALL ENTRIES and also INNERJOIN in loop..endloop. I have tested both programs with around 1000 records, i found that INNERJOIN with FOR ALL ENTRIES is taking more time compared to the other one. As we know FOR ALL ENTRIES with SIMPLE SELECT takes less time compared to select in loop..endloop. Anybody tell me is there any specific reason for this
    thanks in advance
    rajavardhana reddy

    Have a look at this weblog by Dharmaveer Singh:
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/2986 [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken]
    Sudha

  • Select For all entries with multiple keys

    Dear Developers,
    im writing a program which reads the last the last mseg entry with bwart 101 and bwart 201 an writes it into different fields of a table. In dependance of the bwart the max-value of mkpf-budat should be moved into field wedat or wadat.
    At the moment i use this coding:
    loop at gt_daten assigning <fs_daten>.
        select distinct max( budat ) from wb2_v_mkpf_mseg2 into <fs_daten>-wedat
          where matnr_i = <fs_daten>-matnr
            and werks_i = <fs_daten>-werks
            and lgort_i = <fs_daten>-lgort
            and bwart_i = '101'.
        select distinct max( budat ) from wb2_v_mkpf_mseg2 into <fs_daten>-wadat
        where matnr_i = <fs_daten>-matnr
          and werks_i = <fs_daten>-werks
          and lgort_i = <fs_daten>-lgort
          and bwart_i = '201'.
      endloop.
    wb2_v_mkpf_mseg2 is a view combining mkpf an mseg by primary keys.
    Searching the internet i read, using FOR ALL ENTRIES should be prefered to selectstatements in loops.
    So i tried:
    *selectstatement
    select budat matnr_i werks_i lgort_i bwart_i from wb2_v_mkpf_mseg2 into table lt_mseg for all entries in gt_daten
        where matnr_i = gt_daten-matnr
          and werks_i = gt_daten-werks
          and lgort_i = gt_daten-lgort
          and ( bwart_i = '101' or bwart_i = '201' )
    *Substitute the MAX( )-Function
      sort lt_mseg descending by matnr werks lgort bwart budat.
      delete adjacent duplicates from lt_mseg comparing matnr werks lgort bwart.
    *Differ between wedat and wadat
      loop at gt_daten assigning <fs_daten>.
        loop at lt_mseg assigning <fs_mseg>
          where matnr = <fs_daten>-matnr
            and werks = <fs_daten>-werks
            and lgort = <fs_daten>-lgort.
          case <fs_mseg>-bwart.
            when '101'.
              <fs_daten>-wedat = <fs_mseg>-budat.
            when '201'.
              <fs_daten>-wadat = <fs_mseg>-budat.
          endcase.
        endloop.
    Even in the dev-system this takes twice the time of the "nested" selects.
    Imho this is because of the internal OR interpretation of the FOR ALL ENTRIES-statement and the size of the result.
    Can somebody give me a hint, how to tune this code?
    Select Inner join should be difficult because the target field differs, dependent of the value in bwart...
    Thanks in advance!

    I understand that you are trying to capture the maximum value of posting date MKPF-BUDAT for movement types 101 and 201 for each combination of material, plant and storage location.
    Few things, that makes the below coding more efficient at both application and database level and I confirmed this on an IDES sandbox
    1. Along with MKPF and MSEG, there is another table WBGT, in the view WB2_V_MKPF_MSEG join and also WBGT has select condition restrictions imposed on its fields. So if this restriction impacts your selection you may want to do a INNER JOIN of MSEG with MKPF only (with MSEG as leading table, as it has an active secondary index with MATNR, WERKS, LGORT and BWART ) and also there won't be overhead from the unnecessary join with WBGT table whose fields you are not using.
    2. The below SORT on lt_mseg will ensure that the record having greatest BUDAT will be at the top of all rows (least index) for each combination of MATNR, WERKS, LGORT and BWART.
    3. DELETE ADJACENT DUPLICATES will ensure that only the top row (having greatest BUDAT) remains in the table lt_mseg for each combination of MATNR, WERKS, LGORT and BWART. This will ensure that subsequent READs with BINARY SEARCH will always and efficiently read the row with maximum value of BUDAT for each unique combination of MATNR, WERKS, LGORT and BWART.
    4. The below logic will require more memory (even though it is more efficient performance wise) compared to direct SELECT with MAX for each MATNR, WERKS, LGORT and BWART in a LOOP the way you were doing before. So if the size of lt_mseg is causing memory issues, your logic with aggregate function MAX at database level will be your only option.
    So, I propose you revise your coding like below for most optimal results
    CHECK NOT gt_daten[] IS INITIAL.
    *selectstatement
    *SELECT budat matnr_i werks_i lgort_i bwart_i
    *  FROM wb2_v_mkpf_mseg2
    *  INTO TABLE lt_mseg
    *    FOR ALL ENTRIES IN gt_daten
    *    WHERE matnr_i = gt_daten-matnr
    *      AND werks_i = gt_daten-werks
    *      AND lgort_i = gt_daten-lgort
    *      AND ( bwart_i = '101' OR bwart_i = '201' ).
    * The below SELECT is more economical than the one commented above
    SELECT mkpf~budat mseg~matnr mseg~werks mseg~lgort mseg~bwart
      FROM mseg INNER JOIN mkpf
        ON mseg~mblnr = mkpf~mblnr AND
           mseg~mjahr = mkpf~mjahr
        INTO TABLE lt_mseg
          FOR ALL ENTRIES IN gt_daten
            WHERE mseg~matnr = gt_daten-matnr
              AND mseg~werks = gt_daten-werks
              AND mseg~lgort = gt_daten-lgort
              AND ( mseg~bwart = '101' OR mseg~bwart = '201' ).
    *Substitute the MAX( )-Function
    SORT lt_mseg BY matnr werks lgort bwart DESCENDING budat.
    DELETE ADJACENT DUPLICATES FROM lt_mseg COMPARING matnr werks lgort bwart.
    *Differ between wedat and wadat
    LOOP AT gt_daten ASSIGNING <fs_daten>.
      READ TABLE lt_mseg ASSIGNING <fs_mseg>
        WITH KEY matnr = <fs_daten>-matnr
                 werks = <fs_daten>-werks
                 lgort = <fs_daten>-lgort
                 bwart = '101' BINARY SEARCH.
      IF sy-subrc = 0.
        <fs_daten>-wedat = <fs_mseg>-budat.
      ENDIF.
      READ TABLE lt_mseg ASSIGNING <fs_mseg>
        WITH KEY matnr = <fs_daten>-matnr
                 werks = <fs_daten>-werks
                 lgort = <fs_daten>-lgort
                 bwart = '201' BINARY SEARCH.
      IF sy-subrc = 0.
        <fs_daten>-wadat = <fs_mseg>-budat.
      ENDIF.
    ENDLOOP.

  • 2 for all entries with different condition

    Hi
    i have an internal 2 internal table which have the following field
    ITAB1 : Stock category, plant, storage location , SKU code   (those value are given though flat file)
    ITAB2 : Grid value , meterial NO, SKU code  (those values are determine through a FM where we export the SKU code and it will retreive the matnr and grid value in an ITAB2)
    I have to do select FROM database MCHB
    with the condition Grid value , material NO , Stock category, plant, storage location
    Note that gris value and matnr are found in two different internal table i was thinking of doing for all entries but
    is it possible to do for all entries from 2 internal table
    SELECT FOROM MCHB
    FOR ALL ENTRIES in ITAB1
    FOR ALL ENTRIES in ITAB2
    WHERE
    grid value = itab2-gridvalue
    matnr = itab2-matnr
    stock cat = itab1-stock cat
    plant = itab1-plant
    storage location = itab1-storage location
    Please help on how to tackle this?

    Hi,
    You have to create a new third internal table with the fields matnr, grid value, stock category, plant and storage location....
    Then process the itab1 and get the process the itab2 for the corresponding SKU Code (which I believe is the common field for both of the internal tables) and then populate the third internal table itab3...
    Then use the itab3 for the FOR ALL ENTRIES.
    Thanks
    Naren

  • For all entries on custom tables

    i have created 2 custom tables::zhospital_info n zpatient_info..
    zhospitalinfo tab fields:::_
    doc_name::prim key
    patient_name:::prim key
    place::prim key
    zpatientinfo tab fields::_
             ZDATE ::prim key
             JOINING
             MEDICINE
             PRICE
             QUANTITY
             DOC_NAME ::for key
             PATIENT_NAME::for key
             PLACE ::for key
    and inserted some values to the table contents..
    this is my logic:::
    TYPES: BEGIN OF ZHOSPITAL_INFO,
            DOC_NAME TYPE ZDOC_NAME,
            PATIENT_NAME TYPE ZPATIENT_NAME,
            PLACE TYPE ZPLACE,
           END OF ZHOSPITAL_INFO.
    DATA: W_HI TYPE ZHOSPITAL_INFO.
    DATA:T_HI TYPE STANDARD TABLE OF ZHOSPITAL_INFO.
    TYPES: BEGIN OF ZPATIENTL_INFO,
             ZDATE TYPE ZDATE,
             JOINING TYPE ZJOINING,
             MEDICINE TYPE ZMEDICINE,
             PRICE TYPE ZPRICE,
             QUANTITY TYPE ZQUANTITY,
             DOC_NAME TYPE ZDOC_NAME,
             PATIENT_NAME TYPE ZPATIENT_NAME,
             PLACE TYPE ZPLACE,
           END OF ZPATIENTL_INFO.
    DATA: W_PI TYPE ZPATIENTL_INFO.
    DATA:T_PI TYPE STANDARD TABLE OF ZPATIENTL_INFO.
    TYPES: BEGIN OF FTAB,
            DOC_NAME TYPE ZDOC_NAME,
            PATIENT_NAME TYPE ZPATIENT_NAME,
            PLACE TYPE ZPLACE,
            DATE TYPE ZDATE,
            JOINING TYPE ZJOINING,
            MEDICINE TYPE ZMEDICINE,
            PRICE TYPE ZPRICE,
            QUANTITY TYPE ZQUANTITY,
           END OF FTAB.
    DATA: W_FTAB TYPE FTAB,
          T_FTAB TYPE STANDARD TABLE OF FTAB.
    SELECT DOC_NAME
           PATIENT_NAME
           PLACE
           INTO TABLE t_hi
           FROM ZHOSPITAL_INFO .
    IF NOT t_hi IS NOT INITIAL.
    SELECT DOC_NAME
           PATIENT_NAME
           PLACE
           ZDATE
          MEDICINE*
           PRICE
           QUANTITY FROM ZPATIENTL_INFO INTO TABLE t_pi FOR ALL ENTRIES IN
    t_hi
           WHERE DOC_NAME = t_hi-doc_name.
    ENDIF.
    LOOP AT t_pi INTO w_pi.
    MOVE-CORRESPONDING: w_pi TO W_FTAB.
    READ TABLE t_hi INTO w_hi WITH KEY DOC_NAME = W_FTAB-DOC_NAME.
    MOVE: w_hi-patient_name TO W_FTAB-PATIENT_NAME,
          w_hi-place TO W_FTAB-PLACE.
          APPEND W_FTAB TO T_FTAB.
    ENDLOOP.
    LOOP AT T_FTAB INTO W_FTAB.
       WRITE:/ W_FTAB-DOC_NAME,
               W_FTAB-PATIENT_NAME,
               W_FTAB-PLACE,
               W_FTAB-DATE,
               W_FTAB-JOINING,
               W_FTAB-MEDICINE,
               W_FTAB-PRICE,
               W_FTAB-QUANTITY.
    ENDLOOP.
    req output:::when i enter doc_name the related info accr to doc_name from the both tables should be display..
    m getting no errors but i cant execute my prog..
    please check out my code...
    thanx in adv..

    Hi,
    The problem is in the select statement:
    SELECT DOC_NAME
    PATIENT_NAME
    PLACE
    ZDATE
    MEDICINE
    PRICE
    QUANTITY FROM ZPATIENTL_INFO INTO TABLE t_pi FOR ALL ENTRIES IN
    t_hi
    WHERE DOC_NAME = t_hi-doc_name.
    Change this to SELECT DOC_NAME PATIENT_NAME PLACE ZDATE MEDICINE PRICE QUANTITY FROM ZPATIENTL_INFO INTO CORRESPONDING FIELDS OF TABLE t-pi FOR ALL ENTRIES IN t_hi WHERE DOC_NAME = t_hi-doc_name.
    I hope the above code will help you...
    Also i hope to tell the following for performance issues and also a good programming practice:
    LOOP AT t_pi INTO w_pi.
    MOVE-CORRESPONDING: w_pi TO W_FTAB.
    READ TABLE t_hi INTO w_hi WITH KEY DOC_NAME = W_FTAB-DOC_NAME.
    MOVE: w_hi-patient_name TO W_FTAB-PATIENT_NAME,
    w_hi-place TO W_FTAB-PLACE.
    APPEND W_FTAB TO T_FTAB.
    ENDLOOP.
    Please do a sy-subrc check after READ statement always...
    LOOP AT t_pi INTO w_pi.
    MOVE-CORRESPONDING: w_pi TO W_FTAB.
    READ TABLE t_hi INTO w_hi WITH KEY DOC_NAME = W_FTAB-DOC_NAME.
    If sy-subrc = 0.
    MOVE: w_hi-patient_name TO W_FTAB-PATIENT_NAME,
    w_hi-place TO W_FTAB-PLACE.
    clear w_hi.
    Endif.APPEND W_FTAB TO T_FTAB.
    ENDLOOP.
    Please revert back for clarifications.
    Best Regards,
    Suresh

  • FOR ALL ENTRIES - CDHDR / CDPOS Tables

    Hi,
    I know there have been a lot of threads concerning the "for all entries" statement. Nevertheless I got a problem downloading the change document tables CDHDR/CDPOS with this statement and I haven't found anything in this forum regarding this special issue.
    While trying the for all entries statement in the below manner for downloading first CDHDR and then the CDPOS for all entries of the selected CDHDR it took 3 days and didn't finish, so we aborted the ABAP. The JOIN statement doesn't work in a 4.6c environment for the Cluster tables, hence this isn't an option.
    Can you give me some advise of how to improve downloading those tables in this way:
    1. Download CDHDR with limitation of fields OBJECTCLAS and UDATE
    2. Then Download CDPOS for all CHANGENR out of the first selection of CDHDR
    This was the way I tried it:
    SELECT
    ACT_CHNGNO  CHANGE_IND  CHANGENR  MANDANT  OBJECTCLAS  OBJECTID  PLANCHNGNR  TCODE  UDATE  USERNAME  UTIME  WAS_PLANND APPENDING CORRESPONDING FIELDS OF TABLE T_CDHDR FROM CDHDR WHERE UDATE IN  s_UDAT1 AND OBJECTCLAS IN  s_OBJE0.
    ENDSELECT.
    SELECT
    CHANGENR  CHNGIND  CUKY_NEW  CUKY_OLD  FNAME  MANDANT  OBJECTCLAS  OBJECTID  TABKEY  TABNAME  UNIT_NEW  UNIT_OLD  VALUE_NEW  VALUE_OLD INTO gs_CDPOS FROM CDPOS CLIENT SPECIFIED for all entries in  T_CDHDR WHERE OBJECTCLAS IN  s_OBJE2 AND MANDANT EQ  T_CDHDR-MANDANT AND OBJECTCLAS EQ  T_CDHDR-OBJECTCLAS AND CHANGENR EQ  T_CDHDR-CHANGENR.
    ENDSELECT.

    THis prg might b usefull to u
    *  Mass display or print Purchase Order History
    *  You can request report by :
    *  1.  Change date
    *  2.  User Name
    *  3.  Purchase Order Number
    *  4.  Vendor Code
    * Written by : SAP Basis, ABAP Programming and Other IMG Stuff
    *              http://www.sap-img.com
    REPORT ZPOCHANGE LINE-SIZE 132 NO STANDARD PAGE HEADING
                     LINE-COUNT 065(001)
                     MESSAGE-ID VR.
    TABLES: DD04T,
            CDHDR,
            CDPOS,
            DD03L,
            DD41V,
            T685T,
            VBPA,
            TPART,
            KONVC,
            EKKO.
    SELECT-OPTIONS: XUDATE FOR CDHDR-UDATE,
                    XNAME  FOR CDHDR-USERNAME,
                    XEBELN FOR EKKO-EBELN,
                    XLIFNR FOR EKKO-LIFNR.
    SELECTION-SCREEN SKIP.
    * TEXT-001 - Sorting Sequence
    SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
    PARAMETERS: SUDATE RADIOBUTTON GROUP R1,
                SNAME  RADIOBUTTON GROUP R1,
                SOBID  RADIOBUTTON GROUP R1.
    SELECTION-SCREEN END OF BLOCK BLK1.
    DATA: WFLAG,
          WCHANGENR LIKE CDHDR-CHANGENR.
    DATA: INDTEXT(60) TYPE C.
    DATA: BEGIN OF ICDHDR OCCURS 50.
            INCLUDE STRUCTURE CDHDR.
    DATA: END OF ICDHDR.
    DATA: BEGIN OF ICDSHW OCCURS 50.
            INCLUDE STRUCTURE CDSHW.
    DATA: END OF ICDSHW.
    DATA: BEGIN OF EKKEY,
            EBELN LIKE EKET-EBELN,
            EBELP LIKE EKET-EBELP,
            ETENR LIKE EKET-ETENR,
          END OF EKKEY.
    DATA: BEGIN OF ITAB OCCURS 50,
            BEGIN OF EKKEY,
              EBELN LIKE EKET-EBELN,
              EBELP LIKE EKET-EBELP,
              ETENR LIKE EKET-ETENR,
            END OF EKKEY,
            CHANGENR LIKE CDHDR-CHANGENR,
            UDATE    LIKE CDHDR-UDATE,
            UTIME    LIKE CDHDR-UTIME,
            USERNAME LIKE CDHDR-USERNAME,
            CHNGIND  LIKE CDSHW-CHNGIND,
            FTEXT    LIKE CDSHW-FTEXT,
            OUTLEN   LIKE CDSHW-OUTLEN,
            F_OLD    LIKE CDSHW-F_OLD,
            F_NEW    LIKE CDSHW-F_NEW,
          END OF ITAB.
    DATA: OLD_OBJECTID LIKE CDHDR-OBJECTID.
    FIELD-SYMBOLS: <F_OLD>, <F_NEW>.
    SELECT * FROM EKKO WHERE EBELN IN XEBELN AND
                             LIFNR IN XLIFNR.
      CLEAR CDHDR.
      CLEAR CDPOS.
      CDHDR-OBJECTCLAS = 'EINKBELEG'.
      CDHDR-OBJECTID   = EKKO-EBELN.
      PERFORM GETCHGDOCS.
    ENDSELECT.
    IF SUDATE = 'X'.
      SORT ITAB BY UDATE EKKEY-EBELN CHANGENR EKKEY-EBELP
                   EKKEY-ETENR.
    ELSEIF SNAME = 'X'.
      SORT ITAB BY USERNAME EKKEY-EBELN CHANGENR EKKEY-EBELP
                   EKKEY-ETENR.
    ELSE.
      SORT ITAB BY EKKEY-EBELN CHANGENR EKKEY-EBELP EKKEY-ETENR.
    ENDIF.
    LOOP AT ITAB.
      CLEAR: INDTEXT, EKKEY.
      CASE ITAB-CHNGIND.
        WHEN 'U'.
            INDTEXT(50) = ITAB-FTEXT.
            INDTEXT+51  = TEXT-020.
            CONDENSE INDTEXT.
        WHEN 'D'.
            INDTEXT = TEXT-021.
        WHEN 'E'.
            INDTEXT(5) = ITAB-FTEXT.
            INDTEXT+51 = TEXT-021.
            CONDENSE INDTEXT.
          WHEN 'I'.
            INDTEXT = TEXT-022.
        ENDCASE.
        RESERVE 4 LINES.
        IF WCHANGENR NE ITAB-CHANGENR.
          WCHANGENR = ITAB-CHANGENR.
          EKKEY = ITAB-EKKEY.
          WRITE:/ ITAB-UDATE UNDER 'Change Date',
                  ITAB-UTIME UNDER 'Time',
                  ITAB-USERNAME UNDER 'User Name',
                  ITAB-EKKEY-EBELN UNDER 'PO No',
                  ITAB-EKKEY-EBELP UNDER 'Item',
                  ITAB-EKKEY-ETENR UNDER 'Sch No',
                  INDTEXT     UNDER 'Changes'.
        ELSEIF ITAB-EKKEY NE EKKEY.
          WRITE:/ ITAB-EKKEY-EBELP UNDER 'Item',
                  ITAB-EKKEY-ETENR UNDER 'Sch No',
                  INDTEXT     UNDER 'Changes'.
        ENDIF.
        CASE ITAB-CHNGIND.
          WHEN 'U'.
            ASSIGN ITAB-F_OLD(ITAB-OUTLEN) TO <F_OLD>.
            ASSIGN ITAB-F_NEW(ITAB-OUTLEN) TO <F_NEW>.
            WRITE: / TEXT-023  UNDER 'Changes',
                     <F_OLD>.
            WRITE: / TEXT-024 UNDER 'Changes',
                     <F_NEW>.
          WHEN 'E'.
            ASSIGN ITAB-F_OLD(ITAB-OUTLEN) TO <F_OLD>.
            WRITE: TEXT-023 UNDER 'Changes',
                   <F_OLD>.
        ENDCASE.
        SKIP.
    ENDLOOP.
    TOP-OF-PAGE.
    WRITE:/ SY-DATUM,SY-UZEIT,
           50 'P U R C H A S E  O R D E R   H I S T O R Y',
          120 'Page', SY-PAGNO.
    WRITE: / SY-REPID,
             60 'Purchase Orders Changes'.
    SKIP.
    ULINE.
    IF SUDATE = 'X'.
      WRITE:/001 'Change Date',
             014 'Time',
             024 'User Name',
             038 'PO No',
             050 'Item',
             057 'Sch No',
             065 'Changes'.
    ELSEIF SOBID = 'X'.
      WRITE:/001 'PO No',
             013 'Item',
             020 'Sch No',
             028 'Change Date',
             041 'Time',
             051 'User Name',
             065 'Changes'.
    ELSE.
      WRITE:/001 'User Name',
             015 'Change Date',
             028 'Time',
             038 'PO No',
             050 'Item',
             057 'Sch No',
             065 'Changes'.
    ENDIF.
    ULINE.
    FORM GETCHGDOCS.
      CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
           EXPORTING
                DATE_OF_CHANGE    = CDHDR-UDATE
                OBJECTCLASS       = CDHDR-OBJECTCLAS
                OBJECTID          = CDHDR-OBJECTID
                TIME_OF_CHANGE    = CDHDR-UTIME
                USERNAME          = CDHDR-USERNAME
           TABLES
                I_CDHDR           = ICDHDR
           EXCEPTIONS
                NO_POSITION_FOUND = 1
                OTHERS            = 2.
      CHECK SY-SUBRC EQ 0.
      DELETE ICDHDR WHERE CHANGE_IND EQ 'I'.
      CHECK NOT ICDHDR[] IS INITIAL.
      LOOP AT ICDHDR.
        CHECK ICDHDR-UDATE IN XUDATE.
        CHECK ICDHDR-USERNAME IN XNAME.
        CALL FUNCTION 'CHANGEDOCUMENT_READ_POSITIONS'
                     EXPORTING  CHANGENUMBER       = ICDHDR-CHANGENR
                     IMPORTING  HEADER             = CDHDR
                     TABLES     EDITPOS            = ICDSHW
                     EXCEPTIONS NO_POSITION_FOUND  = 1
                                OTHERS             = 2.
        CHECK SY-SUBRC EQ 0.
        LOOP AT ICDSHW.
          CHECK ICDSHW-TEXT_CASE EQ SPACE.
          MOVE-CORRESPONDING ICDSHW TO ITAB.
          MOVE-CORRESPONDING ICDHDR TO ITAB.
          MOVE ICDSHW-TABKEY+3 TO ITAB-EKKEY.
          APPEND ITAB.
        ENDLOOP.
      ENDLOOP.
    ENDFORM.
    * END OF PROGRAM

  • Want to Avoid Loop for all entries with select query !!

    Hi Guru's  !
    This is my following code . I want to avoid loop  to improve the performance of program.
    data: lt_cuhd type HASHED TABLE OF /sapsll/cuhd WITH UNIQUE key guid_cuhd,
          ls_cuhd type /sapsll/cuhd.
    data: lt_comments type STANDARD TABLE OF zss_comments,
          ls_comments type zss_comments.
    data: lv_objkey type string.
    select * from /sapsll/cuhd into table lt_cuhd.
    loop at lt_cuhd  into ls_cuhd.
      CONCATENATE ls_cuhd-corder '%' into lv_objkey. " Example 'Mum%'
      select * from zss_comments into table lt_comments
                where objkey like lv_objkey
                 AND guid_cuhd = ls_cuhd-guid_cuhd
                  AND event_id <> ''.
    endloop.
    I want
    New code should be...using all entries no loop required.
      *select * from zss_comments into table lt_comments
                where objkey like lv_objkey
                 AND guid_cuhd = ls_cuhd-guid_cuhd
                  AND event_id <> ''.*

    why dont you add the object key also to  lt_cuhd and once you fetch the data to lt_cuhd loop it and add the '%'
    when looping use field symbols so that you dont have to use  modify.
    then use for all entries using lt_cuhd
    i don't you can find a better way to add the % mark apart from looping but by this way only one select query will be done for
    zss_comments
    Thanks
    Nafran

  • Inner join and select for all entries with respect to performance

    Hi Friends,
    I just want to know which is more efficient with respect to performance the Inner join or select for all entries?which is more efficient? and how? can you explain me in detail ?
    Regards,
    Dinesh

    INNER JOIN->
    The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view. With an outer join, records are also selected for which there is no entry in some of the tables used in the view.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ec77446011d189700000e8322d00/content.htm
    FOR ALL ENTRIES->
    Outer join can be created using this addition to the where clause in a select statement. It speeds up the performance tremendously, but the cons of using this variation are listed below
    Duplicates are automatically removed from the resulting data set. Hence care should be taken that the unique key of the detail line items should be given in the select statement.
    If the table on which the For All Entries IN clause is based is empty, all rows are selected into the destination table. Hence it is advisable to check before-hand that the first table is not empty.
    If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. Hence attempt should be made to keep the table size to a moderate level.
    Not Recommended
    Loop at int_cntry.
    Select single * from zfligh into int_fligh
    where cntry = int_cntry-cntry.
    Append int_fligh.
    Endloop.
    Recommended
    Select * from zfligh appending table int_fligh
    For all entries in int_cntry
    Where cntry = int_cntry-cntry.

  • For all entries with large sets

    Hello All,
    Does for all entries have restriction that the itab should not exceed the maximum entries? Look at code below:
      select pernr raufpl raplzl catshours
             from catsdb
             into corresponding fields of table lit_catshrs
             for all entries in itab
             where pernr = itab-pernr
               and status in ('10', '20', '30')
               and workdate in s_date.
    if itab have 7000 entries in production system, will the select statement cause a short dump such as DBIF_RSQL_INVALID_RSQL?
    Thanks,
    Alex M

    Hi,
    check the sequence of the fields in the internal table lit_catshrs
    Because RSQL error occurs because of this.
    and Whenevr you use for all entries of some Internal Table it is a must to check that
    IF not ITAB[] Is initial.
    < write the select>
    endif.
    Other performance related thing w.r.t to ABAP are
    1) Dont use nested seelct statement
    2) If possible use for all entries in addition
    3) In the where addition make sure you give all the primary key
    4) Use Index for the selection criteria.
    5) You can also use inner joins
    6) You can try to put the data from the first select statement into an Itab and then in order to select the data from the second table use for all entries in.
    7) Use the runtime analysis SE30 and SQL Trace (ST05) to identify the performance and also to identify where the load is heavy, so that you can change the code accordingly
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5d0db4c9-0e01-0010-b68f-9b1408d5f234
    reward if useful
    regards,
    Anji

  • For all entries from 2 tables that have no common key

    Hello
    I have the next querry that i want to write in abap
    AUFK -
    >aufk-aufnr = afko- aufnr----> AFKO        
    AUFK---->aufk-pspel = afvc-projn -
    >AFVC      
    AFKO-----> afko-rsnum = resb-rsnum   -
    > RESB
    AFVC-----> afvc-aufpl = resb-aufpl       -
    > RESB
    AFVC-----> afvc-vornr = resb-vornr      -
    > RESB
    So that i have to start with AUFK and from there i read AFKO and AFVC  and with the entries from AFKO and AFVC i have to do a select on RESB.
    How can i do this
    select from RESB
    for all entries in AFKO
       where ...
    for all entries in AFVC
       where...  ?
    I do not have any common key between AFVC and AFKO. How can i select the correct entries from RESB?
    I have to mention that i have 1-1 entries for AUFK and AFKO
                                           and 1-N entries for AUFK and AFVC
    Thank you

    Why don't you use afko-aufpl = afvc-aufpl ?
    Regards,
    Raymond

  • Inner join and select for all entries with respect to performance in SAP

    Hi Friends,
    I just want to know which is more efficient with respect to performance the Inner join or select for all entries?which is more efficient?
    Regards,
    Dinesh

    I did some testing a while ago and found that a JOIN is usually a bit more efficient than FOR ALL ENTRIES. This wasn't always the case though, so the best thing to do is to write it both ways and see which is faster.
    Rob

  • For all entries query

    Hi,
    can we do a for all entries with a table type parameter.
    select * from <tablename> for all entries in <internal table> (importing parameter in an FM a table type parameter)....where <cond>

    go thrugh this and check dynamic select it may help you
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/840ad679-0601-0010-cd8e-9989fd650822#q-16">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/840ad679-0601-0010-cd8e-9989fd650822#q-16</a>
    regards
    shiba dutta

  • How to use dynamic internal table with FOR ALL ENTRIES

    Hello SDNers,
    I am having a dynamic internal table & want to use FOR ALL ENTRIES(FAE) using this dyn. table.
    This works fine for me:
    IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
            SELECT field1 field2
              FROM TABLE ztable
              INTO TABLE itab "Itab is a static table
              FOR ALL ENTRIES IN <lt_tmp>
              WHERE (lv_dynwhere). "lv_dynwhere -> dynamic where clause
          ENDIF.
    SAP documentation says:
    "The logical expression sql_cond of the WHERE condition can be comprised of several logical expressions using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one comparison with a column of the internal table itab that can be specified statically or dynamically. "
    How do we specify the column of the internal table dynamically ? Can we do something like this:
    IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
            SELECT field1 field2
              FROM TABLE
              INTO TABLE itab "Itab is a static table
              FOR ALL ENTRIES IN <lt_tmp>
              WHERE key_field1 = (dynamic token for column1 of <lt_tmp>)
                           key_field2 = (dynamic token for column2 of <lt_tmp>)
          ENDIF.
          ENDIF.
    Let me know if i am not clear about my requirement.
    BR,
    Suhas

    Hello Thomas,
    What i meant was something like this:
    WHERE key_field1 = ('<LT_TMP-COL1>') AND
          key_field2 = ('<LT_TMP-COL2>')
    I am confused by what SAP means with "dynamic representation of internal table columns" in FAE ?
    @Rob: I was referring to SAPNW 7.0 documentation & the phrase (release 6.40 & higher) is missing. Anyways fyi i am on ECC5.0 ABAP release 6.40.
    @Subhankar: This is what Marcin had proposed in For all entries and dynamic table.
    Thanks,
    Suhas
    Edited by: Suhas Saha on Apr 6, 2010 11:53 AM

  • Issue with FOR ALL ENTRIES

    Hi All,
    I have used FOR ALL ENTRIES statement in while selecting data based on some other internal table (to avoid select within loop).
    While using FOR ALL ENTRIES, the target table (internal table in which data is getting stored) is getting affected.
    The other fields are becoming zero and several rows gets delerted from the internal table after performing select query.
    How to avoid this bug?
    Kindly help me out....
    Regards
    Pavan

    hi after the for all entries statement did you used the read statement .
    if not you will not get any data ..check this program..
    tables:mara,marc.
    data:begin of itab occurs 0,
         matnr like mara-matnr,
         end of itab.
    data:begin of itab1 occurs 0,
         matnr like marc-matnr,
         werks like marc-werks,
         end of itab1.
    select   matnr
          from mara
          into corresponding fields of  table itab.
          if   itab is initial.
          select  matnr
                  werks
                 from marc
                 into  table itab1
                 for all entries in itab
                 where matnr = itab-matnr.
                 loop at itab1.
                 read table itab with key matnr = itab-matnr.
                 write:/ itab1-matnr,itab1-werks.
                 endloop.
                 endif.

Maybe you are looking for

  • How do I remove an older itunes password from my iphone and begin using my up to date one?

    I have rebooted phone...took out old itunes from computer downloaded new one, got new user ID (apple)and when I click update on my iphone itunes, it still is showing the old apple ID username?

  • A New Year, a New Challenge! Become the FIRST BizTalk Guru of 2015!

    Happy New Year! "Guru 2014" is so last year! The real glory is to be the first Guru of 2015! :D The birth of a new year, and a new hero? Or the stamp of authority from long established Guru leaders? The challenge is on, all eyes are watching, anyone

  • Is it possible to transfer a catalog from PSE4 to PSE11?

    I am having difficulties in transferring my catalog from PSE4, on my old PC, to PSE11 on my new one. The main problem relates to the position of captions in images in full screen mode. In an online chat yesterday with an Adobe Technical Support guy,

  • Sys Tables In Stored Procedure

    How can I use Sys Table in Stored Procedure. I want to use DBA_TAB_COLOUMNS, in stored procedure. When I used this table in stored procedure I got an error ORA - 00942 Table or View Does not exists. Thanks, Ahamed

  • 11g Release 2 install missing packages

    Hi, I'm trying to install 11g Release 2 on a CentOS (4.9) box, but the pre-req check shows that I'm missing the following packages (I had 9 to begin): gcc-3.4.6 (X86_64) gcc-c++-3.4.6(X86_64) libstdc++-devel-3.4.6 Tried to use the yum command "yum in