‎2006 May 22 11:45 AM
I am trying to use the SPLIT command for splitting a field to an Internal table.I have added the code snippets in case 1 the program runs fine but in case 2 it creates a problem.When data is assinged manaully the split works fine but when I am uploading a fiel and trying to use the uploaded data it fails.
Any help in this regard is much appreciated.
CASE 1 :
TYPES : BEGIN OF gty_table,
field(1024) TYPE c,
END OF gty_table.
TYPES : BEGIN OF gty_tabl,
field1(10) TYPE c,
field2(10) TYPE c,
field3(10) TYPE c,
field4(10) TYPE c,
field5(10) TYPE c,
END OF gty_tabl.
DATA : gt_table TYPE STANDARD TABLE OF gty_table WITH HEADER LINE.
DATA : gt_tabl TYPE STANDARD TABLE OF gty_tabl WITH HEADER LINE.
gt_table-field = 'AUART#VKORG#VTWEG#KUNNR#MATNR#MENGE#MEINS#WERKS'.
READ TABLE gt_table INDEX 1.
SPLIT gt_table-field AT '#' INTO TABLE gt_tabl.
CASE 2 :
Table gt_table gets populated from a TXT file upload and has same data value as CASE 1 but doesnt work.
READ TABLE gt_table INDEX 1.
SPLIT gt_table-field AT '#' INTO TABLE gt_tabl.
‎2006 May 22 11:49 AM
Hi Gaurav,
The '#' you see in the file is not actually a # but it must be a Line feed character or a horozontal tab or a end of line indicator.
That is the reason the case 2 is failing.
so try your code with
SPLIT gt_table-field AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO TABLE gt_tabl.
Regards,
Ravi
‎2006 May 22 11:49 AM
Hi Gaurav,
The '#' you see in the file is not actually a # but it must be a Line feed character or a horozontal tab or a end of line indicator.
That is the reason the case 2 is failing.
so try your code with
SPLIT gt_table-field AT CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO TABLE gt_tabl.
Regards,
Ravi
‎2006 May 22 11:53 AM
‎2006 May 22 11:49 AM
HI,
To split a character string into two or more smaller strings, use the SPLIT statement as follows:
SPLIT <c> AT <del> INTO <c1> ... <cn>.
The system searches the field <c> for the separator <del>. The parts before and after the separator are placed in the target fields <c1> ... <cn>.
To place all fragments in different target fields, you must specify enough target fields. Otherwise, the last target field is filled with the rest of the field <c> and still contains delimiters.
If all target fields are long enough and no fragment has to be truncated, SY-SUBRC is set to 0. Otherwise it is set to 4.
DATA: STRING(60),
P1(20) VALUE '++++++++++++++++++++',
P2(20) VALUE '++++++++++++++++++++',
P3(20) VALUE '++++++++++++++++++++',
P4(20) VALUE '++++++++++++++++++++',
DEL(3) VALUE '***'.
STRING = ' Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5'.
WRITE STRING.
SPLIT STRING AT DEL INTO P1 P2 P3 P4.
WRITE / P1.
WRITE / P2.
WRITE / P3.
WRITE / P4.
The output appears as follows:
Part 1 *** Part 2 *** Part 3 *** Part 4 *** Part 5
Part 1
Part 2
Part 3
Part 4 *** Part 5
Note that the contents of the fields P1 ...P4 are totally overwritten and that they are filled out with trailing blanks.
You can also split a string into the individual lines of an internal table as follows:
SPLIT <c> AT <del> INTO TABLE <itab>.
The system adds a new line to the internal table <itab> for each part of the string.
Regards.
‎2006 May 22 11:51 AM
THIS IS because of tabdelimit.
you need to split at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
SPLIT gt_table-field AT cl_abap_char_utilties=>horizontal_tab INTO TABLE gt_tabl.
this will work
regards
vijay
‎2006 May 22 11:59 AM
whenever you are using the same internal table for diffrent cases, try to refresh and clear the internal table before processing starts for each case.
Try this and see.
Lakshminarayanan
‎2006 May 22 12:02 PM
PROBABLY YOU MIGHT HAVE DONE THE MISTAKE WHILE UPLOADING THE FILE
IT IS WORKING AS IN THE CASE1
I TRIED IT.
IT IS WORKING PROPERLY
THE CODE IS
TYPES : BEGIN OF gty_table,
field(1024) TYPE c,
END OF gty_table.
TYPES : BEGIN OF gty_tabl,
field1(10) TYPE c,
field2(10) TYPE c,
field3(10) TYPE c,
field4(10) TYPE c,
field5(10) TYPE c,
END OF gty_tabl.
DATA : gt_table TYPE STANDARD TABLE OF gty_table WITH HEADER LINE.
DATA : gt_tabl TYPE STANDARD TABLE OF gty_tabl WITH HEADER LINE.
*gt_table-field = 'AUART#VKORG#VTWEG#KUNNR#MATNR#MENGE#MEINS#WERKS'.
*READ TABLE gt_table INDEX 1.
*SPLIT gt_table-field AT '#' INTO TABLE gt_tabl.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\VIJAY.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = gt_table
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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
READ TABLE gt_table INDEX 1.
SPLIT gt_table-field AT '#' INTO TABLE gt_tabl.