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

loop-problem

Former Member
0 Likes
847

hi,

i have to check my itab if there are 20 or more blnr for one vtref.

at the checking i have to use the first 12 positions of the blnr.

i tried it with this loop but it doesn't work.

hope u can help me.

LOOP AT itab.

AT NEW vtref.

lf_merkblnr = itab-blnr.

CLEAR counter.

REFRESH wa_itab.

ENDAT.

IF itab-blnr(12) EQ lf_merkblnr(12).

+counter = counter + 1.+

APPEND itab TO wa_itab.

ENDIF.

AT LAST." vtref.

IF counter LE 20.

DELETE itab WHERE vtref = wa_itab-vtref.

ENDIF.

ENDAT.

ENDLOOP.

regards,

tobias

6 REPLIES 6
Read only

former_member194669
Active Contributor
0 Likes
783

clear : counter.
LOOP AT itab where blnr eq lf_merkblnr.

IF itab-blnr(12) EQ lf_merkblnr(12).
counter = counter + 1.
APPEND itab TO wa_itab.
ENDIF.

AT end of vtref.
 IF counter LE 20.
  DELETE itab WHERE vtref = wa_itab-vtref.
 ENDIF.
ENDAT.

ENDLOOP.

keep it mind that the first field in itab will be vtref and also sorted with vtref.

a®s

Edited by: a®s on Jan 10, 2008 11:25 AM

Read only

0 Likes
783

Hi aRs,


clear : counter.
LOOP AT itab where blnr eq lf_merkblnr. "all rows will not be looped, where is lf_merkblnr being set???
 
IF itab-blnr(12) EQ lf_merkblnr(12).
counter = counter + 1.
APPEND itab TO wa_itab.
ENDIF.
 
AT end of vtref.
 IF counter LE 20.
  DELETE itab WHERE vtref = wa_itab-vtref.
 ENDIF.
ENDAT.
 
ENDLOOP.

I think the correct one will be:



LOOP AT itab.
 AT NEW vtref.
  lf_merkblnr = itab-blnr.
  CLEAR counter.
  REFRESH wa_itab.
 ENDAT.

 IF itab-blnr(12) EQ lf_merkblnr(12).
 counter = counter + 1.
 APPEND itab TO wa_itab.
 ENDIF.
 
 AT end of vtref.
  IF counter LT 20. "LT and not LE for 20 or more
   DELETE itab WHERE vtref = itab-vtref. "and not wa_itab
  ENDIF.
 ENDAT.
 
ENDLOOP.

Hope this helps.

Thanks

Sanjeev

Read only

0 Likes
783

there's still a failure in the code

when i debugg the program my lf_merkblnr stays empty but i dont know why.

hope someone has n idea why.

regards,

tobias

Read only

0 Likes
783

Hi Tobias,

the field sequence in the record of itab must be VTREF BLNR ....

And it must be sorted.

Regards,

Clemens

Read only

0 Likes
783

Hi Clemens,

i know and done this already.

DATA: BEGIN OF itab OCCURS 1000,

vtref TYPE dfkkop-vtref,

blnr TYPE dfkkop-xblnr,

bukrs TYPE dfkkop-bukrs,

gpart TYPE dfkkop-gpart,

n1 TYPE adrc-name1,

n2 TYPE adrc-name2,

n3 TYPE adrc-name3,

augst TYPE dfkkop-augst,

END OF itab.

SORT itab BY vtref blnr.

LOOP AT itab.

AT NEW vtref.

lf_merkblnr = itab-blnr.

CLEAR counter.

REFRESH wa_itab.

ENDAT.

IF itab-blnr(12) EQ lf_merkblnr(12).

counter = counter + 1.

APPEND itab TO wa_itab.

ENDIF.

AT END OF vtref.

IF counter LT 20.

DELETE itab WHERE vtref = itab-vtref.

ENDIF.

ENDAT.

ENDLOOP.

that's the reason why i don't unterstand it, that lf_merkblnr is empty.

the values of itab-blnr are changing in the loop but lf_merkblnr stays empty.

regards,

tobias

Read only

Former Member
0 Likes
783

CHECK this code.

but actually i did not understand ur req.ment. if it has count le 20. then deleting the entries from itab. if it had more than 20 entries for the same vtref, wht will be the process.

TYPES: BEGIN OF ty_itab,

vtref(10) TYPE c,

belnr(20) TYPE c,

END OF ty_itab.

DATA: itab TYPE ty_itab OCCURS 0 WITH HEADER LINE,

wa_itab TYPE ty_itab OCCURS 0 WITH HEADER LINE,

temp_itab TYPE ty_itab OCCURS 0 WITH HEADER LINE.

DATA: temp(12) TYPE c.

DATA: counter(02) TYPE c,

flag TYPE c,

set TYPE c.

itab-vtref = '0000000001'.

itab-belnr = '000000000010001'.

APPEND itab.

itab-vtref = '0000000001'.

itab-belnr = '000000000010002'.

APPEND itab.

itab-vtref = '0000000004'.

itab-belnr = '000000000010003'.

APPEND itab.

itab-vtref = '0000000005'.

itab-belnr = '000000000010004'.

APPEND itab.

itab-vtref = '0000000001'.

itab-belnr = '000000000010005'.

APPEND itab.

itab-vtref = '0000000002'.

itab-belnr = '000000000010001'.

APPEND itab.

itab-vtref = '0000000002'.

itab-belnr = '000000000010002'.

APPEND itab.

itab-vtref = '0000000007'.

itab-belnr = '000000000010003'.

APPEND itab.

itab-vtref = '0000000008'.

itab-belnr = '000000000010004'.

APPEND itab.

itab-vtref = '0000000002'.

itab-belnr = '000000000010005'.

APPEND itab.

SORT itab BY vtref belnr.

LOOP AT itab.

AT NEW vtref.

CLEAR counter.

REFRESH wa_itab.

flag = 'X'.

ENDAT.

IF flag = 'X'.

temp = itab-belnr+0(12).

CLEAR: flag.

ENDIF.

IF itab-belnr(12) EQ temp.

counter = counter + 1.

APPEND itab TO wa_itab.

ENDIF.

AT END OF vtref.

IF counter LE 2.

set = 'X'.

ENDIF.

ENDAT.

IF set = 'X'.

APPEND LINES OF wa_itab TO temp_itab.

CLEAR: set.

ENDIF.

ENDLOOP.

LOOP AT temp_itab.

DELETE TABLE itab FROM temp_itab.

ENDLOOP.