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

field text

Former Member
0 Likes
838

hi to all exprts,

my recuirment is that the extract field text from data base table.

suppose to extract lifnr from lfa1

instead of coming lifnr , vendor(field text) is coming.

how can i solve this issue.

thanks in advance and reward also.

Regard :

Deep

4 REPLIES 4
Read only

Former Member
0 Likes
755

Hi,

where exactly you want to display the field name??? tell me more clearly..

Regards,

Bharat.

Read only

Former Member
0 Likes
755

Hi Deep,

Check this Example.

DATA: ONR(7) TYPE C,

DATE TYPE D,

POSITION(3) TYPE N,

CUSTOMER(16) TYPE C,

PNR(5) TYPE N,

NAME(10) TYPE C,

UNITS TYPE I,

ORDERS TYPE I.

FIELD-GROUPS:

HEADER, ORDER, PRODUCT, DATE_FIRST.

INSERT ONR DATE POSITION INTO HEADER.

INSERT CUSTOMER INTO ORDER.

INSERT PNR NAME UNITS INTO PRODUCT.

INSERT DATE ONR POSITION INTO DATE_FIRST.

ONR = 'GF00012'. DATE = '19921224'.

POSITION = '000'. CUSTOMER = 'Good friend (2.)'.

EXTRACT ORDER.

ADD 1 TO POSITION.

PNR = '12345'. NAME = 'Screw'. UNITS = 100.

EXTRACT PRODUCT.

ADD 1 TO POSITION.

PNR = '23456'. NAME = 'Nail'. UNITS = 200.

EXTRACT PRODUCT.

ONR = 'MM00034'. DATE = '19920401'.

POSITION = '000'. CUSTOMER = 'Moneymaker'.

EXTRACT ORDER.

ADD 1 TO POSITION.

PNR = '23456'. NAME = 'Nail'. UNITS = 300.

EXTRACT PRODUCT.

ADD 1 TO POSITION.

PNR = '34567'. NAME = 'Hammer'. UNITS = 4.

EXTRACT PRODUCT.

ONR = 'GF00011'. DATE = '19921224'.

POSITION = '000'. CUSTOMER = 'Good friend (1.)'.

EXTRACT ORDER.

ADD 1 TO POSITION.

PNR = '34567'. NAME = 'Hammer'. UNITS = 5.

EXTRACT PRODUCT.

SORT BY DATE_FIRST.

LOOP.

AT ORDER.

WRITE: /, / DATE, ONR, POSITION,

CUSTOMER, 'ordered:'.

ENDAT.

AT PRODUCT.

WRITE: / DATE, ONR, POSITION,

PNR, NAME, UNITS.

ENDAT.

ENDLOOP.

This generates the following list:

01041992 MM00034 000 Moneymaker ordered:

01041992 MM00034 001 23456 Nail 300

01041992 MM00034 002 34567 Hammer 4

24121992 GF00011 000 Good friend (1.) ordered:

24121992 GF00011 001 34567 Hammer 5

24121992 GF00012 000 Good friend (2.) ordered:

24121992 GF00012 001 12345 Screw 100

24121992 GF00012 002 23456 Nail 200

Example

Binary and locale-specific sorting of a name list:

DATA: NAME(10) TYPE C,

AGE TYPE I,

COUNTRY(3) TYPE C,

NR(5) TYPE N.

FIELD-GROUPS:

HEADER, PERSON.

INSERT NAME COUNTRY INTO HEADER.

INSERT NAME COUNTRY AGE INTO PERSON.

NAME = 'Muller'. AGE = 22. COUNTRY = 'USA'.

EXTRACT PERSON.

NAME = 'Moller'. AGE = 25. COUNTRY = 'FRG'.

EXTRACT PERSON.

NAME = 'Möller'. AGE = 22. COUNTRY = 'USA'.

EXTRACT PERSON.

NAME = 'Miller'. AGE = 23. COUNTRY = 'USA'.

EXTRACT PERSON.

SORT BY NAME.

LOOP.

WRITE: / NAME, AGE, COUNTRY.

ENDLOOP.

This generates the following binary sorted list:

Miller 23 USA

Moller 25 FRG

Muller 22 USA

Möller 22 USA

If, for example, you apply German sort rules where the umlaut comes directly after the letter 'o' in the sort, the data record beginning with 'Möller' would not be in the right place in this sequence. It should come second.

