Application Development and Automation 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: 
Read only

syntax for structure definition

Former Member
0 Likes
6,992

Hi expert,

          I can't understand following syntax for structure t_str_reservationx. why using period for each line of this structure definition? and why use the second 'TYPES' before 'END OF'

TYPES:

BEGIN OF t_mark,

mark TYPE c,

END OF t_mark,

BEGIN OF t_str_reservationx.

INCLUDE STRUCTURE zptb00_hreservat.

INCLUDE TYPE t_mark.

TYPES:

END OF t_str_reservationx.

Many Thanks,

Andy

1 ACCEPTED SOLUTION
Read only

former_member220538
Active Participant
0 Likes
2,961

Hi,

Here there are two structures declared t_mark and t_str_reservationx.

The strucuture  t_str_reservationx contain  structure CAUFV, is be a standard one.ie declared globally.

The statement INCLUDE STRUCTURE CAUFV will include all the fields of the structure CAUFV in to the structure t_str_reservationx.

INCLUDE STRUCTURE  to include standard structure

INCLUDE TYPES to include the local structure.

Using this declaration the structure t_str_reservationx will contain all the fields of the structure CAUFV and the field mark.

Double click on CAUFV to view all the fields in that structure.

TYPES: BEGIN OF ty.

       INCLUDE STRUCTURE CAUFV.

TYPES: date TYPE d,

       END OF ty.

In the above example I have included a structure. We have to use period in the line above the INCLUDE statement and TYPES below the INCLUDE  this is how it is declared.

10 REPLIES 10
Read only

Arun_Prabhu_K
Active Contributor
0 Likes
2,961

Hello Bo Zhang.

     The code snippet which you had put is shortened form of

TYPES: BEGIN OF T_MARK,
           MARK
TYPE C.
TYPES: END OF T_MARK.
TYPES: BEGIN OF T_STR_RESERVATIONX.
          
INCLUDE STRUCTURE CAUFV.
          
INCLUDE TYPE T_MARK.
TYPES: END OF T_STR_RESERVATIONX.

Regarding the PERIOD part, it is standard ABAP syntax.

Regards.

Read only

0 Likes
2,961

Hi K.Arun,

      for structure t_mark, all statements are all ended with comma, but for structure t_str_reservationx, all statements are all ended with period. why there have such difference?

Many Thanks,

Read only

Former Member
0 Likes
2,961

Hi,

normally you can define a type structure by

TYPES: BEGIN OF t1,

     field1,

     field2,

     ...

     fieldn,

END OF t1.

But if you want to include a type or structure with INCLUDE TYPE or INCLUDE STRUCTURE the line before must be closed by a dot, and that is where 1st TYPES: is ending. The following fields or the end of type structure must complete the TYPES declaration:

TYPES: BEGIN OF t1,

     field1,

     field2,

     ...

     fieldn."<= closing dot here

INCLUDE STRUCTURE s1.  "<= INCLUDE must also be closed by a dot.

TYPES:"<= needed for completion of TYPES structure

     field m

     ...

     fieldz,

END OF t1.

Now the TYPES declaration is completed.

Regards,

Klaus

Read only

Former Member
0 Likes
2,961

HI,

When you define a structure rec (with DATA

or TYPES
), this statement copies the components of the structured data type

s to the structure rec.

Since, as of Release 3.0, you

can define nested data structures (i.e. structures with sub-structures), INCLUDE

STRUCTURE should no longer be used.

A data definition

DATA: BEGIN OF rec. INCLUDE STRUCTURE s. DATA: END OF rec.

is equivalent to

DATA rec LIKE s.

You are recommended to use the second formulation.

Even if the
structure rec to be defined contains additional components, instead
of

DATA: BEGIN OF rec, ... INCLUDE STRUCTURE s. DATA:   ... END OF rec.

you should use

DATA: BEGIN OF rec, ... rec LIKE s, ... END OF rec.

so that s can be referenced as a sub-structure of
rec.

Note

Although "INCLUDE STRUCTURE subRec." breaks up the
sub-structure s into its components, the alignment of s
is retained. This means that padding fields may be inserted before the first
and/or before the last component of s in rec.

Read only

Former Member
0 Likes
2,961

Hi,

INCLUDE
STRUCTURE

INCLUDE
STRUCTURE


Additions:
1. ... AS name1
2.
... AS name1 RENAMING WITH SUFFIX name2
Effect
You can use INCLUDE
STRUCTURE s.
" when you define a structure rec (using /SAPIrExtHelp/IWB_IMG.asp?_LOIO=348E72B66DF74873E10000009B38F9B8

