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

former_member515329
Participant
0 Likes
1,047

i m writing simple report ...in internal (itab) i have 4 fields...below is internal table

X1 X2 X3 X4

880 770 112 4

881 771 113 5

881 771 114 6

882 772 115 7

882 772 116 8

883 773 117 9

883 773 118 7

883 773 119 7

i want the logic to retrieve the above fields i need to write the code based on X1 and X2 fields...A separate internal table need to be passed (itab1)for each combination of X1 & X2 parties. A X1 may have several X2 assigned to it. Lines having same combination of X1- X2 should be added to be passed an enty in internal table (itab1). A separate record will be passed if a line has different X1 even if the X2 remains same

i want the above internal table to be displayed like this..

itab1

X1 X2 X3 X4

880 770 112 4

then passing to some tcode and clearing itab1

then

881 771 113 5

881 771 114 6

then passing to some tcode and clearing itab1

882 772 115 7

882 772 116 8

then passing to some tcode and clearing itab1

883 773 117 9

883 773 118 7

883 773 119 7

then passing to some tcode and clearing itab1

pls hlp

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
972

Hi,

You can check out this following piece of code

TYPES : BEGIN OF gty_test,

field1 TYPE c LENGTH 10,

field2 TYPE c LENGTH 10,

field3 TYPE c LENGTH 10,

field4 TYPE c LENGTH 10,

END OF gty_test.

DATA : gt_test1 TYPE STANDARD TABLE OF gty_test,

gt_test2 TYPE STANDARD TABLE OF gty_test,

gt_test3 TYPE STANDARD TABLE OF gty_test,

gs_test1 TYPE gty_test,

gs_test2 TYPE gty_test,

gs_test3 TYPE gty_test.

gs_test1-field1 = 'AAAA'.

gs_test1-field2 = '1111'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'AAAA'.

gs_test1-field2 = '1112'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'BBBB'.

gs_test1-field2 = '1111'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'BBBB'.

gs_test1-field2 = '1112'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'BBBB'.

gs_test1-field2 = '1113'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'CCCC'.

gs_test1-field2 = '1111'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

DATA : lv_tabix TYPE sy-tabix.

SORT gt_test1 BY field1 field2.

LOOP AT gt_test1 INTO gs_test1.

lv_tabix = sy-tabix.

IF lv_tabix EQ 1.

MOVE : gs_test1 TO gs_test3.

ENDIF.

MOVE : gs_test1 TO gs_test2.

IF gs_test1-field1 NE gs_test3-field1.

MOVE : gs_test1 TO gs_test3.

" Your own logic here - do what ever your logic require - transfer the table

" Call Transaction

CLEAR : gt_test2[].

ENDIF.

APPEND gs_test1 TO gt_test2.

WRITE : gs_test1-field1,gs_test1-field2,gs_test1-field3,gs_test1-field4.

SKIP 1.

CLEAR : gs_test1.

ENDLOOP.

Hope this helps.

Thanks,

Samantak.

9 REPLIES 9
Read only

Former Member
0 Likes
972

use one more internal table.

data : itab_temp like table of itab with header line.

now move itab to itab_temp

itab_temp[] = itab[].

sort itab_temp by x1 x2.

delete adjecent duplicates from itab_temp compairing x1 x2.

loop at itab_temp.

loop at itab where x1 = itab_temp-x1

x2 = itab_temp-x2.

call transaction.

endloop.

endloop.

regards,

Alpesh

Edited by: Alpesh on Jun 11, 2009 9:34 AM

Read only

0 Likes
972

Alpesh,

but when i wrote this code...

LOOP AT i_input_bdc." INTO wa_input_bdc.

move i_input_bdc to i_input_bdc1.

APPEND i_input_bdc1.

ENDLOOP.

delete adjacent duplicates from i_input_bdc1 comparing soldto shipto.

loop at i_input_bdc1." into wa_input_bdc1.

loop at i_input_bdc

where soldto = i_input_bdc1-soldto

and shipto = i_input_bdc1-shipto.

move i_input_bdc to i_input_bdc2.

clear i_input_bdc2.

endloop.

endloop.

only one entry from table i_input_bdc will be moved to i_input_bdc2...but i have 2 entries matching that condition...

Read only

Former Member
0 Likes
972

Dear Ravi,

Take one temp internal table and move this data to that table.

Now loop one itab.

with in the loop

again loop the other internal table with ur conditions

loop itab1.

loop itab2 where x1 = itab1-x1 and x2 = itab1-x2.

here pass this data to ur tcodes.

and delete the record from itab1

endllop.

endloop.

Rgds,

Kiran

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
972

use control break statements

at New

Read only

Former Member
0 Likes
972

Hi Ravi,

You need to sort the Internal Table based on Fields X1 and X2. And then you need to use the control break statement to populate the internal table and to display the data. At the end of the loop you can refresh the Table.

SORT ITAB by X1 X2.

LOOP at ITAB1 into workarea.

write : ITAB1-workarea.

move itab1-workarea to itab2-workarea.

append itab2-workarea to ITAB2. " Use your own logic

call transaction.

ON CHANGE OF X1.

ITAB3[] = ITAB2[].

REFRESH : ITAB2.

ENDON.

ENDON.

clear : ITAB1-workarea,ITAB2-workarea.

ENDLOOP.

Hope this helps.

Thanks,

Samantak.

Read only

0 Likes
972

Samantak..

ur code will work only for one eentry as u r using workarea...i m having similar entries of X1 and X2 as many...

