You are currently viewing System Fields, Date Conversion and Meaning of SY-SUBRC

System Fields, Date Conversion and Meaning of SY-SUBRC

In my previous articles we learn about classical reports, alv grid reports. In this article we will learn about some keywords, some conversions which we are used in SAP in daily life.

System Fields for Date and Time

System fieldContent
sy-datloDate in the current user’s time zone.
sy-datumLocal date of the ABAP system.
sy-daystIndicator for summer time. During summer time, “X”, otherwise ” “.
sy-fdaywFactory calendar weekday. “1” for Monday, …, “5” for Friday.
sy-timloTime in the current user’s time zone.
sy-tzoneTime difference from the UTC reference time in seconds, ignoring summer time.
sy-uzeitLocal time of the ABAP system.
sy-zonloUser’s time zone.

 

SY-DATUM————-defines SYSTEM DATE

SY-UNAME————-defines CURRENT USER

SY-UZEIT—————defines CURRENT TIME

The above three system fields are commonly used in SAP ABAP Programming when you create any record or during insertion of a record in database table.

Date Conversion in SAP ABAP
In SAP ABAP programming system can’t understand the normal date format which we generally use in our daily life. If we enter date 02-October-2016 or 02/10/2016. It will understand the format of YYYYMMDD for example 20161002. To see this when you write your code in your system then debug at execution time and you can see the format of date.

Some functions which are used for date conversion in SAP ABAP are:-

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'  "CHENAGE THE FORMAT OF DATE FROM YYYYMMDD TO DD.MM.YYYY

EXPORTING

DATE_INTERNAL = SY-DATUM

IMPORTING

DATE_EXTERNAL = DATUM.


call function 'CONVERT_DATE_TO_EXTERNAL'

exporting

date_internal = sy-datum

importing

date_external = datum.

 

What is SY-SUBRC ?
When you debug the code, Some time there are errors occurring during execution in your code like when SQL Query doesn’t give desired result on passing condition in where clause. Now the key point is how do you come to know about error, don’t worry about it. When you debug the code then on top in the middle there is a field of sy-subrc showing on the screen which acts as a flag. If it is 0 then code execute properly means no error and if it is non-zero it means there is a error in that code. Following are meanings of sy-subrc values:-

SY-SUBRC = 0:- means source code table is not empty, contains no errors and is broken down into tokens.

SY-SUBRC = 1:- means source code table is not empty and is broken down into tokens, but at least one include program does not exist (can occur only in connection with the addition WITH INCLUDES ).

SY-SUBRC = 2:- means source code table itab1 is empty or a blank line range was selected (applies to the additions FROM and TO ).

SY_SUBRC = 4:- means scanner detects error in source code.

SY-SUBRC = 8:- Other error or RABAX in scanner.

Mostly system shows two values either 0 or 4 and others in rare cases.

 

Dinesh Kumar Bansal

Dinesh Kumar Bansal is an Indian Software Developer, who is working on ASP.Net, MS-SQL, SAP-ABAP technologies from last one year. His Basic Principle of developing software is, “You have to clear about, what do you want to do, how can it be done”. He always says that development can be done with a cool & fresh mind.

Leave a Reply