‎2009 Aug 04 12:08 PM
Hi ABAP Experts,
I have some doubt on declaring Internal tables, could you tell me which case case1 or case 2 is correct.
Case1.
types: begin of t_kunnr,
name1(30) type c,
name2(30) type c,
kunnr(10) type c,
end of t_kunnr.
TYPES it_kunnr TYPE standard table of t_kunnr.
DATA: wa_kunnr TYPE t_kunnr.
DATA: it_kunnr type t_kunnr.
wa_kunnr-name1 = 'KK'.
wa_kunnr-name2 = 'MM'.
wa_kunnr-kunnr = '4999'.
append wa_kunnr to it_kunnr.
wa_kunnr-name1 = 'KK1'.
wa_kunnr-name2 = 'MM1'.
wa_kunnr-kunnr = '4999'.
append wa_kunnr to it_kunnr.
wa_kunnr-name1 = 'KK1'.
wa_kunnr-name2 = 'MM1'.
wa_kunnr-kunnr = '3999'.
append wa_kunnr to it_kunnr.
loop at it_kunnr into wa_kunnr.
write : / wa_kunnr-name1, wa_kunnr-kunnr.
endloop.
case2
types: begin of t_kunnr,
name1(30) type c,
name2(30) type c,
kunnr(10) type c,
end of t_kunnr.
DATA: wa_kunnr TYPE t_kunnr,
it_kunnr TYPE STANDARD TABLE OF t_kunnr.
wa_kunnr-name1 = 'KK'.
wa_kunnr-name2 = 'MM'.
wa_kunnr-kunnr = '4999'.
append wa_kunnr to it_kunnr.
wa_kunnr-name1 = 'KK1'.
wa_kunnr-name2 = 'MM1'.
wa_kunnr-kunnr = '4999'.
append wa_kunnr to it_kunnr.
wa_kunnr-name1 = 'KK1'.
wa_kunnr-name2 = 'MM1'.
wa_kunnr-kunnr = '3999'.
append wa_kunnr to it_kunnr.
loop at it_kunnr into wa_kunnr.
write : / wa_kunnr-name1, wa_kunnr-kunnr.
endloop.
Thanks in advance.
‎2009 Aug 04 12:11 PM
HI,
Your case 2 is correct. If you declare as DATA: it_kunnr type t_kunnr. it will be considered as a work area rather than a internal table . Also clear the internal table header after appending.
types: begin of t_kunnr,
name1(30) type c,
name2(30) type c,
kunnr(10) type c,
end of t_kunnr.
DATA: wa_kunnr TYPE t_kunnr,
it_kunnr TYPE STANDARD TABLE OF t_kunnr.
wa_kunnr-name1 = 'KK'.
wa_kunnr-name2 = 'MM'.
wa_kunnr-kunnr = '4999'.
append wa_kunnr to it_kunnr.
clear it_kunnr.
wa_kunnr-name1 = 'KK1'.
wa_kunnr-name2 = 'MM1'.
wa_kunnr-kunnr = '4999'.
append wa_kunnr to it_kunnr.
clear it_kunnr.
wa_kunnr-name1 = 'KK1'.
wa_kunnr-name2 = 'MM1'.
wa_kunnr-kunnr = '3999'.
append wa_kunnr to it_kunnr.
clear it_kunnr.
loop at it_kunnr into wa_kunnr.
write : / wa_kunnr-name1, wa_kunnr-kunnr.
endloop.
Regards,
Vik
‎2009 Aug 04 12:11 PM
‎2009 Aug 04 12:12 PM
‎2009 Aug 04 12:12 PM
Hi,
Case 2 is correct.
Because in case 1 , you are overriting table declartion.
‎2009 Aug 04 12:15 PM
Hi Thanks for your replies,
Could you explain me how case1 is correct one.
‎2009 Aug 04 12:17 PM
Hi Sorry,
Sorry for above reply, Could you explain me how case 2 declaration is correct.
‎2009 Aug 04 12:20 PM
‎2009 Aug 04 12:13 PM
Hi,
If you need to declare Internal Tables, use DATA Statement.
You are declarinf Types and not Internal Tables.
Uou need to add OCCUR Clause to declare internal table, other wise it works like a work area only.
Example:
data : begin of t_kunnr occurs 0,
kunnr like kna1-kunnr,
name1 like kna1-name1,
end of t_kunnr.
Regds,
Anil
‎2009 Aug 04 12:16 PM
hi,
case 2 is correct way to declare the internal table.
thanks
Ashu
‎2009 Aug 04 12:20 PM
Case 2 is suggestable
in case1
TYPES it_kunnr TYPE standard table of t_kunnr.
this means u r declaring the structure again using TYPES.
Thanks,
ajay
‎2009 Aug 04 12:23 PM
Hi,
As everyone has said case 2 is the right way.
In Case1.
TYPES it_kunnr TYPE standard table of t_kunnr.
DATA: it_kunnr type t_kunnr.
these two statements are wrong. First one rong because 'Types ' statement is used to decalre local program types, which only have a defenition and no related object in Data Base. Data statement is used to create objects in DB of a specific type.
Second statement is wrong because it only creates a DB object of structure type and not table type.
As suggested u can use occurs 0 additions but this is obsolete and not advisable anymore. This is because occurs 0 creates a table with a header line and header line concept is obsolete.
The best practise is to declare the Type using TYPES statement and the decalring table of that type using "type [STANDARD/HASHED/SORTED] table of " addition.
‎2009 Aug 04 12:40 PM
Hi,
Case 2 is correct, Why becuase in case 1 your creating Type it_kunnr is not treating as an internal table but you are trying to append to it. So internal table always should be Data type only.
Regards,
Ganesh