Programming Structure and Field Strings

In our previous tutorials on creating database tables, we have created a table by name ZEMPLOYEE. Now let’s define pre-defined programming structures and see how they work.

Pre-Defined Programming Structure

Using the keyword TABLES you can create a pre-defined programming structure. For example, a structure of type ZEMPLOYEE table can be created in memory using the following statement

Tables : ZEMPLOYEE.

User-Defined Programming Structure

A user defined Programming structure is also called as a Fields String. The syntax is very similar to a structure in C. A field string can hold only 1 record at any given point in time.

BEGIN OF FS,
--
END OF FS.

For example, let’s create an employee field string.

DATA : BEGIN OF EMP,
EMPNO(10)  TYPE I,
EMPNAME(50)  TYPE C,
END  OF EMP.

Now, in order to put data into the field string, enter the following SQL Statement.

SELECT * FROM ZEMPLOYEE INTO EMP,
ENDSELECT.

To print out the contents of the EMP structure, use the WRITE statement

WRITE:/EMP.

As discussed previously the field string EMP can only hold one record irrespective of how many records the ZEMPLOYEE table contains.


SAP Training | SAP Access


Now let’s do a demo.

*&---------------------------------------------------------------------*
*& Report   ZEMPLOY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ZEMPLOY.
TABLES: ZEMPLOYEE. " This is a Pre-Defined Programming  Structure of type ZEMPLOYEE Table
DATA: BEGIN OF EMP,
MANDT(3)  TYPE C,
EMPNO(10) TYPE C,
END OF EMP.
SELECT * FROM ZEMPLOYEE INTO EMP.
ENDSELECT.
WRITE:/ EMP.

Execute this program by clicking on the Test button.

You should now see the employees in the table as the output.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s