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

Split and pick

kiran_k8
Active Contributor
0 Likes
949

Hi Folks,

I need to pick the data from a field and dispaly it as two fields.Can anyone here let me know how to go with this.

addr1_data-remark:-(table is addr1_data and the field is remark).

now i have to pick the contents from the field "remark" of table "addr1_data",split it into two to fill in two fields namely registration and tax-id.

If I am confusing you with the fields and the content just let me know the way to split the data.

Points will be given.

K.Kiran.

11 REPLIES 11
Read only

Former Member
0 Likes
911

you can split one field into two by using the SPLIT statment. but you will need a delimiter to use this statment

SPLIT addr1_data-remark at space into registration taxid.

in this case we are using SPACE as delimiter

for examlple if you have 'ABCDEF 12345' in the remark field. the split statement will split the data at SPACE and put 'ABCDEF' in the field registration and '12345' in the field taxid.

-Kalyan

Read only

0 Likes
911

Kalyan,

What if that field has multiple spaces?

I mean if addr1_data-remark has the followding data:- kiran vijayawada 520003.

now i have to fetch "kiran vijayawada" into registration and 520003 into taxid.

as per your words the syntax should be--- SPLIT ADDR1_DATA-REMARK AT SPACE INTO REGISTRATION TAXID.Am I right?

Points given.

Thanks,

K.Kiran

Read only

0 Likes
911

Try this for multiple spaces. You'll need to fiddle with the data definitions. Theoretically you can just have the itab be made up of a single line of type string, but I kept getting an error and I don't have time to dig into why.


report ybctest.

PARAMETERS: text(50) TYPE c.

DATA: BEGIN OF itab OCCURS 0,
        line(20) type c,
      END OF itab.

data: test type string.

DATA: name(20) TYPE c,
      id(10) TYPE c.

SPLIT text AT space INTO TABLE itab.

LOOP AT itab.

  condense itab-line.
  test = itab-line.

  IF test CO '0123456789'.
    id = itab-line.
    DELETE itab.
  ENDIF.

ENDLOOP.

LOOP AT itab.
  CONCATENATE name itab-line INTO name SEPARATED BY space.

ENDLOOP.

WRITE: / 'name: ', name.
WRITE: / 'ID: ', id.

Read only

0 Likes
911

Hi Kiran,

for things like spliting text, you should define a fixed structue whether two spaces or one space, You will not be able to handle all the cases generically. You can ask the users to enter the data in the remark field in a certain format. if they enter it right you can split it correctly, if they enter it wrong it will be at their own peril.

if possible as them to enter it this way ,

'Kiran vijayawada : 1234567' , this way you can split at the character ':' and get the data into the two fields.

- Kalyan

Read only

0 Likes
911

Hi,

If you are sure that your field is under this format: letters numbers, you shoul try to use TRANSLATE myText USING '0 1 2 3 4 5 6 7 8 9 '

all numbers will be replace by space, so you get the first part of the field. Get its lenght using strlen.

Then you can get the second part of the field using offset: myField+lengh_first_part(total_lenght)

Hope it will help you

Read only

0 Likes
911

Bryan,

The code you have given is Sexy.It is working perfectly,but I have to do some fine tuning to fit that into my requirements.

Points given.

Thanks,

K.Kiran.

Read only

Former Member
0 Likes
911

Hi

What is the criteria for the split? The SPLIT command is the easiest if you are splitting the field at a specific character.

  SPLIT remark AT (something) INTO registration tax_id .

Otherwise you will have to do a bit of string manipulation, I guess?

Cheers

Lyal

Read only

Former Member
0 Likes
911

There has to be some rule as to how you are going to split it. Otherwise it will not be correct. It has to be either fixed length values or separated by something. If they are fixed length values, then all you have to do is to move the offsets


move: remarks+0(xx) to registration,
      remarks+yy(zz) to taxid.

If they are separated by something then split will work as others suggested.

Read only

kiran_k8
Active Contributor
0 Likes
911

Hi Folks,

Thanks alot to everybody.I have one more question.

Addr1_data is a structure.So,I will not be able to retrieve any data from it.

But the screen field is Addr1_data-remarks.

I have to fetch the data given in this screen field.

Now I will be able to retrieve from it as it is not a table but a structure.The data entered in this screen field has to get stored in some or the other table,right?Now how to find where it is getting stored and then retrieving it.

I will try splitting the data as mentioned by you all.

Points given.

K.Kiran.

Read only

Former Member
0 Likes
911

Hi Kiran,

chk the where-used-list of the field REMARK , u can get some some table , u can find out from that

Read only

kiran_k8
Active Contributor
0 Likes
911

problems solved