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 concept

Former Member
0 Likes
1,239

Hi Friends,

I m confused abt internal table concept.

how to define internal table & wa separately?

how to use wa & internal table?

how to define internal table with header line.

What is the diff b/w header line & without header line.

According to my knowledge header line i.e. wa. It can hold only one record at a time.

Plz tell me in detail.

plz help me for this.

15 REPLIES 15
Read only

Former Member
0 Likes
1,180

hi,

It_vbak is an internal table with header line,

it_vbak1 is internal table without header line,

wa_vbak is a workarea which is having a similar structure of it_vbak internal table.



types : begin of t_vbak,
          vbeln like vbak-vbeln,
          vbtyp like vbak-vbtyp,
          aurat like vbak-auart,
        end of t_vbak.

data: it_vbak type standard table of t_vbak with header line,
      it_vbak1 type table of t_vbak,
      wa_vbak type t_vbak.

When you create internal table with header line, a default work area is created.

while creating internal table without header line, we need to create explicit work area to work with it. When we need to nest the tables with in tables, we need to use this type of internal table.

there are still many ways of declaring internal tables with and without header lines.

Regards,

Sailaja.

Read only

0 Likes
1,180

Hi Sailaja,

thanks for ur good reply.

Will u tell me the different ways of defining internal table with header line & without header line.

& how to read the data from wa to body, how to move etc.

i need ur help. Plz help me.

Read only

0 Likes
1,180

Please see the following. Notice that the WITH HEADER LINE extension is obselete and shouldn't be used.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb367a358411d1829f0000e829fbfe/frameset.htm

Regards,

Rich Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,180

The header line is used to hold one line when reading the table. For example, for an internal table with a header line you can simply loop or read it and the current row will be read into the "header line" of the itab.

data: itab type table of string with header line.

loop at itab.
  write:/ itab.
endloop.

Now, if you don't use a header line, you must use a work area, because you need a place to read the data into.

data: itab type table of string .
data: wa type string.

loop at itab into wa.
  write:/ wa.
endloop.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,180

1) To define itab and wa separately.

data: itab type table of lfa1.

data: wa type lfa1.

usage

loop at itab into wa.

write:/ wa-lifnr.

endloop.

The difference between an internal table with and a/o header is the header line itself.

in short :

work area + itab without header line = itab with header line.

REgards,

Ravi

Read only

Former Member
0 Likes
1,180

how to define internal table & wa separately?

*INTERNAL TABLE

data : begin of itab occurs 0,

matnr like mara-matnr,

end of itab.

*WORK AREA

data : wa_itab like itab.

how to use wa & internal table?

Each internal table is looped and that record is passes to workarea and that workarea is used inside the loop.

loop at itab into wa_itab.

write : / wa_itab-matnr.

endloop.

What is the diff b/w header line & without header line.

if there is header line , for every loop the data will be retreived to header line and this is used

if the internal table is without header line , then each internal table record is looped and stored in workarea and this workarea is used

Read only

Former Member
0 Likes
1,180

Hi Salil,

How to Define an Internal Table and WA?

DATA: ITAB like standard table of <DBTAB/STRUCT NAME/Line type>.

DATA: WA_ITAB type <DBTAB/STRUCT NAME/Line type>.

Now this WA_ITAB is the Work Area of ITAB.

If you are populating values to this internal table ITAB and i fyou would like to read values from it then you hav eto move to the WorkArea defined for it i.e., WA_ITAB.

For example.

Read,

read table itab into wa_itab with key .....

Loop,

loop at itab into wa_itab.

endloop.

This is because you are using internal table without a header line.

if you are using internal table with header line(i.e., ITAB addition with header line.) then the table itab is itself an WA and you need not have to move i tto WA i.e.,

While Reading ITAB,

Read table ITAB with key .......

While Looping,

Loop at itab.

Endloop.

defining Internal Table with header line?

DATA: ITAB Like standard table of <DBTAB/STRUCT NAME/Line type> with header line.

or

DATA: begin of itab occurs 0.

end of itab.

Hope this would have bought some light!

Cheers,

Prashanth

Read only

Former Member
0 Likes
1,180

hi,

data: wa_vbak1 like wa_vbak,
      
      wa_vbak2 like line of it_vbak,
      
      it_vbak2 like table of wa_vbak with header line,
      
      it_vbak3 like table of it_vbak2 with header line.

Regards,

Sailaja.

Read only

0 Likes
1,180

Hi,

It's fine.

Will u just tell me what is the difference b/w

data: itab like table of kna1.

&

data: itab type table of kna1.

Read only

0 Likes
1,180

hi,

Here, the LIKE addition refers to an existing table object in the same program. The TYPE addition can refer to an internal type in the program declared using the TYPES statement, or a table type in the ABAP Dictionary.

You must ensure that you only refer to tables that are fully typed. Referring to generic table types (ANY TABLE, INDEX TABLE) or not specifying the key fully is not allowed (for exceptions, refer to Special Features of Standard Tables).

rgds

anver

if hlped mark points

Read only

0 Likes
1,180

Check this link,to know the Difference betwen TYPE and LIKE

the same concept also applies to internal table definition.

Regards,

Srikanth

Read only

Former Member
0 Likes
1,180

hi,

<b> TYPES and DATA will be having different namespaces.</b>

So, we can declare 2 variables with the same name but one should be declared using DATA statement and other using TYPES statement.

types : v_var type c.
data: v_var type i.

data: v_new like v_var,
      v_next type v_var.

v_new is of type integer, and v_next will be of type character.

While declaring v_new, as you specified like, it checks for those varaibles which are declared using <b>DATA </b>statement.

In case of V_MEXT, it checks for variables that are declared using <b>TYPES</b> statement.

Regards,

Sailaja.

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,180

Hello Salil

There is only one point that has not been mentioned yet:

<b>DO NOT USE HEADER LINES!!!!</b>

Itabs with header lines mess up any ABAP coding and they are a nightmare with regards to maintainability.

Why am I so opposed to itabs having header lines?

(1) The same variable has two completely different meanings (either it is the body of the itab or the single header line).

(2) If the header line is filled with data can we work on that data or did somebody simply miss to initialize the header line correctly?

(3) When it comes to ABAP-OO (and we should exclusively program in ABAP-OO and leave the classical ABAP behind us) we cannot use header lines anymore because SAP has abandoned them from ABAP-OO (luckily!!!).

I have maintained lots of programs from other developers and one of the very first things I did was to get rid of all header lines. Even if you think I am a bit weird about this topic I repeat myself:

<b>DO NOT USE HEADER LINES!!!!</b>

Regards

Uwe

Read only

0 Likes
1,180

Uwe, I did mentioned it above, but obviously it has been overlooked. Thanks for the additional point of view.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,180

hi,

Internal table is a table that u declare in ur program of some standard or ur own table ttype.

this is how u declare an internal table without header line of type tab le MARA

itab TYPE TABLE OF MARA.

this is how u declare a work area of type MARA

wa_itab type MARA.

THIS is how u declare a table with header line.

itab TYPE TABLE OF MARA with header line.

what happens if there is no header line?

if u dont declare a table without header line then u need to explicitly declare a work area , if u need to do some display or calculations. u cannot use in this case the internal table to display.

u cannot read the internal table.

if u have a internal table with header line then no need to have an explict work area

reward if helpful.