Hi Experts,
I am new to ABAP and I was trying to develop a program to read data from the file and identify whether it is prime or not.
The code is
REPORT zbtprime2.
TYPES:
BEGIN OF ty_zbtprime2,
f1num TYPE int1,
comments TYPE c LENGTH 500,
END OF ty_zbtprime2.
DATA:
lt_zbtprime2 TYPE STANDARD TABLE OF ty_zbtprime2, "INTERNAL TABLE
ls_zbtprime2 TYPE ty_zbtprime2. "WORK AREA
SELECT * INTO TABLE lt_zbtprime2 FROM zbtprime.
LOOP AT lt_zbtprime2 INTO ls_zbtprime2.
WRITE / ls_zbtprime2-f1num.
DATA t TYPE i VALUE '2'.
DATA f TYPE i VALUE '0'.
WHILE t LE ls_zbtprime2-f1num / 2.
IF ls_zbtprime2-f1num MOD 2 EQ 0.
f = 1.
ENDIF.
t = t + 1.
ENDWHILE.
IF f = 0.
WRITE 'It is prime number'.
ELSE.
WRITE 'It is not a prime number'.
ENDIF.
"ENDIF.
ENDLOOP.
1 Step: I have created internal table and work area
2 Step: Selecting data from the external table to the internal table
3 Step: Looping to write data from the internal to work area and I am checking for prime number in this step by having a while loop
4 Step: Write prime if it is a prime number or not prime if it is not (Expectation)
How ever i am getting the below result
I understand i am doing some mistake with the while loop and updating t he variable f, but having tough time in figuring out what the problem is.
Your help is much appreciated.
Thanks and Regards,
Sai