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

Similar Messages

  • Change field value in a table, based on another field value in the same row (for each added row)

    Please Help, I want to change field value in a table, based on another field value in the same row (for each added row)
    I am using this code :
    <HTML>
    <HEAD>
    <SCRIPT>
    function addRow(tableID) {
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    var colCount = table.rows[0].cells.length;
    for(var i=0; i<colCount; i++ ) {
    var newcell = row.insertCell(i);
    newcell.innerHTML = table.rows[1].cells[i].innerHTML;
    switch(newcell.childNodes[0].type) {
    case "text":
    newcell.childNodes[0].value = "";
    break;
    case "checkbox":
    newcell.childNodes[0].checked = false;
    break;
    case "select-one":
    newcell.childNodes[0].selectedIndex = 0;
    break;}}}
    function deleteRow(tableID) {
    try {var table = document.getElementById(tableID);
    var rowCount = table.rows.length;
    for(var i=0; i<rowCount; i++) {
    var row = table.rows[i];
    var chkbox = row.cells[0].childNodes[0];
    if(null != chkbox && true == chkbox.checked) {
    if(rowCount <= 2) {
    alert("Cannot delete all the rows.");
    break;}
    table.deleteRow(i);
    rowCount--;
    i--;}}}catch(e) {alert(e);}}
    </SCRIPT>
    </HEAD>
    <BODY>
    <INPUT type="button" value="Add Row" onClick="addRow('dataTable')" />
    <INPUT type="button" value="Delete Row" onClick="deleteRow('dataTable')" />
    <TABLE id="dataTable" width="350px" border="1">
    <TR>
    <TD width="32"></TD>
    <TD width="119" align="center"><strong>Activity</strong></TD>
    <TD width="177" align="center"><strong>Cost</strong></TD>
    </TR>
    <TR>
    <TD><INPUT type="checkbox" name="chk"/></TD>
    <TD>
    <select name="s1" id="s1">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    </TD>
    <TD><input type="text" name="txt1" id="txt1"></TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>

    Hi,
    Let me make sure u r working with table control.
    First u have to create a event(VALIDATE) to do the validation.
    Inside the event,
    1. First get the current index where user has pointed the curson
    2. Once u get the index read the internal table with index value.
    3. Now u can compare the col1 and col2 values and populate the error message.
    1. DATA : lo_elt TYPE REF TO if_wd_context_element,
                   l_index type i.
    lo_elt = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
         CALL METHOD LO_ELT->GET_INDEX( RECEIVING  MY_INDEX = l_index.
    above code should be written inside the event.
    Thanks,

  • How to update one table based on another table ??

    Hello Friends:
    I am trying to run the following query in oracle but it won't run.
    UPDATE BOYS
    SET
    BOYS.AGE = GIRLS.AGE
    FROM GIRLS
    WHERE
    BOYS.FIRSTNAME = GIRLS.FIRSTNAME AND
    BOYS.LASTNAME = GIRLS.LASTNAME;
    This query runs fine in sql server but in oracle its saying can't find "SET". PLease tell me what is the correct syntax in oracle to update one table based on another table.
    thanks

    See if this helps.
    If you wrote an SQL statement:
    update boys set age = 10;
    Every row in the boys table will get updated with an age of 10. But if you wrote:
    update boys set age = 10
    where firstname = 'Joe';
    Then only the rows where the firstname is Joe would be updated with an age of 10.
    Now replace the 10 in the above statements with (select g.age from girls g where g.firstname = b.firstname and g.lastname = b.lastname) and replace where firstname = 'Joe' in the second statement with where exists (select null from girls g where g.firstname = b.firstname and g.lastname = b.lastname). The same concepts apply whether 10 is an actual value or a query and whether you have a where clause with the update statement to limit rows being updated.
    About the select null question regarding the outer where clause:
    Since the query is checking to see if the row in the girls table exists in the boys table what the column is in this select statement doesn't matter, this column isn't being used anywhere. In this case Todd chose to use null. He could have also used a column name from the table or a lot of times you'll see the literal value 1 used here.

  • Best way to create a table based on another table

    Hello,
    I am trying to create a table based on another table with all the data in it. It has large data.
    create table <tablename> as select * from table1.
    Is this the best way of doing it or is there any other way. please advice.
    thanks

    I am suggested to create new table as
    create table <newtable> as
    select * from <oldtable> where rownum < 1;
    then
    alter table <newtable> compress;
    then
    insert /*+ append */ into <newtable> as select * from <oldtable>;
    but i getting an error saying missing values key words ora- 00926.
    please advice

  • Choose field from joined table based on another field?

    Good morning!
    Is it possible to select a field from a joined table row based on another field? Consider the following data in the CVALUES table:
    ID  C1   C2    C3    C4    C5    C6
    T1  9.6  10.3  12.4  19.6  19.6    0
    T7  9.6  10.4     0     0     0    0
    T3  8.2   9.9  11.4  19.6  19.6    0
    T8  8.3  10.7  13.5  20.7     0    0
    T5  9.4  10.3  12.7  22.9  19.6    0
    ...And the following data in the MDETAIL table:
    ID           MDATE        CNUM     ...
    T1  03/28/2012 18:00:00    4
    T1  03/28/2012 18:00:00    1
    T8  03/29/2012 06:00:00    6
    T8  03/29/2012 06:00:00    5
    ...I want to get the column from CVALUES corresponding to the CNUM field in the MDETAIL table. I'm currently doing this:
    SELECT m.t1, m.mdate,
           CASE WHEN m.cnum = 1 THEN c.c1
                WHEN m.cnum = 2 THEN c.c2
                WHEN m.cnum = 3 THEN c.c3
                WHEN m.cnum = 4 THEN c.c4
                WHEN m.cnum = 5 THEN c.c5
                WHEN m.cnum = 6 THEN c.c6 END AS cvalue
      FROM mdetail m
      JOIN cvalues c ON m.id = c.idThe records in the CVALUES table are unique; only one row per ID.
    This method works, and it's fast but it's messy code and I think there has to be a better way to do it. I use the cvalue value in several calculations so every calculation I use it in has this giant glob of CASE in it!

    Since you're comparing the same column against scalar values, the CASE statement could be simplified in a similar way :
    CASE m.cnum
      WHEN 1 THEN c.c1
      WHEN 2 THEN c.c2
      WHEN 3 THEN c.c3
      WHEN 4 THEN c.c4
      WHEN 5 THEN c.c5
      WHEN 6 THEN c.c6
    END AS cvalueSince performance is not the issue here, now it depends on what you consider "more readable".
    Using a one-liner piece of code certainly makes the query looks less bulky, but I won't be so sure about readability and immediate understanding.

  • Want to sort the records based on non-base table item

    I have a multi-record block and I am trying to sort the data based on nbt item
    I have a table called X which has x_type,x_code fields.
    The table on which the block is created is Y. the table Y has x_type and y_desc as its fields
    form layout is like below .the x_type is key field on which I have to query the records
    and x_code is a non-base item in the form.I want to sort the records by X_code.
    x_code y_desc
    A     xyz
    c par
    B     lmn
    my pre-query has this code
    select x_type from y
    where
    x_type := x_type;
    post-query has this code
    select x_code from x
    where x_type = :x_type;     
    It works fine in Enter-Queryand execute query mode. but when I am sorting the records on
    nbt item x_code by SET-BLOCK-PROPERTY it doesn't do any thing

    Hi Tony ,
    I have created a function and in Pre-Query & have add this
    SET_BLOCK_PROPERTY('b1', ORDER_BY, 'fn_get_code(x_type)');
    and the function created is as below
    Function fn_get_code (p_x_type in varchar2) return varchar2 is
    v_code varchar2(40);
    begin
    select x_code into v_code
    from X, Y
    where X.x_type = Y.x_type
    and y.x_type = p_x_type
    return v_code;
    end;
    when I run the form and execute query it comes up with the error message
    FRM-40505 and when I pressed display error it shows
    SQL Statement error:
    SELECT ROWID,X_TYPE,X_CODE
    FROM Y order by fn_get_code(x_type)
    Error:
    "ORA-00904: "FN_GET_code": invalid identifier"
    Is it that I need to create a function on the database?. As I have created function
    in program unit section

  • Updating one table based on another

    Ok, that sounds a little confusing, but this is what I want to do:
    Table A is my source table and is a temp table and will be reloaded daily.
    Table B is my target table.
    What I want to do is update Table B using a subset of Table A based on a date within Table B. A simple psuedo code would look like:
    update Table B
    insert * from Table A where Table B.datefield <> Table A.datefield.
    Both tables contain the same data elements, so the structure is an exact 1 to 1 match.
    Table B was initially created from Table A using the copy command to do an intial load. From this point forward, I just need to update Table B with new data from Table A, which has data loaded into it throughout the day. My idea is to grab just the data that isn't in Table B once a day.
    I'm open to all suggestions or ideas............
    Doug

    By cracky, I think that merge thing is just what I'm looking for.
    In theory the data in Table A will contain the data in Table B, plus newer data. The older data in Table A is stagnant, meaning that that table is just appended to. The problem is, Table A is periodically trimmed by the application. Table B is to be used for compiling all the data and reporting trend and historical data.
    More, specifically, Table A is the History table in HP Openview. Table B will be a table in HP Performance Insight. Since theses are 2 totally seperate databases, I will need to copy over the OpenView History table to a temp table in PI nightly, then cull out the records that were added during that day and place those and only those into the PI table for reporting.
    I'll give the merge command a try. I think it will do exactly what i need.
    Thanks,
    Doug

  • Create another table based on data from table above

    Hi all am using EJB 3.0 as technology.
    I have a table where user insert records.
    The field are as below
    TableId, projectId, TaskId, TOdate, duration, comments.
    I need to traverse this table and create another table that will display duration perday.
    for example
    Monday Tuesday Wednesday Thursday Friday
    6hr 8hr 7hr 8hr 9hr
    Thank you for your help regards
    Lutchumaya

    How-to information added to the example page.
    I experimented (not altogether to my satisfaction) with APEX 4.0 sub-regions which won't be usable anywhere else at present, so haven't said anything about region layout. In earlier versions you could use 2 or 3 regions with suitable choices of region templates according to your preference.

  • Granting table privileges on another users tables

    Can anyone tell me what privilege needs to be granted to a user to be able to grant insert/update/select/delete/execute on another users tables/packages?
    I had thought that 'grant any privilege' was the one to have... and - the user I am trying to use to grant the privileges on the other users schema has this however - I'm still getting : ORA-01031: insufficient privileges when trying to run the grants.
    Any ideas what I'm doing wrong here?

    Ok... well...
    The 'with grant' option doesn't appear to be the issue.
    The user attempting to perform the grants:
    i.e. GRANT SELECT ON user_2.table_1 TO view_role
    has the 'grant any object privilege' and - that seems to be enough. When I run the statement above as a simply as typed - it works fine.
    However - what I'm actually doing is concatenating that together in a string and running (from a package created by/as user_1) and doing an execute immediate...
    i.e.
    l_sql := 'GRANT ' || l_rec.privilege || ' ON ' || l_rec.owner || '.' || l_rec.table_name || ' TO ' || p_role;
    EXECUTE IMMEDIATE l_sql;
    And - it's this that's giving me the insufficient privileges...
    I do not have invokers rights set on the package - so that shouldn't be an issue. And - I can't find any documented restriction on doing this (and - in fact - it works fine if I create the package as user_2 and run it as user_2 - the owner of the objects).
    I'm at a loss.

  • PL/SQL insert nested table value into another nested table.

    Hi Guy
    I've created a table with nested table in and inserted some values. note: this is just an example the real table has more values inserted.
    REATE OR REPLACE TYPE tt_hours AS OBJECT(hours INTEGER, data NUMBER);
    CREATE OR REPLACE TYPE tt_day AS VARRAY(7) OF tt_hours;
    CREATE TABLE old_table
    DAY DATE,
    VALUE_hours tt_day
    INSERT INTO old_table
    (day, value_hours)
    VALUES
    (TO_DATE('01/06/2012 22:00:34'),
    tt_DAY(
    tt_hours(1,0.025727),
    tt_hours(2,0.012047),
    tt_hours(3,0.012857),
    tt_hours(4,0.012107),
    tt_hours(5,0.012849),
    tt_hours(6,0.01215),
    tt_hours(7,0.0129)))
    I've also created another table with same structure but with no value inserted.
    REATE OR REPLACE TYPE yy_hours AS OBJECT(thours INTEGER, tdata NUMBER);
    CREATE OR REPLACE TYPE yy_day AS VARRAY(7) OF yy_hours;
    CREATE TABLE new_table ( tDAY DATE, VALUE_thours yy_day )
    I run a select from statement which workout the average of data from old table by group.
    SELECT to_char(DAY, 'Day'), hours, AVG(data)
    FROM old_table n, TABLE(n.value_hours) v
    GROUP BY to_char(DAY, 'Day'), hours;
    How do I insert the result in new_table's ?

    I believe I said
    >
    You basically need to construct the INSERT statement just like you did manually for the first table.
    >
    and instead you used
    INSERT INTO new_table a (tday, t.hours, t.DATA) TABLE(a.value_thours) t This is what you did manually for the first table. Do you see TABLE (...) in here anywhere?
    INSERT INTO old_table
    (day, value_hours)
    VALUES
    (TO_DATE('01/06/2012 22:00:34'),
    tt_DAY(
    tt_hours(1,0.025727),
    tt_hours(2,0.012047),
    tt_hours(3,0.012857),
    tt_hours(4,0.012107),
    tt_hours(5,0.012849),
    tt_hours(6,0.01215),
    tt_hours(7,0.0129)))NO YOU DON'T - you used a tt_DAY constructor for the outer nested table and multiple tt_hours constructors for the inner nested table.
    You need to do the same thing in your INSERT query.

  • How to map lookup main table field in another main table using MDM 7.1?

    We created a new SAP MDM 7.1 repository with multiple main tables.  The first main table is called ProductMaster table which contains Products information.  The ProductCode is the primary key and the only display field for the table during data loading process. The second main table is ProductByRegion table which has a main table lookup field ProductCode and a RegionId field.  These two fields (ProductCode and RegionId) combine as the PK for this main table.  Both main tables have key mapping enabled. 
    I was able to load ProductMaster table using Import Manager.  But Iu2019m having trouble to load data into ProductByRegion table using MDM Import Manager.  Although I have met all the 5 requirements below (excerpted from MDM Import Manager Reference Guide P.222), the ProductCode wonu2019t show up on the destination value pane.  If I mapped all productCode to NULL field, ProductCode wonu2019t load.  If I u2018Addu2019 all ProductCode to Destination Value pane, the Import Manager added duplicated rows to Product Master table while only loading 1 record to ProductByRegion table.  I canu2019t get ProductCode show up in Matching Destination Field list.  When I checked ProductMaster records in MDM Data Manager, I right-clicked on one of records, chose Edit Key Mappings, it didnu2019t show anything.  However, if I right-clicked on one of those duplicated rows, Edit Key Mapping shows remote system and key correctly.
    Where did I do wrong?  How can I fix the problem?
    Thank you for help in advance.
    From: SAP MDM Import Manager Reference Guide:
    Mapping to Main Table Lookup Destination Fields
    Import Manager handles main table lookup fields (Lookup [Main])
    differently than other MDM lookup fields. Specifically, Import Manager
    does not display the complete set of display field values of the records
    of the underlying lookup table. Instead, the values it displays for a main
    table lookup field are limited by both the key mappings for the lookup
    table and the values in the source file.
    Also, Import Manager does not automatically display the values of a
    Lookup [Main] destination field in the Destination Values grid when you
    select the field in the Destination Fields grid. Instead, for a main table
    lookup field value to appear in the Destination Values grid, all of the
    following conditions must be met:
    u2022 The lookup table must have key mapping enabled
    u2022 The lookup field must be mapped to a source field
    u2022 The source field must contain key values for the lookup table
    u2022 The destination value must have a key on the current remote system
    u2022 The destination valueu2019s key must match a source field value
    NOTE ►► The current remote system is the remote system that was
    selected in Import Manageru2019s Connect to Source dialog (see
    u201CConnecting to a Remote Systemu201D on page 416 for more information).
    Vicky

    Hi Michael,
    Thank you very much for your response.  I'm new to SAP MDM, I need some clarification and help regarding your solution. 
    I did use two maps to load ProductMaster and ProductByRegion separately.  Here were my steps:
    1. create main table ProductMaster with key mapping enabled at the table level and set ProductCode as unique and writable once (primary key).
    2. create a map to load ProductMaster record from a staging table located an oracle database.  But Key mapping didn't show anything when I looked at them using Data Manager.
    3. create main table ProductByRegion with a lookup field looking at ProductMaster table.  This field and RegionId combines as a unique field for ProductByRegion table. 
    4. create a map to load ProductByRegion table.  But ProductCode records only shows on the source pane not destination pane and can't be mapped properly.
    My questions:
    1. How can I "Ensure that you add key mapping info for all ProductMaster records" besides enabling Key Mapping on the table level?
    2. How can I define a concatenation of ProductCode and RegionId as a REMOTE KEY"?
    Thanks a lot for your help!
    Vicky

  • 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

  • Adding the field in the internal table based on another field

    Hi all,
    I am Creating a Function module with three fields (HKONT,EBELN,DMBTR) in the output internal table(ITAB)
    My Requirement is that as soon as the value of the HKONT in the internal table changes,  i need to sum the DMBTR field values  and should pass into a variable(v_sum).
    ON CHANGE OF seems to me Obsolete.
    Please help me in doing this.
    Thanks
    Ajay

    HI,
         Use control break event . AT END OF.
         loop at ITAB.
           V_DMBTR = V_DMBTR + ITAB-DMBTR.
           at end of HKONT.
              v_sum =  V_DMBTR.
              clear : V_DMBTR.
           endat.
         endloop.
    Regards,
    Srini.

  • Populate 1 table based on another table

    I have a "VISITOR_TRACKER" application with the following 2 tables:
    VISITORS (table)
    VISITOR_ID (pk)
    F_NAME
    L_NAME
    VISITOR_DETAILS (table)
    V_DETAILS_ID (pk)
    V_TIME_IN
    V_DESTINATION
    I want to do the following:
    1. The visitor types in his/her last name in a search box.
    2. Everyone with that last name shows up in either a report or a drop-down select list. The visitor selects his/her name.
    3. A form "displays only" the name selected and has 2 text fields for the customer to enter their DESTINATION and TIME_IN and presses the submit button.
    How do I set this up? The problem I'm encountering is that if I create a form w/report off of the VISITORS table, I'm unable to populate the DESTINATION and TIME-IN because the F_NAME and L_NAME from the VISITORS table is already popluted - it is trying to populate twice.
    I tried basing the form w/report off of the VISITOR_DETAILS table but my report shows only the names that have any records in VISITOR_DETAILS. Also, the form shows the details of the VISITOR_DETAILS record that was selected.
    My report query looks like this:
    select "VISITOR_DETAILS"."V_DETAILS_ID" as "V_DETAILS_ID",
    "VISITOR_DETAILS"."VISITOR_ID_LU" as "VISITOR_ID_LU",
    "VISITORS"."F_NAME" || ' ' || "VISITORS"."L_NAME" as "NAME"
    from "VISITOR_DETAILS" "VISITOR_DETAILS",
    "VISITORS" "VISITORS"
    where "VISITOR_ID_LU" = "VISITOR_ID"
    I prefer to have a drop-down select list instead of a report if possible.
    Please help! I have been working HOURS on this?

    if you only want a duplicat of the structure and don't worry about constraints, indexes, triggers etc you could use something like this
    create table emp_dup as
    select * from emp
    where 1=0;Another more flexible way is to use the package DBMS_METADATA
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_metada.htm#ARPLS026

  • Create Materialized View  based on another database table using db link?

    SQL> SELECT sysdate
    2 FROM dual@CBRLINK ;
    SYSDATE
    21-NOV-12
    SQL> CREATE MATERIALIZED VIEW USERCBR.V_T24_COUNTRY1
    2 REFRESH COMPLETE
    3 START WITH SYSDATE NEXT SYSDATE + (5/24)
    4 AS
    5 SELECT sysdate
    6 FROM dual@CBRLINK ;
    CREATE MATERIALIZED VIEW USERCBR.V_T24_COUNTRY1
    ERROR at line 1:
    ORA-04052: error occurred when looking up remote object SYS.DUAL@CBRLINK
    ORA-00600: internal error code, arguments: [ORA-00600: internal error code,
    arguments: [qksfroFXTStatsLoc() - unknown KQFOPT type!], [0], [], [], [], [],
    ORA-02063: preceding line from CBRLINK

    It works for me:orcl>
    orcl> CREATE MATERIALIZED VIEW scott.V_T24_COUNTRY1
      2  REFRESH COMPLETE
      3  START WITH SYSDATE NEXT SYSDATE + (5/24)
      4  AS
      5  SELECT sysdate
      6  FROM dual@l1 ;
    Materialized view created.
    orcl> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for 32-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    orcl>so there is no problem with the code. HTH.

Maybe you are looking for

  • Single Sign On Authentication on SAP EP 6.0 SP15+ base on Novell

    Hi all, I saw that starting from NW SP15, the kerberos authentication for SSO on the Enterprise Portal is suggested instead of NTLM authentication with IISproxy using Windows AD as user repository. Now I have to investigate the possibility to achieve

  • Stuck processes indicating hard disk problems?

    I have had trouble with "stuck processes" on my mini 10.5.3 server since it crashed after a Retrospect back up a month ago and found an interesting piece of data this am: Using a recycled usb connected hard drive connected to the mini server, Retrosp

  • What can be causing inconsistent DVD video and audio distortions...

    Does anyone have any idea why the DVD I burn using DVD Studio Pro (from a 90-min FCP QT movie) - whether it's compressed by DVD Studio Pro, or through Compressor (with bit-rates of 4 for avg., and 7.2 for maximum) - plays with some serious simultaneo

  • Purchased on iPad Playlist not showing in iTunes

    My "Purchased on iPad" playlist is missing from the "Store" section on the left in iTunes. Is there a way to put it back?

  • Daughter's wedding is this week....

    I'm new to Photoshop Essentials.  I had the bright idea to generate a slide show of my daughter and my son-in-law.  What I want to do is put side by side pics of them together from birth to their engagement picture.  I cannot figure out how to make P