What’s there in the Date?

What’s there in the Date? 1) At any point pondered, why SAP saves date in YYYYMMDD design?

 

First why not DDMMYYYY or MMDDYYYY?

Lets expect SAP saved date as DDMMYYYY.
first Jan 2000 is saved as 01012000
first Dec 2000 is saved as 01122000
Yet, look how first Dec 1999 seems to be: 01121999.

The issue lies with here.. Presently first Jan 2000 become under first Dec 1999.
Mathematically, 01012000 < 1121999. In any case, 1 Jan 2000 ought to be more prominent than first Dec 1999.
In this way, DDMMYYY is definitely not an effective method for saving date.

Presently, lets expect SAP saved date as MMDDYYYY.

1st Jan 2000 is saved as 01012000
1st Dec 2000 is saved as 12012000
But look how 1st Dec 1999 looks like: 12011999.

Here is the issue once more. first Jan 2000 become under first Dec 1999.

Mathematically, 01012000 < 12011999. In any case, 1 Jan 2000 ought to be more noteworthy than first Dec 1999.
In this way, MMDDYYY is likewise not an effective method for saving date.

Our understanding: Why YYYYMMDD is the method for saving?

1st Jan 2000 is saved as 20000101
31st Dec 2000 is saved as 20001201
1st Dec 1999 is saved as 19991201

Mathematically 19991201 < 20000101. And furthermore hypothetically, first Dec 1999 is under first Jan 2000.

Appears, SAP is playing with numbers. Future dates are dependably more prominent than present dates and past dates. Also, this can be accomplished provided that you save date as YYYYMMDD. Isn’t it smart thinking by the system.. 

2) Our young ABAPers often get confused, how to use a date and time together in WHERE clause during SELECTs.

Say the prerequisite is to bring all Business Request information from VBAK which were make after 7 AM on first Jan 2014 till 11 AM on ninth July 2014.

The primary instinct of the designer is to compose:

SELECT VBELN
FROM VBAK
INTO TABLE I_VBAK
WHERE ERDAT GE '20140101' AND ERZET GT '070000'
AND ERDAT LE '20140709' AND ERZET LT '110000'.

On the off chance that the designers doesn’t do the unit test appropriately, then (s)he wouldn’t understand the information misfortune. The above inquiry is intelligently wrong.

What is the issue?
It would bring just those deals request which were made between 7 AM to 11 AM consistently from first Jan to ninth Jan. Any deals request made after 11 AM till 7 AM wouldn’t be chosen. For second Jan ahead, 24 hours information ought to be chosen i.e anything before 7 AM and furthermore after 11 AM.

What might the right Choose get?
Just for first Jan, information before 7 AM ought not be chosen.
Just for ninth July, information after 11 AM ought not be chosen. For rest the entire in the middle between, every one of the 24 hours information ought to be chosen.

So the right methodology would be:

SELECT VBELN
FROM VBAK
INTO TABLE i_vbak
WHERE ERDAT GE '20140101'
AND   ERDAT LE '20140709'.
IF i_vbak[] IS NOT INITIAL.
* For the first date, remove before start time data
DELETE i_vbak[] where ERDAT EQ '20140101' AND ERZET LT '070000'.
* For the last date, remove after end time data
DELETE i_vbak[] where ERDAT EQ '20140709' AND ERZET GT '110000'.
ENDIF.

PS: You can forestall the Erase proclamations by utilizing the ERZET appropriately in the WHERE provision of the SELECT. Be that as it may, but you outline your WHERE condition, it ought to do exactly the same thing as finished by Erase articulations above.

3) Confusion while using Validity Period?

Say your necessity is to get information from a table (A017) in the legitimacy scope of first Jan 2014 till 31st Dec 2014.

Does this mean, you really want to approach your question WHERE proviso as:

SELECT * FROM A017 " * is only for demo. not a good practice :)
WHERE DATAB GE '20140101' " Validity From
AND DATBI LE '20141231'.  " Validity To

Simple answer is .. a big NO.

Say, a section is there in A017 which has legitimate from date as first Jan 2000 and substantial to date as 30th June 2014. This passage is legitimate in the reach first Jan 2014 to 31st Dec 2014. Yet, the above SELECT wouldn’t bring this and there would be information misfortune.

Right way is: Befuddle of Legitimacy From and To in the WHERE statement.

SELECT * FROM A017        " * is only for demo. not a good practice :)
WHERE DATAB LE '20141231' " Validity From
AND DATBI GE '20140101'.  " Validity To

This WHERE statement would pick the column mentioed above in A017. Substantial from first Jan 2000 is LE ‘20141231’ and the Legitimate To 30th Jun 2014 is GE ‘20140101’.

Does it appear to be legit? Recall the Bungle rationale..

4) Change date to internal and external format.

This is an extremely normal prerequisite and engineers will more often than not split/link the date values and attempt to transform it to wanted inside/outside design.
Say date is 01/09/2014.. Engineers attempt to part at ‘/’ and design it to 20140109 to get the inward organization.

Now and again, engineer will generally hard code ‘/’ or ‘.’ to get the outer configuration of the date. They don’t understand that, the end clients or business clients might not have the
same date design as the engineer’s. In those situations, hard coding would prompt issue.

What’s there in the Date? 1) At any point pondered, why SAP saves date in YYYYMMDD design? To forestall it, we ought to utilize SAP gave capability modules viz. CONVERT_DATE_TO_EXTERNAL and CONVERT_DATE_TO_INTERNAL.

 

YOU MAY BE INTERESTED IN

Mastering the Basics of SAP ABAP: A Comprehensive Guide

ABAP Objects Tips

SAP ABAP Tips

 

 

X
WhatsApp WhatsApp us