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

Function module to split strings

former_member202335
Participant
0 Likes
2,946

Hi,

I have a string value ' DBTABLE-FIELDNAME'. I need to split this into 2 strings - The first one is the database table name and the second one is the fieldname. So, the character '-' is the point where the split needs to be done. How can this be achieved. Any FM that I could use?

Thanks for your help!

Regards,

Divyaman Singh Rawat

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,442

Hi!

The answer is in your question.

Use the SPLIT command for this.

Regards

Tamá

5 REPLIES 5
Read only

Former Member
0 Likes
1,443

Hi!

The answer is in your question.

Use the SPLIT command for this.

Regards

Tamá

Read only

0 Likes
1,442

thanks a lot!

regards,

Divyaman

Read only

Former Member
0 Likes
1,442

there is no FM

but u can use split command.

DATA: str1 TYPE string,

str2 TYPE string,

str3 TYPE string,

text TYPE string.

text = `mara-matnr`.

SPLIT text AT '-' INTO str1 str2 .

Read only

Former Member
0 Likes
1,442

Use FM 'STRING_SPLIT'

REPORT ZEXAMPLE.

DATA: V_HEAD(10), V_TAIL(10).

PARAMETERS: P_STR(20),

P_DEM.

CALL FUNCTION 'STRING_SPLIT'

EXPORTING

DELIMITER = P_DEM

STRING = P_STR

IMPORTING

HEAD = V_HEAD

TAIL = V_TAIL

EXCEPTIONS

NOT_FOUND = 1

NOT_VALID = 2

TOO_LONG = 3

TOO_SMALL = 4

OTHERS = 5.

IF SY-SUBRC EQ 0.

WRITE:/ 'HEAD:', V_HEAD,

/ 'TAIL:', V_TAIL.

ELSE.

WRITE:/ 'ERROR SPLITTING STRING'.

ENDIF.

Regards,

Joy.

Read only

Former Member
0 Likes
1,442

Hi,

For this type of logic what you need to do is use CA operator ( Contains Any)

Exmaple:

DATA: ulimit type DBTABLE-FIELDNAME'. DATA: STR(10) TYPE C. DATA: LEN TYPE I. DATA: LEN1 TYPE I. DATA: TOTAL TYPE I. DATA: REMAIN TYPE I. STR = ULIMIT. CONDENSE STR. IF STR CA '-'. LEN = SY-FDPOS. LEN1 = LEN - 1. TOTAL = STRLEN( STR ). REMAIN = TOTAL - LEN. TABLE = STR+0(LEN). FIELDNAME = STR+LEN1( REMAIN ). ENDIF. WRITE:/ TABLE. WRITE:/ FLDNAME.