get_range_table

in src/ZGOOG_DEMO_RAP_AGENT/src/zcl_goog_rap_generative_model.clas.abap [0:0]


  METHOD get_range_table.

    DATA:
      lo_typedescr   TYPE REF TO cl_abap_typedescr,
      lo_structdescr TYPE REF TO cl_abap_structdescr,
      lo_tabledescr  TYPE REF TO cl_abap_tabledescr,
      lt_components  TYPE cl_abap_structdescr=>component_table,
      ls_component   LIKE LINE OF lt_components.

    FIELD-SYMBOLS:
      <lt_any_table> TYPE STANDARD TABLE. " To hold the final table reference

    " 1. Get type description for the field for which range is needed
    TRY.
        lo_typedescr = cl_abap_typedescr=>describe_by_name( pi_type ).
    ENDTRY.

    " 2. Define components for the range line structure
    CLEAR lt_components.

    " SIGN component
    ls_component-name = 'SIGN'.
    ls_component-type = cl_abap_elemdescr=>get_c( p_length = 1 ). " Character length 1
    APPEND ls_component TO lt_components.

    " OPTION component
    ls_component-name = 'OPTION'.
    ls_component-type = cl_abap_elemdescr=>get_c( p_length = 2 ). " Character length 2
    APPEND ls_component TO lt_components.

    " LOW component (using the dynamically determined type)
    ls_component-name = 'LOW'.
    ls_component-type ?= lo_typedescr. " Use the descriptor obtained earlier
    APPEND ls_component TO lt_components.

    " HIGH component (using the dynamically determined type)
    ls_component-name = 'HIGH'.
    ls_component-type ?= lo_typedescr. " Use the descriptor obtained earlier
    APPEND ls_component TO lt_components.

    " 3. Create the structure descriptor for the range line
    TRY.
        lo_structdescr = cl_abap_structdescr=>create( lt_components ).
    ENDTRY.

    " 4. Create the table descriptor for the range table (standard table)
    TRY.
        lo_tabledescr = cl_abap_tabledescr=>create(
                          p_line_type  = lo_structdescr
                          p_table_kind = cl_abap_tabledescr=>tablekind_std " Standard table
                          p_key_kind   = cl_abap_tabledescr=>keydefkind_default ). " Default key
    ENDTRY.

    " 5. Create the actual data object (internal table)
    CREATE DATA pr_data TYPE HANDLE lo_tabledescr.

    FIELD-SYMBOLS: <lt_range> TYPE STANDARD TABLE.

    ASSIGN pr_data->* TO <lt_range>.
    APPEND INITIAL LINE TO <lt_range> ASSIGNING FIELD-SYMBOL(<ls_range>).
    ASSIGN COMPONENT 'LOW' OF STRUCTURE <ls_range> TO FIELD-SYMBOL(<lv_comp>).
    <lv_comp> = pi_value.
    ASSIGN COMPONENT 'SIGN' OF STRUCTURE <ls_range> TO FIELD-SYMBOL(<lv_sign>).
    <lv_sign> = 'I'.
    ASSIGN COMPONENT 'OPTION' OF STRUCTURE <ls_range> TO FIELD-SYMBOL(<lv_option>).
    <lv_option> = 'EQ'.