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

Hi

Former Member
0 Likes
949

Hi,

In this program what does the function of types, structure and Internal table. Plz explain.

REPORT ZBDC_TAB1. .

<b>TYPES:

BEGIN OF TY_SOURCE,

KUNNR(10) TYPE C,

LAND1(2) TYPE C,

NAME(30) TYPE C,

ORT01(30) TYPE C,

TELF1(10) TYPE C,

END OF TY_SOURCE.

DATA:

ST_SOURCE TYPE TY_SOURCE,

IT_SOURCE TYPE TABLE OF TY_SOURCE,

ST_BDCDATA TYPE BDCDATA,

IT_BDCDATA TYPE TABLE OF BDCDATA.</b>

START-OF-SELECTION.

PERFORM UPLOAD.

LOOP AT IT_SOURCE INTO ST_SOURCE.

PERFORM MAPPING.

CALL TRANSCATION 'ZMP_TAB1_TC'

USING IT_BDCDATA.

ENDLOOP.

&----


*& Form UPLOAD

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM UPLOAD .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'c:\textcustomer.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = ' '

HEADER_LENGTH = 0

READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = it_source

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " UPLOAD

&----


*& Form MAPPING

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM MAPPING .

REFRESH IT_BDCDATA.

ST_BDCDATA-PROGRAM = 'ZMP_TAB1'.

ST_BDCDATA-DYNPRO = '9001'.

ST_BDCDATA-DYNBEGIN = ' '.

ST_BDCDATA-FNAM = KNA1-KUNNR.

ST_BDCDATA-FVAL = ST_SOURCE-KUNNR.

APPEND ST_BDCDATA TO IT_BDCDATA.

ENDFORM. " MAPPING

1 ACCEPTED SOLUTION
Read only

gopi_narendra
Active Contributor
0 Likes
900

TYPES: BEGIN OF TY_SOURCE, " Defining a structure with the following fields
KUNNR(10) TYPE C,
LAND1(2) TYPE C,
NAME(30) TYPE C,
ORT01(30) TYPE C,
TELF1(10) TYPE C,
END OF TY_SOURCE.

DATA: IT_SOURCE TYPE TABLE OF TY_SOURCE, " internal table IT_SOURCE declaration of type TY_SOURCE
" Can contain data ie number of records in the format of TY_SOURCE
ST_SOURCE TYPE TY_SOURCE. " Work Area ST_SOURCE declaration of type TY_SOURCE 
" which holds the same structure as of TY_SOURCE, contains only one record

Regards

Gopi

10 REPLIES 10
Read only

Former Member
0 Likes
900

Hi,

REPORT ZBDC_TAB1. .

TYPES:

BEGIN OF TY_SOURCE,

KUNNR(10) TYPE C,

LAND1(2) TYPE C,

NAME(30) TYPE C,

ORT01(30) TYPE C,

TELF1(10) TYPE C,

END OF TY_SOURCE.

*here types indicates the structure for your program

DATA:

ST_SOURCE TYPE TY_SOURCE,

IT_SOURCE TYPE TABLE OF TY_SOURCE,

ST_BDCDATA TYPE BDCDATA,

IT_BDCDATA TYPE TABLE OF BDCDATA.

*IT_SOURCE is the internal table without header line.

*TY_SOURCE is an work area for your program.

*IT_BDCDATA is another internal table which stores the BDCDATA which is retrieved from the table.

-


TYPES:

Syntax Forms

Use Predefined Types

1. TYPES { {dtype[(len)] TYPE abap_type [DECIMALS dec]}

| {dtype TYPE abap_type [LENGTH len] [DECIMALS dec]} }.

Refer to Existing Types

2. TYPES dtype { {TYPE [LINE OF] type}

| {LIKE [LINE OF] dobj} }.

Reference Types

3. TYPES dtype { {TYPE REF TO type}

| {LIKE REF TO dobj} }.

Structured Types

4. TYPES BEGIN OF struc_type.

...

{TYPES dtype ...} | {INCLUDE {TYPE|STRUCTURE} ...}.

...

TYPES END OF struc_type.

Table Types

5. TYPES dtype { {TYPE tabkind OF [REF TO] type}

| {LIKE tabkind OF dobj} }

[WITH key] [INITIAL SIZE n].

Ranges Table Types

6. TYPES dtype {TYPE RANGE OF type}|{LIKE RANGE OF dobj}

[INITIAL SIZE n].

Effect

The TYPES statement defines either an independent data type dtype or a structured data type struc_type. The naming conventions apply to the names dtype and struc_type. The defined data type can be viewed within the current context from this position.

Any data type dtype is either defined with the addition TYPE and a type, or with the addition LIKE and a data object. The syntax allows you to define elementary data types, reference types, structured types, and table types.

For the definition of a structured type struc_type, any type definitions of two TYPES statements are included with the additions BEGIN OF and END OF; a structured data type struc_type is defined here, which contains the included data types as components struc_type-dtype. The structure definitions can be nested.

