Globale Datums-Aufbereitung

Hinweise, Tips und Tricks, FAQs - keine Anfragen!!
1 Beitrag • Seite 1 von 1
1 Beitrag Seite 1 von 1

Globale Datums-Aufbereitung

Beitrag von Tron (Top Expert / 1327 / 35 / 331 ) »
Insbesondere bei der Formularaufbereitung eines Datums fällt auf, dass die Darstellung von den Benutzereinstellungen abhängig ist. (das ist nicht wirklich schön)

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: Alles auswählen.

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

  PERFORM init_dateref.

* Checking the format given by user.
  CLEAR l_format.
  READ TABLE gt_dateformats INTO l_format WITH KEY val = format.


*  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).
          SELECT SINGLE * FROM t247 INTO w_t247
             WHERE spras = 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_date+l_ctr(1) = format+l_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.

*&---------------------------------------------------------------------*
*&      Form  init_dateref
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM init_dateref.

  CHECK gt_dateformats[] IS INITIAL.

  APPEND 'DD.MM.YY' TO gt_dateformats.
  APPEND 'MM.DD.YY' TO gt_dateformats.
  APPEND 'MM.YY.DD' TO gt_dateformats.
  APPEND 'YY.MM.DD' TO gt_dateformats.
  APPEND 'YY.DD.MM' TO gt_dateformats.
  APPEND 'DD.YY.MM' TO gt_dateformats.
  APPEND 'DD-MM-YY' TO gt_dateformats.
  APPEND 'MM-DD-YY' TO gt_dateformats.
  APPEND 'MM-YY-DD' TO gt_dateformats.
  APPEND 'YY-MM-DD' TO gt_dateformats.
  APPEND 'YY-DD-MM' TO gt_dateformats.
  APPEND 'DD-YY-MM' TO gt_dateformats.
  APPEND 'DD/MM/YY' TO gt_dateformats.
  APPEND 'MM/DD/YY' TO gt_dateformats.
  APPEND 'MM/YY/DD' TO gt_dateformats.
  APPEND 'YY/MM/DD' TO gt_dateformats.
  APPEND 'YY/DD/MM' TO gt_dateformats.
  APPEND 'DD/YY/MM' TO gt_dateformats.
  APPEND 'DDMMYY' TO gt_dateformats.
  APPEND 'MMDDYY' TO gt_dateformats.
  APPEND 'MMYYDD' TO gt_dateformats.
  APPEND 'YYMMDD' TO gt_dateformats.
  APPEND 'YYDDMM' TO gt_dateformats.
  APPEND 'DDYYMM' TO gt_dateformats.
  APPEND 'DD.MMM.YY' TO gt_dateformats.
  APPEND 'MMM.DD.YY' TO gt_dateformats.
  APPEND 'MMM.YY.DD' TO gt_dateformats.
  APPEND 'YY.MMM.DD' TO gt_dateformats.
  APPEND 'YY.DD.MMM' TO gt_dateformats.
  APPEND 'DD.YY.MMM' TO gt_dateformats.
  APPEND 'DD-MMM-YY' TO gt_dateformats.
  APPEND 'MMM-DD-YY' TO gt_dateformats.
  APPEND 'MMM-YY-DD' TO gt_dateformats.
  APPEND 'YY-MMM-DD' TO gt_dateformats.
  APPEND 'YY-DD-MMM' TO gt_dateformats.
  APPEND 'DD-YY-MMM' TO gt_dateformats.
  APPEND 'DD/MMM/YY' TO gt_dateformats.
  APPEND 'MMM/DD/YY' TO gt_dateformats.
  APPEND 'MMM/YY/DD' TO gt_dateformats.
  APPEND 'YY/MMM/DD' TO gt_dateformats.
  APPEND 'YY/DD/MMM' TO gt_dateformats.
  APPEND 'DD/YY/MMM' TO gt_dateformats.
  APPEND 'DDMMMYY' TO gt_dateformats.
  APPEND 'MMMDDYY' TO gt_dateformats.
  APPEND 'MMMYYDD' TO gt_dateformats.
  APPEND 'YYMMMDD' TO gt_dateformats.
  APPEND 'YYDDMMM' TO gt_dateformats.
  APPEND 'DDYYMMM' TO gt_dateformats.
  APPEND 'DD.MM.YYYY' TO gt_dateformats.
  APPEND 'MM.DD.YYYY' TO gt_dateformats.
  APPEND 'MM.YYYY.DD' TO gt_dateformats.
  APPEND 'YYYY.MM.DD' TO gt_dateformats.
  APPEND 'YYYY.DD.MM' TO gt_dateformats.
  APPEND 'DD.YYYY.MM' TO gt_dateformats.
  APPEND 'DD-MM-YYYY' TO gt_dateformats.
  APPEND 'MM-DD-YYYY' TO gt_dateformats.
  APPEND 'MM-YYYY-DD' TO gt_dateformats.
  APPEND 'YYYY-MM-DD' TO gt_dateformats.
  APPEND 'YYYY-DD-MM' TO gt_dateformats.
  APPEND 'DD-YYYY-MM' TO gt_dateformats.
  APPEND 'DD/MM/YYYY' TO gt_dateformats.
  APPEND 'MM/DD/YYYY' TO gt_dateformats.
  APPEND 'MM/YYYY/DD' TO gt_dateformats.
  APPEND 'YYYY/MM/DD' TO gt_dateformats.
  APPEND 'YYYY/DD/MM' TO gt_dateformats.
  APPEND 'DD/YYYY/MM' TO gt_dateformats.
  APPEND 'DDMMYYYY' TO gt_dateformats.
  APPEND 'MMDDYYYY' TO gt_dateformats.
  APPEND 'MMYYYYDD' TO gt_dateformats.
  APPEND 'YYYYMMDD' TO gt_dateformats.
  APPEND 'YYYYDDMM' TO gt_dateformats.
  APPEND 'DDYYYYMM' TO gt_dateformats.
  APPEND 'DD.MMM.YYYY' TO gt_dateformats.
  APPEND 'MMM.DD.YYYY' TO gt_dateformats.
  APPEND 'MMM.YYYY.DD' TO gt_dateformats.
  APPEND 'YYYY.MMM.DD' TO gt_dateformats.
  APPEND 'YYYY.DD.MMM' TO gt_dateformats.
  APPEND 'DD.YYYY.MMM' TO gt_dateformats.
  APPEND 'DD-MMM-YYYY' TO gt_dateformats.
  APPEND 'MMM-DD-YYYY' TO gt_dateformats.
  APPEND 'MMM-YYYY-DD' TO gt_dateformats.
  APPEND 'YYYY-MMM-DD' TO gt_dateformats.
  APPEND 'YYYY-DD-MMM' TO gt_dateformats.
  APPEND 'DD-YYYY-MMM' TO gt_dateformats.
  APPEND 'DD/MMM/YYYY' TO gt_dateformats.
  APPEND 'MMM/DD/YYYY' TO gt_dateformats.
  APPEND 'MMM/YYYY/DD' TO gt_dateformats.
  APPEND 'YYYY/MMM/DD' TO gt_dateformats.
  APPEND 'YYYY/DD/MMM' TO gt_dateformats.
  APPEND 'DD/YYYY/MMM' TO gt_dateformats.
  APPEND 'DDMMMYYYY' TO gt_dateformats.
  APPEND 'MMMDDYYYY' TO gt_dateformats.
  APPEND 'MMMYYYYDD' TO gt_dateformats.
  APPEND 'YYYYMMMDD' TO gt_dateformats.
  APPEND 'YYYYDDMMM' TO gt_dateformats.
  APPEND 'DDYYYYMMM' TO gt_dateformats.

