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

read data string from right to left

Former Member
0 Likes
4,308

hi guys,

i need some advice on the coding.


      READ TABLE it_zsd_mat_format INTO wa_zsd_mat_format WITH KEY
                 matnr = wa_zsdserial-material BINARY SEARCH.

      w_st1 = wa_zsd_mat_format-matlength.
      w_st2 = wa_zsdserial-serial_num(w_st1).

the above gave me the wrong data, because i want to take the number from right to left, but above code take the number from left to right. can any one help me how to code to get the wa_zsdserial-serial_num from right to left?

thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,733

Hi Lee,

You can use a function module 'STRING_REVERSE'.

For your case wa_zsdserial-serial_num should of type 'C' or type 'N'.

DATA: v_reverse_strng(80) TYPE c,

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = wa_zsdserial-serial_num

lang = sy-langu

IMPORTING

rstring = v_reverse_strng

EXCEPTIONS

too_small = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE v_reverse_strng.

**************************************************

You can use v_reverse_strng as type of wa_zsdserial-serial_num but both should be either of type 'N' or 'C', otherwise it may give Short Dump.

Please reward if it helps.

6 REPLIES 6
Read only

Former Member
0 Likes
1,733

Hi,

data : lv_len type i.

data : lv_num type i.

READ TABLE it_zsd_mat_format INTO wa_zsd_mat_format WITH KEY

matnr = wa_zsdserial-material BINARY SEARCH.

w_st1 = wa_zsd_mat_format-matlength.

lv_len = STRLEN( wa_zsdserial-serial_num ).

lv_num = lv_len - w_st1.

w_st2 = wa_zsdserial-serial_num+lv_num(w_st1).

clear : lv_len,lv_num.

Try this code yur probelm will solve.

Reward if useful..

Thanks,

Durai.V

Read only

Former Member
0 Likes
1,733

Hi,

I presume you are wanting data like 'value' and instead getting it like ' value'.

If that is the case, please use CONDENSE w_st2.

That will take care of the problem.

Regards,

Prosenjit.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,733

Just refer this sample code...u will get it


TYPES:BEGIN OF tt,
      val TYPE string,
     END OF tt.
DATA:itab TYPE TABLE OF tt.
DATA:wa TYPE tt.
DATA:length TYPE i.
DATA:out TYPE string.

wa-val = 'ABCDEFG'.
APPEND wa TO itab.
wa-val = '123456789'.
APPEND wa TO itab.

LOOP AT itab INTO wa.
  CLEAR length.
  length = STRLEN( wa-val ).
  length = length - 1.
  WHILE length >= 0.
    IF sy-index = 1.
      out = wa-val+length(1).
    ELSE.
      CONCATENATE out wa-val+length(1) INTO out.
    ENDIF.
    CONDENSE out NO-GAPS.
    length = length - 1.
  ENDWHILE.
  WRITE / out.
ENDLOOP.
Read only

Former Member
0 Likes
1,734

Hi Lee,

You can use a function module 'STRING_REVERSE'.

For your case wa_zsdserial-serial_num should of type 'C' or type 'N'.

DATA: v_reverse_strng(80) TYPE c,

CALL FUNCTION 'STRING_REVERSE'

EXPORTING

string = wa_zsdserial-serial_num

lang = sy-langu

IMPORTING

rstring = v_reverse_strng

EXCEPTIONS

too_small = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

WRITE v_reverse_strng.

**************************************************

You can use v_reverse_strng as type of wa_zsdserial-serial_num but both should be either of type 'N' or 'C', otherwise it may give Short Dump.

Please reward if it helps.

Read only

0 Likes
1,733

hi,

what i want is example:

correct result:

input : 000000000012345678

string length i want is 12

output:000012345678

but the code above i enter got the result of

output:000000000012, which is wrong.

so how am i going to code to read from right side of the character, to the left side.

Read only

0 Likes
1,733

hi Ben,

you have to do something like:

SHIFT string RIGHT BY 12 PLACES CIRCULAR.

now the first 12 character of string is what you need.

hope this helps

ec