2013 Dec 04 1:16 AM
Hi Gurus,
I created a report which output ALV grid as below:
But user want to change the display Date format (as YYYY/MM/DD) and display Decimal Format (as 1,234,567.89) as below From SU3 (Maintain User Profile) :
But I am not sure how to set this in my program, can any experts give me direction?
Really appreciate your help.
2013 Dec 04 1:44 AM
Hi Gurus,
I created a report which output ALV grid as below:
But user want to change the display Date format (as YYYY/MM/DD) and display Decimal Format (as 1,234,567.89) as below From SU3 (Maintain User Profile) :
But I am not sure how to set this in my program, can any experts give me direction?
Really appreciate your help.
2013 Dec 04 1:44 AM
2013 Dec 04 1:55 AM
Thank you Jack for the response.
I am just wonderinga is it possible to do what user want, I meant user can change the ALV date display format according what they set in SU3?
2013 Dec 04 4:56 AM
Hi,
Yes it is possible.
-> you need to get the date format of the user as per the SU3 settings. For this you can use the below FM: SUSR_USER_DEFAULT_DATE_FORMAT ( FM provide the user date format)
-> Pass the date format and date to this FM /OSP/TRVL_DATE_IN_USER_FORMATE
Example:
CALL FUNCTION 'SUSR_USER_DEFAULT_DATE_FORMAT'
IMPORTING
DATFM = l_dateformat.
CALL FUNCTION '/OSP/TRVL_DATE_IN_USER_FORMATE'
EXPORTING
iv_date = date " which you want to display
IV_DATE_FORMATE = l_dateformat
IMPORTING
EV_DATE_TEXT = alv_date
2013 Dec 04 6:06 AM
Yes Blue,
Its very simple.
In the field catalog, just set the following attributes for the date field. The format as defined in logon master data of user would be used to display the date field.
LVC_S_FCAT-DATATYPE = 'DATS'.
LVC_S_FCAT-INTTYPE = 'D'.
LVC_S_FCAT-INTLEN = '000008'.
LVC_S_FCAT-DD_OUTLEN = '000010'.
Or another option is, you could just move this to a date field in the internal table. The date format in ALV would automatically be according to SU3 settings.
begin of it_data.
...
date type datum "date type ekbe-budat.
...
end of it_data.
2013 Dec 04 1:21 PM
Hi Susmitha,
Thank you so much for your reply. I used your way, it is simple and works well.
The only thing is the DATA in the other columns seems all messed up, and also do you know how to do the same thing for Decimal format set in SU3?
2013 Dec 04 2:05 PM
Hi kiran,
I tried your way, the syntax is correct, but it seems not outputing the Date format set in SU3. Not sure if I missed anything
2013 Dec 05 2:54 AM
Have you cleared the field catalog work area before adding the attributes of other columns?
LVC_S_FCAT-DATATYPE = 'DATS'.
....
APPEND lvc_s_fcat TO lvc_t_fieldcat.
clear LVC_S_FCAT.
Probably the clear statement is missing after you set the attributes of the date column in field catalog.
For decimal numbers, try this.
LVC_S_FCAT-datatype = 'QUAN' .
LVC_S_FCAT-inttype = 'P'.
LVC_S_FCAT-intlen = 13 .
LVC_S_FCAT-dd_outlen = 17 .
......
APPEND lvc_s_fcat TO lvc_t_fieldcat.
clear LVC_S_FCAT.
2013 Dec 04 7:11 AM
Hi,
For date.
I suppose you got a list box. You can feel it with different formats of date.
To do so you can use the following link.
FUNCTION MODULE FOR CONVERTING DATE INTO THE GIVEN FORMAT - Code Gallery - SCN Wiki
Then use the following FM to convert date into user selected format.
FORMAT_DATE_4_OUTPUT.
And pass that value to the ALV.
For decimal notation.
Create a list box with entries like in field DCPFM of USR01.
For logic please check the below link.
https://scn.sap.com/thread/1449990
Hope this helps.
BR
2013 Dec 04 1:26 PM
Table USR01 stores the date format and user format for user.
Pass the user name to the table USR01, and get the date and decimals format.
Based on the user fomate, change the date and decimal formate.
2013 Dec 04 1:45 PM
Thank you abap udupi for your reply.
Is it possible to set Decimal format using FieldCatalog like Susmitha suggested for Date format as below?
LVC_S_FCAT-DATATYPE = 'DATS'.
LVC_S_FCAT-INTTYPE = 'D'.
LVC_S_FCAT-INTLEN = '000008'.
LVC_S_FCAT-DD_OUTLEN = '000010'.
2013 Dec 04 2:01 PM
you need to use the date function module DATE EXTERNAL FORMAT and DATE INTERNAL FORMAT.
or else u can concatenate depend on the formate
2013 Dec 04 2:03 PM
Hi abap,
Is it possible you give a sample code on how to use DATE EXTERNAL FORMAT and DATE INTERNAL FORMAT?
2013 Dec 04 2:15 PM
u can use concatenate also.
for example if u get the '/' date format
concatenate DD '/' MM '/' YYYY into s_date.
similarly if u get the '.' date format
concatenate DD '/' MM '.' YYYY into s_date.
2013 Dec 05 6:06 AM
This should be default behavior if variable is declared correctly.
Ex:
DATA lv_date TYPE c LENGTH 8. --> results date in YYYYMMDD format
DATA lv_date1 TYPE D. --> results date in YYYYMMDD format
DATA lv_date2 TYPE DATS. --> results date in User default format
DATA lv_date3 TYPE sy-datum. --> results date in User default format
DATA lv_date4 TYPE vbak-erdat. --> results date in User default format
Alternatively, Date format can be modified by providing the 'Reference field' (REF_FIELD) and 'Reference table' (REF_TABLE) in field catalog(structure LVC_S_FCAT).
Same holds good for quantity field also.
For Date format conversion, other alternative solution is to call function module 'SLS_MISC_CONVERT_TO_DATE' to convert date into user default format from system default format(YYYYMMDD).
Please check and let us know the result.
2013 Dec 05 10:06 AM
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |