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 SPLIT Command

Former Member
0 Likes
46,673

Hi Guys,

I need some help.

I need to SPLIT data that I am gathering in SAP to pass to an interface.

Street and House Number field  looks like :   " Avenue Boulevard 235 C"

What I need is ALL before number in field a, number in field b, all after number in field c.

What I have into the program is in attachment.

I have tried a couple of things with no success, please help. quite urgent.

Next time do not post any urgent threads on SCN! (Why?? - Read the forum RoE)

Thank you

F

Message was edited by: Suhas Saha

Message was edited by: Suhas Saha

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
20,172

Hi Guys,

Unfortunatelly I tried a couple of solutions but none of them work.

I will try to be more specific:

I need to SPLIT data that I am gathering in SAP to pass to an interface.      Street and House Number field  looks like :   " Avenue Boulevard Margout 235 C"      What I need is ALL before number in field a, number in field b, all after number in field c.

field a ) should contain " Avenue Boulevard Margout " and all spaces MUST remain because they need to feed the interface as is. If they are without spaces, outsourced system does not read data.

field b) should contain "235"

field c) should contain "C" - which means everything else in this string after number.

I need to pass those values so i am not looking to write them in the output ....

Please help. Any help is highly appreciated!

34 REPLIES 34
Read only

Former Member
0 Likes
20,172

This is the code into my program:

data:

str5 type string,

str6 type string,

str7 type strring,

stringstreet type string,

i_streethause_tab type table of string,

textstras type string.

....

split textstras at space into str5 str6 str7,

table i_streethause_tab.

Read only

Former Member
0 Likes
20,172

Anyone to help please?

Read only

0 Likes
20,172

Data: numberpassed type c.

loop at i_streethause_tab into wa_streethouse.

if wa_streethouse CO '0123456789'.

* here is your number field

   move wa_streethouse to numberfield.

   numberpassed = 'X'.

else.

   if numberpassed  = 'X'.

        concatenate afternumberfield wa_streethouse into afternumberfield.

   else.

        concatenate streetfield wa_streethouse into streetfield.

   endif.

endif.

endloop.

Read only

0 Likes
20,172

This message was moderated.

Read only

Former Member
0 Likes
20,172

Hi Fafa,

Follow the logic in this thread.

http://scn.sap.com/thread/1388064

If there is going to be only three parts, you can follow this logic.

DATA : str1 TYPE c,
        str2 TYPE string,
        str7 TYPE string,
        c TYPE string,
       stringstreet TYPE string,
       i_streethouse_tab TYPE TABLE OF string,
       len TYPE i,
       counter TYPE i, begin TYPE i, offset TYPE i.
stringstreet = ' Avenue Boulevard 235 C'.
begin = 0.
counter = 0.
len = STRLEN( stringstreet ).

* First part.

DO .
   str1 = stringstreet+counter(1).
   IF str1 CO '0123456789'.
     str2 = stringstreet+begin(counter).
     APPEND str2 TO i_streethouse_tab.
     begin = counter.
     EXIT.
   ENDIF.
   counter = counter + 1.
ENDDO.

* Second part.

clear str2.
DO.
   counter = counter + 1.
   str1 = stringstreet+counter(1).
   IF str1 NA '0123456789'.
     offset = counter - begin.
     str2 = stringstreet+begin(offset).
     APPEND str2 TO i_streethouse_tab.
     begin = counter.
     EXIT.
   ENDIF.
ENDDO.

* Third part

CLEAR str2.
offset = len - begin.
str2 = stringstreet+begin(offset).
APPEND str2 TO i_streethouse_tab.

LOOP AT i_streethouse_tab INTO str7.
   WRITE 😕 str7.
ENDLOOP.

Output


Read only

0 Likes
20,172

Thank you for posting.

It did not work for me though.

But big thanks anyways!

Read only

Former Member
0 Likes
20,172

data: str type string value 'Avenue Boulevard 235 C'.

data: str type string value 'Avenue Boulevard 235 C'.

data: str1 type string,

       str2 TYPE string,

       str3 type string,

       str4 type string.

data: itab type table of string.

data: wa LIKE LINE OF itab.

SPLIT str at space into:  str1 str2 str3 str4, table itab.

WRITE: str1.

WRITE😕 str2.

WRITE😕 str3.

WRITE😕 str4.

loop at itab into wa.

   write😕 wa.

   ENDLOOP.

Read only

former_member188282
Active Participant
0 Likes
20,172

Try this code:

