2005 Jan 11 2:58 PM
Hi Guys:
I have to add one charecter inthe existing filed.
example:
data : begin of itab,
string_a(10) type c,
end of itab.
string_a = '1234567890'.
now i want to add X after 12345 it mean string_a = 12345X67890.I need exactly in 6th postion X and then modify the internal table.
Advanced Thanks
Suresh Babu Karanam
Hi Guys:
I have to add one charecter inthe existing filed.
example:
data : begin of itab,
string_a(10) type c,
end of itab.
string_a = '1234567890'.
now i want to add X after 12345 it mean string_a = 12345X67890.I need exactly in 6th postion X and then modify the internal table.
Advanced Thanks
Suresh Babu Karanam
2005 Jan 11 3:00 PM
but here string_a must be at least 11 characters.
data:
zi type i
zi = strlen( string_a ).
right = zi - 7.
string_a7(right) = string_a7.
string_a+6(1) = 'X'.
-
if it helps please give points.
Message was edited by: Fuat Ulugay
2005 Jan 11 3:07 PM
now out is like string_a = 12345X7890. I am loosing actuval 6 number in the string.
2005 Jan 11 3:09 PM
I modified it try it again with new code.
and tested it.
The code below works.
DATA:
zi TYPE i,
right TYPE i.
string_a = '1234567890'.
zi = strlen( string_a ).
right = zi - 6.
string_a7 = string_a6(right) .
string_a+6(1) = 'X'.
Message was edited by: Fuat Ulugay
2005 Jan 11 3:19 PM
Thanks Fuat Ulugay. You are right i have increased string length.
loop at itab.
REPLACE FIRST OCCURRENCE OF '6' IN itab-string_a WITH 'X6'.
modify
endloop.
2005 Jan 11 3:25 PM
Yes this is a better solution
shortest is the best.
REPLACE '6' into string_a WITH 'X6'.
2005 Jan 11 3:22 PM
Hi Suresh,
Check the below code. It will give the exact result you need,
REPORT zc1test_string .
DATA : old_str(10) TYPE c,
new_str(11) TYPE c.
old_str = '1234567890'.
This moves 5 characters to new_str
MOVE old_str TO new_str PERCENTAGE 50.
*now removing the first 5 chars in old_str
SHIFT old_str BY 5 PLACES LEFT.
*joining them together
CONCATENATE new_str 'X' old_str into new_str.
write:/ new_str.
In your program make sure the final field should be of size 11 to hold the extra value.
Thanks and Regards,
Kathirvel.
2005 Jan 11 3:25 PM
Hi Suresh,
You can use the coding below.It is an example for both string and char variables :
DATA : lv_str TYPE string VALUE '1234567890',
lv_char TYPE char11 VALUE '1234567890'.
CONCATENATE lv_str+0(5)
'X'
lv_str+5(5)
INTO lv_str.
WRITE / lv_str.
CONCATENATE lv_char+0(5)
'X'
lv_char+5(5)
INTO lv_char.
WRITE / lv_char.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |