A D V E R T I S E M E N T
|
S A P - R E S O U R C E S
Get Free SAP Resources:
Are you looking for:
- SAP Jobs
- Free SAP eBooks
- SAP Softwares
- SAP Tutorials
- ERP Implementation Examples
Search SAP Resources:
|
Macro to validate Date
PROGRAM ZDATE_VALIDATE .
* Validation of Date
DEFINE VAL_DATE.
CLEAR: %_DATE1,
%_DATE2.
%_DATE1(4) = &1. "Year
%_DATE1+4(2) = &2. "Month
%_DATE1+6(2) = &3. "Date
%_DATE2 = %_DATE1 - 1.
%_DATE2 = %_DATE2 + 1.
IF %_DATE1 <> %_DATE2.
SY-SUBRC = 1.
ELSE.
SY-SUBRC = 0.
ENDIF.
END-OF-DEFINITION.
DEFINE VALDATE.
***************************************************
* Passing Parameters: &1 - Date
* &2 - Date Format
*
* Date Format:
* DDMMYYYY MMDDYYYY YYYYMMDD YYYYDDMM
*
* SY-SUBRC Return Value:
* 1 invalid date
* 0 Valid Date
* 2 Invalid Format
***************************************************
DATA: %_DATE1 LIKE SY-DATUM ,
%_DATE2 LIKE SY-DATUM ,
%_DATE3(8).
case &2.
when 'DDMMYYYY'.
val_date &1+4(4) &1+2(2) &1+0(2).
when 'MMDDYYYY'.
val_date &1+4(4) &1+0(2) &1+2(2).
when 'YYYYMMDD'.
val_date &1+0(4) &1+4(2) &1+6(2).
when 'MMYYYYDD'.
val_date &1+2(4) &1+0(2) &1+6(2).
when others.
sy-subrc = 2.
endcase.
END-OF-DEFINITION.
***********************************************
* SAMPLE USE of above MACRO *
***********************************************
DATA: V_DATE(8).
V_DATE = '30022002'.
*=>
VALDATE V_DATE 'DDMMYYYY'.
*=>
IF SY-SUBRC = 0.
WRITE:/ 'Valid Date'.
ELSEIF SY-SUBRC = 1.
WRITE:/ 'Invalid Date'.
ELSEIF SY-SUBRC = 2.
WRITE:/ 'Invalid Format'.
ENDIF.
*********************************************************************
*-- End of Program
A D V E R T I S E M E N T
|
|
|