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: 

hi all

Former Member
0 Kudos

What are strings?What are the main uses of strings in abap? any real time scenario or ex where we can use strings ? iam a new abaper as i said and new to programming itself so bare with my silly ones...

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello,

Strings - Fields with Variable Length

The elementary data type STRING is similar to data type C and refers to a variable-length string. Accordingly, the elementary data type XSTRING is similar to data type X and refers to a variable-length byte sequence.

In contrast to a C or X field, the length of a string is not static but variable and adjusts itself to the current field content at runtime. Dynamic memory management is used internally. Strings can have any length.

The initial value of a string is an empty string with length 0. A structure containing a string is seen as deep. A deep structure cannot be used like a C field. Strings can be displayed in the ABAP Debugger and used in the ABAP Dictionary.

It is not yet possible to use strings in screens or database tables. However, strings can be stored in database tables as clusters using EXPORT and transferred using IMPORT.

the current release it has not been possible to fully complete the implementation of strings. Especially the handling of blank characters at the end of a string has not been finalized for a number of ABAP statements.

For the highlighted argument positions of the following ABAP statements, blank characters at the end of strings are not taken into account. This may change in the next release. Therefore strings with blank characters at the end should not be used in these positions.

ASSIGN f TO <fs> TYPEtype

ASSIGN TABLE FIELD (f)

ASSIGN (f) TO <fs>

ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO <fs>

ASSIGN COMPONENTname OF STRUCTURE struc TO <fs>

ASSIGN LOCAL COPY OF (f) TO <fs>

CALL SELECTION-SCREEN scr USING SELECTION-SETset

CLOSE DATASETdsn

CREATE OBJECT ref TYPE (class)

CREATE DATA dref TYPE (type)

DELETE FROM dbtab WHERE ...

(applies toall strings in the WHERE clause)

EDITOR-CALL FOR REPORTprog

EDITOR-CALL FOR itab TITLEtext

GENERATE DYNPRO ... IDid

GENERATE REPORTprog

GENERATE SUBROUTINE POOL itab NAMEname

IMPORT DYNPRO ... IDid

MESSAGE xnnn WITHf1 ...f4

MESSAGE ID id TYPEmtype NUMBERn

NEW-PAGE PRINT ON ... (applies toall additions)

OPEN DATASET dsn ...

... TYPEc

... MESSAGEm

... FILTERf

PERFORM (form)

... IN PROGRAM (prog)

SET PF-STATUSpfstat

... EXCLUDINGf

... OF PROGRAMprog

SET TITLEBARtitle

... OF PROGRAMprog

SET USER-COMMANDcmd

SUBMIT rep ... TO SAP-SPOOL ... (applies toall additions)

SUBMIT rep ... WITH FREE SELECTIONStexpr

TRANSFER f TOdsn

UPDATE dbtab WHERE ...

(applies toall strings in the WHERE clause)

WRITE ...

... CURRENCYw

... UNITu

If useful reward.

Vasanth

3 REPLIES 3

Former Member
0 Kudos

Hello,

Strings - Fields with Variable Length

The elementary data type STRING is similar to data type C and refers to a variable-length string. Accordingly, the elementary data type XSTRING is similar to data type X and refers to a variable-length byte sequence.

In contrast to a C or X field, the length of a string is not static but variable and adjusts itself to the current field content at runtime. Dynamic memory management is used internally. Strings can have any length.

The initial value of a string is an empty string with length 0. A structure containing a string is seen as deep. A deep structure cannot be used like a C field. Strings can be displayed in the ABAP Debugger and used in the ABAP Dictionary.

It is not yet possible to use strings in screens or database tables. However, strings can be stored in database tables as clusters using EXPORT and transferred using IMPORT.

the current release it has not been possible to fully complete the implementation of strings. Especially the handling of blank characters at the end of a string has not been finalized for a number of ABAP statements.

For the highlighted argument positions of the following ABAP statements, blank characters at the end of strings are not taken into account. This may change in the next release. Therefore strings with blank characters at the end should not be used in these positions.

ASSIGN f TO <fs> TYPEtype

ASSIGN TABLE FIELD (f)

ASSIGN (f) TO <fs>

ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO <fs>

ASSIGN COMPONENTname OF STRUCTURE struc TO <fs>

ASSIGN LOCAL COPY OF (f) TO <fs>

CALL SELECTION-SCREEN scr USING SELECTION-SETset

CLOSE DATASETdsn

CREATE OBJECT ref TYPE (class)

CREATE DATA dref TYPE (type)

DELETE FROM dbtab WHERE ...

(applies toall strings in the WHERE clause)

EDITOR-CALL FOR REPORTprog

EDITOR-CALL FOR itab TITLEtext

GENERATE DYNPRO ... IDid

GENERATE REPORTprog

GENERATE SUBROUTINE POOL itab NAMEname

IMPORT DYNPRO ... IDid

MESSAGE xnnn WITHf1 ...f4

MESSAGE ID id TYPEmtype NUMBERn

NEW-PAGE PRINT ON ... (applies toall additions)

OPEN DATASET dsn ...

... TYPEc

... MESSAGEm

... FILTERf

PERFORM (form)

... IN PROGRAM (prog)

SET PF-STATUSpfstat

... EXCLUDINGf

... OF PROGRAMprog

SET TITLEBARtitle

... OF PROGRAMprog

SET USER-COMMANDcmd

SUBMIT rep ... TO SAP-SPOOL ... (applies toall additions)

SUBMIT rep ... WITH FREE SELECTIONStexpr

TRANSFER f TOdsn

UPDATE dbtab WHERE ...

(applies toall strings in the WHERE clause)

WRITE ...

... CURRENCYw

... UNITu

If useful reward.

Vasanth

Former Member
0 Kudos

Hi Santosh,

STRING is a bulit in data type and can be used to describe data objects of varaible length. It is used to store text into variables in programs.

Example:

DATA: NAME TYPE STRING VALUE 'SANTOSH'.

Reward points if helpful.

Regards,

Renuka

Former Member
0 Kudos

Hi,

<b>Predefined Elementary ABAP Types with Variable Length</b>

These predefined elementary data types are used to specify the types of individual fields whose lengths are not fixed until runtime. There are two predefined ABAP data types with variable length that are generically known as strings:

STRING for character strings

A string is a sequence of characters with variable length. A string can contain any number of alphanumeric characters. The length of a string is the number of characters multiplied by the length required for the internal representation of a single character.

XSTRING for byte strings

A byte string is a hexadecimal type with variable length. It can contain any number of bytes. The length of a byte string is the same as the number of bytes.

When you create a string as a data object, only a string header is created statically. This contains administrative information. The actual data objects are created and modified dynamically at runtime by operational statements.

The initial value of a string is the empty string with length 0. A structure that contains a string is handled like a deep structure. This means that there are no conversion rules for structures that contain strings.

Regards,

Azaz Ali.