Open In App

Prime numbers from 1 to n in SAP ABAP

Last Updated : 15 Dec, 2023
Like Article

SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP (Systems, Applications, and Products in Data Processing). It was developed in the 1980s for building business applications in the SAP environment.

SAP ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which includes enterprise resource planning (ERP) systems and other business software solutions. C++ is used to implement the ABAP kernel. A procedural and object-oriented programming model are both supported by the hybrid programming language ABAP.


Prime numbers in SAP ABAP

Program to print prime numbers from 1 to N in SAP ABAP:

Below is the Program to Print Prime numbers from 1 to N in SAP ABAP:

REPORT zprime_numbers.
PARAMETERS: p_number TYPE i.
DATA: lv_flag TYPE abap_bool,
lv_counter TYPE i.
IF p_number <= 1.
WRITE: 'Please enter a number greater than 1.'.
WRITE: 'Prime numbers from 1 to', p_number, ':'.
DO lv_counter = 2 TO p_number.
lv_flag = abap_true.
DO lv_counter = 2 TO lv_counter / 2.
IF lv_counter MOD lv_counter = 0.
lv_flag = abap_false.
IF lv_flag = abap_true.
WRITE lv_counter.

This code includes a report named zprime_numbers. It prompts the user to enter a number p_number. Then, it iterates from 2 up to the entered number, checking for prime numbers and displaying them.

suppose if N = 20

Output 1:

Prime numbers from 1 to 20:
2 3 5 7 11 13 17 19

suppose N=-1

Output 2:

Please enter a number greater than 1.

This message indicates that the input is invalid for finding prime numbers because the program is designed to work with numbers greater than 1. Therefore, it prompts the user to enter a number greater than 1 to proceed with finding prime numbers.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads