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 according to user requirement

sivakrishna_boddapati
Participant
0 Kudos

Hi experts

I have a selection-screen date field when user enter date with the help of F4 it shows error message like this

Input date format like this : 09/01/2010

Please Enter date in the format : __.__.____ like this

is there any function modules to convert date like this format .

Thanks & Regards

Siva Krishna.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

The out put format of date depends on the user settings. Ask user to choose the settings which he wants to have for date.

System->user profile>own data->defaults.

change the date format here and it will appear as you want.

8 REPLIES 8

Former Member
0 Kudos

Hi,

The out put format of date depends on the user settings. Ask user to choose the settings which he wants to have for date.

System->user profile>own data->defaults.

change the date format here and it will appear as you want.

0 Kudos

Thanks for your answer is there any way to get F4_help also comes with that format I.e according to user settings

When user enter date with the help F4 : The input like this : 09.01.2010

is there any function module to convert like this with the help at selection screen on value request

0 Kudos

Hi,

Use the following FM:

DATE_TO_PERIOD_CONVERT

Thanks & Regardss

Rocky

0 Kudos

Hi,

i don't get you completely, but if you define date of type sy-datum. F4 help automatically comes up and when user choose date , it comes up according to his settings. this is I think the standard way for date currency and other user specific fields.

Former Member
0 Kudos

Hi

You can use CONVERSION_EXIT_ALPA_INPUT function module

or else make use of OFFSETS.

Regards,

Pravin

Pranay_Panchbha
Participant
0 Kudos

To solve this purpose, a function module has been created which takes the date and format (in which date needs to be converted) as input and gives the date in the desired format as output. It also raises an exception if the format is incorrect.

For achieving this functionality, a ztable is to be created which contains all the possible formats of a date. Then the format given on the screen is to be validated against this table.

*

STRUCTURE OF THE FUNCTION MODULE

FUNCTION zdummy_date_conv.

*"----


""Local Interface:

*" IMPORTING

*" REFERENCE(DATE) TYPE SYDATUM

*" REFERENCE(FORMAT) TYPE CHAR15

*" EXPORTING

*" REFERENCE(DATE_FINAL) TYPE CHAR15

*" EXCEPTIONS

*" INCORRECT_FORMAT

*"----


*

POSSIBLE DATE FORMATS

DATE FORMATS

DD.MM.YY

MM.DD.YY

MM.YY.DD

YY.MM.DD

YY.DD.MM

DD.YY.MM

DD-MM-YY

MM-DD-YY

MM-YY-DD

YY-MM-DD

YY-DD-MM

DD-YY-MM

DD/MM/YY

MM/DD/YY

MM/YY/DD

YY/MM/DD

YY/DD/MM

DD/YY/MM

DDMMYY

MMDDYY

MMYYDD

YYMMDD

YYDDMM

DDYYMM

DD.MMM.YY

MMM.DD.YY

MMM.YY.DD

YY.MMM.DD

YY.DD.MMM

DD.YY.MMM

DD-MMM-YY

MMM-DD-YY

MMM-YY-DD

YY-MMM-DD

YY-DD-MMM

DD-YY-MMM

DD/MMM/YY

MMM/DD/YY

MMM/YY/DD

YY/MMM/DD

YY/DD/MMM

DD/YY/MMM

DDMMMYY

MMMDDYY

MMMYYDD

YYMMMDD

YYDDMMM

DDYYMMM

DD.MM.YYYY

MM.DD.YYYY

MM.YYYY.DD

YYYY.MM.DD

YYYY.DD.MM

DD.YYYY.MM

DD-MM-YYYY

MM-DD-YYYY

MM-YYYY-DD

YYYY-MM-DD

YYYY-DD-MM

DD-YYYY-MM

DD/MM/YYYY

MM/DD/YYYY

MM/YYYY/DD

YYYY/MM/DD

YYYY/DD/MM

DD/YYYY/MM

DDMMYYYY

MMDDYYYY

MMYYYYDD

YYYYMMDD

YYYYDDMM

DDYYYYMM

DD.MMM.YYYY

MMM.DD.YYYY

MMM.YYYY.DD

YYYY.MMM.DD

YYYY.DD.MMM

DD.YYYY.MMM

DD-MMM-YYYY

MMM-DD-YYYY

MMM-YYYY-DD

YYYY-MMM-DD

YYYY-DD-MMM

DD-YYYY-MMM

DD/MMM/YYYY

MMM/DD/YYYY

MMM/YYYY/DD

YYYY/MMM/DD

YYYY/DD/MMM

DD/YYYY/MMM

DDMMMYYYY

MMMDDYYYY

MMMYYYYDD

YYYYMMMDD

YYYYDDMMM

DDYYYYMMM

*

CODE OF FUNCTION MODULE

FUNCTION zdummy_date_conv.

*"----


""Local Interface:

*" IMPORTING