LOOP AT i_input_bdc." INTO wa_input_bdc.

move i_input_bdc to i_input_bdc1.

APPEND i_input_bdc1.

ENDLOOP.

delete adjacent duplicates from i_input_bdc1 comparing soldto shipto.

loop at i_input_bdc1." into wa_input_bdc1.

loop at i_input_bdc

where soldto = i_input_bdc1-soldto

and shipto = i_input_bdc1-shipto.

move i_input_bdc to i_input_bdc2.

  • here after i_input_bdc2 has all similar soldto and similar shipto...i need to call a tcode...but here only one entry will be passed to i_input_bdc2..i need all simialr at a bunch..i.e,

883 773 117 9

883 773 118 7

883 773 119 7

these values should be passed to i_input_bdc2 and call tcode ..then clear the i_input_bdc2....then next values...

882 772 115 7

882 772 116 8

these values should be passed to i_input_bdc2 and call tcode..then clear the i_input_bdc2....then next values...*

endloop.

endloop.

Read only

Former Member
0 Likes
972

Hi Ravi!

Check the code below in debug mode, i reckon it will fulfill your requirement.


DATA:
BEGIN OF itab OCCURS 0,
  x1(3),
  x2(3),
  x3(3),
  x4(1),
END OF itab,

itab2 LIKE TABLE OF itab WITH HEADER LINE.

itab-x1 = 880.
itab-x2 = 770.
itab-x3 = 112.
itab-x4 = 4.
APPEND itab.

itab-x1 = 881.
itab-x2 = 771.
itab-x3 = 113.
itab-x4 = 5.
APPEND itab.

itab-x1 = 881.
itab-x2 = 771.
itab-x3 = 114.
itab-x4 = 6.
APPEND itab.

itab-x1 = 882.
itab-x2 = 772.
itab-x3 = 115.
itab-x4 = 7.
APPEND itab.

itab-x1 = 882.
itab-x2 = 772.
itab-x3 = 116.
itab-x4 = 8.
APPEND itab.

itab-x1 = 883.
itab-x2 = 773.
itab-x3 = 117.
itab-x4 = 9.
APPEND itab.

itab-x1 = 883.
itab-x2 = 773.
itab-x3 = 118.
itab-x4 = 7.
APPEND itab.

itab-x1 = 883.
itab-x2 = 773.
itab-x3 = 119.
itab-x4 = 7.
APPEND itab.

SORT itab BY x1 x2.

LOOP AT itab.

  IF NOT itab2 IS INITIAL AND itab-x1 NE itab2-x1 AND
         itab-x2 NE itab2-x2.
*      CALL YOUR TRANSACTION HERE.
    CLEAR: ITAB2,itab2[].
  ENDIF.

  itab2 = itab.
  APPEND itab2.

  AT LAST.
*      CALL YOUR TRANSACTION HERE.
    CLEAR: ITAB2,itab2[].
  ENDAT.
ENDLOOP.

Read only

Former Member
0 Likes
972

Hi,

data : i_temp like itab occurs 0 with header line.

i_temp[ ] = itab[ ].

sort i_temp by x1.

delete adjecent duplicates from i_temp compairing x1.

loop at i_temp.

loop at itab where x1 = i_temp-x1.

call transaction.

endloop.

delete itab where x1 = i_temp-x1.

endloop.

Regards,

Kumar Bandanadham

Edited by: Velangini Showry Maria Kumar Bandanadham on Jun 11, 2009 8:30 AM

Read only

Former Member
0 Likes
973

Hi,

You can check out this following piece of code

TYPES : BEGIN OF gty_test,

field1 TYPE c LENGTH 10,

field2 TYPE c LENGTH 10,

field3 TYPE c LENGTH 10,

field4 TYPE c LENGTH 10,

END OF gty_test.

DATA : gt_test1 TYPE STANDARD TABLE OF gty_test,

gt_test2 TYPE STANDARD TABLE OF gty_test,

gt_test3 TYPE STANDARD TABLE OF gty_test,

gs_test1 TYPE gty_test,

gs_test2 TYPE gty_test,

gs_test3 TYPE gty_test.

gs_test1-field1 = 'AAAA'.

gs_test1-field2 = '1111'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'AAAA'.

gs_test1-field2 = '1112'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'BBBB'.

gs_test1-field2 = '1111'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'BBBB'.

gs_test1-field2 = '1112'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'BBBB'.

gs_test1-field2 = '1113'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

gs_test1-field1 = 'CCCC'.

gs_test1-field2 = '1111'.

gs_test1-field3 = 'Welcome'.

gs_test1-field4 = 'Sachin'.

APPEND gs_test1 TO gt_test1.

CLEAR : gs_test1.

DATA : lv_tabix TYPE sy-tabix.

SORT gt_test1 BY field1 field2.

LOOP AT gt_test1 INTO gs_test1.

lv_tabix = sy-tabix.

IF lv_tabix EQ 1.

MOVE : gs_test1 TO gs_test3.

ENDIF.

MOVE : gs_test1 TO gs_test2.

IF gs_test1-field1 NE gs_test3-field1.

MOVE : gs_test1 TO gs_test3.

" Your own logic here - do what ever your logic require - transfer the table

" Call Transaction

CLEAR : gt_test2[].

ENDIF.

APPEND gs_test1 TO gt_test2.

WRITE : gs_test1-field1,gs_test1-field2,gs_test1-field3,gs_test1-field4.

SKIP 1.

CLEAR : gs_test1.

ENDLOOP.

Hope this helps.

Thanks,

Samantak.