Application Development 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: 

How to get Substring in ABAP

Former Member
0 Kudos

Hi Experts,

I want to get the substring from a string. Actually I have material description which is "P KRA/KPC DCB 2.5X270 SAPH 341", in this material description substring "2.5X270" is the thickness of the material. I want to get this thickness in my report. All the material descriptions have thickness in them as above. I want to get this and the description length is different for materials and the thickness will be different also like "127X40.5" etc.

Please help me out.

Regards

Sameer

2 REPLIES 2

Former Member
0 Kudos

1st, you have to define the sign that "the thickness" is begin.

2nd, define how many lenght of "the thickness".

0 Kudos

I use " " (space) as separator to find "the thickness". Warning, you have to check all the combination of material description, since there is no solid separator to define "the thickness".

=====================================================

DATA: ld_string TYPE string,
       ld_result TYPE string,
       ld_starts TYPE i,
       ld_length TYPE i,
       ld_counts TYPE i,
       ld_founds TYPE i.

ld_string = 'P KRA/KPC DCB 2.5X270 SAPH 341'.
ld_length = strlen( ld_string ).

CLEAR ld_founds.
DO ld_length TIMES.
ld_counts = SY-INDEX - 1.
   IF ld_string+ld_counts(1) = ' '.
     IF ld_founds EQ 0.
       ld_starts = ld_counts.

       ADD 1 TO ld_founds.
     ELSEIF ld_founds EQ 1.
       ld_length = ld_counts - ld_starts.

       ADD 1 TO ld_founds.

     ENDIF.
   ENDIF.
ENDDO.

IF ld_founds >= 1.

   ld_result = ld_string+ld_starts(ld_length).

ENDIF.