Sie sind auf Seite 1von 6

ABAP STRING FUNCTIONS

1. CONCATENATE : - Concatenate is the string function used to combine different strings into one string. concatenate <c1> .. <cn> into <str> [separated by 's1']. DATA: CNTR(10) VALUE 'USA', STATE(10) VALUE 'CA', CITY(10) VALUE 'LA'. DATA STR(30). CONCATENATE CNTR STATE CITY INTO STR. WRITE STR. ****Result:-USACALA ****************************************** DATA: CNTR(10) VALUE 'USA', STATE(10) VALUE 'CA', CITY(10) VALUE 'LA'. DATA STR(30). CONCATENATE CNTR STATE CITY INTO STR SEPARATED BY ':'. WRITE STR. ****RESULT--USA:CA:LA =============================================================== 2. SPLIT :This string function is used to divide one string data into different strings. Syntax : Split <str> at <del>into <c1> .. <cn>. *EXAMPLEFORSPLIT DATA : A TYPE STRING VALUE 'INDIA@IS$GREAT', B TYPE STRING. SPLIT A AT '@' INTO A B. WRITE : A,/ B

http://sapbinavigations.blogspot.in/(PratapLavu)

Page 1

ABAP STRING FUNCTIONS


3. TRANSLATE This string function is used to convert the data of string into upper case or lower case. *EXAMPLETRANSALTETOLOWERCASE DATA : STR(30) VALUE 'CHANGE THIS TO LOWER CASE'. TRANSLATE STR TO LOWER CASE. WRITE STR. *EXAMPLETRANSALTETOLOWERCASE DATA : STR(30) VALUE 'change to lower case'. TRANSLATE STR TO upper case. WRITE STR.

4. SHIFT:This string function is used to move the data of the string in required direction, and also used to delete unwanted data from the specified direction. This string function has 3 Syntaxes. 1st Syntax SHIFT <str> [by <n> places] [mode]. where n is number of characters. mode is : left / right / circular. DATA : STR(20) VALUE 'INDIA IS GREAT'. SHIFT STR BY 5 PLACES. " IS GREAT" WRITE STR. DATA : STR(20) VALUE 'INDIA IS GREAT'. SHIFT STR BY 5 PLACES RIGHT. WRITE STR. " INDIA IS GREAT " DATA : STR(20) VALUE 'INDIA IS GREAT'. SHIFT STR BY 5 PLACES CIRCULAR. WRITE STR. " IS GREAT INDIA" Syntax #2. shift <str> left deleting leading <s1>. data str(20) VALUE '### 00000008373'. SHIFT STR LEFT DELETING LEADING '0 #'. WRITE STR. http://sapbinavigations.blogspot.in/(PratapLavu) Page 2

ABAP STRING FUNCTIONS


Syntax #3. shift <str> right deleting trailing <s1>. data str(30) VALUE '3874#$#$$$%'. shift str right deleting trailing '#%$ '. shift str left deleting leading ' '. write str.

5. CONDENSE :Using this function multiple spaces are converted into single space and deletes all other space from both right and left. 1)*Exampleforcondense data str(30) value 'SAP *(*&^%*&^^ INDIA'. REPLACE ALL OCCURRENCES OF '*(*&^%*&^^ ' IN STR WITH ''. CONDENSESTR. WRITE STR COLOR 7. ===================== 2)*Exampleforcondense data str(30) value 'SAP *(*&^%*&^^ INDIA'. REPLACE ALL OCCURRENCES OF '*(*&^%*&^^ ' IN STR WITH ''. *CONDENSESTR. CONDENSE STR NO-GAPS. WRITE STR COLOR 7.

6. REPLACE: Using this string function we can replace unwanted data with required characters. This string function has 2 syntaxes: i) REPLACE <S1> WITH <S2> INTO <STR> . here only first occurrence of <s1> will be replaced with <s2> ii) REPLACE ALL OCCURRENCES OF <S1> IN <STR> WITH <S2>. Example: data name(20) value 'nil kumr'. *replace '' with 'A' into name. replace all occurrences of '' in name with 'A'. write name. http://sapbinavigations.blogspot.in/(PratapLavu) Page 3

ABAP STRING FUNCTIONS


7. OVERLAY:Is another string function is to overlap one string data with another string data internally when ever the spaces of first string replace with corresponding index data of second string DATA STR(30) VALUE '9:03 AM 1/6/2009'. DATA : T1(6), STA(2) , DT(10). SPLIT STR AT ' ' INTO T1 STA DT. DATA : DD(2) , MM(2) , YY(4). SPLIT DT AT '/' INTO MM DD YY. SHIFT DD RIGHT DELETING TRAILING SPACE. OVERLAY DD WITH '00'. SHIFT MM RIGHT DELETING TRAILING SPACE. OVERLAY MM WITH '00'. WRITE : / MM COLOR 7 , / DD COLOR 5, / YY COLOR 4. CONCATENATE DD MM YY INTO STR. WRITE : / STR. "SAPDATEFORMAT. "NONSAPDATEFORMAT

8. SEARCH:Is another string function is used to find for the data in a string. if data is found then returns "SY-SUBRC" ( predefined system variable) value as "0" else non zero. Example code. DATA STR(50) VALUE 'India is great'. search str for 'India'. if sy-subrc = 0. write 'search is successful'. else. write 'search failure'. endif.

http://sapbinavigations.blogspot.in/(PratapLavu)

Page 4

ABAP STRING FUNCTIONS


9. OFFSET FUNCTIONALITY : This is also known as substring function in other programming languages. syntax: str+<offset_position>[(width)]. data str(25) value 'india is great in all'. *write str+0(5). "india *write str+6(2). "is *write str+9(5). "great write str+9. "great in all

10. STRLEN:Is the string function is used to find data length of string. data str(20) value 'india is great'. data len type i. len = strlen( str ). write : str , 'length is ', len.

EXAMPLE FOR DATE FORMAT:-

YYYYMMDD ( SAP FORMAT) MMDDYYYY ( USA FORMAT ) DATA : STR(8) VALUE '01272012'. DATA : DD(2), MM(2), YY(4). DD = STR+2(2). MM = STR+0(2). YY = STR+4. CONCATENATE YY MM DD INTO STR. WRITE STR.

DATA : STR(10) VALUE '01/27/2012'. DATA : DD(2), MM(2), YY(4). SPLIT STR AT '/' INTO MM DD YY. CONCATENATE YY MM DD INTO STR. WRITE STR. DATA : STR(10) VALUE '1/27/2012'. DATA : DD(2), MM(2), YY(4). http://sapbinavigations.blogspot.in/(PratapLavu) Page 5

ABAP STRING FUNCTIONS


SPLIT STR AT '/' INTO MM DD YY. SHIFT MM RIGHT DELETING TRAILING SPACE. OVERLAY MM WITH '00'. CONCATENATE YY MM DD INTO STR. WRITE STR. DATA : STR(10) VALUE '1/27/98'. DATA : DD(2), MM(2), YY(4). SPLIT STR AT '/' INTO MM DD YY. DATA NUM TYPE I. NUM = YY. SHIFT YY RIGHT DELETING TRAILING SPACE. IF NUM > 50. OVERLAY YY WITH '1900'. ELSE. OVERLAY YY WITH '2000'. ENDIF. SHIFT MM RIGHT DELETING TRAILING SPACE. OVERLAY MM WITH '00'. CONCATENATE YY MM DD INTO STR. WRITE STR.

http://sapbinavigations.blogspot.in/(PratapLavu)

Page 6

Das könnte Ihnen auch gefallen