Skip to Content
author's profile photo Former Member
Former Member

ABAP code for trimming.

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 06:16 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 05:48 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 23, 2007 at 05:52 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 05:53 AM

    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>

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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>

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 05:59 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 06:05 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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>

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 06:14 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 23, 2007 at 06:24 AM

    I got a lot of ideas!

    Thank you very much!:o)

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.