Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

add charecter

Former Member
0 Likes
1,240

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

7 REPLIES 7
Read only

Former Member
0 Likes
1,134

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

Read only

Former Member
0 Likes
1,134

now out is like string_a = 12345X7890. I am loosing actuval 6 number in the string.

Read only

0 Likes
1,134

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

Read only

Former Member
0 Likes
1,134

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.

Read only

0 Likes
1,134

Yes this is a better solution

shortest is the best.

REPLACE '6' into string_a WITH 'X6'.

Read only

Former Member
0 Likes
1,134

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.

Read only

Former Member
0 Likes
1,134

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.