Skip to Content
0

Change TEXT_CONVERT_XLS_TO_SAP

Aug 22, 2017 at 01:21 PM

163

avatar image
Former Member

Hey Guys,

how it is possible to Change the existing FM TEXT_CONVERT_XLS_TO_SAP that the data i'll get isn't in the Format of ROW | COLUMN | VALUE.

I need the data like the XLS itself. That means in need a table with the field names like the first row of the xls...

Is this even possible?

Greetings, Alex :)

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Bertrand DELVALLEE Aug 22, 2017 at 03:36 PM
1

Hello,

To understand how to do that in ABAP you should create a local test program and paste this :

DATA :  comp_tab TYPE         cl_abap_structdescr=>component_table,
        comp     LIKE LINE OF comp_tab,
        new_str  TYPE REF TO  cl_abap_structdescr,
        new_tab  TYPE REF TO  cl_abap_tabledescr,
        tref     TYPE REF TO  data,
        lref     TYPE REF TO  data.




FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
FIELD-SYMBOLS: <iline> TYPE any.
FIELD-SYMBOLS: <ifield> TYPE any.


* 1 - Create the structured data you want to fill
comp-name = 'COL1'.
comp-type = cl_abap_elemdescr=>get_c( 10 ).
APPEND comp TO comp_tab.
comp-name = 'COL2'.
comp-type = cl_abap_elemdescr=>get_c( 12 ).
APPEND comp TO comp_tab.


new_str = cl_abap_structdescr=>create( comp_tab[] ).
new_tab = cl_abap_tabledescr=>create(
                  p_line_type  = new_str
                  p_table_kind = cl_abap_tabledescr=>tablekind_std
                  p_unique     = abap_false ).


CREATE DATA tref TYPE HANDLE new_tab.
ASSIGN tref->* TO <itab>. "INTERNAL TABLE.
CREATE DATA lref TYPE HANDLE new_str.
ASSIGN lref->* TO <iline>. "INTERNAL LINE.


* 2 - Fill data table
DO 2 TIMES. " Repeat for each "XLS line"
  CLEAR <iline>.
  ASSIGN COMPONENT 'COL1' OF STRUCTURE <iline> TO <ifield>. " with name
  <ifield> = 'VALUE1'.
  ASSIGN COMPONENT 2 OF STRUCTURE <iline> TO <ifield>. " with column number
  <ifield> = 'VALUE2'.
  APPEND <iline> TO  <itab>.
ENDDO.




* Now <itab> contents values
BREAK-POINT.

Now in debug mode have a look on <itab> content. It should fit with what you want to do.

Play a bit with with program and you will be able to create your own method/FM (or enhance bottom of TEXT_CONVERT_XLS_TO_SAP if your boss asked you...) to output <itab>

Best regards

Bertrand

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks, i've done that like you wrote in that coding. Everything worked fine :)

0
Former Member
Bertrand, when we meet sometime, i'll get you a beer for all your answers :)
0
avatar image
Former Member Aug 22, 2017 at 02:49 PM
0

Hi Alex,

I believe your mentioned FM 'TEXT_CONVERT_XLS_TO_SAP' will work just as you want. If you check the tables section, the associated type is STANDARD TABLE which means you can define your custom structure which you can match just like in your excel sheet. I remember I have used this FM in certain instances.

The FM 'ALSM_EXCEL_TO_INTERNAL_TABLE' works like you don't want, i.e - ROW,COL and VALUE. ( the associated type is ALSMEX_TABLINE ).

Cheers,

Sampat.

Share
10 |10000 characters needed characters left characters exceeded
Uwe Fetzer Aug 22, 2017 at 02:06 PM
0

Sure it is possible. Call the function module and transform the result.

... all you need is a bit of ABAP ;)

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member
So you mean, after executing, i should just move every entry of the data table [ ROW | COLUMN | VALUE ] individualy into the structure which i need? I've done that before, but i was told to generate the data dynamicly inside of this FM for every sheet of the Excel because every sheet Looks different...
0

But where ist the difference whether you do the work inside or outside the FM?

I will not give you the solution here, but I think this is a nice task to learn ABAP (and coding in general).

Hint: you have the field names in the first row. You can use ASSIGN fieldname OF STRUCTURE xyz TO FIELD-SYMBOL <f>. If the row number changes, you can do the INSERT of the last row.

1
Former Member

Thanks for your hint, that worked like i wanted it :)

0