Application Development and Automation 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: 
Read only

how to do loop just one time

Former Member
0 Likes
2,220

hi

i wont to do this loop just one time in program what is the best way to do that?

Regards

LOOP AT target_hours_exp ASSIGNING <target_hours_exp>.

IF <target_hours_exp>-stdaz = '0.5' .

ADD 1 TO cnt_days.

ENDIF.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,721

Hi

LOOP AT target_hours_exp ASSIGNING <target_hours_exp> where stdaz = '0.5' .
  ADD 1 TO cnt_days.
ENDLOOP.

Max

hi

i wont to do this loop just one time in program what is the best way to do that?

Regards

LOOP AT target_hours_exp ASSIGNING <target_hours_exp>.

IF <target_hours_exp>-stdaz = '0.5' .

ADD 1 TO cnt_days.

ENDIF.

ENDLOOP.

10 REPLIES 10
Read only

Former Member
0 Likes
1,722

Hi

LOOP AT target_hours_exp ASSIGNING <target_hours_exp> where stdaz = '0.5' .
  ADD 1 TO cnt_days.
ENDLOOP.

Max

Read only

0 Likes
1,721

hi max

i sorry i dont explain my self well i have loop for tmp_emp_day and i wont to do the loop target_hours_exp just one time in all the big loop (tmp_emp_day)

LOOP AT tmp_emp_day ASSIGNING <fs_emp>.

CALL FUNCTION 'Z_EMP_CAP'

EXPORTING

pernr = <fs_emp>-pernr

begda = fir_day

endda = last_day

IMPORTING

target_hrs = target_hrs

TABLES

target_hours_exp = target_hours_exp

work_hours = work_hours.

DO 1 TIMES.

LOOP AT target_hours_exp ASSIGNING <target_hours_exp> WHERE stdaz = '0.5' .

ADD 1 TO cnt_days.

ENDLOOP.

ENDDO.

<fs_emp>-miss_days = <fs_emp>-miss_days - cnt_days.

APPEND <fs_emp> TO emp_miss_days.

ENDLOOP.

Regards

Read only

0 Likes
1,721

Hi

Ok, so u need to do a READ TABLE statament or insert EXIT statament into the loop (it's the same):

LOOP AT tmp_emp_day ASSIGNING <fs_emp>.

CALL FUNCTION 'Z_EMP_CAP'
  EXPORTING
       pernr = <fs_emp>-pernr
       begda = fir_day
       endda = last_day
  IMPORTING
       target_hrs = target_hrs
  TABLES
      target_hours_exp = target_hours_exp
      work_hours = work_hours.

* Or you use the READ TABLE statament.....:

  READ TABLE target_hours_exp ASSIGNING <target_hours_exp>
                                                        WITH KEY stdaz = '0.5' .
  IF SY-SUBRC = 0.
     ADD 1 TO cnt_days.
  ENDIF.

*...or EXIT into the LOOP:

  LOOP AT target_hours_exp ASSIGNING <target_hours_exp> WHERE stdaz = '0.5' .
    ADD 1 TO cnt_days.
    EXIT.
  ENDLOOP.

  <fs_emp>-miss_days = <fs_emp>-miss_days - cnt_days.

  APPEND <fs_emp> TO emp_miss_days.

ENDLOOP.

Max

Read only

Former Member
0 Likes
1,721

Hi

LOOP AT target_hours_exp ASSIGNING <target_hours_exp>.

IF <target_hours_exp>-stdaz = '0.5' .

ADD 1 TO cnt_days.

<b>if sy-INDEX = 1.

exit.

endif.</b>

ENDIF.

ENDLOOP.

reward if useful

Read only

Former Member
0 Likes
1,721

Hi,

LOOP AT target_hours_exp ASSIGNING <target_hours_exp>.

IF <target_hours_exp>-stdaz = '0.5' .

ADD 1 TO cnt_days.

<b>exit.</b>

ENDIF.

ENDLOOP.

thanks & regards,

Venkatesh

Read only

former_member188827
Active Contributor
0 Likes
1,721

use:

LOOP AT target_hours_exp ASSIGNING <target_hours_exp>.

if sy-tabix = 1.

IF <target_hours_exp>-stdaz = '0.5' .

ADD 1 TO cnt_days.

ENDIF.

endif.

ENDLOOP.

plz reward points if it helps

Read only

Former Member
0 Likes
1,721

Hi Tal,

well, you may insert an EXIT statement inside your loop:


LOOP AT target_hours_exp ASSIGNING <target_hours_exp>.
  IF <target_hours_exp>-stdaz = '0.5' .
    ADD 1 TO cnt_days.
  ENDIF.
  EXIT.                "<-- insert
ENDLOOP. 

(depending on your needs, you may change the EXIT statement into the IF..ENDIF)

I hope it helps. Best regards,

Alvaro

Read only

Former Member
0 Likes
1,721

Hi,

LOOP AT target_hours_exp ASSIGNING <target_hours_exp>.

IF <target_hours_exp>-stdaz = '0.5' .

ADD 1 TO cnt_days.

ENDIF.

EXIT.

ENDLOOP.

Thanks and Best Regards,

Vikas Bittera.

Read only

Former Member
0 Likes
1,721

Hi,

LOOP AT target_hours_exp ASSIGNING <target_hours_exp> where <target_hours_exp>-stdaz = '0.5' .

ADD 1 TO cnt_days.

EXIT.

ENDLOOP.

Instead of looping you can use READ statement

READ TABLE target_hours_exp ASSIGNING <target_hours_exp> with key <target_hours_exp>-stdaz = '0.5' .

If sy-subrc = 0.

ADD 1 TO cnt_days.

endif.

rewards if useful,

regards,

nazeer

Read only

Former Member
0 Likes
1,721

LOOP AT target_hours_exp ASSIGNING <target_hours_exp>.

IF <target_hours_exp>-stdaz = '0.5' .

ADD 1 TO cnt_days.

ENDIF.

exit.

ENDLOOP.