12-13-2007 10:24 AM
Experts Im having a problem on how to formulate my logic.
Please pardon if I cant explain it well and let me show you an example of my problem.
Example I have 5 number:
shine
mary
mary
arenas
gilbert
john
john
the above names are my data then I want to give numberings of each data and it would look like this.
shine - 1
mary - 1
mary - 2
arenas-1
gilbert-1
john - 1
john - 2.
did you notice the pattern of my numbering?if the data changed i would number it as 1 if in the next loop it didnt change I would number it 2 and so fort.
Could you help me on my logic...those data are stored in one field inside in internal table then I put it in a loop.
Help me please on constructing my logic...
2
1
2
12-13-2007 10:29 AM
Hi,
Use AT new or on change of statement
Loop at itab.
on chage of field1.
give no 1 here.
endon.
endloop.
Regards,
Prashant
12-13-2007 10:35 AM
sort itab by name.
loop at itab.
at new name.
v_count = 0.
endat.
v_count = v_count + 1.
itab-number = v_count.
modify itab transporting number.
endloop.
12-13-2007 10:35 AM
Hi
Try ..
data: l_v_current type char10,
l_v_prev type char10.
Loop at <your int table> into <your wa>.
l_v_current = <your wa>-field. " so l_v_current = mary as per ur example
if l_v_current = l_v_prev. " first l_v_prev is initial hence value will be 1
set value as 2
else.
*set value as 1.
endif.
l_v_prev = l_v_current. " so that in the next iteration we have the previous value
endloop.
Regards
Arun
12-13-2007 10:47 AM
Hi ,
try like this
v_index1 = 1.
v_index = 2.
loop at itab into wa1.
read table itab into wa2 index v_index.
if wa2-name = wa1-name.
wa1-count = v_index1.
modify itab from wa1 transporting count.
v_index1 = v_index1 + 1.
else.
v_index1 = 1.
wa1-count = v_index1.
modify itab from wa1 transporting count.
endif.
v_index = v_index + 1.
endloop.
Regards,
Nagaraj
12-13-2007 10:48 AM
Hi salma,
I wrote small program ..try this..
REPORT test.
DATA : BEGIN OF itab OCCURS 0,
name TYPE char20,
num TYPE i,
END OF itab.
DATA number TYPE i.
itab-name = 'shine'.
APPEND itab.
itab-name = 'mary'.
APPEND itab.
itab-name = 'mary'.
APPEND itab.
itab-name = 'arenas'.
APPEND itab.
itab-name = 'gilbert'.
APPEND itab.
itab-name = 'john'.
APPEND itab.
itab-name = 'john'.
APPEND itab.
itab-name = 'john'.
APPEND itab.
SORT itab.
LOOP AT itab.
ADD 1 TO number.
itab-num = number.
MODIFY itab INDEX sy-tabix.
AT END OF name.
CLEAR number.
ENDAT.
ENDLOOP.
LOOP AT itab.
WRITE 😕 itab-name, itab-num.
ENDLOOP.
12-13-2007 10:57 AM
data:begin of itab occurs 100,
idx type p no decimals,
names(50) type c.
end of itab.
data:wk_names(50) type c
loop at itab.
if sy-tabix = 1.
wk_names = itab-names.
itab-idx = 1.
else.
if wk_names = itab-names.
itab-idx = 2.
else.
wk_names = itab-names.
itab-idx = 1.
endif.
endif.
modify itab transporting idx.
endloop.
just try this.........if any problem revert !!!!