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

Questions

Former Member
0 Likes
531

Hi all,

Can anybody clear my doubts?

1. Can we define header and footer in Hierarchical ALV and if yes than how?

2. What is difference between type and like?

3. What is difference between field group and field symbol?

4. What is Nested Internal table? Can anybody clear it with example?

Thanks in advance....

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
477

answer 2)

LIKE is used inorder to refer to a present object and to have the semantic definition of that object that is being refered to.

TYPE is used in declaring the object using an elementary data type or a data element which has the same semantic definition that is required.

It is good practice to use TYPE as much as possible when there is a possibility to avoid LIKE.

TYPE

You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.

LIKE

You use the LIKE addition, similarly to the TYPE addition , in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols.

it can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression.

You use LIKE to make the new object or type inherit the technical attributes of an existing data object.

The LIKE Addition:

You use the LIKE addition, similarly to the TYPE addition, in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The addition

LIKE <obj>

can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression

LINE OF <table-object>

In this case, the LIKE addition describes the line type of a table object that is visible at that point in the program.

You use LIKE to make the new object or type inherit the technical attributes of an existing data object.

The TYPE Addition:

You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.

Referring to Known Data Types You can use the addition

TYPE <type> to refer to any data type <type> that is already known at this point in the program. It can be used in any of the statements listed below. The expression <obj> is either the name of the data object or the expression

LINE OF <table-type> In this case, the TYPE addition describes the line type of a table type <table-type> that is visible at that point in the program.

answer 4):

Field symbols: are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field Groups:

A field group is a user-defined grouping of characteristics and basic key figures from the EC-EIS or EC-BP field catalog.

Use

The field catalog contains the fields that are used in the aspects. As the number of fields grows, the field catalog becomes very large and unclear. To simplify maintenance of the aspects, you can group fields in a field group. You can group the fields as you wish, for example, by subject area or responsibility area. A field may be included in several field groups.

When maintaining the data structure of an aspect, you can select the field group that contains the relevant characteristics and basic key figures. This way you limit the number of fields offered.

A field group combines several existing fields together under one name

like

FIELD-GROUPS: fg.

then you can use one insert statement to insert values in fields of field-group.

INSERT f1 f2 ... INTO fg.

Field symbols

If u have experience with 'C', then understand this to be similar to a pointer.

It is used to reference another variable dynamically. So this field symbol will simply point to some other variable. and this pointer can be changed at runtime.

FIELD-SYMBOLS <FS>.

DATA FIELD VALUE 'X'.

ASSIGN FIELD TO <FS>.

WRITE <FS>.

Field symbols: are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field Groups:

A field group is a user-defined grouping of characteristics and basic key figures from the EC-EIS or EC-BP field catalog.

Use

The field catalog contains the fields that are used in the aspects. As the number of fields grows, the field catalog becomes very large and unclear. To simplify maintenance of the aspects, you can group fields in a field group. You can group the fields as you wish, for example, by subject area or responsibility area. A field may be included in several field groups.

When maintaining the data structure of an aspect, you can select the field group that contains the relevant characteristics and basic key figures. This way you limit the number of fields offered.

2 REPLIES 2
Read only

Former Member
0 Likes
478

answer 2)

LIKE is used inorder to refer to a present object and to have the semantic definition of that object that is being refered to.

TYPE is used in declaring the object using an elementary data type or a data element which has the same semantic definition that is required.

It is good practice to use TYPE as much as possible when there is a possibility to avoid LIKE.

TYPE

You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.

LIKE

You use the LIKE addition, similarly to the TYPE addition , in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols.

it can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression.

You use LIKE to make the new object or type inherit the technical attributes of an existing data object.

The LIKE Addition:

You use the LIKE addition, similarly to the TYPE addition, in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The addition

LIKE <obj>

can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression

LINE OF <table-object>

In this case, the LIKE addition describes the line type of a table object that is visible at that point in the program.

You use LIKE to make the new object or type inherit the technical attributes of an existing data object.

The TYPE Addition:

You use the TYPE addition in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The TYPE addition can have various meanings depending on the syntax and context.

Referring to Known Data Types You can use the addition

TYPE <type> to refer to any data type <type> that is already known at this point in the program. It can be used in any of the statements listed below. The expression <obj> is either the name of the data object or the expression

LINE OF <table-type> In this case, the TYPE addition describes the line type of a table type <table-type> that is visible at that point in the program.

answer 4):

Field symbols: are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field Groups:

A field group is a user-defined grouping of characteristics and basic key figures from the EC-EIS or EC-BP field catalog.

Use

The field catalog contains the fields that are used in the aspects. As the number of fields grows, the field catalog becomes very large and unclear. To simplify maintenance of the aspects, you can group fields in a field group. You can group the fields as you wish, for example, by subject area or responsibility area. A field may be included in several field groups.

When maintaining the data structure of an aspect, you can select the field group that contains the relevant characteristics and basic key figures. This way you limit the number of fields offered.

A field group combines several existing fields together under one name

like

FIELD-GROUPS: fg.

then you can use one insert statement to insert values in fields of field-group.

INSERT f1 f2 ... INTO fg.

Field symbols

If u have experience with 'C', then understand this to be similar to a pointer.

It is used to reference another variable dynamically. So this field symbol will simply point to some other variable. and this pointer can be changed at runtime.

FIELD-SYMBOLS <FS>.

DATA FIELD VALUE 'X'.

ASSIGN FIELD TO <FS>.

WRITE <FS>.

Field symbols: are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.

Field Groups:

A field group is a user-defined grouping of characteristics and basic key figures from the EC-EIS or EC-BP field catalog.

Use

