- SAP Community
- Groups
- Interest Groups
- Application Development
- Discussions
- Finding Prime Numbers from 1 to 100

Application Development Discussions

Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Finding Prime Numbers from 1 to 100

Former Member

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

09-13-2005 4:25 PM

Hi Friends

I want to get prime numbers from 1 to 100, please help me, how to develop logic.

Regards

Praveen

- SAP Managed Tags:
- ABAP Development

1 ACCEPTED SOLUTION

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

09-13-2005 4:51 PM

Praveen, look at the following report

**&----**

*& Report ZTEST_PNUM *

*& *

**&----**

*& *

*& *

**&----**

REPORT ZTEST_PNUM .

PARAMETERS : start(16) TYPE p DECIMALS 0 DEFAULT 1,

endnum(16) TYPE p DECIMALS 0 OBLIGATORY DEFAULT 100.

TYPES ans(16) TYPE p DECIMALS 0.

DATA ans(16) TYPE p DECIMALS 0.

DATA itab TYPE TABLE OF ans.

DATA wa TYPE ans.

DATA wa_1(16) TYPE p DECIMALS 0.

DATA wa_2 TYPE ans.

DATA wa_3(16) TYPE p DECIMALS 0.

DATA wa_4(16) TYPE p DECIMALS 0.

START-OF-SELECTION.

DO .

CLEAR wa_4.

wa_3 = 1.

wa_1 = sqrt( wa_2 ).

WHILE wa_3 <> 0.

ADD 1 TO wa_4.

IF wa_4 > wa_1 AND wa_2 <> 4.

EXIT.

ENDIF.

IF wa_4 > 1.

wa_3 = wa_2 MOD wa_4.

ENDIF.

ENDWHILE.

IF wa_3 <> 0 and wa_2 > 0.

APPEND wa_2 TO itab.

ENDIF.

ADD 1 TO wa_2.

IF wa_2 = endnum.

EXIT.

ENDIF.

ENDDO.

LOOP AT itab INTO wa.

WRITE: / sy-tabix, wa.

ENDLOOP.

Hope it will give you the solution.

Don't forget to reward points if this code solves your issue.

Regards.

Naveen

- SAP Managed Tags:
- ABAP Development

3 REPLIES 3

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

09-13-2005 4:32 PM

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

09-13-2005 4:51 PM

Praveen, look at the following report

**&----**

*& Report ZTEST_PNUM *

*& *

**&----**

*& *

*& *

**&----**

REPORT ZTEST_PNUM .

PARAMETERS : start(16) TYPE p DECIMALS 0 DEFAULT 1,

endnum(16) TYPE p DECIMALS 0 OBLIGATORY DEFAULT 100.

TYPES ans(16) TYPE p DECIMALS 0.

DATA ans(16) TYPE p DECIMALS 0.

DATA itab TYPE TABLE OF ans.

DATA wa TYPE ans.

DATA wa_1(16) TYPE p DECIMALS 0.

DATA wa_2 TYPE ans.

DATA wa_3(16) TYPE p DECIMALS 0.

DATA wa_4(16) TYPE p DECIMALS 0.

START-OF-SELECTION.

DO .

CLEAR wa_4.

wa_3 = 1.

wa_1 = sqrt( wa_2 ).

WHILE wa_3 <> 0.

ADD 1 TO wa_4.

IF wa_4 > wa_1 AND wa_2 <> 4.

EXIT.

ENDIF.

IF wa_4 > 1.

wa_3 = wa_2 MOD wa_4.

ENDIF.

ENDWHILE.

IF wa_3 <> 0 and wa_2 > 0.

APPEND wa_2 TO itab.

ENDIF.

ADD 1 TO wa_2.

IF wa_2 = endnum.

EXIT.

ENDIF.

ENDDO.

LOOP AT itab INTO wa.

WRITE: / sy-tabix, wa.

ENDLOOP.

Hope it will give you the solution.

Don't forget to reward points if this code solves your issue.

Regards.

Naveen

- SAP Managed Tags:
- ABAP Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

07-06-2015 7:38 AM