Monday 6 May 2019

JSON to Internal Tables & vice-versa

DATA: lt_flight TYPE STANDARD TABLE OF sflight,
      lrf_descr TYPE REF TO cl_abap_typedescr,
      lv_json   TYPE string.

SELECT * FROM sflight INTO TABLE lt_flight.

* serialize table lt_flight into JSON, skipping initial fields and
* converting ABAP field names into camelCase
lv_json = /ui2/cl_json=>serialize(
                data = lt_flight
                compress = abap_true
                pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).
WRITE / lv_json.

* LV_JSON will have the coverted records to JSON

CLEAR lt_flight.

* deserialize JSON string json into internal table
* lt_flight doing camelCase to ABAP like field name mapping
/ui2/cl_json=>deserialize(
  EXPORTING
    json = lv_json
    pretty_name = /ui2/cl_json=>pretty_mode-camel_case
    CHANGING
      data = lt_flight ).

* LT_FLIGHT[] will have the coverted records from JSON

Report to find CDS view of Standard Table

A small change has been made to the original program ( SAP YARD Article ) so that it can also display the common CDS used by multiple table...