Giter VIP home page Giter VIP logo

Comments (2)

darnoc312 avatar darnoc312 commented on June 16, 2024 1

Hello,

My suggestion:
Replace line:

  lt_dfies = lo_tabdescr->get_ddic_field_list( ).

by:

  lt_dfies = zcl_excel_common=>describe_structure( io_struct = lo_tabdescr ).

This method works with non DDIC structure, too

And i would prefer renaming lo_tabdescr to lo_structdescr

Thanks
Bernd

from abap2xlsx.

sandraros avatar sandraros commented on June 16, 2024

One possible solution is this one:

  METHOD set_table.
    DATA: lo_tabdescr     TYPE REF TO cl_abap_structdescr,
          lr_data         TYPE REF TO data,
          lt_dfies        TYPE ddfields,
          lv_row_int      TYPE zexcel_cell_row,
          lv_column_int   TYPE zexcel_cell_column,
          lv_column_alpha TYPE zexcel_cell_column_alpha,
          lv_cell_value   TYPE zexcel_cell_value.
    DATA lt_components TYPE abap_component_tab.

    FIELD-SYMBOLS: <fs_table_line> TYPE any,
                   <fs_fldval>     TYPE any,
                   <fs_dfies>      TYPE dfies.
    FIELD-SYMBOLS <fs_component> TYPE abap_componentdescr.

    lv_column_int = lcl_excel_common=>convert_column2int( ip_top_left_column ).
    lv_row_int    = ip_top_left_row.

    CREATE DATA lr_data LIKE LINE OF ip_table.

    lo_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ).
    lt_components = lo_tabdescr->get_components( ).

    IF ip_no_header = abap_false.
      CALL METHOD lo_tabdescr->get_ddic_field_list
        RECEIVING
          p_field_list = lt_dfies
        EXCEPTIONS
          not_found    = 1
          no_ddic_type = 2
          others       = 3.
      IF sy-subrc <> 0.
        zcx_excel=>raise_text( 'SET_TABLE parameter IP_TABLE must have lines defined by a DDIC Structure' ).
      ENDIF.
    ENDIF.

* It is better to loop column by column
    LOOP AT lt_components ASSIGNING <fs_component>.
      lv_column_alpha = lcl_excel_common=>convert_column2alpha( lv_column_int ).

      IF ip_no_header = abap_false.
        " First of all write column header
        READ TABLE lt_dfies ASSIGNING <fs_dfies> WITH KEY fieldname = <fs_component>-name.
        IF sy-subrc = 0.
          lv_cell_value = <fs_dfies>-scrtext_m.
          set_cell( ip_column = lv_column_alpha
                        ip_row    = lv_row_int
                        ip_value  = lv_cell_value
                        ip_style  = ip_hdr_style ).
        ENDIF.
        IF ip_transpose = abap_true.
          ADD 1 TO lv_column_int.
        ELSE.
          ADD 1 TO lv_row_int.
        ENDIF.
      ENDIF.

      LOOP AT ip_table ASSIGNING <fs_table_line>.
        lv_column_alpha = lcl_excel_common=>convert_column2alpha( lv_column_int ).
        ASSIGN COMPONENT <fs_component>-name OF STRUCTURE <fs_table_line> TO <fs_fldval>.
        lv_cell_value = <fs_fldval>.
        set_cell( ip_column = lv_column_alpha
                      ip_row    = lv_row_int
                      ip_value  = <fs_fldval>   "lv_cell_value
                      ip_style  = ip_body_style ).
        IF ip_transpose = abap_true.
          ADD 1 TO lv_column_int.
        ELSE.
          ADD 1 TO lv_row_int.
        ENDIF.
      ENDLOOP.
      IF ip_transpose = abap_true.
        lv_column_int = lcl_excel_common=>convert_column2int( ip_top_left_column ).
        ADD 1 TO lv_row_int.
      ELSE.
        lv_row_int = ip_top_left_row.
        ADD 1 TO lv_column_int.
      ENDIF.
    ENDLOOP.

  ENDMETHOD.                    "SET_TABLE

from abap2xlsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.