0% found this document useful (0 votes)
34 views

Logical Programs in Abap

The document contains 7 sections describing different mathematical operations and algorithms: 1. Interchanging the values of two variables A and B and reporting the new values. 2. Reversing a number by iterating through its digits. 3. Summing the digits of a number by iterating through each digit. 4. Generating the Fibonacci series by calculating each term as the sum of the previous two terms. 5. Calculating the Nth Fibonacci number directly. 6. Calculating the factorial of a number by multiplying from 1 to the given number. 7. Determining if a number is prime by checking if it is only divisible by 1 and itself.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Logical Programs in Abap

The document contains 7 sections describing different mathematical operations and algorithms: 1. Interchanging the values of two variables A and B and reporting the new values. 2. Reversing a number by iterating through its digits. 3. Summing the digits of a number by iterating through each digit. 4. Generating the Fibonacci series by calculating each term as the sum of the previous two terms. 5. Calculating the Nth Fibonacci number directly. 6. Calculating the factorial of a number by multiplying from 1 to the given number. 7. Determining if a number is prime by checking if it is only divisible by 1 and itself.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.INTERCHANGE THE VALUES B/W A AND B. REPORT ZINTERCHANGE. PARAMETERS : A TYPE I , B TYPE I. NEW-LINE. WRITE 'BEFORE CHANGE'.

WRITE : A , B. A = A + B . B = A - B. A = A - B. NEW-LINE. WRITE 'AFTER CHANGE'. WRITE : A , B.

2. REVERSE A NUMBERS REPORT ZNUM_REVERSE. PARAMETERS : N TYPE I . DATA : REM TYPE I , TOTAL TYPE I . WHILE N GT 0 . REM = N MOD 10 . TOTAL = TOTAL * 10 + REM . N = N / 10 . ENDWHILE. WRITE TOTAL. 3. SUM OF DIGHTS REPORT ZSUMOFDIGHTS. PARAMETERS : N TYPE I . DATA : REM TYPE I , TOTAL TYPE I VALUE 0 . WHILE N GT 0 . REM = N MOD 10 . TOTAL = TOTAL + REM . N = N / 10 . ENDWHILE. WRITE / TOTAL .

4. FIBONOCCI SERIES. REPORT ZFIBO. DATA : A TYPE I VALUE 0,B TYPE I VALUE 1,C TYPE I. PARAMETERS : N TYPE I. N = N - 2. WRITE : A , B. WHILE SY-INDEX LE N. C = A + B . WRITE : C. A = B. B = C. ENDWHILE.

5. Nth FIBONOCCI NUMBER. REPORT ZNTH_FIBO.

DATA : A TYPE I VALUE 0, B TYPE I VALUE 1, C TYPE I. PARAMETERS : N TYPE I. DATA : NTH TYPE I . NTH = N - 2. WHILE SY-INDEX LT N. C = A + B . A = B . B = C . IF SY-INDEX EQ NTH. WRITE : N NO-GAP , 'th FIBONOCCI NUM IS ' , C. ENDIF. ENDWHILE.

6. FACTORIAL REPORT ZFACTORIAL. PARAMETERS : N TYPE I. DATA : COUNT TYPE I VALUE 1, FACT TYPE I VALUE 1. WHILE COUNT LE N. FACT = FACT * COUNT. COUNT = COUNT + 1 . ENDWHILE. WRITE : 'THE FACTORIAL OF', N NO-GAP, 'IS', FACT.

7. PRIME NUMBER. REPORT ZPRIME.

PARAMETERS : N TYPE I. DATA : I TYPE I VALUE 1, COUNT TYPE I VALUE 0, TEMP TYPE I. WHILE I LE N . TEMP = N MOD I . IF TEMP EQ 0. COUNT = COUNT + 1. ENDIF. I = I + 1. ENDWHILE.

IF COUNT EQ 2. WRITE : / N , 'IS PRIME NUMBER'. ELSE. WRITE : / N , 'IS NOT PRIME NUMBER'. ENDIF.

You might also like