0% found this document useful (0 votes)
10 views3 pages

JSON Data Processing in ABAP Report

Uploaded by

naseema.begum
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

JSON Data Processing in ABAP Report

Uploaded by

naseema.begum
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

*&---------------------------------------------------------------------*

*& Report ZAPI_JSON_TO_IT


*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zapi_json_to_it.

INITIALIZATION.
DATA:filename TYPE string.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS : fpath TYPE rlgrap-filename.
SELECTION-SCREEN :END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR fpath.

CALL METHOD cl_gui_frontend_services=>directory_browse


CHANGING
selected_folder = filename
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
fpath = filename.

START-OF-SELECTION.

TABLES:kna1,adrc,adr6.

filename = fpath.

TYPES:BEGIN OF ty_file,

text(5000),

END OF ty_file.

DATA:lv_json TYPE TABLE OF ty_file,


wa_json TYPE ty_file.

TYPES:BEGIN OF ty_buyercode,

buyerCode(50),

END OF ty_buyercode.

DATA:tt_buyercode TYPE TABLE OF ty_buyercode.

TYPES: BEGIN OF ty_buyerInfo,

type(50),
value(100),

END OF ty_buyerInfo,

BEGIN OF ty_buyer,
buyerCode(50), " like tt_buyercode,
buyerNm TYPE name1_gp,
addrLine1 TYPE zaddress,
city TYPE ort01_gp,
postalCode TYPE pstlz,
stateNm TYPE regio,
stateCode(5),
cntryNm TYPE land1_gp,
cntryCode(3),
mobile TYPE telf1,
telNo TYPE ad_tlnmbr1,
email TYPE ad_smtpadr,
paymentMethod(4),
buyerAltInfo TYPE ty_buyerInfo,
active(10),

END OF ty_buyer.

DATA:lt_buyer TYPE TABLE OF ty_buyer.

TYPES:BEGIN OF final_json,

action(10),
buyer LIKE lt_buyer,

END OF final_json.

data: lt_final type final_json.

CALL FUNCTION 'GUI_UPLOAD'


EXPORTING
filename = filename
* HEADER =
TABLES
data_tab = lv_json
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
DATA lv_json1 TYPE string.
LOOP AT lv_json INTO wa_json.

CONCATENATE lv_json1 wa_json-text INTO lv_json1 SEPARATED BY space.

ENDLOOP.

CONDENSE lv_json1.

/ui2/cl_json=>deserialize(
EXPORTING
json = lv_json1

pretty_name = /ui2/cl_json=>pretty_mode-camel_case

CHANGING
data = lt_final
).

IF sy-subrc = 0 .

ENDIF.

You might also like