Ich habe eine Konvertierungs-/ Aufbereitungsroutine im SDN ausfindig machen können, welche die Benutzerabhängigkeit "austrickst" und auch ein paar schöne Aufbereitungsoptionen besitzt, die so im Standard nicht vorhanden sind.
Eine Sprachenabhängige Steuerung der Monatsnamen habe ich in die Schnittstelle aufgenommen.
Anders als im SDN-Template, habe ich die Prüfwerte der möglichen Aufbereitungsoptionen
in das Coding übernommen. (siehe ausgesternte Abschnitte)
Wer sicher ist, das Er/Sie sich nicht vertippt, kann den Abschnitt auch völlig streichen.
Die Originalvorlage findet Ihr:
http://wiki.sdn.sap.com/wiki/display/Sn ... VEN+FORMAT
Das neue Coding des Funktionsbausteins:
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- FUNCTION Y_BC_DATE_CONVERT .
- *"----------------------------------------------------------------------
- *"*"Lokale Schnittstelle:
- *" IMPORTING
- *" REFERENCE(DATE) TYPE SYDATUM DEFAULT SY-DATUM
- *" REFERENCE(FORMAT) TYPE CHAR15
- *" REFERENCE(LANGU) TYPE SYST-LANGU DEFAULT SY-LANGU
- *" EXPORTING
- *" REFERENCE(DATE_FINAL) TYPE CHAR15
- *" EXCEPTIONS
- *" INCORRECT_FORMAT
- *"----------------------------------------------------------------------
- * Local variables declaration
- 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
- c_m TYPE char1 VALUE 'M',
- c_y TYPE char1 VALUE 'Y',
- c_mmm TYPE char3 VALUE 'MMM',
- c_yyyy TYPE char4 VALUE 'YYYY'.
- PERFORM init_dateref.
- * Checking the format given by user.
- CLEAR l_format.
- * SELECT SINGLE zformat
- * FROM zformat_date
- * INTO l_format
- * WHERE zformat = format.
- * 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_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).
- WHERE spras = langu
- AND mnr = date+4(2).
- l_final_date+l_ctr(3) = w_t247-ktx.
- l_ctr = l_ctr + 3.
- 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.
- 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_ctr = l_ctr + 1.
- date_final = l_final_date.
- ELSE.
- CLEAR date_final.
- RAISE incorrect_format.
- *&---------------------------------------------------------------------*
- *& Form init_dateref
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- FORM init_dateref.
- GeSHi ©
Muß in den Top-Include
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- GeSHi ©
Ein kleines Testprogramm:
- Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
- *&---------------------------------------------------------------------*
- *& Report YBC_TEST_DATECONVERT
- *&
- *&---------------------------------------------------------------------*
- *&
- *&
- *&---------------------------------------------------------------------*
- REPORT YBC_TEST_DATECONVERT.
- break bcuser.
- CALL FUNCTION 'Y_BC_DATE_CONVERT'
- EXPORTING
- * DATE = SY-DATUM
- format = f1
- IMPORTING
- DATE_FINAL = df
- EXCEPTIONS
- INCORRECT_FORMAT = 1
- OTHERS = 2.
- break bcuser.
- CALL FUNCTION 'Y_BC_DATE_CONVERT'
- EXPORTING
- * DATE = SY-DATUM
- format = f2
- IMPORTING
- DATE_FINAL = df
- EXCEPTIONS
- INCORRECT_FORMAT = 1
- OTHERS = 2.
- break bcuser.
- CALL FUNCTION 'Y_BC_DATE_CONVERT'
- EXPORTING
- * DATE = SY-DATUM
- format = f3
- IMPORTING
- DATE_FINAL = df
- EXCEPTIONS
- INCORRECT_FORMAT = 1
- OTHERS = 2.
- break bcuser.
- GeSHi ©
Der Einsatz in Smartforms:
Der Aufruf als globale FORM-Routine
![Image](https://public.blu.livefilestore.com/y1pYI212MBxZjZzFj6xErHYORNYdgE_i1DSyOwkx1UnraptfhOZNl2zyLql0D2VodRvJoabIBKp9sf1qn6eDvnGBg/000.png)
Ergebnis:
![Image](https://public.blu.livefilestore.com/y1pc4D0QnudTer_aFHjCWufZo_iaLfKl1JDBLYtQoopYBx7ifYOdGtJ5LQIWQrSHOxdarxs0CzzMrWCpo9YwOOfVg/001.png)
viel Freude damit
lg Jens