cancel
Showing results for 
Search instead for 
Did you mean: 

Split Statement

Former Member
0 Kudos

Hi to all Guru's,

before splitting any string if i want to know how many words are there so that i can create a internal table containing same number of fileds.

i want to do some thing like this.

text = `What a drag it is getting old`.

SPLIT text AT space INTO: TABLE itab. "how can i come to know that i need

to create 7 fields.

Thanks & Regards

Priyalatha

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

try like this.

types : begin of struct,

words(50) type c,

end of struct.

data : itab type standard table of struct with header line,

num_words type i.

split text at space into table itab.

describe table itab lines num_words.

num_words contains total no of words in the text.

hope this gives u some idea.

Clemenss
Active Contributor
0 Kudos

Hi,

Full agree to Mathew.

sree ram seems to be one of those software codes that read but don't understand the question and then pasting a plethora of unrelated information hoping for points.

Note that starting with ECC600 you can write

num_words = lines( itab ).

replacing

describe table itab lines num_words

Regards,

Clemens

Former Member
0 Kudos

Hi kamini,

TYPES : BEGIN OF struct,

words(50) TYPE c,

END OF struct.

text = 'I KNOW THIS'.

DATA : i_tab TYPE STANDARD TABLE OF struct WITH HEADER LINE.

SPLIT text AT space INTO TABLE i_tab.

DESCRIBE TABLE i_tab LINES num_words.

HERE I NEED TO CREATE DYNAMIC INTERNAL TABLE AND AGAIN I NEED TO USE SPLIT STATEMENT RYT?

PLEASE READ MY CONCLUSION.

1.you mean to say that after getting num_words(number of words in that internal table) at run time i need to create a dynamic internal table which consist of same numebr of fields and then use again split statement .

2.what if the length of text is more than 50 CHARACTERS.

AND then i need to create dynamic internal table ryt?

do you mean this?

PLEASE GURU'S CLARIFY ME REGARDING THIS

Thanks & Regards

Priyalatha

JozsefSzikszai
Active Contributor
0 Kudos

hi Priya,

can you clarify what do you want to achieve? Independently from what advices you got here from the 'gurus'...

thanks

ec

Former Member
0 Kudos

Hi eric,

This is my problem,

before splitting any string if i want to know how many words are there so that i can create a internal table containing same number of filed's.

then i can use split text at space into table itab.

but to create itab i need to know how many fields i have to create in that internal table?

if i use this then,

TYPES : BEGIN OF struct,

words(50) TYPE c,

END OF struct.

text = 'I KNOW THIS'.

DATA : i_tab TYPE STANDARD TABLE OF struct WITH HEADER LINE.

SPLIT text AT space INTO TABLE i_tab.

DESCRIBE TABLE i_tab LINES num_words.

HERE I NEED TO CREATE DYNAMIC INTERNAL TABLE AND AGAIN I NEED TO USE SPLIT STATEMENT RYT?

PLEASE READ MY CONCLUSION.

1.you mean to say that after getting num_words(number of words in that internal table) at run time i need to create a dynamic internal table which consist of same numebr of fields and then use again split statement .

2.what if the length of text is more than 50 CHARACTERS.

AND then i need to create dynamic internal table ryt?

help me out if you can

Thanks & regards

Priyalatha

JozsefSzikszai
Active Contributor
0 Kudos

Priya,

you have to understand the following:

the SPLIT ... INTO TABLE ... will split the words into lines of the internal table and NOT into fields. So I don't really understand why do you want to create dynamic internal table with proper number of fields.

The real question is : You have a string (a sentence in fact), you sllit that into words (on way or another). What do you want to do with these words after the split?

ec

Former Member
0 Kudos

Hi Priya,

>before splitting any string if i want to know how many words are there so that i >can create a internal table containing same number of filed's.

I can provide you solution for this...remaining sort out with eric...check this code..


DATA string(70) VALUE 'This is a little sentence adas asdasd asdasd.'.
DATA : word TYPE i,
       words TYPE i.

word = STRLEN( string ).
CONDENSE string NO-GAPS.
words = STRLEN( string ).

word = ( word - words ) + 1.

WRITE 😕 'Number of words :', word.

Former Member
0 Kudos

Hi eric,

so u mean to say that if i have one character field in the internal table of length 50

then split will automatically splitt the fields and puts into internal table.This u want to say ryt?

Thanks & Regards

Priya

Former Member
0 Kudos

This is exactly what i needed.

Thank you Perez C

really thank you very much

Former Member
0 Kudos

but Perez C

after that code again i need to create dynamic internal table which contains 8 fields,is there any way so that i can avoide this?

Thanks

Priya

matt
Active Contributor
0 Kudos

Priya - look carefully: Eric is right. But don't define a table with record type char(50), define one with record type STRING.

<b>

DATA: mytab TYPE table_string.

DATA: mystring TYPE string `This is my string`.

SPLIT mystring AT SPACE INTO TABLE mytab</b>

Will put 'This' as the first record of mytab. The second record will have 'is'. The third record will have 'my', the fourth record will be 'string'.

You don't need a dynamic table. You don't need to know how many words beforehand. You don't need to know the length of the words beforehand. If your first word to be one thousand characters long, it will still work.

matt

Clemenss
Active Contributor
0 Kudos

Hi priya,

Perez C's code will return the wrong number if two words are separated by more than one space.

Erics question about what you really want to achieve remains a secret.

do as follows: first split into table of strings.

Then define a table with fields as maximum number od words.

