Thursday, 23 October 2025

Code Syntax Try...Endtry

 Code :

Report Try.

Parameters NUMBER type I.

data RESULT type decimals 2.
data OREF type ref to CX_ROOT.
data TEXT type STRING.

start-of-selection.

write'Testing division and Sqare root with'NUMBER.

uline

try.

if ABSNUMBER 100.
  raise exception type CX_DEMO_ABS_TOO_LARGE.
endif.

try.
RESULT NUMBER.
write'Result of division:'RESULT.
RESULT SQRTNUMBER ).

write'Result of square root:'RESULT.

catch CX_SY_ZERODIVIDE into OREF.

TEXT OREF->GET_TEXT).
cleanup.

clear RESULT.
endtry.
catch CX_SY_ARITHMETIC_ERROR into OREF.

TEXT OREF->GET_TEXT).

catch CX_ROOT into OREF.

TEXT OREF->GET_TEXT).

endtry.

if not TEXT is initial.

write TEXT.

endif.

write'Final result:'RESULT.

**

Wednesday, 22 October 2025

Abap Code Fibonachi Number

 Code :

Report zfibo.

PARAMETERSp_from TYPE i,
             p_to   TYPE i.

 DATAv_from      TYPE i,
       v_to        TYPE i.

 DATATYPE i,
       b TYPE i,
       TYPE i,
      cnt type i.

 START-OF-SELECTION.

   v_from p_from.
   v_to   p_to.

   MOVE v_from TO b.

   cnt 0.
   DO  v_to times.


     IF v_to < cnt.
       EXIT.
     ENDIF.

     a + b.
     a b.
     b c.

     writec.

     cnt b + 1.
   enddo.

Result :














Tuesday, 21 October 2025

Abap Code Prime Number

Code : 

Report Prime_no.

 PARAMETERS: p_from TYPE i,

                             p_to   TYPE i.


DATA: v_from      TYPE i,

            v_to        TYPE i,

            v_remainder TYPE i,

           v_is_prime  TYPE c,

           v_divisor   TYPE i.


START-OF-SELECTION.

  v_from = p_from.

  v_to   = p_to.


  DO.

    IF v_from = v_to.

      EXIT.

    ENDIF.

    CLEAR v_is_prime.

    DO v_from TIMES.

      v_divisor = sy-index.

      v_remainder = v_from MOD v_divisor.

      IF v_divisor <> 1      AND

         v_divisor <> v_from AND

         v_remainder = 0.

*-- not a prime

        v_is_prime = 'N'.

        EXIT.

      ENDIF.

    ENDDO.

    IF v_is_prime IS INITIAL.

*-- the number is prime 

      WRITE:/ v_from.

    ENDIF.

    v_from = v_from + 1.

  ENDDO.


*****************************************************************

Result :





Visitor

Code Syntax Try...Endtry

  Code : Report Try. Parameters  NUMBER  type  I . data  RESULT  type  P  decimals  2 . data  OREF  type  ref  to  CX_ROOT . data  TEXT  typ...