Skip to Content
avatar image
-4
Former Member

Syntax for creating local structure type & table type

Hi

I'm trying to learn ABAP and before posting this question I have spent a lot of time searching the web for my clarifications as well gone through SAP documents & Blogs apart from the study guides I have purchased from SAP & other publications, but still there I have doubts.

Firstly,while creating Internal Tables I came across the various methods by which they can be created & the associated syntax. Now they all sometimes differ in terms of keywords or some other thing.

So I post my doubts here with the hope that some fellow friend here can guide me-

1) Firstly, there is this confusion between the TYPES statement and the TYPE statement.

What does the following syntax declare -

(a) Syntax 1 :

TYPES : Begin of ZABC,

F1 Type C,

F2 Type I

......

....... etc. etc.

End of ZABC.

(b) Syntax 2 :

TYPES <internal_tab> TYPE /LIKE <internal_tab_type> OF <line_type_itab> [ WITH <key>]

Now my first question is what is the difference between the above 2 syntax & what do they create respectively? Do they create a table type or local structure type & what is the difference between the two i.e. a "table type" & a "local structure type"?

2)My 2nd question is - sometimes we are creating Internal Tables using the syntax : -

DATA : <itab> Type Table of <some_name >

When is the above syntax used? What is the difference between these & earlier syntaxes?

3) My 3rd doubt is can I create a "table type" both in ABAP Editor as well as in DDIC?

What is the difference between an "Internal table object" and "internal table type"

And finally how can I use a predefined system defined data type "I" as a row or line type in the following syntax which I found in an ABAP text book eg. -

TYPES VectorTab TYPE SORTED TABLE OF I WITH UNIQUE KEY TABLE LINE.

Here the book says that VectorTab is a table type but then how can it have 'I' as row / line type ?? Also, as far as I know "table types " can be created in DDIC , then what is difference between a "table type" created in DDIC and a "table type" created in SE38(ABAP Editor) ??

Hope someone from this community can surely help me.

