‎2008 Jul 04 5:56 AM
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
‎2008 Jul 04 6:31 AM
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.
‎2008 Jul 04 6:13 AM
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
‎2008 Jul 04 6:27 AM
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.
‎2008 Jul 04 6:31 AM
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.
‎2008 Jul 04 6:31 AM
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.
‎2008 Jul 04 8:35 AM
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.
‎2008 Jul 04 8:42 AM
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