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: 

When to use structures and when to use Internal tables ?????

Former Member
0 Kudos

Hi all, i am a beginner to ABAP/4 language , i have a doubt, i'm having a confusion with Structures and internal tables concepts, i've gone through many books, some of them used internal tables and some used structures while retrieving the data from the data tables, can any one clarify me when to use what ?

Thnx in advance............

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

It is very simple,

Structures are used in the select statements if it going to fetch single record for eg. Select * from vbak into wa_vbak where vbeln = xxxxxxxx. in this case there will be only one record for a sales order in vbak(Header table)

Internal tables are used in the select statements if it going to fetch more than one record for eg. Select * from vbap into table i_vbak where vbeln = xxxxxxxx. in this case there will be more than one record for a sales order in vbap(item table).

<b><REMOVED BY MODERATOR></b>

Thanks,

Muthu.

Message was edited by:

Alvaro Tejada Galindo

5 REPLIES 5

Former Member
0 Kudos

Hi,

It is very simple,

Structures are used in the select statements if it going to fetch single record for eg. Select * from vbak into wa_vbak where vbeln = xxxxxxxx. in this case there will be only one record for a sales order in vbak(Header table)

Internal tables are used in the select statements if it going to fetch more than one record for eg. Select * from vbap into table i_vbak where vbeln = xxxxxxxx. in this case there will be more than one record for a sales order in vbap(item table).

<b><REMOVED BY MODERATOR></b>

Thanks,

Muthu.

Message was edited by:

Alvaro Tejada Galindo

Former Member
0 Kudos

Imagine the structure is a single row of data. If you get more than 1 row of data from a database table then you effectively have multiple instances of the structure - or in other words you have an internal table with multiple rows, all with the same structure.

When retrieving data from a DB table, if you know you will only get 1 row returned then you can put the data into a structure (assuming yuo are getting multiple fields) or if you know you will get multilpe rows returned then you would typically put the data into an internal table.

Gareth.

raymond_giuseppi
Active Contributor
0 Kudos

<b>Structures</b>

A structure (structured type) comprises components (fields). Types are defined for the

components A component can refer to an elementary type (via a data element or by directly

specifying the data type and length in the structure definition), another structure or a table type. A structure can therefore be nested to any depth.

Structures are used to define the data at the interface of module pools and screens and to define the parameter types of function modules.

e.g.: The material master data is structure MARA, also a database table, the fields of a dynpro can be defined thru a structure...

<b>Internal tables</b>

Internal tables provide a means of taking data from a fixed structure and storing it in working

memory in ABAP. The data is stored line by line in memory, and each line has the same

structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data

objects, they save the programmer the task of dynamic memory management in his or her

programs. You should use internal tables whenever you want to process a dataset with a fixed

structure within a program. A particularly important use for internal tables is for storing and

formatting data from a database table within a program. They are also a good way of including very complicated data structures in an ABAP program.

e.g. : The data read from a database table is stored in an internal table.

Regards

Former Member
0 Kudos

Hi Kris,

Internal table is used to store multiple records and structure is used to store single record.

types : begin of ty_struct,

name(20) type c,

id type i,

end of ty_struct.

  • Here structure get created

data : v_struct type ty_struct.

  • Here internal table get created

data : t_tab type standard table of ty_struct.

Former Member
0 Kudos

Hi Kris,

Structure: is having the memory to hold only one record.

Table : is used to hold the multiple records.

If your requirement is to hold only one record goto Structure.

or if it is multiple records goto intenal table.

Structure is just like header or workarea of an internal table