Thanks & Regards

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Aug 17, 2017 at 06:13 AM

    Question 1) a):

    The syntax declares a structured type ZABC.

    Question 1) b)

    The syntax declares a table type.

    Question 2)

    DATA declares data objects. TYPES declares data types.

    Question 3)

    Yes.

    Question: What is the difference between an "Internal table object" and "internal table type"

    One is a data object, the other is a data type.

    Question: how can it have 'I' as row / line type

    Internal tables can have any line type.

    Question: what is difference between a "table type" created in DDIC and a "table type" created in SE38

    The visibiltiy.

    Follow the links to learn more.

    Add comment
    10|10000 characters needed characters exceeded

    • A table type is a table type. It can be created in the contexts of an ABAP Program, in classes, or in the ABAP Dictionary.

      With TYPES you can create

      • local table types in programs (either program global or procedure local)
      • global table types as public attributes of global classes and interfaces
      • global table types in type pools (obsolete)

      Don't mix up the statement TYPES with the context where it is used. In fact TYPES is used for all kinds of table types except those that are defined by the form based tool SE11.

  • Aug 16, 2017 at 04:21 PM

    You have to understand the basic difference between data types and data objects. Data types are declared with TYPES, data objects (fields) are declared with DATA. Data types are referred by the TYPE addition. Data objects are referred by the LIKE addition. Going on from that learn about the different data types, which can be elementary, structured, tabular, references. Table types, the data types of internal tables, are complex types that can have any line type: elementary, structured, tabular, reference type. Last but not least, learn where types and data can be declared: locally in programs or globally in the ABAP Dictionary or in global classes.

    Look also here.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Horst. Thank you Sir for the good explanations by both you & Bertrand. But you also skipped some of my questions -

      2)What is the difference between Syntax 1 and Syntax 2 that I mentioned in my first question?

      3) My 3rd doubt regarding this following syntax -

      DATA : <itab> Type Table of <any_name >

      When is the above syntax used? What is the difference between these & earlier 2 syntax? Can this "any_name" object be any of the following -

      a)structure / (b)database table/transparent table / (c)local structure / d)predefined types like I,C,N,P (Int,Char,Numeric or Packed) ??

      4)Last another of my main confusions is -

      Are "local structure type" & "local table type" one & same thing?Because as far as I understand I can create a table type both in DDIC (using Tcode SE11) as well as in ABAP Editor(SE38) using the syntax TYPES as mentioned in Syntax 2 in my original post. In this context,does it mean that syntax 2 is creating a table type or local structure type?

      With Regards,

      Dip

  • avatar image
    Former Member
    Aug 16, 2017 at 03:49 PM
    -1

    Sir,

    Firstly,Thank you very much for answering.

    Now you mentioned "vector table" in the last of your answer but I never mentioned 'vector table". What I stated was "VectorTab" in my 3rd doubt in the example -

    TYPES VectorTab TYPE SORTED TABLE OF I WITH UNIQUE KEY TABLE LINE.

    I already clearly mentioned "VectorTab" according to the author of the book from where I read that example iis simply a "table type" with that name being created(it can be any name other than VectorTab like iTab,inttab etc etc so just ignore that name). So I feel you didn't fully understood my question. And you also skipped many of my questions like -

    1)What is the difference between an "Internal table object" and "internal table type"?

    2)What is the difference between Syntax 1 and Syntax 2 that I mentioned in my first question?

    3) My 3rd doubt regarding this following syntax -

    DATA : <itab> Type Table of <any_name >

    When is the above syntax used? What is the difference between these & earlier 2 syntax? Can this "any_name" object be any of the following -

    a)structure / (b)database table/transparent table / (c)local structure / d)predefined types like I,C,N,P (Int,Char,Numeric or Packed) ??

    4)Last another of my main confusions is -

    Are "local structure type" & "local table type" one & same thing?Because as far as I understand I can create a table type both in DDIC (using Tcode SE11) as well as in ABAP Editor(SE38) using the syntax TYPES as mentioned in Syntax 2 in my original post. In this context,does it mean that syntax 2 is creating a table type or local structure type?

    So Sir, I'm sorry to say but your answer can't be marked yet as an "answer" till you answer all my questions or I get a satisfactory answer to all my questions.

    Thanks & Regards

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 16, 2017 at 03:01 PM

    Hello,

    In abap several statements can be followed by ':' to allow you to write this statement only once, and then write several lines (to clarify the code as you could write all in the same line). So :

    TYPES : begin of MyType,
    field1,
    end of MyType. 
    * or
    TYPES : begin of MyType, field1, end of MyType.
    * are equivalent to :
    TYPES begin of MyType.
    TYPES field1.
    TYPES end of MyType.

    That said, TYPES statement is to create a local type (data element/structure/table/...). TYPE statement is..not a statement, just a keyword you used when you have to detailed the type of a parameter. We use TYPE keyword everywhere ([...] parameter TYPE type [...]), in a lot of different statements.

    If a type doesn't exist in DDIC (see transaction SE11), you can create it locally in your code using TYPES statement. Typically when you want few fields from a standard table : you don't need all of them so you can optimize your code creating a local type (using TYPES) containing that fields (and create a DATA using type).

    As you begin, consider there is no differences between TYPES from DDIC or locally defined. Just that DDIC centralize definitions so if your type has to be used by several programs, FM, class,.. you have to create it in DDIC (using SE11). That way if you have to change it (data element/structure/table/...) every programs using it will be updated. Just keep in mind that only useful types (data element/domain/structure/table) should be created via SE11 (and never in double if for same purpose). Or you quickly will not be able to determine which one to pick.

    You can locally create a structured data (single line or table) without using TYPES before. You should not do it yourself as it's obsolete. But you can find it in some programs. Syntax is the same :

    DATA : begin of MyDataTypedLine,
    field1,
    end of MyDataTypedLine.
    
    DATA : begin of MyDataTypedTable occurs 0,
    field1,
    end of MyDataTypedTable.

    Note that using DATA + OCCURS create a table with header line. This is bad and obsolete. Don't do it.

    Never heard of "vector table" in abap but I guess it refers to tables containing only 1 field. In this case you are not obliged to name the field, each line being typed as the initial field but without name. It's an obsolete things too, you should not use it anymore.

    It seems your book is too old now, you should purchase a far more recent one. Don't put your first effort on old stuff ;)

    Best regards

    Bertrand

    Add comment
    10|10000 characters needed characters exceeded

    • Hello,

      I don't know what an "Internal table object" is. If you mean "internal table data" then... no offense but if you don't know the difference between a data and a type then you are probably not ready to create ABAP reports. Because ABAP is not just a language, it's an old one with a lot of obsolete statements (still working) and it evolves in a very complex environment. Don't start programming with ABAP if you are alone with books. For your sanity, just don't.

      You can't learn how to program from books/sites/videos only. If you want to learn ABAP then you have to create ABAP programs. And if you have access to an ABAP developer environment then you just have to hit "F1" key on any keyword from ABAP editor to learn all you need to start.

      If my answer is not enough for you, be sure nobody will detailed you more than me. You are just currently not at the right place for beginner courses.

      Best regards

      Bertrand