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

SPLIT STATEMENT

Former Member
0 Likes
1,810

Hi,

I have down load a file from application server into an internal table having a single field using read statement. From that internal table i am trying to split the records and to fill an internal table with respective fields. But only the first records i am able to get. The sy-subrc is returning 4. Can anybody give the suggession how to split all the fields and get into the required format to fill internal table. if u are having provide the coding.......Urgent........

Thanks......

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,307

refer this demo code -

1)

data: begin of itab occurs 0,

ch(20),

end of itab.

data : begin of itab1 occurs 0,

ch1(10),

ch2(10),

end of itab1.

start-of-selection.

itab-ch = 'Amit Tyagi'.

append itab.

split itab at SPACE into itab1-ch1 itab1-ch2.

append itab1.

write:/ itab1-ch1,' ',itab1-ch2.

2) to upload a Text tab delimted file to internal table refer below code,u have to use gui_upload (ws_upload is obselete FM) -

data :begin of itab occurs 0,

pernr(8),

bdate(10),

edate(10),

mail(30),

end of itab.

parameters: p_file like rlgrap-filename default 'C:\temp\emp.txt'.

start-of-selection.

perform read_file.

&----


*& Form read_file

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM read_file .

DATA: full_file_name TYPE string.

full_file_name = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = full_file_name

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = ','

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = itab

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

MESSAGE e000(000) WITH 'Upload-Error; RC:' sy-subrc.

ENDIF.

ENDFORM. " read_file

9 REPLIES 9
Read only

Former Member
0 Likes
1,307

do one think 1st upload file into internal table of type string line by line.

than after that split this internal table value into 2nd internal table field value on the basis of seprator.

kishan negi

Read only

Former Member
0 Likes
1,307

Hi ,

Use the statement SPLIT ITAB1 AT ',' INTO ( the Fields )

Incase you still have problem.Then send us the code to resolve .

Regards

Sunil.M

Read only

Former Member
0 Likes
1,307

data : i_tab1(500).

OPEN DATASET g_file FOR INPUT IN TEXT MODE

ENCODING DEFAULT

IGNORING CONVERSION ERRORS.

IF SY-SUBRC EQ 0.

DO.

READ DATASET g_file INTO i_tab1.

if sy-subrc = 0.

split i_tab1 at ',' into I_TAB-SOL_DOCNO I_TAB-SOL_DOCDT

I_TAB-GI_TXN_TYPE I_TAB-WERKS I_TAB-LGOBE I_TAB-MATNR

I_TAB-ERFMG I_TAB-EXBWR.

else.

exit.

endif.

APPEND I_TAB.

clear I_TAB.

ENDDO.

ENDIF.

CLOSE DATASET g_file.

Read only

Former Member
0 Likes
1,307

SPLIT V_CHAR AT '/' INTO ITAB-F1 ITAB-F2 ITAB-F3 LIKE THIS OR

SPLIT f AT g INTO TABLE itab.

REGARDS

SHIBA DUTTA

Read only

Former Member
0 Likes
1,307

HI ,

Use the Function Module - WS_UPLOAD for upload of the datato Internal table.

Hope this helps

Sunil

Read only

Former Member
0 Likes
1,307

Here the seperator is tab

Read only

Former Member
0 Likes
1,308

refer this demo code -

1)

data: begin of itab occurs 0,

ch(20),

end of itab.

data : begin of itab1 occurs 0,

ch1(10),

ch2(10),

end of itab1.

start-of-selection.

itab-ch = 'Amit Tyagi'.

append itab.

split itab at SPACE into itab1-ch1 itab1-ch2.

append itab1.

write:/ itab1-ch1,' ',itab1-ch2.

2) to upload a Text tab delimted file to internal table refer below code,u have to use gui_upload (ws_upload is obselete FM) -

data :begin of itab occurs 0,

pernr(8),

bdate(10),

edate(10),

mail(30),

end of itab.

parameters: p_file like rlgrap-filename default 'C:\temp\emp.txt'.

start-of-selection.

perform read_file.

&----


*& Form read_file

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM read_file .

DATA: full_file_name TYPE string.

full_file_name = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = full_file_name

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = ','

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = itab

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

MESSAGE e000(000) WITH 'Upload-Error; RC:' sy-subrc.

ENDIF.

ENDFORM. " read_file

Read only

0 Likes
1,307

use like that.

split itab-rec at cl_abap_char_utilities=>horizontal_tab
                          into idat-fld1
                               idat-fld2
                               idat-fld3.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,307

Hi,

DATA: BEGIN OF T_INPUT OCCURS 0, " Flat file data

F1(9) TYPE C,

F2(15) TYPE C,

END OF T_INPUT.

DATA : G_DATA(1000) TYPE C,

G_AFILE1(100) TYPE C,

DELIM TYPE C VALUE CLABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.

OPEN DATASET G_AFILE1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF SY-SUBRC = 0.

DO.

READ DATASET G_AFILE1 INTO G_DATA.

IF SY-SUBRC = 0.

SPLIT G_DATA AT G_DELIM INTO T_INPUT-F1 T_INPUT-F2.

IF SY-SUBRC = 0.

APPEND T_INPUT.

CLEAR T_INPUT.

ENDIF.

ELSE.

EXIT. "After reading last Record

ENDIF.

ENDDO.

ELSE.

MESSAGE E001 WITH 'Error in Uploading'.

ENDIF.