Skip to Content
avatar image
Former Member

String "starts with" function in ABAP

Hi!

I need to check in ABAP, if a given profit center (char 10) starts with P172. It could be filled with zeros -> 0000P17255. So I need to perform 2 actions:

1)

Lefttrim the 0 -> Result: P17255.

2)

Check, if the string starts with P172.

How can I do this in ABAP?

Thanks,

Konrad

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 21, 2008 at 03:26 PM

    data : var(10) type c.

    move profit_center to var.

    call conversion_exit_alpha_output

    exporting

    var

    importing

    var

    condense var no-gaps.

    if var+0(4) = 'P172'.

    *--condition satisfied...

    endif.

    ************************(or)****************

    data : var(10) type c.

    move profit_center to var.

    shift var left deleting leading '0'.

    if var+0(4) = 'P172'.

    endif.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 21, 2008 at 03:26 PM

    Try this.

    
    data: lv_str type string value '0000P17255'.
    
    shift lv_str left deleting LEADING '0'.
    
    if lv_str cp 'P172*'.
       write:/ 'yes, it starts with P172'.
    else.
       write:/ 'no, it does not start with P172'.
    endif.
    
    

    Regards,

    Rich Heilman

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 21, 2008 at 03:33 PM

    Hi

    DATA: PROFIT(10) VALUE '0000P17255'.

    WHILE PROFIT(1) = '0'.

    SHIFT PROFIT.

    ENDWHILE.

    WRITE PROFIT.

    IF PROFIT(4) = 'P172'.

    WRITE 'P172'.

    ENDIF.

    Max

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 21, 2008 at 03:28 PM

    Hi,

    You can do as below :

    1st scenario :

    loop at itab.

    "Below code will delete leading zero.

    SHIFT itab-prctr LEFT DELETING LEADING '0'.

    "Second scenario

    if itab-prctr(4) = 'P1972'.

    "Do necessary coding as per your requirment.

    endif.

    "If you wnat chnage tje contensts of the itab you can use modify else you append to append to another internal table.

    endloop.

    Thanks,

    Sriram POnna

    Add comment
    10|10000 characters needed characters exceeded