Archive for March, 2013

ABAP – List of Events

Below is the list of events in ABAP:   Initialization : triggered when the report is loaded in memory. At selection-screen output : triggered when the selection screen is loaded in memory before being displayed. At selection-screen / <field> : before leaving the selection screen. start-of-selection : the first event for displaying the report. end-of-selection : ...

. Read More →

ABAP – Validation On Selection Screen Fields

Many time we need to some validation on fields in selection screen. In that case we can use the event      AT SELECTION-SCREEN ON. Syntax: AT SELECTION-SCREEN ON <fieldname>. IF NOT <fieldname> IS INITIAL MESSAGE "Cannot Empty'  TYPE 'E'. ENDIF.

. Read More →

ABAP – Declaring Constants

In ABAP constants can be declared as follows: CONSTANTS:  c_x(1)     TYPE    c    VALUE  'X',                            c_dot(1)   TYPE   i    VALUE  '134'.

. Read More →

ABAP – Termination date or Leave date of an employee

For getting the the termination date or leaving  date of an employee we can use the following Function Module  HR_LEAVING_DATE   CALL FUNCTION 'HR_LEAVING_DATE' EXPORTING persnr      = p_pernr begda       = '19980101' endda       = '99991231' IMPORTING leavingdate = l_date exceptions leaving_date_not_found       = 1 pernr_not_assigned           = 2 others                       = 3.   Pass the pernr for which you want the leaving date in to the variable p_pernr ...

. Read More →

ABAP – Adding one day to date

For getting next day of the date we can use the following code: SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-001. SELECTION-SCREEN SKIP 1. PARAMETERS p_date TYPE  sy-datum. SELECTION-SCREEN END OF BLOCK B1. WRITE:'Before', p_date. p_date = p_date + 1. WRITE:/ 'After', p_date. Input: 30.04.2013 Output: Before 30.04.2013 After 01.05.2013

. Read More →

ABAP – Getting difference between the dates in days, weeks, years

To get the difference between two dates we can use the FM  HR_CALC_YEAR_MONTH_DAY.   DATA: l_years_out(2) type n, l_months_out(2) type n, l_days_out(2) type n. CALL FUNCTION 'HR_CALC_YEAR_MONTH_DAY' EXPORTING BEGDA            = '20130631' ENDDA            = '20180705' IMPORTING YEARS_OUT        = l_years_out MONTHS_OUT       = l_months_out DAYS_OUT         = l_days_out . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. write: l_years_out, l_months_out, l_days_out.   Output: 05 01 00 Means the difference between two dates is 5 years 0 months 4 days

. Read More →

ABAP – To get the day of the date

To get the day like Sunday, Monday etc of a particular date we can use the following function.   DATA: V_DATE(10) type c. CALL FUNCTION 'DATE_TO_DAY' EXPORTING DATE          =  sy-datum IMPORTING WEEKDAY       = v_date . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. write: 'Today is', V_DATE.   This will displays today's day

. Read More →

ABAP – Getting last day of a month

To get the last day of a month we can use the functional module RP_LAST_DAY_OF_MONTHS. DATA: V_DATE LIKE SY-DATUM. CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS' EXPORTING DAY_IN                  = sy-datum IMPORTING LAST_DAY_OF_MONTH       = V_DATE EXCEPTIONS DAY_IN_NO_DATE          = 1 OTHERS                  = 2 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. write: 'Last day is', V_DATE+6(2).   Output will display the last day of the month. If sy-datum is: 07- march -2013 then Output  is as follows: Last day is 31

. Read More →

ABAP Modul Pool programming – Making a field read only

To make a field read only either we can make it as output field only. or we can write the following code LOOP AT SCREEN. IF screen-group1 EQ 'group name' screen-input = 0. MODIFY SCREEN.     ENDIF. ENDLOOP.   Like that we can make one field as input by setting screen-input = 1.

. Read More →

ABAP – Counting number of records in an Internal Table

We can count the number of records in an internal table using the built in function LINES(). i,e  l_count = lines (it_tab) . This will displays the total number of records in the internal table it_tab.

. Read More →