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