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: 

Select a range

Former Member
0 Kudos

How do I select a range of values? For instance, I need to write a select statement that, among others, selects documents based on a date range. What I am doing is trying to pick billing documents that have a billing date within the last 365 days. Also I need to figure out a way (an easy way) to determine if a particular day is a weekend.

Regards,

Aaron

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Ok, thanks to all for the wonderful help! I have one quick addition to this question before I mark it answered. Right now, as it stands, I have (theoretically) a list of document numbers (with their data) that is in a date range (the last 365). I then want to restrict the material numbers to certain material groups. Each time this report is run the material groups will change and it could be one to all material groups. How would I do a "range" in this instance?

Thanks,

Aaron

13 REPLIES 13

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Hi Aaron, for you first requirement, you can simply use a RANGE.

Ranges:  r_datum for sy-datum.

r_datum-sign = 'I'.
r_datum-optin = 'BT'.
r_datum-low = sy-datum - 365.
r_datum-high = sy-datum.
append r_datum.


select * into table itab
                  from ztab
                           where datum in r_datum.

Regards,

Rich Heilman

0 Kudos

Hello Rich,

First off, thanks for the quick reply. After I set up the range, as you outlined, can I add other requirements on the select statement like normal? I assume I can. One more thing (it’s related). I am doing a select off the table VBRP_VRPMA but that is a joined table. Can I treat this table like any other table? I am attempting to determine the 5 largest, consecutive, shipping days per Mat#. Do you know of a better way to do this besides going through every billing document one at a time? Sorry for all of the questions.

0 Kudos

> can I add other

> requirements on the select statement like normal? I

> assume I can.

Yes you can

> doing a select off the table VBRP_VRPMA but that is a

> joined table. Can I treat this table like any other

> table?

Yes u can.

Aaron, by 5 largest and consecutive shipping days what do you exactly mean? Can you illustrate your requirement with sample data?

Former Member
0 Kudos

Aaron

data: YearAgo like sy-datum.

YearAgo = sy-datum - 365.

select * from SomeTable into i_table

where BillDate >= YearAgo

and BillDate <= sy-datum.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

For your second requirement, you can use the function module DATE_TO_DAY to convert each date to the week day. Then you can check the return value for 'Sat.' or 'Sunday'.

REgards,

Rich Heilman

Former Member
0 Kudos

RANGES: s_date FOR ekko-aedat.

DATA: lv_day TYPE scal-indicator.

s_date-high = sy-datum.

s_date-low = sy-datum - 365.

s_date-option = 'BT'.

s_date-sign = 'I'.

APPEND s_date.

DATA: t_ekko TYPE STANDARD TABLE OF ekko.

SELECT * FROM ekko

INTO TABLE t_ekko

WHERE aedat IN s_date.

CALL FUNCTION 'DATE_COMPUTE_DAY'

EXPORTING

date = sy-datum

IMPORTING

day = lv_day.

IF sy-subrc = 0.

ENDIF.

LV_DAY = '6' for saturday and '7' for sunday.

Former Member
0 Kudos

Ok, thanks to all for the wonderful help! I have one quick addition to this question before I mark it answered. Right now, as it stands, I have (theoretically) a list of document numbers (with their data) that is in a date range (the last 365). I then want to restrict the material numbers to certain material groups. Each time this report is run the material groups will change and it could be one to all material groups. How would I do a "range" in this instance?

Thanks,

Aaron

0 Kudos

I am not sure i follow your question. You can provide material range as part of the selection screen and then include it in your selection statement..

0 Kudos

If the material groups are going to change, I would suggest using a SELECT-OPTION in the selection screen instead of the RANGE. There is no difference between the two other than the SO, will produce fields on the selection-screen. So you can put the values in the selection screen as single entries and save this as a screen variant. Then when the material groups change, you can simply change the variant without having to change the program coding.

Regards,

Rich HEilman

0 Kudos

Thanks Rich. When I use the SO is each field on the Selection Screen a different variable? What I'm getting at is how would I put them in a select statement?

0 Kudos

Say that you want to select data based on one or more material groups. You would set up the SELECT-OPTION, then on the screen, add the material groups that you want. Then you just use the IN operator like you did for the RANGE.

tables: mara.

Select-options: s_matkl for mara-matkl.


select * into table it023
                from t023
                         where matkl in s_matkl.

Regards,

Rich Heilman

0 Kudos

you would define a select option (assuming u are selecting from material master)

select-optionS s_matkl for mara-matkl.

SELECT * from MARA

where matkl in S_MATKL.

When u define a select option, you can enter multiple values by clicking on the button at the end of your input box.

0 Kudos

Rich, thank you SO MUCH for your help! I appreciate the help everybody gave me!

Thanks again,

Aaron