data: str(100),      

len type i,      

counter type i,      

symb. data: begin of itab occurs 0,      

flag,      

str(20),      

end of itab.

data: begin of xtab occurs 0,      

str(20),      

end of xtab.

str = '56ddfdfhh hjhj 12 ggh fss 33s-yuyu'. len = strlen( str ).

do len times. 

symb = str+counter(1).  

itab-str = symb.  

if symb CO '0123456789'.    

itab-flag = 'N'.  

else.    

itab-flag = 'C'.  

endif.  

append itab.  

counter = counter + 1.

enddo. 

loop at itab.  

at new flag.    

clear xtab. 

endat.   

concatenate xtab-str itab-str into xtab-str.   

at end of flag.    

append xtab.  

endat.

endloop

Regards,

Rajesh

Read only

Former Member
0 Likes
20,172

Regular expression can give desired result in one line.

DATA: a TYPE string,
      b TYPE string,
      c TYPE string.
a = 'Avenue Boulevard 235 C'.
FIND REGEX '(\D+)(\d.*)' IN a SUBMATCHES b c.
WRITE:/ b,
      / c.

Read only

Former Member
0 Likes
20,172

DATA LV_B(10) TYPE N.

LV_ADDRESS = " Avenue Boulevard 235 C"

LV_B = LV_ADDRESS.  ----Since this is of type N only numbers will be stored here charachters will be ignrored

SPLIT LV_ADRESS AT LV_B into LV_A LV_C.

Read only

Former Member
0 Likes
20,173

Hi Guys,

Unfortunatelly I tried a couple of solutions but none of them work.

I will try to be more specific:

I need to SPLIT data that I am gathering in SAP to pass to an interface.      Street and House Number field  looks like :   " Avenue Boulevard Margout 235 C"      What I need is ALL before number in field a, number in field b, all after number in field c.

field a ) should contain " Avenue Boulevard Margout " and all spaces MUST remain because they need to feed the interface as is. If they are without spaces, outsourced system does not read data.

field b) should contain "235"

field c) should contain "C" - which means everything else in this string after number.

I need to pass those values so i am not looking to write them in the output ....

Please help. Any help is highly appreciated!

Read only

0 Likes
20,172

please help, I really appreciate if you could.

Read only

0 Likes
20,172

This snippet extract 235 and C from given string using regular expression.

DATA: a TYPE string,
      b TYPE string,
      c TYPE string.
a = 'Avenue Boulevard 235 C'.
FIND REGEX '(\d+)\s*(.*)' IN a SUBMATCHES b c.
WRITE:/ b,
      / c.

Read only

0 Likes
20,172

Hi Fafa,

Try using the shift command to find the beginning and ending postions of the numbers and then use the postions numbers to parse the field.  In this case you would not need the split command.

Here's an example of what I am trying to say:

data: wa_street_house char 80,

        wa_begin type i,

        wa_end   type i.

loop at i_street_house into wa_street_house

  l_street_house =  wa_street_house.

  do 80 times.

     if l_street_house(1) CO '0123456789'.

        if wa_begin is initial.

          wa_begin = sy-index.

        else.

          wa_end  = sy-index.

        endif.

     endif.

     shift l_street_house left by 1 space.

  enddo.

  l_numb = wa_end - wa_begin.

  wa_str5 = wa_street_house+0(wa_begin)

  wa_str6 = wa_street_house+wa_begin(l_numb)

  wa_str7 = wa_street_house+wa_end( the rest .....)

endloop.

You may have to adjust some of the index values but I think this will get you close.

Regards,

Steve

Read only

0 Likes
20,172

Thank you Steve.

Will try to use this logic but not sure I can as it will change code a lot.

But thank you anyways, will try.

Any Expert that could give me some light into SPLIT would be appreciated.

Thank you!

Read only

0 Likes
20,172

Hi Fafa

Did you try running logic posted by me?

Read only

0 Likes
20,172

Hi Manish,

I did but it does not work for what I need.

I need to pass result structure for the interface not display output.

If i can pass structure with your code, please enlighten me.

Thank you

Fafa

Read only

0 Likes
20,172

Hi Fafa,

you might want to enlighten us on what type of interface structure all the results should come together - since I think all solutions provided are looking quiet sufficient.

Best,

Sander

Read only

0 Likes
20,171

Manish just used WRITE command as example, you don't need to write as output, just pass the variables a,b,c to your structure.

Read only

0 Likes
20,171

