json DDIC表可以有嵌套或复杂类型吗?

e4yzc0pl  于 2023-05-08  发布在  其他
关注(0)|答案(1)|浏览(146)

我创建了一个带有用户属性的表“users”……

然而,我想有一个复杂的/嵌套的字段称为“地址”,但似乎表只能在abap字典表平面…我只能使用“.INCLUDE”将地址字段平铺到表中,对吗?
我只是想知道,我如何在ABAP REPORT程序中解析我的复杂JSON用户对象,并将它们插入到我的DDict表中...

REPORT zzzfz_ins_users.

*TYPES: ty_coord TYPE TABLE OF dec015 WITH NON-UNIQUE DEFAULT KEY.

TYPES: BEGIN OF address,
         country       TYPE char30,
         county        TYPE char30,
         city          TYPE char50,
         streetAddress TYPE string,
         latitude      TYPE dec015,
         longitude     TYPE  dec015,
         zipcode       TYPE int4,
       END OF address.

TYPES: BEGIN OF ls_user,
         mandt         TYPE mandt,
         id            TYPE num05_kk2,
         uuid          TYPE sysuuid_c36,
         firstName     TYPE char30,
         lastName      TYPE char30,
         fullName      TYPE char50,
         gender        TYPE char10,
         username      TYPE char30,
         email         TYPE ad_smtpadr,
         avatar        TYPE string,
         password      TYPE char50,
         birthdate     TYPE char10,
         registeredAt  TYPE char30,
         phone         TYPE char30,
         jobTitle      TYPE char50,
         jobType       TYPE char30,
         profileInfo   TYPE string,
         address       TYPE address,
*         country       TYPE address-city,
*         county        TYPE address-county,
*         city          TYPE address-city,
*         streetAddress TYPE address-streetaddress,
*         latitude      TYPE address-latitude,
*         longitude     TYPE address-longitude,
*         zipcode       TYPE address-zipcode,
*         maybe         TYPE  char30,

       END OF ls_user.

DATA lt_user TYPE STANDARD TABLE OF ls_user WITH NON-UNIQUE DEFAULT KEY.
DATA lv_dauer TYPE i.
*TYPES user_table TYPE STANDARD TABLE OF ls_user WITH NON-UNIQUE DEFAULT KEY.
DATA wa_user TYPE ls_user.


DATA(lv_json) =
`[{"id":1,"uuid":"3423e00f-b5c2-4f2c-bf88-baceca11c5f4","firstName":"Isabel",...}]
* JSON -> ABAP (iTab)
/ui2/cl_json=>deserialize(
  EXPORTING
    json             = lv_json
*    jsonx            =
    pretty_name      = /ui2/cl_json=>pretty_mode-camel_case
*    assoc_arrays     =
*    assoc_arrays_opt =
*    name_mappings    =
*    conversion_exits =
*    hex_as_base64    =
  CHANGING
    data             = lt_user
).

*cl_demo_output=>write_data( lv_json ).
cl_demo_output=>write_data( lt_user[ 4 ] ).
*

cl_demo_output=>write_data( lt_user[ 5 ]-jobtitle ).
cl_demo_output=>display( lt_user[ 6 ]-profileinfo ).
*
DELETE FROM zalm_fs_users.
*
GET RUN TIME FIELD lv_dauer.
*
*
*INSERT zalm_fs_users FROM TABLE lt_user. "ACCEPTING DUPLICATE KEYS.
*
DATA: zalm_local_user TYPE zalm_fs_users.

*LOOP AT lt_user into DATA(lv_user).
*    zalm_local_user-avatar = lv_user-avatar.
**  INSERT zalm_fs_todos from lv_user. "Loop in Workarea
*ENDLOOP.
**
** loop at lt_todo assigning <fs_todo>.  "Loop mit Field-Symbol
**      INSERT zalm_fs_todos from <fs_todo>.
**endloop.
*
*
GET RUN TIME FIELD lv_dauer.
WRITE lv_dauer.

在debug中,它将地址字段显示为嵌套对象:

并且输出在打印出来时显示“kind of”嵌套内部表类型地址:

在SEGW中,似乎也存在“复杂类型”类型,这是一个没有主键的对象/结构,可以插入到另一个结构(或表?,对此不确定)...现在如何将嵌套的typeds插入到users表中?还是不可能,所以我必须再次展平我的结构?
顺便说一句,我在SEGW中创建的“实体类型”与ddict表类型不同吗?因为我假设实体类型(或实体的示例)以某种方式存储在实体表中。它们与DDIC表是不同的概念吗?我通常也通过从ddict表导入来创建实体类型。所以我想知道

wljmcqd8

wljmcqd81#

我找到了问题的答案。(已经有一段时间了,忘记了这个线程;))。因此,要寻址DDIC物理表上的工作区内部表中包含的命名“地址”结构类型。在DDIC表中有一个列“GROUP”,在那里你可以给予你的包含一个“组名”。因此在这种情况下,当您将数据插入DDIC表时,它可以被识别为命名结构“地址”类型。

相关问题