-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzgsp_api_connect.abap
126 lines (112 loc) · 4.33 KB
/
zgsp_api_connect.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
*&---------------------------------------------------------------------*
*& Report ZGSP_API_CONNECT
*&---------------------------------------------------------------------*
*& GST E-Invoicing GSP API Connectivity Solution (SAP ABAP Code)
*& Please review first then adjust the code
*&
*& Details:
*& https://github.com/sujianalytics/gst-e-invoicing-sap
*&
*& Note: You need to use dynamic data instead of static invoice number
*& in the following code. This is only connectivity solution, this code
*& does not contains any busines data mapping.
*&---------------------------------------------------------------------*
REPORT zgsp_api_connect
LINE-SIZE 400 NO STANDARD PAGE HEADING.
DATA: BEGIN OF tabl OCCURS 500,
line(400),
END OF tabl.
DATA: lt_file_table TYPE rsanm_file_table,
ls_file_table TYPE LINE OF rsanm_file_table.
*&---------------------------------------------------------------------*
*& Create payload and save into JSON file
*&---------------------------------------------------------------------*
CLEAR: ls_file_table.
REFRESH: lt_file_table.
"To have following data in payload
*[
* {
* "transaction": {
* "Version": "1.1",
* "TranDtls": {
* "TaxSch": "GST",
* "SupTyp": "B2B",
* "RegRev": "Y",
* "EcmGstin": null,
* "IgstOnIntra": "N"
* "DocNumer": "INV123"
* }
* }
* }
*]
*
" You need to enter them line by as shown below:
ls_file_table = '['. APPEND ls_file_table TO lt_file_table.
ls_file_table = '{'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '"transaction": {'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '"Version": "1.1",'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '"TranDtls": {'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '"TaxSch": "GST",'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '"SupTyp": "B2B",'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '"RegRev": "Y",'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '"EcmGstin": null,'. APPEND ls_file_table TO lt_file_table..
ls_file_table = '"IgstOnIntra": "N"'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '"DocNumer": "INV123"'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '}'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '}'. APPEND ls_file_table TO lt_file_table.
ls_file_table = '}'. APPEND ls_file_table TO lt_file_table.
ls_file_table = ']'. APPEND ls_file_table TO lt_file_table.
CALL METHOD cl_rsan_ut_appserv_file_writer=>appserver_file_write
EXPORTING
i_filename = '/usr/sap/SID/D01/work/INV123_P.json' "<--- Use dynamic data
i_overwrite = abap_true
i_data_tab = lt_file_table
EXCEPTIONS
open_failed = 1
write_failed = 2
close_failed = 3
OTHERS = 4.
IF sy-subrc IS INITIAL.
WRITE:/ 'File Write', 'Success'.
ELSE.
WRITE:/ 'File Write', 'Error'.
ENDIF.
*&---------------------------------------------------------------------*
*& Trigger data send process and wait for result
*&---------------------------------------------------------------------*
WRITE:/ 'Send Data', 'Started'.
CALL 'SYSTEM' ID 'COMMAND' FIELD 'bash sujigspcon.sh sujiapi.conf INV123_P.json' "<--- Use dynamic data
ID 'TAB' FIELD tabl[]. "<--- CLI return found here
IF sy-subrc IS INITIAL.
WRITE:/ 'Send Data', 'Success'.
WRITE:/ '====================================================='.
LOOP AT tabl.
WRITE:/ tabl.
ENDLOOP.
ELSE.
WRITE:/ 'Send Data', 'Error', sy-subrc.
ENDIF.
*&---------------------------------------------------------------------*
*& Read received data
*&---------------------------------------------------------------------*
CLEAR: ls_file_table.
REFRESH: lt_file_table.
CALL METHOD cl_rsan_ut_appserv_file_reader=>appserver_file_read
EXPORTING
i_filename = '/usr/sap/JPD/D01/work/INV123_R.json' "<--- Use dynamic data
CHANGING
c_data_tab = lt_file_table
EXCEPTIONS
open_failed = 1
read_failed = 2
close_failed = 3
OTHERS = 4.
IF sy-subrc IS INITIAL.
WRITE:/ 'File Read', 'Success'.
WRITE:/ '====================================================='.
LOOP AT lt_file_table INTO ls_file_table.
WRITE:/ ls_file_table.
ENDLOOP.
ELSE.
WRITE:/ 'File Read', 'Error', 'File not found'.
ENDIF.