This is the TRY.

  TRY.

       ls_request-name = ls_addr_list-nachn.

       ls_request-street = str5.

       ls_request-haus_nr = str6.

       ls_request-Plz = ls_addr_list-pstlz.

       ls_request-ort = ls_addr_list-ort01.

      

ENDTRY.

Read only

0 Likes
20,171

Hi Fafa and for this LS_REQUEST structured variable, which kind of TYPE is defined?

   

Read only

0 Likes
20,171

Are you able to debug? Does str5 and str6 contain the values that you need ? after attributions does ls_request filled as you expect?

Read only

0 Likes
20,171

Hi Sander,    this is the ls_request structure.   ls_request          TYPE ZWS_INPUT   The problem is that with all the codes provided, I still cannot pass the correct values.   Yes, I did debug and the values are never passed correctly, in any of the cases.   Remember that I need:   field a ) should contain " Avenue Boulevard Margout " and all spaces MUST remain because they need to feed the interface as is. If they are without spaces, outsourced system does not read data.  field b) should contain "235"  field c) should contain "C" - which means everything else in this string after number.  NOTE: When I used str5 str6 and etc before it did work but the problem was that if a Street Name was longer e.g Rua de Monaco Prince ... the string for Number was being filled with another peace of the street name ... so I know my code has no issues, i just need to find a way to separate the fields and pass them correctly.   Hope i could clarify ....

Read only

0 Likes
20,171

Hi Felipe,   In my simple old code with SPLIT :    split textstras at space into str5 str6 str7,  table i_streethause_tab.    yes, but I will try to elaborate better my problem.    I was separating the field STRAS from internal table into  Str5 Str6 Str7  Look at the example:   Sunnystreet 21 A   Then Str5 would return SunnyStreet Str6 would return 21 and Srt7 would return A. That was working perfectly.   BUT   The majority of streets are:   Sunny Street Honey 21 A  or  Sunny Honey 21 A  or  Sunny Street Honey Moon 21 A   Then I could not get the data correct all the time ...  Hope I was clear now.  NOTE: If interface would accept concatenation of Street names I would do that and have no problem, but it does not.  I need to pass values with spaces in between even if the street name is made of 30 names with spaces in between.  Only stop indicator for the street name is the Street Number ( which unfortunately occupy the same field in my system ).

Read only

0 Likes
20,171

Check this one:

DATA: lv_street TYPE string,

       lv_numb   TYPE string,

       lv_compl  TYPE string,

       lv_off    TYPE i.

lv_street = 'Avenue Boulevard 235 C'.

FIND REGEX '(\d+)\s*(.*)' IN lv_street SUBMATCHES lv_numb lv_compl  MATCH OFFSET lv_off.

lv_street = lv_street(lv_off).

CONDENSE: lv_street, lv_numb, lv_compl.

WRITE:/ lv_street,

       / lv_numb,

       / lv_compl.

Read only

0 Likes
20,171

Thank you so much Felipe,  It worked great!!!

Read only

0 Likes
20,171

Hello Felipe,   I used your code but now that i go for all employes I notice I have a major error:   I am having a run time error : illegal access to a string ( lenght too large )   error is exactly here:         lv_street = lv_street(lv_off).   Please help!   Anyone is welcome to ...

Read only

0 Likes
20,171

I am having issue now that I am testing to all employees.   Issue is right here.       lv_street = lv_street(lv_off).   Run time error. Lenght is too long.   However, this lenght (13) exceeded the current lenght of the string (7) This kind of access is illegal .   Anyone to help please?

Read only

0 Likes
20,171

Category: Abap programming error Runtime errors: STRING_LENGTH_TOO_LARGE Exp. CX_SY_RANGE_OUT_OF_BOUNDS

Read only

0 Likes
20,171

you might consider starting a new discussion, since this one is marked answered.

Read only

Former Member
0 Likes
20,172

Some expert to chime in?

The code for the interface is so extensive that I would really rather to keep the SPLIT as I have it also in other areas.

I am feeding webservices so I really need to pass straight to the call.

Read only

0 Likes
20,171

I am trying to pass values into

TRY

ENTRY

to feed my interface.

Read only

0 Likes
20,171

Hi Fafa,

I don't think you can do it using only the SPLIT command.  It does not have the options you require. 

I also don't understand why you can insert other options.  You say the code is very extensive but it should still allow you to insert new code or a PERFORM.

Regards,

Steve

Read only

Former Member
0 Likes
20,171

This message was moderated.