Open SQL statment for Update flag based on Date

Dear all,
I am trying to write an Open SQL statement to update a flag in a table. Table Ztable1 with fields Sr.No, Flag, Datefrom, DateTo. i would like to update Flag entry in the table only if today falls in between Datefrom & Dateto. I can satisfy the above requirement using the following ABAP code.
DATA: lv_timestamp TYPE timestamp,
      lv_today LIKE adr2-valid_from,
      tz TYPE timezone.
CONVERT DATE sy-datlo TIME sy-timlo INTO TIME STAMP lv_timestamp
  TIME ZONE tz.
lv_today = lv_timestamp.
update ztable1 set flag = 'X' where lv_today BETWEEN datefrom and dateto.
But the issue is that, DateFrom & DateTo contains space aswell Dates. Datefrom can be space if it is start of Time (01010001) and also DateTo can be space if it is End of time (31129999). Which means that if DateFrom is space, then it should treated as 01010001, simlarly DateTo is space, then it should be 31129999. How can i write the if else cases within where clauses.
I know Decode statement in Native sql programming, but that won't fit for Opensql in ABAP. Also, because of huge entries in database, i cannot read entries, manupulate & then update.
How can i enhance the same above Update statement to cater this need.
Please advise.
Thanks a lot in advance.
Greetings, Satish

Hi,
first fetch records in to internal table.
ranges: r_range for sy-datum.
loop at itab into wa.
if wa-validfrom is initial.
wa-validfrom =  (here u pass valid from date).
elseif wa-validto is initial
wa-validto = 99991231.
endif.
r_range-low = wa-validfrom
r_range-high = wa-validto
*check here current date is falling in interval. if its fall between ranges update flas in work area and *modify you internal table
if sy-datum in r_range.
wa-flag = 'x'.
modify itab from wa.
endif.
refresh r_range.
clear wa-flag.
endloop.
*--Finally update your ztable
modify ztable from table itab.
Regards,
Peranandam

