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: 

Numbering Logic

Former Member
0 Kudos

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

6 REPLIES 6

former_member386202
Active Contributor
0 Kudos

Hi,

Use AT new or on change of statement

Loop at itab.

on chage of field1.

give no 1 here.

endon.

endloop.

Regards,

Prashant

former_member624107
Contributor
0 Kudos

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.

Former Member
0 Kudos

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

former_member404244
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.

kesavadas_thekkillath
Active Contributor
0 Kudos

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 !!!!