DATA or /SAPIrExtHelp/IWB_IMG.asp?_LOIO=348E72B76DF74873E10000009B38F9B8
  • TYPES ) to include the componen of
    the structured data object s in the structure rec.



    Note
    Do not use the INCLUDE STRUCTURE any more for defining
    structures with reference to an existing structure. Instead, use one of the
    constructions listed below. You should now only use INCLUDE STRUCTURE
    with the AS additions to avoid using offset and length specifications
    with structures.

    Instead of

     DATA: BEGIN OF rec. 
    INCLUDE STRUCTURE s.
    DATA: END OF rec.
    Use

     DATA rec LIKE s. 

    Even if the structure rec that you want to define contains
    extra components, do not use

     DATA: BEGIN OF rec, 
    ...
    INCLUDE STRUCTURE s.
    DATA: ...
    END OF rec.
    Instead, use

     DATA: BEGIN OF rec, 
    ...
    rec LIKE s,
    ...
    END OF rec.
    You can then address s as a substructure of
    rec.


    Note

    Although "INCLUDE STRUCTURE s." expands the substructure
    s into its components, its
    alignment
    remains unchanged. This means that
    there may be extra fields inserted as padding before the first component or
    after the last component of s within rec.


    Effect

    The components included using INCLUDE STRUCTURE can be
    addressed as a unit under the group name name1.


    Group components are only visible if you address them explicitly by
    name. This applies, for example, to the following situations and
    statements:


    • Normal selection of components from a structure:
      rec-name1









    • ASSIGN (name) TO <fs>.

    • ASSIGN COMPONENT name OF STRUCTURE rec TO <fs>.

  • Group components nare not taken into account in the following
    statements:


    • MOVE-CORRESPONDING rec1 TO rec2.


    • ASSIGN COMPONENT index OF STRUCTURE rec TO <fs>.

    • Notes

  • Group names for includes in the ABAP Dictionary are treated in the same
    way as group names that you declare in programs using INCLUDE TYPE ...
    AS
    bzw. INCLUDE STRUCTURE ... AS.


    • You should only use group names with includes in conjunction with
      database tables to access a set of components symbolically as a substructure. In
      all other cases, you should use nested structures instead of includes or group
      names.


  • Effect
    The components included using INCLUDE STRUCTURE can be
    addressed as a unit under the group name name1 . They behave in the
    same way as described in addition 1. When you include the components of the
    structure s , the components are renamed by appending the name
    name2. This enables you to include the structure s more than
    once.

    http://help.sap.com/saphelp_banking463/helpdata/en/34/8e72b86df74873e10000009b38f9b8/frameset.htm

with regards ,

Juneed K Manha

Read only

Former Member
0 Likes
2,961

Hi,

In the above syntax you are actually including a structure inside a structure.
Its interesting why you need to know the definition.Its only a syntax to attach a structure to another structure.

Regards,

Alenlee MJ

Read only

Former Member
0 Likes
2,961

use of '':' after a statement makes it a chain statement and is used to avoid writing the keyword repeatedly.

e.g :

Normal :

     TYPES     BEGIN OF ABC.

     TYPES     X TYPE Y.

     TYPES     END OF ABC.

Chain :

     TYPES :     BEGIN OF ABC,

                        X TYPE Y,

                         END OF ABC.

Chain is just for programmers ease to avoid writing same keyword again and again. It is interpreted same as normal example given above by the compiler.

Notice the ',' and '.' used. A period '.' marks the end of a chain i.e you need to provide keywords (TYPES in this case ) after it for next statements.

A ',' comma indicates continuation of the chain and that the same keyword has to be used and thus its not needed to be written again.

The second TYPES used with END OF is not needed if the statement is a part of the TYPES chain. But if the previous statement is ended by a period "." then you need to specify the keyword (TYPES) to be used again.

e.g :

     TYPES     :     BEGIN OF ABC ,

                              INCLUDE STRUCTURE XYZ .

     see the above statement is ended by a period so it ends the chain and you will have to use the keyword in next statement, which will make it as

     TYPES     END OF ABC.

regards,

Ashish Rawat

Read only

former_member220538
Active Participant
0 Likes
2,962

Hi,

Here there are two structures declared t_mark and t_str_reservationx.

The strucuture  t_str_reservationx contain  structure CAUFV, is be a standard one.ie declared globally.

The statement INCLUDE STRUCTURE CAUFV will include all the fields of the structure CAUFV in to the structure t_str_reservationx.

INCLUDE STRUCTURE  to include standard structure

INCLUDE TYPES to include the local structure.

Using this declaration the structure t_str_reservationx will contain all the fields of the structure CAUFV and the field mark.

Double click on CAUFV to view all the fields in that structure.

TYPES: BEGIN OF ty.

       INCLUDE STRUCTURE CAUFV.

TYPES: date TYPE d,

       END OF ty.

In the above example I have included a structure. We have to use period in the line above the INCLUDE statement and TYPES below the INCLUDE  this is how it is declared.

Read only

Former Member
0 Likes
2,961

Hi

In your structure definition you are declaring two structure.

The first one is a normal one.

In the next structure definition  "t_str_reservationx"  you are including another structure( zptb00_hreservat) which is already defined using data(So using include structure).

And you are including t_mark as include type as the structure is defined as (Types and not data, else you would have used Include structure here too.)

The periods here represents that these structures have been included.It is merely a syntax only.

Regards

Read only

former_member9607
Active Participant
0 Likes
2,961

HI Bo Zhang,

It has used "Types - Begin Of" statement and shows the definition of struct_type. It is used to create structure type.

Syntax:

TYPES Begin of          struct_type.

          Types component_1...

          Types component_2 type struct_type Boxed.

          INCLUDE TYPE ...

          INCLUDE STRUCTURE...

TYPES End of            struct_type.

It is showing a TYPES statement with the addition of BEGIN OF and must finish with a TYPES statement with the addition END OF.

It can incorporate the following statements within this TYPES statements.

  •           Any TYPES statement ( closed structure definition )
  •           Definition of staticboxes using BOXED
  •           The statements INCLUDE TYPE and INCLUDE STRUCTURE

No structured types can be created that do not have at least one component.

Example:

TYPES:

BEGIN OF ty_standard,


   class  type char20,

   rollno type char20,

end of  ty_standard.

TYPES BEGIN OF ty_std.

   INCLUDE STRUCTURE Zname_118235.

   INCLUDE TYPE ty_standard.

TYPES END OF ty_std.


** Zname_118235 is the ABAP data dictionary structure.

For more details please see the link http://help.sap.com/abapdocu_731/en/abaptypes_struc.htm

Hope this will give you some idea.

Regards,

KK