Using for all entries of two internal tables in where clause of the select

Hi experts,
My requirement is, need to select Marc-minbe and wrpl-sobst, for all the entries of the two internal tables it_mara , and it_t001w.
here is the select queries i have used,
select matnr normt from  mara into it_mara for all entries in it_data where normt = it_data-normt.
select konnr werks from t001w into it_t001w for all entries in it_data where konnr = it_data-konnr.
now i need to select minbe of marc table and sobse of wrpl table for all the entries of above internal tables, it_mara and it_t001w, using both matnr of it_mara and werks of it_t001w in where condition.
Pls advise how i can do it.
Thanks.
Moderator message: very basic, please work on this yourself first, these forums are not a substitute for ABAP training.
Edited by: Thomas Zloch on Dec 6, 2010 9:38 AM

Hi
call SE16 with table TFTIT in order to get a full list (it will be long...)
A list of FMs with parameters can be found in table FUNCT.
Finally go to sm37rsdf4
that will give you all the function modules with description
Here is the list:
http://www.erpgenie.com/abap/functions.htm
hope this helps...
Regards
CSM Reddy

Similar Messages

  • Extract Cube data for all entries of an internal table

    Hi
    I want to fetch the data from the cube for all entries of another internal table.
    Scenario : Fetching the COMPANY_CODE and DATE into an internal table and for those company codes and Dates, I have to fetch the records of the Cube.,
    I am using the Function Module : RSDRI_INFOPROV_READ
    But not sure how to accommodate the multiple selections condition for this.
    Selection Required:
                                    *For all entries of it_cc
                                      where comp_code = it_cc-comp_code and
                                                  date = it_cc-date.*
    Please help me how to such multiple conditions and "for all entries" functionality for fetching the data from the cube.
    Thanks.
    Veera Karthik G

    HI
    You can try like this
    LOOP AT lt_donotcall_old .
    <ls_donotcall>-examination_date = sy-date.
    <ls_donotcall>-examination_time = sy-time.
    ENDLOOP.
    append it_donotcall_old.
    Reward all helpfull answers
    Regards
    Pavan

  • 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

  • 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

  • Advice required on a select statement using "FOR ALL ENTRIES"

    Hi,
    this is really intresting ...
    I have a small requirement where in i have to find out
    the valid entries in my internal table (T_MATNR) by using a select statement to a check table (MARA) which has all the fields present in the internal table T_MATNR.
    Select statement is
    SELECT MATNR
           MTART
           from MARA
           for all entries in T_MATNR
           into table T_MATNR
           where matnr eq T_MATNR-MATNR.
    If you observe the itab in the option 'FOR ALL ENTRIES' and the destination table is the same. I want to know whether this is correct? will it cause any performance issue? right now this statement is working fine for me.

    Hi,
    U have to use
    SELECT MATNR
    MTART
    from MARA
    <b>into table I_MATNR(different table)</b>
    for all entries in T_MATNR
    where matnr eq T_MATNR-MATNR.
    If u r specifying both same table name then for what entries it will retrieve, if u have alreay selected some entries and appending u can use
    SELECT MATNR
    MTART
    from MARA
    <b>into table T_MATNR</b>where matnr eq T_MATNR-MATNR.
    then
    SELECT MATNR
    MTART
    from MARA
    <b>appending table T_MATNR</b>
    for all entries in T_MATNR
    where matnr eq T_MATNR-MATNR.
    In this way u can do.
    Hope u got it.

  • Left outer join using For All Entries

    how to implement left outer join using for all entries In REPORTS.

    hi Mansi,
    this is how i populate
    SELECT VGBEL LFIMG POSNR VBELN FROM LIPS INTO  TABLE IT_delv  FOR ALL ENTRIES IN IT_VBAP WHERE VGBEL = IT_VBAP-VBELN.
    LOOP AT IT_delv INTO WA_delv.
    WA_FINAL-VBELN_1 = WA_DELV-VBELN_1.
    WA_FINAL-LFDAT =   WA_DELV-LFDAT.
    WA_FINAL-LFIMG   = WA_DELV-LFIMG.
    WA_FINAL-POSNR2 =   WA_DELV-POSNR2..
    APPEND WA_FINAL TO IT_FINAL.
    CLEAR: WA_FINAL , WA_delv.
    ENDLOOP.
    LOOP AT IT_FINAL INTO WA_FINAL.
    READ TABLE IT_vbap INTO WA_vbap WITH KEY VGBEL = WA_FINAL-VBELN.
      WA_FINAL-VBELN = WA_VBAP-VBELN.
    WA_FINAL-MATNR = WA_VBAP-MATNR.
    WA_FINAL-KWMENG = WA_VBAP-KWMENG.
    WA_FINAL-NETWR = WA_VBAP-NETWR.
    MODIFY IT_FINAL FROM WA_FINAL.
    ENDLOOP.
    My question is , it_vbap has 5 five records A,B,C,D,E.
    in it_delv ,there are 20 record corrresponding to A,B,D of IT_VBAP.
    in final table i wont get info of recors B,E. I want those info also in final table ..how can i do that...

  • Is it not recommended to use FOR ALL ENTRIES in version 4.5B

    Hi,
    Is it not recommended to used For all entries in version 4.5B as  Size limit for SQL is 32KB hence we should not be using FOR ALL ENTRIES, instead of this we should be using select inside the loop?
    Can anyone please let me know if this is correct and if you can provide me the SAP documentation on the specific statement.
    Regards
    Ria

    Hi Ria,
    From what I understand, you cannot use JOINS with FOR ALL ENTRIES in 4.5b & lower versions. In general the SELECT..FOR ALL ENTRIES statement has been in use from 3.1i versions. For more information, PL take a look at OSS Note #652634.
    Regards,
    Suresh Datti

  • Populating Empty Fields for Existing Internal Table Using For All Entries

    I have an internal table called itab_extract that populates without any issues in SELECT A and SELECT B below. Trying to avoid looping, I am using select DB table 'for all entries' in itab_extract. I want the empty fields in itab_extract to populate from the values in the database. However, about 200,000 entries are being appended to the table, and, the values that existed for the already populated fields in itab_extract are gone, and the new fields are populated.
    I've played with the syntax and cannot seem to get it to work. My next option is a time consuming loop.
    How should the for all entries syntax look to accomplish filling the empty fields in the itab?   Thank-You
    *read ekko
        select ebeln lifnr aedat bsart from ekko                                                     *SELECT A*
               into  CORRESPONDING FIELDS OF TABLE me->itab_extract
               where aedat in r_aedat.
        select ebeln lifnr aedat BSART from ekko                                                  *SELECT B*
               appending CORRESPONDING FIELDS OF TABLE me->itab_extract
               where aedat in S_DATE2 AND
                     BSART IN S_BSART.
          select ebelp werks matnr                                                                           *SELECT C*
            into CORRESPONDING FIELDS OF TABLE itab_extract
            from ekpo
            FOR ALL ENTRIES IN itab_extract
            where ebeln = itab_extract-ebeln.

    Hi Tom,
               This SQL statement will be time consuming, Do not use a loop.
    There are two options.
    1. Select EKKO and EKPO details based on standard SAP view. (You can type EKKO in se11 view to find the correct view).
        also use one range table populate r_aedat and s_date2 in the same. So you where condition will have r_newrange and   
        s_bsart. Also do not use into corresponding fields, it is not a good idea. It will increase your performance. Maintain the proper 
        sequence (Based on database structure of EKKO and EKPO)
    2. If you are keen to use for all entries, then first select ekko then after your sy-subrc check get the data from EKPO.
    Should be like this.
    select ebeln bsart aedat lifnr from ekko into table gt_ekko where aedat in r_newrange and bsart in s_bsart.
    if sy-subrc eq 0.
    sort gt_ekko by ebeln ascending.
    select ebeln ebelp werks matnr  into table gt_ekpo for all entries in gt_ekko where ebeln eq gt_ekko-ebeln.
    endif.
    Hope it helps,
    Best Regards,
    Tapodipta Khan.

  • I have a problem in using  for all entries

    Hi i have a problem in using <b>for all entries</b>
    i have declared the two internal tables as below
      DATA: BEGIN OF ITAB OCCURS 10,
              EBELN LIKE EKKO-EBELN,
              LIFNR LIKE EKKO-LIFNR,
              EBELP LIKE EKBE-EBELP,
              BELNR LIKE EKBE-BELNR,
    *          MATNR LIKE EKPO-MATNR,
    *          TXZ01 LIKE EKPO-TXZ01,
              VGABE LIKE EKBE-VGABE,
              GJAHR LIKE EKBE-GJAHR,
              KNUMV LIKE EKKO-KNUMV,
         END OF ITAB.
    DATA: BEGIN OF ITAB1 OCCURS 10,
              EBELN LIKE EKPO-EBELN,
              MATNR LIKE EKPO-MATNR,
              TXZ01 LIKE EKPO-TXZ01,
              WERKS LIKE EKPO-WERKS,
              NETWR LIKE EKPO-NETWR,
              MENGE LIKE EKPO-MENGE,
              MWSKZ LIKE EKPO-MWSKZ,
              LIFNR LIKE EKKO-LIFNR,
              EBELP LIKE EKBE-EBELP,
              BELNR LIKE EKBE-BELNR,
          END OF ITAB1.
    <b>and now i have tried to move the values in those internal tables using these statements</b>
       SELECT  A~EBELN A~LIFNR A~KNUMV B~VGABE B~EBELP B~GJAHR B~BELNR
            FROM  EKKO AS A
            INNER JOIN EKBE  AS B ON  B~EBELN = A~EBELN
            INTO  CORRESPONDING
            FIELDS OF TABLE ITAB WHERE B~VGABE = '2'.
       SELECT EKPO~EBELN EKPO~MATNR EKPO~TXZ01 EKPO~WERKS EKPO~NETWR
              EKPO~MENGE EKPO~MWSKZ
          FROM EKPO
          INTO CORRESPONDING FIELDS OF TABLE ITAB1
          FOR ALL ENTRIES IN ITAB
          WHERE EBELN = ITAB-EBELN.
          LOOP AT ITAB1.
           READ TABLE ITAB WITH KEY EBELN = ITAB-EBELN.
           ITAB-EBELN = ITAB1-EBELN.
           ITAB1-LIFNR = ITAB-LIFNR.
           ITAB1-EBELP = ITAB-EBELP.
           ITAB1-BELNR = ITAB-BELNR.
           ITAB1-EBELP = ITAB-EBELP.
           APPEND ITAB1.
          ENDLOOP.
    But when i was using loop then it was displaying values in debugging mode but while i was trying to execute it was taking a lot of time i thought that it was due to more information in the already declared internal table so i have tried to remove the previous entries but it was showing an error while i was removing the old entries
    and when i  remove the loop at itab1 then i'll get output directly but it was displaying the itab fields which is my 1st internal table but not the values of itab1 can u explain me what is the possible error for that
    Regards ,
    Pavan

    before using for all entries in, u need to check whether the driver internal table is empty, if it is empty, u should not enter into select statement.
    if u wont use this check means, when the driver internal table is empty, the second select will take all the entires from the tables.
    SELECT  AEBELN ALIFNR AKNUMV BVGABE BEBELP BGJAHR B~BELNR
            FROM  EKKO AS A
            INNER JOIN EKBE  AS B ON  BEBELN = AEBELN
            INTO  CORRESPONDING
            FIELDS OF TABLE ITAB WHERE B~VGABE = '2'.
    if itab[] is not initial.
       SELECT EKPOEBELN EKPOMATNR EKPOTXZ01 EKPOWERKS EKPO~NETWR
              EKPOMENGE EKPOMWSKZ
          FROM EKPO
          INTO CORRESPONDING FIELDS OF TABLE ITAB1
          FOR ALL ENTRIES IN ITAB
          WHERE EBELN = ITAB-EBELN.
    endif.
    I hope this will help u.
    else,
    Sujatha.

  • Develop alv using for all entries

    Develop an Sales Document ALV Report .   
         Select the mentioned field from two tables using FOR ALL ENTRIES , display the output in ALV Format.
    Table Name 1     KNA1     General Data in Customer Master
    Fields     KUNNR     
         LAND1     
         ERDAT     
         NAME1     
         ORT01     
         PSTLZ
    Table Name 2     VBAK     Sales Document: Header Data
    Fields     VBELN     
         AUDAT     
         VBTYP     
         TRVOG     
         AUART     
    ALV O / P Format Fields     KUNNR     from KNA1 Table
         LAND1     from KNA1 Table
         ERDAT     from KNA1 Table
         NAME1     from KNA1 Table
         ORT01     from KNA1 Table
         PSTLZ     from KNA1 Table
         VBELN     from VBAK Table
         AUDAT     from VBAK Table
         VBTYP     from VBAK Table
         TRVOG     from VBAK Table
         AUART     from VBAK Table
    Moderator Message: This is not a training forum. Please refrain from using it as one.
    Edited by: kishan P on Jun 6, 2011 2:23 PM

    FOA is for passing one internal table to select statement..
    Press F1 on it, it will give you the details.
    if you really want to pass more than one tables, you can use range tables.. just similar to what we do in case of select-options..
    as in
    select x y z from dbtab
                         where x in s_x
                                  y in s_y.
    hope you understand..

  • Duplicate entries missing using for all entries in select query.

    Hi Gurus,
    Is there any way to avoid missing duplicate entries in an internal table if you use for all entries in select statement?
    Note : i am selecting two tables using non key fields and i have to aggregate the data. I want only 2 data fields and one amount field in my final internal table. I can add all the primary key fields into my internal table and collect my required fields in another table, but  I just want to know is there any other way to avoid missing duplicate entries without adding all the key fields?
    Regards,
    Raghavendra

    Hi,
    Just check what are the other possible fields in the table which may be having
    duplicate entries and make use of them in the selection accordingly.
    You may not miss any entries unless there is any restriction on them.
    You can better judge that in debugging mode while selecting data from that table.

  • What is the condition for using 'for all entries' and  why?

    what is the condition for using 'for all entries' and  why? can any body tell the reason for this ? its a big favour of me .
    regards,
    ravi.

    hi,
    for all entries is used to join two or more tables.
    It is same as join but performance wise for all entries is more effective.
    You can only use FOR ALL ENTRIES IN ...WHERE ...in a SELECT statement.
    SELECT ... FOR ALL ENTRIES IN itab WHERE cond returns the union of the solution sets of all SELECT
    statements that would result if you wrote a separate statement for each line of the internal table replacing the symbol
    itab-f with the corresponding value of component f in the WHERE condition.Duplicates are discarded from the result
    set. If the internal table itab does not contain any entries, the system treats the statement as though there were
    no WHERE cond condition, and selects all records (in the current client).
    for example:
    SELECT * FROM sflight INTO wa_sflight
    FOR ALL ENTRIES IN ftab
    WHERE CARRID = ftab-carrid AND
    CONNID = ftab-connid AND
    fldate = '20010228'.
    this condition, return all entries of the sflight
    hen using FOR ALL ENTRIES the number of matching records is restricted to the number of records in the internal table. If the number of records in the database tables is too large then join would cause overheads in performance. Additionally a JOIN bypasses the table buffering.
    So for all entries is used for filtering out the data from the two tables based on the entries in them.
    Advantages:
    1) For all entries avoids inner join & so the performance increases.
    2) For specified values in 1 itab, if you to fetch values from other table you can use it.
    3) Use of select stmt in loop is gets avoided, as u can use read statement on the the new itab.

  • SD Flow program using For all entries.

    using simple ALV grid: I have the urgent requirement of changing the following program using 'For all entries' instead of joins and I should not use 'TABLES' -- For top-of-page I need to get dynamic fields like if I select company code in the selection screen then I need to get 'This report is base on COMPANY CODE'.
    This program is about sales flow where i shud get only those records that have ebeln in vbak, delivery, invoice.
    The original program is as follows:
    *& Report  ZSD_DOCU_FLOW                                               *
    REPORT  zsd_docu_flow  NO STANDARD PAGE HEADING                    .
    * Program     : ZCOS_SALES                                           *
    * Dev. Class  :  ZSD
    * Functional  :
    * Created on  :                                                        *
    * Project     :
    * CR Number   :
    * Transaction :  ZSDCSUT                                               *
    * Description :   * Sales document life cylce for given customer
    *                  to declaired period displaying the sales document
    *                  details ,with relevant del details and corresponding
    *                  Invocie Details
    *-----------     Tables Declaration      -----------*
    TABLES: vbak,vbap,vbfa,kna1,vbrk,vbrp,likp,lips,t001.
    TYPE-POOLS : slis.
    *-----------    Internal Tables Declaration      -----------*
    *      Internal Table for Sales Order data                   *
    DATA: BEGIN OF it_so OCCURS 0,
            vbeln LIKE vbak-vbeln,
            kunnr LIKE vbak-kunnr,
            posnr LIKE vbap-posnr,
            matnr LIKE vbap-matnr,
            kwmeng LIKE vbap-kwmeng,
            netwr LIKE vbap-netwr,
         END OF it_so.
    *      Internal Table for Delivery Order data                   *
    DATA: BEGIN OF it_del OCCURS 0,
            delnum  LIKE likp-vbeln,
            lfdat LIKE likp-lfdat,
            delitem LIKE lips-posnr,
            lfimg LIKE lips-lfimg,
          END OF it_del.
    *      Internal Table for Invoice data                          *
    DATA: BEGIN OF  it_inv OCCURS 0,
            invnum LIKE vbrk-vbeln,
            invitem LIKE vbrp-posnr,
            fkimg LIKE vbrp-fkimg,
            amount LIKE vbrp-netwr,
         END OF it_inv.
    *      Internal Table for Final data                            *
    DATA: BEGIN OF it_final OCCURS 0,
            vbeln LIKE vbak-vbeln,
            posnr LIKE vbap-posnr,
            kunnr LIKE vbak-kunnr,
            name LIKE kna1-name1,
            matnr LIKE vbap-matnr,
            kwmeng LIKE vbap-kwmeng,
            netwr LIKE vbap-netwr,
            delnum  LIKE likp-vbeln,
            lfdat LIKE likp-lfdat,
            delitem LIKE lips-posnr,
            lfimg LIKE lips-lfimg,
            invnum LIKE vbrk-vbeln,
            invitem LIKE vbrp-posnr,
            fkimg LIKE vbrp-fkimg,
            amount LIKE vbrp-netwr,
         END OF it_final.
    *-----------    Variables Declaration      -----------*
    DATA: v_name LIKE kna1-kunnr," variable for customer name
          v_delnum LIKE likp-vbeln," variable for delivery number
          v_invnum LIKE vbrk-vbeln." variable for invoce number
    DATA : ls_layout TYPE slis_layout_alv,
           it_fcat TYPE slis_t_fieldcat_alv ,
           wa_fcat TYPE slis_fieldcat_alv,
           lh TYPE slis_t_listheader,
           ls TYPE slis_listheader,
           it_events TYPE slis_t_event  ,
           ls_event TYPE slis_alv_event ,
           i_sort     TYPE slis_t_sortinfo_alv,
           w_var TYPE i.
    DATA : l_date(10).
    DATA : l_date1(20).
    DATA : l_repid LIKE trdir-name.
    l_repid = 'ZSD_DOCU_FLOW1'.
    *-----------    Select-options & parameters Declaration  ---*
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    PARAMETERS: p_bukrs LIKE vbak-bukrs_vf,
                 p_vkorg LIKE vbak-vkorg,
                p_vtweg LIKE vbak-vtweg,
                p_spart LIKE vbak-spart.
    SELECT-OPTIONS: s_kunnr FOR vbak-kunnr,
                    s_audat FOR vbak-audat.
    SELECTION-SCREEN END OF BLOCK b1.
    *----------- AT SELECTION-SCREEN  --------------------------*
    AT SELECTION-SCREEN.
      SELECT SINGLE * FROM  t001 INTO t001
                                WHERE bukrs = p_bukrs.
      IF sy-subrc <> 0.
        MESSAGE e000(8i) WITH 'Enter a Valid Company Code'.
      ENDIF.
      SELECT SINGLE * FROM vbak INTO vbak
                              WHERE vkorg = p_vkorg.
      IF sy-subrc <> 0.
        MESSAGE e000(8i) WITH 'Enter a Valid Sales Organization'.
      ENDIF.
      SELECT SINGLE * FROM vbak INTO vbak
                                WHERE vtweg = p_vtweg.
      IF sy-subrc <> 0.
        MESSAGE e000(8i) WITH 'Enter a Valid distribution channel'.
      ENDIF.
      SELECT SINGLE * FROM vbak INTO vbak
                                WHERE spart = p_spart.
      IF sy-subrc <> 0.
        MESSAGE e000(8i) WITH 'Enter a Valid Division'.
      ENDIF.
      SELECT SINGLE * FROM kna1 INTO kna1
                                WHERE kunnr IN s_kunnr.
      IF sy-subrc <> 0.
        MESSAGE e000(8i) WITH 'Enter a Valid Customer Number'.
      ENDIF.
    *----------- START-OF-SELECTION-----------------------------*
    START-OF-SELECTION.
      ls-typ = 'H'.
      ls-info = 'Sales Document Flow'.
      APPEND ls TO lh.
      ls-typ = 'S'.
      WRITE: sy-datum TO l_date USING EDIT MASK '__/__/____'.
      CONCATENATE 'DATE :' l_date INTO l_date1 SEPARATED BY space.
      ls-info = l_date1.
      APPEND ls TO lh.
      PERFORM field_cat.
      PERFORM t_sort_build USING i_sort.
      PERFORM get-data.
    *----------- END-OF-SELECTION-----------------------------*
    END-OF-SELECTION.
    IF it_final[] IS INITIAL.
        MESSAGE i000(8i) WITH 'No data Found'.
        EXIT.
      ENDIF.
    PERFORM print-data.
    *&      Form  get-data
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM get-data .
    *  Accesing Sales Data
      SELECT a~vbeln a~kunnr b~posnr b~matnr b~kwmeng b~netwr
       INTO CORRESPONDING FIELDS OF TABLE it_so
       FROM vbak AS a INNER JOIN vbap AS b
                             ON a~vbeln = b~vbeln
                              WHERE a~bukrs_vf = p_bukrs
                                 AND a~vkorg = p_vkorg
                                 AND  a~vtweg = p_vtweg
                                    AND a~spart = p_spart
                                     AND a~kunnr IN s_kunnr
                                          AND a~audat IN s_audat.
      LOOP AT it_so.
        SELECT SINGLE name1 FROM kna1 INTO v_name
                                         WHERE kunnr = it_so-kunnr.
        SELECT SINGLE vbeln FROM vbfa INTO v_delnum
                                          WHERE vbelv = it_so-vbeln
                                            AND  vbtyp_n = 'J'.
        IF sy-subrc = 0.
          SELECT SINGLE  vbeln FROM vbfa INTO v_invnum
                                WHERE vbelv = v_delnum
                                  AND  vbtyp_n = 'M'.
        ENDIF.
        MOVE-CORRESPONDING it_so TO it_final.
        it_final-name = v_name.
        it_final-delnum = v_delnum.
        it_final-invnum = v_invnum.
        APPEND it_final.
        CLEAR it_final.
        CLEAR v_delnum.
        CLEAR v_invnum.
      ENDLOOP.
      LOOP AT it_final.
        IF it_final-delnum NE ' '.
    * Reading Del Data.
          SELECT SINGLE  a~vbeln  a~lfdat b~posnr b~lfimg   INTO
                    (it_del-delnum, it_del-lfdat, it_del-delitem,
                     it_del-lfimg ) FROM
                        likp AS a INNER JOIN lips AS b ON a~vbeln = b~vbeln
                                   WHERE a~vbeln = it_final-delnum
                                   AND b~posnr = it_final-posnr.
          MOVE-CORRESPONDING it_del TO it_final.
          MODIFY it_final.
        ENDIF.
        IF it_final-invnum NE ' '.
    * Reading Invoice Data.
          SELECT SINGLE vbeln posnr fkimg netwr INTO
         (it_inv-invnum, it_inv-invitem, it_inv-fkimg, it_inv-amount )
                       FROM vbrp  WHERE vbeln = it_final-invnum
                                  AND   posnr = it_final-posnr.
          MOVE-CORRESPONDING it_inv TO it_final.
          MODIFY it_final.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " get-data
    *&      Form  print-data
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM print-data .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
    *     I_INTERFACE_CHECK                 = ' '
    *     I_BYPASSING_BUFFER                = ' '
    *     I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = l_repid
    *     I_CALLBACK_PF_STATUS_SET          = ' '
    *     I_CALLBACK_USER_COMMAND           = ' '
         i_callback_top_of_page            = 'TOP'
    *     I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    *     I_CALLBACK_HTML_END_OF_LIST       = ' '
    *     I_STRUCTURE_NAME                  =
    *     I_BACKGROUND_ID                   = ' '
    *     I_GRID_TITLE                      =
    *     I_GRID_SETTINGS                   =
    *     IS_LAYOUT                         =
         it_fieldcat                       = it_fcat
    *     IT_EXCLUDING                      =
    *     IT_SPECIAL_GROUPS                 =
         IT_SORT                           = i_sort[]
    *     IT_FILTER                         =
    *     IS_SEL_HIDE                       =
    *     I_DEFAULT                         = 'X'
    *     I_SAVE                            = ' '
    *     IS_VARIANT                        =
    *     IT_EVENTS                         =
    *     IT_EVENT_EXIT                     =
    *     IS_PRINT                          =
    *     IS_REPREP_ID                      =
    *     I_SCREEN_START_COLUMN             = 0
    *     I_SCREEN_START_LINE               = 0
    *     I_SCREEN_END_COLUMN               = 0
    *     I_SCREEN_END_LINE                 = 0
    *     IT_ALV_GRAPHICS                   =
    *     IT_HYPERLINK                      =
    *     IT_ADD_FIELDCAT                   =
    *     IT_EXCEPT_QINFO                   =
    *     I_HTML_HEIGHT_TOP                 =
    *     I_HTML_HEIGHT_END                 =
    *   IMPORTING
    *     E_EXIT_CAUSED_BY_CALLER           =
    *     ES_EXIT_CAUSED_BY_USER            =
        TABLES
          t_outtab                          = it_final.
    *   EXCEPTIONS
    *     PROGRAM_ERROR                     = 1
    *     OTHERS                            = 2
    *  IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *  ENDIF.
    ENDFORM.                    " print-data
    *&      Form  field_cat
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM field_cat .
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'VBELN'.
      wa_fcat-key = 'X'.
      wa_fcat-ref_fieldname = 'VBELN'.
      wa_fcat-ref_tabname = 'VBAK'.
      wa_fcat-seltext_m = 'Sales Order NO'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'POSNR'.
      wa_fcat-ref_fieldname = 'POSNR'.
      wa_fcat-ref_tabname = 'VBAP'.
      wa_fcat-seltext_m = 'SalesItemNO'.
      wa_fcat-fix_column = 'X'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'KUNNR'.
      wa_fcat-seltext_m = 'CUSTNUM'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'NAME'.
      wa_fcat-seltext_m = 'CUSTNAME'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'MATNR'.
      wa_fcat-seltext_m = 'MATNUM'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'KWMENG'.
      wa_fcat-seltext_m = 'Sales Quantity'.
      wa_fcat-do_sum = 'X'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'NETWR'.
      wa_fcat-seltext_m = 'Value'.
      wa_fcat-do_sum = 'X'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'DELNUM'.
      wa_fcat-seltext_m = 'DeloveryNum'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'DELITEM'.
      wa_fcat-seltext_m = 'DelItemNO'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'LFDAT'.
      wa_fcat-seltext_m = 'DelDate'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'LFIMG'.
      wa_fcat-seltext_m = 'DelQuantity'.
      wa_fcat-do_sum = 'X'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'INVNUM'.
      wa_fcat-seltext_m = 'InvoiceNum'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'INVITEM'.
      wa_fcat-seltext_m = 'InvoiceItem'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'FKIMG'.
      wa_fcat-seltext_m = 'INVQuantity'.
      wa_fcat-do_sum = 'X'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
      wa_fcat-col_pos = w_var.
      wa_fcat-tabname = 'IT_FINAL'.
      wa_fcat-fieldname = 'AMOUNT'.
      wa_fcat-seltext_m = 'INVvalue'.
      wa_fcat-do_sum = 'X'.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
      ADD 1 TO w_var.
    ENDFORM.     " field_cat
    *&      Form  top
    *       text
    FORM t_sort_build USING l_sort TYPE slis_t_sortinfo_alv.
      DATA: ls_sort TYPE slis_sortinfo_alv.
      ls_sort-fieldname = 'VBELN'.
      ls_sort-spos      = 1.
      ls_sort-up        = 'X'.
      ls_sort-subtot    = 'X'.
      APPEND ls_sort TO l_sort.
      ls_sort-fieldname = 'KUNNR'.
      ls_sort-spos      = 2.
      ls_sort-up        = 'X'.
      APPEND ls_sort TO l_sort.
    ENDFORM.                    "t_sort_bui
    FORM top.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary       = lh
    *   I_LOGO                   =
    *   I_END_OF_LIST_GRID       =
    ENDFORM.                    "TOP
    ===========================================================================
    I have started the new program but i have trouble with the final internal table. Since i'm using For all entries I have declared internal tables for each table. My incomplete new program is as follows(not sure if the logic is correct till what I have coded):
    *& Report  Z_SDFLOW                                                    *
    REPORT  Z_SDFLOW  NO STANDARD PAGE HEADING.
    ********* TABLES TO BE USED ***********************
    **** VBAK - SALES DOCUMENT HEADER
    * VBAP - SALES ITEM
    * VBFA - SALES DOCUMENT FLOW
    * KNA1- CUSTOMER MASTER
    * VBRK - BILLING DOCUMENT HEADER
    * VBRP - BLLING DOCUMENT ITEM
    * LIKP - DELIVERY HEADER
    * LIPS - DELIVERY ITEM
    * TOO1 - COMPANY CODES
    * SLIS.
    TYPE-POOLS: SLIS.
    ** STRUCTURE DECLARATIONS ********
    **STRUCTURE FOR ENQUIRY.
    **STRUCTURE FOR QUOTATION.
    **STRUCTURE FOR SALES ORDER HEADER- VBAK.
    TYPES: BEGIN OF XT_VBAK,
    VBELN TYPE VBAK-VBELN,     "SALES DOCUMENT NUMBER
    KUNNR TYPE VBAK-KUNNR,     " SOLD-TO-PARTY
    END OF XT_VBAK.
    **STRUCTURE FOR SALES ORDER  ITEM-VBAP
    TYPES: BEGIN OF XT_VBAP,
    POSNR TYPE VBAP-POSNR,     " SALES ITEM NUMBER
    MATNR TYPE VBAP-MATNR,     " MATERIAL NUMBER
    KWMENG TYPE VBAP-KWMENG,   " CUMMULATIVE ORDER QUANTITY IN SALES UNITS
    NETWR TYPE VBAP-NETWR,     " NET VALUE OF THE ORDER ITEM
    END OF XT_VBAP.
    ** STRUCTURE FOR DELIVERY HEADER -LIKP
    TYPES: BEGIN OF XT_LIKP,
    DELVBELN TYPE LIKP-VBELN,           "DELIVERY DOCUMENT NUMBER
    LFDAT TYPE LIKP-LFDAT,           " DELIVERY DATE
    END OF XT_LIKP.
    **STRUCTURE FOR DELIVERY ITEM - LIPS
    TYPES: BEGIN OF XT_LIPS,
    DELPOSNR TYPE LIPS-POSNR,           " DELIVERY ITEM NUMBER
    LFIMG TYPE LIPS-LFIMG,           " ACTUAL QUANTITY DELIVERED
    END OF XT_LIPS.
    **STRUCTURE FOR BILLING DOCUMENT HEADER -VBRK
    TYPES: BEGIN OF XT_VBRK,
    INVVBELN TYPE VBRK-VBELN,          "BILLING DOCUMENT NUMBER
    END OF XT_VBRK.
    **STRUCTURE FOR BILLING DOCUMENT ITEM - VBRP
    TYPES: BEGIN OF XT_VBRP,
    INVPOSNR TYPE VBRP-POSNR,          "BILLING ITEM NUMBER
    FKIMG TYPE VBRP-FKIMG,          "ACTUAL INVOICED QUANTITY
    INVNETWR TYPE VBRP-NETWR,          "NET VALUE OF THE BILLING ITEM
    END OF XT_VBRP.
    **STRUCTURE FOR FINAL INTERNAL TABLE.
    TYPES: BEGIN OF XT_FINAL,
    VBELN TYPE VBAK-VBELN,
    DELVBELN TYPE LIKP-VBELN,
    INVBELN TYPE VBRK-VBELN,
    KUNNR TYPE VBAK-KUNNR,
    POSNR TYPE VBAP-POSNR,
    DELPOSNT TYPE LIPS-POSNR,
    INVPOSNR TYPE VBRP-POSNR,
    MATNR TYPE VBAP-MATNR,
    KWMENG TYPE VBAP-KWMENG,
    NETWR TYPE VBAP-NETWR,
    INVNETWR TYPE VBRP-NETWR,
    LFDAT TYPE LIKP-LFDAT,
    LFIMG TYPE LIPS-LFIMG,
    FKIMG TYPE VBRP-FKIMG,
    NAME1 TYPE KNA1-NAME1,
    END OF XT_FINAL.
    **DATA DECLARATIONS
    DATA: V_NAME1 TYPE KNA1-NAME1,  "#EC *
          V_DELVBELN TYPE LIKP-VBELN,
          V_INVVBELN TYPE VBRK-VBELN,
          V_BUKRS TYPE T001-BUKRS,    "COMPANY CODE "#EC *
          V_AUDAT TYPE VBAK-AUDAT,
          V_VKORG TYPE VBAK-VKORG,
          V_VKGRP TYPE VBAK-VKGRP,
          V_SPART TYPE VBAK-SPART.
    **INTERNAL TABLE DECLARATIONS
    DATA: IT_VBAK TYPE STANDARD TABLE OF XT_VBAK,
          WA_VBAK TYPE XT_VBAK,
          IT_VBAP TYPE STANDARD TABLE OF XT_VBAP,
          WA_VBAP TYPE XT_VBAP,
          IT_LIKP TYPE STANDARD TABLE OF XT_LIKP,
          WA_LIKP TYPE XT_LIKP,
          IT_LIPS TYPE STANDARD TABLE OF XT_LIPS,
          WA_LIPS TYPE XT_LIPS,
          IT_VBRK TYPE STANDARD TABLE OF XT_VBRK,
          WA_VBRK TYPE XT_VBRK,
          IT_VBRP TYPE STANDARD TABLE OF XT_VBRP,
          WA_VBRP TYPE XT_VBRP,
          IT_FINAL TYPE STANDARD TABLE OF XT_FINAL,
          WA_FINAL TYPE XT_FINAL.
    **ALV DECLARATIONS
    DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
          WA_FLDCAT TYPE SLIS_FIELDCAT_ALV,
          IT_LSTHDR TYPE SLIS_T_LISTHEADER,
          WA_LSTHDR TYPE SLIS_LISTHEADER,
          IT_EVENTS TYPE SLIS_T_EVENT,
          WA_EVENTS TYPE SLIS_ALV_EVENT,
          IT_SORT TYPE SLIS_T_SORTINFO_ALV,
          IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: S_BUKRS FOR V_BUKRS NO INTERVALS NO-EXTENSION,
                    S_VBELN FOR WA_VBAK-VBELN,  "SALES DOCUMENT NUMBER
                    S_KUNNR FOR WA_VBAK-KUNNR,  "SOLD-TO-PARTY
                    S_AUDAT FOR V_AUDAT,      "SALES DOCUMENT DATE
                    S_VKORG FOR V_VKORG,      "SALES ORGANISATION
                    S_VKGRP FOR V_VKGRP,      "SALES GROUP
                    S_SPART FOR V_SPART.      "DIVISION
    SELECTION-SCREEN END OF BLOCK b1.
    *****************SCREEN VALIDATION***************
    AT SELECTION-SCREEN.
    SELECT SINGLE BUKRS FROM T001 INTO V_BUKRS WHERE BUKRS IN S_BUKRS."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID COMPANY CODE'.
    ENDIF.
    SELECT SINGLE VBELN FROM VBAK INTO
              CORRESPONDING FIELDS OF WA_VBAK WHERE VBELN IN S_VBELN.
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER VALID SALES DOCUMENT NUMBER'.
    ENDIF.
    SELECT SINGLE KUNNR FROM VBAK INTO
              CORRESPONDING FIELDS OF WA_VBAK WHERE KUNNR IN S_KUNNR. "EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID CUSTOMER NUMBER'.
    ENDIF.
    SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE AUDAT IN S_AUDAT."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DOCUMENT DATE'.
    ENDIF.
    SELECT SINGLE VKORG FROM VBAK INTO V_VKORG WHERE VKORG IN S_VKORG."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES ORGANISATION'.
    ENDIF.
    SELECT SINGLE VKGRP FROM VBAK INTO V_VKGRP WHERE VKGRP IN S_VKGRP."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES GROUP'.
    ENDIF.
    SELECT SINGLE SPART FROM VBAK INTO V_SPART WHERE SPART IN S_SPART."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DIVISION'.
    ENDIF.
    PERFORM GET_DATA.
    *&      Form  GET_DATA
    FORM GET_DATA .
    SELECT VBELN KUNNR
            INTO TABLE IT_VBAK
            FROM VBAK
            WHERE VBELN IN S_VBELN.
    *        BUKRS_VF IN S_BUKRS AND
    *        VKORG IN S_VKORG AND
    *        VKGRP IN S_VKGRP AND
    *        SPART IN S_SPART AND
    *        KUNNR IN S_KUNNR AND
    *        AUDAT IN S_AUDAT.
    IF IT_VBAK[] IS NOT INITIAL.
    SELECT POSNR MATNR KWMENG NETWR
            INTO TABLE IT_VBAP
            FROM VBAP
            FOR ALL ENTRIES IN IT_VBAK
            WHERE VBELN = IT_VBAK-VBELN.
    ENDIF.
    IF IT_VBAK[] IS NOT INITIAL.
    SELECT VBELN LFDAT
            INTO TABLE IT_LIKP
            FROM LIKP
            FOR ALL ENTRIES IN IT_VBAK
            WHERE VBELN = IT_VBAK-VBELN.
    ENDIF.
    IF IT_VBAP[] IS NOT INITIAL.
    SELECT POSNR LFIMG
            INTO TABLE IT_LIPS
            FROM LIPS
            FOR ALL ENTRIES IN IT_VBAP
            WHERE POSNR = IT_VBAP-POSNR.
    ENDIF.
    IF IT_LIKP[] IS NOT INITIAL.
    SELECT VBELN
            INTO TABLE IT_VBRK
            FROM VBRK
            FOR ALL ENTRIES IN IT_LIKP
            WHERE VBELN = IT_LIKP-DELVBELN.
    ENDIF.
    IF IT_LIPS[] IS NOT INITIAL.
    SELECT POSNR FKIMG NETWR
            INTO TABLE IT_VBRP
            FROM VBRP
            FOR ALL ENTRIES IN IT_LIPS
            WHERE POSNR = IT_LIPS-DELPOSNR.
    ENDIF.
    ENDFORM.                    " GET_DATA
    Edited by: srk s on Jan 29, 2008 7:33 PM
    Edited by: Alvaro Tejada Galindo on Jan 29, 2008 9:49 AM

    Hi Satish,
    I have started the new program but i have trouble with the final internal table. Since i'm using For all entries, I have declared internal tables for each table. My incomplete new program is as follows(not sure if the logic is correct till what I have coded):
    *& Report  Z_SDFLOW                                                    *
    REPORT  Z_SDFLOW  NO STANDARD PAGE HEADING.
    ********* TABLES TO BE USED ***********************
    **** VBAK - SALES DOCUMENT HEADER
    * VBAP - SALES ITEM
    * VBFA - SALES DOCUMENT FLOW
    * KNA1- CUSTOMER MASTER
    * VBRK - BILLING DOCUMENT HEADER
    * VBRP - BLLING DOCUMENT ITEM
    * LIKP - DELIVERY HEADER
    * LIPS - DELIVERY ITEM
    * TOO1 - COMPANY CODES
    * SLIS.
    TYPE-POOLS: SLIS.
    ** STRUCTURE DECLARATIONS ********
    **STRUCTURE FOR ENQUIRY.
    **STRUCTURE FOR QUOTATION.
    **STRUCTURE FOR SALES ORDER HEADER- VBAK.
    TYPES: BEGIN OF XT_VBAK,
    VBELN TYPE VBAK-VBELN,     "SALES DOCUMENT NUMBER
    KUNNR TYPE VBAK-KUNNR,     " SOLD-TO-PARTY
    END OF XT_VBAK.
    **STRUCTURE FOR SALES ORDER  ITEM-VBAP
    TYPES: BEGIN OF XT_VBAP,
    POSNR TYPE VBAP-POSNR,     " SALES ITEM NUMBER
    MATNR TYPE VBAP-MATNR,     " MATERIAL NUMBER
    KWMENG TYPE VBAP-KWMENG,   " CUMMULATIVE ORDER QUANTITY IN SALES UNITS
    NETWR TYPE VBAP-NETWR,     " NET VALUE OF THE ORDER ITEM
    END OF XT_VBAP.
    ** STRUCTURE FOR DELIVERY HEADER -LIKP
    TYPES: BEGIN OF XT_LIKP,
    DELVBELN TYPE LIKP-VBELN,           "DELIVERY DOCUMENT NUMBER
    LFDAT TYPE LIKP-LFDAT,           " DELIVERY DATE
    END OF XT_LIKP.
    **STRUCTURE FOR DELIVERY ITEM - LIPS
    TYPES: BEGIN OF XT_LIPS,
    DELPOSNR TYPE LIPS-POSNR,           " DELIVERY ITEM NUMBER
    LFIMG TYPE LIPS-LFIMG,           " ACTUAL QUANTITY DELIVERED
    END OF XT_LIPS.
    **STRUCTURE FOR BILLING DOCUMENT HEADER -VBRK
    TYPES: BEGIN OF XT_VBRK,
    INVVBELN TYPE VBRK-VBELN,          "BILLING DOCUMENT NUMBER
    END OF XT_VBRK.
    **STRUCTURE FOR BILLING DOCUMENT ITEM - VBRP
    TYPES: BEGIN OF XT_VBRP,
    INVPOSNR TYPE VBRP-POSNR,          "BILLING ITEM NUMBER
    FKIMG TYPE VBRP-FKIMG,          "ACTUAL INVOICED QUANTITY
    INVNETWR TYPE VBRP-NETWR,          "NET VALUE OF THE BILLING ITEM
    END OF XT_VBRP.
    **STRUCTURE FOR FINAL INTERNAL TABLE.
    TYPES: BEGIN OF XT_FINAL,
    VBELN TYPE VBAK-VBELN,
    DELVBELN TYPE LIKP-VBELN,
    INVBELN TYPE VBRK-VBELN,
    KUNNR TYPE VBAK-KUNNR,
    POSNR TYPE VBAP-POSNR,
    DELPOSNT TYPE LIPS-POSNR,
    INVPOSNR TYPE VBRP-POSNR,
    MATNR TYPE VBAP-MATNR,
    KWMENG TYPE VBAP-KWMENG,
    NETWR TYPE VBAP-NETWR,
    INVNETWR TYPE VBRP-NETWR,
    LFDAT TYPE LIKP-LFDAT,
    LFIMG TYPE LIPS-LFIMG,
    FKIMG TYPE VBRP-FKIMG,
    NAME1 TYPE KNA1-NAME1,
    END OF XT_FINAL.
    **DATA DECLARATIONS
    DATA: V_NAME1 TYPE KNA1-NAME1,  "#EC *
          V_DELVBELN TYPE LIKP-VBELN,
          V_INVVBELN TYPE VBRK-VBELN,
          V_BUKRS TYPE T001-BUKRS,    "COMPANY CODE "#EC *
          V_AUDAT TYPE VBAK-AUDAT,
          V_VKORG TYPE VBAK-VKORG,
          V_VKGRP TYPE VBAK-VKGRP,
          V_SPART TYPE VBAK-SPART.
    **INTERNAL TABLE DECLARATIONS
    DATA: IT_VBAK TYPE STANDARD TABLE OF XT_VBAK,
          WA_VBAK TYPE XT_VBAK,
          IT_VBAP TYPE STANDARD TABLE OF XT_VBAP,
          WA_VBAP TYPE XT_VBAP,
          IT_LIKP TYPE STANDARD TABLE OF XT_LIKP,
          WA_LIKP TYPE XT_LIKP,
          IT_LIPS TYPE STANDARD TABLE OF XT_LIPS,
          WA_LIPS TYPE XT_LIPS,
          IT_VBRK TYPE STANDARD TABLE OF XT_VBRK,
          WA_VBRK TYPE XT_VBRK,
          IT_VBRP TYPE STANDARD TABLE OF XT_VBRP,
          WA_VBRP TYPE XT_VBRP,
          IT_FINAL TYPE STANDARD TABLE OF XT_FINAL,
          WA_FINAL TYPE XT_FINAL.
    **ALV DECLARATIONS
    DATA: IT_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,
          WA_FLDCAT TYPE SLIS_FIELDCAT_ALV,
          IT_LSTHDR TYPE SLIS_T_LISTHEADER,
          WA_LSTHDR TYPE SLIS_LISTHEADER,
          IT_EVENTS TYPE SLIS_T_EVENT,
          WA_EVENTS TYPE SLIS_ALV_EVENT,
          IT_SORT TYPE SLIS_T_SORTINFO_ALV,
          IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: S_BUKRS FOR V_BUKRS NO INTERVALS NO-EXTENSION,
                    S_VBELN FOR WA_VBAK-VBELN,  "SALES DOCUMENT NUMBER
                    S_KUNNR FOR WA_VBAK-KUNNR,  "SOLD-TO-PARTY
                    S_AUDAT FOR V_AUDAT,      "SALES DOCUMENT DATE
                    S_VKORG FOR V_VKORG,      "SALES ORGANISATION
                    S_VKGRP FOR V_VKGRP,      "SALES GROUP
                    S_SPART FOR V_SPART.      "DIVISION
    SELECTION-SCREEN END OF BLOCK b1.
    *****************SCREEN VALIDATION***************
    AT SELECTION-SCREEN.
    SELECT SINGLE BUKRS FROM T001 INTO V_BUKRS WHERE BUKRS IN S_BUKRS."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID COMPANY CODE'.
    ENDIF.
    SELECT SINGLE VBELN FROM VBAK INTO
              CORRESPONDING FIELDS OF WA_VBAK WHERE VBELN IN S_VBELN.
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER VALID SALES DOCUMENT NUMBER'.
    ENDIF.
    SELECT SINGLE KUNNR FROM VBAK INTO
              CORRESPONDING FIELDS OF WA_VBAK WHERE KUNNR IN S_KUNNR. "EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID CUSTOMER NUMBER'.
    ENDIF.
    SELECT SINGLE AUDAT FROM VBAK INTO V_AUDAT WHERE AUDAT IN S_AUDAT."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DOCUMENT DATE'.
    ENDIF.
    SELECT SINGLE VKORG FROM VBAK INTO V_VKORG WHERE VKORG IN S_VKORG."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES ORGANISATION'.
    ENDIF.
    SELECT SINGLE VKGRP FROM VBAK INTO V_VKGRP WHERE VKGRP IN S_VKGRP."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES GROUP'.
    ENDIF.
    SELECT SINGLE SPART FROM VBAK INTO V_SPART WHERE SPART IN S_SPART."#EC *
    IF SY-SUBRC <> 0.
    MESSAGE E000(Z_SD2) WITH 'ENTER A VALID SALES DIVISION'.
    ENDIF.
    PERFORM GET_DATA.
    *&      Form  GET_DATA
    FORM GET_DATA .
    SELECT VBELN KUNNR
            INTO TABLE IT_VBAK
            FROM VBAK
            WHERE VBELN IN S_VBELN.
    *        BUKRS_VF IN S_BUKRS AND
    *        VKORG IN S_VKORG AND
    *        VKGRP IN S_VKGRP AND
    *        SPART IN S_SPART AND
    *        KUNNR IN S_KUNNR AND
    *        AUDAT IN S_AUDAT.
    IF IT_VBAK[] IS NOT INITIAL.
    SELECT POSNR MATNR KWMENG NETWR
            INTO TABLE IT_VBAP
            FROM VBAP
            FOR ALL ENTRIES IN IT_VBAK
            WHERE VBELN = IT_VBAK-VBELN.
    ENDIF.
    IF IT_VBAK[] IS NOT INITIAL.
    SELECT VBELN LFDAT
            INTO TABLE IT_LIKP
            FROM LIKP
            FOR ALL ENTRIES IN IT_VBAK
            WHERE VBELN = IT_VBAK-VBELN.
    ENDIF.
    IF IT_VBAP[] IS NOT INITIAL.
    SELECT POSNR LFIMG
            INTO TABLE IT_LIPS
            FROM LIPS
            FOR ALL ENTRIES IN IT_VBAP
            WHERE POSNR = IT_VBAP-POSNR.
    ENDIF.
    IF IT_LIKP[] IS NOT INITIAL.
    SELECT VBELN
            INTO TABLE IT_VBRK
            FROM VBRK
            FOR ALL ENTRIES IN IT_LIKP
            WHERE VBELN = IT_LIKP-DELVBELN.
    ENDIF.
    IF IT_LIPS[] IS NOT INITIAL.
    SELECT POSNR FKIMG NETWR
            INTO TABLE IT_VBRP
            FROM VBRP
            FOR ALL ENTRIES IN IT_LIPS
            WHERE POSNR = IT_LIPS-DELPOSNR.
    ENDIF.
    ENDFORM.                    " GET_DATA
    Code Formatted by: Alvaro Tejada Galindo on Jan 29, 2008 9:48 AM

  • Selecting single value using for all entries.

    Hi Experts,
    I want to know that is it possible to fetch only the first record for a particular condition while using for all entries.
    For ex:
    Suppose i got 10 different vbeln from vbak table into my internal table it_vbak. For a particular vbeln there can be multiple records in vbap table.
    Now i need to fetch only the first record which is getting from vbap table for different vbeln while using 'for all entries in it_vbak where vbeln = it_vbak-vbeln'. Is it possible?
    Thanks in Advance
    Be$t!N
    Moderator message - Moved to the correct forum
    Edited by: Rob Burbank on Nov 17, 2009 9:38 AM

    Hi Rob Burbank,
    Thanks..
    You are correct.. If that is the scenario in their company... Again it depends on the configuration and business process.. But it's possible that they may need to delete first on any line item after creation of sale order..
    In that case below solution will work..
    IF IT_VBAK[] IS NOT INITIAL.
    SELECT * FROM VBAP
    INTO TABLE IT_VBAP
    for all entries in it_vbak
    where vbeln = it_vbak-vbeln.
    ENDIF.
    SORT IT_VBAP BY VBELN POSNR.
    LOOP AT IT_VBAK INTO WA_VBAK.
    READ TABLE IT_VBAP INTO WA_VBAP WITH KEY VBELN = WA_VBAK-VBELN.
    IF SY-SUBRC = 0.
    APPEND WA_VBAP TO IT_VBAP2. " Another Internal table which stores only first record
    ENDIF.
    CLEAR : WA_VBAP.
    ENDLOOP.
    OR
    IT_VBAP3[] = IT_VBAP[].
    SORT IT_VBAP3 BY VBELN POSNR.
    DELETE ADJACENT DUPLICATES FROM IT_VBAP3 COMPARING VBELN.
    Now Table IT_VBAP2 and IT_VBAP3 will be having only first line items for all sales orders..
    Do some little changes in the code as per your requirement.
    Hope it will solve your problem..
    Thanks & Regards
    ilesh 24x7
    ilesh Nandaniya

  • Can a JOIN statement be rewritten using FOR ALL ENTRIES in any case ?

    I had a SELECT statement, like:
        select p~key1 t~col3 t~col4 p~col2 p~col3
          into table itab1
          from ( table1 as p left outer join table2 as t
                  on p~key1 = t~key1 and t~col2 = someValue ).
    Among which, table1 and table2 are fully buffered.
    Code Inspector suggests that this statement should be, e.g., rewritten using FOR ALL ENTRIES.
    Since FOR ALL ENTRIES is only possible for WHERE conditions of the SELECT statement, which means the internal table right after it is not available for the RESULT clause of the SELECT statement, can the above statement be rewritten? If yes, how?
    Thanks!

    hi ,
    select pkey1 tcol3 tcol4 pcol2 p~col3
          into table itab1
          from ( table1 as p left outer join table2 as t
                  on pkey1 = tkey1 and t~col2 = someValue ).
    <i>look below code</i>
    select * from  table2  into table int_tab2 where col2 = someValue.
    select key1 col2 col3  into table  int_tab1
    FOR ALL ENTRIES IN int_tab2
    WHERE key = int_tab2-key1.
    then use read statements for manipulations
    rgds
    Anver

