Application Development and Automation 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: 
Read only

Select Statement to check date between dates

former_member207873
Participant
0 Likes
6,939

Hi Experts,

I wanted to find data from table based on the dates. But it is not fetching any data.

SELECT UKURS FROM TCURR INTO TABLE IT_UKURS
        WHERE  GDATU GE <FS_OUTTAB>-BUDAT AND GDATU LE LV_LAST_DAY.


** I also tried BETWEEN Statement still not working.



My  <FS_OUTTAB>-BUDAT and
LV_LAST_DAY is of the format YYYYMMDD.


BR.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,788

Hi,

     Try Declaring Lv_Last_day as date Type like

     Lv_Lst_day type sy_datum.

9 REPLIES 9
Read only

Former Member
0 Likes
2,789

Hi,

     Try Declaring Lv_Last_day as date Type like

     Lv_Lst_day type sy_datum.

Read only

0 Likes
2,788

No, the issue is with field GDATU in Table TCURR. It is not of date type. So how can I use the select statement with a between statement ?

Read only

0 Likes
2,788

Hi

You need to convert <FS_OUTTAB>-BUDAT and  LV_LAST_DAY in the same format of GDATU

Max

Read only

0 Likes
2,788

Hi Max,

Thank you. I converted both into inverted format. Still not fetching any data.

CONVERT DATE LV_LAST_DAY INTO INVERTED-DATE LV_LAST_DAY.
CONVERT DATE <FS_OUTTAB>-BUDAT INTO INVERTED-DATE FROM_DATE.

SELECT UKURS FROM TCURR INTO TABLE IT_UKURS
WHERE  GDATU GE FROM_DATE AND GDATU LE LV_LAST_DAY.


BR.

Read only

0 Likes
2,788

Then you are using the wrong dates. I wrote this and it worked fine:

   data: it_ukurs type table of tcurr-ukurs.
DATA: fs_outtab-budat(8),
      lv_last_day(8). " is of the format YYYYMMDD

DATA: h_begdat LIKE sy-datum,
      h_enddat LIKE sy-datum.

START-OF-SELECTION.

  fs_outtab-budat = '19900101'.
  lv_last_day = '20141231'.

  CONVERT DATE fs_outtab-budat INTO INVERTED-DATE h_begdat.
  CONVERT DATE lv_last_day INTO INVERTED-DATE h_enddat.

  SELECT ukurs FROM tcurr INTO TABLE it_ukurs
          WHERE  gdatu GE h_enddat AND gdatu LE h_begdat.

Read only

0 Likes
2,788

Hi

The rule to convert is easy:


GDATU = '99999999' - DATE (YYYYMMDD)

Try to run this report:


parameters: p1 type sy-datum,

                  p2 type sy-datum.

data date_c(8) type c.

data p1_int(8) type c.

data p2_int(8) type c.


   move p1 to date_c.

   p1_int = '99999999' - date_c.

   write: p1, p1_int.

   move p2 to date_c.

   p2_int = '99999999' - date_c.

   skip.

   write: p2, p2_int.

if P1 is greater than P2 => P2  (converted) will be greater than P1 converted

Max

Read only

Former Member
0 Likes
2,787

hi,

your question should have been how to compare inverted-Dates with normal dates...

convert your date to invert-Date Format. It took me 1 min going into the table looking for conversion exit. use FM convert_exit_invdt_input as shown in screenshot below. Enter your min and max date there and use the FM-results to do your select-statement...

by the way you find convertion exits when klicking on the dataelement and then double click the domain. It shows that convert-exit INVDT is used. so ther always is a CONVERSION_EXIT_INVDT_INPUT and CONVERSION_EXIT_INVDT_OUTPUT. you can use this FM to figure out how SAP does the conversion.

regards

Stefan Seeburger

Read only

former_member201275
Active Contributor
0 Likes
2,787

Is your issue resolved? Did any of the replies help or answer your question? Please mark accordingly and close.

Read only

0 Likes
2,787

Thank you .