User Tools

Site Tools


ABAP Date Formatting

Il existe moultes techniques pour formater des dates :

* Using the WRITE statement
  data: gd_date(10).  "field to store output date
* Converts SAP date from 20020901 to 01.09.2002
  write sy-datum to gd_date dd/mm/yyyy.
* Converts SAP date from 20020901 to 01.09.02
  write sy-datum to gd_date dd/mm/yy.
* Using data manipulation techniques
  data: gd_date(8).  "field to store output date
* Converts SAP date from 20010901 to 01092001
  gd_date(2)   = sy-datum+6(2).
  gd_date+2(2) = sy-datum+4(2).
  gd_date+4(4) = sy-datum(4).
data mydate like sy-datum.
data: year(4) type c,
      month(2) type c,
      date(2) type c.
year = mydate(4).
month = mydate+4(2).
date = mydate+6(2).
write: / year no-gap, month no-gap, date.
* Using Function modules
  data: gd_date(8).  "field to store output date
* Converts date from 20010901 to 01SEP2001
  gd_date   = sy-datum.
      input         = gd_date
      OUTPUT        = gd_date.
* Do you want to WRITE it to a list screen? Use the formatting options described in the documentation and online help:
    data : date(10)  type  c value '01122004'.
    WRITE l_my_date MM/DD/YYYY.
    write:/ gv_date edit mask 'YYYY.MM.DD'.
    write:/ date using edit mask '__/__/____'. 
                   T_0008-BEGDA(04)  INTO T_AUX-DT_ALT. 
* To set the date format in a SAPscript form, see the SET DATE MASK command.
* To print the formatted date in a SmartForm, use the WRITE command and a temporary variable (yes, ugly, I know...)
* Most controls (ALV Grid for example) should take care of the format automatically.
if w_country is initial.
  select single LAND1
    from T001W
    into w_country
   where WERKS eq w_the_plant.
SET COUNTRY w_country.
write w_the_date to w_export.
abap/format_string/date.txt · Last modified: 2014/11/18 16:07 by ginko