Maybe you are looking for

  • My MacBook Pro screen doesn't turn on when I the open lid.

    So I bought my 13inch MacBook Pro Retina two weeks ago. 70% of the time when opening the lid the screen will not turn on but my keyboard backlight will. I then have to either close the lid and open again or press the power to put the system to sleep

  • Checking code for SAP USER EXIT

    we have enhanced SAP given data-source 2LIS_XX_XXXXX, there are hard coded user exits for this extractor. How to debug the code for enhancements? I know we enhance data-source in CMOD....SAPLRSAP001 (transactional data)....SAPLRSAP002(attributes)

  • PXI 5105 - min record length varies with number of initialized channels

    Hello everyone, I'm having a hard time with this issue. Why the record length I acquire with "niScope Multi Fetch Cluster" varies, depending on how many channels I initialize? I.E., I want to fetch 20k data points per channel. If I configure and acqu

  • Per-VRF TACACS config gets "Address already in use" error

    I have created a per-VRF TACACS config on a couple of network devices. I can ping the ACS servers through the VRF. TACACS makes the attempt to contact the servers, but the following message shows up in the log when I debug TACACS: *Mar 11 08:57:38 st

  • Big gap in IE7

    Hello Can someone help get rid of an unwanted gap? In IE7 a large gap appears at the bottom of the page between main div and the footer, In safari and Firefox it appears as solid block (which is how I want it) how can I get rid of the gap in IE7?? ww