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

internal tables.

Former Member
0 Likes
650

hi I am having couple of issues i need to solve if you can help.

one is in my report there is a select option for profit centre. I want to write code that once user presses execute, my select-option is validated and all entries from a table CSKS which have profit centre falling in my select-option range are populated in my itab1.

2. I am having an internal table itab2. i want to get all the entries from itab2 that have matching profit centres in itab1. I want to avoid double loop; if i can.

so its like if my itab1 has 30 different profit centres then i want all the entries from itab2 where profit centre is equal to either of the entries in itab1.

thanks and regards,

Reena..

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
624

Hi Reena,

try to make it faster:


select-options:
  s_prctr for CSKS-prctr.
data:
  lt_prctr type hashed table of prctr with unique key table_line.

select distinct prctr from csks into table lt_prctr from csks where prctr in s_prctr.

loop at itab2.
  read table lt_prctr transporting no fields with table key table_line = itab2-prctr.
  check sy-subrc = 0.
* process record for selected profit centers
*...
endloop.

Expained: internal table lt_prctr can only store different profit centers; HASHED table guarantees fastest access if more than ca. 30 records; below it does not matter.

select distinct will only get each profit center once - precondition for storing in HASHED table .

In the loop at itab2 we only have to check if the profit center has been selected. lt_prctr has no structure, so ABAP pseudo-component table_line is used.

Regards,

Clemens

P.S.: Impress colleagues with simplicity and speed! - use field-symbols for loop at itab2 to make it even faster.

5 REPLIES 5
Read only

Former Member
0 Likes
624

Do you want to validate against CSKS (Cost Centers) or CEPC (Profit Center)?

Rob

Read only

0 Likes
624

my primary intent is to get all the concerned fields from table CSKS. so main motive is create an internal table for entries containing profit centre and cost centre before anything is processed.

Read only

Former Member
0 Likes
624

sort itab1 by <profitcenter>.

sort itab2 by <profitcenter>.

loop at itab1.

read table itab2 withe key <profitcenter> = itab1-<profitcenter>.

write ur further logic...................

endloop.

Read only

Clemenss
Active Contributor
0 Likes
625

Hi Reena,

try to make it faster:


select-options:
  s_prctr for CSKS-prctr.
data:
  lt_prctr type hashed table of prctr with unique key table_line.

select distinct prctr from csks into table lt_prctr from csks where prctr in s_prctr.

loop at itab2.
  read table lt_prctr transporting no fields with table key table_line = itab2-prctr.
  check sy-subrc = 0.
* process record for selected profit centers
*...
endloop.

Expained: internal table lt_prctr can only store different profit centers; HASHED table guarantees fastest access if more than ca. 30 records; below it does not matter.

select distinct will only get each profit center once - precondition for storing in HASHED table .

In the loop at itab2 we only have to check if the profit center has been selected. lt_prctr has no structure, so ABAP pseudo-component table_line is used.

Regards,

Clemens

P.S.: Impress colleagues with simplicity and speed! - use field-symbols for loop at itab2 to make it even faster.

Read only

Former Member
0 Likes
624

select prctr into table itab1 from csks where prctr in so_prctr.

loop at itab2.

read table itab1 with key prctr = itab2-prctr.

if sy-subrc = 0.

  • records in itab2 with entry of profit centre in itab1.

endif.

endloop.