forked from SAP2Moose/SAP2Moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
z_moose_extractor.abap
8055 lines (6329 loc) · 294 KB
/
z_moose_extractor.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
* generated on system T80 at 12.01.2024 on 11:54:54
*
* This is version 1.3.2
*
*The MIT License (MIT)
*
*Copyright (c) 2016 Rainer Winkler, CubeServ
*
*Permission is hereby granted, free of charge, to any person obtaining a copy
*of this software and associated documentation files (the "Software"), to deal
*in the Software without restriction, including without limitation the rights
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*copies of the Software, and to permit persons to whom the Software is
*furnished to do so, subject to the following conditions:
*
*The above copyright notice and this permission notice shall be included in all
*copies or substantial portions of the Software.
*
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*SOFTWARE.
"! The latest version is available on https://github.com/SAP2Moose/SAP2Moose
"!
"! Thanks to Enno Wulff for providing the initial ABAP 7.31 version
"!
REPORT z2mse_moose_extractor2.
TABLES tadir. "So that select-options work
SELECTION-SCREEN BEGIN OF BLOCK block_global_source WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN END OF BLOCK block_global_source.
SELECTION-SCREEN BEGIN OF BLOCK block_selct_sap_comp WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS s_pack FOR tadir-devclass.
SELECT-OPTIONS s_spack FOR tadir-devclass.
DATA: element_filter TYPE string.
PARAMETERS p_eltyp TYPE text30.
PARAMETERS p_elpar TYPE c LENGTH 30.
PARAMETERS p_elnam TYPE c LENGTH 61.
PARAMETERS p_sub AS CHECKBOX DEFAULT 'X'.
PARAMETERS p_nup TYPE i DEFAULT -1.
PARAMETERS p_ndown TYPE i DEFAULT 1.
"Exclude interfaces in sap name space when found via where used analysis
PARAMETERS p_ex AS CHECKBOX DEFAULT 'X'.
PARAMETERS p_dyn TYPE string. "Classes to determine dynamic accesses
*SELECT-OPTIONS s_compsn FOR tadir-obj_name.
SELECTION-SCREEN END OF BLOCK block_selct_sap_comp.
SELECTION-SCREEN BEGIN OF BLOCK block_using_comp WITH FRAME TITLE TEXT-003.
*PARAMETERS: p_dm AS CHECKBOX DEFAULT ' '.
*"! Usages outside package grouped
*"! If false, a recursive search for using components is performed until no further using components are found
*DATA g_param_usage_outpack_groupd TYPE abap_bool.
*g_param_usage_outpack_groupd = p_dm.
SELECTION-SCREEN END OF BLOCK block_using_comp.
SELECTION-SCREEN BEGIN OF BLOCK block_infos WITH FRAME TITLE TEXT-004.
*PARAMETERS: p_list AS CHECKBOX DEFAULT ' '.
*"! List Tokens of selected programs
*DATA g_parameter_list_tokens TYPE abap_bool.
*g_parameter_list_tokens = p_list.
SELECTION-SCREEN END OF BLOCK block_infos.
" include z_mse.
******************************************** Begin Include Z_MSE_ABAP *****************************
*The MIT License (MIT)
*
*Copyright (c) 2016 Rainer Winkler, CubeServ
*
*Permission is hereby granted, free of charge, to any person obtaining a copy
*of this software and associated documentation files (the "Software"), to deal
*in the Software without restriction, including without limitation the rights
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*copies of the Software, and to permit persons to whom the Software is
*furnished to do so, subject to the following conditions:
*
*The above copyright notice and this permission notice shall be included in all
*copies or substantial portions of the Software.
*
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*SOFTWARE.
SELECTION-SCREEN BEGIN OF BLOCK bl_model_settings WITH FRAME TITLE TEXT-100.
PARAMETERS: p_down AS CHECKBOX DEFAULT 'X',
p_somix AS CHECKBOX DEFAULT 'X',
" Default filename
p_df TYPE string.
*"! Download model to file
*DATA g_parameter_download_file TYPE abap_bool.
*g_parameter_download_file = p_down.
SELECTION-SCREEN END OF BLOCK bl_model_settings.
SELECTION-SCREEN BEGIN OF BLOCK bl_customize WITH FRAME TITLE TEXT-200.
PARAMETERS: p_intrev AS CHECKBOX DEFAULT ''.
SELECTION-SCREEN END OF BLOCK bl_customize.
" Begin Model
"! Specifies a model.
"! Create an instance only once, otherwise there will be multiple models each containing only part of the informations.
CLASS cl_model DEFINITION
CREATE PUBLIC .
PUBLIC SECTION.
TYPES: BEGIN OF line_type,
line TYPE string,
END OF line_type.
TYPES: lines_type TYPE STANDARD TABLE OF line_type WITH DEFAULT KEY.
METHODS constructor.
"! Add a named entity
"! @parameter elementname | The name of the FAMIX Element. Like FAMIX.NamedEntity
"! @parameter name_group | optional to handle cases where names may be duplicates
"! @parameter is_named_entity | True if the entity has a name
"! @parameter is_id_required | Set true if (id: ...) is always required
"! @parameter can_be_referenced_by_name | True if referencing by name is possible (For this the name has to be unique)
"! @parameter name | the name of a FAMIX Entity that inherits from FAMIX.NamedEntity leave empty is is_named_entity is false
"! @parameter exists_already_with_id | only if can_be_referenced_by_name true. Zero if it does not yet exist, otherwise filled with id
"! @parameter processedid | the id in model either if just created or already existing
METHODS add_entity
IMPORTING elementname TYPE clike
name_group TYPE clike OPTIONAL
is_named_entity TYPE abap_bool
is_id_required TYPE abap_bool DEFAULT ''
can_be_referenced_by_name TYPE abap_bool
name TYPE clike OPTIONAL
EXPORTING VALUE(exists_already_with_id) TYPE i
VALUE(processed_id) TYPE i.
"! Generates a string with a valid MSE file
METHODS make_mse
EXPORTING
mse_model TYPE lines_type.
"! Generates an attribute of type string
"! Provide either ID or type and name of element
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
"! @parameter attribute_name | the name of the attribute
"! @parameter string | The value of the attribute
METHODS add_string
IMPORTING
element_id TYPE i
element_type TYPE clike OPTIONAL
element_name_group TYPE clike OPTIONAL
element_name TYPE clike OPTIONAL
attribute_name TYPE clike
string TYPE clike.
"! Generates an attribute of type reference using a name
"! Provide either ID or type and name of element
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
"! @parameter attribute_name | the name of the attribute
"! @parameter elementname | the element type of the reference
"! @parameter name_of_reference | the reference
METHODS add_reference_by_name
IMPORTING
element_id TYPE i
element_type TYPE clike OPTIONAL
element_name_group TYPE clike OPTIONAL
element_name TYPE clike OPTIONAL
attribute_name TYPE clike
type_of_reference TYPE clike
name_group_of_reference TYPE clike OPTIONAL
name_of_reference TYPE clike.
"! Generates an attribute of type reference using an id
"! Provide either ID or type and name of element
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
"! @parameter attribute_name | the name of the attribute
"! @parameter reference_id | the id of the reference
METHODS add_reference_by_id
IMPORTING
element_id TYPE i
element_type TYPE clike OPTIONAL
element_name_group TYPE clike OPTIONAL
element_name TYPE clike OPTIONAL
attribute_name TYPE clike
reference_id TYPE i.
"! Provide either ID or type and name of element
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
METHODS add_boolean
IMPORTING
element_id TYPE i
element_type TYPE clike OPTIONAL
element_name_group TYPE clike OPTIONAL
element_name TYPE clike OPTIONAL
attribute_name TYPE clike
is_true TYPE abap_bool.
" Public type so that the caller is able to test the model
TYPES:
"! A public type that returns the attributes of the model
"! Provide either ID or type and name of element
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
BEGIN OF public_attribute_type,
attribute_id TYPE i,
attribute_type TYPE string,
string TYPE string,
reference TYPE i,
boolean TYPE abap_bool,
END OF public_attribute_type.
TYPES:
"! A public table type to contain the attributes of an element
public_attributes_type TYPE HASHED TABLE OF public_attribute_type WITH UNIQUE KEY attribute_id.
TYPES:
"! A type that contains informations on an element
BEGIN OF public_element_type,
element_id TYPE i,
element_type TYPE string,
is_named_entity TYPE abap_bool,
is_id_required TYPE abap_bool,
public_attributes TYPE public_attributes_type,
END OF public_element_type.
TYPES:
"! A public table type to contain all elements of a model
public_elements_type TYPE HASHED TABLE OF public_element_type WITH UNIQUE KEY element_id.
"! Returns the current model
"! Use for checks and to decide what further actions are done to build the model.
"! Also to give a feedback what is extracted
METHODS get_model
RETURNING VALUE(public_elements) TYPE public_elements_type.
protected section.
PRIVATE SECTION.
TYPES: BEGIN OF element_in_model_type,
element_id TYPE i,
is_named_entity TYPE abap_bool,
is_id_required TYPE abap_bool,
element_type TYPE string,
END OF element_in_model_type.
"! A table with all Elements in the model
DATA g_elements_in_model TYPE HASHED TABLE OF element_in_model_type WITH UNIQUE KEY element_id.
TYPES: BEGIN OF named_entity_type,
element_type TYPE string,
element_name_group TYPE string,
element_name TYPE string,
element_id TYPE i,
END OF named_entity_type.
"! A table to find IDs using the names
DATA g_named_entities TYPE HASHED TABLE OF named_entity_type WITH UNIQUE KEY element_type element_name_group element_name.
TYPES value_type TYPE c LENGTH 1.
"! An attribute where a name is specified
CONSTANTS string_value TYPE value_type VALUE 'S'.
"! An attribute where a reference is specified
CONSTANTS reference_value TYPE value_type VALUE 'R'.
CONSTANTS boolean_value TYPE value_type VALUE 'B'.
TYPES: BEGIN OF attribute_type,
element_id TYPE i,
attribute_id TYPE i,
attribute_type TYPE string,
value_type TYPE value_type,
name TYPE string,
reference TYPE i,
boolean TYPE abap_bool,
END OF attribute_type.
"! A table with all the attributes of an entity
DATA g_attributes TYPE SORTED TABLE OF attribute_type WITH UNIQUE KEY element_id attribute_id.
"! The ID of processed entity in the model
DATA g_processed_id TYPE i.
"! The ID of any attribute. Unique together with mv_id
DATA g_attribute_id TYPE i.
"! True if attribute is already identically assigned
METHODS _check_if_attr_already_there
IMPORTING
attribute TYPE cl_model=>attribute_type
RETURNING
VALUE(already_there) TYPE abap_bool.
METHODS _get_element_id
IMPORTING
element_id TYPE i
element_type TYPE clike
element_name_group TYPE clike
element_name TYPE clike
RETURNING
VALUE(my_element_id) TYPE i.
ENDCLASS.
CLASS CL_MODEL IMPLEMENTATION.
METHOD add_boolean.
DATA ls_attribute LIKE LINE OF g_attributes. " ABAP 7.31 use prefix ls_ to prevent shadowing after conversion
CLEAR ls_attribute.
ls_attribute-element_id = _get_element_id( element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name ).
ls_attribute-attribute_type = attribute_name.
ls_attribute-value_type = boolean_value.
ls_attribute-boolean = is_true.
" SAP_2_FAMIX_52 Do not attributes twice if they are added with identical attributes
IF _check_if_attr_already_there( ls_attribute ) EQ abap_false.
sy-subrc = 1.
WHILE sy-subrc <> 0.
ADD 1 TO g_attribute_id.
ls_attribute-attribute_id = g_attribute_id.
INSERT ls_attribute INTO TABLE g_attributes.
ENDWHILE.
ENDIF.
ENDMETHOD.
METHOD add_entity.
IF can_be_referenced_by_name EQ abap_true.
ASSERT name_group IS NOT INITIAL.
ENDIF.
FIELD-SYMBOLS <ls_name> LIKE LINE OF g_named_entities.
IF can_be_referenced_by_name EQ abap_true.
READ TABLE g_named_entities ASSIGNING <ls_name>
WITH TABLE KEY element_type = elementname element_name_group = name_group element_name = name.
IF sy-subrc EQ 0. "OK
exists_already_with_id = <ls_name>-element_id.
processed_id = <ls_name>-element_id.
RETURN.
ENDIF.
ENDIF.
ADD 1 TO g_processed_id.
g_attribute_id = 0.
IF can_be_referenced_by_name EQ abap_true.
DATA ls_named_entity LIKE LINE OF g_named_entities. " ABAP 7.31 use prefix ls_ to prevent shadowing after conversion
CLEAR ls_named_entity.
ls_named_entity-element_type = elementname.
ls_named_entity-element_name_group = name_group.
ls_named_entity-element_name = name.
ls_named_entity-element_id = g_processed_id.
INSERT ls_named_entity INTO TABLE g_named_entities.
ENDIF.
DATA ls_elements_in_model LIKE LINE OF g_elements_in_model. " ABAP 7.31 use prefix ls_ to prevent shadowing after conversion
CLEAR ls_elements_in_model.
ls_elements_in_model-element_id = g_processed_id.
ls_elements_in_model-is_named_entity = is_named_entity.
ls_elements_in_model-is_id_required = is_id_required.
ls_elements_in_model-element_type = elementname.
INSERT ls_elements_in_model INTO TABLE g_elements_in_model.
IF is_named_entity EQ abap_true.
me->add_string( EXPORTING element_id = g_processed_id attribute_name = 'name' string = name element_name_group = name_group ).
ENDIF.
processed_id = g_processed_id.
ENDMETHOD.
METHOD add_reference_by_id.
DATA ls_attribute TYPE attribute_type. " ABAP 7.31 use prefix ls_ to prevent shadowing after conversion
CLEAR ls_attribute.
ls_attribute-element_id = _get_element_id( element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name ).
ls_attribute-attribute_type = attribute_name.
ls_attribute-value_type = reference_value.
ls_attribute-reference = reference_id.
" SAP_2_FAMIX_52 Do not attributes twice if they are added with identical attributes
IF _check_if_attr_already_there( ls_attribute ) EQ abap_false.
sy-subrc = 1.
WHILE sy-subrc <> 0.
ADD 1 TO g_attribute_id.
ls_attribute-attribute_id = g_attribute_id.
INSERT ls_attribute INTO TABLE g_attributes.
ENDWHILE.
ENDIF.
ENDMETHOD.
METHOD add_reference_by_name.
ASSERT name_group_of_reference IS NOT INITIAL.
FIELD-SYMBOLS <named_entity> LIKE LINE OF g_named_entities.
READ TABLE g_named_entities ASSIGNING <named_entity> WITH TABLE KEY element_type = type_of_reference
element_name_group = name_group_of_reference
element_name = name_of_reference.
* ASSERT sy-subrc EQ 0. "OK
IF sy-subrc <> 0.
ASSERT 1 = 2.
ENDIF.
DATA ls_attribute LIKE LINE OF g_attributes. " ABAP 7.31 use prefix ls_ to prevent shadowing after conversion
CLEAR ls_attribute.
ls_attribute-element_id = _get_element_id( element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name ).
ls_attribute-attribute_type = attribute_name.
ls_attribute-value_type = reference_value.
ls_attribute-reference = <named_entity>-element_id.
" SAP_2_FAMIX_52 Do not attributes twice if they are added with identical attributes
IF _check_if_attr_already_there( ls_attribute ) EQ abap_false.
sy-subrc = 1.
WHILE sy-subrc <> 0.
ADD 1 TO g_attribute_id.
ls_attribute-attribute_id = g_attribute_id.
INSERT ls_attribute INTO TABLE g_attributes.
ENDWHILE.
ENDIF.
ENDMETHOD.
METHOD add_string.
DATA ls_attribute LIKE LINE OF g_attributes. " ABAP 7.31 use prefix ls_ to prevent shadowing after conversion
CLEAR ls_attribute.
ls_attribute-element_id = _get_element_id( element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name ).
ls_attribute-attribute_type = attribute_name.
ls_attribute-value_type = string_value.
ls_attribute-name = string.
" SAP_2_FAMIX_52 Do not attributes twice if they are added with identical attributes
IF _check_if_attr_already_there( ls_attribute ) EQ abap_false.
sy-subrc = 1.
WHILE sy-subrc <> 0.
ADD 1 TO g_attribute_id.
ls_attribute-attribute_id = g_attribute_id.
INSERT ls_attribute INTO TABLE g_attributes.
ENDWHILE.
ENDIF.
ENDMETHOD.
METHOD constructor.
g_processed_id = 0.
ENDMETHOD.
METHOD get_model.
DATA ls_public_element TYPE public_element_type.
DATA ls_public_attribute TYPE public_attribute_type.
DATA lt_public_attributes TYPE public_attributes_type.
CLEAR public_elements.
DATA ls_elements_in_model LIKE LINE OF g_elements_in_model.
LOOP AT g_elements_in_model INTO ls_elements_in_model.
CLEAR lt_public_attributes.
DATA ls_attributes LIKE LINE OF g_attributes.
LOOP AT g_attributes INTO ls_attributes WHERE element_id = ls_elements_in_model-element_id.
CLEAR ls_public_attribute.
ls_public_attribute-attribute_id = ls_attributes-attribute_id.
ls_public_attribute-attribute_type = ls_attributes-attribute_type.
ls_public_attribute-boolean = ls_attributes-boolean.
ls_public_attribute-reference = ls_attributes-reference.
ls_public_attribute-string = ls_attributes-name.
INSERT ls_public_attribute INTO TABLE lt_public_attributes.
ENDLOOP.
CLEAR ls_public_element.
ls_public_element-element_type = ls_elements_in_model-element_type.
ls_public_element-element_id = ls_elements_in_model-element_id.
ls_public_element-is_named_entity = ls_elements_in_model-is_named_entity.
ls_public_element-is_id_required = ls_elements_in_model-is_id_required.
ls_public_element-public_attributes = lt_public_attributes.
INSERT ls_public_element INTO TABLE public_elements.
ENDLOOP.
ENDMETHOD.
METHOD make_mse.
" SAP_2_FAMIX_34 Allow to export the model in the .mse Moose format
DATA: mse_model_line TYPE line_type.
mse_model_line-line = |( |.
SORT g_elements_in_model BY element_id.
DATA is_first TYPE boolean VALUE abap_true.
FIELD-SYMBOLS <element_in_model> LIKE LINE OF g_elements_in_model.
LOOP AT g_elements_in_model ASSIGNING <element_in_model>.
IF is_first EQ abap_false.
APPEND mse_model_line TO mse_model.
CLEAR mse_model_line.
ENDIF.
mse_model_line-line = mse_model_line-line && |(| && <element_in_model>-element_type.
IF <element_in_model>-is_named_entity EQ abap_true
OR <element_in_model>-is_id_required EQ abap_true.
mse_model_line-line = mse_model_line-line && | (id: | && <element_in_model>-element_id && | )|.
ENDIF.
FIELD-SYMBOLS <attribute> LIKE LINE OF g_attributes.
LOOP AT g_attributes ASSIGNING <attribute> WHERE element_id = <element_in_model>-element_id.
APPEND mse_model_line TO mse_model.
mse_model_line-line = | (| && <attribute>-attribute_type.
ASSERT ( <attribute>-value_type EQ string_value ) OR ( <attribute>-value_type EQ reference_value ) OR ( <attribute>-value_type EQ boolean_value ).
CASE <attribute>-value_type.
WHEN string_value.
mse_model_line-line = mse_model_line-line && | '| && <attribute>-name && |')|.
WHEN reference_value.
mse_model_line-line = mse_model_line-line && | (ref: | && <attribute>-reference && |))|.
WHEN boolean_value.
ASSERT ( <attribute>-boolean EQ abap_true ) OR ( <attribute>-boolean EQ abap_false ).
CASE <attribute>-boolean.
WHEN abap_true.
mse_model_line-line = mse_model_line-line && | true)|.
WHEN abap_false.
mse_model_line-line = mse_model_line-line && | false)|.
ENDCASE.
ENDCASE.
ENDLOOP.
mse_model_line-line = mse_model_line-line && |)|.
is_first = abap_false.
ENDLOOP.
mse_model_line-line = mse_model_line-line && |)|.
APPEND mse_model_line TO mse_model.
ENDMETHOD.
METHOD _check_if_attr_already_there.
" Check if attribute is already there
DATA ls_attribute_2 TYPE attribute_type.
DATA ls_attribute_3 TYPE attribute_type.
ls_attribute_3 = attribute.
CLEAR ls_attribute_3-attribute_id.
already_there = abap_false.
LOOP AT g_attributes INTO ls_attribute_2 WHERE element_id = attribute-element_id.
CLEAR ls_attribute_2-attribute_id.
IF ls_attribute_2 EQ ls_attribute_3.
already_there = abap_true.
EXIT.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD _get_element_id.
" Get element ID
IF element_id <> 0.
my_element_id = element_id.
ELSE.
ASSERT element_name_group IS NOT INITIAL.
FIELD-SYMBOLS <element_named_entity> LIKE LINE OF g_named_entities.
READ TABLE g_named_entities ASSIGNING <element_named_entity> WITH TABLE KEY element_type = element_type
element_name_group = element_name_group
element_name = element_name.
ASSERT sy-subrc EQ 0. "OK
my_element_id = <element_named_entity>-element_id.
ENDIF.
ENDMETHOD.
ENDCLASS.
CLASS cl_output_model DEFINITION
CREATE PUBLIC.
PUBLIC SECTION.
METHODS make
IMPORTING
mse_model TYPE cl_model=>lines_type
g_parameter_download_file TYPE abap_bool
i_default_prefix TYPE string.
protected section.
private section.
ENDCLASS.
CLASS CL_OUTPUT_MODEL IMPLEMENTATION.
METHOD make.
" Download the file
DATA: filename TYPE string,
default_file_name TYPE string,
pathname TYPE string,
fullpath TYPE string,
user_action TYPE i.
default_file_name = |{ i_default_prefix }_{ sy-sysid }_{ sy-datum }_{ sy-uzeit }|.
IF g_parameter_download_file EQ abap_true.
cl_gui_frontend_services=>file_save_dialog( EXPORTING default_extension = 'mse'
default_file_name = default_file_name
CHANGING filename = filename " File Name to Save
path = pathname " Path to File
fullpath = fullpath " Path + File Name
user_action = user_action ). " User Action (C Class Const ACTION_OK, ACTION_OVERWRITE etc)
IF user_action = cl_gui_frontend_services=>action_cancel.
WRITE: / 'Canceled by user'.
ELSE.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = fullpath
TABLES
data_tab = mse_model.
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
******************************************** End Include Z_MSE_ABAP *******************************
" include z_famix.
******************************************** Begin Include Z_FAMIX_ABAP ***************************
*The MIT License (MIT)
*
*Copyright (c) 2016 Rainer Winkler, CubeServ
*
*Permission is hereby granted, free of charge, to any person obtaining a copy
*of this software and associated documentation files (the "Software"), to deal
*in the Software without restriction, including without limitation the rights
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*copies of the Software, and to permit persons to whom the Software is
*furnished to do so, subject to the following conditions:
*
*The above copyright notice and this permission notice shall be included in all
*copies or substantial portions of the Software.
*
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*SOFTWARE.
CLASS cl_famix_entity DEFINITION ABSTRACT
CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor IMPORTING model TYPE REF TO cl_model.
PROTECTED SECTION.
DATA g_elementname TYPE string.
DATA g_model TYPE REF TO cl_model.
DATA g_last_used_id TYPE i.
private section.
ENDCLASS.
CLASS CL_FAMIX_ENTITY IMPLEMENTATION.
METHOD constructor.
g_model = model.
ENDMETHOD.
ENDCLASS.
CLASS cl_famix_sourced_entity DEFINITION ABSTRACT INHERITING FROM cl_famix_entity
CREATE PUBLIC.
PUBLIC SECTION.
"! Declare source language
"! Provide either ID or type and name of element
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
"! @parameter source_language_element | the FAMIX element of the source language
"! @parameter source_language_name | the name of the source language
METHODS set_declared_source_language
IMPORTING
element_id TYPE i
element_type TYPE clike OPTIONAL
element_name_group TYPE clike OPTIONAL
element_name TYPE clike OPTIONAL
source_language_element TYPE clike
source_language_name TYPE clike.
protected section.
private section.
ENDCLASS.
CLASS CL_FAMIX_SOURCED_ENTITY IMPLEMENTATION.
METHOD set_declared_source_language.
g_model->add_reference_by_name( EXPORTING element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name
attribute_name = 'declaredSourceLanguage'
type_of_reference = source_language_element
name_of_reference = source_language_name ).
ENDMETHOD.
ENDCLASS.
class CL_FAMIX_FILE_ANCHOR definition
inheriting from CL_FAMIX_ENTITY
create public .
public section.
"! Call once to create a new file anchor entiry
"! @parameter element_id | The ID of the element for which a source is specified
"! @parameter file_name | The path or link to the source
methods ADD
importing
!ELEMENT_ID type I
!FILE_NAME type CLIKE
exporting
value(ID) type I .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS CL_FAMIX_FILE_ANCHOR IMPLEMENTATION.
METHOD add.
g_model->add_entity( EXPORTING elementname = |FAMIX.FileAnchor|
name_group = |FILE_ANCHOR|
is_named_entity = abap_false
is_id_required = abap_true
can_be_referenced_by_name = abap_false
IMPORTING processed_id = id ).
g_model->add_reference_by_id( EXPORTING element_id = id
attribute_name = 'element'
reference_id = element_id ).
g_model->add_string( EXPORTING element_id = id
attribute_name = 'fileName'
string = file_name ).
g_last_used_id = id.
ENDMETHOD.
ENDCLASS.
CLASS cl_famix_named_entity DEFINITION INHERITING FROM cl_famix_sourced_entity ABSTRACT
CREATE PUBLIC.
PUBLIC SECTION.
"! Call once to create a new named entity
"! @parameter exists_already_with_id | Contains the id if entry already existed.
"! @parameter id | The id in model either if just created or already existing.
"! @parameter modifiers | A list of modifiers separated by blank. This attribute is marked by an asterisk in the Moose Meta Browser, which may be the sign of this. Will be an Ordered Collection in Moose.
METHODS add
IMPORTING name_group TYPE clike OPTIONAL
name TYPE clike
modifiers TYPE clike OPTIONAL
EXPORTING VALUE(exists_already_with_id) TYPE i
VALUE(id) TYPE i.
"! Call once to set the parent package
"! Provide either ID or type and name of element
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
"! @parameter parent_package | the name of an element of type FAMIX.Package
METHODS set_parent_package IMPORTING element_id TYPE i
element_type TYPE clike OPTIONAL
element_name_group TYPE clike OPTIONAL
element_name TYPE clike OPTIONAL
parent_package TYPE clike
parent_package_name_group TYPE clike.
"! Set the container an element is in using the reference
"! Provide either ID or type and name of element
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
"! @parameter container_element | the FAMIX element of the Container
"! @parameter source_anchor_id | the id of the SoureceAnchor
METHODS set_source_anchor_by_id IMPORTING element_id TYPE i
element_type TYPE clike OPTIONAL
element_name_group TYPE clike OPTIONAL
element_name TYPE clike OPTIONAL
source_anchor_id TYPE i.
PROTECTED SECTION.
private section.
ENDCLASS.
CLASS CL_FAMIX_NAMED_ENTITY IMPLEMENTATION.
METHOD add.
" ASSERT name_group IS NOT INITIAL.
g_model->add_entity( EXPORTING elementname = g_elementname
is_named_entity = abap_true
can_be_referenced_by_name = abap_true
name_group = name_group
name = name
IMPORTING exists_already_with_id = exists_already_with_id
processed_id = id ).
IF modifiers IS SUPPLIED.
g_model->add_string( EXPORTING element_id = id
attribute_name = 'modifiers'
string = modifiers ).
ENDIF.
g_last_used_id = id.
ENDMETHOD.
METHOD set_parent_package.
g_model->add_reference_by_name( element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name type_of_reference = 'FAMIX.Package'
name_of_reference = parent_package
name_group_of_reference = parent_package_name_group
attribute_name = 'parentPackage' ).
ENDMETHOD.
METHOD set_source_anchor_by_id.
g_model->add_reference_by_id( EXPORTING element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name
attribute_name = 'sourceAnchor'
reference_id = source_anchor_id ).
ENDMETHOD.
ENDCLASS.
CLASS cl_famix_attribute DEFINITION INHERITING FROM cl_famix_named_entity
CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor IMPORTING model TYPE REF TO cl_model.
"! Store the relation between class, attribute name and id in internal table to enable associations
"! Call before performing the next time the method add, because the ID is stored internally after creating an element
"! @parameter class | the class of the method
"! @parameter attribute | the attribute name
METHODS store_id
IMPORTING
name_group TYPE clike
class TYPE clike
attribute TYPE clike.
"! Returns the ID for a given attribute of a class
"! Returns 0 if the attribute is not known
"! @parameter class | the class of the attribute
"! @parameter attribute | the attribute name
"! @parameter id | the ID of the element
METHODS get_id
IMPORTING
name_group TYPE clike
class TYPE clike
attribute TYPE clike
RETURNING VALUE(id) TYPE i.
METHODS add REDEFINITION.
"! set the parent type, for instance the class the method is contained in
"! Provide either ID or type and name of element
"! For parent: provide either parent_element and parent_name or parent_id
"! @parameter element_id | the ID of the element where the ID shall be added
"! @parameter elemenent_type | the element type of the element (not needed if ID is provided)
"! @parameter element_name_group | the name group of the element where the ID shall be added
"! @parameter element_name | the name of the element
"! @parameter parent_element | the FAMIX element of the parent Type
"! @parameter parent_name_group | the name group of the parent element
"! @parameter parent_name | the name of the parent element
"! @parameter parent_id | the id of the parent element
METHODS set_parent_type
IMPORTING
element_id TYPE i
element_type TYPE clike OPTIONAL
element_name_group TYPE clike OPTIONAL
element_name TYPE clike OPTIONAL
parent_element TYPE clike OPTIONAL
parent_name_group TYPE clike OPTIONAL
parent_name TYPE clike OPTIONAL
parent_id TYPE i OPTIONAL.
protected section.
PRIVATE SECTION.
TYPES: BEGIN OF attribute_id_type,
name_group TYPE string,
class TYPE string,
attribute TYPE string,
id TYPE i,
END OF attribute_id_type.
DATA: g_attribute_ids TYPE HASHED TABLE OF attribute_id_type WITH UNIQUE KEY name_group class attribute.
ENDCLASS.
CLASS CL_FAMIX_ATTRIBUTE IMPLEMENTATION.
METHOD add.
g_model->add_entity(
EXPORTING elementname = g_elementname
is_named_entity = abap_true
can_be_referenced_by_name = abap_false
name = name
IMPORTING processed_id = id ).
g_last_used_id = id.
ENDMETHOD.
METHOD constructor.
CALL METHOD super->constructor( model ).
g_elementname = 'FAMIX.Attribute'.
ENDMETHOD.
METHOD get_id.
FIELD-SYMBOLS <attribute_id> LIKE LINE OF g_attribute_ids.
READ TABLE g_attribute_ids ASSIGNING <attribute_id> WITH TABLE KEY name_group = name_group class = class attribute = attribute.
IF sy-subrc EQ 0. "OK
id = <attribute_id>-id.
ELSE.
id = 0.
ENDIF.
ENDMETHOD.
METHOD set_parent_type.
ASSERT ( parent_element IS SUPPLIED AND parent_name IS SUPPLIED )
OR parent_id IS SUPPLIED.
IF parent_element IS SUPPLIED AND parent_name IS SUPPLIED.
g_model->add_reference_by_name( EXPORTING element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name
attribute_name = 'parentType'
type_of_reference = parent_element
name_group_of_reference = parent_name_group
name_of_reference = parent_name ).
ELSEIF parent_id IS SUPPLIED.
g_model->add_reference_by_id( EXPORTING element_id = element_id
element_type = element_type
element_name_group = element_name_group
element_name = element_name
attribute_name = 'parentType'
reference_id = parent_id ).
ENDIF.
ENDMETHOD.
METHOD store_id.
DATA ls_attribute_id LIKE LINE OF g_attribute_ids. " ABAP 7.31 use prefix ls_ to prevent shadowing after conversion
CLEAR ls_attribute_id.
ls_attribute_id-id = g_last_used_id.
ls_attribute_id-name_group = name_group.
ls_attribute_id-class = class.
ls_attribute_id-attribute = attribute.
INSERT ls_attribute_id INTO TABLE g_attribute_ids.