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

string processing statements

Former Member
0 Likes
976

hi

i like to know what is string processing statement and i like to have an example for string processing statement

4 REPLIES 4
Read only

Former Member
0 Likes
774

hi

hope it will help you.

Reward if help.

String processing statements, whose arguments were all interpreted as fields of type C until now, are now divided into statements with character arguments and those with byte arguments.

String processing statements

CLEAR ... WITH

CONCATENATE

CONDENSE

CONVERT TEXT ... INTO SORTABLE CODE

OVERLAY

REPLACE

SEARCH

SHIFT

SPLIT

TRANSLATE ... TO UPPER/LOWER CASE

TRANSLATE ... USING

The arguments of these instructions must be single fields of type C, N, D, T or STRING or structures of character-type only. There is a syntax or runtime error if arguments of a different type are passed. A subset of this function is provided with the addition IN BYTE MODE for processing byte strings – that is, operands of type X or XSTRING. A statement such as CONCATENATE a x b INTO c is thus no longer possible when a,b, and c are all character-type, but x is of type X.

TRANSLATE ... CODEPAGE ...

TRANSLATE ... NUMBER FORMAT ...

The above statements are not allowed in Unicode programs. Instead, you can use the new conversion classes, which are described in more detail in Converting Data.

Comparison operators for string processing

CO

CN

CA

NA

CS

NS

CP

NP

As with the string processing statements, these operators need single fields of type C, N, D, T or STRING as arguments and again structures of character-type only are allowed. Special compare operators defined with the prefix BYTE- are provided for byte strings.

Functions for string processing

Function STRLEN only works with character-type fields and returns the length in characters. The new function XSTRLEN finds the length of byte strings.

Until now, function CHARLEN returned the value1 for a text field beginning with a single byte character under an NUS. The value 2 is returned for text fields beginning with a double byte character. Under a US, CHARLEN returns the value 1 if text begins with a single Unicode character. If text begins with a Unicode double character from the surrogate area, the value 2 is returned.

Function NUMOFCHAR returns the number of characters in a string or a character-type field. In single byte code pages, the function behaves like STRLEN. In multi-byte code pages, characters filling more than 1 byte are nevertheless considered to have length 1.

Output in fields and lists

In WRITE ...TO, any flat data types that were handled like C fields were allowed as the target field. A UP now requires that the target field be of character-type in a WRITE ... TO ... statement. The line type of the table must be of character-type for the table variant WRITE ... TO itab INDEX idx. The offset and length are counted in characters.

Until now, any flat structures could be output with WRITE. If the source field is a flat structure in a WRITE, it must have character-type only, in a UP. This affects the following statements:

WRITE f.

WRITE f TO g[+off][(len)].

WRITE (name) TO g.

WRITE f TO itab[+off][(len)] INDEX idx.

WRITE (name) TO itab[+off][(len)] INDEX idx.

Read only

Former Member
0 Likes
774

Hi,

Here are some examples....

1) CONCATENATE C1 C2 C3 C4 INTO C5.

WRITE C5.

2) LEN = STRLEN( STRING ).

3) CONDENSE STRING.

4) TRANSLATE STRING TO LOWER CASE.

5) TRANSLATE STRING TO UPPER CASE.

6) TRANSLATE STRING USING RULE.

7) OVERLAY STRING WITH OVER ONLY STR.

😎 REPLACE STR1 WITH STR2 INTO STRING.

9) SPLIT STRING AT DEL INTO P1 P2 P3 P4.

Search SAP help for more string processing statements

Reward points if helpful.

Read only

Former Member
0 Likes
774

hi mahesh,

Check to this link..

