Application Development 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: 

Date Format in Zreport similar to the default date format set using su01.

Former Member
0 Kudos

Dear All,

I have a requirement as to change the date format in Zreport as the one which is set in default date format for the user in Su01 tcode.

Ex.. If the user has set the default date format in SU01 as ' YYYY-MM-DD' , in report also, date should appear as '2009-12-24'.

Is there any code or Function Module to change the date format in report as in the default Date format?

Can u help me in this?

Bye.....

Cheers

Christina.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

1. First you need to get the user default date format

Use function module BAPI_USER_GET_DETAIL

You will get the default date format in the parameter DEFAULTS-DATFM (Values 1 to 9, A, B etc)

Example (see value range for domain XUDATFM)

1	DD.MM.YYYY
2	MM/DD/YYYY
3	MM-DD-YYYY
4	YYYY.MM.DD
5	YYYY/MM/DD
6	YYYY-MM-DD

2. Use function module FORMAT_DATE_4_OUTPUT (Pass the above format in the parameter FORMAT)

Note that the function module handles most of the date format. But i am not sure about the Japenese date format (GYY.MM.DD etc)

Regards

10 REPLIES 10

Former Member
0 Kudos

Hi,

1. First you need to get the user default date format

Use function module BAPI_USER_GET_DETAIL

You will get the default date format in the parameter DEFAULTS-DATFM (Values 1 to 9, A, B etc)

Example (see value range for domain XUDATFM)

1	DD.MM.YYYY
2	MM/DD/YYYY
3	MM-DD-YYYY
4	YYYY.MM.DD
5	YYYY/MM/DD
6	YYYY-MM-DD

2. Use function module FORMAT_DATE_4_OUTPUT (Pass the above format in the parameter FORMAT)

Note that the function module handles most of the date format. But i am not sure about the Japenese date format (GYY.MM.DD etc)

Regards

0 Kudos

Hi

Thanks for your reply...

I logged off SAP and relogged in again. But the date format did not change.So i tried using the second method.

I got the default vlues for the user using the FM ''BAPI_USER_GET_DETAIL".

But since we r using ECC 5 , i think there is no FM "FORMAT_DATE_4_OUTPUT" . It says FM does no exist. I think this FM is available only in ECC 6.

is there any other FM to get the date format instead of "FORMAT_DATE_4_OUTPUT".

Thanks

Cheers

Christina.

0 Kudos

Try the following code.

  • select the format of current user from usr01 table.

SELECT SINGLE datfm FROM usr01

INTO w_datfm

WHERE bname = sy-uname.

Format based upon the current user settings. put this total code inside one form for reusability.

IF w_datfm = '1'.

CONCATENATE w_date6(2) c_dot w_date4(2) c_dot w_date+0(4) INTO outtab-value.

CONDENSE outtab-value NO-GAPS.

CONCATENATE w_rundate6(4) w_rundate3(2) w_rundate+0(2) INTO w_date.

CONDENSE w_date NO-GAPS.

ELSEIF w_datfm = '2'.

CONCATENATE w_date4(2) '/' w_date6(2) '/' w_date+0(4) INTO outtab-value.

CONDENSE outtab-value NO-GAPS.

CONCATENATE w_rundate6(4) w_rundate0(2) w_rundate+3(2) INTO w_date.

CONDENSE w_date.

ELSEIF w_datfm = '3'.

CONCATENATE w_date4(2) '-' w_date6(2) '-' w_date+0(4) INTO outtab-value.

CONDENSE outtab-value NO-GAPS.

CONCATENATE w_rundate6(4) w_rundate0(2) w_rundate+3(2) INTO w_date.

CONDENSE w_date.

ELSEIF w_datfm = '4'.

CONCATENATE w_date0(4) '-' w_date4(2) '-' w_date+6(2) INTO outtab-value.

CONDENSE outtab-value NO-GAPS.

