11-14-2007 4:44 AM
Hi Abapers,
Please tell me how to replace first 4 characters of one variable with some other characters.
11-14-2007 4:46 AM
11-14-2007 4:47 AM
Hi,
You can use REPLACE ALL..
Ex..
REPLACE ALL OCCURRENCES OF ',' IN temp WITH ''.
Thanks
naren
11-14-2007 4:49 AM
Hi,
have a look at this link,
http://help.sap.com/saphelp_46c/helpdata/en/71/52604ff6f011d2961c00a0c930660b/frameset.htm
11-14-2007 4:50 AM
hi shruti,
a string in a field with a different string, use the REPLACE statement.
REPLACE <str1> WITH <str2> INTO <c> [LENGTH <l>].
The statement searches the field <c> for the first occurrence of the first <l> positions of the pattern <str1>. If no length is specified, it searches for the pattern <str1> in its full length.
Then, the statement replaces the first occurrence of the pattern <str1> in field <c> with the string <str2>. If a length <l> was specified, only the relevant part of the pattern is replaced.
If the return code value of the system field SY-SUBRC is set to 0, this indicates that <str1> was found in <c> and replaced by <str2>. A return code value other than 0 means that nothing was replaced. <str1>, <str2>, and <len> can be variables.
*************************
example:
DATA: T(10) VALUE 'abcdefghij',
STRING LIKE T,
STR1(4) VALUE 'cdef',
STR2(4) VALUE 'klmn',
STR3(2) VALUE 'kl',
STR4(6) VALUE 'klmnop',
LEN TYPE I VALUE 2.
STRING = T.
WRITE STRING.
REPLACE STR1 WITH STR2 INTO STRING.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR2 INTO STRING LENGTH LEN.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR3 INTO STRING.
WRITE / STRING.
STRING = T.
REPLACE STR1 WITH STR4 INTO STRING.
WRITE / STRING.
The output appears as follows:
abcdefghij
abklmnghij
abklmnefgh
abklghij
abklmnopgh
***********************
reward if useful..
11-14-2007 4:51 AM
Hi,
Check the mentioned examples you will get a clear picture.
*EG1:
DATA STR1(36).
STR1 = 'APPLE & ORANGE & BANANA'.
REPLACE '&' WITH ' . ' INTO STR1.
WRITE:/ STR1.
*EG2:
Data p(6) value 'ABCABC'.
Replace 'ABC' with 'DEF' into p.
Write:/ p.
Reward if helpful.
Regards,
Harini.S
11-14-2007 4:52 AM
11-14-2007 4:53 AM
Hi Shruti,
Data: str1(10) type c value 'abcdefghij',
str2(4) type c value 'wxyz'.
shift str1 by 4 places.
concatenate str2 str1 into str1.
condense str1 no-gaps.
11-14-2007 4:55 AM
Hi,
Try this..
DATA: BEGIN OF S_TEST,
CHAR(10),
VALUE(10),
END OF S_TEST.
S_TEST-VALUE = 'TeST'.
**Now S_TEST will have 10 blank places in front..
Thanks
naren
11-14-2007 5:01 AM
Hi Shruti ,
Go through this example.
DATA v1(10) TYPE C value '1234567891'.
REPLACE SECTION OFFSET 0 LENGTH 1 OF v1 WITH 'H'
IN CHARACTER MODE.
REPLACE SECTION OFFSET 1 LENGTH 1 OF v1 WITH 'H'
IN CHARACTER MODE.
REPLACE SECTION OFFSET 2 LENGTH 1 OF v1 WITH 'H'
IN CHARACTER MODE.
REPLACE SECTION OFFSET 3 LENGTH 1 OF v1 WITH 'H'
IN CHARACTER MODE.
WRITE: v1.
please reward the points if helpful.
Regards,
Rajesh Akarte
11-14-2007 5:02 AM
Ok. If the number of spaces I want to add is not a constant. Suppose some times 20 sometimes 21 sometimes 30. It depends on the value of PO number.
11-14-2007 5:06 AM
HI,
Try this..give the input and it will put that number of blank spaces in the front.
PARAMETERS: P_TIMES TYPE I.
START-OF-SELECTION.
DATA: V_STRING TYPE STRING.
**default value.
V_STRING= 'TEST'.
*" Concatenate blank according to the selectionscreen parameter.
do p_times times.
concatenate space v_string into v_string.
enddo.
write: / v_string.
Thanks
naren
11-14-2007 5:20 AM
11-14-2007 5:23 AM