04-02-2009 7:31 PM
Hi Experts,
I am learning Abap objets, could someone help me in understanding the output of the below program... I was expecting to have 1,3,5,7,9,11,13 as answers but I got 1,3,5,7,9,1,3. I don't understand why I have 1 and 3 at the end instead of 11 and 13.
REPORT z_check.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: is_zero TYPE i,
n_index TYPE n.
DO 13 TIMES.
is_zero = sy-index MOD 2.
CHECK is_zero = 1.
n_index = sy-index.
MESSAGE n_index TYPE 'I'.
ENDDO.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
Thanks
04-02-2009 7:36 PM
Hi,
REPORT z_check.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: is_zero TYPE i,
n_index(2)TYPE n. --> Increase the length of the field to 2 then you can see 11,13 else the value is getting truncated.
DO 13 TIMES.
is_zero = sy-index MOD 2.
CHECK is_zero = 1.
n_index = sy-index.
MESSAGE n_index TYPE 'I'.
ENDDO.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
04-02-2009 7:36 PM
Hi,
REPORT z_check.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: is_zero TYPE i,
n_index(2)TYPE n. --> Increase the length of the field to 2 then you can see 11,13 else the value is getting truncated.
DO 13 TIMES.
is_zero = sy-index MOD 2.
CHECK is_zero = 1.
n_index = sy-index.
MESSAGE n_index TYPE 'I'.
ENDDO.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
04-02-2009 7:39 PM
04-02-2009 7:44 PM
Hi,
Change the Declaration of n_index to the following way, i have tested after change and it is working fine now
DATA: n_index TYPE n LENGTH 2.
Hope will solve out your problem,.
Best Regards,
Faisal
04-02-2009 8:38 PM