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: 

logic required

Former Member
0 Kudos

Hi all,

I have an internal table with fields matnr and fevor and i have to check for no of records for every materal if the no of entries for each material more than 1 then i have to furthur coding based on fevor field.

And i want to know which system filed to use and which control break is better(at new or at end of) and some sample code is very helpful

regards

chandu.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Data count_mat type I.

Sort itab by matnr.

Loop at itab.

Count_mat = count_mat + 1.

At end of matnr.

Itab-count = count_mat.

Modify itab transporting count.

Clear count_mat.

Endloop.

Loop at itab where count > 1.

Do the coding for fevor.

endloop

11 REPLIES 11

Former Member
0 Kudos

Check this -

<b>data count type i.

data flg_further .

sort itab by matnr.

loop at itab.

count = count + 1 .

at end of matnr .

If count gt 1 .

flg_further = 'X'.

endif.

clear count.

endat.

if flg_further = 'X'.

< Your code here >.

clear flg_further .

endif.

endloop.</b>

Cheers.

Sanjay

Former Member
0 Kudos

Data count_mat type I.

Sort itab by matnr.

Loop at itab.

Count_mat = count_mat + 1.

At end of matnr.

Itab-count = count_mat.

Modify itab transporting count.

Clear count_mat.

Endloop.

Loop at itab where count > 1.

Do the coding for fevor.

endloop

0 Kudos

Hi,

As Usha suggested,you can go for that logic.

If you declare count field in your internal table with others fields,you can easily handle this situation.

types : begin of ty,

matnr type mara-matnr,

fevor...

...

count type i,

end of ty.

data : itab type standard table of ty,

wa type ty.

select required_fields from required_tables into corresponding fields of table itab where condition.

wa-count = 0.

loop at itab into wa.

wa-count = wa_count + 1.

at end of matnr.

*Here you need to modify for all the corresponding materials where condition is must.

<b>modify itab from wa transporting count where matnr = wa-matnr.</b>

wa-count = 0.

endat.

endloop.

loop at itab into wa where count > 1.

...logic needed for your program

endloop.

0 Kudos

Hi

And i have to check fevor also for every material.

ex:

My internal table contains:

matnr fevor

25 s07

25 empty

24 T04

24 s03

26 empty

27 s08

so my requirement is for every matnr check the no of records

if no of records is 1 then do nothing.(case 26 and 27)

if no of records is greater than 1(25 and 24) for that matnr i have to check fevor if it is empty (case 25) then delete that record otherwise do nothing (case 24)

I hope now it is clear.

Thanks and regards

Chandu

0 Kudos
Data: cnt type i.
cnt = 0.
Loop at itab.
cnt = cnt + 1.
At end of matnr.
if cnt > 1.
 CONTINUE.
else.
<b> IF itab-fevor[] IS INITIAL.
  DELETE itab.
  ENDIF.</b>
 clear cnt.
endif.

Hope this solves ur problem.

Kindly reward if u find helpful.

0 Kudos

Hi,

cnt = 0.

loop at itab into wa.

cnt = cnt + 1.

at end of matnr.

if cnt ge 1.

delete itab where matnr = wa-matnr and fervr is initial.

endif.

cnt = 0.

endat.

endloop.

0 Kudos
Data: cnt type i.
cnt = 0.
Loop at itab.
cnt = cnt + 1.
At end of matnr.
if cnt > 1.
 CONTINUE.
else.
 IF itab-fevor[] IS INITIAL.
  DELETE itab.
  ENDIF.
 clear cnt.
endif.

<b>
ENDAT.
ENDLOOP</b>

Forgot to add endloop in my code just try this out u can solve ur problem.

0 Kudos

Hi all

Thanks alot once again for your valuable help.

regards

chandu.

Former Member
0 Kudos

Hi,

The above postings however solves your problem.

however, i shall explain the case where you should use <b> AT NEW OR AT END OF</b>.

consider an internal table with 2 fields

A B

1 1 <-gets triggered

2 1

2 1 <-gets triggered

2 2 <-gets triggered

3 1 <-gets triggered

LOOP AT ITAB.

AT END OF B.

// TRIGGERS RECORD 1 1 , 2 1.....

ENDAT.

AT LAST.

// TRIGGERS ONLY AT THE LAST RECORD OF ITAB.

ENDAT.

ENDLOOP.

1)Table should be sorted before using control breaks.

2)WHere condition should not be specified in loop while using control breaks.

3)Control breaks considers all fields left to field mentioned in control break.

So, in this case,

AT end of B.

triggers 1 1 and then 2 1 and so on.

though there is no change in B in first 3 records, even then the records gets triggered as there is change in A.

Regards,

Sailaja.

Former Member
0 Kudos

Hi sanjay,

A small clarification from you.

As per your code, the variable flg_further will be set to X only for the last material in the group (Say if the material T5 exists 3 times..only the third occurance of T5 will be picked up and the code applies there alone...am I right)

Regards,

Usha

Former Member
0 Kudos

Hi,

sort itab by matnr.

loop at itab.

gv_tabix = sy-tabix.

count = count + 1.

if count > 1.

if itab-fevor is initial.

delete itab index gv_tabix.

endif.

endif.

at end of matnr.

clear count.

endat.

endloop.

Regards,

Sailaja.