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 code to get the date

Former Member
0 Likes
788

hi

i hve in selection screen data as fiscal year and period

eg 2007 fiscal year

and period 02 - 09

please let me know how to get date range based on this above parameters for fiscal year and period

i want to have code for the above my outcome should be for above eg

01/01/2008 - 30/06/2008 for if month is 30 if month is 31 it should be 31st ie last day of month

regards

Arora

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
747

Here we go. Code for getting the dates


DATA : gv_year   TYPE gjahr,
       gv_month1 TYPE poper,  "start month
       gv_month2 TYPE poper,  "last month
       gv_periv  TYPE periv,
       gv_begin  TYPE datum,  "start day
       gv_end    TYPE datum,  "last day
       gv_bukrs  TYPE bukrs.
 
SELECT SINGLE periv
       INTO gv_periv
       FROM t001
       WHERE bukrs EQ gv_bukrs.
 
gv_year = '2008'.
gv_month1 = '001'.
gv_month2 = '006'.
 
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
  EXPORTING
    i_gjahr              = gv_year
*   I_MONMIT             = 00
    i_periv              = gv_periv
    i_poper              = gv_month1
 IMPORTING
   e_date               = gv_begin
 EXCEPTIONS
   input_false          = 1
   t009_notfound        = 2
   t009b_notfound       = 3
   OTHERS               = 4.
 
IF sy-subrc  0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
  EXPORTING
    i_gjahr              = gv_year
*   I_MONMIT             = 00
    i_periv              = gv_periv
    i_poper              = gv_month2
 IMPORTING
   e_date               = gv_end
 EXCEPTIONS
   input_false          = 1
   t009_notfound        = 2
   t009b_notfound       = 3
   OTHERS               = 4.
 
IF sy-subrc  0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

hi

i hve in selection screen data as fiscal year and period

eg 2007 fiscal year

and period 02 - 09

please let me know how to get date range based on this above parameters for fiscal year and period

i want to have code for the above my outcome should be for above eg

01/01/2008 - 30/06/2008 for if month is 30 if month is 31 it should be 31st ie last day of month

regards

Arora

4 REPLIES 4
Read only

Former Member
0 Likes
748

Here we go. Code for getting the dates


DATA : gv_year   TYPE gjahr,
       gv_month1 TYPE poper,  "start month
       gv_month2 TYPE poper,  "last month
       gv_periv  TYPE periv,
       gv_begin  TYPE datum,  "start day
       gv_end    TYPE datum,  "last day
       gv_bukrs  TYPE bukrs.
 
SELECT SINGLE periv
       INTO gv_periv
       FROM t001
       WHERE bukrs EQ gv_bukrs.
 
gv_year = '2008'.
gv_month1 = '001'.
gv_month2 = '006'.
 
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
  EXPORTING
    i_gjahr              = gv_year
*   I_MONMIT             = 00
    i_periv              = gv_periv
    i_poper              = gv_month1
 IMPORTING
   e_date               = gv_begin
 EXCEPTIONS
   input_false          = 1
   t009_notfound        = 2
   t009b_notfound       = 3
   OTHERS               = 4.
 
IF sy-subrc  0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
 
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
  EXPORTING
    i_gjahr              = gv_year
*   I_MONMIT             = 00
    i_periv              = gv_periv
    i_poper              = gv_month2
 IMPORTING
   e_date               = gv_end
 EXCEPTIONS
   input_false          = 1
   t009_notfound        = 2
   t009b_notfound       = 3
   OTHERS               = 4.
 
IF sy-subrc  0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Read only

0 Likes
747

very good Sriram, this was a 1 to 1 copy of my source code (answering the same question from the same user) from here:

Read only

Former Member
0 Likes
747

hi

u have replied from my earlie thread in which i have asked for function module

lease not that i havent asked for any funtion module in this question but hard coded code to do so?

please read the query fully...

regards

ARora

Read only

Former Member
0 Likes
747

problem solved