Find missing values in third table based on two other tables

Hi- I have tried to do this on my own but the answer eludes me. Can someone please point me in a better direction? We have a table project_categories with project_IDs and related project category_IDs. We have another table contact_categories with contact_IDs and related contact category_IDs. We use these two tables to link contacts to projects by at least one category_ID. It works well for email notifications. We have a third table for "planholders" who are interested in particular projects. The planholder table has contact_IDs and related project_IDs. I want to find contacts who have expressed interest in a project, by inserting a row in the planholder table, but they have not selected any of the project categories in contact categories. This would be an unusually rare exception, so to test it I added myself as a contact 100010 and as a project "planholder", but deliberately did not select any of the related project categories in contact categories.
select ph.contact_id, ph.project_id, pc.category_id, cc.category_id
from purchasing_planholder ph, purchasing_project_categories pc, purchasing_contact_categories cc
where ph.project_id=pc.project_id
and ph.contact_id=cc.contact_id
and ph.contact_id||ph.project_id||cc.category_id
not in (select ph.contact_id||pc.project_id||pc.category_id
from purchasing_planholder ph, purchasing_project_categories pc, purchasing_contact_categories cc
where ph.project_id=pc.project_id
and ph.contact_id=cc.contact_id)
and ph.contact_id=100010
This gives me every category for the test contact and every category for the project. I want to find contacts in the planholder table who have not selected any of the categories related to the specific project they selected in the planholder table. I tried minus, outer joins, etc. Does this require PL/SQL and a temp table, or can I find the exceptions with a report? Or do I need a different approach? The ideal answer would display one row with the contact_ID and the project_ID, where the contact has not selected any of the project categories. This would be used to alert them that they need to select at least one of the project categories on the contact form. Thanks for any feedback.
Peter
CONTACT_ID PROJECT_ID CATEGORY_ID CATEGORY_ID
100010 701 1 19
100010 701 1 18
100010 701 16 19
100010 701 16 18
100010 701 21 19
100010 701 21 18
100010 701 24 19
100010 701 24 18
8 rows selected

Hi User,
When you Post a Question in Forum, Please be clear of the Inputs to be given, the expected output and the tries you made,
the errors/results you faced.
Also, see this link of BluShadow.
SQL and PL/SQL FAQ
Please enclose the query or programs in code tags for a formatted code.
Just Try something like this,
SELECT *
  FROM emp c
WHERE NOT EXISTS (SELECT *
                     FROM emp a
                    WHERE EXISTS (SELECT *
                                    FROM emp b
                                   WHERE a.empno = b.empno));In the Inner Query, the conditon checked is empno same in both the tables, and for example some rows are obtained, other than
this rows all other results are obtained from the outer query.
In the above case no rows are returned.
Thanks,
Shankar

