SAP R/3

How to Find First Date and End Date of Period in ABAP/4

If you know year, month and fiscal year variant and you want to know the first date and end date of that period, you can apply function module "PERIOD_DAY_DETERMINE" in ABAP/4 to get them.

Example


CALL FUNCTION ’PERIOD_DAY_DETERMINE’
EXPORTING
I_GJAHR = ’2006’ "Year
I_MONAT = ’01’ "Month
I_PERIV = ’F2’ "Fiscal Year Variant

IMPORTING
E_FDAY = FIRST_DATE
E_LDAY = END_DATE
EXCEPTIONS

Example to apply DO statement in ABAP/4

You will apply this statement when you want to loop data with non-condition loops.

Example 1: Simple Loop

DO.
WRITE:/ sy-index.
IF sy-index = 4.
    EXIT.
ENDIF.
ENDDO.

The output is


1
2
3
4

Example 2: Loops with n times

DO 4 TIMES.
WRITE:/ sy-index.
ENDDO.

The output is same as example 1.

Example 3: Nested Loops

Difference between CONTINUE, CHECK and EXIT statement in ABAP/4

  • CONTINUE
    When you apply this statement, system will pass a current loop. System  ignores any statements after CONTINUE statement and start to the next loop.

Example

DO 4 TIMES.
WRITE:/ sy-index.
IF sy-index <= 2.
CONTINUE.

ENDIF.
WRITE: ’After’.
ENDDO.

The output is

1  
2
3  After
4  After
  • CHECK
    This statement will apply if you want to check condition before go to next statement. If the result of checking is ’TRUE’, system will go to next step as normally. If the result of checking is ’FALSE’, system will operate look like CONTINUE statement.

Example

Example to apply WHILE statement in ABAP/4

You will apply this statement when you want to loop data with condition loops.

Example 1: Simple Loop

DATA: lv_int TYPE I VALUE 1.
WHILE lv_int <= 4.
WRITE:/ lv_int.
lv_int = lv_int + 1.




ENDWHILE.

The output is 

1
2
3
4

Example 3: Nested Loops

DATA: lv_int TYPE I VALUE 1,
lv_int2 TYPE I.

WHILE lv_int <= 4.
WRITE:/ lv_int.
lv_int2 = 1.
WHILE lv_int2 <= 2.
WRITE: lv_int2.
lv_int2 = lv_int2 + 1.
ENDWHILE.
lv_int = lv_int + 1.




ENDWHILE.

The output is 

Select...Where & Select...Check in ABAP/4

Select...Where


SELECT * FORM SPFLI
WHERE CARRID = ’LH’.
...
...
...
ENDSELECT.

Select...Check

SELECT * FORM SPFLI.
CHECK SPFLI-CARRID = ’LH’.
...
...
...
ENDSELECT.
In above logic, Select...Where is better than Select...Check because the database can then user an index and system resource load is considerably less.

SELECT...INTO TABLE & SELECT...APPEND in ABAP/4

Select...Into Table


DATA: itab LIKE SPFLI OCCURS 0 WITH HEADER LINE.
SELECT * FORM SPFLI INTO TABLE itab.

Select...Append

DATA: itab LIKE SPFLI OCCURS 0 WITH HEADER LINE.
SELECT * FORM SPFLI INTO itab.
APPEND itab.
ENDSELECT.
In above logic, Select...Into Table is faster than Select...Append.