Skip to Content

Function module to split strings

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 02:03 PM

    Hi!

    The answer is in your question.

    Use the SPLIT command for this.

    Regards

    Tamá

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 02:03 PM

    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 .

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 17, 2008 at 02:07 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 17, 2008 at 02:09 PM

    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.

    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.