Sap Abap- Usage of String and Xstring

Only available on StudyMode
  • Topic: String, Perl, ASCII
  • Pages : 6 (1366 words )
  • Download(s) : 307
  • Published : April 2, 2013
Open Document
Text Preview
what it is, how and when to use each piece of code.  First, let’s understand String Handling. 

What, How, When to Use a String

A String is a variable length data type which is used to store any length of data. Variable length fields are used because they save space.  Example:
Raj is 3 characters long, Vemuri Rajgopal is 14 character long. With fixed-length fields, you need to define each field to be long enough to hold the longest name. This would waste space for records that had short names. In variable length fields it stores the exact length of the string. • String, can store any number of characters. String will allocate the memory at runtime which is also called as dynamic memory allocation, will allocate the memory as per the size of the string. Strings cannot be declared using parameters as the memory of allocation is dynamic. • RFC(Remote Function Call) type for string is RFC_String. RFC is a interface for communication between a SAP system and other SAP or third party compatible system. • The XSD type for string is xsd:string.

• To convert a string to xstring we use the function module scms_string_to_xstring Syntax:
DATA [()] TYPE [DECIMALS ]… [VALUE ].
Example:
DATA : V_NAME TYPE STRING.
V_NAME = ‘RAJ’.
Memory is allocated only for RAJ, which always depends on the number of characters stored currently. Advantages of using a String:
• Efficient management of string storage space.
• String values are stored separately from variables in memory. Operations Of Strings:
• Concatenate : To club more than one sub string into one main string. Syntax :
Concatenate ….. into separated by a .
Example :
Concatenate ‘code’ ‘excellence’ into s_name separated by ‘,’. Output : code,excellence
• Condense : Replaces sequence of spaces into one space. Syntax :
Condense ‘               ’.
Example:
1. Condense ‘code                excellence’. - All the blanks in the above example are converted into a single blank.       Output : code excellence
      2. Condense ‘code                      excellence’ no-gaps.              - There will not be any gap between the two strings.       Output : codeexcellence
• Translate : Used to translate the string into upper/lower case. Syntax :
TRANSLATE  TO UPPERCASE/LOWERCASE.
Example :
TRANSLATE  ‘CODE EXCELLENCE’ TO LOWERCASE.
Output : code excellence
• Replace : Replaces the string, With replace we can only replace the first occurrences of the string. Syntax :
REPLACE WITH INTO .
- Replace only the first occurrence (but not all).
Example :
REPLACE ‘I’ WITH ‘E’ INTO ‘INTELLIGENT’.
Output : ENTELLIGENT.
• Split : To split the main string into substrings by the given separators. Syntax :
SPLIT AT INTO … .
Example :
SPLIT ‘C99,CODE EXCELLENCE,USA’ AT ‘,’ INTO  S_ID S_NAME S_COUNTRY. Note : S_ID,S_NAME,S_COUNTRY should be declared as strings.
Output :
S_ID                       -              C99 S_NAME              -              CODE EXCELLENCE S_COUNTRY -    USA
• Shift : Shifts the string by one place, by default it will shift to left side. String can be shifted to left, right, circular. Syntax :
1. SHIFT BY PLACES.
2. SHIFT LEFT DELETING LEADING .
3. SHIFT RIGHT DELETING TRAILING .
Example :
1. SHIFT ‘ARISE’.      --  MAX (Since default LEFT). 2. SHIFT ‘ARISE’ CIRCULAR  -- RISEA.
3. SHIFT ‘ARISE’ RIGHT BY 2 PLACES  --  ‘  ARISE’ (First two characters are places. • Search : Searches for the required string in the main string. o ‘str’ – a character string (trailing spaces are ignored). o  ‘.str.’ – any string between the periods. o  ‘*str’ -  a word ending with str.

o Str*’ – a word beginning with str.
 Comparing Strings :
• CO(Contains Only) : 
IF CO .
Is true if contains only characters from . The comparison is case sensitive. Trailing blanks are included. If the comparison of the string Is...
tracking img