Reputation: 18816
I need to split ABAP date like
20091101 --> "01", "november", "2009"
The "01" and "2009" are trivial, but how do I get the month name (which should be localized)?
Is there a function to do that?
If there is no such function, perhaps a table with month names?
Upvotes: 9
Views: 30930
Reputation: 9
PARAMETERS: P_1 TYPE SY-DATUM.
DATA : LV_DATE TYPE SY-DATUM,LV_TIME TYPE SY-UZEIT,lv_month type string.
LV_TIME = SY-UZEIT.
DATA: YEAR(4) TYPE C,
MONTH(2) TYPE C,
DAY(2) TYPE C.
YEAR = P_1+0(4).
MONTH = P_1+4(2).
DAY = P_1+6(2).
IF MONTH = '01'.
lv_month = 'JAN'.
ELSEIF Month = '02'.
lv_month = 'Feb'.
ELSEIF Month = '03'.
lv_month = 'Mar'.
ELSEIF Month = '04'.
lv_month = 'Apr'.
ELSEIF Month = '05'.
lv_month = 'May'.
ELSEIF Month = '06'.
lv_month = 'Jun'.
ELSEIF Month = '07'.
lv_month = 'Jul'.
ELSEIF Month = '08'.
lv_month = 'Aug'.
ELSEIF Month = '09'.
lv_month = 'Sep'.
ELSEIF Month = '10'.
lv_month = 'Oct'.
ELSEIF Month = '11'.
lv_month = 'Nov'.
ELSEIF Month = '12'.
lv_month = 'Dec'.
ENDIF.
WRITE: '|',day NO-GAP,'-',
lv_month NO-GAP,'-',year NO-GAP.
Upvotes: -1
Reputation: 1
data : lv_timestamp TYPE string,
lv_str TYPE STRING.
concatenate sy-datum sy-uzeit into lv_timestamp.
concatenate 'C:\Users\Roopa Rani\desktop\header' '_' lv_timestamp '.txt' INTO FILEPATH.
I think it's useful.
Upvotes: -2
Reputation: 76
Normally you can also export the date into the plant level country specific date format:
if w_country is initial.
select single LAND1
from T001W
into w_country
where WERKS eq w_the_plant.
endif.
SET COUNTRY w_country.
write w_the_date to w_export.
Upvotes: 1
Reputation: 285
* to get full name of the day / month also can use
GET_MONTH_NAME ... for month and
GET_DATE_DAYNAME for the specific day name too
and other methods to get other format of the date are
Using the WRITE statement
data: get_date(10). "field to store output date
Converts SAP date from 20130901 to 01.09.2013
write sy-datum to get_date dd/mm/yyyy.
Converts SAP date from 20130901 to 01.09.13
write sy-datum to get_date dd/mm/yy.
Using data manipulation techniques
data: get_date(8). "field to store output date
Converts SAP date from 20130901 to 01092013
get_date(2) = sy-datum+6(2).
get_date+2(2) = sy-datum+4(2).
get_date+4(4) = sy-datum(4).
Using Function modules
data: get_date(8). "field to store output date
Converts date from 20130901 to 01SEP2013
get_date = sy-datum.
CALL FUNCTION 'CONVERSION_EXIT_IDATE_OUTPUT'
EXPORTING
input = get_date
IMPORTING
OUTPUT = get_date.
these all the formats you can use for the specific dates/months and year
Upvotes: 2
Reputation: 31
This code will give you the date in the long text format like 'December 02, 2011'. You may change the code accordingly to print the date with long MONTH name.
DATA: LONG_DATE(20).
PERFORM GET_LONG_DATE USING LONG_DATE.
WRITE: LONG_DATE.
FORM GET_LONG_DATE USING DATE.
DATA: T_MONTH_NAMES LIKE TABLE OF T247 WITH HEADER LINE.
CALL FUNCTION 'MONTH_NAMES_GET'
EXPORTING
LANGUAGE = SY-LANGU
TABLES
MONTH_NAMES = T_MONTH_NAMES
.
DATA: YEAR(4) TYPE C,
MONTH(2) TYPE C,
DAY(2) TYPE C.
YEAR = SY-DATUM+(4).
MONTH = SY-DATUM+4(2).
DAY = SY-DATUM+6(2).
READ TABLE T_MONTH_NAMES INDEX ( MONTH ).
CONCATENATE T_MONTH_NAMES-LTX ' ' DAY INTO DATE SEPARATED BY SPACE.
CONCATENATE DATE ',' INTO DATE.
CONCATENATE DATE YEAR INTO DATE SEPARATED BY SPACE.
WRITE / DATE.
ENDFORM.
Upvotes: 3
Reputation: 343
You may use a simple FM 'MONTH_NAMES_GET'
CALL FUNCTION 'MONTH_NAMES_GET'
EXPORTING
LANGUAGE = SY-LANGU
* IMPORTING
* RETURN_CODE =
TABLES
month_names = it_t247
EXCEPTIONS
MONTH_NAMES_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.
Upvotes: 0
Reputation: 18591
I think the absolute simplest way would be to apply the conversion exit LDATE to your date field. Easiest is to call function module CONVERSION_EXIT_LDATE_OUTPUT.
This would for example convert
20090101
to
01. January 2009
(Unless you need to actually have the day, month text and year in separate strings, which you seem to indicate. Anyway, maybe it will help someone else).
Upvotes: 3
Reputation: 4337
You can get the month's name in a given language using the module function 'MONTH_NAMES_GET
', passing the language as a parameter. The day (Sunday for example) can also be obtained using 'RH_GET_DATE_DAYNAME
'
Guillaume
Upvotes: 8