Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

User setting for date format and decimal format

Former Member
0 Likes
7,857

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,987

Please you refer to the following link,

Maybe you need to change your fields' format  in your program.

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.

15 REPLIES 15
Read only

Former Member
0 Likes
4,988

Please you refer to the following link,

Maybe you need to change your fields' format  in your program.

Read only

0 Likes
4,987

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?

Read only

0 Likes
4,987

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

Read only

0 Likes
4,987

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.

Read only

0 Likes
4,987

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?


Read only

0 Likes
4,987

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

Read only

0 Likes
4,987

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.

Read only

Former Member
0 Likes
4,987

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

Read only

0 Likes
4,987

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.

Read only

0 Likes
4,987

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'.

Read only

0 Likes
4,987

you need to use the date function module DATE EXTERNAL FORMAT and DATE INTERNAL FORMAT.

or else u can concatenate depend on the formate

Read only

0 Likes
4,987

Hi abap,

Is it possible you give a sample code on how to use DATE EXTERNAL FORMAT and DATE INTERNAL FORMAT?

Read only

0 Likes
4,987

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.

Read only

former_member215575
Active Participant
0 Likes
4,987

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.

Read only

Former Member
0 Likes
4,987