loop at the string table and dynamically transfer the values using ASSIGN COMPONENT n OF STRUCTURE.

Regards,

Clemens

Former Member
0 Kudos

Hi Matthew ,

So you want to conclude that split statement will take care everything only thing is we need to create a internal table with one field which is of type string then execute the split statement then check for that string in that internal table,

i will get the splitted records in that table.

Correct me if i am wrong

Thank you very very much

Priyalatha

matt
Active Contributor
0 Kudos

It sounds right to me. But I'm still not entirely clearly what you're trying to achieve. Try what's been suggested, and see if it works!

One poster has raised the issue of more than one space between words. To deal with this, use CONDENSE mystring, before the SPLIT command.

cheers

matt

Former Member
0 Kudos

Hi priya,

in repsonse to CLEMENS issue..add one extra statement.. problem will solve..



DATA string(70) VALUE 'This is a little sentence adas asdasd          asdasd.'.
DATA : word TYPE i,
       words TYPE i.

CONDENSE string.  "extra statement

word = STRLEN( string ).

CONDENSE string NO-GAPS.
words = STRLEN( string ).

word = ( word - words ) + 1.

WRITE 😕 'Number of words :', word.

Message was edited by:

Perez C

JozsefSzikszai
Active Contributor
0 Kudos

"check for that string in that internal table"

one thing to correct: check <b>for the number of lines</b> in that internal table

Answers (8)

Answers (8)

Former Member
0 Kudos

Hi,

priya

data: begin of wa1,

ch(10) type string,

end of wa1.

data: itab1 like table of wa1.

data:w_int type i.

split 'i know you know' at space into table itab1.

loop at itab1 into wa1.

w_int = w_int + 1.

endloop.

WRITE: / W_INT.

TRY THIS CODE

PLZZZZ REWARD IF USEFULLL

Former Member
0 Kudos

Thanks to all Guru's

matt
Active Contributor
0 Kudos

So far, only Eric has the correct answer. Stick to his.

matt

Former Member
0 Kudos

Hi Priya,

Try this program

data: text(50) type c value  '0011 1110 0111 1100 1111 1001 0011 0101',
      len type i,
      ind type i,
      pos type i,
      cnt type i.
 
len = strlen( text ).
 cnt = 1.
do len times.
 ind = sy-index.
 pos = sy-tabix.
 if text+ind(pos) = ' '.
  cnt = cnt + 1.
 endif.
enddo.
write cnt. " CNT will have total number of words.

Regards,

Satish

sreeramkumar_madisetty
Active Contributor
0 Kudos

Hi Priya

First understand the importance of split command and when we go for split command.

see the example:

Split valuation enables you to valuate sub-stocks of a material in different ways (for example, according to external procurement or in-house production or by batches).

Recommended valuation levels are at Plant level.

In split valuation, you can distinguish between partial stocks of a material according to certain criteria and valuate them separately.

The material stock is divided according to valuation category and valuation type:

The valuation category determines how the partial stocks are divided, that is, according to which criteria.

The valuation type describes the characteristics of the individual stocks.

With the function "Setting" you can determine:

which valuation categories exist in your company (global categories)

which valuation types exist in your company (global types)

which valuation types belong to which valuation category

which valuation categories exist in a valuation area (local categories)

Your entries are only relevant if you set split valuation as active in the function "Global settings".

In the standard SAP R/3 System, the following valuation categories are preset:

Example:

B procurement type

with the valuation types:

"EIGEN" for in-house production

"FREMD" for external procurement

H Origin

X automatic valuation (only for batch)

Actions

To select split valuation, proceed as follows:

1. Determine the valuation categories and valuation types that are allowed for all valuation areas:

global valuation categories via menu "Goto --> Global Categories"

global valuation types via menu "Goto --> Global Types"

2. Allocate the valuation types to the valuation categories.

a) Select "Goto --> Global Categories".

b) Position the cursor on a valuation category and select "Goto --> Global Categories --> Allocations --> Types->Category".

c) Activate the valuation types you want.

3. Determine the local valuation categories for each valuation area.

a) Select "Goto --> Local definitions".

b) Position the cursor on a valuation area and select "Goto --> Local Definitions --> Allocate Categoires->Org.units". You obtain a list of the global valuation categories.

c) Activate the categories to be used in this valuation area.

The system creates the local valuation types based on the allocations under point 2.

Only now can you create a master record with split valuation.

Please refer below link

http://www.sap-img.com/mm025.htm

Regards,

Sree

JozsefSzikszai
Active Contributor
0 Kudos

hi Prya,

the SPLIT statement will split the words not into fields of the internal table, but into different lines. Your internal table will look like after SPLIT:

What

a

drag

it

is

getting

old

hope this helps

ec

Former Member
0 Kudos

Hi Priya,

Yes you have to create all fields.

What you can do is to create a Internal table with a exhaustive number of fileds ( for eg : 100 ).

data: begin of st1,
ch01(50) type c,
ch02(50) type c,
ch03(50) type c,
....
ch99(50) type c,
end of st1.
data: itab1 like table of st1.

OR,

<i>If each record have the same number of splitted fields, you can count them and create a dinamyc table.</i>

Hope this helps,

Erwan

Former Member
0 Kudos

you can do like this...

data: begin of wa1,

ch(10) type c,

end of wa1.

data: itab1 like table of wa1.

split 'i know you know' at space into table itab1.

loop at itab1 into wa1.

write:/ wa1-ch.

endloop.