SAP 自定义解析JSON方法

JSON串
HEADER = ‘{“STATUS”:“1”,“BSART”:“SH02”,“LIFNR”:“0040003799”,“EKORG”:“SHM1”,“EKGRP”:“SH2”,“BUKRS”:“5200”,“ZCMISNO”:"",“ZCRTNAME”:"",“ZSWZXR”:"",“LONGTEXT”:"",“ERNAM”:"",“WAERS”:"",“EBELNESSC”:""}’.

FORM analysis_json TABLES tab_alv TYPE STANDARD TABLE
USING t
CHANGING gv_text status ebelnessc tdline.
FIELD-SYMBOLS: .

DATA:BEGIN OF tab_j,
txt(262143) TYPE c,
END OF tab_j.
DATA:tab1 LIKE TABLE OF tab_j WITH HEADER LINE.
DATA:tab2 LIKE TABLE OF tab_j WITH HEADER LINE.
DATA:lv_fld_name TYPE string.
DATA:key TYPE string.
DATA:value TYPE string.
REPLACE ALL OCCURRENCES OF ‘[’ IN t WITH ‘’.
REPLACE ALL OCCURRENCES OF ‘]’ IN t WITH ‘’.
SPLIT t AT ‘}’ INTO TABLE tab1.
LOOP AT tab1.
REPLACE ALL OCCURRENCES OF ‘{’ IN tab1-txt WITH ‘’.
SPLIT tab1-txt AT ‘,’ INTO TABLE tab2.
LOOP AT tab2.
IF tab2-txt <> ‘’.
CLEAR:key,value.
REPLACE ALL OCCURRENCES OF ‘"’ IN tab2-txt WITH ‘’.
SPLIT tab2-txt AT ‘:’ INTO key value.
CONDENSE key NO-GAPS.
CONDENSE value NO-GAPS.
IF key = ‘PS_PSP_PNR’.
SELECT SINGLE pspnr INTO value FROM prps WHERE posid = value.
ENDIF.
IF value = ‘NULL’.
value = ‘’.
ENDIF.
IF value = ‘null’.
value = ‘’.
ENDIF.

    IF key = 'LONGTEXT'.
      gv_text = value.
    ELSEIF key = 'STATUS'.
      status = value.
    ELSEIF key = 'EBELNESSC'.
      ebelnessc = value.
    ELSEIF key = 'TDLINE'.
      tdline = value.
    ELSE.
      CONCATENATE 'TAB_ALV-' key INTO lv_fld_name.
      ASSIGN (lv_fld_name) TO <fs1>.
      <fs1> = value.
    ENDIF.
  ENDIF.
ENDLOOP.
APPEND tab_alv.
CLEAR:tab_alv.
CLEAR:tab2,tab2[].

ENDLOOP.
ENDFORM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值