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: 

Month Year format

Former Member
0 Kudos

Hi all

I've passed the paramaters : year and month i.e. 2005, 06(month).

i want to select one month for example june 2005, in vbak table erdate. how should write query?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

I did some modification to my earlier post

Now you can eneter any month or year on the selection-screen and you call get the documents for that perios from VBAk.

REPORT YUP_TEST2 .

DATA: IT_VBAK TYPE TABLE OF VBAK WITH HEADER LINE.

DATA:V_DATE_A TYPE SY-DATUM,

V_DATE_B TYPE SY-DATUM.

PARAMETERS:P_YEAR(4),

P_MONTH(2).

  • v_date = sy-datum.

*write:/ sy-datum.

CONCATENATE P_YEAR P_MONTH '01' INTO V_DATE_A.

CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

EXPORTING

DAY_IN = V_DATE_A

IMPORTING

LAST_DAY_OF_MONTH = V_DATE_B

EXCEPTIONS

DAY_IN_NOT_VALID = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

SELECT * FROM VBAK INTO TABLE IT_VBAK

WHERE ERDAT >= V_DATE_A AND

ERDAT <= V_DATE_B.

LOOP AT IT_VBAK.

WRITE:/ IT_VBAK-VBELN,IT_VBAK-ERDAT.

ENDLOOP.

10 REPLIES 10

Former Member
0 Kudos

data: gv_date like sy-datum.

data: gv_out(7),

gv_yy(4),

gv_mmm(2) .

select single erdat into gv_date from vbak.

gv_yy = gv_date+0(4).

gv_mmm = gv_date+4(2).

CONCATENATE of gv_yy gv_mmm into gv_out seprated by ','.

write : gv_out .

Former Member
0 Kudos

Using this will give you the month you want.

m = VBAK-ERDAT+4(2)

READ TABLE t247 INDEX m.

IF sy-subrc = 0.

mname = month_names-ltx.

ENDIF.

Rgds,

Jothi.

Former Member
0 Kudos

Hi,

What you can do is to concatenate the 01 / 31 to the month and date and then use the BETWEEN clause

concatenate year month '01' into w_start_date.

Using the starting date, get the last day of the month.

Now use the BETWEEN clause.

Select * from VBAK where erdat between w_start_date and w_end_date.

Regards,

Ravi

Note : Please mark the helpful answers

Former Member
0 Kudos

hi

just check the way in which date is stored in vbak..

pass the date to some string..w_string(200506)

then concatenate w_string '01' to w_first_date.

use this fm to get the last date of the month SG_PS_GET_LAST_DAY_OF_MONTH...pass it w_last_date

query at vbak

select...

...

where erdate ge w_first_date and erdate le w_last_date..

and manipulate this part accordingly..

Reward points if it helps

regards

Gunjan

0 Kudos

hi

thanks for u r response.but data not taken

see this query

firstd=01032005

select vbeln erdat into (salno, saldate) from vbak where

erdat le firstd.

no data display

Former Member
0 Kudos

Hi,

I wrote this sample program . you will get all documents

for the the entered June month.

DATA: IT_VBAK TYPE TABLE OF VBAK WITH HEADER LINE.

DATA:V_DATE_A TYPE SY-DATUM,

V_DATE_B TYPE SY-DATUM.

PARAMETERS:P_YEAR(4) DEFAULT '2006',

P_MONTH(2) DEFAULT '06'.

  • v_date = sy-datum.

*write:/ sy-datum.

CONCATENATE P_YEAR P_MONTH '01' INTO V_DATE_A.

CONCATENATE P_YEAR P_MONTH '30' INTO V_DATE_B.

SELECT * FROM VBAK INTO TABLE IT_VBAK

WHERE ERDAT >= V_DATE_A AND

ERDAT <= V_DATE_B.

LOOP AT IT_VBAK.

WRITE:/ IT_VBAK-VBELN,IT_VBAK-ERDAT.

ENDLOOP.

Thanks,

Pramod

Former Member
0 Kudos

Hi,

I did some modification to my earlier post

Now you can eneter any month or year on the selection-screen and you call get the documents for that perios from VBAk.

REPORT YUP_TEST2 .

DATA: IT_VBAK TYPE TABLE OF VBAK WITH HEADER LINE.

DATA:V_DATE_A TYPE SY-DATUM,

V_DATE_B TYPE SY-DATUM.

PARAMETERS:P_YEAR(4),

P_MONTH(2).

  • v_date = sy-datum.

*write:/ sy-datum.

CONCATENATE P_YEAR P_MONTH '01' INTO V_DATE_A.

CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

EXPORTING

DAY_IN = V_DATE_A

IMPORTING

LAST_DAY_OF_MONTH = V_DATE_B

EXCEPTIONS

DAY_IN_NOT_VALID = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

SELECT * FROM VBAK INTO TABLE IT_VBAK

WHERE ERDAT >= V_DATE_A AND

ERDAT <= V_DATE_B.

LOOP AT IT_VBAK.

WRITE:/ IT_VBAK-VBELN,IT_VBAK-ERDAT.

ENDLOOP.

Former Member
0 Kudos

Hi Muthu,

U can try out this.

tables: vbak.

select * from vbak where erdat like '200508%'.

write: vbak-erdat.

endselect.

Rgds,

Sumana

Former Member
0 Kudos

Hi Muthu,

Please check this code.

TABLES : vbak.

DATA : itab TYPE TABLE OF vbak WITH HEADER LINE.

DATA : l_start_date TYPE sy-datum,

l_end_date TYPE sy-datum.

PARAMETERS : l_month(2),

l_year(4).

CONCATENATE l_year l_month '01' INTO l_start_date.

--- Getting last day of the month --

CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'

EXPORTING

day_in = l_start_date

IMPORTING

last_day_of_month = l_end_date

EXCEPTIONS

day_in_no_date = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

SELECT * FROM vbak

INTO TABLE itab

WHERE erdat GE l_start_date

AND

erdat LT l_end_date.

IF sy-subrc = 0.

LOOP AT itab.

WRITE : / itab-erdat, itab-vbeln.

ENDLOOP.

ENDIF.

If found helpful, please do reward.

0 Kudos

Hi Muthu,

you are far more flexible if you use a range for the selection; you declare it in the selection screen like

<pre>

TABLES:

vbak.

DATA:

gt_vbak TYPE TABLE of vbak.

SELECT-OPTIONS:

s_erdat FOR vbak-erdat.

SELECT vbeln erdat "an the fields you really need

FROM vbak

INTO CORRESPONDING FIELDS OF TABLE gt_vbak

WHERE erdat IN s_erdat.

  • ... further processing

</pre>

Note: This database selection will be quite time-cosuming if you do not have an index defined on field erdat.

The big advantage of ranges is that they can be used for a lot of selection conditions including patterns, exclusions and so on. With a range you could for example specify for example specific months and exclude in the same selection specific dates.

Regards,

Clemens