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

exit loop if condition is true

Former Member
0 Likes
1,093

Hi,

I have selected a couple of personnal numbers (key) and i loop them into wa_pernr_select which is used in an functional module (HR_READ_INFOTYPE) to get information for this personal number.

What i want to do is to exclude the record if a certain condition is true (bukrs ne bukrs).

I don't want to exit the whole loop just exclude a specific record. I have tried with continue and exit but i doesn't seem to work. Any suggestions?

 LOOP AT it_pernr INTO wa_pernr_sel.

        CALL FUNCTION 'HR_READ_INFOTYPE'
              EXPORTING
                tclas                 = 'A'
                pernr                 = wa_pernr_sel
                infty                 = '0001'
                .........
              TABLES
                infty_tab             = p0001_endda
                 ......
                

        CALL FUNCTION 'HR_READ_INFOTYPE'
              EXPORTING
                tclas                 = 'A'
                pernr                 = wa_pernr_sel
                infty                 = '0001'
                .........
              TABLES
                infty_tab             = p0001_begda
                 ......

      IF p0001_begda-bukrs NE p0001_endda-bukrs.
              EXIT.
      ELSE.
              MOVE p0001_endda-bukrs TO wa_out_data_wage-bukrs.
      ENDIF.



 ENDLOOP.

Best Regards

Claes

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,057

I wonder why CONTINUE will not work in the place of EXIT in your current code.

You can also use


      CHECK p0001_begda-bukrs EQ p0001_endda-bukrs.
      MOVE p0001_endda-bukrs TO wa_out_data_wage-bukrs.

I also see that p0001_begda and p0001_endda are internal tables and will NOT make sense to compare like p0001_begda-bukrs EQ p0001_endda-bukrs, as here you are only comparing the headers which MAY or MAY NOT contain data which makes sense to compare. What if both the tables have multiple rows of data, how will you compare BUKRS fields from multiple rows then?

Hi,

I have selected a couple of personnal numbers (key) and i loop them into wa_pernr_select which is used in an functional module (HR_READ_INFOTYPE) to get information for this personal number.

What i want to do is to exclude the record if a certain condition is true (bukrs ne bukrs).

I don't want to exit the whole loop just exclude a specific record. I have tried with continue and exit but i doesn't seem to work. Any suggestions?

 LOOP AT it_pernr INTO wa_pernr_sel.

        CALL FUNCTION 'HR_READ_INFOTYPE'
              EXPORTING
                tclas                 = 'A'
                pernr                 = wa_pernr_sel
                infty                 = '0001'
                .........
              TABLES
                infty_tab             = p0001_endda
                 ......
                

        CALL FUNCTION 'HR_READ_INFOTYPE'
              EXPORTING
                tclas                 = 'A'
                pernr                 = wa_pernr_sel
                infty                 = '0001'
                .........
              TABLES
                infty_tab             = p0001_begda
                 ......

      IF p0001_begda-bukrs NE p0001_endda-bukrs.
              EXIT.
      ELSE.
              MOVE p0001_endda-bukrs TO wa_out_data_wage-bukrs.
      ENDIF.



 ENDLOOP.

Best Regards

Claes

7 REPLIES 7
Read only

Former Member
0 Likes
1,057

Hi,

Please try this if continue or exit doesn't work.


LOOP AT it_pernr INTO wa_pernr_sel.
 
  CALL FUNCTION 'HR_READ_INFOTYPE'
    EXPORTING
      tclas                 = 'A'
      pernr                 = wa_pernr_sel
      infty                 = '0001'
      .........
    TABLES
      infty_tab             = p0001_endda
      ......
        
 
  CALL FUNCTION 'HR_READ_INFOTYPE'
    EXPORTING
      tclas                 = 'A'
      pernr                 = wa_pernr_sel
      infty                 = '0001'
      .........
    TABLES
      infty_tab             = p0001_begda
      ......
 
  IF p0001_begda-bukrs EQ p0001_endda-bukrs.
    MOVE p0001_endda-bukrs TO wa_out_data_wage-bukrs.
  ENDIF.
  
ENDLOOP.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
1,057

Replace this....


      IF p0001_begda-bukrs NE p0001_endda-bukrs.
              EXIT.
      ELSE.
              MOVE p0001_endda-bukrs TO wa_out_data_wage-bukrs.
      ENDIF.

With this -;)


      IF p0001_begda-bukrs NE p0001_endda-bukrs.
              CONTINUE.
      ELSE.
              MOVE p0001_endda-bukrs TO wa_out_data_wage-bukrs.
      ENDIF.

Greetings,

Blag.

Read only

Former Member
0 Likes
1,057

How did you define your internal tables p0001_endda and p0001_begda? Do they have header lines?

If not, your IF does not make sense (and even if they do it is not clean the way you do it since the FM might have processed the table and therefor set your header line randomly).

Did you set a break point and check before the IF?

Read only

Former Member
0 Likes
1,058

I wonder why CONTINUE will not work in the place of EXIT in your current code.

You can also use


      CHECK p0001_begda-bukrs EQ p0001_endda-bukrs.
      MOVE p0001_endda-bukrs TO wa_out_data_wage-bukrs.

I also see that p0001_begda and p0001_endda are internal tables and will NOT make sense to compare like p0001_begda-bukrs EQ p0001_endda-bukrs, as here you are only comparing the headers which MAY or MAY NOT contain data which makes sense to compare. What if both the tables have multiple rows of data, how will you compare BUKRS fields from multiple rows then?

Read only

0 Likes
1,057

Hi,

I thought that this should work since it is only possible for a person to have one (1) bukrs at a specific time. But obviously it doesn't....

Have you any suggestions of how i can do instead?

Regards

Claes

Read only

0 Likes
1,057

Well, if you known (and validated) that 1 employee can only have 1 comp code and that all the records in the table have the same BUKRS, you can read the 1st record of each table in a work area and compare those.

Guenther

Read only

Former Member
0 Likes
1,057

Hey,

Are you using the p0001_endda and p0001_begda for importing data or exporting.

If you are using this for importing then your logic doesn't work coz data in both the tables is same. Same parameters yield same output.

If you have the table as export parameters then try debugging and getting the scenario with different data.

This requirement of yours is a logical error. Check the logic or send complete details for help.

Let me know if you have any more questions.

Regards

Rakeesh