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: 

Rowcount based on the selection from the internal table

Former Member
0 Kudos
135

Hi Everyone,

I am able to display the data from the internal table for the values of fiscyear and compcode and at the same time I want to display the rowcount for each combination.

Say Fiscyear Compcode Rowcount

2000 1000 8000

2000 2000 200

etc

But so far successful only with fiscyear and compcode, how do i achieve this any help will be of great use to me.

All my data I am getting it in a internal table itab. From that only I am able to sort and display distinct vvalues.

Please advise,

Thanks,

Prashant.

8 REPLIES 8

former_member156446
Active Contributor
0 Kudos
105

Hi Pradanth

you can create another table of same type and use it as below:


data: lv_count type i.

itab_buff [ ] =  data_table[ ].

delete itab_buff where fiscear NE '2000'.
describe table itab_buff lines lv_count. 
"move this lv_count to the table you wanted...

0 Kudos
105

Hi Jay,

Thanks for the suggestion, but it did not work, here is the code below:

After getting the data into the internal table g_t_data, I have given it as suggested by you.

*************************

FORM print_result.

data: lv_count type i.

itab_temp[] = g_t_data[].

SORT itab_temp BY fiscyear comp_code.

delete adjacent duplicates from itab_temp comparing fiscyear comp_code.

g_t_data[] = itab_temp[].

itab_temp[] = g_t_data[].

delete itab_temp where fiscyear NE '2000'.

describe table itab_temp lines lv_count.

g_t_data[] = itab_temp[].

LOOP AT g_t_data INTO g_s_data.

WRITE: /(10) g_s_data-fiscyear,

(25) g_s_data-comp_code,

g_s_data-rowcount.

ENDLOOP.

ENDFORM.

******************************************************

I have print the result in the column rowcount as explained in the begginning.

For fiscyear 2000 and comp code 1000 the rowcount is 8000 records,

for fisyear 2000 and comp code 2000 the rwocount is 300 records.

Please advise,

thanks,

Prashant.

0 Kudos
105

Hi

Where are you writing the variable lv_count in ur code??

Write:/ 'No: of records equals: ' lv_count.

LOOP AT g_t_data INTO g_s_data.

WRITE: /(10) g_s_data-fiscyear,

(25) g_s_data-comp_code,

ENDLOOP

Cheers

~Arun

0 Kudos
105

Hi ,

I guess u did not understand what i am planning to get here, I want to get the rowcount of the combination of fiscyear and compcode and put it is one column which is rowcount. So how I query the data which is in internal table to get the rowcount for the required combination.

Read table also did not work.

Regards,

Prashant.

0 Kudos
105

Hi

here p_FY and p_CC are user input parameters

LOOP AT g_t_data in g_s_data.

IF g_s_data-FY = p_FY and g_s_CC = p_CC.

count = count + 1.

flag = 1.

ENDIF.

ENDLOOP.

IF flag = 1

Append g_s_data to itab_temp.

ENDIF.

Now in count u wll get the number of records and itab_temp will have the required data

Cheers

~Arun

0 Kudos
105

Hi Arun,

It did not work, here is the code which u suggested.

FORM print_result.

data: count type i.

itab_temp[] = g_t_data[].

SORT itab_temp BY fiscyear comp_code.

delete adjacent duplicates from itab_temp comparing fiscyear comp_code.

g_t_data[] = itab_temp[].

LOOP AT g_t_data INTO g_s_data.

IF g_s_data-fiscyear = '2000' and g_s_data-comp_code = '2000'.

count = count + 1.

Append g_s_data to itab_temp.

clear g_s_data.

ENDIF.

WRITE: /(10) g_s_data-fiscyear,

(25) g_s_data-comp_code,

g_s_data-rowcount.

  • g_s_data-0CACQ_VL_YR,

  • g_s_data-0COR_DEP_YR,

  • g_s_data-0CRES_TR_YR.

ENDLOOP.

For this combination fiscyear = 2000 and compcode = 2000 I must get 8000 records. But not getting it. What could be the problem.

0 Kudos
105

Hello

U r clearing the g_s_data...then how will you get it???

LOOP AT g_t_data INTO g_s_data.

IF g_s_data-fiscyear = '2000' and g_s_data-comp_code = '2000'.

count = count + 1.

Append g_s_data to itab_temp.

clear g_s_data. <<<<<<<<<<<<<<<<< u r clearing it.

write like this

LOOP AT g_t_data in g_s_data.

IF g_s_data-FY = '2000' and g_s_CC = '2000'.

count = count + 1.

flag = 1.

ENDIF.

ENDLOOP.

IF flag = 1

Append g_s_data to itab_temp.

ENDIF.

Loop at itab_temp.

WRITE: /(10) itab_temp-fiscyear,

(25) itab_tempcomp_code,

(30) lv_count.

endloop.

0 Kudos
105
FORM print_result.

data: count type i.

itab_temp] = g_t_data[.

SORT itab_temp BY fiscyear comp_code.

delete adjacent duplicates from itab_temp comparing fiscyear comp_code.

itab_temp_1[ ] = itab_temp [ ].

delete itab_temp_1 where fiscear NE '2000'. " create another temp table

describe table  itab_temp_1 lines lv_count.

g_t_data[ ] = itab_temp[ ].

LOOP AT g_t_data INTO g_s_data where fiscyear = '2000' and comp_code = '2000' .

g_s_data-rowcount = lv_count. " <<<< move the total to str.
Append g_s_data to itab_temp.
clear g_s_data.

WRITE: /(10) g_s_data-fiscyear,
(25) g_s_data-comp_code,
g_s_data-rowcount.

    * g_s_data-0CACQ_VL_YR,
    * g_s_data-0COR_DEP_YR,
    * g_s_data-0CRES_TR_YR.

ENDLOOP.