Moving records to a table based on a condition...

Hello experts,
Here is the problem.
1. select all records from table ztm0019 and put it in internal table t_ztm0019_tmp.
2. sort t_ztm_acc_variance by sernr(serial no), datum in descending order and uzeit also in descending order.
3. now loop t_ztm_acc_variance and at every new sernr, check whether its bwart is either 702, 708, 712, 718. Now if it is, move all of it(of the same serial no) into another table named t_ztm0019_tmp but if its bwart is not equal to the bwarts above then leave the first record and move all the remaining(with same serial no) in t_ztm0019. And then all the records that satisfied the condition must be deleted from the source table which is ztm0019.
4. all the records of t_ztm0019_tmp would now be inserted to table ztm_acc_variance.
example:
     SERNR        BWART
   123456         702
   123456         701
   123456         708
   123456         707
   222222         702
   222222         701
So at every new sernr in the loop it must check whether the bwart is either 702, 708, 712, 718. If it is, then move all of the records with same sernr(123456) and so on. but if it is like this:
    SERNR        BWART
   123456         701
   123456         702
   123456         701
   123456         718
the first record should be retained and the 2nd to last record(of the same sernr) must be moved.
Help would really be appreciated. Thank you very much guys!

1.
DATA  t_ztm0019_tmp LIKE TABLE OF ztm0019 WITH HEADER LINE.
SELECT *
FROM ztm0019
INTO TABLE t_ztm0019_tmp.
2.
SORT t_ztm_acc_variance BY <b>sernr ascending datum uzeit descending.</b>
3.
<b>DATA is_new TYPE i.</b>LOOP AT t_ztm_acc_variance.
AT NEW sernr.
IF bwart EQ '702' OR
   bwart EQ '708' OR
   bwart EQ '712' OR
   bwart EQ '718'.
is_new = 1.
LOOP AT t_ztm_acc_variance WHERE sernr = t_ztm_acc_variance-sernr.
IF sy-subrc EQ 0.
APPEND t_ztm_acc_variance TO t_ztm0019_tmp.
DELETE t_ztm_acc_variance.
ENDIF.
ENDLOOP.
ENDAT.
IF is_new EQ 1.
APPEND t_ztm_acc_variance TO t_ztm0019_tmp.
DELETE t_ztm_acc_variance.
ENDIF.
AT END OF sernr.
is_new = 0.
ENDAT.
ENDLOOP.
4.
CLEAR ztm_acc_variance[].
APPEND LINES OF t_ztm0019_tmp TO ztm_acc_variance.

