Skip to Content
author's profile photo Former Member
Former Member

convert mmyyyy to ddmmyyyy format

hi im new to abap.

im passing periods in select-options.

select-options: spmon type s301-spmon,

spmon1 type s301-spmon.

i want these two periods to convert into ddmmyyyy format.

at present the perform convert is only applied to one period.

i want to apply for both periods and finally they should be taken as ddmmyyyy format.

PERFORM CONVERT_MMYYYY_TO_DDMMYYY.

FORM CONVERT_MMYYYY_TO_DDMMYYY .

DATA: LW_VAR TYPE I . "LW-Local Workfield

DATA: LW_DATE1 TYPE SY-DATUM ,

LW_DATE2 TYPE SY-DATUM .

DATA: LW_STR_LOW TYPE STRING,

LW_STR_LOW1 TYPE STRING,

LW_STR_LOW2 TYPE STRING.

DATA: LW_STR_HIGH TYPE STRING,

LW_STR_HIGH1 TYPE STRING,

LW_STR_HIGH2 TYPE STRING.

LW_STR_LOW1 = SO_SPMON-LOW+0(4).

LW_STR_LOW2 = SO_SPMON-LOW+4(2).

CONCATENATE LW_STR_LOW1 LW_STR_LOW2 '01' INTO LW_STR_LOW.

LW_DATE1 = LW_STR_LOW.

*WRITE LW_DATE1.

LW_STR_HIGH1 = SO_SPMON-HIGH+0(4).

LW_STR_HIGH2 = SO_SPMON-HIGH+4(2).

IF LW_STR_HIGH2 = '01' OR

LW_STR_HIGH2 = '03' OR

LW_STR_HIGH2 = '05' OR

LW_STR_HIGH2 = '07' OR

LW_STR_HIGH2 = '08' OR

LW_STR_HIGH2 = '10' OR

LW_STR_HIGH2 = '12'.

CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '31' INTO LW_STR_HIGH.

LW_DATE2 = LW_STR_HIGH.

WRITE LW_DATE2.

ELSEIF LW_STR_HIGH2 = '04' OR

LW_STR_HIGH2 = '06' OR

LW_STR_HIGH2 = '09' OR

LW_STR_HIGH2 = '11'.

CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '30' INTO LW_STR_HIGH.

LW_DATE2 = LW_STR_HIGH.

WRITE LW_DATE2.

*Logic to check for Leap Year:-

*For all years that are multiples of 100,we need to test if its divisible by 400

*(instead of 4).If yes, then we can be sure that the year is a Leap Year.

ELSEIF LW_STR_HIGH2 = '02'.

*Begin:-To check for Leap Year when February.

LW_VAR = LW_STR_HIGH1 MOD 100.

IF LW_VAR EQ 0.

LW_VAR = LW_STR_HIGH1 MOD 400.

IF LW_VAR EQ 0.

CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '29' INTO LW_STR_HIGH.

LW_DATE2 = LW_STR_HIGH.

WRITE LW_DATE2.

ELSE.

CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '28' INTO LW_STR_HIGH.

LW_DATE2 = LW_STR_HIGH.

WRITE LW_DATE2.

ENDIF.

ELSEIF LW_VAR NE 0.

LW_VAR = LW_STR_HIGH1 MOD 4.

IF LW_VAR EQ 0.

CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '29' INTO LW_STR_HIGH.

LW_DATE2 = LW_STR_HIGH.

WRITE LW_DATE2.

ELSE.

CONCATENATE LW_STR_HIGH1 LW_STR_HIGH2 '28' INTO LW_STR_HIGH.

LW_DATE2 = LW_STR_HIGH.

WRITE LW_DATE2.

ENDIF.

ENDIF.

*End:-To check for Leap Year when February.

ENDIF.

*Since we have low and high dates in two different strings,they directly

*cannot be passed to standard table (MSEG).So we first get them into RO_DATE.

RO_DATE-SIGN = 'I'.

RO_DATE-OPTION = 'BT'.

RO_DATE-LOW = LW_DATE1.

RO_DATE-HIGH = LW_DATE2.

APPEND RO_DATE.

ENDFORM. " CONVERT_MMYYYY_TO_DDMMYYY

Plz help me.

Vijay

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 09:37 AM

    hi vijay,

    use this function modules to convert the date format

    convert_date_format

    convert_date_to_intern_format

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 07, 2008 at 09:46 AM

    Vijay,

    ex: Assume getting date "mmddyyyy" in field v_date.

    to convert the date to ddmmyyyy

    CONCATENATE v_date2(2) v_date0(2) v_date+4(4)

    into v_date .

    Pls. reward if useful...

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.