Application Development 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: 

internal table

Former Member
0 Kudos

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?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

7 REPLIES 7

Former Member
0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

0 Kudos

Hi tahnks.

But where you are mentioning # replace statement?

regards

0 Kudos

Hi,

Thanks ...

It is working...

0 Kudos

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.