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: 

How to convert the date format from MM/YYYY to MM/DD/YYYY.

Former Member
0 Kudos

hi friends,

I have the select option date which is of the format MM/YYYY..I need the deliveries from the table likp for the above format.for example if the user enters 01/2007 then i need all the deliveries from 01/01/2007 to 01/31/2007.can anyone help me in this??

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You might want to try this..........




report zrich_0001.

data ilikp type table of likp.

ranges: r_datum for sy-datum.

parameters: p_spbup type spbup.


start-of-selection.

r_datum-sign = 'I'.
r_datum-option = 'BT'.

r_datum-low = p_spbup.
r_datum-low+6(2) = '01'.

r_datum-high = r_datum-low.
r_datum-high+4(2) = r_datum-high+4(2) + 1.
r_datum-high = r_datum-high - 1.
append r_datum.

select * into table ilikp from likp
            where erdat in r_datum.

Regards.

Rich Heilman

22 REPLIES 22

Former Member
0 Kudos

Hi Sangeetha,

One interesting point to note about date field @ db level is it is always stored in YYYYMMDD format. Hence what you can do is - read the MM/YYYY field from the selection screen, and construct the string of length 8 charactes in format YYYYMMDD and pass it to variables of type sy-datum which would be used in the query.

I dont foresee any issues then.

Rgds,

Aditya

former_member181962
Active Contributor
0 Kudos

Hi sangeetha,

This fm is tailor made for you:

/IBS/RB_FI_FIRST_LAST_DAY

month = s_date-low+0(2).

year = s_date-low+3(4).

Regards,

Ravi

Former Member
0 Kudos

Hi,

Lets take the User enterd 01/2007(jan 2007), then take 3 fields, 1 for date and 1 for month and third for Year and move that fields accordingly using the offset.

then you have the perfect date. then the First day of the month would be 01/01/2007. and to find the last day of the month use SG_PS_GET_LAST_DAY_OF_MONTH funtion moduel, then you will get the last data, so now you have first daty of the month and last day of the month

Regards

Sudheer

amit_khare
Active Contributor
0 Kudos

Hi,

Welcome to SDN.

All function modules take full date as input to find the start and end date of the month.

Use this routine.

month = date+0(2).

year = date+2(4).

concatenate month '01' year to newstart_date separated by '/'.

concatenate month '31' year to newterm_date separated by '/'.

Hope this help you.

Regards,

Amit

Former Member
0 Kudos

Hi,

Use this FM:

HR_GB_PERIOD_DATES

CALL FUNCTION 'HR_GB_PERIOD_DATES'

EXPORTING

  • ABKRS =

  • PERMO =

pabrj = '01'

pabrp = '2007'

  • IMPORTING

  • BEGDA =

  • ENDDA =

  • EXCEPTIONS

  • PERIOD_NOT_FOUND = 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.

This will return the starting date and the ending date in that month.

Regards

Subramanian

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You might want to try this..........




report zrich_0001.

data ilikp type table of likp.

ranges: r_datum for sy-datum.

parameters: p_spbup type spbup.


start-of-selection.

r_datum-sign = 'I'.
r_datum-option = 'BT'.

r_datum-low = p_spbup.
r_datum-low+6(2) = '01'.

r_datum-high = r_datum-low.
r_datum-high+4(2) = r_datum-high+4(2) + 1.
r_datum-high = r_datum-high - 1.
append r_datum.

select * into table ilikp from likp
            where erdat in r_datum.

Regards.

Rich Heilman

0 Kudos

Hi Rich.

Problem Solved.Many Thanks.

0 Kudos

Hi

Instead of parameters im trying for select-options.for an example i need data from 01/2007 to 02/2007(for 2 months).

select-options: p_spbup for s723-spmon.

In what way i have to modify your code for this requirement.can you help me plz?

Thanks

Sangeetha

0 Kudos

Hi Sangeetha,

Check the below code in bold which need changes as per select-options.

data ilikp type table of likp.

ranges: r_datum for sy-datum.

<b>select-options: s_spbup type spbup.</b>

start-of-selection.

r_datum-sign = 'I'.

r_datum-option = 'BT'.

<b>r_datum-low = s_spbup-low</b>.

r_datum-low+6(2) = '01'.

<b>if s_spbup-high is not inital.

r_datum-high = s_spbup-high.

r_datum-high+6(2) = '01'.

r_datum-high = s_spbup-high.

else.

r_datum-high = r_datum-low.

endif</b>

r_datum-high4(2) = r_datum-high4(2) + 1.

r_datum-high = r_datum-high - 1.

append r_datum.

select * into table ilikp from likp

where erdat in r_datum.

Thanks,

Vinay

0 Kudos

Vinay,

I tried the given coding.its not working.

Thanks,

sangeetha.

0 Kudos

This should work.



report zrich_0001.

tables: mcs0  .
data: ilikp type table of likp.
ranges: r_datum for sy-datum.

select-options: s_spbup for mcs0-spbup no-extension.


start-of-selection.

  read table s_spbup index 1.

  r_datum-sign = 'I'.
  r_datum-option = 'BT'.

  r_datum-low = s_spbup-low.
  r_datum-low+6(2) = '01'.

  if not s_spbup-high is initial.
    r_datum-high = s_spbup-high.
    r_datum-high+6(2) = '01'.
  else.
    r_datum-high = r_datum-low.
  endif.
  r_datum-high+4(2) = r_datum-high+4(2) + 1.
  r_datum-high = r_datum-high - 1.
  append r_datum.

  select * into table ilikp from likp
  where erdat in r_datum.

