-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata uploader abap
More file actions
206 lines (184 loc) · 8.19 KB
/
data uploader abap
File metadata and controls
206 lines (184 loc) · 8.19 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
CLASS zrkc_xx_data_builder DEFINITION
PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PRIVATE SECTION.
DATA: out TYPE REF TO if_oo_adt_classrun_out.
METHODS fill_master_data RAISING cx_uuid_error.
METHODS fill_transaction_data RAISING cx_uuid_error.
METHODS flush.
ENDCLASS.
CLASS zrkc_xx_data_builder IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
me->out = out.
TRY.
out->write( |CLIENT: { sy-mandt }| ).
flush( ).
fill_master_data( ).
fill_transaction_data( ).
COMMIT WORK.
out->write( 'processing is completed successfully!' ).
DATA: lv_bp TYPE i, lv_prod TYPE i, lv_hdr TYPE i, lv_item TYPE i.
SELECT COUNT(*) FROM zrkc_xx_bpa INTO @lv_bp.
SELECT COUNT(*) FROM zrkc_xx_product INTO @lv_prod.
SELECT COUNT(*) FROM zrkc_xx_so_hdr INTO @lv_hdr.
SELECT COUNT(*) FROM zrkc_xx_so_item INTO @lv_item.
out->write( |DB counts -> BP: { lv_bp }, PROD: { lv_prod }, SO_HDR: { lv_hdr }, SO_ITEM: { lv_item }| ).
CATCH cx_uuid_error INTO DATA(lx_uuid).
out->write( |UUID Error: { lx_uuid->get_text( ) }| ).
ROLLBACK WORK.
ENDTRY.
ENDMETHOD.
METHOD fill_master_data.
DATA: lt_bp TYPE TABLE OF zrkc_xx_bpa,
lt_prod TYPE TABLE OF zrkc_xx_product.
" 8 BPs - FULL DDL FIELDS + CLIENT
APPEND VALUE #( client = sy-mandt
bp_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
bp_role = '01'
company_name = 'TACUM'
street = 'Victoria Street'
city = 'Kolkatta'
country = 'IN'
region = 'APJ' ) TO lt_bp.
APPEND VALUE #( client = sy-mandt
bp_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
bp_role = '01'
company_name = 'SAP'
street = 'Rosvelt Street Road'
city = 'Walldorf'
country = 'DE'
region = 'EMEA' ) TO lt_bp.
APPEND VALUE #( client = sy-mandt
bp_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
bp_role = '01'
company_name = 'Asia High tech'
street = '1-7-2 Otemachi'
city = 'Tokyo'
country = 'JP'
region = 'APJ' ) TO lt_bp.
APPEND VALUE #( client = sy-mandt
bp_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
bp_role = '01'
company_name = 'AVANTEL'
street = 'Bosque de Duraznos'
city = 'Maxico'
country = 'MX'
region = 'NA' ) TO lt_bp.
APPEND VALUE #( client = sy-mandt
bp_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
bp_role = '01'
company_name = 'Pear Computing Services'
street = 'Dunwoody Xing'
city = 'Atlanta, Georgia'
country = 'US'
region = 'NA' ) TO lt_bp.
APPEND VALUE #( client = sy-mandt
bp_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
bp_role = '01'
company_name = 'PicoBit'
street = 'Fith Avenue'
city = 'New York City'
country = 'US'
region = 'NA' ) TO lt_bp.
APPEND VALUE #( client = sy-mandt
bp_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
bp_role = '01'
company_name = 'TACUM'
street = 'Victoria Street'
city = 'Kolkatta'
country = 'IN'
region = 'APJ' ) TO lt_bp.
APPEND VALUE #( client = sy-mandt
bp_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
bp_role = '01'
company_name = 'Indian IT Trading Company'
street = 'Nariman Point'
city = 'Mumbai'
country = 'IN'
region = 'APJ' ) TO lt_bp.
" 6 Products (adjust fields to match your product table)
APPEND VALUE #( client = sy-mandt
product_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
name = 'Blaster Extreme'
category = 'Speakers'
price = 1500
currency = 'INR'
discount = 3 ) TO lt_prod.
APPEND VALUE #( client = sy-mandt
product_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
name = 'Sound Booster'
category = 'Speakers'
price = 2500
currency = 'INR'
discount = 2 ) TO lt_prod.
APPEND VALUE #( client = sy-mandt
product_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
name = 'Smart Office'
category = 'Software'
price = 1540
currency = 'INR'
discount = 32 ) TO lt_prod.
APPEND VALUE #( client = sy-mandt
product_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
name = 'Smart Design'
category = 'Software'
price = 2400
currency = 'INR'
discount = 12 ) TO lt_prod.
APPEND VALUE #( client = sy-mandt
product_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
name = 'Transcend Carry pocket'
category = 'PCs'
price = 14000
currency = 'INR'
discount = 7 ) TO lt_prod.
APPEND VALUE #( client = sy-mandt
product_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
name = 'Gaming Monster Pro'
category = 'PCs'
price = 15500
currency = 'INR'
discount = 8 ) TO lt_prod.
INSERT zrkc_xx_bpa FROM TABLE @lt_bp.
INSERT zrkc_xx_product FROM TABLE @lt_prod.
out->write( |Inserted { lines( lt_bp ) } BP(s) and { lines( lt_prod ) } product(s).| ).
ENDMETHOD.
METHOD fill_transaction_data.
DATA: lv_date TYPE timestamp, lv_ord_id TYPE zrkc_xx_dte_id,
lt_so TYPE TABLE OF zrkc_xx_so_hdr, lt_so_i TYPE TABLE OF zrkc_xx_so_item,
lt_bpa TYPE TABLE OF zrkc_xx_bpa, lt_prod TYPE TABLE OF zrkc_xx_product.
GET TIME STAMP FIELD lv_date.
SELECT * FROM zrkc_xx_bpa INTO TABLE @lt_bpa.
SELECT * FROM zrkc_xx_product INTO TABLE @lt_prod.
DO 50 TIMES.
lv_ord_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( ).
READ TABLE lt_bpa INDEX 1 INTO DATA(ls_bp).
APPEND VALUE #( client = sy-mandt
order_id = lv_ord_id
order_no = sy-index
buyer = ls_bp-bp_id
gross_amount = 1000
currency_code = 'INR'
created_by = sy-uname
created_on = lv_date ) TO lt_so.
READ TABLE lt_prod INDEX 1 INTO DATA(ls_prod).
APPEND VALUE #( client = sy-mandt
item_id = cl_uuid_factory=>create_system_uuid( )->create_uuid_c32( )
order_id = lv_ord_id
product = ls_prod-product_id
qty = 1
uom = 'EA'
amount = ls_prod-price
currency = 'INR' ) TO lt_so_i.
ENDDO.
INSERT zrkc_xx_so_hdr FROM TABLE @lt_so.
INSERT zrkc_xx_so_item FROM TABLE @lt_so_i.
out->write( |Inserted 50 SO header(s) and 50 item(s).| ).
ENDMETHOD.
METHOD flush.
DELETE FROM zrkc_xx_bpa. DELETE FROM zrkc_xx_product.
DELETE FROM zrkc_xx_so_hdr. DELETE FROM zrkc_xx_so_item.
out->write( |Existing data deleted.| ).
ENDMETHOD.
ENDCLASS.