The field catalog contains the fields that are used in the aspects. As the number of fields grows, the field catalog becomes very large and unclear. To simplify maintenance of the aspects, you can group fields in a field group. You can group the fields as you wish, for example, by subject area or responsibility area. A field may be included in several field groups.

When maintaining the data structure of an aspect, you can select the field group that contains the relevant characteristics and basic key figures. This way you limit the number of fields offered.

Read only

Former Member
0 Likes
477

Hi,

1. Check the following link:

http://sap-img.com/abap/test-alv-display-with-header-footer.htm

4. <b>Formatting Data Using Nested Internal Tables</b>Assume the following program is linked to the logical database F1S.

REPORT DEMO.

DATA: SUM TYPE I, CNT TYPE I.

NODES: SPFLI, SFLIGHT, SBOOK.

DATA: BEGIN OF WA_SBOOK,

BOOKID TYPE SBOOK-BOOKID,

SMOKER TYPE SBOOK-SMOKER,

CLASS TYPE SBOOK-CLASS,

LUGGWEIGHT TYPE SBOOK-LUGGWEIGHT,

WUNIT TYPE SBOOK-WUNIT,

END OF WA_SBOOK.

DATA: BEGIN OF WA_SFLIGHT,

FLDATE TYPE SFLIGHT-FLDATE,

SBOOK LIKE TABLE OF WA_SBOOK,

END OF WA_SFLIGHT.

DATA: BEGIN OF WA_SPFLI,

CARRID TYPE SPFLI-CARRID,

CONNID TYPE SPFLI-CONNID,

CITYFROM TYPE SPFLI-CITYFROM,

CITYTO TYPE SPFLI-CITYTO,

SFLIGHT LIKE TABLE OF WA_SFLIGHT,

END OF WA_SPFLI.

DATA TAB_SPFLI LIKE TABLE OF WA_SPFLI.

START-OF-SELECTION.

GET SPFLI.

REFRESH WA_SPFLI-SFLIGHT.

GET SFLIGHT.

REFRESH WA_SFLIGHT-SBOOK.

GET SBOOK.

MOVE-CORRESPONDING SBOOK TO WA_SBOOK.

APPEND WA_SBOOK TO WA_SFLIGHT-SBOOK.

GET SFLIGHT LATE.

MOVE-CORRESPONDING SFLIGHT TO WA_SFLIGHT.

APPEND WA_SFLIGHT TO WA_SPFLI-SFLIGHT.

GET SPFLI LATE.

MOVE-CORRESPONDING SPFLI TO WA_SPFLI.

APPEND WA_SPFLI TO TAB_SPFLI.

END-OF-SELECTION.

SORT TAB_SPFLI BY CITYFROM CITYTO CONNID.

LOOP AT TAB_SPFLI INTO WA_SPFLI.

SKIP.

WRITE: / WA_SPFLI-CARRID,

WA_SPFLI-CONNID,

'from', (15) WA_SPFLI-CITYFROM,

'to', (15) WA_SPFLI-CITYTO.

ULINE.

SORT WA_SPFLI-SFLIGHT BY FLDATE.

LOOP AT WA_SPFLI-SFLIGHT INTO WA_SFLIGHT.

SKIP.

WRITE: / 'Date:', WA_SFLIGHT-FLDATE.

WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.

ULINE.

SORT WA_SFLIGHT-SBOOK BY CLASS SMOKER BOOKID.

SUM = 0.

CNT = 0.

LOOP AT WA_SFLIGHT-SBOOK INTO WA_SBOOK.

WRITE: / WA_SBOOK-BOOKID UNDER 'Book-ID',

WA_SBOOK-SMOKER UNDER 'Smoker',

WA_SBOOK-CLASS UNDER 'Class'.

SUM = SUM + WA_SBOOK-LUGGWEIGHT.

CNT = CNT + 1.

ENDLOOP.

ULINE.

WRITE: 'Number of bookings: ', (3) CNT,

/ 'Total luggage weight:',

(3) SUM, WA_SBOOK-WUNIT.

ENDLOOP.

ENDLOOP.

During the GET events, the system reads the data into the three-level

internal table SORT_SPFLI which contains the substructure SFLIGHT and its

substructure SBOOK. The sorting process takes place on the individual nesting

levels.

This way of programming does not require key relations between the internal tables

(no WHERE conditions), but it is more complex than using flat internal tables. And

the increased internal administration effort has a negative effect on the storage

space required as well as on the runtime.

3. <b>Field Group</b>

An extract dataset consists of a sequence of records. These records may have different structures. All records with the same structure form a record type. You must define each record type of an extract dataset as a field group, using the FIELD-GROUPS statement.

FIELD-GROUPS <fg>.

This statement defines a field group <fg>. A field group combines several fields under one name. For clarity, you should declare your field groups at the end of the declaration part of your program.

A field group does not reserve storage space for the fields, but contains pointers to existing fields. When filling the extract dataset with records, these pointers determine the contents of the stored records.

You can also define a special field group called HEADER:

FIELD-GROUPS HEADER.

This group is automatically placed before any other field groups when you fill the extract. This means that a record of a field group <fg> always contains the fields of the field group HEADER. When sorting the extract dataset, the system uses these fields as the default sort key.

<b>Field Symbols</b>

Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.

Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to a field symbol before you can address it in a program.

Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects.

All operations programmed with field symbols are applied to the field assigned to it. For example, a MOVE statement between two field symbols moves the contents of the field assigned to the first field symbol to the field assigned to the second field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before.

You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.

The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.

While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.

For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. However, since the MOVE statement also supports variable offset and length specifications, you should use it instead. The MOVE statement (with your own auxiliary variables if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve performance in some cases.

Regards,

Bhaskar