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 do I avoid Do loop.

Former Member
0 Likes
949

Hello Experts,

I have a requirement to find unused trading partner numbers . Trading partner is 6 digit numeric value stored in table T880. I have to find all the numbers from 10000 to 99999 which are not there in rcomp field of T880. I am this logic.

select rcomp from t880 into corresponding fields of table lt_t880.

CLEAR LV_COUNT.

lv_count = 9999.

do 90000 times.

lv_count = lv_count + 1.

read table lt_t880 into wa_t880 with key rcomp = lv_count.

if sy-subrc ne 0.

wa_range-rcomp = lv_count.

append wa_range to lt_range.

endif.

enddo.

I am trying to avoid Do loop. Please suggest.

7 REPLIES 7
Read only

former_member186055
Active Participant
0 Likes
898

Hi Vishal,

You can try LOOP ENDLOOP.

LOOP AT IT_T800 INTO WA_T800.

  • your logic...

WA_RANGE-RCOMP = WA_T800-RCOMP.

APPEND WA_RANGE TO IT_RANGE.

ENDLOOP.

Regards,

Surya

Read only

0 Likes
898

Hi Surya,

LOOP ENDLOOP at internal table will not help.

internal table will have som random values from 1 to 99999 lets say 7000 values I want all other values except from those 7000 random values

Read only

0 Likes
898

Vishal,

As per my knowledge please check...

First fill all the values in IT_RANGE internal table. Then in between loop and endloop delete those records which are there in IT_T800.

DELETE TABLE...

Regards,

Surya

Read only

prince_isaac
Active Participant
0 Likes
898

Hi Vishal

I hope i understood your requirement, maybe you could try it like this


TYPES: BEGIN OF ltyp_t880,
        rcomp TYPE rcomp,
       END OF ltyp_t880.

DATA: lt_t880  TYPE TABLE OF ltyp_t880,
      lw_t880  TYPE ltyp_t880,
      lr_t880  TYPE RANGE OF ltyp_t880,
      lwr_t880 LIKE LINE OF lr_t880,
      lw_count TYPE rcomp.

SELECT rcomp FROM t880 INTO TABLE lt_t880 WHERE rcomp BETWEEN 10000 AND 99999.

* build range of rcomp values
lw_count = 10000.
WHILE lw_count <= 99999.
  lwr_t880-option = 'EQ'.
  lwr_t880-sign   = 'I'.
  lwr_t880-low    = lw_count.
  APPEND lwr_t880 TO lr_t880.
  lw_count = lw_count + 1.
ENDWHILE.

LOOP AT lr_t880 INTO lwr_t880.
  READ TABLE lt_t880 WITH KEY rcomp = lwr_t880-low.
  IF sy-subrc = 0.
    DELETE lr_t880 FROM lwr_t880.
  ENDIF.
ENDLOOP.

regards

Prince Isaac

Read only

0 Likes
898

and even possibly like this also:


* build range of rcomp values
lw_count = 10000.
WHILE lw_count <= 99999.
  lwr_t880-option = 'EQ'.
  lwr_t880-sign   = 'I'.
  lwr_t880-low    = lw_count.
  READ TABLE lt_t880 WITH KEY rcomp = lwr_t880-low.
  IF sy-subrc = 0.
    CONTINUE.
  ELSE.
    APPEND lwr_t880 TO lr_t880.
  ENDIF.
  lw_count = lw_count + 1.
ENDWHILE.

Read only

Former Member
0 Likes
898

Hi,

You could give this a try.

TYPES: BEGIN OF ty_missing,
        rcomp TYPE rcomp_d,
       END OF ty_missing.

DATA: i_partners TYPE STANDARD TABLE OF t880,
           i_missing TYPE STANDARD TABLE OF ty_missing,
           wa_missing TYPE ty_missing,
           wa_t880 TYPE t880.

DATA: r_comp TYPE RANGE OF rcomp_d,
           wa_comp LIKE LINE OF r_comp,
           lv_comp TYPE rcomp_d.


wa_comp-sign = 'I'.
wa_comp-option = 'BT'.
wa_comp-low = '100000'.
wa_comp-high = '999999'.
APPEND wa_comp TO r_comp.

SELECT * FROM t880 INTO TABLE i_partners
  WHERE rcomp IN r_comp.

lv_comp = wa_comp-low.

LOOP AT i_partners INTO wa_t880.
  WHILE lv_comp NE wa_t880-rcomp.
    MOVE lv_comp TO wa_missing-rcomp.
    APPEND wa_missing TO i_missing. "+Missing trading partners+    
 lv_comp = lv_comp + 1.
  ENDWHILE.
  lv_comp = lv_comp + 1.
ENDLOOP.

Read only

0 Likes
898

Thanks Aneel and Prince , I have got the solution of the problem using ranges concept.