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

How to default date values in Selection Screen

Former Member
0 Likes
11,397

Hi everyone,

I would like to display the 1st day of the previous month into the I_GSTRP-LOW field and the last day of the current month into the I_GSTRP-HIGH field.

For example, this in the 5th month of the year (May), therefore, in the selection screen it should appear like this:

Basic Date: <u>01.04.2006</u> to <u>31.05.2006</u>

How do i do it?


*&---------------------------------------------------------------------*
*& SELECTION-SCREEN                                                    *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS:
  I_AUFNR FOR AFIH-AUFNR,                           "ORDER NUMBER
  I_GSTRP FOR AFKO-GSTRP,                           "BASIC DATE
  I_BUDAT FOR AUFM-BUDAT,                           "POSTING DATE
  I_IWERK FOR AFIH-IWERK DEFAULT '6010' OBLIGATORY, "PLANNING PLANT
  I_ARBPL FOR CRHD-ARBPL,                           "WORK CENTER
  I_ERNAM FOR AUFK-ERNAM,                           "CREATED BY
  I_MATNR FOR RESB-MATNR,                           "MATERIAL
  I_KTEXT FOR AUFK-KTEXT.                           "EQUIPMENT

SELECTION-SCREEN END OF BLOCK 1.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,595

Hi Bernard,

in INITIALIZATION use:

*

I_BUDAT-LOW = SY-DATUM.

I_BUDAT-HIGH = SY-DATUM.

CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'

EXPORTING

MONTHS = '-1'

OLDDATE = I_BUDAT-LOW

IMPORTING

NEWDATE = I_BUDAT-LOW.

I_BUDAT-LOW+6 = '01'.

-> gives you the first day of the actual Month -1.

CALL FUNCTION 'LAST_DAY_OF_MONTHS'

EXPORTING

DAY_IN = I_BUDAT-HIGH

IMPORTING

LAST_DAY_OF_MONTH = I_BUDAT-HIGH.

-> Gives you the last day of a Month

APPEND I_BUDAT.

Hope i can Help you

Regards, Dieter

Hi everyone,

I would like to display the 1st day of the previous month into the I_GSTRP-LOW field and the last day of the current month into the I_GSTRP-HIGH field.

For example, this in the 5th month of the year (May), therefore, in the selection screen it should appear like this:

Basic Date: <u>01.04.2006</u> to <u>31.05.2006</u>

How do i do it?


*&---------------------------------------------------------------------*
*& SELECTION-SCREEN                                                    *
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS:
  I_AUFNR FOR AFIH-AUFNR,                           "ORDER NUMBER
  I_GSTRP FOR AFKO-GSTRP,                           "BASIC DATE
  I_BUDAT FOR AUFM-BUDAT,                           "POSTING DATE
  I_IWERK FOR AFIH-IWERK DEFAULT '6010' OBLIGATORY, "PLANNING PLANT
  I_ARBPL FOR CRHD-ARBPL,                           "WORK CENTER
  I_ERNAM FOR AUFK-ERNAM,                           "CREATED BY
  I_MATNR FOR RESB-MATNR,                           "MATERIAL
  I_KTEXT FOR AUFK-KTEXT.                           "EQUIPMENT

SELECTION-SCREEN END OF BLOCK 1.

7 REPLIES 7
Read only

Former Member
0 Likes
4,595

hi

use the fm to find last date

<b>SG_PS_GET_LAST_DAY_OF_MONTH</b>

sample code

<b>data : d1 type datum,

d2 type datum.

d1 = '20060401'.

d2 = '20060531'.

l_gstrp-low = d1.

l_gstrp-high = d2.

l_gstrp-sign = bt

ll_gstrp-option = i

append l_gstrp.</b>

Read only

rahulkavuri
Active Contributor
0 Likes
4,595
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS: S_VBELN FOR VBRK-VBELN,
                S_FKDAT FOR VBRK-FKDAT,
                S_MATNR FOR VBRP-MATNR.

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-001.

PARAMETERS : LIST RADIOBUTTON GROUP G1,
             GRID  RADIOBUTTON GROUP G1 DEFAULT 'X'.


SELECTION-SCREEN END OF BLOCK B2.

************************************************************************
*****************            INITIALIZATION         ********************
************************************************************************

