Application Development 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: 

Strucutre....

Former Member
0 Kudos
145

Hi all,

How to declare a structure in the prog n how to use it.

Thanks

Khan

1 ACCEPTED SOLUTION

Former Member
101

Hi,

  • with types

types: begin of t_struc,

matnr like mara-matnr,

matkl like mara-matkl,

end of t_struc.

*

data: struc1 type t_struc.

*

  • or like this

data: begin of struc,

matnr like mara-matnr,

matkl like mara-matkl,

end of struc.

*

select single * from mara where matnr = '000000000000000001'.

*

if sy-subrc = 0.

struc-matnr = mara-matnr.

struc-matkl = mara-matkl.

struc1-matnr = mara-matnr.

struc1-matkl = mara-matkl.

endif.

Regards, Dieter

8 REPLIES 8

Former Member
0 Kudos
101

hi..

u can declare a structure like this..

<b>DATA:BEGIN OF STRUCT,

A TYPE I,

B(20) TYPE C,

C TYPE I,

END OF STRUCT</b>.

u can use the structure to create <b>internal table</b>..and also u can use the structure as <b>work area..</b>

Reward points if useful

Regards

Ashu

Former Member
0 Kudos
101

Hi,

Simple Program to get an idea.

data: begin of str,

a,

end of str.

data: w type str.

w-a = 'B'.

Write w-a.

Output: B

Reward if useful!

Former Member
0 Kudos
101

Hi jareer,

i am really not aware of what you would like to see or achieve, but let me give u a sample declaration of what a structure could be.

A structure is nothing but a prototype of a single record of the internal table or a table.

Data : begin of stru,

matnr type matnr,

matkl type matkl,

end of stru.

This sample is a strucuture which can hold Material details. This is a structure which could be declared in a program. We can create structures outside program using the transaction SE11, but then those would be Global Structures.

<b>Rewards points if this helps,</b>

Kiran

Former Member
0 Kudos
101

Data: BEGIN OF name,

title(5) TYPE c,

first_name(10) TYPE c,

last_name(10) TYPE c,

END OF name.

name-title = 'Lord'.

name-first_name = 'Howard'.

name-last_name = 'Mac Duff'.

WRITE name-title .

WRITE name-first_name .

WRITE name-last_name .

Former Member
0 Kudos
101

Hello,


TYPES: BEGIN OF ty_tab1,
         f1 TYPE char5,
       END OF ty_tab1.


Data: it_tab1 TYPE STANDARD TABLE OF ty_tab1.

DATA: wa_tab TYPE ty_tab1.

CLEAR wa_tab.

wa_tab-f1 = '1ABC'.
APPEND wa_tab TO it_tab1.
CLEAR wa_tab.

wa_tab-f1 = '2DEF'.
APPEND wa_tab TO it_tab1.
CLEAR wa_tab.

wa_tab-f1 = '3GHI'.
APPEND wa_tab TO it_tab1.
CLEAR wa_tab.

LOOP AT it_tab1 INTO wa_tab.
  WRITE:/ wa_tab-f1.
ENDLOOP.

Regards,

Deepu.K

Former Member
0 Kudos
101

Structures are used to define any user-defined types in the ABAP Dictionary. A structure has components that can themselves be structured, that is they can obtain their type from a structure or a table type.

A structure (structured type) comprises components (fields). Types are defined for the components A component can refer to an elementary type (via a data element or by directly specifying the data type and length in the structure definition), another structure or a table type. A structure can therefore be nested to any depth.

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

The data for managing the addresses of persons can be represented as a nested structure PERSON. The structure comprises the components (structures) NAME and ADDRESS. The structure NAME comprises the components (data elements) FIRSTNAME and LASTNAME. The structure ADDRESS comprises the components (structures) STREET and TOWN. The structure STREET comprises the components (data elements) STREETNAME and HOUSENO. The structure TOWN comprises the components (data elements) ZIP and TOWNNAME.

The central definition of structures that are used more than once makes it possible for them to be changed centrally. The active ABAP Dictionary then makes this change wherever required. ABAP programs or screen templates that use a structure are automatically adjusted when the structure is changed (see Runtime Objects). This ensures the greatest possible consistency of the data definition, also for complex programs.

There are Flat, nested and deep structures. A flag structure only references elementary types. A nested structure references at least one further structure, but not a table type. A deep structure references at least one table type.

In a database table, you can only include flat structures as substructures.

Procedure

In the initial screen of the ABAP Dictionary, enter the structure name in field Data type and choose Create.

A dialog box appears in which you must select the type category.

Select Structure and choose .

The maintenance screen for structures appears.

Enter an explanatory short text in field Short text.

You can for example find the structure at a later time using this short text.

Carry out the following steps for all the components you want to include in the structure.

You can also include structures, tables or views instead of individual components. The procedure here is described in Inserting an Include.

Enter a name in column Components.

If you want to use the structure as an include in a transparent table at a later time, the component names may not be longer than 16 characters.

Enter the name of the type whose attributes should be used in the component in field Component name. You can enter any type (data element, structure or table type) here.

You can also add components by directly specifying the data type and length. Choose Built-in type. You can now enter values for fields DTyp, Length, Dec.places and Short description. With Component type you can switch back to the screen for entering references to existing types.

You can combine components with direct type definition and components that are defined by referencing an existing type as you like.

The reference field and reference table must be specified for components of type CURR (currency) and QUAN (quantity).

You can make these entries on the Currency/quantity fields tab page.

Now maintain the foreign keys of the structure.

Proceed as when maintaining the foreign keys of a table (see Creating Foreign Keys).

Save your entries once you have defined all the components of the structure.

You are asked to assign the structure a development class. You can change the development class later with Goto ® Change object directory entry.

Choose .

Result

The structure is now activated. The runtime object of the structure is created. At activation, a log is written; it can be displayed with Utilities ® Activation log. If errors occurred when the structure was activated, the activation log is automatically displayed.

Other Options

Create documentation: You can enter information about using the structure with Goto ® Documentation. This documentation is also output when the structure is printed.

Assign a search help: You can assign the structure a search help. This search help is offered on all the screen fields referring to this structure field when the input help (F4 help) is called (see Attaching Search Helps to Table Fields). Proceed as follows:

Choose Goto ® Search help.

In the next dialog box, enter the search help name and choose

The system automatically makes a proposal for the assignment of the search help parameters to structure fields. An attempt is made to assign a structure field with the same domain to a search help parameter. If there is no such field, the assignment is open. The assignment is displayed in a dialog box.

You can change the system proposal (except for the search field, that is the field to which the search help was assigned) by assigning a structure field with the same data type and same field length to a search help parameter.

Choose Copy.

Define the activation type: The activation type defines whether the structure can be activated directly from the ABAP Dictionary, or whether the runtime object of the structure must first be generated with a C program. It is only important to define an activation type for structures of the runtime environment. You can define the activation type with Extras ® Activation type.

rewards point if useful.....

regards...

Abhay singh

Former Member
102

Hi,

  • with types

types: begin of t_struc,

matnr like mara-matnr,

matkl like mara-matkl,

end of t_struc.

*

data: struc1 type t_struc.

*

  • or like this

data: begin of struc,

matnr like mara-matnr,

matkl like mara-matkl,

end of struc.

*

select single * from mara where matnr = '000000000000000001'.

*

if sy-subrc = 0.

struc-matnr = mara-matnr.

struc-matkl = mara-matkl.

struc1-matnr = mara-matnr.

struc1-matkl = mara-matkl.

endif.

Regards, Dieter

Former Member
0 Kudos
101

Hi,

problem solved??

Regards, Dieter