Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "Data" and "Types" creating a structure?

I found 2 examples for creating a structure.

This one with TYPES:

TYPES : BEGIN OF employee_information,
            name TYPE c LENGTH 20,
            surname TYPE c LENGTH 20,
            tel_no TYPE n LENGTH 12,
          END OF employee_information.

and this other one with DATA:

DATA : BEGIN OF employee_information,
            name TYPE c LENGTH 20,
            surname TYPE c LENGTH 20,
            tel_no TYPE n LENGTH 12,
          END OF employee_information.

I read the documentation topic "The Statements TYPES and DATA" in the SAP Library, but I don't understand why we use these distinct terms TYPES and DATA for creating a structured data type.

Can you explain the difference?

like image 517
Merve Avatar asked Jun 13 '12 10:06

Merve


1 Answers

First of all, creating a TYPE is the newer and recommended method to use.

When you create a DATA, lets say for an internal table;

DATA: BEGIN OF employee_information OCCURS 0,             "itab with header line
            name TYPE c LENGTH 20,
            surname TYPE c LENGTH 20,
            tel_no TYPE n LENGTH 12,
      END OF employee_information.

You can have the internal table with header line. But this is the old method.

When you use TYPE in order to declare an internal table you can use its headerline and its content simultaneously;

  TYPES: BEGIN OF t_employee_information,
            name TYPE c LENGTH 20,
            surname TYPE c LENGTH 20,
            tel_no TYPE n LENGTH 12,
  END OF t_employee_information.

  DATA: employee_information TYPE STANDARD TABLE OF t_employee_information INITIAL SIZE 0,      "itab
        employee_information TYPE t_employee_information.                    "work area (header line)

For example: You can use this TYPE in order to create as many internal tables as you want such as:

  DATA: employee_information_1 TYPE TABLE OF t_employee_information, "itab1
        employee_information_1 TYPE t_employee_information.          "work area1 (header line)
  DATA: employee_information_2 TYPE TABLE OF t_employee_information, "itab2
        employee_information_2 TYPE t_employee_information.          "work area2 (header line)
  DATA: employee_information_3 TYPE TABLE OF t_employee_information, "itab3
        employee_information_3 TYPE t_employee_information.          "work area3 (header line)
like image 98
Mtu Avatar answered Oct 18 '22 14:10

Mtu