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

Problem in uploading Excel to internal table

Former Member
0 Likes
984

I am trying to upload an excel file which contains 5 columns. The last column in the e file will have long text of length(may be even 1000 char).

I have tried the options of F.M: 'gui_upload', 'TEXT_CONVERT_XLS_TO_SAP'.

'TEXT_CONVERT_XLS_TO_SAP' this FM could read the 256 characters of the last column, but not the hole.

Please suggest me if there is any other way.

Please reply at the earliest

Reward points guaranteed

I am trying to upload an excel file which contains 5 columns. The last column in the e file will have long text of length(may be even 1000 char).

I have tried the options of F.M: 'gui_upload', 'TEXT_CONVERT_XLS_TO_SAP'.

'TEXT_CONVERT_XLS_TO_SAP' this FM could read the 256 characters of the last column, but not the hole.

Please suggest me if there is any other way.

Please reply at the earliest

Reward points guaranteed

6 REPLIES 6
Read only

Former Member
0 Likes
817

Hi

try like this one

at selection-screen on value-request for P_FILE.

  • IF THE USER SELECT EXTENTION BUTTON IT WILL OPEN THE LOCAL DIRECTORY FOR SELECTING THE FILE LOCATION.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

  • EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION = 'CSV'

  • DEFAULT_FILENAME = 'C:\Documents and Settings\kiran\Desktop\STATUS.csv'

  • FILE_FILTER =

  • INITIAL_DIRECTORY = 'C:\Documents and Settings\kiran\Desktop\'

  • MULTISELECTION =

  • WITH_ENCODING =

CHANGING

FILE_TABLE = L_FILETABLE

RC = RC

  • USER_ACTION =

  • FILE_ENCODING =

EXCEPTIONS

FILE_OPEN_DIALOG_FAILED = 1

CNTL_ERROR = 2

ERROR_NO_GUI = 3

NOT_SUPPORTED_BY_GUI = 4

others = 5

.

IF SY-SUBRC <> 0.

ELSE.

LOOP AT l_filetable INTO L_FILETAB_H.

P_FILE = L_FILETAB_H-FILENAME.

move p_file to p_file1.

EXIT.

ENDLOOP.

ENDIF.

  • passing the selected file name to gui_upload for loading the data

  • into internal table

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = p_file1

  • 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_string

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 I000(Z00) WITH 'PLEASE PROVIDE CORRECT FILE NAME'.

ENDIF.

loop at itab_string.

  • now split the statuses

split itab_string at ',' into itab_status-aufnr itab_status-asttx itab_status-asttx1.

  • and move one internal table

append itab_status.

clear itab_status.

endloop.

reward points to all helpful answers

kiran.M

Read only

Former Member
0 Likes
817

hi,

try using the FM ALSM_EXCEL_TO_INTERNAL_TABLE

chk this sample program

REPORT ZNTERACTIVEREPORTS NO STANDARD PAGE HEADING

LINE-COUNT 65(2).

PARAMETERS:

P_INFL like RLGRAP-FILENAME.

DATA:

BEGIN OF T_DATA1 OCCURS 0,

RESOURCE(25) TYPE C,

DATE(10) TYPE C,

DURATION TYPE P DECIMALS 2,

ACTIVITY(25) TYPE C,

B_NBILL(1) TYPE C,

END OF T_DATA1,

T_DATA TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE,

BEGIN OF T_FINAL OCCURS 0,

RESOURCE(25) TYPE C,

DATE(10) TYPE C,

DURATION(15) TYPE C,

ACTIVITY(25) TYPE C,

B_NBILL(10) TYPE C,

END OF T_FINAL.

DATA : HEADER TYPE XSTRING.

  • Work Variables Declaration.

CONSTANTS:

W_Y TYPE C VALUE 'Y',

W_N TYPE C VALUE 'N'.

  • Work area.

DATA:

WA_DATA LIKE T_FINAL.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFL.

PERFORM GET_FILENAME CHANGING P_INFL.

----


START-OF-SELECTION.

----


PERFORM UPLOAD_DATA_FROMEXCEL.

PERFORM PROCESS_DATA.

&----


*& Form download_data

&----


  • text

----


FORM UPLOAD_DATA_FROMEXCEL.

  • Downloading the data from presentation server

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_infl

I_BEGIN_COL = 1

I_BEGIN_ROW = 2

I_END_COL = 8

I_END_ROW = 1000

TABLES

INTERN = T_DATA

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " upload_data_fromexcel

&----


*& Form process_data

&----


  • text

----


FORM PROCESS_DATA .

T_FINAL-RESOURCE = 'Resource'.

T_FINAL-DATE = 'Date'.

T_FINAL-DURATION = 'Duration'.

T_FINAL-ACTIVITY = 'Activity'.

T_FINAL-B_NBILL = 'Billable'.

APPEND T_FINAL.

SORT T_DATA BY ROW COL.

LOOP AT T_DATA.

CASE T_DATA-COL.

WHEN 3.

T_DATA1-RESOURCE = T_DATA-VALUE.

WHEN 4.

T_DATA1-DATE = T_DATA-VALUE.

WHEN 5.

T_DATA1-DURATION = T_DATA-VALUE.

WHEN 6.

  • t_data1-activity = t_data-value.

WHEN 7.

T_DATA1-B_NBILL = T_DATA-VALUE.

ENDCASE.

AT END OF ROW.

COLLECT T_DATA1.

ENDAT.

ENDLOOP.

LOOP AT T_DATA1.

T_FINAL-RESOURCE = T_DATA1-RESOURCE.

T_FINAL-DATE = T_DATA1-DATE.

T_FINAL-DURATION = T_DATA1-DURATION.

T_FINAL-ACTIVITY = T_DATA1-ACTIVITY.

T_FINAL-B_NBILL = T_DATA1-B_NBILL.

APPEND T_FINAL.

ENDLOOP.

ENDFORM. " process_data

&----


*& Form get_filename

&----


FORM GET_FILENAME CHANGING P_FILENAME.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = SPACE

DEF_PATH = P_FILENAME

MASK = ',. ,..'

MODE = 'O' " O = Open, S = Save

  • TITLE = BOX_TITLE

IMPORTING

FILENAME = P_FILENAME

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5.

*

  • CASE SY-SUBRC.

  • WHEN 1.

  • MESSAGE I999 WITH

  • 'File selector not available on this windows system'(046).

  • WHEN 2.

  • MESSAGE E999 WITH

  • 'Frontend function cannot be executed in background'(047).

  • WHEN 3.

  • MESSAGE I999 WITH 'Selection was cancelled'(048).

  • WHEN 4.

  • MESSAGE E999 WITH 'Communication error'(049).

  • WHEN 5.

  • MESSAGE E999 WITH 'Other error'(050).

  • ENDCASE.

ENDFORM. " get_filename

regards,

priya.

Read only

0 Likes
817

Hi Priya,

ALSM_EXCEL_TO_INTERNAL_TABLE gives maximum field value as 40 char only

Read only

0 Likes
817

Any more replay ..............

Read only

0 Likes
817

Any more reply...................

Read only

former_member194669
Active Contributor
0 Likes
817

Hi,

Due to excel length limitation. please use txt file to upload long text into SAP.

aRs