Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

get records from a table with current year

Former Member
0 Kudos

Hi all,

In one of my report i need to fetch records from a table where the enddate (RVEND) is of current year

so what i was doing is taking a variable v_year = sy-datum+0(4). so now v_year will have current year

and i am taking a char(10) variable v_enddate and concatinating '%' and v_year to it.

now when i am trying to fetch values using this in the select query with where-like condition i am not getting any records for the table.

Can any one of you please help me regarding this issue. how can i retreive records for a table where enddate is of current year.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Tulasi,

select <fields>

from <db table>

into table <itab>

where <your conditions>

and rvend eq sy-datum+0(4).

Regards

Indu

7 REPLIES 7

Former Member
0 Kudos

Hi Tulasi,

select <fields>

from <db table>

into table <itab>

where <your conditions>

and rvend eq sy-datum+0(4).

Regards

Indu

Former Member
0 Kudos

Hi Tulasi Deepthi,

Do not conatenate %.

Use Less than symbol for year comparision.

Example:

data:

v_year(4) type c.

v_year = sy-datum+0(4).

select f1 f2...fn

from database table

into table t_itab

where RVEND LE v_year.

Regards,

Rama.

former_member188685
Active Contributor
0 Kudos

instead of that you can try this approach.

data: r_date type range of sy-datum,
        w_date like line of r_date.
data: it_flight type sflight_tab1.
concatenate sy-datum+0(4) '01' '01' into w_date-low.
concatenate sy-datum+0(4) '12' '31' into w_date-high.
w_date-sign = 'I'.
w_date-option = 'BT'.
append w_date to r_date.

select * from sflight
into table it_flight
where fldate in r_date.

Former Member
0 Kudos

Hi Tulasi,

select <fields>

from <db table>

into table <itab>

where <your conditions>

and rvend eq sy-datum+0(4).

Regards

Indu

Former Member
0 Kudos

hi,

check the code-proto

let itab be your target internal table.

DATA: DATE TYPE SY-DATUM,
      DATE_TEMP(2) TYPE C,
      DATE_CHECK(8) type c.
 
DATE = SY-DATUM.
DATE_TEMP = DATE+0(4).
 
concatenate  DATE_TEMP '____' INTO DATE_CHECK.   

                 " the 2nd component string consist of 4 underscore
                 " as '_' is the wild card char for single char
                 
SELECT *
  FROM ( table_name)
  INTO TABLE itab
 WHERE endda like DATE_CHECK.

Regards,

Anirban

former_member787646
Contributor
0 Kudos

Hi

Try this...

DATA: STR1(30) TYPE C.

CONCATENATE '%' v_year '%' INTO STR1.

SELECT ...... WHERE <FIELD> LIKE <STR1>.

Hope it helps.

Murthy

Former Member
0 Kudos

Hi,

Data:w_date type sy-datum.

Concatenate sy-datum+0(4) '%' into w_date.

Select * from Ztable
  into table itab
where RVEND like w_date.

Regards,

Sujit