Similar Messages

  • Can we create a hierarchy based on two logical table in 10g RPD

    Hi,
    I have a question, please give me some clarity, about creating hierarchy,
    I know we can create a hierarchy based on one logical table which is form by two physical table...
    Can we create a hierarchy based on two logical table? If yes, and how?
    Thanks in advance!
    anne

    Use preffered drill paths...
    -suman

  • Update joining two other tables.

    Hi,
    I have a question on update of one table using two other tables.
    There are three tables: a_visitors(vis_str, vis_flag), b_hub(vis_str ), c_uv_xref(vis_str, user_str).
    And a_visitors.vis_flag needs to be updated with '1', '2' or '3'.
    1 - if there is a record in b_hub table exists where a_visitors.vis_str = b_hub.vis_str
    and a_visitors.vis_str = c_c_uv_xref.vis_str and c_uv_xref.user_str like *'%type_1%'*
    2 - if exists where a_visitors.vis_str = b_hub.vis_str
    and a_visitors.vis_str = c_c_uv_xref.vis_str and c_uv_xref.user_str like *'%type_2%'*
    3- if exists where a_visitors.vis_str = b_hub.vis_str
    Thanks a lot for your help !!!
    And here's the code
    CREATE TABLE "A_VISITORS"
        "VIS_STR"  VARCHAR2(20 BYTE),
        "VIS_FLAG" VARCHAR2(20 BYTE)
    REM INSERTING into A_VISITORS
    Insert into A_VISITORS (VIS_STR,VIS_FLAG) values ('aaa',null);
    Insert into A_VISITORS (VIS_STR,VIS_FLAG) values ('bbb',null);
    Insert into A_VISITORS (VIS_STR,VIS_FLAG) values ('ccc',null);
    Insert into A_VISITORS (VIS_STR,VIS_FLAG) values ('ddd',null);
    Insert into A_VISITORS (VIS_STR,VIS_FLAG) values ('eee',null);
    CREATE TABLE "B_HUB"  ("VIS_STR" VARCHAR2(20 BYTE)   );
    REM INSERTING into B_HUB
    Insert into B_HUB (VIS_STR) values ('aaa');
    Insert into B_HUB (VIS_STR) values ('bbb');
    Insert into B_HUB (VIS_STR) values ('fff');
    Insert into B_HUB (VIS_STR) values ('ggg');
    Insert into B_HUB (VIS_STR) values ('hhh');
    CREATE TABLE "CARAW"."C_UV_XREF" (
        "VIS_STR"  VARCHAR2(20 BYTE),
        "USER_STR" VARCHAR2(20 BYTE)
    REM INSERTING into C_UV_XREF
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('aaa','type_1');
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('aaa','aaaaa');
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('bbb','type_2');
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('ccc','ttt');
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('ddd',null);
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('eee','kkk');
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('fff','lll');
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('ggg','aaaaa');
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('hhh','aaaaa');
    Insert into C_UV_XREF (VIS_STR,USER_STR) values ('aaa','type_2');Edited by: lsy_nn on Sep 20, 2010 12:06 PM
    Edited by: lsy_nn on Sep 20, 2010 12:07 PM

    Hi,
    Thanks for posting the sample data.
    Don't forget to post the results you want from that data (that is, the contents of a_visitors after the UPDATE.)
    Here's one way:
    MERGE INTO     a_visitors     a
    USING  (
            SELECT    NVL (b.vis_str, c.vis_str)     AS vis_str
            ,          COUNT (CASE WHEN c.user_str LIKE '%type_1%' THEN 1 END)     AS type_1_cnt
            ,          COUNT (CASE WHEN c.user_str LIKE '%type_2%' THEN 1 END)     AS type_2_cnt
            FROM                 b_hub     b
            FULL OUTER JOIN  c_uv_xref     c     ON     b.vis_str     = c.vis_str
            GROUP BY  NVL (b.vis_str, c.vis_str)
           )                          bc
    ON     (a.vis_str            = bc.vis_str)
    WHEN MATCHED THEN
    UPDATE  SET  a.vis_flag     = CASE
                        WHEN  bc.type_1_cnt > 0  THEN  '1'
                        WHEN  bc.type_2_cnt > 0  THEN  '2'
                                                    ELSE  '3'
                          END
    ;

  • Converting a single column table into a two-column table

    Hi everybody
    What I'm trying to do is convert a single column table into a two-column table. Here an example:
    Table A (single column):
    ID1
    ID2
    ID3
    ID4
    ID5
    Table B (two-column) should be:
    ID1 ID2
    ID3 ID4
    ID5
    I already did it by looping through a cursor and making an insert every 2 rows, but don't like performance.
    Is there an easier/faster way to do this?
    Thanks in advance
    Oscar

    with t as (
               select 'ID1' col1 from dual union all
               select 'ID2' from dual union all
               select 'ID3' from dual union all
               select 'ID4' from dual union all
               select 'ID5' from dual
              ) -- end of sample table
    select  col1,
            col2
      from  (
             select  col1,
                     lead(col1) over(order by col1) col2,
                     row_number() over(order by col1) rn
               from  t
      where mod(rn,2) = 1
    COL COL
    ID1 ID2
    ID3 ID4
    ID5
    SQL> SY.

  • Finding Missing values

    How to find the missing values in sequence of values. I need a query for this.
    Thanks

    Assuming you are looking for sequences missing in table YourTable and column YourSequenceColumnName from the list starting from 4 to 10... This query will get them
    select a.seqno
    from
         (select level as seqno
         from dual
         where level>=4
         connect by level <=10
         ) a
    left outer join YourTable b
         on a.seqno = b.YourSequenceColumnName
    where b.YourSequenceColumnName is null
    /

  • Sum the value of look up table based on two filter criteria

    Hello Everyone
    I am new to Powerpivot and would appreciate if someone could help me on the following problem.
    You can download the example of this excel file form the following DropBox link:
    Dropbox Link
    The first table is tOrders
    Week number
    Work center
    order number
    Production time in minutes
    2
    a
    111
    60
    2
    a
    112
    70
    2
    b
    113
    60
    3
    b
    114
    50
    3
    a
    115
    40
    3
    b
    116
    60
    4
    a
    117
    90
    4
    b
    118
    40
    The second is dLookupList
    Week number
    Work center
    mantenace in minutes per week
    Break dows in minutes per week
    2
    a
    10
    10
    2
    b
    20
    5
    3
    a
    15
    12
    3
    b
    30
    10
    4
    a
    20
    10
    4
    b
    10
    10
    I’m trying to create Pivot that has filter on Week number to show the number of orders, Sum of Production time in minutes and the total of the values form the lookup table dLookupList that matches the work center and the selected week
    numbers. So that I can calculate the total time for each work center.  Filter criteria is Week number and Work center.  
    For example if someone select all weeks numbers the result sould look like this
    Week number
    (All)
    Work center
    Count of order number
    Sum of Production time in minutes
    mantenace in minutes per week
    Break dows in minutes per week
    Total time
    a
    4
    260
    45
    32
    337
    b
    4
    210
    60
    25
    295
    Grand Total
    8
    470
    Result for week 2
    Week number
    2
    Work center
    Count of order number
    Sum of Production time in minutes
    mantenace in minutes per week
    Break dows in minutes per week
    Total time
    a
    2
    130
    10
    10
    150
    b
    1
    60
    20
    5
    85
    Grand Total
    3
    190
    How can I relate these two tables to get the above result?
    Any help is highly appreciated.
    Regards
    Priyan

    Hi Recio
    Thank you very much for the swift response. I was able to get it work.
    I got two questions:
    How do you add a total time column to the pivot table like you did? Because there are no calculated field in power pivot.
    I prefer that the filter is based on the Orders table. So that if you select all Week numbers in the filter, that pivot will show result for all orders and relevant sums from the lookup list.
    Link download the example file
    For example: I add Week number 5 to the work center “a”
    Week number
    Work center
    WNandWC
    mantenace in minutes per week
    Break dows in minutes per week
    2
    a
    WN2WCa
    10
    10
    2
    b
    WN2WCb
    20
    5
    3
    a
    WN3WCa
    15
    12
    3
    b
    WN3WCb
    30
    10
    4
    a
    WN4WCa
    20
    10
    4
    b
    WN4WCb
    10
    10
    5
    a
    WN5WCa
    1
    1
    In the orders table there are no records for week number 5
    Week number
    Work center
    WNandWC
    order number
    Production time in minutes
    2
    a
    WN2WCa
    111
    60
    2
    a
    WN2WCa
    112
    70
    2
    b
    WN2WCb
    113
    60
    3
    b
    WN3WCb
    114
    50
    3
    a
    WN3WCa
    115
    40
    3
    b
    WN3WCb
    116
    60
    4
    a
    WN4WCa
    117
    90
    4
    b
    WN4WCb
    118
    40
    4
    a
    WN4WCa
    119
    50
    But the pivot sums up the week number 5 also.
    Do you have any idea how to solve it?
    Thank you very much.
    Regards
    Priyan

  • Compare two tables based on two columns

    Hi,
    my tables looks like this:
    Desc Table A (account)
    Account1_id
    Account2_id
    name,
    empid
    Table B (Bill )
    BillNo
    Advertiserid
    agencyid
    total vvalue
    I need to pick up total value from table B where the unique combination of advertiser-Agency id is the same as the given account1_id -Account2_id combination in table A for each employee id.
    In other words my output should be like
    Empid | Account_id (should be same as advertiserid)| Account2_id (same as agencyid) | sum(total_value) for this adv-agency combination.....
    objective: Get the total value from table B for each unique account1-account2 combination (advertiser-agency in other words) .
    I am not sure if I should use a coreelated subquery or how to handle the situation....Right now I am just checking the two columns separately like this:
    select.......from a,b
    where b.advertiser_id = a.account1_id and b.agencyid = b.account2id
    Is it correct to do so? I have a feeling that I am missing something if I join them seperately like this......Any advice on this?
    I am using Oracle 10g. Hope I am clear.Please let me know. Thankx in advance.

    Here you go:
    SQL> WITH bill AS
      2  (
      3          SELECT 1000 AS billno, 101 AS advertiserid, 102 AS agencyid, 5000 AS total_value FROM DUAL UNION ALL
      4          SELECT 1001, 101, 103, 5000 FROM DUAL UNION ALL
      5          SELECT 1002, 101, 102, 1000 FROM DUAL
      6  ), account AS
      7  (
      8          SELECT 101 AS account1_id, 102 AS account2_id, 'John' AS name, 50 AS empid FROM DUAL UNION ALL
      9          SELECT 101, 103, 'James', 40 FROM DUAL UNION ALL
    10          SELECT 101, 105, 'Joe', 60 FROM DUAL
    11  )
    12  /* End Sample Data */
    13  SELECT a.name
    14       , a.empid
    15       , a.account1_id
    16       , a.account2_id
    17       , SUM(b.total_value)
    18  FROM   account a
    19  JOIN   bill    b ON  a.account1_id = b.advertiserid
    20                   AND a.account2_id = b.agencyid
    21  GROUP BY a.name
    22         , a.empid
    23         , a.account1_id
    24         , a.account2_id
    25  ;
    NAME                 EMPID          ACCOUNT1_ID          ACCOUNT2_ID   SUM(B.TOTAL_VALUE)
    John                    50                  101                  102                 6000
    James                   40                  101                  103                 5000

  • Sort Internal table based on another internal table

    Hello All,
    My Requirement is :
    I have two internal tables itab1 and itab2. itab1 has partner_number along with some more fields/columns. Based on the partner_numbers of the itab1 i write a query to get the values for partner_last_name and central_block_flag from the table but000 and i fill these values into a new itab2.
    Sort itab2 by partner_last_name and central_block.
    Now how do I sort itab1 based on the sorted itab2-partner_number. I need to have itab1 sorted similar to the order in the itab2.
    How do i do this?
    Please let me know if you need more details.Looking forward for your support.
    Regards,
    Harish P M

    Hello Micky,
    Thank you for your early reply.
    I have this scenario wherein i need to sort a existing internal table itab1 of type 'bapibus1006_relations' based on the 'Partner last name ' and 'Inactive/Active Flag'. These two fields are not available in this itab1 and so i need to create itab2 after a query on table but000.
    Sorting itab2 is , first sort itab2 based on the 'Active flag' and then sort this itab2 again by 'Partner last name'(ascending order).
    Finally when i get my sorted itab2 i would have to ensure that my objective of sorting itab1 is obtained.
    I guess i sound better now.
    Would be helpful if you could reply.
    Regards,
    Harish P M

  • Find if there is any common record in two internal tables

    hi,
    I have two internal tables of same structure... say A and B.
    I need to know if there are any common lines in them.
    one way is to loop in any one of them and keep executing a read on the other.
    can anyone suggest a better way.
    thanks,
    Arindam.

    Hi Arindam,
    To find common records in two internal tables, they can be compared
    If INT_DATA1 EQ INT_DATA2.
    endif.
    The first criterion for comparing internal tables is the number of lines they contain. If two internal tables contain the same number of lines, they are compared line by line, component by component.
    If the internal tables contain the same number of records and are sorted on the same key, the comparison stops at the line where the records are not common. For example, if the number of common records is 4, the comparison stops at the 5th line and sy-tabix becomes 5.
    Hope it helps.
    Regards,
    Nupur

  • How to update standard table based on the custom table

    Hi,
    I have requirement , I have custom table whatever changes done to the custom table must be updated in the standard table
    i have tried the table maintenance events but unable to handle delimit , what is the base solution for this.
    1) create
    2) change
    3) delimit
    4) delete
    6)copy

    the table im updating is t710
    the custom table is same as the standard table except for one field . whatever the user maintains the values in custom table except for the one field everything should update back to the standard table. Im able to update when we create delele but the problem is delimition. when im delimiting the record in custom table its just changing the startdate and it is not actually delimiting the record itself .I want both records the latest one and previous one and should be update back into the standard table same as the custom table

  • Oracle 11 RPD: Create 2 Logical Tables Based on 1 Physical Table

    Hello,
    I have a date dimension table in the physical layer. From that I need to create 2 date dimension tables in the BMM layer. One is for order date and the other is for shipped date. There is a ship_date_key and an order_date_key in my fact table that I'm trying to use as my foreign key.  Seems I can create a joined ship date logical table or a joined order date logical table but not both.
    Very new to OBI Admin tool.  Any help would be greatly appreciated.

    If you create only one alias from Date dimension in Physical Layer then you can get only one data either Ship Date or Order date details.
    The data from Date dimension gets retrieved on the basis of the Join i.e on which key it was joined to the Fact.
    To solve the above ambiguity you should create two separate alias tables in physical layer, hence you will have two logical tables in BMM Layer
    Create Dim_Ship_Date and Dim_Order_Date from Date dimension.
    And now, you can join the fact with these two aliases on different keys. This practice is usually followed.
    If found useful mark the answer
    Srikanth

  • Binding for table produces list for other tables using foreign key and crea

    Using
    software Jdev 11G, WLS 11G, Oracle DB 11G, Windows Vista platform
    technology EJB 3.0, jspx, backing beans, session bean
    I cannot create a namedquery on my secondary table. The method for the column uses the entity object rather than the name and value of the column.
    For instance,
    (Coketruck) table has inventory records(Products) table
    Coketruck has one to many to the Products table
    Products has a many to one to the Coketruck
    I need to return the products from the product table based on the CokeTruck but I cannot create a namedQuery because the method in the Product table is an entity object type instead of a long that I can use to look up all the products based off the column truck_id.
    This is what I was expecting…
    Private Long truckId;
    public Long getTruckId() {
    return truckId;
    public void setTruckId (Long truckId) {
    this. truckId = truckId;
    Instead this is what I have…
    @ManyToOne
    @JoinColumn(name = "TRUCK_ID")
    private Coketruck coketruck;
    this. coketruck = coketruck
    public Coketruck getCoketruck() {
    return coketruck;
    public void set Coketruck (Coketruck coketruck) {
    this. coketruck = coketruck;
    How do I do a query on the Product table to return all the products that are in the coketruck?
    If I do the following it expects for me to pass the Entity Object which I cannot use as search criteria for my find method.
    @NamedQuery(name = "Products.findById", query = "select o from Products o where o.truckId = :truckId")
    On a different note but the same song…
    I noticed that when I look at my Session Bean Data Contols that the coketruck already has a list of the products. I have created a jsp page with a backing bean and have been able to use the namedquery on the coketruck entity to retrieve the productList. Unfortunately I need to sort the products by type and was also not able to find where to perform the work to be able to iterate through the productList to get my desired display. Therefore I started looking at doing another namedquery that would only retrieve the product_type ordering by the truckId.
    Seems I have come full circle… I don’t care what method I have to use to get the info back.
    Any help is greatly appreciated!

    user9005175 wrote:
    Hi!
    I work on an application wich uses a shopping cart stored in a database. The shopping cart uses two tables:
    CART: Holds information common for one shopping cart: the user it is connected to etc.
    - Primary key: CART_ID
    CART_ROW: One row in the cart, e.g. one new product to buy.
    - Primary key: ROW_ID
    - Foreign key: CART_ROW.CART_ID references CART.CART_ID
    From the code the rows in the cart are collected per cart, as is modelled by the foreign key. There exists one more relationship, which we use in the code, but which is not modelled by a foreign key in the database. One row can be dependent on another row, which makes the other row a parent.
    CART_ROW has a column PARENT_ID which references CART_ROW.ROW_ID.
    Should we add a foreign key for PARENT_ID? Or are there any questions to consider when it is a foreign key to the same table?
    I suggest to add foreign key it wont harm the performance (except while on insert when there would be validation for the foreign key). But it would prevent users to insert wrong/corrupt data either through code or directly by loggin in the database.
    A while ago we added indexes, both on ROW_ID and on PARENT_ID. Could the index on PARENT_ID have been harmful, since there is no foreign key?
    Index on parent_id would only be harmful if you do not make use of index after creating it (i.e. there is no query which make use of this index).
    And if you decide to have a foreign key on parent_id then I suggest to have index too on parent_id as it would be helpful atleast when you delete any record in this table.
    Best regards!

  • How to track the changes to a table and update the other table ?

    Hi Guys,
                   I am looking to track deletion of entries on KONV table and sync these missing entries in an other table which has primary key entries of KONV.
    How to do this.. is ALE change pointer is any good for this purpose ?
    Thanks
    AJ

    Hi Sam,
      In order to track the changes in the KONV table, go to table CDHDR and give objectclass and objectid, you will get all the details.
    Regards,
    ramesh.

  • To populate dynamically created int table with data from other table

    Hi everybody,
    I have already created an internal table dynamically, but now want to populate it with data from another IT depending on the plant name.
    My dynamic int table contains fields with plant name like '8001' ,'8002' and so on.
    no I want to read data from the other table and depending on bwkey which contains similar data like plant name , want to append to this new dynamic int table through read key statement.
    I cannot reference the field name hard coded as it does not allow field symbol reference to be hard coded.
    Pls help.

    Hi,
    Check the code below:
    REPORT  ztestdyn.
    TYPE-POOLS : slis.
    TABLES: yyle0003.
    DATA:
      g_exit    TYPE c,
      g_save    VALUE 'A',               "For parameter I_SAVE
      g_repid   LIKE sy-repid,           "For program name
      g_variant TYPE disvariant.         "For parameter IS_VARIANT
    *Tables
      DATA: d_ref TYPE REF TO data,
            d_ref1 TYPE REF TO data,
            i_alv_cat1 TYPE TABLE OF lvc_s_fcat,
            ls_alv_cat1 LIKE LINE OF i_alv_cat1.
      DATA: BEGIN OF total_tab OCCURS 0 ,
            tknum TYPE yyle0003-tknum,
            quantity TYPE p,  "yyle0003-QUANTITY,
            END OF total_tab.
      DATA: BEGIN OF g_scandata_tab OCCURS 0.
              INCLUDE STRUCTURE yyle0003.
      DATA: END OF g_scandata_tab.
      DATA: g_yyle0003_tab LIKE yyle0003 OCCURS 0 WITH HEADER LINE.
      DATA: g_itab1 TYPE TABLE OF yyle0003.
      DATA: wa_itab1 LIKE g_scandata_tab.
      TYPES: BEGIN OF itab2,
             tknum TYPE yyle0003-tknum,
             vhilm TYPE yyle0003-vhilm,
             quantity TYPE p,
             END OF itab2.
      DATA: g_itab3 TYPE TABLE OF itab2.
      DATA: wa_itab3 TYPE itab2.
      DATA: g_itab5 TYPE TABLE OF itab2.
      DATA: wa_itab5 TYPE itab2.
      DATA: g_itab4 TYPE TABLE OF itab2.
      DATA: wa_itab4 TYPE itab2.
      DATA: gv_wa TYPE REF TO data.
      DATA : wa_tab TYPE itab2.
      DATA: BEGIN OF itab6 OCCURS 0,
             vhilm TYPE yyle0003-vhilm,
             quantity TYPE p,
             END OF itab6.
    ******************Start of Internal Table Definition *******************
      DATA:
            g_custom_container_0100 TYPE REF TO cl_gui_custom_container,
            g_alv_grid_0100    TYPE REF TO cl_gui_alv_grid,
            g_container_0100   TYPE scrfname VALUE 'LIST',
            g_mylayout         TYPE lvc_s_layo,
            ok_code            LIKE sy-ucomm.
      FIELD-SYMBOLS :<f_fs> TYPE table,
                     <f_fs11> TYPE table,
                     <f_fs1> TYPE table,
                     <f_fs3> TYPE ANY,
                     <f_fs4> TYPE ANY,
                     <f_field> TYPE ANY,
                     <f_fs5> TYPE ANY.
      FIELD-SYMBOLS: <fs_wa> TYPE ANY.
      DATA: l_var TYPE i,
            l_i   TYPE i.
      DATA: l_var1 TYPE char20,
            l_var2 TYPE char20.
    DATA: l_TOTAL TYPE I,
          L_FILL TYPE i,
          L_TOT  TYPE I.
    DATA: l_int TYPE i,
           l_sum TYPE i.
    FIELD-SYMBOLS: <f_fs2> TYPE  itab2, "
                     <f_fs6> TYPE ANY,
                     <f_fs7> TYPE ANY.
      DATA: l_var3 TYPE char15.
      DATA: l_quant TYPE p.
    FIELD-SYMBOLS: <f_fs8> LIKE itab6, "
                     <f_fs9> TYPE ANY,
                     <f_fs10> TYPE ANY.
    FIELD-SYMBOLS : <f_fs12> TYPE ANY,
                      <f_fs13> TYPE ANY.
      SORT g_scandata_tab BY tknum vhilm.
      LOOP AT g_scandata_tab INTO wa_itab1.
        MOVE-CORRESPONDING wa_itab1 TO wa_itab3.
        APPEND wa_itab3 TO g_itab3.
      ENDLOOP.
      LOOP AT g_itab3 INTO wa_itab3.
        COLLECT wa_itab3 INTO g_itab4.
      ENDLOOP.
      LOOP AT g_itab4 INTO wa_itab4.
        MOVE-CORRESPONDING wa_itab4 TO wa_itab5.
        MOVE-CORRESPONDING wa_itab4 TO itab6.
        APPEND wa_itab5 TO g_itab5.
        COLLECT itab6.
      ENDLOOP.
      CLEAR wa_itab3.
      SORT g_itab4 BY tknum vhilm.
      DELETE ADJACENT DUPLICATES FROM g_itab4 COMPARING vhilm.
      DESCRIBE TABLE g_itab4 LINES l_var.
      l_i = '2'.
      ls_alv_cat1-fieldname = 'TKNUM'.
      ls_alv_cat1-col_pos = 1.
      ls_alv_cat1-coltext ='ShipmentNo.'.
      APPEND ls_alv_cat1 TO i_alv_cat1.
      DATA: l_var4(10) TYPE c,
            l_var5(10) TYPE c,
            l_fieldname(20) TYPE c..
      LOOP AT g_itab4 INTO wa_itab4.
        IF l_var >= 1.
          CONDENSE wa_itab4-vhilm NO-GAPS.
          ls_alv_cat1-fieldname = wa_itab4-vhilm. "l_fieldname.
          ls_alv_cat1-col_pos = l_i.
          ls_alv_cat1-coltext = wa_itab4-vhilm.
          ls_alv_cat1-do_sum  ='X'.
          APPEND ls_alv_cat1 TO i_alv_cat1.
          CLEAR : ls_alv_cat1, l_fieldname.
          l_i = l_i + 1.
        ENDIF.
        AT LAST.
          ls_alv_cat1-fieldname = 'TOTAL'. "l_fieldname.
          ls_alv_cat1-col_pos = l_i.
          ls_alv_cat1-coltext = 'TOTAL'.
          ls_alv_cat1-do_sum  ='X'.
          APPEND ls_alv_cat1 TO i_alv_cat1.
          CLEAR : ls_alv_cat1, l_fieldname.
        ENDAT.
        SORT i_alv_cat1 BY fieldname.
        DELETE ADJACENT DUPLICATES FROM i_alv_cat1.
      ENDLOOP.
      SORT i_alv_cat1 BY col_pos.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = i_alv_cat1
        IMPORTING
          ep_table = d_ref.
      ASSIGN d_ref->* TO <f_fs>.
      CREATE DATA gv_wa LIKE LINE OF <f_fs>.
      ASSIGN gv_wa->* TO <fs_wa>.
      DELETE ADJACENT DUPLICATES FROM <f_fs> COMPARING ALL FIELDS.
        LOOP AT itab6.
        CLEAR wa_itab5.
        wa_itab5-tknum = 'Total'.
        MOVE-CORRESPONDING itab6 TO wa_itab5.
        APPEND wa_itab5 TO g_itab5.
        CLEAR wa_itab5.
      ENDLOOP.
         DESCRIBE TABLE g_itab5 LINES L_TOT.
           LOOP AT TOTAL_TAB.
          L_TOTAL = L_TOTAL + total_tab-quantity.
         ENDLOOP.
      LOOP AT g_final ASSIGNING <f_fs2>.
        ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <f_fs2> TO <f_fs6>.
        ASSIGN COMPONENT 'TKNUM' OF STRUCTURE <fs_wa> TO <f_fs7>.
        <f_fs7> = <f_fs6>.
        CONDENSE <f_fs2>-vhilm NO-GAPS.
        ASSIGN COMPONENT 'VHILM' OF STRUCTURE <f_fs2> TO <f_fs3>.
        ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.
        MOVE <f_fs3> TO l_var1.
        ASSIGN COMPONENT l_var1 OF STRUCTURE <fs_wa> TO <f_fs5>.
        <f_fs5> =  <f_fs4>.
        CLEAR total_tab-quantity.
        READ TABLE total_tab WITH KEY tknum = <f_fs6>.
        IF sy-subrc = 0.
          ASSIGN total_tab-quantity TO <f_fs12>.
          ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.
          <f_fs13> = <f_fs12>.
        ENDIF.
        L_FILL = L_FILL + 1.
        IF L_FILL = L_TOT.
         ASSIGN L_TOTAL TO <f_fs12>.
          ASSIGN COMPONENT 'TOTAL' OF STRUCTURE <fs_wa> TO <f_fs13>.
          <f_fs13> = <f_fs12>.
        ENDIF.
        AT END OF <f_fs2>-tknum.
          APPEND <fs_wa> TO <f_fs>.
          CLEAR  <fs_wa>.
        ENDAT.
      ENDLOOP.
      CLEAR: <f_fs6>,
              <f_fs7>.
      CLEAR <fs_wa>.
    CALL SCREEN 0100.
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'ZVKS'.
      SET TITLEBAR 'ZVKS'.
      CHECK sy-ucomm IS INITIAL.
      SORT g_scandata_tab BY tknum vhilm.
      CREATE OBJECT g_custom_container_0100
             EXPORTING container_name = g_container_0100
             EXCEPTIONS
               cntl_error = 1
               cntl_system_error = 2
               create_error = 3
               lifetime_error = 4
               lifetime_dynpro_dynpro_link = 5.
      CREATE OBJECT g_alv_grid_0100
             EXPORTING i_parent = g_custom_container_0100.
      g_mylayout-grid_title = 'Display Scanning data'.
      CALL METHOD g_alv_grid_0100->set_table_for_first_display
        CHANGING
          it_outtab                     = <f_fs>
          it_fieldcatalog               = i_alv_cat1
                    EXCEPTIONS
                      invalid_parameter_combination = 1
                      program_error                 = 2
                      too_many_lines                = 3
                      OTHERS                        = 4.
      IF sy-subrc <> 0.
                  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    Regards
    Kannaiah

  • Insert into one table by query from other table

    Dear sir, i have inserted in to Table A as below:
    ROLE_ID
    USER_ID
    AUTH_STAT
    BRANCH_CODE
    Teller1
    Phearom
    A
    001
    Teller2
    Phearom
    A
    001
    I want to insert the same more value for field ROLE_ID, USER_ID and AUTH_STAT, except BRANCH_CODE must change. Value of field BRANCH_CODE in can query form Table B.
    Kindly give me some idea.
    Thank and Regard.
    Phearom

    7d8870ae-222b-4d73-8251-86f34b1ad49e wrote:
    Dear sir, i have inserted in to Table A as below:
    ROLE_ID
    USER_ID
    AUTH_STAT
    BRANCH_CODE
    Teller1
    Phearom
    A
    001
    Teller2
    Phearom
    A
    001
    I want to insert the same more value for field ROLE_ID, USER_ID and AUTH_STAT, except BRANCH_CODE must change. Value of field BRANCH_CODE in can query form Table B.
    Kindly give me some idea.
    Thank and Regard.
    Phearom
    You don't seem to have taken any notice of the advice given in your last thread: Insert multi row
    about reading Re: 2. How do I ask a question on the forums?
    and following the advice there.
    In fact, I suspect this is just another thread on the same problem.
    Unless you give us the information required, we can't really help

Maybe you are looking for