This repository has been archived by the owner on Jul 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
zcl_generate_dev268.txt
178 lines (126 loc) · 7.39 KB
/
zcl_generate_dev268.txt
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
CLASS zcl_generate_dev268_#### DEFINITION
PUBLIC
INHERITING FROM cl_xco_cp_adt_simple_classrun
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
PROTECTED SECTION.
METHODS main REDEFINITION.
PRIVATE SECTION.
DATA package_name TYPE sxco_package VALUE 'ZRAP_INVENTORY_####'.
DATA unique_number TYPE string VALUE '####'.
DATA table_name_inventory TYPE sxco_dbt_object_name.
DATA dev_system_environment TYPE REF TO if_xco_cp_gen_env_dev_system.
DATA transport TYPE sxco_transport .
METHODS generate_table IMPORTING io_put_operation TYPE REF TO if_xco_cp_gen_d_o_put
table_name TYPE sxco_dbt_object_name
table_short_description TYPE if_xco_cp_gen_tabl_dbt_s_form=>tv_short_description .
METHODS get_json_string RETURNING VALUE(json_string) TYPE string.
ENDCLASS.
CLASS zcl_generate_dev268_#### IMPLEMENTATION.
METHOD main.
DATA json_string TYPE string.
json_string = get_json_string( ).
package_name = to_upper( package_name ).
DATA(lo_package) = xco_cp_abap_repository=>object->devc->for( package_name ).
IF NOT lo_package->exists( ).
RAISE EXCEPTION TYPE /dmo/cx_rap_generator
EXPORTING
textid = /dmo/cx_rap_generator=>package_does_not_exist
mv_value = CONV #( package_name ).
ENDIF.
table_name_inventory = |ZRAP_INVEN_{ unique_number }|.
DATA(lo_table) = xco_cp_abap_repository=>object->tabl->for( CONV #( table_name_inventory ) ).
IF lo_table->exists( ) = abap_false.
DATA(lv_package_software_component) = lo_package->read( )-property-software_component->name.
DATA(lo_transport_layer) = lo_package->read( )-property-transport_layer.
DATA(lo_transport_target) = lo_transport_layer->get_transport_target( ).
DATA(lv_transport_target) = lo_transport_target->value.
DATA(lo_transport_request) = xco_cp_cts=>transports->workbench( lo_transport_target->value )->create_request( | create tables | ).
DATA(lv_transport) = lo_transport_request->value.
transport = lv_transport.
dev_system_environment = xco_cp_generation=>environment->dev_system( lv_transport ).
DATA(lo_objects_put_operation) = dev_system_environment->create_put_operation( ).
generate_table(
EXPORTING
io_put_operation = lo_objects_put_operation
table_name = table_name_inventory
table_short_description = | Inventory data group { unique_number }|
).
DATA(lo_result) = lo_objects_put_operation->execute( ).
out->write( | table { table_name_inventory } created| ).
DATA(lo_findings) = lo_result->findings.
DATA(lt_findings) = lo_findings->get( ).
IF lt_findings IS NOT INITIAL.
out->write( lt_findings ).
ENDIF.
ELSE.
out->write( | table { table_name_inventory } already exists| ).
ENDIF.
"create RAP BO
DATA(rap_generator) = NEW /dmo/cl_rap_generator( json_string ).
DATA(todos) = rap_generator->generate_bo( ).
DATA(rap_bo_name) = rap_generator->root_node->rap_root_node_objects-service_binding.
out->write( |RAP BO { rap_bo_name } generated successfully| ).
out->write( |Todo's:| ).
LOOP AT todos INTO DATA(todo).
out->write( todo ).
ENDLOOP.
ENDMETHOD.
METHOD generate_table.
DATA(lo_specification) = io_put_operation->for-tabl-for-database_table->add_object( table_name
)->set_package( package_name
)->create_form_specification( ).
lo_specification->set_short_description( table_short_description ).
lo_specification->set_delivery_class( xco_cp_database_table=>delivery_class->l ).
lo_specification->set_data_maintenance( xco_cp_database_table=>data_maintenance->allowed ).
DATA database_table_field TYPE REF TO if_xco_gen_tabl_dbt_s_fo_field .
database_table_field = lo_specification->add_field( 'CLIENT' ).
database_table_field->set_type( xco_cp_abap_dictionary=>data_element( 'MANDT' ) )->set_key_indicator( )->set_not_null( ).
database_table_field = lo_specification->add_field( 'UUID' ).
database_table_field->set_type( xco_cp_abap_dictionary=>data_element( 'SYSUUID_X16' ) )->set_key_indicator( )->set_not_null( ).
database_table_field = lo_specification->add_field( 'INVENTORY_ID' ).
database_table_field->set_type( xco_cp_abap_dictionary=>built_in_type->numc( 6 ) ).
database_table_field = lo_specification->add_field( 'PRODUCT_ID' ).
database_table_field->set_type( xco_cp_abap_dictionary=>built_in_type->char( 10 ) ).
database_table_field = lo_specification->add_field( 'QUANTITY' ).
database_table_field->set_type( xco_cp_abap_dictionary=>built_in_type->quan( iv_length = 13 iv_decimals = 3 ) ).
database_table_field->currency_quantity->set_reference_table( CONV #( to_upper( table_name ) ) )->set_reference_field( 'QUANTITY_UNIT' ).
database_table_field = lo_specification->add_field( 'QUANTITY_UNIT' ).
database_table_field->set_type( xco_cp_abap_dictionary=>built_in_type->unit( 3 ) ).
database_table_field = lo_specification->add_field( 'PRICE' ).
database_table_field->set_type( xco_cp_abap_dictionary=>built_in_type->curr( iv_length = 16 iv_decimals = 2 ) ).
database_table_field->currency_quantity->set_reference_table( CONV #( to_upper( table_name ) ) )->set_reference_field( 'CURRENCY_CODE' ).
database_table_field = lo_specification->add_field( 'CURRENCY_CODE' ).
database_table_field->set_type( xco_cp_abap_dictionary=>built_in_type->cuky ).
database_table_field = lo_specification->add_field( 'REMARK' ).
database_table_field->set_type( xco_cp_abap_dictionary=>built_in_type->char( 256 ) ).
database_table_field = lo_specification->add_field( 'NOT_AVAILABLE' ).
database_table_field->set_type( xco_cp_abap_dictionary=>data_element( 'ABAP_BOOLEAN' ) ).
database_table_field = lo_specification->add_field( 'CREATED_BY' ).
database_table_field->set_type( xco_cp_abap_dictionary=>data_element( 'SYUNAME' ) ).
database_table_field = lo_specification->add_field( 'CREATED_AT' ).
database_table_field->set_type( xco_cp_abap_dictionary=>data_element( 'TIMESTAMPL' ) ).
database_table_field = lo_specification->add_field( 'LAST_CHANGED_BY' ).
database_table_field->set_type( xco_cp_abap_dictionary=>data_element( 'SYUNAME' ) ).
database_table_field = lo_specification->add_field( 'LAST_CHANGED_AT' ).
database_table_field->set_type( xco_cp_abap_dictionary=>data_element( 'TIMESTAMPL' ) ).
ENDMETHOD.
METHOD get_json_string.
json_string ='{' && |\r\n| &&
' "implementationType": "managed_uuid",' && |\r\n| &&
' "namespace": "Z",' && |\r\n| &&
| "suffix": "_{ unique_number }",| && |\r\n| &&
' "prefix": "RAP_",' && |\r\n| &&
| "package": "{ package_name }",| && |\r\n| &&
' "datasourcetype": "table",' && |\r\n| &&
' "bindingtype": "odata_v2_ui",' && |\r\n| &&
| "transportrequest": "{ transport }",| && |\r\n| &&
' "hierarchy": {' && |\r\n| &&
' "entityName": "Inventory",' && |\r\n| &&
| "dataSource": "zrap_inven_{ unique_number }",| && |\r\n| &&
' "objectId": "inventory_id" ' && |\r\n| &&
' }' && |\r\n| &&
'}'.
ENDMETHOD.
ENDCLASS.