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: 

Question about type definitions

Former Member
0 Kudos

I have a syntax question about the command TYPES

I want to define a Type that consists of the complete structure of a database table + two other fields.

What syntax do i have to use for this

2 REPLIES 2

Former Member
0 Kudos

Two ways. Assume table dbtab has a field called f1.


TYPES:
  BEGIN OF MYTYPE,
    dbtab          TYPE dbtab,
    myf1,
    myf2,
  END OF MYTYPE.

DATA:
  myvar TYPE MYTYPE.
...

WRITE: myvar-dbtab-f1, myvar-myf1.

or


TYPES:
  BEGIN OF MYTYPE.
    INCLUDE STRUCTURE dbtab.
TYPES:
    myf1,
    myf2,
  END OF MYTYPE.

DATA:
  myvar TYPE MYTYPE.
...

WRITE: myvar-f1, myvar-f2.

Personally I dislike the syntax of the second since it requires a break in the chaining (that is a second TYPES statement). It is possible that nowadays INCLUDE STRUCTURE xxx should be INCLUDE TYPE xxx - haven't tried for a while but you should get the idea.

It is also clearer (IMO) with the first approach what the data represents, plus you don't have to worry about field-names conflicting - that is, it wouldn't matter if dbtab also had a field called myf1.

Scott

Former Member
0 Kudos

Use INCLUDE STRUCTURE and then individually place the other two fields between BEGIN and END in the TYPE definition.

TYPES: BEGIN OF....

INCLUDE STRUCTURE DBNAME.

TYPES: f1 type ..

f2 type ..

END OF ...