Showing posts with label OFFESTS in ABAP. Show all posts
Showing posts with label OFFESTS in ABAP. Show all posts

Tuesday, 27 October 2015

Offset Concept in SAP ABAP

Most of the time in ABAP, we may have to read the part of data of a field (say X) and populate to other field (Say Y). In this case we have to use the offset concept to read the value.

Example:

SY-DATUM is the standard SAP field, which holds the current system date. The format of the date in SY-DATUM field will be YYYYMMDD.

Where,
  • YYYY => Year
  • MM => Month
  • DD => Day

In most of the cases we may have to read the value of month form the SY-SATUM and pass to some variable. Similarly we may have to read the value of year & day.


Below is a simple SAP ABAP program which gives clear picture on how to use offset concept.

======================

REPORT  ZVTEST_PGM_1.

DATAl_day(2)   TYPE c" Day
      l_month(2TYPE c" Month
      l_year(4)  TYPE c" Year

*--Print the value of Current System Date (YYYYMMDD)
WRITE:'Current System Date : ' sy-datum.

*--Use offset concept & populate the Year, Month & Day value to Local valriables

*--Year: Starting form Zeroth Position next 4 characters
l_year sy-datum+0(4).

*--Month: Starting form fourth Position next 2 characters
l_month sy-datum+4(2).

*--Day: Starting form sixth Position next 2 characters
l_day sy-datum+6(2).

*--Print value of Year, Month & date which is stored in local variables
WRITE:'Year  : 'l_year.
WRITE:'Month : 'l_month.
WRITE:'Day   : 'l_day.

======================

Hope post explained the OFFSET concept which we generally use in SAP ABAP.

Will share more useful articles soon.

Thanks & Regards,
Venugopal M N
SAP BI-ABAP Consultant