Similar Messages

  • How to update records in a table based on user selection..

    Hi all,
    This time the above doubt is totally based on the logic of coding which I tried a lot but didn't get any solution. so atlast I come to sdn site.
    please help..
    The requirement is like that I have a table with 6 fields (1 primary key and other are nonkeys). If the user inputs some values in the fields on the screen, then a row will be added in the table. Upto this i have done well. but when the user want to change some value  in the existing row of the table my program unable to do so. Because I couldn't get any logic to do that as there are 5 nonkey fields, so if any one field is modified then the respective row should be selected first based on the user selection and then it should be updated.
    At this point I could not get any idea as it may take a lots of if conditions (I guess) to reach to that particular row.
    Please help..
    thanks ,
    sekhar

    Hi Sekhar,
    I am afraid, the whole design of your program is wrong, let me explain
    Let us say you have two rows(5 non key fields) that the user wants to update and the data in these five non key fields are identical and in your program you are getting a number(which is the key) using a number range object. So you will have two entries in the table for the same data.
    And on the update page when the user enters the non key fields, how will the program know(or for that matter any one of us) which record to pick, if you have two identical books and if asked for a book wouldn't you ask which one among these two do you want?
    Possible Solution: Identify a possible key maintaining the integrity of the data, that is a combination of the non key fields which will help you identify a unique row and make these fields as key fields in the table.
    A more costly solution(if you do not want to change the non key field keys to key fields) would be to, adding a check(using select statement) to see if the non key fields combination already exists in the Z table before inserting a record into the table.
    If yes, throw a message to the user and just update the values in the table, else insert the record.
    Another solution would be to, use the non key fields to generate a key(using some logic) and using this instead of the number range object.
    regards,
    Chen

  • Deleting records in a table based a collection

    I wanna delete records in a table which do not match the records in the collection.
    Since the collection is a pl/sql collection I cannot do it like
    v_t v_type;
    DELETE FROM sample WHERE flex_name NOT IN (SELECT * FROM TABLE(v_type(SELECT * FROM v_t)));
    is there any other alternative to do the same ?

    Hi
    please use this code it is working
    DATA :
       BEGIN OF fs_itab,
          first(2) TYPE c,
          second TYPE c,
          third TYPE c,
          fourth(2) TYPE c,
       END OF fs_itab.
    DATA :
    t_itab LIKE STANDARD TABLE OF fs_itab.
    CLEAR fs_itab.
    fs_itab-first = 'AA'.
    fs_itab-second = 'Z'.
    fs_itab-third = 'Y'.
    fs_itab-fourth = 'AA'.
    APPEND fs_itab TO t_itab.
    CLEAR fs_itab.
    fs_itab-first = 'AA'.
    fs_itab-second = 'Z'.
    fs_itab-third = 'Y'.
    fs_itab-fourth = 'AA'.
    APPEND fs_itab TO t_itab.
    CLEAR fs_itab.
    fs_itab-first = 'AA'.
    fs_itab-second = 'Z'.
    fs_itab-third = 'Y'.
    fs_itab-fourth = 'CC'.
    APPEND fs_itab TO t_itab.
    CLEAR fs_itab.
    fs_itab-first = 'BB'.
    fs_itab-second = 'P'.
    fs_itab-third = 'Q'.
    fs_itab-fourth = 'DD'.
    APPEND fs_itab TO t_itab.
    CLEAR fs_itab.
    fs_itab-first = 'BB'.
    fs_itab-second = 'P'.
    fs_itab-third = 'Q'.
    fs_itab-fourth = 'BB'.
    APPEND fs_itab TO t_itab.
    LOOP AT t_itab INTO fs_itab.
      IF fs_itab-first NE fs_itab-fourth.
        DELETE TABLE t_itab FROM fs_itab.
      ENDIF.
    ENDLOOP.
    LOOP AT t_itab INTO fs_itab.
      WRITE :
         / fs_itab-first,
           fs_itab-second,
           fs_itab-third,
           fs_itab-fourth.
    ENDLOOP.
    Regards
    Pavan

  • Dropdown editable in a table based on a condition

    Hi,
    I would like to know how to solve these problems.
    1. I have a cell (of the type dropdown by key) in a table, which is editable or not, depending on a condition ? Is this is possible? Please let me know if there is a sample code
    2. So basically I have a  table that has 2 entries in it, user details and one of the fields in FLAG showing the values Yand N for the user. I want the table in the webdynpro application to show the 2 user entries and then in the Flag column have a DROPDOWNBYKEY that DEFAULTS to showing what flag the user has, but also allows the user to CHANGE the entry.
    Thanks in advance
    I appreciate for the help.

    is possible
    In your Context node which is binded to the table as DataSource, add an attribute WDY_BOOLEAN type
    In layout bind the newly created attribute to the dropdown UI element Enable property
    while filling your context node, fill the attribute with abap_true and abap_false based on your condition
    Abhi

  • Show or Hide empty table based on If condition

    I want to show or hide empty table based on condition. The table will be empty with 5 rows,2 cols and should display if <?Rout_Information1_id1?> is blank or null or when XML field is not present. Actually the JDEdwards report will generate XML file. In the XML file if <?Rout_Information1_id1?> is present it will have definitely value like 'PULL' or 'Cut' otherwise sometimes XML field itself will not be present. Need to display the empty table when the <?Rout_Information1_id1?> is not present. I am trying to do as below but the table is not displayed. Can someone tell me how to resolve this.
    <?if:Rout_Information1_id1=' '?>
    5 rows,2 cols table
    <?end if?>
    Thanks,
    Vijay Vattiprolu

    Ok. I used the below syntax from other post and it resolved displaying empty table issue.
    <?if:not(XML_TAG_NAME)?>
    <?end if?>
    Thanks,
    Vijay

  • Inserting millions of records into new table based on condition

    Hi All,
    We have a range partitioned table that contains 950,000,000 records (since from 2004) which is again list sub-partitioned on status. Possible values of stauts are 0,1,2,3 and 4.
    The requirement is to get all the rows with status 1 and date less than 24-Aug 2011. (Oracle 11g R2).
    I trying below code
    CREATE TABLE RECONCILIATION_TAB PARALLEL 3 NOLOGGING  
    AS SELECT /*+ INDEX(CARDS_TAB STATUS_IDX) */ ID,STATUS,DATE_D
    FROM CARDS_TAB
    WHERE DATE_D < TO_DATE('24-AUG-2011','DD-MON-YYYY')
    AND STATUS=1; CARDS_TAB has tow global indexes one on status and another on date_d.
    Above query is running for last 28Hrs! Is this the right approach?
    With Regards,
    Farooq Abdulla

    You said the table was range partitioned but you didn't say by what. I'm guessing the table is range partitioned by DATE_D. Is that a valid assumption?
    You said that the table was subpartitioned by status. If the table is subpartitioned by status, what do you mean that the data is randomly distributed? Surely it's confined to particular subpartitions, right?
    What is the query plan without the hint?
    What is the query plan with the hint?
    Why do you believe that adding the hint will be beneficial?
    Justin

  • Insert into a final table based on a condition

    Hi,
    create table table1(invoice_number varchar2(4), covg_date date, employee_number varchar2(5),
    service_option varchar2(2), FEES VARCHAR2(5), AMOUNT NUMBER(9,2));
    insert into table1 values('1','01-JUL-2011','11','8','F1,F2',100);
    insert into table1 values('2','01-JUL-2011','12','2','F1,F2',110);
    insert into table1 values('3','01-JUL-2011','13','9','F1,F2',120);
    insert into table1 values('4','01-JUL-2011','14','3','F1,F2',130);
    commit;
    create table table2(invoice_number varchar2(4), covg_date date, employee_number varchar2(5),
    service_option varchar2(2),FEES VARCHAR2(5), AMOUNT NUMBER(9,2));
    insert into table2 values('1','01-JUL-2011','11','88','F1,F2',100);
    insert into table2 values('2','01-JUL-2011','12','2','F1,F2',110);
    insert into table2 values('3','01-JUL-2011','13','9','F1,F2',122);
    insert into table2 values('4','01-JUL-2011','14','3','F1',130);
    insert into table2 values('4','01-JUL-2011','15','3','F1',130);
    commit;
    create table final_table(insert_type varchar2(1),invoice_number varchar2(4), covg_date date, employee_number varchar2(5),
    service_option varchar2(2),FEES VARCHAR2(5), AMOUNT NUMBER(9,2));we need to insert into final_table based on the differences between table1 and table2. The condition for that is:
    Eg: For a given employee number(11) for a given covg_date(July-2011), if there is at least one difference in any column value which in this case is the service_option (8,88)..
    i need to insert table1 record into final_table with insert_type as 'OLD'
    and insert table2 record into final_table with insert_type as 'NEW'
    Similarly employee number 14, there is a difference between fees column and i should insert them like the above example
    Similarly employee number 13, there is a difference between AMOUNT column and i should insert them like the above example.
    For example employee number 15, there is no record in table1 but exists in table2 and that will be inserted as it is..
    What my idea was to loop through distinct employee_number, covg_date in table1 and check each value in table2 for the same condition and insert into final_table..
    But if there is a better option like inserting directly using select clause or some sort of direct insert without loop...
    Thanks for the help in advance

    Possibly a modified version of something like this:
    INSERT INTO final_table
    ( insert_type
    , invoice_number
    , covg_date
    , employee_number
    , service_option
    , fees
    , amount
    SELECT insert_type
         , invoice_number
         , covg_date
         , employee_number
         , service_option
         , fees
         , amount
    FROM   (
         SELECT invoice_number
              , covg_date
              , employee_number
              , service_option
              , fees
              , amount
              , 'OLD' AS insert_type
         FROM   table1
         MINUS
         SELECT invoice_number
              , covg_date
              , employee_number
              , service_option
              , fees
              , amount
              , 'OLD' AS insert_type
         FROM   table2
         UNION ALL
         SELECT invoice_number
              , covg_date
              , employee_number
              , service_option
              , fees
              , amount
              , 'NEW' AS insert_type
         FROM   table2
         MINUS
         SELECT invoice_number
              , covg_date
              , employee_number
              , service_option
              , fees
              , amount
              , 'NEW' AS insert_type
         FROM   table1
    WHERE  employee_number = :emp_number
    AND    covg_date       = TO_DATE(:date_string,'MM/DD/YYYY')
    ;

  • Insert data in same table based on some condition

    Hi. I am new to this forum.
    I have to write a stored procedure to Insert Data into a table say MYTABLE ,having structure as:
    Col1 Col2 Col3 ................ TotalInstallments CurrentInstallment PaidAmount MonthYear
    I have to insert all the data as it is in the same table(MYTABLE) except changing some fields on basis of some conditions:
    1. if PaidAmount>0 && CurrentInstallment<TotalInstallment then
    CurrentInstallment=CurrentInstallment+1
    2. In the MonthYear field I am having data in formate(month/year)ex. 01/2012, 11/2012 ....
    So I have to insert data by incrementing month and year. for example:
    if currentdata is 11/2012 then next data will be 12/2012
    But next will be 01/2013
    I have to select all the records which belongs to previous month(through MonthYear field ) and put checking & changes on each record of the selected data and then insert them into same table(MYTABLE).
    How to achive that?
    Thanks.

    978184 wrote:
    Every thing is working fine but some strange result as:
    when i run my Procedure TRANSFERDATATONEXTMONTH
    1. by Passing Value as : CUSTOMERID_var ='ABX101' and MONTHYEAR_var='12/2012' it insurts 5 rows
    which is correct , since I have 5 records where CUSTOMERID='ABX101' and MONTHYEAR='12/2012' and
    new 5 rows has CUSTOMERID='ABX101' and MONTHYEAR='01/2013' (all other values are as expected)
    2. now when i again run by passing values: CUSTOMERID='ABX101' and MONTHYEAR='01/2013' it inserts 10 records(just double )
    and new records has value CUSTOMERID='ABX101' and MONTHYEAR='02/2013' (while on the basis of condition CUSTOMERID='ABX101' and MONTHYEAR='01/2013' i have in my table only 5 records)
    and all records are duplicate. Some times it inserts three times , while on condition basis it should no. What is happening?Probably, meanwhile you were trying to Insert the First time and the second time, someone did run the procedure that Inserted 5 More records for 01/2013. And, hence your Second run inserted 10 records instead of 5.
    >
    Why it is inserting double of records while i have only 5 records on given condition? Am I missing some thing?Yes, you are. You are missing your Tables, Your Dummy/Sample Data, Working Procedure/Function that can be replicated.
    Without this, we cannot simply believe on assertions that Oracle is behaving incorrectly.
    In addition to this, the GetMonthYear function, should be scrapped. It is un-necessary, when the same logic can be achieved using Oracle ADD_MONTHS function (See my previous post). And you are storing the MonthYear in a Varchar field, which ideally should be a Date field. This eradicates the un-wanted need to cast from VARCHAR - DATE - VARCHAR.
    Please do make some time to read {message:id=9360002} and mentioned relevant details.
    And notice, the code difference in my previous post and in your code.
    Please use
    {noformat}
    (exactly as shown) above and below your code, that indents the code properly for better readability.
    {noformat}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Records to be saved based on some condition

    hi all,
    i am using form6i.
    i have multi record block. i should allow the user to update the record based some condtion.
    my question is where to write the update statement and how to check the condition(i have to check for process_type = 'H' and status = '1,2,3' etc..)
    I am new to this type of requirement. please help me.
    Thanks..

    Hello,
    Better is to avoid the end user to update records that are not allowed.
    In the When-New-Record-Instance trigger, you can set the UPDATE_ALLOWED to true or false depending on any condition, via the Set_Item_Instance_Property() trigger (see the doc)
    Francois

  • Selecting a value to a column from a different table based on a condition

    I apologize for the confusing title.
    I have to select values from Table_1. 2 of those columns needs to be checked for values in Table_2 based on the ID and if values are present, then those values should be taken, if not the values from Table_1 should be taken. How can I achieve this?
    e.g.
    table_1
    date
    id
    fact1
    fact2
    type
    table_2
    id
    fact1
    fact2
    select date,id,type, (Need to check the condition for fact1 and fact 2, if present in table_2, then that value should be used, if not table_1 values should be used) from table_1 and table_2.
    I need to use this condition in another big query. Any help/suggestions appreciated.
    Thanks.

    Thanks Tubby,
    It worked and I incorporated with the master query too.
    Thanks a lot.
    EDIT
    Thanks for all the replies> I just saw your answers after I finished and posted the reply.
    hoek, I am not a DB person, I used to write some SQLs, but not in the last 3 years or so. I am trying to work on some reports, hence some trivial questions.
    Edited by: vj on Aug 7, 2010 5:48 PM

  • ADF -- Dynamic InlineStyle on cells of table based on specified conditions.

    Hi there!!
    I am trying to figure out Dynamic Inline Style on cells in ADF:
    Need to color a few columns for a particular row (don't wanna color the entire column--just want to color those cells in columns that matches the specified condition for that particular row, in MY CASE:- row: having Col-A ="BBB" column: having value>250 ).
    Col-A Col-B Col-C Col-D
    AAA 100 255 300
    BBB *255* *300* 100
    I want to color the cells in BOLD....
    My basic condition:- Col-A = 'BBB' and other col values >250
    Can anyone help me out with this???

    Hi,
    try as following
    <af:inputText contentStyle=#{row.bindings.Col-A.inputValue eq 'BBB' and (row.bindings.Col-B.inputValue gt 250 or row.bindings.Col-C.inputValue gt 250 or row.bindings.Col-D.inputValue gt 250) ? 'font-weight:bold;':''}"/>
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to get count as 0 for records not in table

    Hi All,
    I have requirement where I need count of records in the table based on ids. Example query below
    SELECT empid ,
    nvl(COUNT(id), 0) empcount
    FROM employee
    WHERE empid IN(1, 2, 4, 5)
    GROUP BY empid
    In the table only record for "empid=2" is present so I get count 1 for it. But with it I should get count as 0 for non existing records. Expecting below output
    empid | empcount
    1 | 0
    2 | 1
    4 | 0
    5 | 0
    Appreciate your help and Thanks in advance.
    Regards.
    Ashish

    e.g.
    SQL> select column_value deptno, count (deptno)
    from emp, table (sys.odcinumberlist (10, 20, 100))
    where deptno(+) = column_value
    group by column_value
        DEPTNO COUNT(DEPTNO)
            10             3
            20             5
           100             0
    3 rows selected.

  • To delete duplicate records from internal table

    hi friends,
    i have to delete records from internal table based on following criterion.
    total fields are 7.
    out of which  if 4 fields are same and 5th field is different,then both records must be deleted.
    in case all five fields are same,the program should do nothing.
    for example.
    if there are 3 records as follows
    a1 b1 c1 d1 e1 f g
    a1 b1 c1 d1 e2 w r
    a1 b1 c1 d1 e1 j l
    then first two records should be deleted as four fields are same but fifth(e) field differs.
    but third record should remain as it is evenif first five fields are same for first and third record.
    values of last two fields need not to be consider for deleting the records.

    LOOP AT ITAB.
      V_FILED5 = ITAB-F5. "to compare later
      V_TABIX = SY-TABIX. "used to delete if condition not matches
      READ TABLE ITAB WITH KEY F1 = ITAB-F1
                               F2 = ITAB-F2
                               F3 = ITAB-F3
                               F4 = ITAB-F4.
      IF SY-SUBRC = 0.
        IF ITAB-F5 <> V_FIELD5.
    *--both the records to be deleted,as Field5 is different.
          DELETE ITAB INDEX SY-TABIX. "deletes that record
          DELETE ITAB INDEX V_TABIX. "deletes the current record
        ENDIF.
      ENDIF.
    ENDLOOP.
    Message was edited by: Srikanth Kidambi
    added comments
    Message was edited by: Srikanth Kidambi

  • Extracting from table based on conditions from two internal tables

    Hi,
         i to have select few records from  a table based on conditions from two different internal tables. How can I achieve this.?
    ex:
          select objid from HRVPAD25 into table t_pad25
                                                    where PLVAR = 01
                                                                OTYPE = E
                                                                OBJID = itab1-sobid
                                                                sobid = itab2-pernr.
    How can this be written? can i use "for all entries..." addition with 2 tables?

    Hi Maansi_SAP,
    you can use exactly one internal table in the FOR ALL ENTRIES clause. Consider this alternative:
    data:
      itab_sobid_hash like itab1 with unique key sobid,
      ls_pad25  like line of  t_pad25.
    sort itab1.
    delete adjacend duplicates from itab1 comparing sobid.
    itab_sobid_hash = itab1.
    select objid
      into ls_pad25
      from HRVPAD25
      for all entries in itab2
      where PLVAR = '01'
        and OTYPE = E
        and sobid = itab2-pernr..
    read table itab_sobid_hash with table key sobid = ls_pad25-objid.
    check sy-subrc = 0.
    append ls_pad25 to t_pad25.
    endselect.
    You may decide if itab1 or itab2 is better used as hashed table. Make a performance test.
    The critics will tell you that SELECT ... ENDSELECT is not performant. That was very true, back in last milleniums's 90ies
    Regards,
    Clemens

  • Querying a table based on a selection criteria

    Hi Gurus,
    Could you please help me in creating a function module that picks records from the table based on certain selection criteria.For eg, If contract number(a primary field) is an import parameter and I want the Function module to export all the records with contract number starting with 1 or may be ending with 303.How could I query this??
    Thanks,
    Ashwini

    Hello,
    Creation of Function Module
    Goto TCode SE37
    Click on the Menu Goto->Create Function Group
    Create Z (ZPTP) function group and Activate Function Group even if the error occurs
    Create Function module Namely Z (ZTEST) assign to the function group (ZPTP)
    Go to the Import parameters (EBLEN TYPE EKKO-EBELN)
    Go to the Tables ( itab type ekpo)
    Goto the Source code
    tables ekpo.
    Select * from ekpo into table itab
    where ebeln eq ebeln.
    Activate the function module and run the function
    regards
    suresh nair

Maybe you are looking for

  • Spelling Errors In Mail Are Not Highlighted As I Type

    Hi, I have 'Check Spelling As I Type' enabled in Preferences in Mail, however my spelling errors are not highlighted (underlined in red) as I type. This feature used to work but for some reason no longer does - not sure if this is attributable to rec

  • I downloaded yosemite now can't get my new emails

    Hi All' I downloaded Yosemite, and now find I can't get my new emails. When I logged on my little notification popped up in the right hand corner of my screen showing i had 11 new emails, so I opened mail as usual and the emails are not there. Any id

  • How can i get a copy of my receipt from a FuelBand SE?

    I lost my original receipt. But my FuelBand doesn't work. I am able to configured the FuelBand whe is connected to the PC, but at the time to put on my wrist and push the button, nothing happens. Do I need the receipt to ask for the warranty??? I wil

  • Upgrade from Cisco Prime infrastructure verion 2.0 to 2.1

    Request you all to please let me know if i have to install point patch before upgrading the cisco prime infrastructure 2.0 to 2.1.

  • Workflows sending duplicate emails.

    I have many workflows that send 2+ email notifications. Sometimes it's a brand new wf - or sometimes I've had a wf working fine for months, then I edit the email part (add a email address or add to email message body - NOT edit the wf) and it starts