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

Logic issue with Internal Table

Former Member
0 Likes
724

Hi All,

I have an internal table with following structure.

Name of Internal table: ITAB

Fields: userid login date number

Values: abc 01012008

abc 02012008

abc 02012008

abc 03012008

Now i should store the value for the field itab-number, based on the ita-logindate.

If the field logindate is having same date for 2 times (for the user 'abc'),

the field itab-number should have the value as '2' .

Basically i want to display a report to show how many times a user has logged into SAP system for a given date.......

How to incorporate this logic?

Regards

Pavan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
702

Hi,

Use the below logic.

data: begin of itab1 occurs 0,

uid like sy-uname,

date like sy-datum,

end of itab1.

data: begin of itab2 occurs 0,

uid like sy-uname,

date like sy-datum,

count type i,

end of itab2.

data v_count type i.

start-of-selection.

itab1-uid = 'abc'.

itab1-date = '20080101'.

append itab1.

itab1-uid = 'abc'.

itab1-date = '20080102'.

append itab1.

itab1-uid = 'abc'.

itab1-date = '20080102'.

append itab1.

itab1-uid = 'abc'.

itab1-date = '20080103'.

append itab1.

itab1-uid = 'abc'.

itab1-date = '20080104'.

append itab1.

sort itab1 by uid date.

loop at itab1.

v_count = v_count + 1.

at end of date.

itab2-uid = itab1-uid.

itab2-date = itab1-date.

itab2-count = v_count.

append itab2.

clear v_count.

endat.

endloop.

6 REPLIES 6
Read only

Sm1tje
Active Contributor
0 Likes
702

first sort the table on user id and date.

Next loop over internal table.

LOOP AT itab ASSIGNING <line>.

AT NEW date.

CLEAR: lv_number.

ENDAT.

<line>-number = lv_number + 1.

ENDLOOP.

Something like this???

Read only

Former Member
0 Likes
702

Hi,

sort itab and

delete adjacent duplicates..

prabhu.

Read only

Former Member
0 Likes
702

Hi pavan,

1. We have to use COLLECT for this.

2. Declare another itab, exactly similar to ITAB.

egs. STAB.

3.



Loop at ITAB.

STAB = ITAB.
Collect STAB.

Endloop.

regards,

amit m.

Read only

Former Member
0 Likes
702

hi,

try in this way,

first sort the internal table on user id and date.

loop at itab into wa.

l_tabix = sy-tabix.

number = number + 1.

wa-number = number.

modify itab from wa index l_tabix transporting number.

at end of date.

clear number.

endat.

endloop.

regards,

muralidhar.

Read only

Former Member
0 Likes
702

Hi,

Try the following

DATA : g_date TYPE sy-datum,

g_count(2) TYPE c,

g_id(10) TYPE c.

**After populating the internal table

g_count = 1.

CLEAR g_id.

LOOP AT itab.

IF itab-date EQ g_date AND g_id = itab-id.

g_count = g_count + 1.

ENDIF.

g_date = itab-date.

g_id = itab-id.

AT END OF date.

itab-number = g_count.

CLEAR g_id.

WRITE : / itab-id,itab-date,itab-number.

clear : g_id.

g_count = 1.

ENDAT.

ENDLOOP.

Regards,

Hema.

Read only

Former Member
0 Likes
703

Hi,

Use the below logic.

data: begin of itab1 occurs 0,

uid like sy-uname,

date like sy-datum,

end of itab1.

data: begin of itab2 occurs 0,

uid like sy-uname,

date like sy-datum,

count type i,

end of itab2.

data v_count type i.

start-of-selection.

itab1-uid = 'abc'.

itab1-date = '20080101'.

append itab1.

itab1-uid = 'abc'.

itab1-date = '20080102'.

append itab1.

itab1-uid = 'abc'.

itab1-date = '20080102'.

append itab1.

itab1-uid = 'abc'.

itab1-date = '20080103'.

append itab1.

itab1-uid = 'abc'.

itab1-date = '20080104'.

append itab1.

sort itab1 by uid date.

loop at itab1.

v_count = v_count + 1.

at end of date.

itab2-uid = itab1-uid.

itab2-date = itab1-date.

itab2-count = v_count.

append itab2.

clear v_count.

endat.

endloop.