Skip to Content
avatar image
Former Member

Change TEXT_CONVERT_XLS_TO_SAP

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 :)

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Aug 22, 2017 at 03:36 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 22, 2017 at 02:49 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 22, 2017 at 02:06 PM

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

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

    Add comment
    10|10000 characters needed characters exceeded