SAP 内表数据转换为JSON格式

DATA: lv_json TYPE string.

DATA: lt_mapping_items TYPE /ui2/cl_json=>name_mappings.

DATA: BEGIN OF ls_detail,

code TYPE string,

name TYPE string,

age TYPE string,

END OF ls_detail,

lt_detail LIKE TABLE OF ls_detail,

BEGIN OF ls_header,

origh TYPE string,

orname TYPE string,

details LIKE lt_detail,

END OF ls_header.

ls_detail-code = 'A001'.

ls_detail-name = '张三'.

ls_detail-age = '18'.

APPEND ls_detail TO lt_detail.

ls_detail-code = 'A002'.

ls_detail-name = '李四'.

ls_detail-age = '25'.

APPEND ls_detail TO lt_detail.

ls_header-origh = 'C0001'.

ls_header-orname = '测试'.

ls_header-details = lt_detail.

"ABAP对应JSON字段映射

lt_mapping_items = VALUE #( ( abap = 'origh' json = 'orgid' )

( abap = 'orname' json = 'orname' )

( abap = 'details' json = 'details' )

( abap = 'code' json = 'id' )

( abap = 'name' json = 'name' )

( abap = 'age' json = 'age' )

).

"ABAP结构转JSON

lv_json = /ui2/cl_json=>serialize(

data = ls_header

compress = abap_false

pretty_name = /ui2/cl_json=>pretty_mode-camel_case

name_mappings = lt_mapping_items ).

WRITE: / 'ABAP转JSON结果:',lv_json.

相关推荐
Martin-Luo3 天前
Vue3 通过json配置生成查询表单
javascript·vue.js·json
星尘库3 天前
后端json数据反序列化枚举类型不匹配的错误
json
BXCQ_xuan3 天前
软件工程实践四:MyBatis-Plus 教程(连接、分页、查询)
spring boot·mysql·json·mybatis
王维志4 天前
LiteDB详解
数据库·后端·mongodb·sqlite·c#·json·database
ID_180079054734 天前
Python采集京东店铺所有商品数据,json数据返回
json
ljh5746491194 天前
mysql 必须在逗号分隔字符串和JSON字段之间二选一,怎么选
数据库·mysql·json
小孔龙4 天前
02.Kotlin Serialization 属性序列化控制
kotlin·json
Cachel wood4 天前
信息检索、推荐系统模型排序质量指标:AP@K和MAP@K
windows·搜索引擎·json·推荐系统·搜索
tebukaopu1485 天前
json文件转excel
json·excel
小孔龙6 天前
01.Kotlin Serialization - 基础用法
kotlin·json