Regards,

Rich Heilman

0 Kudos

Hi Sangeetha,

Check with this code now.

report zrich_0001.

tables s002.

data ilikp type table of likp.

ranges: r_datum for sy-datum.

select-options: s_spbup for s002-spbup.

start-of-selection.

r_datum-sign = 'I'.

r_datum-option = 'BT'.

r_datum-low = s_spbup-low.

r_datum-low+6(2) = '01'.

if s_spbup-high is not initial.

r_datum-high = s_spbup-high.

r_datum-high+6(2) = '01'.

else.

r_datum-high = r_datum-low.

endif.

r_datum-high4(2) = r_datum-high4(2) + 1.

r_datum-high = r_datum-high - 1.

append r_datum.

select * into table ilikp from likp

where erdat in r_datum.

Thanks,

Vinay

0 Kudos

Awesome.It Works really fine.Thank you so much.

Sangeetha.

0 Kudos

Thanks Vinay.

0 Kudos

Hi Rich,

Sorry to keep bothering you but I am wondering, it is not working if i give only the from date.If i give both dates it works really fine.

Thanks,

Sangeetha.

0 Kudos

Hi Vinay,

your suggestion also works fine but for both the fields.if i give only from date,then it is not working.

0 Kudos

Hi,

If i try to give only from date..then im not getting the results.if i give both from and To dates then it is working fine.can you help me?

Thanks,

sangeetha

0 Kudos

This program is working fine for me, if I only enter a value in the FROM field.



report zrich_0003.

tables: mcs0  .
data: ilikp type table of likp.
ranges: r_datum for sy-datum.

select-options: s_spbup for mcs0-spbup no-extension.

start-of-selection.

  read table s_spbup index 1.

  r_datum-sign = 'I'.
  r_datum-option = 'BT'.

  r_datum-low = s_spbup-low.
  r_datum-low+6(2) = '01'.

  if not s_spbup-high is initial.
    r_datum-high = s_spbup-high.
    r_datum-high+6(2) = '01'.
  else.
    r_datum-high = r_datum-low.
  endif.
  r_datum-high+4(2) = r_datum-high+4(2) + 1.
  r_datum-high = r_datum-high - 1.
  append r_datum.

*  select * into table ilikp from likp
*  where erdat in r_datum.
write:/ r_datum-sign,
        r_datum-option,
        r_datum-low,
        r_datum-high.

I enter 01/2007 in the from field and the output shows.....

I BT 01/01/2007 01/31/2007 which is what we want.

Are you seeing something different?

Regards,

RIch Heilman

0 Kudos

Hi Sangeetha,

I copied the code which i posted is working fine for me even if i have given the FROM DATE only. You can view the code which in bold which takes care of FROM DATE condition exclusively.

Can you check again and confirm once ??

I am pasting the code again.

report zrich_0001.

tables s002.

data ilikp type table of likp.

ranges: r_datum for sy-datum.

select-options: s_spbup for s002-spbup.

start-of-selection.

r_datum-sign = 'I'.

r_datum-option = 'BT'.

r_datum-low = s_spbup-low.

r_datum-low+6(2) = '01'.

<b>if s_spbup-high is not initial.</b>

r_datum-high = s_spbup-high.

r_datum-high+6(2) = '01'.

else.

<b>r_datum-high = r_datum-low.</b>

endif.

r_datum-high4(2) = r_datum-high4(2) + 1.

r_datum-high = r_datum-high - 1.

append r_datum.

select * into table ilikp from likp

where erdat in r_datum.

Thanks,

Vinay

0 Kudos

hey,

you are right.if i give 01/2007 in the from field it is working fine.but try giving the input as 12/2006 in the from field.then it is behaving strange.

Thanks,

Sangeetha.

0 Kudos

Ah.... yes. Didn't think about that. There are a couple ways to handle this. Here is one.



report zrich_0003.

tables: mcs0  .
data: ilikp type table of likp.
ranges: r_datum for sy-datum.

select-options: s_spbup for mcs0-spbup no-extension.

start-of-selection.

  read table s_spbup index 1.

  r_datum-sign = 'I'.
  r_datum-option = 'BT'.

  r_datum-low = s_spbup-low.
  r_datum-low+6(2) = '01'.

  if not s_spbup-high is initial.
    r_datum-high = s_spbup-high.
    r_datum-high+6(2) = '01'.
  else.
    r_datum-high = r_datum-low.
  endif.
  r_datum-high+4(2) = r_datum-high+4(2) + 1.

* Handle change in year
  if  r_datum-high+4(2) = '13'.
    r_datum-high+4(2) = '01'.
    r_datum-high+0(4) = r_datum-high+0(4) + 1.
  endif.


  r_datum-high = r_datum-high - 1.
  append r_datum.

*  select * into table ilikp from likp
*  where erdat in r_datum.
  write:/ r_datum-sign,
          r_datum-option,
          r_datum-low,
          r_datum-high.

Regards,

Rich Heilman

0 Kudos

Thank you so much.problem got solved.

Regards

Sangeetha.