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

ABAP

Former Member
0 Likes
1,052

Hi all,

How will i get the last 6 letters from a variable that is of type character? And in that 6 letters i should not take preceding zero's if any.

TIA,

sinthu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,016

hi

use <b>offset</b>

data : str(16) value '111003456',

temp(10) type c,

c ,

a type i value 0,

count type i,

j type i value '0'.

count = strlen( str ).

a = strlen( str ).

count = count + 1.

do count times.

c = str+a(1).

if c ne '0'.

if j = 7.

exit.

else.

concatenate c temp into temp.

j = j + 1.

endif.

endif.

a = a - 1.

enddo.

write 😕 temp.

9 REPLIES 9
Read only

Former Member
0 Likes
1,017

hi

use <b>offset</b>

data : str(16) value '111003456',

temp(10) type c,

c ,

a type i value 0,

count type i,

j type i value '0'.

count = strlen( str ).

a = strlen( str ).

count = count + 1.

do count times.

c = str+a(1).

if c ne '0'.

if j = 7.

exit.

else.

concatenate c temp into temp.

j = j + 1.

endif.

endif.

a = a - 1.

enddo.

write 😕 temp.

Read only

0 Likes
1,016

hi Sinthu,

Use <b>offset</b>

i.e,

data var1(10) type c value 'sinthunair'.

var1 = var1 + 3(6) " this statement will fetch the last 6 characters to var1.

write var1 no-zero.

Regards,

Santosh

Read only

Former Member
0 Likes
1,016

hii

len = strlen(string) .

" this will

"calculate the length

" of your string

strlen = strlen - 6 . " since only last 6 letters are

" needed

<b>string_new = string + strlen(6) .</b> " this will

" capture last 6 letters

<b>CONDENSE string_new NO-ZERO NO GAPS .</b>

WRITE:/ string_new .

use offset with no zero and no gaps.

syntax:

<b><f>[+<o>][(<l>)]</b>

The operation of the statement is performed for the part of the field <f> that begins at position <o>+1 and has a length of <l>.

If the length <l> is not specified, the field is processed for all positions between <o> and the end of the field.

String = string1+3(4).

Assuming that string1 = ‘abcdefgjk’.

Here string will contain ‘defg’.

Regards

Naresh

Read only

Former Member
0 Likes
1,016

Hi,

w_length = strlen(w_field)

w_length = w_length - 6

w_newfield = w_field+w_length(6).

condense w_newfield.

Regards,

Ravi

Read only

Former Member
0 Likes
1,016

Hi Sinthu,

You can use Offset, and in case you do not want zeroes.

also use condense.

If this is useful, award points pls..

Regards,

Bharadwaj

Read only

rahulkavuri
Active Contributor
0 Likes
1,016

data: char(10).

data: char2(6).

char2 = char+3(6).

This will work , please award points if found helpful

Read only

Former Member
0 Likes
1,016

Hi,

check this...


REPORT ZTEST_LAST_SIX_WITHOUTZERO                                .

data: char(12),
      six(6),
      len type i,
      len6 type i.

char = '123450000123'.

len = strlen( char ).

len6 = len - 6.

write char+len6(6) to six no-zero.

write six.

regards

vijay

Read only

Former Member
0 Likes
1,016

Hi

Check this code it will work for u

CONSTANTS: lc_6 TYPE i VALUE '6'.

DATA : lv_strlen TYPE i,

xv_offer_num type char20,

yv_offer_6ch type char6.

CLEAR : lv_strlen.

  • Calculate String Lenght

lv_strlen = STRLEN( xv_offer_num ).

  • Take last 6 charectors

IF lv_strlen >= lc_6.

lv_strlen = lv_strlen - lc_6.

yv_offer_6ch = xv_offer_num+lv_strlen(lc_3).

ELSE.

yv_offer_6ch = xv_offer_num.

ENDIF.

Reward Points if solved.

to remove leading zero

conversion_exit_alpha_output........fm and pass yv_offer_6ch has input and output parameter

Reagards.

Read only

Former Member
0 Likes
1,016

Hi Sinthu,

The below code may help you in solving your problem.

data:

cc(10) type c value '0000000089',

len type i.

len = strlen( cc ). "To get length of character string

len = len - 6. "Offset for last six characters

write cc+len(6) no-zero to cc. "no-zeros in the result

condense cc. "Codensing the result

write:/ cc.

Thanks,

Vinay