0

I have one big select like this;

SELECT (lv_selection) FROM crms4d_serv_h
        INNER JOIN crm_jest ON crm_jest~objnr = crms4d_serv_h~header_guid
            AND crm_jest~inact = space
        INNER JOIN crms4c_stat_lc_t ON crms4c_stat_lc_t~stat_lifecycle = crms4d_serv_h~stat_lifecycle
            AND crms4c_stat_lc_t~language = sy-langu
        INNER JOIN crms4d_partner ON crms4d_partner~object_id = crms4d_serv_h~object_id
            AND partner_fct = lv_pfct_vendor
        INTO CORRESPONDING FIELDS OF TABLE <t_dyntable>
        WHERE process_type                     =  lv_warr_claim_ptype
              AND crms4d_serv_h~object_id      IN it_warranty_id
              AND posting_date                 IN it_datum
              AND sales_org                    IN it_sales_org
              AND service_org                  IN it_service_org
              AND crms4d_serv_h~stat_lifecycle IN lt_claimable_status
              AND partner_id                   =  iv_vendor
        ORDER BY crms4d_serv_h~object_id.

As you might have guessed lv_selection is dynamic and type of <t_dyntable> is INDEX TABLE.

What I want is basically add a new field to that t_dyntable and fill it from already existed internal table. Object_id is guaranteed to have in that lv_selection and my internal table has that new field and object id. So I want to fill that field with the condition lt_itab-object_id = t_dyntable-object_id (object ids in the lt_itab is same with t_dyntable). If it is not possible I am open to new approaches. Thanks for your help!

I have tried to use method cl_abap_typedescr=>describe_by_data( <t_dyntable>[ 1 ] ). But I couldn't manage to use it.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • 1
    To create a new internal table as a copy of a dynamic internal table + a new component to the line type, you have to use `cl_abap_typedescr=>describe_by_data`, `cl_abap_tabledescr` (casting), method `get_line_type`, `cl_abap_structdescr` (casting), method `get_components`, methods `get`, `create data dref type handle ...` and then `assign dref->* to `...) – Sandra Rossi Jul 23 '23 at 20:03
  • By the way, the title of the question is misleading ("*adding new field to a dynamic table*") because you can't change an existing internal table, whatever it has been defined statically or created at runtime, you can only create a new one at runtime, based on an existing internal table (or from scratch). The exact answer to the question would be that it's not possible. – Sandra Rossi Jul 24 '23 at 07:37

0 Answers0