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 -option Date field in MM/YYYY format!

naveen_inuganti2
Active Contributor
0 Kudos

Hi.. Friends..

Iam having DATE field as selection screen SELECT_OPTION parameter.

And I am fetching records from one of my tables with where condition of this select-option.

Now my reuirement is to modify that DATE select-option with 7 characters i.e. MM/YYYY

So if user enters 09/2008 as DATE-LOW.. I have to fetch all records of September 2008.

If user enters 09/2008(lower limit) and 02/2009(Upper limit)...

I have to fetch records between... September 1st 2008 to 28th february 2009.

What is the simplest way to impliment this?

Thanks,

Naveen.I

1 ACCEPTED SOLUTION

Former Member
0 Kudos

U have to find the end date of the corresponding months. For that use below FM:

JVA_LAST_DATE_OF_MONTH

And first date is by default 01.

Regards,

15 REPLIES 15

Former Member
0 Kudos

Hi,

let your select-options name in sl

data:

lowdate type SY-DATUM ,

highdate type SY_DATUM.

lowdate = concatenate '01' 'sl-low' into lowdate.

highdate = concatenate '30' 'sl-high' into lowdate

In your select query set where condition as

DATE between lowdate and highdate

0 Kudos

Hi Anir...

I dont think That BETWEEN condition always satisfies OPTION field in select-options table.

so it will not works....!!!

Thanks for your attention,

Naveen.I

GauthamV
Active Contributor
0 Kudos

hi,

use this data element.

JAHRPER.

concatenate period and year into the variable defined with this data element.

u can see the same field in KE24 transaction ,selection screen.

Former Member
0 Kudos

U have to find the end date of the corresponding months. For that use below FM:

JVA_LAST_DATE_OF_MONTH

And first date is by default 01.

Regards,

asik_shameem
Active Contributor
0 Kudos

Hi

Use data element SPMON as in below code.

  TABLES: S001.

  DATA: l_year(4)  TYPE n,
        l_month(3) TYPE n,
        g_sdate TYPE sy-datum,
        g_edate TYPE sy-datum.

  RANGES: gr_pdate FOR sy-datum.

  CONSTANTS: lc_low   TYPE sy-datum VALUE '00010101',
             lc_high  TYPE sy-datum VALUE '99990101'.

  SELECT-OPTIONS:   s_spmon  FOR  s001-spmon.

  l_year  = s_spmon-low(4).
  l_month = s_spmon-low+4(2).

* Get the first day of PERIOD-LOW
  CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
    EXPORTING
      i_gjahr        = l_year
      i_periv        = 'K2'
      i_poper        = l_month
    IMPORTING
      e_date         = g_sdate
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.

  l_year  = s_spmon-high(4).
  l_month = s_spmon-high+4(2).

* Get the last day of PERIOD-HIGH
  CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
    EXPORTING
      i_gjahr        = l_year
      i_periv        = 'K2'
      i_poper        = l_month
    IMPORTING
      e_date         = g_edate
    EXCEPTIONS
      input_false    = 1
      t009_notfound  = 2
      t009b_notfound = 3
      OTHERS         = 4.

  IF NOT s_spmon-low IS INITIAL.
    gr_pdate-low = g_sdate.
  ELSE.
    gr_pdate-low = lc_low.
  ENDIF.

  IF NOT s_spmon-high IS INITIAL.
    gr_pdate-high = g_edate.
  ELSE.
    gr_pdate-high = lc_high.
  ENDIF.

  IF NOT s_spmon-low IS INITIAL OR NOT s_spmon-high IS INITIAL.
    gr_pdate-option = 'BT'.
    gr_pdate-sign = 'I'.
    APPEND gr_pdate.
  ENDIF.

" SELECT RECORDS
" >>> SELECT field1 field2 FROM TAB1 WHERE erdat IN gr_pdate. <<<

0 Kudos

Hi Friends....

One thing i Want to conform to all of you..,

Here DATE field should act as select-option only, but it should be 7 character format in selection-screen...

i.e. MM/YYYY..

So It should accept sign, option fields of select-option always....

Ok, Now I will try with above DATA ELEMENTS.

Thanks,

Naveen.i

0 Kudos

Create a dataelement of size 7 and use it in selection-screen as select-option..

0 Kudos

Hi Friends...

What is the problem if i hard code upper limit date with always 31, in concatenate in this case?

Thanks,

Naveen.I

0 Kudos

Create one temp internal table(with sigh and options) in that you must need to concatenate with 01(low date) 31(high date) than use this internal table in select query with where condition.

though in your database table date field is in datum format not in mm/yyyy.

0 Kudos

Hi....

SOLVED

I declared one ranges table i.e. r_date.

In the initialization...

concatenate s_date-low+3(4) s_date-low+0(2) '01' into r_date-low.
  if s_date-high is not initial.
    concatenate s_date-high+3(4) s_date-high+0(2) '31' into r_date-high.
  else.
    concatenate s_date-low+3(4) s_date-low+0(2) '31' into r_date-high.
  endif.
  r_date-sign = s_date-sign.
  r_date-option = s_date-option.
  append r_date.
endloop.

There is no more modifications reuired more than LAST DAY caluclations.

But let me know when user gets problem with above hard code(last day - 31), because any way he never allows with perticuler date limits.

Thanks,.

Naveen.I

0 Kudos

Hi

Nothing will happen. You won't get proper data since it has invalid dates.

Try to make use of standard FM instead of hard-coding them.

0 Kudos

>

> But let me know when user gets problem with above hard code(last day - 31), because any way he never allows with perticuler date limits.

>

> Thanks,.

> Naveen.I

Hard code in your case must the there other wise how you handle your query?

and moreover user dosn't know what you code behind.

because he only enter 09/2008 than obviously date doest matter for him.he expect the data of 09 month which only can be achieve by just hard code 01 and 31 in date level.

Amit.

0 Kudos

Hi Asik...,

Its working fine...unlike it will gives error from SE16 as invalid date.

So here no need to go for LAST_DATE function module.

And in above code OPTION will be BT always if user not enters upper limit.

Thanks,

Naveen.I

Former Member
0 Kudos

Hi Naveen,

S094-SPBUP (month and year) Period of 6 chars

select-options: s_spbup for s094-spbup

naveen_inuganti2
Active Contributor
0 Kudos

I will check it.

Thanks,

Naveeen.I