ABAPJson格式转ABAP内表
Posted SAP剑客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAPJson格式转ABAP内表相关的知识,希望对你有一定的参考价值。
Demo 1:
TYPES: BEGIN OF T_RECORD1,
NUMNO TYPE CHAR10,
PRODNAME TYPE CHAR50,
END OF T_RECORD1.
DATA: JSON1 TYPE STRING.
DATA : RECORD1 TYPE TABLE OF T_RECORD1 WITH HEADER LINE .
JSON1 = '["NumNo":"001","ProdName":"Fert01","NumNo":"002","ProdName":"Fert02"]'.
/UI2/CL_JSON=>DESERIALIZE( EXPORTING JSON = JSON1
PRETTY_NAME = /UI2/CL_JSON=>PRETTY_MODE-CAMEL_CASE
CHANGING DATA = RECORD1[] ).
LOOP AT RECORD1.
WRITE : / RECORD1-NUMNO,RECORD1-PRODNAME.
ENDLOOP.
Demo 2:
DATA : BEGIN OF LS_RECORD,
DATALIST TYPE TABLE OF ZDATALIST_DETAIL,
END OF LS_RECORD.
DATA: JSON TYPE STRING.
DATA : RECORD2 TYPE ZDATALIST WITH HEADER LINE.
JSON = '"dataList":["NumNo":"001","ProdName":"Fert01","NumNo":"002","ProdName":"Fert02"]'.
/UI2/CL_JSON=>DESERIALIZE( EXPORTING JSON = JSON
PRETTY_NAME = /UI2/CL_JSON=>PRETTY_MODE-CAMEL_CASE
CHANGING DATA = LS_RECORD ).
IF LS_RECORD-DATALIST IS NOT INITIAL.
RECORD2[] = LS_RECORD-DATALIST.
ENDIF.
LOOP AT RECORD2.
WRITE : / RECORD2-NUMNO,RECORD2-PRODNAME.
ENDLOOP.
以上是关于ABAPJson格式转ABAP内表的主要内容,如果未能解决你的问题,请参考以下文章