*" REFERENCE(DATE) TYPE SYDATUM

*" REFERENCE(FORMAT) TYPE CHAR15

*" EXPORTING

*" REFERENCE(DATE_FINAL) TYPE CHAR15

*" EXCEPTIONS

*" INCORRECT_FORMAT

*"----


  • Local variables declaration

DATA: l_y1 TYPE numc1,

l_y2 TYPE numc1,

l_y3 TYPE numc1,

l_y4 TYPE numc1,

l_m1 TYPE numc1,

l_m2 TYPE numc1,

l_d1 TYPE numc1,

l_d2 TYPE numc1,

l_len TYPE int1,

l_ctr TYPE int1,

w_t247 TYPE t247,

l_flag_m1 TYPE char1,

l_flag_init TYPE char1,

l_flag_d TYPE char1,

l_flag_y TYPE char1,

l_format TYPE char15,

l_final_date TYPE char15.

  • Local constants declaration

CONSTANTS: c_d TYPE char1 VALUE 'D',

c_m TYPE char1 VALUE 'M',

c_y TYPE char1 VALUE 'Y',

c_mmm TYPE char3 VALUE 'MMM',

c_yyyy TYPE char4 VALUE 'YYYY'.

  • Checking the format given by user.

SELECT SINGLE zformat

FROM zformat_date

INTO l_format

WHERE zformat = format.

IF sy-subrc EQ 0.

  • Processing Logic of the routine

l_y1 = date+0(1).

l_y2 = date+1(1).

l_y3 = date+2(1).

l_y4 = date+3(1).

l_m1 = date+4(1).

l_m2 = date+5(1).

l_d1 = date+6(1).

l_d2 = date+7(1).

l_len = STRLEN( format ).

CLEAR : l_flag_m1, l_flag_init, l_flag_d,l_flag_y.

WHILE l_ctr < l_len.

IF format+l_ctr(1) = c_m.

IF NOT format CS c_mmm.

l_final_date+l_ctr(1) = l_m1.

l_ctr = l_ctr + 1.

l_flag_m1 = l_flag_m1 + 1.

l_final_date+l_ctr(1) = l_m2.

l_ctr = l_ctr + 1.

l_flag_m1 = l_flag_m1 + 1.

ELSE.

SELECT SINGLE * FROM t247 INTO w_t247

WHERE spras = sy-langu

AND mnr = date+4(2).

IF sy-subrc EQ 0.

l_final_date+l_ctr(3) = w_t247-ktx.

l_ctr = l_ctr + 3.

ENDIF.

ENDIF.

ELSEIF format+l_ctr(1) = c_y.

IF format CS c_yyyy.

l_final_date+l_ctr(1) = l_y1.

l_ctr = l_ctr + 1.

l_final_date+l_ctr(1) = l_y2.

l_ctr = l_ctr + 1.

l_final_date+l_ctr(1) = l_y3.

l_ctr = l_ctr + 1.

l_final_date+l_ctr(1) = l_y4.

l_ctr = l_ctr + 1.

ELSE.

l_final_date+l_ctr(1) = l_y3.

l_ctr = l_ctr + 1.

l_flag_y = l_flag_y + 1.

l_final_date+l_ctr(1) = l_y4.

l_ctr = l_ctr + 1.

l_flag_y = l_flag_y + 1.

ENDIF.

ELSEIF format+l_ctr(1) = c_d.

l_final_date+l_ctr(1) = l_d1.

l_ctr = l_ctr + 1.

l_flag_d = l_flag_d + 1.

l_final_date+l_ctr(1) = l_d2.

l_ctr = l_ctr + 1.

l_flag_d = l_flag_d + 1.

ELSE.

l_final_datel_ctr(1) = formatl_ctr(1).

l_ctr = l_ctr + 1.

ENDIF.

IF NOT l_final_date IS INITIAL.

date_final = l_final_date.

ENDIF.

ENDWHILE.

ELSE.

CLEAR date_final.

RAISE incorrect_format.

ENDIF.

ENDFUNCTION.

Former Member
0 Kudos

Hi,

When you select the date through F4 help, the date format will come in the same format as the User System's Setting.

You can either handle it through Write To command or use some logic topass it into the required fields.

Read the date as your getting into internal table and pass it to date field.

Data: w_year(4) TYPE n, " Year

w_month(2) TYPE n, " Month

w_day(2) TYPE n, " Day

w_date(10) TYPE c. " Date

w_year = wa_header-invoice_date+4(4).

w_month = wa_header-invoice_date+2(2).

w_day = wa_header-invoice_date+0(2).

CONCATENATE w_day w_month w_year INTO w_date

SEPARATED BY '.'( AS per your requirement)

Former Member
0 Kudos

If you have the field described as type D or dats or for sy-datum, why is this a problem? SAP expects the input to be in the individual users' own formats.... So, if you write your selection screen correctly, SAP will handle this for you, regardless of the users' settings.