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

String "starts with" function in ABAP

Former Member
0 Likes
32,347

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
10,386

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.

4 REPLIES 4
Read only

Former Member
0 Likes
10,387

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.

Read only

RichHeilman
Developer Advocate
Developer Advocate
10,386

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

Read only

Former Member
0 Likes
10,386

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

Read only

Former Member
0 Likes
10,386

Hi

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

WHILE PROFIT(1) = '0'.

SHIFT PROFIT.

ENDWHILE.

WRITE PROFIT.

IF PROFIT(4) = 'P172'.

WRITE 'P172'.

ENDIF.

Max