[String processing][http://help.sap.com/saphelp_470/helpdata/EN/fc/eb3357358411d1829f0000e829fbfe/frameset.htm]

Read only

Former Member
0 Likes
774

Hie,

Try this code,

    • shifting strings by a given number of places*

DATA: t1(10) TYPE c VALUE 'abcdefghij',

string1 LIKE t1.

string1 = t1.

WRITE string1.

SHIFT string1.

WRITE / string1.

string1 = t1.

SHIFT string1 BY 3 PLACES LEFT.

WRITE / string1.

string1 = t1.

SHIFT string1 BY 3 PLACES RIGHT.

WRITE / string1.

string1 = t1.

SHIFT string1 BY 3 PLACES CIRCULAR.

WRITE / string1.

SKIP.

ULINE.

    • shifting up to a given string*

DATA: t2(10) TYPE c VALUE 'abcdefghij',

string2 LIKE t2,

str2(2) TYPE c VALUE 'ef'.

string2 = t2.

WRITE string2.

SHIFT string2 UP TO str2.

WRITE / string2.

string2 = t2.

SHIFT string2 UP TO str2 LEFT.

WRITE / string2.

string2 = t2.

SHIFT string2 UP TO str2 RIGHT.

WRITE / string2.

string2 = t2.

SHIFT string2 UP TO str2 CIRCULAR.

WRITE / string2.

SKIP.

ULINE.

    • shifting a string depending on the first or last sign*

DATA: t3(14) TYPE c VALUE ' abcdefghij',

string3 LIKE t3,

str3(6) TYPE c VALUE 'ghijkl'.

string3 = t3.

WRITE string3.

SHIFT string3 LEFT DELETING LEADING space.

WRITE / string3.

string3 = t3.

SHIFT string3 RIGHT DELETING TRAILING str3.

WRITE / string3.

SKIP.

ULINE.

    • replacing values*

DATA: t4(10) TYPE c VALUE 'abcdefghij',

string4 LIKE t4,

str41(4) TYPE c VALUE 'cdef',

str42(4) TYPE c VALUE 'klmn',

str43(2) TYPE c VALUE 'kl',

str44(6) TYPE c VALUE 'klmnop',

len4 TYPE i VALUE 2.

string4 = t4.

WRITE string4.

REPLACE str41 WITH str42 INTO string4.

WRITE / string4.

string4 = t4.

REPLACE str41 WITH str42 INTO string4 LENGTH len4.

WRITE / string4.

string4 = t4.

REPLACE str41 WITH str43 INTO string4.

WRITE / string4.

string4 = t4.

REPLACE str41 WITH str44 INTO string4.

WRITE / string4.

*searching strings

DATA string7(30) TYPE c VALUE 'This is a little sentence.'.

WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.

ULINE /1(26).

SEARCH string7 FOR 'X'.

WRITE: / 'X', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

SEARCH string7 FOR 'itt '.

WRITE: / 'itt ', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

SEARCH string7 FOR '.e .'.

WRITE: / '.e .', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

SEARCH string7 FOR '*e'.

WRITE: / '*e ', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

SEARCH string7 FOR 's*'.

WRITE: / 's* ', sy-subrc UNDER 'SY-SUBRC',

sy-fdpos UNDER 'SY-FDPOS'.

DATA: int TYPE i,

word1(20) TYPE c VALUE '12345',

word2(20) TYPE c ,

word3(20) TYPE c VALUE ' 4 '.

int = strlen( word1 ). WRITE int.

int = strlen( word2 ). WRITE / int.

int = strlen( word3 ). WRITE / int.

SKIP.

ULINE.

    • condensing strings*

DATA: string9(25) TYPE c VALUE ' one two three four',

len9 TYPE i.

len9 = strlen( string9 ).

WRITE: string9, '!'.

WRITE: / 'Length: ', len9.

CONDENSE string9.

len9 = strlen( string9 ).

WRITE: string9, '!'.

WRITE: / 'Length: ', len9.

CONDENSE string9 NO-GAPS.

len9 = strlen( string9 ).

WRITE: string9, '!'.

WRITE: / 'Length: ', len9.

SKIP.

ULINE.

    • concatenating strings*

DATA: c1(10) TYPE c VALUE 'Sum',

c2(3) TYPE c VALUE 'mer',

c3(5) TYPE c VALUE 'holi ',

c4(10) TYPE c VALUE 'day',

c5(30) TYPE c ,

sep(3) TYPE c VALUE ' - '.

CONCATENATE c1 c2 c3 c4 INTO c5.

WRITE c5.

CONCATENATE c1 c2 c3 c4 INTO c5 SEPARATED BY sep.

WRITE / c5.

SKIP.

ULINE.

    • splitting strings*

DATA: string10(60) TYPE c ,

p1(20) TYPE c VALUE '++++++++++++++++++++',

p2(20) TYPE c VALUE '++++++++++++++++++++',

p3(20) TYPE c VALUE '++++++++++++++++++++',

p4(20) TYPE c VALUE '++++++++++++++++++++',

del10(3) TYPE c VALUE '***'.

string10 = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.

WRITE string10.

SPLIT string10 AT del10 INTO p1 p2 p3 p4.

WRITE / p1.

WRITE / p2.

WRITE / p3.

WRITE / p4.

SKIP.

ULINE.

    • moving parts of strings*

DATA: mc1(10) TYPE c VALUE 'ABCDEFGHIJ',

mc2(10) TYPE c .

MOVE mc1 TO mc2 PERCENTAGE 40.

WRITE mc2.

MOVE mc1 TO mc2 PERCENTAGE 40 RIGHT.

WRITE / mc2.

Hope this answers wholly!!

Bijal:)