Note

Outside of ABAP Objects, you can use the addition LIKE to refer to the properties of data objects as well as the flat structures, database tables, or Views of the ABAP Dictionary.

-


STRUCTURE.

Syntax

TYPES BEGIN OF struc_type.

...

{TYPES dtype ...} | {INCLUDE {TYPE|STRUCTURE} ...}.

...

TYPES END OF struc_type.

Effect:

A structured type struc_type is started by a TYPES statement with the addition BEGIN OF and must be ended with a TYPES statement with the addition END OF.

Between these two TYPES statements, there can be any number of TYPES statements, in particular additional closed structure definitions, and the statements INCLUDE TYPE and INCLUDE STRUCTURE. A structured type cannot be created without at least one component.

The TYPES statements within the statements with BEGIN OF and END OF define components of the structured type struc_type. If a component is a structured type or a new structured type is defined within a structure using BEGIN OF and END OF, this results in substructures. A structure with substructures is known as a nested structure.

The statement INCLUDE defines components of the structured type struc_type by copying the components of another structured type or an existing structure on the same level.

The components of a structured type are addressed using the name struc_type and the name of the component, separated by the structure component selector (-).

Example:

In this example, two structured types street_type and address_type are defined. address_type contains structured types as components. The definition of zipcode_type shows access to substructures.

TYPES: BEGIN OF street_type,

name TYPE c LENGTH 40,

no TYPE c LENGTH 4,

END OF street_type.

TYPES: BEGIN OF address_type,

name TYPE c LENGTH 30,

street TYPE street_type,

BEGIN OF city,

zipcode TYPE n LENGTH 5,

name TYPE c LENGTH 40,

END OF city,

END OF address_type.

TYPES zipcode_type TYPE address_type-city-zipcode.

-


INTERNAL TABLE

Syntax

DATA itab { {TYPE tabkind OF [REF TO] type}

| {LIKE tabkind OF dobj} }

[WITH key] [INITIAL SIZE n]

[WITH HEADER LINE]

[VALUE IS INITIAL]

[READ-ONLY].

Addition:

... WITH HEADER LINE

Effect

This statement defines an internal table. The definition of the row type, table kind tabkind and initial memory size INITIAL SIZE exactly corresponds to the definition of table types in section TYPES - TABLE OF, except that you cannot use the generic types ANY TABLE and INDEX TABLE. Use DATA to generate a bound table type with these additions.

The syntax for defining the table key key is also the same as for defining table types. In contrast to the definition of table types, an internal table as a data object cannot have a generic table key. This results in a slightly different semantics when you omit the table key specification in the DATA statement or when you do not specify the uniqueness using UNIQUE or NON-UNIQUE:

If for standard tables you specify no key, the table key is automatically determined as a non-unique standard key. A key specified without explicit uniqueness is implicitly enhanced with the addition NON-UNIQUE KEY. You cannot specify addition UNIQUE KEY.

For sorted tables, you must specify the key fully; both additions UNIQUE KEY or NON-UNIQUE KEY are allowed.

For hashed tables, you must specify the key fully; only addition UNIQUE KEY is allowed.

When defining internal tables before release 6.40, you could not specify a start value with addition VALUE. As of release 6.40, you can specify IS INITIAL as a start value.

Notes

When creating an internal table as a data object, only the administration entry for an internal table is generated. The actual table rows are not inserted until runtime. Under Obsolete Declarations, obsolete declaration forms for standard tables and special tables are described.

Example

Declaration of an internal table. The row type corresponds to the structure of database table SPFLI. For the table key, two key fields are defined. The other statements show how to fill the table with rows from database table SPFLI and how to read a row.

DATA: spfli_tab TYPE HASHED TABLE OF spfli

WITH UNIQUE KEY carrid connid,

spfli_wa LIKE LINE OF spfli_tab.

SELECT *

FROM spfli

INTO TABLE spfli_tab

WHERE carrid = 'LH'.

READ TABLE spfli_tab

WITH TABLE KEY carrid = 'LH' connid = '0400'

INTO spfli_wa.

...

Addition

... WITH HEADER LINE

Effect

Apart from the internal table, this addition, which is not allowed in classes, declares another data object, the header line, which has exactly the same name as the internal table and has the row type of the internal table as the data type.

If at an operand position of an ABAP statement, you specify the name of internal table itab, it depends on the statement whether the table body or the header line are used. As a rule, all table-specific statements such as SORT or LOOP use the internal table, while all other statements use the header line. Exceptions are - among others - the statements IMPORT andEXPORT.

To address the table body instead of the header line in a statement, you can append [] to the name (or a field symbol or dereferenced data reference):

... itab[] ...

For internal tables without header line, the table body is always used. An internal table with a header line can not be a component of a structure or a row of another internal table.

Note

These statements for processing individual table rows have short forms that implicitly use the header line as work area. These short forms are allowed only outside of ABAP Objects.

