10-30-2007 3:02 PM
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............
10-30-2007 3:14 PM
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
10-30-2007 3:14 PM
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
10-30-2007 3:16 PM
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.
10-30-2007 3:25 PM
<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
10-30-2007 3:31 PM
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.
10-30-2007 3:50 PM
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