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 month() from a date field

0 Kudos

Hi,

How can I get the month from a day field in select statement ?

e.g.

select month(erdat), count(*) from vbak group by month(erdat).

Thanks

Wilson

7 REPLIES 7

Former Member
0 Kudos

data: begin of itab occurs 0.

erdat

count

month

end of itab.

select erdat count(*) from vbak into table itab group by erdat.

loop at itab.

itab-month = itab-erdate+4(2).

modify itab.

endloop.

Message was edited by: kishan negi

suresh_datti
Active Contributor
0 Kudos

Hi Wilson,

Try this..


data: w_date type sydatum,
      w_month(2).
select erdat from vbak into w_date...
w_month = w_date+4(2).

Regards,

Suresh Datti

0 Kudos

Hi,

In a select statemant only aggregate expressions like SUM are possible. You need to determine the month between teh select ... endselect

Eddy

Former Member
0 Kudos

Hi wilson,

1. How can I get the month from a day field in select statement ?

Directly extracting MONTH from the date field,

is not possible in open sql.

2. U will have to first extract the full date,

in the internal table.

3. After that, u can once again,

loop at the table,

and extract the MONTH from the DATE

in put in extra field.

month = date+4(2).

regards,

amit m.

Former Member
0 Kudos

hi wilson,

i think u need to handle the month explicitly into ur table .

just execute the code and see the month field in mm .

hope this helps.

regards,

vikky.

-


tables vbak.

data mm(2).

select-options : so_vbeln for vbak-vbeln.

data: begin of itab occurs 0 ,

vbeln like vbak-vbeln,

erdat like vbak-erdat,

mm(2),

end of itab.

select vbeln erdat

into table itab

from vbak where vbeln in so_vbeln.

loop at itab .

write:/ itab-vbeln,

itab-erdat using edit mask '________'.

mm = itab-erdat+4(2).

write mm.

endloop.

0 Kudos

Hi,

I use native SQL statement solved the problem. Thanks all!.

Wilson

0 Kudos

Hi,

Pls don't forget to reward points and close the question if you find the answers useful.

Eddy