CONCATENATE w_rundate0(4) w_rundate5(2) w_rundate+8(2) INTO w_date.

CONDENSE w_date NO-GAPS.

ELSEIF w_datfm = '5'.

CONCATENATE w_date0(4) '/' w_date4(2) '/' w_date+6(2) INTO outtab-value.

CONDENSE outtab-value NO-GAPS.

CONCATENATE w_rundate0(4) w_rundate5(2) w_rundate+8(2) INTO w_date.

CONDENSE w_date NO-GAPS.

ENDIF.

0 Kudos

Hi,

Try function module

CONVERSION_EXIT_PDATE_OUTPUT

Input should be in format 20090101 (Internal format)

1. Change the date in SU01

2. Logoff from system or run report RSUSR405 (For the changes in SU01 to be effective either one should be done)

3. use CONVERSION_EXIT_PDATE_OUTPUT

Note that there is no need to get the user default date in this case as it is taken care by the WRITE statement inside the module

Regards

0 Kudos

Hi

Thank You .. This FM 'CONVERSION_EXIT_PDATE_OUTPUT' Solved my problem..

Cheers

Christina.

former_member195698
Active Contributor
0 Kudos

As far as I know..the format that appears by Default for date printing in List is picked from SU01 parameters. (or SU3)

But the Date Format Is not reflected just by changing the format, you need to Log Off and Log In again to see the changed format in the output.

Regards,

Aj

Former Member
0 Kudos

Hello,

Please check the FM SUSR_GET_USER_DEFAULTS. This gives the system user default for the user id. Based on this you can change the date format in your report.

Cheers,

Balaji

Former Member
0 Kudos

Hi,

One FM is there as :

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

EXPORTING

DATE_INTERNAL = P_BUDAT

IMPORTING

DATE_EXTERNAL = V_DATE

EXCEPTIONS

DATE_INTERNAL_IS_INVALID = 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.

Second option is to achieve it using some variable declaration as follows:

data : DATA: YEAR(4),

DATE(2),

MONT(2).

date = p_budat(2).

mont = p_budat+2(2).

year = p_budat+4(4).

CONCATENATE year mont date INTO z_date separated by '-'.

Former Member
0 Kudos

Hi,

What Abhishek said is right in case of lists reports. For any other case you can use what i suggested.

Regards

Former Member
0 Kudos

Hi Lavanya,

Please see the code as below/

select single datfm from usr01 into gv_datfm where bname = sy-uname .

  • change the date and quantity fiels.

if gv_datfm = '2'.

write gwa_gmhead-pstng_date to gv_budat mm/dd/yyyy .

write gwa_gmhead-doc_date to gv_bldat mm/dd/yyyy .

write gv_asset_val_dat to gv_ass_val_dat mm/dd/yyyy .

elseif gv_datfm = '1' .

concatenate gwa_gmhead-pstng_date6(2) gwa_gmhead-pstng_date4(2) gwa_gmhead-pstng_date+0(4)

into gv_budat separated by '.'.

concatenate gwa_gmhead-doc_date6(2) gwa_gmhead-doc_date4(2) gwa_gmhead-doc_date+0(4)

into gv_bldat separated by '.'.

concatenate gv_asset_val_dat6(2) gv_asset_val_dat4(2) gv_asset_val_dat+0(4)

into gv_ass_val_dat separated by '.'.

elseif gv_datfm = '5' .

concatenate gwa_gmhead-pstng_date0(4) gwa_gmhead-pstng_date4(2) gwa_gmhead-pstng_date+6(2)

into gv_budat separated by '/'.

concatenate gwa_gmhead-doc_date0(4) gwa_gmhead-doc_date4(2) gwa_gmhead-doc_date+6(2)

into gv_bldat separated by '/'.

concatenate gv_asset_val_dat0(4) gv_asset_val_dat4(2) gv_asset_val_dat+6(2)

into gv_ass_val_dat separated by '/'.

Thanks,

Deepanker Dwivedi