Skip to Content
0
Former Member
Mar 24, 2008 at 10:28 AM

Unable to split string at '#' in below program

479 Views

&----


*& Report ZTEST1231212

*&

&----


*&

*&

&----


REPORT ZTESTSPLIT.

DATA: cmd(254), "Max length = 254 Bytes

result(255) OCCURS 100 WITH HEADER LINE, "No max length

BEGIN OF list OCCURS 100,

nr TYPE i,

line(255),

END OF list,

res(40) TYPE c,

res1(20) TYPE c,

res2(20) TYPE c,

list1 type table of string.

DATA list2 TYPE TABLE OF xstring.

DATA res3 TYPE xstring.

DATA res4 TYPE string.

CONCATENATE 'du -ks /usr/sap/' sy-sysid '/D*/work' INTO cmd.

CALL 'SYSTEM' ID 'COMMAND' FIELD cmd

ID 'TAB' FIELD result-sys.

CLEAR list.

LOOP AT result.

list-line = result.

APPEND list.

ENDLOOP.

WRITE: 'Execution success'.

WRITE: cmd.

DATA splt TYPE xstring.

DATA splt1 TYPE string.

LOOP AT list.

WRITE : list-line.

res = list-line.

SPLIT res AT '#' INTO: res1 res2, table list1.

SHIFT res UP TO '#'.

write: res.

ENDLOOP.

res3 = res.

splt1 = '#'.

DATA result1 TYPE string.

result1 = substring_after( val = res sub = '#' ).

DATA: result_tab TYPE match_result_tab.

FIND FIRST OCCURRENCE OF '#' IN res RESULTS result_tab.

res4 = res.

CALL FUNCTION 'LXE_COMMON_STRING_TO_XSTRING'

EXPORTING

in_string = res4

  • IN_CODEPAGE = '0000'

  • EX_CODEPAGE = '4110'

IMPORTING

EX_XSTRING = res3

EXCEPTIONS

ERROR = 1

OTHERS = 2

.

CALL FUNCTION 'LXE_COMMON_STRING_TO_XSTRING'

EXPORTING

in_string = splt1

  • IN_CODEPAGE = '0000'

  • EX_CODEPAGE = '4110'

IMPORTING

EX_XSTRING = splt

EXCEPTIONS

ERROR = 1

OTHERS = 2

.

DATA r11 TYPE xstring.

DATA r22 TYPE xstring.

SPLIT res3 AT splt INTO table list2 IN BYTE MODE.

DO.

TRY.

result1 = segment( val = res

index = sy-index

sep = '#' ).

CATCH cx_sy_strg_par_val.

EXIT.

ENDTRY.

ENDDO.