INITIALIZATION.

  STR_DATE = SY-DATUM - 200.
  S_FKDAT-LOW = STR_DATE.
  S_FKDAT-HIGH = SY-DATUM.
  S_FKDAT-SIGN = 'I'.
  APPEND S_FKDAT.

Replace the STR_DATE with the date u want.

To get first and last days of the month use

MC_PERIO_GET_FIRST_AND_LASTDAY....

Then get the date field first day into string and then subsract a month from it after offsetting the month field

<b>P>S> Award points if found helpful</b>

Read only

Former Member
0 Likes
4,595

v_date = sy-datum.

v_month = v_date+4(2) - 1.

concatenate v_date+0(4)

v_month

'01'

into v_low_value.

I_GSTRP-LOW = v_low_value.

then call the function module "NUMBER_OF_DAYS_PER_MONTH_GET" & populate

month = v_month &

year = sy-datum+0(4).

you will get V_NO_OF_DAYS

you will get no of days on the current month.

then populate it to the HIGH VALUE

concatenate sy-datum+0(6)

V_NO_OF_DAYS

into v_high_value.

I_GSTRP-HIGH = v_high_value.

I_GSTRP-sign = 'I'.

I_GSTRP-OPTION = 'EQ'.

APPEND I_GSTRP.

Regards

Srikanth

Read only

Former Member
0 Likes
4,596

Hi Bernard,

in INITIALIZATION use:

*

I_BUDAT-LOW = SY-DATUM.

I_BUDAT-HIGH = SY-DATUM.

CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'

EXPORTING

MONTHS = '-1'

OLDDATE = I_BUDAT-LOW

IMPORTING

NEWDATE = I_BUDAT-LOW.

I_BUDAT-LOW+6 = '01'.

-> gives you the first day of the actual Month -1.

CALL FUNCTION 'LAST_DAY_OF_MONTHS'

EXPORTING

DAY_IN = I_BUDAT-HIGH

IMPORTING

LAST_DAY_OF_MONTH = I_BUDAT-HIGH.

-> Gives you the last day of a Month

APPEND I_BUDAT.

Hope i can Help you

Regards, Dieter

Read only

Former Member
0 Likes
4,595

with the help of event initialization you can do that.

INITIALIZATION.
 

  I_GSTRP-LOW = '20060401'.
  I_GSTRP-HIGH = '20060531'.
  I_GSTRP-SIGN = 'I'.
  APPEND I_GSTRP.

Regards

vijay

Read only

Former Member
0 Likes
4,595

Here is the code to populate default values,as per your requirement.

data : V_date type sy-datum,

v_month(2) type c,

v_low_value(8) type c,

v_high_value(8) type c,

v_month1(2) type n,

V_NO_OF_DAYS type T009B-BUTAG,

v_curr_month type T009B-BUMON,

v_curr_year type T009B-BDATJ.

select-options : i_gstrp for sy-datum.

initialization.

v_date = sy-datum.

v_month1 = v_date+4(2) - 1.

write v_month1 to v_month.

concatenate v_date+0(4)

v_month

'01'

into v_low_value.

I_GSTRP-LOW = v_low_value.

v_curr_month = sy-datum+4(2).

v_curr_year = sy-datum+0(4).

CALL FUNCTION 'NUMBER_OF_DAYS_PER_MONTH_GET'

EXPORTING

par_month = v_curr_month

par_year = v_curr_year

IMPORTING

PAR_DAYS = V_NO_OF_DAYS

.

concatenate sy-datum+0(6)

V_NO_OF_DAYS

into v_high_value.

I_GSTRP-HIGH = v_high_value.

I_GSTRP-sign = 'I'.

I_GSTRP-OPTION = 'EQ'.

APPEND I_GSTRP.

regards

srikanth

Read only

Former Member
0 Likes
4,595

Re: How to default date values in Selection Screen

Posted: May 16, 2006 8:20 AM Reply

Hello Bernard,

I think it is better to event "At selection screen output"

Checkout following code..

At selection-screen output.

*Get first date of month

Move : sy-datum to lv_first_day.

Move : '01' to lv_first_day+4(6). "This is your first date of the month.

  • Use function module "SG_PS_GET_LAST_DAY_OF_MONTH" to get last date... ie. lv_last_date.

I_GSTRP-LOW = lv_first_day.

I_GSTRP-HIGH = lv_last_day.

Cheers,

Nilesh