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

String truncate?

Former Member
0 Likes
6,811

Hi,All:

I want to truncate a string. but I just need the right side 4 digits.

Is there any function module to implement it.

for example '123456', I just need '3456'.

for example '12345' , I just need '2345'.

Thanks,

10 REPLIES 10
Read only

Former Member
0 Likes
2,366

length = strlen('PRABHU').

length = length - 4.

output = input+length(4).

Regards

Peram

Read only

0 Likes
2,366

Hi Praghu,

be carefull if length < 4.

Regards, Dieter

Read only

Former Member
0 Likes
2,366

Hi!

lv_length = strlen(your_string).

subtract 4 from lv_length.

WRITE:/ your_string+lv_length(4).

Regards

Tamá

Read only

Former Member
0 Likes
2,366

do this way...

v_str = strlen ( field ).

v_str1 = v_str - 4.

field1 = field+v_str(4).

Read only

Former Member
0 Likes
2,366

Hi Yunfa,

You can use <b>strlen</b> option to find the length of the string.

Now deduct 4 from the length and store that in a variable say 'v_len'.

Now you can have <b><field>+v_len(4)</b> for your solution.

<b>Reward points if this helps,</b>

Kiran

Read only

Former Member
0 Likes
2,366

Hi,

try this:

DATA: STR TYPE STRING VALUE 'testfrom2007'.

DATA: CSTR(4).

DATA: STRL TYPE I.

*

STRL = STRLEN( STR ).

IF STRL > 4.

STRL = STRL - 4.

CSTR = STR+STRL(4).

ELSE.

CSTR = STR.

ENDIF.

*

WRITE: CSTR.

Regards, Dieter

Read only

Former Member
0 Likes
2,366

hi yunfa.......

try out this coding:

data:
     test type string VALUE '12345678909',
     len type i,
     result type i.


    len = STRLEN( test ).   " find the length of the string
    len = len - 4.                "determines the offset
     result = test+len(4).     " produces the last 4 digits

---regards,

alex b justin

Read only

Former Member
0 Likes
2,366

You can use it for wa_test as char or wa_test2 as string...

Regards,

Laurent

data wa_test(12) type c value '0123456789'.

data wa_test2 type string value '0123456789'.

data wa_count type i.

condense wa_test2 no-gaps.

wa_count = strlen( wa_test ) - 4. " <- 4 is the count of digit you need

shift wa_test by wa_count places left.

write : / wa_test.

Read only

Former Member
0 Likes
2,366

hI zhang,

str = 123456

len = strlen ( str ) -> len = 6

str1 = len - 4.

final_str = str + str1(4) -> 2(6).

Reward points for all helpful ans;s.

kiran.M

Read only

former_member194669
Active Contributor
0 Likes
2,366

Hi,

Try this code


report  ztest_46.
types : begin of t_t,
        v_1(1) type c,
        v_2(10) type c.
types : end of t_t.
data : wa_t type t_t.

move '123456' to wa_t.

write : wa_t-v_2.

move '12345' to wa_t.
write : wa_t-v_2.

aRs