Skip to Content
author's profile photo Former Member
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 a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on 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 a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on 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 a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.