Skip to Content
0
Former Member
Jan 07, 2008 at 09:22 AM

convert mmyyyy to ddmmyyyy format

68 Views

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