Saturday, January 18, 2014

TAW10 - COMPLEX DATA OBJECTS

DEFINITION OF STRUCTURES WITH GLOBAL TYPES


You can define structured data objects in ABAP. They are also called structure variables or simply structures. Structures allow you to combine values that belong together logically into one data object.
Structures can be nested. Consequently, components can comprise more structures or even internal tables.
In the program, structure variables are defined with the DATA statement, in the same way as elementary data objects.
When you set the types, you can refer either to
  a Dictionary structure; or

  a structure type that is locally declared in the program.

DEFINING STRUCTURES WITH LOCAL TYPES


The TYPES statement can be used to define local structure types.
The statement begins with the TYPES keyword and includes the components within the respective start and end phrases:
TYPES: BEGIN OF and END OF .
You can also define a structured data object directly by replacing the leading key word TYPES with DATA.
The statement now begins with the DATA keyword and includes the relevant components within the respective start and end phrases:
DATA: BEGIN OF and END OF .


ACESS TO STRUCTURE COMPONENT


This slide depicts how you should always address the components of a structure by using a hyphen, as in structure_name-component_name.


COPYING STRUCTURE COMPONENTS WITH THE SAME NAME

By using the MOVE-CORRESPONDING statement, you can copy structure components with the same name from the source structure to the target structure, one component at a time. All the other components of the structures remain unchanged.


STRUCTURES IN DEBUGGING MODE
To trace the field contents of a structure in the Debugger, first enter the structure name in the Variables 1 area. Conversely, you can copy it from the source code by double-clicking it. You can then display the components of the structure by double-clicking the structure name in the Variable area.


INTERNAL TABLES: USAGE OPTION

An internal table is a data object that can hold several identically structured data records at runtime. In other words, internal tables are a simple way of processing large data sets in a structured manner.
The ABAP runtime system dynamically manages the size of the internal table.
Table rows or table entries are the individual data sets in an internal table. The individual components in a row are referred to as fields or columns of the internal table.
An internal table is mainly used for
  retaining data from database tables or sequential files for future processing;

  formatting data for the screen or printer output (for example, sorting); and

  formatting data for use in subroutines, function modules, or methods.

ATTRIBUTES OF INTERNAL TABLES
An internal table has three main attributes:
  Line Type describes the structure of the table rows. Usually a structure type is used but other data types are also possible.

  Key consists of the key fields, including the order in which they are used. The key can be defined as unique or nonunique, depending on the access type. Uniqueness means that a particular combination of key fields can only appear once within the table.

  Table Kind can be standardsorted, and hashed. The use of table kind is based on the appropriate access type.

ATTRIBUTES AND USE OF THE TABLE KINDS
Index access is used when a table entry is accessed by specifying the corresponding row number.
Key access is used when it is accessed by entering a key value.
With standard tables, the row numbering (or index) is maintained internally. Hence, the index and key accesses are both possible.
With sorted tables, the data records are automatically sorted in the ascending order of the key fields. Again, this means that the index is maintained internally and that both index and key accesses are possible.
With hashed tables, fast key access of the data records is enabled by using the hashing procedure. Therefore, with hashed tables, only key access is possible, using a unique key.


DEFINING INTERNAL TABLES WITH GLOBAL TYPES
The type of an internal table is called table type.
Table types can be defined locally in a program, thereby making them accessible only to that program.
Table types can be defined globally in the ABAP Dictionary.


DEFINING INTERNAL TABLES WITH LOCAL TYPES
You can declare table types locally in a program. When listing the key fields in the table type, their order matters for certain processing types, such as the sort by key. You can also define an internal table directly, using DATA instead of TYPES, to declare a local table type.

INDEPENDENT DEFINITION OF INTERNAL TABLES
You can independently define internal tables using
  the TYPES: BEGIN OF …. END OF statement, or

  the DATA keyword with TYPE, referring to a table name in the dictionary and using the words STANDARD, SORTED, or HASHED to describe the table type.

POSSIBLE DEFINITIONS OF INTERNAL TABLES

This slide shows you some possible definitions of internal tables:
  The first example defines a standard definition.

  The second example defines the table type as standard, sorted, or hashed.

  The third example is a shortened version with a nonunique key.


ACCESSING SINGLE RECORD (OVERVIEW)


A structure variable known as the work area, with the same type as the line type of the internal table, is used for single record processing of an internal table.

PROCESSING SETS OF RECORDS (OVERVIEW)
Sets of records can be processed using the ABAP statements, such as
  LOOP AT ENDLOOP, where the LOOP places the rows of an internal table one by one into the structure specified in the INTO clause;

  DELETE, which deletes the rows of the internal table that satisfy the condition;

  INSERT LINES OF, which copies the contents of several rows of an internal table to another internal table; and

  APPEND LINES OF, which appends the contents of several rows of an internal table to another standard table.

SYNTAX EXAMPLE: INSERTING A ROW

You can insert a row into an internal table by writing the required record into the prepared work area, and then inserting it into the internal table with an INSERT statement.


SYNTAX EXAMPLE: OUTPUTTING AN INTERNAL TABLE ROW BY ROW


To read and edit the contents of an internal table row by row, you use a LOOP statement. The system field sy-tabix contains the row number of the current table entry.
This slide depicts how you can process all the rows of the internal table consecutively and use the WRITE statement to provide the output.

SYNTAX EXAMPLE: READING BY INDEX


You can use the FROM–TO addition to restrict the access to certain rows in the loop. The access in this example is restricted to the first five rows. Hence, only those rows of the internal table are processed consecutively.
The READ TABLE statement can be used to read a single record, and the INDEX addition specifies the row number of the required record.

SYNTAX EXAMPLE: READING BY KEY


In the loop, you can use the WHERE addition to restrict access to certain rows. In our example, the system only processes those internal table rows, in which the CARRID field has the value LH.
The READ TABLE syntax can be used to read a specific row of an internal table. In this case, you must assign values to all the key fields after the WITH TABLE KEY addition. The return code sy-subrc is set to zero if a corresponding row is in the internal table.

SYNTAX EXAMPLE: SORTING AND DELETING CONTENT


You can sort standard and hashed tables in an ascending or a descending order, by using either the table key, or columns that use the SORT statement. The field is sorted in ascending order by default.
You use the REFRESH and CLEAR statements for deleting the table contents.
You use FREE to delete the entire contents of an internal table and release the previously used memory.


INTERNAL TABLES IN DEBUGGING MODE

In the Debugger, you can monitor the contents of an internal table by
  entering the table name in the Variables 1 area; and

  branching off to the table display by double-clicking.

Alternatively, use the table tab page; specify the table name in the internal table field; and press Enter, to display the table contents.


COMPARISON: INTERNAL TABLES WITH AND WITHOUT HEADER LINES

To create a table with header line, use the WITH HEADER LINE addition in the definition of an internal table. A work area that suits the table is created automatically, thus simplifying the syntax of the table command.
The automatically generated work area has the same name as the internal table.

1 comment:

  1. There are some problems with data handling that’s why people become frustrated because they do not know the best way to handle the data complexity and its management. So for overcoming this type of problem the people hire the best data scientist from this Activewizards blog who can easily solve their all type of data handling problems.

    ReplyDelete