Skip to Content
author's profile photo
Former Member

Question about type definitions

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • author's profile photo
    Former Member
    Apr 29, 2004 at 07:42 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Apr 29, 2004 at 07:42 AM

    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 ...

    Add comment
    10|10000 characters needed characters exceeded