Similar Messages

  • Tables/FM for opening/closing stock for material on given posting date

    Hi All,
    I had requirement of find the opening/closing stock for material on given posting date. The values we can find out using TCode - MB5B.
    But I cannt use MB5B to extract data because I need to find detials for thousands of material.
    Can you please adivce if their is any FM or tables through which i can find this detial on any given date apart from current date.
    Thanks & Regards,

    Hi,
    [https://forums.sdn.sap.com/click.jspa?searchID=19631709&messageID=6593903]
    [https://forums.sdn.sap.com/click.jspa?searchID=19631709&messageID=6630975]

  • Error while opening SQL source for a Data Load Rules File

    Hi ,I have created Data Laod rules file.When I try to open a SQL source for this rules file (File->Open SQL) , I get an error saying "Your server does not have a SQL connection Option, Please check with your system administrator"Further I get a message "There are no data sources defined. PLease create one to continue.".I have created DSN on my Essbase server.What is the problem.What needs to done to open SQL files.Thanks.

    I have Essbase 7.1 I guess for version 7.1 the SQL interface option is intalled with the Analytic server itself .Am I right?I have setup the DSN also.Please help to resolve this issue.Thanks .

  • BADI for Updating work order component data

    Hi,
    I need to update the field special stock indicator for the work order component data when it is saved. I am using the BADI WORKORDER_UPDATE for the same, but when I implemented the ZWORKORDER_UPDATE_IM using the standard defenition  WORKORDER_UPDATE , the code does not allow me to change the it_component internal table belonging to the BEFORE_UPDATE method. Could you please help me in this.
    Basically if we are implementing a standard defenition how to change the parameters of the methods in it.
    Regards,
    Prabaharan.G

    Hi ,
    It is giving the below dump. The parameter is importing parameter and it does not allow to change even using field symbol. Is there any other way. Is there an user exit which will be called when pressing enter button in component screen. The exit EXIT_SAPLCOBT_001 did not work for this.
    Error analysis                                                                     
        The program tried to assign a new value to the field "<F_FS1>" even though     
        it is protected against changes.                                                                               
    The following objects are protected:                                           
        - Character or numeric literals                                                
        - Constants (CONSTANTS)                                                        
        - Parameters of the category IMPORTING REFERENCE for functions                 
          and methods                                                                  
        - Untyped field symbols to which a field has not yet been assigned             
          using ASSIGN                                                                 
        - TABLES parameters if the corresponding actual parameter is protected         
          against changes                                                              
        - USING reference parameters and CHANGING parameters for FORMs if              
          the actual parameter for this is protected against changes    
    Regards,
    Prabaharan.G

  • Updating tables based on Dates

    In my application I use some tables with a date field.
    table: employee
    period date (e.g. 01-01-2004, 01-02-204, 01-03-2004)
    target money
    result money
    table: project
    date date (e.g. 15-01-2004, 20-01-2004, 03-02-2004)
    revenue money
    If I book a new project the table employee should be updated with result = result + revenue. If there is a new project on 15-01-2004 the record in employee where period = 01-01-2004 should be updated.
    Can someone help me with a sample code for this problem?

    Assuming you have a block in the form call PROJ with fields DATE, REVENUE and EMP_NO. Also that a record exists for the employee and period date.
    Create PRE-INSERT and PRE-UPDATE triggers on the block PROJ containing
    begin
    update employee
    set result=result+:PROJ.REVENUE
    where period_date=trunc(:PROJ.DATE,'Mon')
    and emp_no=:PROJ.EMP_NO;
    end

  • Sql code for authorizing senior staff after data was inserted in the table

    Dear sirs/madams,
    Sub:
    I am using oracle9i/forms6i/reports6i and developing software for rural bank,
    I need sql/procedure/function code for authorizing senior staff after data was inserted in to the table by the junior staff.
    Thanks in advance for your kind help.
    R. Chandrasekar
    e-mail: [email protected]

    So basically you want a form (only accessible by senior staff) which reads the data entered by junior staff and when it is has been validated by senior staff
    does the following in one transaction:
    This is in effect a design question.
    There are two different scenarios I see. Approve transactions in bulk, or approve individual transcations.
    Approve transactions in Bulk:
    Mark a column with approved.
    Move all approved into final table;
    delete all transactions from temp_table which are in final_table;
    commit;
    approve/move individually.
    insert transcation x into final_table where transaction_x in temp_table;
    delete transaction_x from temp_table;
    commit;
    Its basically up to you how you design it.

  • Autofill dates for a week based on date selected...

    If I have a table that has Monday-Friday on it and I want to select the date on Monday and have it fill in the dates for the rest of the week, how would I do that. Or is there a way so that when it is opened on Monday, it inputs the date into the cell for Monday, then on Tuesday when it is opened, it inputs the date into the cell for Tuesday without changing the date in Monday's box? Either way is fine with me. Thanks!

    Here's a sample. https://workspaces.acrobat.com/?d=bWS4uDJgJKsWM8USbHsuKg
    In the Week Ending field you select the date - in this case it is checking to make sure that a Saturday is selected. From there it fills in the dates for the fields.

  • Problem  for updating records in to data targets

    Murali/sreenivas.
    my processchain is working fine ..but upto Persistent Staging Area data is getting updated perfectly but after that daily i need to run
    DTP manually , to avoid this what sholud i do??? i.e.
    selecting particular info source and then Persistent Staging Area and then selecting particular request in PSA and selecting
    update with scheduler.... by rightcliking on that... and then
    after selecting this and then selecting immediate update...then Persistent Staging Area  data is getting updated in to particular data targets...
    i want to the data to be updated immediately once data is succefully reached Persistent Staging Area
    Edited by: ganandkumar on Sep 13, 2010 7:15 AM
    Edited by: ganandkumar on Sep 13, 2010 7:16 AM

    Hi,
    Are you using BW 3.5 or BI 7.0.
    If you are in BW ,then please in the infopackage make the setting psa and data target in parallel.
    If you are in BI 7.0,then include the step DTP.
    Thanks,
    Saveen Kumar

  • Tyring to dynamically create SQL statment for an SQL Calendar

    Is there a way to dynamically create an SQL statement that an SQL Calendar would use. I don't see an option to create a PL/SQL Calendar.
    For example I want to pass a table name, and the corresponding date column to items on the calendar page, and then have the SQL Calendar use those to fields to display the number of records loaded into the specified table. I've written the following but it doesn't work:
    'SELECT count(*), ' || :P8_SOURCE_DATE || ' FROM ' || :P8_SOURCE_TABLE || ' GROUP BY ' || :P8_SOURCE_DATE;
    Does anyone know if there is a why to create a PL/SQL Calendar?

    Jason,
    it is possible, though not so simple as with a report.
    What you need to do is to create a pipelined function, that returns your date and count data. This pipelined function can be the base of a pseudo-table, which can be used in a select. For the pipelined function you need to define types for one row and a table to define the return-type for your function:
    create or replace type calendar_row as object (date_time date, description varchar2(250));
    create type calendar_table as table of calendar_row;
    Then you can create the package with the function:
    ================================================
    create or replace package dyn_calendar is
    procedure set_query(i_query in varchar2);
    function view_source return calendar_table pipelined;
    end;
    create or replace package body dyn_calendar is
    v_query varchar2(100) := null;
    procedure set_query(i_query in varchar2) is
    begin
    v_query := i_query;
    end;
    function view_source return calendar_table pipelined is
    TYPE cursor IS REF CURSOR;
    c_cal cursor;
    v_date_time date := null;
    v_description varchar2(100) := null;
    r_cal calendar_row;
    begin
    open c_cal for v_query;
    fetch c_cal into v_date_time, v_description;
    loop
    exit when c_cal%notfound;
    r_cal := calendar_row(v_date_time, v_description);
    pipe row(r_cal);
    fetch c_cal into v_date_time, v_description;
    end loop;
    return;
    end;
    end;
    ================================================
    Now you can set query in a PL/SL region before the calendar:
    dyn_calendar.set_query(SELECT count(*), ' || :P8_SOURCE_DATE || ' FROM ' || :P8_SOURCE_TABLE || ' GROUP BY ' || :P8_SOURCE_DATE);
    and you can base your calendar on the query:
    select * from table(dyn_calendar(view_source))
    Good luck,
    Dik

  • Form on SQL query for updating.

    Hello again,
    Im trying to wirte a form to udapte the information in a table. I have a table with a PK which holds a persons name, and an activity assigned to them (and loads of other fields but they dont matter atm). I would like to have a form which has an SQL query running in one region and then the form underneath to be able to edit (reassign a person to a different activity) an item appearing in the query result. Ive got a form at the moment which is form on an sql query but its not updating when i fill out the form, is it something to do with the regions?
    http://img.photobucket.com/albums/v611/Funky_Monk/untitled.jpg
    So on the screenie, i have the bottom region for the query (no values in table hence the error (i think!))
    The call ID is FK to another table
    severity level and status will be usdated here
    description is self-explanitory
    analyst_id is the main field to be changed here, the call id will be assigned a new analyst via this form.
    action_id is actions carried out on this problem.
    Any help would be greatly appreciated.
    DM

    hi,
    Can you put this example on apex.oracle.com?
    Regards,
    Kartik Patel
    http://patelkartik.blogspot.com/
    http://apex.oracle.com/pls/apex/f?p=9904351712:1

  • [Solved partially] Sql query for updates compliance

    Hello
    I'm trying (with no success) to translate the "Software+Updates+-+A+Compliance%2fCompliance+1+-+Overall+compliance" report into a sql query that must run for a specific
    Software update group and for a specific Collection ID.
    The expected result should be like the report it self, I mean 3 lines with Kpi (pourcentage).
    The main query in this report is : 
    select
    CollectionID=@CollID,
    Status=sn.StateName,
    cs.NumberOfComputers,
    PComputers=convert(float, isnull(cs.NumberOfComputers, 0)*100.00) / isnull(nullif(cs.NumTotal, 0), 1),
    AuthListID=@AuthListID
    from (select CI_ID, NumTotal, [0]=NumUnknown, [1]=NumPresent+NumNotApplicable, [2]=NumMissing
    from fn_rbac_UpdateSummaryPerCollection(@UserSIDs)
    where CI_ID=@CI_ID and CollectionID=@CollID
    ) cnt
    unpivot (NumberOfComputers for [Status] in ([0], [1], [2])) cs
    left join fn_rbac_StateNames(@UserSIDs) sn on sn.TopicType=300 and sn.StateID=cs.Status
    where cs.NumberOfComputers>0
    order by cs.NumberOfComputers desc
    I have no clue on how to replace or use fr_rbac view when run outside a report.
    Can you please help me ?
    Thanks

    Hi,
    Glad to hear that and thank you for your sharing.
    Best Regards,
    Joyce
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • SQL query for updating values in same cell of a table

    Hi All,
    I'm stuck with a problem and it stands as follows:
    Table name: Track
    Part1  Part2  Part3
    NULL   NULL   NULL
    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,); it should not be overwritten, neither they should appear in separate row, in fact they should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    The new values of Part1 should appear in next row only when value of Part3 changes, so if Part3 changes from SUBM1 to SUBM2, it should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    1,2,3    5          SUBM2
    Count of values in Part1 never exceeds the value of Part2, so if Part2 is 5, then Part1 will look like 1,2,3,4,5. So in other words loop will run only up to the value of Part2.
    Please advise how this could be achieved?
    Kind regards,
    Aniruddha Jagdale

    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,);
    No, don't go there.
    This breaks a fundamental point for relational databases: no repeating groups. A cell should hold an atomic value. And this is not only a matter of purism. Relational databases are designed from this principle, and breaking this means that you will need
    to write complex and higly inefficient code.
    The values in Part1 should be in a separate table, with one value per row.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • SQL Query for update

    hi experts
    I got two tables
    BOOK (DDC,TITLE,ISBN,AUTH_NAME)
    AUTHOR (ID,DDC,AUTH_NAME)
    AUTH_NAME column in BOOK's table contains NULL for all records.
    I want update table BOOK's column AUTH_NAME from AUTHOR's column in AUTHOR table where DDC numbers match. DDC is not unique in AUTHOR's table. I want to update BOOK table with the first matching AUTH_NAME. Rest should be ignored.
    Please write me the query for it.
    thanks

    Please write me the query for it.This fellow has no questions.
    Please, DO NOT ANNOY HIM with hints and tips, he just wants his answer. ; )
    I suspect it's homework, just another cheating student, earning his OCP.
    He is very anxious to get somebody to do his work, as he has spammed this same questtion on several other Oracle forums:
    http://dba.ipbhost.com/index.php?showtopic=10441
    http://www.dba-village.com/village/dvp_forum.OpenThread?ThreadIdA=32264

  • Sql advice for updating a table.

    Hello Wonderful guru's,
    (I am running Oracle 10g 10.1.0.2.0 on Linux AS3) I am stuck trying to delete a user from a user table when the user has not logged into "a software application" for 90 days. The tables are USER: (userid V2(15), name V2(50),password V2(30),update_date date, password_expire_date date, blocked V2(1)).
    Other table is LOCATION_HISTORY: (Location_id Number(3),Userid V2(15),Login_Date Date).
    I have a trigger that populates the Location_history table every time someone logs in to the software that populates who,when and where for each login- there are multiple login dates per id.
    I need to check if the max(Login_date) is 90 days from the sysdate, and if so then delete the userid from the USER table- because the user has not logged in for 90 days, therefore the account is not "active" enough to keep.
    I have an idea how to do it as follows:
    delete from user where (select userid, max(login_date) from location_history where max(login_date) = sysdate-90;
    But I am wondering if I am getting the logic right. I was going to run this sql as a cron job every night after midnight.
    Can you offer me advice to whether I am approaching this from the right angle?
    Thank you in advance for any advice- I do not have anyone to bounce stuff like this off of.

    user542952 wrote:
    delete from user where (select userid, max(login_date) from location_history where max(login_date) = sysdate-90;If that is your logic you can create a job in the Oracle Database itself which will run every day or any frequency you wish to execute the job.
    The package you can use is DBMS_JOB or DBMS_SCHEDULER
    DBMS_SCHEDULER is preferred and it is available in the version you have mentioned.
    [ Documentation | http://download.oracle.com/docs/cd/B14117_01/appdev.101/b10802/d_sched.htm#1012994]
    SS

  • SQL solution for timestamp range based records

    Hi, lets say I have a record on 10.2 Oracle database:
    2011-08-18 12:53:35     2011-08-20 02:53:35
    I want to retrieve via single SQL three records from this record like:
    2011-08-18 12:53:35     2011-08-19 00:00:00
    2011-08-19 00:00:00     2011-08-20 00:00:00
    2011-08-20 00:00:00     2011-08-20 02:53:35
    Is this possible, thanks & regards.

    WITH DATA AS (SELECT TO_DATE('2011-08-18 12:53:35','YYYY-MM-DD HH24:MI:SS') df, to_date('2011-08-20 02:53:35','yyyy-mm-dd hh24:mi:ss') dt from dual)
    select greatest(df,trunc(df) + (rownum-1)) date_from
    ,least(dt,trunc(df) + (rownum) - 1/86400) date_to
    from data
    connect by rownum <= (trunc(dt+1) - trunc(df))
    hth

Maybe you are looking for