‎2006 Jun 13 11:00 PM
Hi,
i need to select entires from a table based on year which i determine dynamically.
for eg w_year = '2006'.
I'm looking for something like this
select * from dbtable into .....where date like w_year%.
can someone help me out .
Thanks,
venu.
‎2006 Jun 13 11:18 PM
This is what you need.
DATA: BEGIN OF where_clause OCCURS 0,
clause(72).
DATA: END OF where_clause.
CONCATENATE w_year
'%'
INTO where_clause-clause.
CONDENSE where_clause-clause NO-GAPS.
CONCATENATE 'DATE LIKE'
where_clause-clause
INTO where_clause-clause SEPARATED BY SPACE.
SELECT * FROM dbtable WHERE (where_clause).Message was edited by: Srinivas Adavi
‎2006 Jun 13 11:03 PM
Hi Venu,
I really dont see need of dynamic select.
Once you have the value of year, you can directly put it in the 'where' conddition of select statement.
Cheers,
Vikram
Pls reward for helpful replies!!
‎2006 Jun 13 11:05 PM
hi Venu,
Why do you want to select the year dynamically??? once the year gets populated to the field(w_year) then use the field(w_year) in the select statement.
i.e,
w_year = 2006.
select * from dbtable into .....where <b>date = w_year</b>.
Regards,
Santosh
‎2006 Jun 13 11:05 PM
You build dynamic select if you derive the table or where conditions at run time. I dont see any need for the synamic select here.
‎2006 Jun 13 11:10 PM
Hi,
appreciate your response. the year field in the table contains yyyymmdd but i have yyyy (in this ex 2006 = w_year) thats the reason i want to use ..where year like W_year% this will be called multiple times based on w_year.
hope i'm clear. your help will be rewarded
Thanks,
venu.
‎2006 Jun 13 11:13 PM
in that case do this way
w_year = field(yyyymmddformat) + 0(4).
now use this variable in the select.
i.e,
select * from dbtable into .....where date = w_year.
Regards,
Santosh
‎2006 Jun 13 11:15 PM
Hi Venu,
Declare internal table itab to hold data from dbtable.
You can try like this :
*Code starts
select * into itab from dbtable.
loop at itab.
if itab-year CP w_year.
continue.
else.
delete itab.
endif.
endloop.
*Code ends
finally itab has all the relevant records from dbtable.
Cheers,
Vikram
Pls reward for helpful replies!!
‎2006 Jun 13 11:18 PM
This is what you need.
DATA: BEGIN OF where_clause OCCURS 0,
clause(72).
DATA: END OF where_clause.
CONCATENATE w_year
'%'
INTO where_clause-clause.
CONDENSE where_clause-clause NO-GAPS.
CONCATENATE 'DATE LIKE'
where_clause-clause
INTO where_clause-clause SEPARATED BY SPACE.
SELECT * FROM dbtable WHERE (where_clause).Message was edited by: Srinivas Adavi
‎2006 Jun 14 12:45 AM
Hi Venu,
Declare 2 temporary date variables.
l_date1 and l_date2.
data: l_Date1 like sy-datum,
l_date2 like sy-datum.
l_date1(4) = w_year.
l_date1+4(4) = '0101'.
l_date2(4) = w_year.
l_date2+4(4) = '1231'.
select * from dbtable into .....where date GE l_date1 and
date le l_date2.
This should solve your problem.
Let me know if you need more inputs.
thanks
Puneet