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 (Not Character) Operations

mike_mcinerney
Participant
0 Likes
1,349

Can someone point me to the list of native operations that can be performed on variables of type string.



Data mystring type string .

Thanks...

...Mike

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,298

Have a good reading [here|http://help.sap.com/erp2005_ehp_04/helpdata/EN/1f/be3d408ae01e24e10000000a1550b0/content.htm]

regards,

Advait

9 REPLIES 9
Read only

former_member156446
Active Contributor
0 Likes
1,298

CS NS

Read only

Former Member
Read only

0 Likes
1,298

Sorry - maybe the term operations inferred a different connotation.

I'm looking for a (complete) list of functionality for querying/manipulating variables of type string.

Things like substring, strlen, etc.

Thanks...

...Mike

Read only

0 Likes
1,298

From top of my mind

DATA: string TYPE string VALUE 'ALH(9(__(*JJJ'.
DATA: lv_len TYPE i.

SHIFT string LEFT DELETING LEADING space.
WRITE: string.
string = string+2(3).  "offset
WRITE: string.
DESCRIBE FIELD string LENGTH lv_len in BYTE MODE.
write: lv_len.
DESCRIBE FIELD string LENGTH lv_len in CHARACTER MODE.
write: lv_len.

DO 25 TIMES.
  DO 25 TIMES.
    CONCATENATE sy-abcde+sy-index(1) string INTO string.
  ENDDO.
ENDDO.
WRITE: string.

[STRING operations|http://www.google.com/url?sa=t&source=web&ct=res&cd=3&url=http%3A%2F%2Fabaplovers.blogspot.com%2F2008%2F04%2Fstring-operations.html&ei=gY2VSZu8GqGbtwfosKSsCw&usg=AFQjCNFa_iG7U9mX19vWn5kJYtoYBjmtbA&sig2=cP7AP-dSUiFTNKDatj8dug]

Read only

awin_prabhu
Active Contributor
0 Likes
1,298

Hi friend,

This report might be useful..

All simple string operations for you.

Report zstringtest.

TABLES:mara.

DATA: a TYPE string VALUE 'robert',

b TYPE string VALUE 'bosch',

c TYPE string,

d TYPE string VALUE 'rRbB',

s1 TYPE string,

s2 TYPE string,

s TYPE i,

a1 TYPE string,

b1 TYPE string.

*Concatenation

WRITE:/'CONCATENATION' COLOR = 1.

CONCATENATE a b INTO c SEPARATED BY space.

WRITE: / ' Concatenation1' COLOR = 3, c.

CONCATENATE a b INTO c.

WRITE:/ ' Concatenation2' COLOR = 3, c.

WRITE:/.

*Translation

WRITE:/'TRANSLATION' COLOR = 1.

TRANSLATE c TO UPPER CASE.

WRITE:/ ' Upper Case' COLOR = 3,c.

TRANSLATE c TO LOWER CASE.

WRITE:/ ' Lower Case' COLOR = 3,c.

TRANSLATE c USING d.

WRITE:/ ' Using Pattern' COLOR = 3,c.

WRITE:/.

c = 'robert bosch'.

WRITE:/ 'CONDENSE' COLOR = 1.

WRITE:/ ' Before Condense:' COLOR = 3,c.

*Condense

CONDENSE c.

WRITE:/ ' After Condense1:' COLOR = 3,c.

CONDENSE c NO-GAPS.

WRITE:/ ' After Condense2:' COLOR = 3,c.

WRITE:/.

*Split

WRITE:/ 'SPLIT' COLOR = 1.

c = 'robert.bosch'.

WRITE:/ ' Before split:' COLOR = 3, c.

SPLIT c AT '.' INTO s1 s2.

WRITE:/' After split:' COLOR = 3.

WRITE: ' String 1:' COLOR = 3, s1.

WRITE:/16 ' String 2:' COLOR = 3 , s2.

*String Length

WRITE:/ 'STRING LENGTH' COLOR = 1.

c = 'robert bosch'.

WRITE: / c.

s = STRLEN( c ).

WRITE: s.

c = 'robert bosch'.

WRITE: / c.

s = STRLEN( c ).

WRITE: s.

WRITE:/.

*Search

CONDENSE c.

WRITE:/ 'SEARCH' COLOR = 1.

WRITE: / ' Text:' COLOR = 3, c.

SEARCH c FOR 'bo'.

WRITE : / ' '' bo'' found at position:',sy-fdpos.

SEARCH c FOR 'o' STARTING AT 8.

WRITE : / ' '' o'' found at position:',sy-fdpos.

WRITE:/.

*Offset

WRITE:/ 'OFFSET' COLOR = 1.

a1 = 'Hello Robert Bosch'.

MOVE a1+6(12) TO b1.

WRITE: / b1.

WRITE:/.

*Contains Only

*a1 = 'Hello'.

WRITE:'Contains Only' COLOR = 1.

WRITE:/ 'a1:',a1.

IF a1 CO 'Hello'.

WRITE:/ 'a1 contains only '' Hello'''.

ELSE.

WRITE:/ 'a1 contains not only '' Hello'''.

ENDIF.

WRITE:/.

*Contains Not Only

*a1 = 'Hello'.

WRITE: 'Contains Not Only' COLOR = 1.

WRITE:/ 'a1:',a1.

IF a1 CN 'Hello'.

WRITE:/ 'a1 contains not only '' Hello'' '.

ELSE.

WRITE:/ 'a1 contains only '' Hello'' '.

ENDIF.

WRITE:/.

*Contains Any

*a1 = 'Hello'.

WRITE: 'Contains Any' COLOR = 1.

WRITE:/ 'a1:',a1.

IF a1 CA 'Riv'.

WRITE:/ 'a1 contains some characters in '' Riv'' '.

ELSE.

WRITE:/ 'a1 contains no single character that are in '' Riv'' '.

ENDIF.

WRITE:/.

*Contains Not Any

WRITE: 'Contains Not Any' COLOR = 1.

WRITE:/ 'a1:',a1.

IF a1 NA 'iv'.

WRITE:/ 'a1 contains not any character from '' iv'' '.

ELSE.

WRITE:/ 'a1 contains some charcters in '' iv'' '.

ENDIF.

WRITE:/.

*Contains String

WRITE: 'Contains String' COLOR = 1.

WRITE:/ 'a1:',a1.

IF a1 CS 'Hello'.

WRITE:/ 'a1 contains string '' Hello'' '.

ELSE.

WRITE:/ 'a1 contains no string '' Hello'' '.

ENDIF.

WRITE:/.

*write:.

*Contains No string

WRITE: 'Contains No String' COLOR = 1.

WRITE:/ 'a1:',a1.

IF a1 NS 'Hai'.

WRITE:/ 'a1 contains no string named '' Hai'' '.

ELSE.

WRITE:/ 'a1 contains string named '' Hai'' '.

ENDIF.

WRITE:/.

*Contains Pattern

WRITE:/ 'Contains Pattern' COLOR = 1.

WRITE:/ 'a1:',a1.

IF a1 CP 'Hello Robert Bosch'.

WRITE:/ 'a1 contains pattern '' Hello robert Bosch'' '.

ELSE.

WRITE:/ 'a1 contains no pattern as '' Hello robert Bosch'''.

ENDIF.

WRITE:/.

*Contains No Pattern

WRITE:/ 'Contains No Pattern' COLOR = 1.

WRITE:/ 'a1:',a1.

IF a1 NP 'Robert Bosch'.

WRITE: / 'a1 contains no pattern as '' Hello robert Bosch'''.

ELSE.

WRITE:/ 'a1 contains pattern '' Hello robert Bosch'' '.

ENDIF.

WRITE:/.

*Move

WRITE:/ 'Move' COLOR = 1.

DATA: a2 TYPE string.

WRITE:/ 'a1:', a1.

MOVE a1 TO a2.

WRITE:/ 'a2:', a2.

WRITE:/.

Thanks......

Edited by: Guest77 on Feb 13, 2009 4:47 PM

Edited by: Guest77 on Feb 13, 2009 4:48 PM

Read only

faisalatsap
Active Contributor
0 Likes
1,298

Hi,

Test my Sample code in the following Thread may it will help you out if you want to use STRLEN and divide the given String to sub strings.

in this Thread the Requirement was to Divide a String to 3 Character each sub string so this Sample code dividing the given string to 3 length of possible sub strings, you can the idea from this.

[Splitting a String in Different Sub Strings (String Operations)|]

Kind Regards,

Faisal

Read only

Former Member
0 Likes
1,299

Have a good reading [here|http://help.sap.com/erp2005_ehp_04/helpdata/EN/1f/be3d408ae01e24e10000000a1550b0/content.htm]

regards,

Advait

Read only

mike_mcinerney
Participant
0 Likes
1,298

Somewhere in these answers I've gleaned some info. I'll just compile a list as I go. Thanks