ENDFORM.                    "init_dateref
&#91; = Eckige Klammer AUF [
&#93; = Eckige Klammer ZU ]
& = "kaufmännisches Und" &

Muß in den Top-Include

Code: Alles auswählen.

types: begin of t_dateformats,
       val type char15,
       end of t_dateformats.

DATA gt_dateformats TYPE STANDARD TABLE OF t_dateformats.
Ein kleines Testprogramm:

Code: Alles auswählen.

*&---------------------------------------------------------------------*
*& Report  YBC_TEST_DATECONVERT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YBC_TEST_DATECONVERT.

data f1 type char15 value 'DD-MMM-YY'.
data f2 type char15 value 'YY.MM.DD'.
data f3 type char15 value 'YY.DD.MM'.


data df type char15.

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.
Der Einsatz in Smartforms:
Der Aufruf als globale FORM-Routine
Bild

Ergebnis:
Bild

viel Freude damit
lg Jens
<:: XING-Gruppe Tricktresor::>
Die deutsche Rechtschreibung ist Freeware, du darfst sie kostenlos nutzen –
Aber sie ist nicht Open Source, d. h. du darfst sie nicht verändern oder in veränderter Form veröffentlichen.

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Seite 1 von 1

Vergleichbare Themen

1
Antw.
1733
Views
Datums-Periode abprüfen
von hazey » 26.04.2011 14:27 • Verfasst in ABAP® Core
6
Antw.
3691
Views
Datums Eingabe Query
von h1as » 23.07.2013 15:50 • Verfasst in ABAP® für Anfänger
4
Antw.
5706
Views
Sprachabhängige Datums- und Dezimaltrennzeichen
von Kerstin_4 » 13.08.2010 13:12 • Verfasst in ABAP® Core
2
Antw.
6474
Views
SapScript Aufbereitung
von jr-ewing » 26.10.2006 13:23 • Verfasst in ABAP® Core
8
Antw.
5026
Views
Aufbereitung EXCEL in SAP
von honeyjam » 08.09.2011 09:09 • Verfasst in ABAP® für Anfänger

Über diesen Beitrag

Tron

Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Aktuelle Forenbeiträge

Zwischensumme Adobe Forms
vor 2 Tagen von Lucyalison 1 / 64
Interne Tabelle
vor 5 Tagen von black_adept 2 / 133
MaLo-Checker in ABAP
vor einer Woche von A6272 6 / 254

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Aktuelle Forenbeiträge

Zwischensumme Adobe Forms
vor 2 Tagen von Lucyalison 1 / 64
Interne Tabelle
vor 5 Tagen von black_adept 2 / 133
MaLo-Checker in ABAP
vor einer Woche von A6272 6 / 254

Unbeantwortete Forenbeiträge

Zwischensumme Adobe Forms
vor 2 Tagen von Lucyalison 1 / 64
Group Items auf einer Filterbar
vor einer Woche von Bright4.5 1 / 107
tRFC Transaktionen SM58
vor 4 Wochen von A6272 1 / 140