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 table operations....

naimkhans_babi
Active Participant
0 Likes
617

Dear friends

I need you help in internal table operations... actually i am copying the data from one internal table to another based on a condintion.... let me give you the scenario.... please help me in this regards...

itab1

partner int

00001 1

00002 1

00003 1

00004 2

00005 2

itab2

partner

here i am supposed to move partner from itab 1 to itab 2 when int is 1... to process only those partner who has int 1 i am supposed to developed this way...

flags = 1.

loop at itab1 into wa_itab1 where int = flags

append wa_itab1 to itab2

partner = itab2-partner

call subroutine using partner(table type)

refresh itab2.

flags flags + 1.

endloop.

so above is the ruff idea what i am supposed to do... i need to pass all the 3 partner in to the table for subroutine...

then 1 has completed flags is increamented and has value of 2 so now i am picking all the partner which has value 2 and passing them to table of partner to subroutin.

any code, suggesion will be great help of mine...

please help me...

regards

naim

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
516

You need to have the table in the order of INT and PARTNER.

Then you SORT the table

SORT ITAB1 BY INT.

LOOP AT ITAB1 WHERE INT = FLAGS.

ITAB2-PARTNER = ITAB1-PARTNER.

APPEND ITAB2.

AT END OF INT.

call subroutine using partner(table type)

REFRESH ITAB2.

FLAGS = FLAGS + 1.

ENDAT.

ENDLOOP.

Regards,

Ravi

Note : Please mark all the helpful answers

5 REPLIES 5
Read only

Former Member
0 Likes
516

Hello

Do like this.

data count type i value 1.

Loop at itab1 where int eq count.

itab2-partner eq itab1-partner.

append itab2.

at last.

perform routine tables itab2.

refresh itab2.

clear itab2.

add 1 to count.

endat.

endloop.

Hope this code works for ur case.

If useful reward .

Vasanth

Read only

Former Member
0 Likes
516

Hi Naim,

You can do this way. Use <b>ON CHANGE OF</b>. No need of incrementing flag or any variable.



<b>SORT itab1 BY int.</b>

LOOP AT itab1 INTO wa_itab1.

  <b>ON CHANGE OF itab1-int.</b>

    IF sy-tabix EQ 1.
      wa_itab2-partner = wa_itab1-partner.
      APPEND wa_itab2 TO itab2.
<b>      CLEAR wa_itab2.
      CONTINUE.</b>
    ENDIF.


<b>    PERFORM your_routine .</b>

<b>    REFRESH itab2.</b>
<b>  ENDON.</b>

  wa_itab2-partner = wa_itab1-partner.
  APPEND wa_itab2 TO itab2.

  <b>CLEAR wa_itab2.</b>

ENDLOOP.


*&--------------------------------------------------------------------*
*&      Form  your_routine
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM your_routine.
"Your Processing

ENDFORM.                    "your_routine

Regards,

Arun S.

Message was edited by: Arun Sambargi

Read only

Former Member
0 Likes
517

You need to have the table in the order of INT and PARTNER.

Then you SORT the table

SORT ITAB1 BY INT.

LOOP AT ITAB1 WHERE INT = FLAGS.

ITAB2-PARTNER = ITAB1-PARTNER.

APPEND ITAB2.

AT END OF INT.

call subroutine using partner(table type)

REFRESH ITAB2.

FLAGS = FLAGS + 1.

ENDAT.

ENDLOOP.

Regards,

Ravi

Note : Please mark all the helpful answers

Read only

Former Member
0 Likes
516

Hi,

Do this .


flag = 0.


do 7 times.

refresh itab2.
flags = flags + 1.


  loop at itab1 into wa_itab1 where int = flags
      partner = itab2-partner
      append wa_itab1 to itab2
  endloop.

  call subroutine using partner(table type)

enddo.

Read only

Former Member
0 Likes
516

Hi Naim,

Consider the complete code.


REPORT zztest
NO STANDARD PAGE HEADING
LINE-COUNT 36(3)
LINE-SIZE 250.

TYPES : BEGIN OF str1,
        partner(10) TYPE n,
        int TYPE i,
        END OF str1.

TYPES : BEGIN OF str2,
        partner(10),
        END OF str2.

DATA : itab1 TYPE STANDARD TABLE OF str1,
       wa_itab1 TYPE str1.

DATA : itab2 TYPE STANDARD TABLE OF str2,
              wa_itab2 TYPE str2.


wa_itab1-partner = 141.
wa_itab1-int     = 1.
APPEND wa_itab1 TO itab1.

wa_itab1-partner = 142.
wa_itab1-int     = 1.
APPEND wa_itab1 TO itab1.

wa_itab1-partner = 143.
wa_itab1-int     = 1.
APPEND wa_itab1 TO itab1.


wa_itab1-partner = 212.
wa_itab1-int     = 2.
APPEND wa_itab1 TO itab1.


wa_itab1-partner = 241.
wa_itab1-int     = 2.
APPEND wa_itab1 TO itab1.


wa_itab1-partner = 354.
wa_itab1-int     = 3.
APPEND wa_itab1 TO itab1.

wa_itab1-partner = 454.
wa_itab1-int     = 4.
APPEND wa_itab1 TO itab1.

wa_itab1-partner = 455.
wa_itab1-int     = 4.
APPEND wa_itab1 TO itab1.



SORT itab1 BY int.

LOOP AT itab1 INTO wa_itab1.

  ON CHANGE OF wa_itab1-int.

    IF sy-tabix EQ 1.
      wa_itab2-partner = wa_itab1-partner.
      APPEND wa_itab2 TO itab2.
      CLEAR wa_itab2.
      CONTINUE.
    ENDIF.


    PERFORM your_routine .
    REFRESH itab2.
  ENDON.

  wa_itab2-partner = wa_itab1-partner.
  APPEND wa_itab2 TO itab2.

  CLEAR wa_itab2.

ENDLOOP.

PERFORM your_routine .

*&--------------------------------------------------------------------*
*&      Form  your_routine
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM your_routine.
  LOOP AT itab2 INTO wa_itab2.

    WRITE : / wa_itab2-partner.

  ENDLOOP.

  SKIP 5.

ENDFORM.                    "your_routine

Regards,

Arun Sambargi.