Provided a German-language locale is set (e.g. sorting is according to official German grammatical rules, see also SET LOCALE), you can sort the names according to German rules as follows:

SORT BY NAME AS TEXT.

This produces the following output:

Miller 23 USA

Moller 25 FRG

Möller 22 USA

Muller 22 USA

Addition 5

... STABLE

Effect

The sort is stable, that is, the relative order of entries that have the same SORT key is not changed in the sort.

Unlike in additions 2 to 4, you cannot specify this addition directly following a sort field.

Notes

General:

The number of sort fields is restricted to 50.

The sort process is only stable when you use the STABLE option. Otherwise, a predefined sequence of fields used to sort a list is not usually retained.

Any field symbol after the BY that is not assigned is ignored. If a field symbol is assigned, but does not point to the field group HEADER, a runtime error results.

The SORT statement sorts fields with the contents HEX 00 before all other fields, regardless of whether you sort in ascending or descending order. When you work with logical databases, the system fills all of the fields of the work area for the current GET statement with the value HEX 00 at the end of a hierarchy level. If you specify a field list in the GET statement, any field not specified in the list is filled with HEX 00 during the GET event.

If you have to sort an extract dataset several times according to locale-specific rules ( AS TEXT), you are recommended to include an additional field in the sort key where you can explicitly store the data formatted appropriate to the locale with the CONVERT TEXT ... INTO SORTABLE CODE statement. If you perform a binary sort on this data, the original data is also implicitly sorted according to the locale.

Extracts larger than 500 KB are stored in the file system. You can define the directory where this file is held with the SAP profile parameter DIR_SORTTMP. By default, the SAP data directory (SAP profile parameter DIR_DATA) is used. Extracts stored in the file system are sorted physically. If the extract is larger than 8 MB, the system uses an external auxiliary file. You can specify the directory in which the system creates this file using the SAP profile parameter DIR_SORTTMP. The default directory is the SAP data directory (SAP profile parameter DIR_DATA).

Notes

Performance:

The runtime required to sort an extract dataset increases with the number of entries and the length of the sort key.

The runtime increases if you use a stable sort.

Physical sorting decreases the runtime required for subsequent sequential processing of the dataset.

Reward if useful.

Regards,

Chitra

Read only

Former Member
0 Likes
755

Hi Deep,

Check the below code..

DATA: v_table LIKE dd03l-tabname,

v_field LIKE dd03l-fieldname,

v_label TYPE string.

PARAMETERS: p_tabfld(60).

START-OF-SELECTION.

IF p_tabfld CA '-'.

SPLIT p_tabfld AT '-' INTO v_table v_field.

ELSE.

WRITE:/ 'Enter value in the format table-field'.

ENDIF.

CHECK v_table IS NOT INITIAL AND

v_field IS NOT INITIAL.

CALL FUNCTION 'DDIF_FIELDLABEL_GET'

EXPORTING

tabname = v_table

fieldname = v_field

langu = sy-langu

  • LFIELDNAME = ' '

IMPORTING

label = v_label

EXCEPTIONS

not_found = 1

internal_error = 2

OTHERS = 3

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ELSE.

WRITE:/ v_label.

ENDIF.

Thanks & Regards

ilesh 24x7

Read only

Former Member
0 Likes
755

Since internal tables have fixed line structures, they are not suited to handle data sets with varying structures. Instead, you can use extract datasets for this purpose.

An extract is a sequential dataset in the memory area of the program. You can only address the entries in the dataset within a special loop. The index or key access permitted with internal tables is not allowed. You may only create one extract in any ABAP program. The size of an extract dataset is, in principle, unlimited. Extracts larger than 500KB are stored in operating system files. The practical size of an extract is up to 2GB, as long as there is enough space in the filesystem.

An extract dataset consists of a sequence of records of a pre-defined structure. However, the structure need not be identical for all records. In one extract dataset, you can store records of different length and structure one after the other. You need not create an individual dataset for each different structure you want to store. This fact reduces the maintenance effort considerably.

In contrast to internal tables, the system partly compresses extract datasets when storing them. This reduces the storage space required. In addition, you need not specify the structure of an extract dataset at the beginning of the program, but you can determine it dynamically during the flow of the program.

You can use control level processing with extracts just as you can with internal tables. The internal administration for extract datasets is optimized so that it is quicker to use an extract for control level processing than an internal table.

