11-08-2006 12:47 PM
Hi experts,
See the below code:
TYPES: TY_D_ITABVALUE TYPE ALSMEX_TABLINE-VALUE,
TY_T_ITAB TYPE ALSMEX_TABLINE OCCURS 0,
BEGIN OF TY_S_SENDERLINE,
LINE(4096) TYPE C,
END OF TY_S_SENDERLINE,
TY_T_SENDER TYPE TY_S_SENDERLINE OCCURS 0 .
DATA: EXCEL_TAB1 TYPE ty_t_sender.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_IMPORT
IMPORTING
DATA = EXCEL_TAB1
EXCEPTIONS
CNTL_ERROR = 1
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE A037(ALSMEX).
ENDIF.
So in debugging i see some '#' in the contents of EXCEL_TAB1
How can i remove that #..can any body tell me how can we do this in above code?
11-08-2006 1:39 PM
hi Ravi,
The '#' is nothing but the separators between columns in the excel sheet....
include the following logic to split the record at the field separator.
data ls_excel_tab1 type ty_s_senderline.
types: begin of itabtype,
field1(20), " as per your requirement
field2(30), " as per your requirement
.........
.........
end of itabtype.
data itab type table of itabtype.
data ls_itab type itabtype.
loop at excel_tab1 into ls_excel_tab1.
split ls_excel_tab1 at cl_abap_char_utilities=>horizontal_tab into
ls_itab-field1 ls_itab-field2 (.....).
append ls_itab to itab.
clear ls_itab.
endloop.
at the end of the loop, you will get itab with the required values, in the required form.
Hope this helps.
Sajan.
Message was edited by: Sajan Joseph
11-08-2006 1:09 PM
TYPES: TY_D_ITABVALUE TYPE ALSMEX_TABLINE-VALUE,
TY_T_ITAB TYPE ALSMEX_TABLINE OCCURS 0,
BEGIN OF TY_S_SENDERLINE,
LINE(4096) TYPE C,
END OF TY_S_SENDERLINE,
TY_T_SENDER TYPE TY_S_SENDERLINE OCCURS 0 .
DATA: EXCEL_TAB1 TYPE ty_t_sender.
DATA: wa LIKE LINE OF EXCEL_TAB1.
* the following LOOP replaces each '#' with SPACE
* afterwards all SPACES are deleted
LOOP AT EXCEL_TAB1 INTO WA.
TRANSLATE wa-line USING '# '.
CONDENSE wa-line NO-GAPS.
MODIFY excel_tab1 FROM wa.
ENDLOOP.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_IMPORT
IMPORTING
DATA = EXCEL_TAB1
EXCEPTIONS
CNTL_ERROR = 1
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE A037(ALSMEX).
ENDIF.
11-08-2006 2:23 PM
HI ,
TAHNKS.BUT TRANSLATE IS NOT WORKING.I THINK ONLY FOR CHARACTER TYPE IT WILL WORK.BUT HERE EXCEL_TAB1 IS OF DIFFERENT TYPE?
IS THERE ANY OTHER WAY TO DO IT?
REGARDS
11-08-2006 1:39 PM
hi Ravi,
The '#' is nothing but the separators between columns in the excel sheet....
include the following logic to split the record at the field separator.
data ls_excel_tab1 type ty_s_senderline.
types: begin of itabtype,
field1(20), " as per your requirement
field2(30), " as per your requirement
.........
.........
end of itabtype.
data itab type table of itabtype.
data ls_itab type itabtype.
loop at excel_tab1 into ls_excel_tab1.
split ls_excel_tab1 at cl_abap_char_utilities=>horizontal_tab into
ls_itab-field1 ls_itab-field2 (.....).
append ls_itab to itab.
clear ls_itab.
endloop.
at the end of the loop, you will get itab with the required values, in the required form.
Hope this helps.
Sajan.
Message was edited by: Sajan Joseph
11-08-2006 2:45 PM
hi Ravi,
if you just need to replace the '#' with space, you can use the following code.
<b>data ls_tab1 type ty_s_senderline.
loop at excel_tab1 into ls_tab1.
replace all occurrences of cl_abap_char_utilities=>horizontal_tab in ls_tab1 with ''.
modify excel_tab1 from ls_tab1.
clear ls_tab1.
endloop.</b>
Hope your problem is solved.
Sajan.
11-08-2006 2:54 PM
Hi tahnks.
But where you are mentioning # replace statement?
regards
11-08-2006 2:58 PM
11-08-2006 3:00 PM
hi Ravi,
if you check the code i had given, you can see some thing like 'cl_abap_char_utilities=>horizontal_tab', which represents the special character for tab separator in EXCEL files or other flat files. If you want to hard code '#', you can change 'cl_abap_char_utilities=>horizontal_tab' with '#' in the code i have given.
Hope this helps.
Sajan.