method ui5_valuehelp_ajax_result. field-symbols: type any. field-symbols: type any. data: wa_desc type dfies, wa_data type seahlpres, wa_interface type ddshiface, lv_content type string, lv_content_d type sy-datum, lv_sep_rec type c, lv_separator type c, lv_f4key type string, lv_f4keysep type string, lv_selmethod type string, lr_dyn_ref type ref to data, lv_length type i. *--------------------------------------------------------------------- * BUILD STRUCTURE *--------------------------------------------------------------------- data: lo_struc type ref to cl_abap_structdescr, lt_desc_temp type standard table of dfies, wa_comp_all type cl_abap_structdescr=>component, wa_comp_new type cl_abap_structdescr=>component, lt_comp_sorted type cl_abap_structdescr=>component_table, wa_comp_sorted type cl_abap_structdescr=>component, lt_comp_all type cl_abap_structdescr=>component_table, lt_comp_new type cl_abap_structdescr=>component_table, wa_type type ref to cl_abap_typedescr. case wa_shlp-intdescr-selmtype. when 'T'. " Selecting from Table * Sorting sort it_desc by offset ascending. * Create Dynamic Reference loop at it_desc into wa_desc. wa_comp_all-type ?= cl_abap_structdescr=>describe_by_name( wa_desc-rollname ). wa_comp_all-name = wa_desc-fieldname. append wa_comp_all to lt_comp_all. clear wa_comp_all. endloop. * Create the RTTC instance for the merged structure try. lo_struc = cl_abap_structdescr=>create( p_components = lt_comp_all ). catch cx_sy_struct_creation. endtry. * Assign to Structure create data lr_dyn_ref type handle lo_struc. assign lr_dyn_ref->* to . when others. " Selecting from View * Create using Search Help selection method clear lv_selmethod. lv_selmethod = wa_shlp-intdescr-selmethod. if lv_selmethod is initial. clear wa_desc. read table it_desc into wa_desc index 1. lv_selmethod = wa_desc-tabname. endif. try. create data lr_dyn_ref type (lv_selmethod). catch cx_sy_create_data_error. endtry. assign lr_dyn_ref->* to . endcase. check sy-subrc eq 0. *--------------------------------------------------------------------- * BUILD CONTENT *--------------------------------------------------------------------- loop at it_data into wa_data. = wa_data-string. concatenate json_data lv_sep_rec '{' into json_data. lv_separator = space. lv_f4keysep = space. lv_f4key = space. loop at it_desc into wa_desc. assign component wa_desc-fieldname of structure to . check sy-subrc eq 0. lv_content = . call method me->server_encode_json changing data = lv_content. * Date Handling if wa_desc-datatype eq 'DATS'. lv_content_d = lv_content. if lv_content_d is initial. lv_content = space. else. call function 'CONVERT_DATE_TO_EXTERNAL' exporting date_internal = lv_content_d importing date_external = lv_content exceptions date_internal_is_invalid = 1 others = 2. endif. endif. * Build JSON concatenate json_data lv_separator '"' wa_desc-fieldname '":"' lv_content '"' into json_data. * Field Separator lv_separator = ','. * Set Key Data read table wa_shlp-interface into wa_interface with key topshlpfld = wa_desc-fieldname. if sy-subrc eq 0. concatenate lv_f4key lv_f4keysep lv_content into lv_f4key. lv_f4keysep = ':'. endif. endloop. "F4 Key concatenate json_data lv_separator '"F4KEY":"' lv_f4key '"' into json_data. lv_sep_rec = ','. concatenate json_data '}' into json_data. endloop. endmethod.