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: 

manipulate internal table..

Former Member
0 Kudos

hi all..

I am having an internal table with 10 columns that is 10 fields. Now one of them is profit centre which is same for many records. Now i want to get all the records for individual profit centre. I know i can do it by using loop and the writing all records to a different internal table for each profit center. Can anyone else suggest me another method??

thanks in advance,

Reena

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

What do you want to do with these records? You just want to move them to another internal table, or you want to write them out? You can do a LOOP with a WHERE clause to just loop at the records with the certain profit center.

Loop at itab where profc = 'TEST'.

endloop.

Regards,

Rich Heilman

7 REPLIES 7

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

What do you want to do with these records? You just want to move them to another internal table, or you want to write them out? You can do a LOOP with a WHERE clause to just loop at the records with the certain profit center.

Loop at itab where profc = 'TEST'.

endloop.

Regards,

Rich Heilman

0 Kudos

i will elaborate my question. for example I have an internal table itab. Now 6 records of them have prctr = AA, 3 of them have prctr = BB and 1 of them have prctr = CC.

Now i want all of these records for a particular PRCTR in a different internal table.

i guess this will make things bit clear..

thanks for your support,

Reena

0 Kudos

Reena...

sort itab by prctr.

v_index = 0.

loop at prctr.

at new prctr.

  • get new itab1

v_index = v_index + 1.

endat.

if v_index = 1.

  • get values into itab1

elseif v_index = 2.

  • get values into itab2

elseif v_index = 3.

  • get values into itab3

endif.

at end of prctr.

if v_index = 1.

  • append itab1

elseif v_index = 2.

  • append itab2

elseif v_index = 3.

  • append itab3

endif.

endat.

endloop.

-Anu

0 Kudos

hello ,

try to use like this

Perform read_profit_center using prft_cntr.

Form read_profit_center using value(p_cntr).

read table itab with key pfr_cntr = p_cntr.

if sy-subrc eq 0.

Move the data here

delete itab index sy-tabix

*call the form again.

Perform read_profit_center using p_cntr.

Else.

continue.

Endform.

Hope this will help you.

Thanks,

Krishnakumar

Message was edited by:

Krishnakumar Ramadoss

0 Kudos

Hi,

Check this

loop at itab.

if itab-prctr eq 'AA'.

move the fields of itab to itab1.

elseif itab-prctr eq 'BB'.

move the fields of itab to itab2.

elseif itab-prctr eq 'CC'

move the fields of itab to itab3.

endloop.

Former Member
0 Kudos

you could:

sort my_table profit_center.

read table my_table with key

prt_cnt = "100013" "example

if sy-subrc eq 0.

collect my_table.

endif.

Warren

Former Member
0 Kudos

hi Reena ,

data : begin of itab occurs 0,
       PRCTR(18),
       val(6) ,
       end of itab .

DATA : JTAB LIKE ITAB OCCURS 0 WITH HEADER LINE.
 DATA: V_FLAG TYPE C.
       itab-PRCTR = 'AA'.
       ITAB-VAL   = '01'.
       APPEND ITAB.

       itab-prctr = 'AA'.
       ITAB-VAL   = '02'.
       APPEND ITAB.


       itab-PRCTR = 'AA'.
       ITAB-VAL   = '03'.
       APPEND ITAB.

       itab-prctr = 'AA'.
       ITAB-VAL   = '04'.
       APPEND ITAB.

       itab-PRCTR = 'AA'.
       ITAB-VAL   = '05'.
       APPEND ITAB.

       itab-prctr = 'AA'.
       ITAB-VAL   = '06'.
       APPEND ITAB.

       itab-PRCTR = 'BB'.
       ITAB-VAL   = '01'.
       APPEND ITAB.

       itab-prctr = 'BB'.
       ITAB-VAL   = '02'.
       APPEND ITAB.


       itab-PRCTR = 'BB'.
       ITAB-VAL   = '03'.
       APPEND ITAB.

       itab-PRCTR = 'CC'.
       ITAB-VAL   = '02'.
       APPEND ITAB.




      LOOP AT ITAB .

      AT NEW PRCTR.

      V_FLAG = 'X'.

      ENDAT.

      IF V_FLAG = 'X'.
      JTAB-PRCTR = ITAB-PRCTR.
      JTAB-VAL =   ITAB-VAL.
      APPEND JTAB.
      CLEAR  JTAB.
      ENDIF.

      AT END OF PRCTR.

       CLEAR V_FLAG.
       CLEAR JTAB.
       LOOP AT JTAB.
       WRITE:/ JTAB-PRCTR,JTAB-VAL.
       ENDLOOP.
       skip 2.

       WRITE:/ '--------------'.
       REFRESH JTAB.
      ENDAT.

     ENDLOOP.

Now in here as per ur requirement

i need to dynamically generate a internal table for the number of profit centers ..

but if i Populate the JTAB / Profit center

u can check the line '----


' being printed at the end of occurance of each profit center .

hope this helps ,

regards,

Vijay