Skip to Content
author's profile photo Former Member
Former Member

Advantage of Structure?

Hi

What is the advantage of structures? How do you use them in the ABAP programs?

Thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2006 at 03:20 PM

    Hi,

    structures and tables are used in ABAP OO. In ABAP/4 you don´t necessarily have to use a structure (tables is enough).

    In ABAP/4 you declare a table with a header line and then you can work with for saving the records in it.

    data: mytable like table of mara with header line.

    In ABAP OO you need obligatorily a table without a header and a structure, which substitutes the header of the table.

    Data: mytable type table of mara,

    mystruc type mara.

    Considering that in ABAP OO you need 2 objects, that means double work. One reason, why I hate ABAP OO !!

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Jorge

      One reason why we should embrace ABAP-OO is that it is no longer allowed to use itab's with a header line.

      Maintaining programs containing itab's with header lines is a nightmare for me:

      - The very same variable can have two completely different meanings.

      - If the header line is filled and the coding is using these data is this on purpose or by accident because the developer had forgotten to initialize the header line somewhere earlier?

      -

      CLEAR itab.

      or

      REFRESH itab.

      or both??? What has been initialized, the itab body, the header line or both?

      In my opinion, using itab's with header lines opens the floodgates for misunderstandings, and thereby, unnecessary program errors.

      Finally, ABAP-OO is not about being forced by the more strict syntax check.

      <b>ABAP-OO is about robustness, maintainability and re-usability of our coding.</b>

      Regards

      Uwe

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2006 at 03:21 PM

    Hi Subhash,

    Structure contains several fields.

    when we declare tables in programs, instead of writing all the field names..we can say include structure

    and we can create a work area of structure type and can use it several times in case we use different tables of same types.

    Moreover while using object oriented programming where tables with header lines are not allowed we use workareas(structure types)

    Regards,

    Vidya

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2006 at 03:22 PM

    Hi subhash,

    the advantage is, that it the same for all

    users and you use it by

    data: begin of ...

    ...

    include structure name.

    ...

    data: end of ...

    or in defenition

    data test like name-test.

    ...

    You have to define it 1 time and not allways in your Report.

    Regards, Dieter

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2006 at 03:22 PM

    Structures allow you to re-use the data layout across programs.

    Saves on coding time and human error when coding.

    Ex. Create a structure and then use it in DATA statement in numerous programs:

    DATA: MyLocalStruct type Z_My_GLOBAL_STRUCT.

    All progs can declare data variables using Z_My_GLOBAL_STRUCT.

    This makes it re-usable and faster to code.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Additionally... if you add a field to Z_My_GLOBAL_STRUCT, all progs that reference this STRUCTURE will AUTOMATICALLY get the new field... without ANY code changes !!!

      Very nice.

      Don't forget points for helpful answers.

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2006 at 03:23 PM

    hi,

    A Structure is similar to a Table that do not have any contents. It is like Table or View without any records.

    The basic difference between Structure and the Table is that the Structure does not exist at the underlying data base level. Structure exists as Definition in the Dictionary.

    we can include or append these structures to the tables.

    Regards,

    Sailaja.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2006 at 03:25 PM

    Hi Subash,

    Look at structure description from SAP.

    =======================================================

    A structure (structured type) consists of components (fields) whose types are defined.

    A component can have an elementary type, a structured type, a table type or a reference type.

    Structures are used especially to define the data at the interface of module pools and screens and to define the types of function module parameters.

    Structures that are used more than once can be changed centrally because they were defined centrall. The active ABAP Dictionary makes this change at all relevant locations. ABAP programs or screen templates that use a structure are automatically adjusted when the structure changes.

    =======================================================

    Compared to database tables, structures doesn't have any key fields. Structures represent one single line and when you define the structure in your program as

    data: begin of itab occurs 0.

    include structure ztest.

    data: end of itab.

    it creates a internal table itab with the records of ztest structure .. structure cannot hold data like database table..

    hope this gives you some idea.

    Regards,

    Vivek

    PS: Award points if helpful

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 17, 2006 at 09:13 PM

    Hello Subhash

    Think about the following (quite reasonable) situation: you have a SAP db table for some kind of business object with many fields of quite different types. Now SAP wants to give developers access to this business object by means of BAPIs but wants to hide the internal complexity of the business object.

    In order to simplify external use of BAPIs their interfaces are kept simple (in terms of data types). Quite often you will see in the coding of BAPIs at the beginning a mapping of data structure from external to internal types and at the end vice versa.

    You will hardly find any DB table (for business objects) in the interface of BAPIs.

    Instead of defining structures in the DDIC you could define them within you applications as program-specific types. However, as soon as I see that I could use this structure in several (different) places I will define it in the DDIC.

    For many of my ALV lists I need specific structures (but no DB tables because I don't want to store any data). Simultaneously to the structures I define the corresponding table type because I use exclusively the ABAP-OO ALV lists.

    In dynpros displaying data of business objects very often structures are used for typing the dynpro fields and not the underlying DB table for the business object. Why? Basically, this is some kind of uncoupling the model (= db table) from the view (= dynpro).

    I hope I could give you some hints why we need structures.

    Regards

    Uwe

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 18, 2011 at 07:23 AM

    Hi,

    1 .Using a structure user can add fields to the existing SAP database tables. Using .INCLUDE and .APPEND statements structures can be added to the database tables.

    2. Creating structures with in a structure is also possible.

    Regards,

    Chitwanjit

    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.