‎2009 Apr 20 7:40 AM
Hi Friends -
I have to replace first three characters of first and last name of an employee with 'XYZ'.
and update back in DB table how to do that ?
eg if name is Mohan Sharma then it shd be XYZAN XYZMA
Regards
Mohini
‎2009 Apr 20 7:46 AM
1) Get the data into internal table.
2) Split 'Mohan Sharma' at space into W_char1 w_char2.
W_char1+0(3) = 'XYZ'.
w_char2+0(3) = 'XYZ'.
Concatenate w_char1 w_char2 into w_char1 separated by space.
3) Modify internal table with W_char1.
4) Update the DB table from Itab.Regards,
Gurpreet
‎2009 Apr 20 7:47 AM
Hi Meeta
Check this Example related to your query
Processing Text Fields
move f+off1(len1) to g+off2(len2).
a = u2018abcdefghiu2019.
b = 'ABCDEFGHI'
move a+5(4) to b+4(4).
b will be ABCDfghiI
Regards
Sachin
‎2009 Apr 20 7:47 AM
hi,
Please refer to the following code
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
Note how, in the last line, the field STRING is truncated on the right. The search pattern 'cdef' of length 4 is replaced by 'klmnop' of length 6. Then, the rest of the field STRING is filled up to the end of the field.
Hope it is helpful to u
Warm Regards,
Srilu
‎2009 Apr 20 7:48 AM
Hi Meeta,
Press F1 on REPLACE for editing the string.
And for updating the database, I assume that you want to update in a database table.
So, you need to use Enqueue, Dequeue FM , then Update statement for database table and do use Commit work after updating DB.
Hope it helps.
Thanks,
Daya
‎2009 Apr 20 8:11 AM
REPORT znitesh1.
DATA: name type string value 'Meeta Nair',
name1(20) TYPE c,
name2(10) TYPE c.
SPLIT name AT space INTO name1 name2.
name1+0(3) = 'XYZ'.
name2+0(3) = 'XYZ'.
CONCATENATE name1 name2 INTO name1 SEPARATED BY space.
WRITE: name1.
‎2009 Apr 20 8:15 AM
This will replace the first & last 3 chars of any string.
data: v_str type string.
data: v_str1 type string,
v_str2 type string,
v_str3 type string,
len type i,
len1 type i.
v_str = 'Mahesh Reddy'.
len = Strlen( v_str ).
len1 = len - 3.
v_str1 = v_str+0(3).
REPLACE v_str1 WITH 'xyz' into v_str1.
concatenate v_str1 v_str+3(len1) into v_str3.
v_str2 = v_str+len1(3).
REPLACE v_str2 WITH 'xyz' into v_str2.
CONCATENATE v_str3+0(len1) v_str2 into v_str3.
WRITE:/ v_str3.Then you can update the value into your DB table using UPDATE .
‎2009 Apr 20 11:35 AM
Hi Friends
Txs for quick truns one thing i forget sorry i need to add the counter too at the end of this string
like if there are 100 employees then
First name Last name
eg Unipeps Gora shd be XYZPEPS01 XYZA01
INDIA Goalf shd be XYZIA02 XYZlf02
Sunita Phoddar shd be XYZita03 XYZddar03
Kamal kunal shd be XYZal04 XYZal04 ............and so on till the 100 number employee .
like that one number will counter will too add at the end i think we can add sy-index while concatenating pls correct me if am wrong ?
i need to update table PA0002 for First and Last Name for this
‎2009 Apr 20 11:40 AM
Yes. You can concatenate a counter.
Suppose you have all the 100 employees in one internal table, you can concatenate the 'SY-TABIX' to the split values.
For this you should first take a character variable and assign the sy-tabix to this char variable and then concatenate this char variable to the splitted names.
If required use 'CONDENSE' to remove any blanks.
Thanks & Regards,
Bhupal
‎2009 Apr 20 11:47 AM
Loop at itab.
Split itab-name at space into w_first w_last.
W_first+0(3) = 'XYZ'.
W_LAST+0(3) = 'XYZ'.
COncatenate w_first '0' sy-tabix into w_first.
COncatenate w_last '0' sy-tabix into w_last.
Concatenate w_first w_last into itab-name separated by space.
modify itab.
Endloop.
Modif ztable from Itab.OR
Loop at itab.
itab-first+0(3) = 'XYZ'.
itab-LAST+0(3) = 'XYZ'.
COncatenate itab-first '0' sy-tabix into itab-first.
COncatenate itab-LAST '0' sy-tabix into itab-LAST.
modify itab.
Endloop.
Modif ztable from Itab.regards,
Gurpreet
‎2009 Apr 20 11:56 AM
Hi..
Check this code...Have all the names in an internal table so that.. you can .. have the counter as well... Let the table be T_ITAB1.
data: w_first3 type string,
w_last3 type string.
w_xyz type char03 value 'XYZ',
w_firstname type string,
w_lastname type string.
Loop at t_itab1 into wa_itab1.
split wa_itab1-name at space into w_firstname w_lastname.
Replace w_firstname+0(3) with w_xyz.
concatenate w_firstname sy-tabix to w_firstname.
replace w_lastname+0(3) with w_xyz.
concatenate w_lastname sy-tabix to w_lastname.
concatenate w_firstname w_lastname into wa_itab1-name separated by space.
modify t_itab1 from wa_itab1.
endloop.
I think this woudl work perfectly...
‎2009 Apr 20 3:25 PM
Hi Friends -
Am able to update the replaced record but i have a new req in this i have to store the max counter number some where so next time if the same prog will run then it shd run for the new employees means
if today there are 100 employee then the last counter should be 100 and tommorw if they run this prog for next new 3 employees then counter should strt with 101 and 102 and 103 and not again from 0 ...
also how can we improve performance of this code as DB update is not good inside loop but this temp variable i need to fill everytime with new value ?
data : itab like pa0002 occurs 0 with header line ,
tt like pa0002 occurs 0 with header line,
wa like line of tt,
count(8) type c ,
temp(40) type c.
select * from pa0002 into corresponding fields of table itab
where pernr not like 'XYZ%'.
sort itab by pernr.
Loop at itab.
itab-nachn+0(3) = 'XYZ'.
itab-vorna+0(3) = 'XYZ'.
count = sy-tabix.
COncatenate itab-nachn count into itab-nachn.
COncatenate itab-vorna count into itab-vorna.
CONDENSE itab-nachn NO-GAPS.
CONDENSE itab-vorna NO-GAPS.
concatenate itab-nachn space itab-vorna into temp separated by space.
*CONDENSE temp .
*append itab.
*Concatenate w_first w_last into itab-name separated by space.
modify itab.
*endloop.
*
*loop at itab.
*wa-pernr = itab-pernr.
*modify pa0002 from itab.
update pa0002 set nachn = itab-nachn
vorna = itab-vorna
nchmc = itab-nachn
vnamc = itab-vorna
where pernr = itab-pernr.
*concatenate itab-nachn itab-vorna into temp.
UPDATE pa0001 SET ename = temp
where pernr = itab-pernr.
Endloop.
Regards
Mohini & Meeta
‎2009 Apr 20 3:35 PM
Solution for your first requirement that for the second run counter should start from 100 (or whereever last run stopped)
you have make use of TVARV table to store that last run last value and fetch that value in the next run at update it with the current at the end of the execution.
Sol for 2nd req is make use of UPDATE BY TABLE instead of updating everytime inside the loop .
Rhea.
Edited by: rhea on Apr 20, 2009 4:36 PM
‎2009 Apr 24 3:00 PM