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: 

ABAP code for trimming.

Former Member
0 Kudos
231

I have a structure data like this:

<b>Consignment Fill-up Reference Nos.: 92001254, 98745521, 36955214 and 62258523</b>

Now my problem is I wanted to trim those numbers and and put it in my declared variables, example:

Data: var1, var2, var3, var4.

var1 = 92001254.

var2 = 98745521

var3 = 36955214

var4 = 62258523

any help will be greatly appreciated.

reward also for useful info

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos
163

small changes:

str1 = 'Consignment Fill-up Reference Nos.: 92001254, 98745521, 36955214 and 62258523'.

constants c_str(10) type c value '0123456789'.

length = strlen(str1).

do length times.

if str1(sy-index) ca c_str.

l_index1 = sy-index.

flag1 = 'X'.

endif.

if str1(sy-index) na c_str and flag1 EQ 'X'.

l_index2 = sy-index.

flag2 = 'X'

endif.

if flag1 EQ 'X' and flag2 EQ 'X'.

move str+l_index1(l_index2-l_index1) to itab-line.

append itab.

clear itab.

clear: flag1,flag2.

endif.

enddo.

reward if solved

12 REPLIES 12

Former Member
0 Kudos
163

Data: var1(8) type c, var2(8) type c, var3(8) type c, var4(8) type c.

or

Data: var1 type i, var2 type i, var3 type i, var4type i.

var1 = 92001254.

var2 = 98745521

var3 = 36955214

var4 = 62258523

varma_narayana
Active Contributor
0 Kudos
163

Hi..

You have to specify the Data type and length while declaring the variables.

Eg:

Data: var1(10) type C,

var2(10) TYPE C,

var3(10) TYPE C,

var4(10) TYPE C.

var1 = '92001254'.

var2 = '98745521'.

var3 = '36955214'.

var4 = '62258523'.

REWARD IF HELPFUL.

Former Member
0 Kudos
163

Hi,

Do as follows

SPLIT field AT ',' INTO: str1 str2 str3.

now your structure seperates the values at , and stores in diff variables

Regards,

Siva chalasani.

<b>reward points if usefull</b>

0 Kudos
163

can you explain more?

0 Kudos
163

Hi,

now you are splitting your field at ',' into separrete variables

when ever it finds a , then the next one will be placed in a new variable

so what i say is replace you 'and' in your field with comma and split at ,

so your [problem will be solved

Regards,

Siva chalasani.

<u><b>Reward points if usefull.</b></u>

Former Member
0 Kudos
163

I mean the whole data is like this:

<b>Consignment Fill-up Reference Nos.: 92001254, 98745521, 36955214 and 62258523</b>

now i want to get only the numbers and set it in the variables. I know what kind of data types but the problem is trimming those numbers

Former Member
0 Kudos
163

HI,

You can do one thing

you are saying your field is having ',' for seperation and for the last one 'AND' is there

now you can replace 'and' with ','.

and use the split command as given above.

Regards,

siva chalasani.

Reward points if usefull.

0 Kudos
163

I understand what you are saying

if i may think the output maybe like this:

correct me if im wrong.

var1 = Consignment Fill-up Reference Nos.: 92001254

var2 = 98745521

var3 = 36955214

var4 = 62258523

0 Kudos
163

Hi,

Yes you are correct

you can do one thing

if your out same always as you menctioned

then you wirte the code

or if it going to change frequently

my answere will not properly

what you can do is

you can use FIND keyword

and find at what position the ' : ' is there in the first string

then you can trim that value

using offset and length

find F1 help on find command you write the statement and trim according to your requirement

example:

FIND patt IN SECTION OFFSET off OF field.

Regards,

Siva chalasani.

<u><b>Reward points if usefull.</b></u>

Former Member
0 Kudos
163

try a logic something like below, i did not test it if it works:

str1 = 'Consignment Fill-up Reference Nos.: 92001254, 98745521, 36955214 and 62258523'.

constants c_str(10) type c value '0123456789'.

length = strlen(str1).

do length times.

if str1(sy-index) ca c_str.

l_index1 = sy-index.

flag1 = 'X'.

endif.

if str1(sy-index) na c_str and fl_flag1 EQ 'X'.

l_index2 = sy-index.

flag2 = 'X'

endif.

if flag1 EQ 'X' and flag2 EQ 'X'.

move str+l_index1(l_index2-l_index1) to itab-line.

append itab.

clear itab.

endif.

enddo.

now itab contains the numbers, u can easily assign to variables

Former Member
0 Kudos
164

small changes:

str1 = 'Consignment Fill-up Reference Nos.: 92001254, 98745521, 36955214 and 62258523'.

constants c_str(10) type c value '0123456789'.

length = strlen(str1).

do length times.

if str1(sy-index) ca c_str.

l_index1 = sy-index.

flag1 = 'X'.

endif.

if str1(sy-index) na c_str and flag1 EQ 'X'.

l_index2 = sy-index.

flag2 = 'X'

endif.

if flag1 EQ 'X' and flag2 EQ 'X'.

move str+l_index1(l_index2-l_index1) to itab-line.

append itab.

clear itab.

clear: flag1,flag2.

endif.

enddo.

reward if solved

Former Member
0 Kudos
163

I got a lot of ideas!

Thank you very much!:o)