cancel
Showing results for 
Search instead for 
Did you mean: 

Formatting a date in YYYY-MM-DD format in a grid in We dynpro abap

former_member402443
Contributor
0 Kudos

Hi All,

I have the requirement to display a date in YYYY-MM-DD format in a salv_wd_table grid .

when i selecting the date from the calender that attached to a column in the grid will show in DD-MM-YYYY format.

Please help in this.

Accepted Solutions (0)

Answers (1)

Answers (1)

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Hi Manoj

Change the User's Default Date Format in SU01 transaction

Abhi

former_member402443
Contributor
0 Kudos

Hi Abhimanyu ,

I don't want like that.

Iwant to know is there any other way apart from this or any property to set the format of a column in salv grid.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Hi Abhimanyu ,

>

> I don't want like that.

> Iwant to know is there any other way apart from this or any property to set the format of a column in salv grid.

ABAP is pretty good about automatically using the user's profile settings for formatting. That enforces consistency across applications. If you want to override this, you will need to do it at the data level. Instead of defining this field in the context as a data - define it like a string or char10. Then when you populate the data within your business logic do a WRITE statement from the data field to the character field. During the WRITE command you can specify the date formatting option:

From the online syntax of WRITE:

Addition 15

... DD/MM/YY | MM/DD/YY

| DD/MM/YYYY | MM/DD/YYYY

| DDMMYY | MMDDYY

| YYMMDD

Effect: These additions influence the output of data objects of the data type d. In all other data types, the addition is ignored.

The content of a data object of type d is interpreted as a valid date in the format YYYYMMDD and is output as follows for the individual additions:

DD/MM/YY and MM/DD/YY:

Both additions have the same effect. The date output has a two-digit year value and a separator. The separator and the order are taken from the definition for date output in the user master record.

DD/MM/YYYY und MM/DD/YYYY:

Both additions have the same effect. The date output has a four-digit year value and separator. The separator and the order are taken from the definition for date output in the user master record.

DDMMYY und MMDDYY:

Both additions have the same effect. The date output has a two-digit year value and no separator. The order is taken from the definition for date output in the user master record.

YYMMDD:

This addition provides a date output with a two-digit year value without a separator in the format YYMMDD.

But even this approach is going to have limited impact. It will only let you chose between the allowed formatting types from the user master. YYYY-MM-DD is not one of those formats.

So if you really want a non-SAP formatted date you will have to break it up yourself. The internal date format is always stored as YYYYMMDD. You can just parse it out:

data year type char4.
data month type char2.
data day type char2.

year = sy-datum+0(4).
month = sy-datum+4(2).
day = sy-datum+6(2).

data date_string type char10.
concatenate year `-` month `-` day into date_string.