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.
cancel
Showing results for 
Search instead for 
Did you mean: 

Report Z_check

former_member649905
Participant
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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( ).

4 REPLIES 4

Former Member
0 Kudos

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( ).

former_member194669
Active Contributor
0 Kudos

Increase the width of n_index to 2


n_index(2) TYPE n.

faisal_altaf2
Active Contributor
0 Kudos

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

former_member649905
Participant
0 Kudos

Thanks Guys, It works...I really appreciate your help.