Procedure for creating an extract:

Define the record types that you want to use in your extract by declaring them as field groups. The structure is defined by including fields in each field group.

Defining an Extract

Fill the extract line by line by extracting the required data.

Filling an Extract with Data

Once you have filled the extract, you can sort it and process it in a loop. At this stage, you can no longer change the contents of the extract.

Processing Extracts

Defining an Extract

To define an extract, you must first declare the individual records and then define their structure.

Declaring Extract Records as Field Groups

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.

Defining the Structure of a Field Group

To define the structure of a record, use the following statement to add the required fields to a field group:

INSERT <f1>... <f n> INTO <fg>.

This statement defines the fields of field group <fg>. Before you can assign fields to a field group, you must define the field group <fg> using the FIELD-GROUPS statement. The fields in the field group must be global data objects in the ABAP program. You cannot assign a local data object defined in a procedure to a field group.

The INSERT statement, just as the FIELD-GROUPS statement, neither reserves storage space nor transfers values. You use the INSERT statement to create pointers to the fields <f i > in the field group <fg>, thus defining the structures of the extract records.

When you run the program, you can assign fields to a field group up to the point when you use this field group for the first time to fill an extract record. From this point on, the structure of the record is fixed and may no longer be changed. In short, as long as you have not used a field group yet, you can still extend it dynamically.

The special field group HEADER is part of every extract record. Consequently, you may not change HEADER once you have filled the first extract record.

A field may occur in several field groups; however, this means unnecessary data redundancy within the extract dataset. You do not need to define the structure of a field group explicitly with INSERT. If the field group HEADER is defined, an undefined field group consists implicitly of the fields in HEADER, otherwise, it is empty.

NODES: SPFLI, SFLIGHT.

FIELD-GROUPS: HEADER, FLIGHT_INFO, FLIGHT_DATE.

INSERT: SPFLI-CARRID SPFLI-CONNID SFLIGHT-FLDATE

INTO HEADER,

SPFLI-CITYFROM SPFLI-CITYTO

INTO FLIGHT_INFO.

The program is linked to the logical database F1S. The NODES statement declares the corresponding interface work areas.

There are three field groups. The INSERT statement assigns fields to two of the field groups.

Filling an Extract with Data

Once you have declared the possible record types as field groups and defined their structure, you can fill the extract dataset using the following statements:

EXTRACT <fg>.

When the first EXTRACT statement occurs in a program, the system creates the extract dataset and adds the first extract record to it. In each subsequent EXTRACT statement, the new extract record is added to the dataset.

Each extract record contains exactly those fields that are contained in the field group <fg>, plus the fields of the field group HEADER (if one exists). The fields from HEADER occur as a sort key at the beginning of the record. If you do not explicitly specify a field group <fg>, the

EXTRACT

statement is a shortened form of the statement

EXTRACT HEADER.

When you extract the data, the record is filled with the current values of the corresponding fields.

As soon as the system has processed the first EXTRACT statement for a field group <fg>, the structure of the corresponding extract record in the extract dataset is fixed. You can no longer insert new fields into the field groups <fg> and HEADER. If you try to modify one of the field groups afterwards and use it in another EXTRACT statement, a runtime error occurs.

By processing EXTRACT statements several times using different field groups, you fill the extract dataset with records of different length and structure. Since you can modify field groups dynamically up to their first usage in an EXTRACT statement, extract datasets provide the advantage that you need not determine the structure at the beginning of the program.

Assume the following program is linked to the logical database F1S.

REPORT demo_extract_extract.

NODES: spfli, sflight.

FIELD-GROUPS: header, flight_info, flight_date.

INSERT: spfli-carrid spfli-connid sflight-fldate

INTO header,

spfli-cityfrom spfli-cityto

INTO flight_info.

START-OF-SELECTION.

GET spfli.

EXTRACT flight_info.

GET sflight.

EXTRACT flight_date.

There are three field groups. The INSERT statement assigns fields to two of the field groups. During the GET events, the system fills the extract dataset with two different record types. The records of the field group FLIGHT_INFO consist of five fields: SPFLI-CARRID, SPFLI-CONNID, SFLIGHT-FLDATE, SPFLI-CITYFROM, and SPFLI-CITYTO. The first three fields belong to the prefixed field group HEADER. The records of the field group FLIGHT_DATE consist only of the three fields of field group HEADER.