Sunday, 23 August 2015

Working With Strings

String is a variable length data type.

Dynamic memory management is used internally.i.e Memory allocated(Adjusted) at run time according to the current field content.


It can have any length(can store any no of character).


Note: String is a dynamic length data type We cannot declare string variables through  PARAMETER.

PARAMETER p_name type string. it can not allowed because the system cannot understand how big the input field is.


Difference between char and strings:

CHAR:

Data:v_name type char 100,
         v_name = 'ABC'.

Memory is always allocated for 100 chars irrespective of the no of chars stored currently.



STRINGS:

Data: v_name type string.
v_name = 'ABC'.

Memory is allocated for only for ABC,which always depends on the no of chars stored currently.


String Operations:

CONCATENATE : To club more than one sub string into one main string.

SYNTAX:concatenate  <str1> <str2> <Str3>...<StrN> into <str> separated by <separator>.


CONDENCE: Replaces sequence of spaces into exactly one space.


CONDENCE 'SAP            ABAP                     CARRER'.

Result: SAP ABAP CARRER.


you also add in condence syntax like


CONDENCE 'SAP ABAP         CONSULTANT ' NO-GAPS.

REsult:

SAPABAP CONSULTANT(All ithe sequential Blanks converted into single blank and even deletes that single space also.

In this way there are lots of of commands in string operations like

TRANSALTE: to translate UPPER/LOWER CASE

REPLACE: REPLACE <str1> with <str2> into <str>.

SPLIT: To split the main string into substring at the given separator.

SHIFT: By default shifts to LEFT by 1 plcae.

Syntax:
1.SHIFT <str> <LEFT/RIGHT/CIRCULAR> by <N> places. (N>0).
2.SHIFT <str> left deleting leading <char>.
3.SHIFT <str> RIGHT Deleting Trailing<char>.

SEARCH:Search For the required sub string in the main string.

SEARCH<str> for <str1>.
'str' is a character string.
'.str' any character string between the periods.
'*str' a word ending with 'str'.including 'str'.
'str*' a word beginning with 'str' including str.


REsult: SY-SUBRC = 0 when search is successful,
                                 = 4 when not found.

            SY-FDPOS = contains the offset(Position) of the string.



COMPARING STRINGS:

its very important topic in string operations.


These Special comparisons can be applied to strings with types C.N,D and T.


Operator:

CO------------------------Contains Only
CN------------------------Contains Not Only
CA------------------------Contains ANY
NA------------------------Contains Not any
CS-------------------------Contains Strings
NS-------------------------Contains No Strings
CP-------------------------Matches Pattern
NP-------------------------Does not match pattern.





















No comments:

Post a Comment