******please reward points if the information is helpful to you*********

Read only

former_member189059
Active Contributor
0 Likes
900

TYPES: is used as a reference for another variable / internal table

it is normally used when you have two tables of the same 'type'

to prevent declaring the same thing twice, you declare on TYPE and then just say that the other tables are of that TYPE

for eg: you have defined a TYPE 'TY_SOURCE'

so now for declaring your workarea ST_SOURCE and your internal table IT_SOURCE, you just have to declare them of that TYPE

there are some standard types available as well which you can use such as BDCDATA. It is a standard SAP type

Read only

gopi_narendra
Active Contributor
0 Likes
901

TYPES: BEGIN OF TY_SOURCE, " Defining a structure with the following fields
KUNNR(10) TYPE C,
LAND1(2) TYPE C,
NAME(30) TYPE C,
ORT01(30) TYPE C,
TELF1(10) TYPE C,
END OF TY_SOURCE.

DATA: IT_SOURCE TYPE TABLE OF TY_SOURCE, " internal table IT_SOURCE declaration of type TY_SOURCE
" Can contain data ie number of records in the format of TY_SOURCE
ST_SOURCE TYPE TY_SOURCE. " Work Area ST_SOURCE declaration of type TY_SOURCE 
" which holds the same structure as of TY_SOURCE, contains only one record

Regards

Gopi

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
900

Hi,

You have used TYPES to create a local type.

And you have created a workarea using strcutre BDCDATA and an internal table of the same type.

<b>BDCDATA is the type you need to use when you want to pass data to a Transaction which is called using CALL TRANSACTION.</b>

Check the F1 help for CALL TRANSACTION.


START-OF-SELECTION.
PERFORM UPLOAD.
LOOP AT IT_SOURCE INTO ST_SOURCE.
PERFORM MAPPING.
CALL TRANSCATION 'ZMP_TAB1_TC' " Check this line of your code
USING IT_BDCDATA.
ENDLOOP

Regards,

Sesh

Read only

Former Member
0 Likes
900

Syntax

TYPES BEGIN OF struc_type.

...

{TYPES dtype ...} | {INCLUDE {TYPE|STRUCTURE} ...}.

...

TYPES END OF struc_type.

Effect:

<b>A structured type struc_type is started by a TYPES statement with the addition BEGIN OF and must be ended with a TYPES statement with the addition END OF. </b>

STRUCTURE: This helps you to define a structure of a Particular type(defined by TYPES).

INT TABLE: This stores the content in the format defined in the Structure.

Regards,

Pavan

Read only

former_member189059
Active Contributor
0 Likes
900

See these two statements

ST_SOURCE TYPE TY_SOURCE,

IT_SOURCE TYPE TABLE OF TY_SOURCE,

in the first case, you have declared a structure of type TY_SOURCE

in the second case, since you used the words TABLE OF, it becomes an internal table of the type TY_SOURCE

a structure is a single one dimensional row whereas a table is made up of rows and columns

Read only

Former Member
0 Likes
900

Hi

If i understood you right...

Types uses you to define structure and structure to define itab to wich you transfer file textcustomer.txt from C drive... so in itab all contenent of file...

Regards

Yossi

Read only

Former Member
0 Likes
900

Hi ram

The TYPES statement creates a structure TY_SOURCE as defined. In the next line when we say DATA : ST_SOURCE type line . An internal table ST_SOURCE is created with the structure of TY_SOURCE .

Read only

Neslinn
Participant
0 Likes
900

Hi ,

Structure

A structure forms the basic framework of the axes in a table (rows or columns). It consists of structural components. We differentiate between key figure structures and characteristic structures.

TYPES:

BEGIN OF TY_SOURCE,

KUNNR(10) TYPE C,

LAND1(2) TYPE C,

NAME(30) TYPE C,

ORT01(30) TYPE C,

TELF1(10) TYPE C,

END OF TY_SOURCE.

Internal Tables:

Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data objects, they save the programmer the task of dynamic memory management in his or her programs. You should use internal tables whenever you want to process a dataset with a fixed structure within a program. A particularly important use for internal tables is for storing and formatting data from a database table within a program. They are also a good way of including very complicated data structures in an ABAP program.

DATA:

ST_SOURCE TYPE TY_SOURCE,

IT_SOURCE TYPE TABLE OF TY_SOURCE,

ST_BDCDATA TYPE BDCDATA,

IT_BDCDATA TYPE TABLE OF BDCDATA.

These structures and ITAB are used for the FIeld catalogue creatiom in u r pgm.

Reward point if helpfull.

Neslin.

Read only

Former Member
0 Likes
900

Hi Ram,

Like Internal table you define a structure using TYPES statement

Begin of ty_source,

---

---

End of ty_source

ST_SOURCE TYPE TY_SOURCE

here you declare ST_SOURCE to be of structure TY_SOURCE

Regards

Arun