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: 

Need to give condition to select the fields for last 2 year &previous year

Former Member
0 Kudos

give a sample program. how to give a condition to select the field values for last 2 year and

a condition to reterieve fields based on perious year

4 REPLIES 4

Former Member
0 Kudos

Josephine,

Could you please elaborate the requirement?????

Thanks

Kam

Clemenss
Active Contributor
0 Kudos

Sorry your question is unspecific.

So how to answer a question if we can not understand what is your goal or task?

parameters:

p_year type gjahr,

p_lastyr type gjahr

initialization.

p_year = sy-datum(4).

p_lastyr = p_year - 1.

start-of-selection.

select ... gjahr ... into ???

case ???-gjahr.

when p_year.

  • do something for this year

when lastyr.

  • do something for last year

endcase.

endselect.

Hope it helps,

C

former_member188685
Active Contributor
0 Kudos

you can directly give the date in where condition if you have date field in side database by providing 2years date or 1 year previous to current date.

andreas_mann3
Active Contributor
0 Kudos

Hi,

calculate previous year:

p_year = sy-datum(4) - 1.

1) p_year_begin type sy-datum:

concatenate p_year '0101' into p_year_begin.

2) p_year_date type sy-datum:

concatenate p_year sy-datum+4 into p_year_date.

-> example for sel. bkpf

select * from bkpf into itab
 where bukrs  in s_bukrs 
   and gjahr between p_year and sy-datum(4)
   and cpudt between p_year_date and sy-datum.

Andreas