-
Notifications
You must be signed in to change notification settings - Fork 286
/
zcl_demo_abap_rap_ext_num_u.clas.abap
1090 lines (941 loc) · 38.5 KB
/
zcl_demo_abap_rap_ext_num_u.clas.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
"! <p class="shorttext"><strong>ABAP EML in a RAP scenario (unmanaged BO)</strong><br/>ABAP cheat sheet example class</p>
"!
"! <p>The example class demonstrates ABAP EML in the context of a RAP demo scenario (unmanaged RAP BO with external numbering).
"! The class represents a RAP BO consumer.<br/> Choose F9 in ADT to run the class.</p>
"!
"! <h2>Note</h2>
"! <ul><li>This class is the RAP BO consumer for a RAP demo scenario that
"! demonstrates various RAP BO standard operations and non-standard
"! operations using ABAP EML in the context of an unmanaged RAP business
"! object with RAP external numbering.</li>
"! <li>Topics covered: RAP BO operations like create, update, delete,
"! executing actions, instance and global feature control, instance
"! authorization, create-by-association (parent to child), read,
"! read-by-association (parent to child), read (child entity),
"! read-by-association (child to parent)</li>
"! <li>Underlying data model: Consists of a root entity and one child entity.
"! The BDEF defines the behavior for these two entities which are connected
"! via a CDS composition relation. The definitions in the BDEF determine
"! which methods must be implemented in the ABAP behavior pool (ABP).
"! <li>ABP for this scenario: {@link zbp_demo_abap_rap_ro_u}.</li>
"! <li> For demonstration purposes, some of the operations are
"! impacted by feature controls and instance authorization as specified
"! in the BDEF.</li>
"! <li> This simplified example is not a real life scenario and rather
"! focuses on the technical side by giving an idea how the communication
"! and data exchange between a RAP BO consumer, which is a class
"! in this case, and RAP BO provider can work. Additionally, it shows
"! how the methods for non-standard RAP BO operations might be
"! self-implemented in an ABP. The example is intentionally kept
"! short and simple and focuses on specific RAP aspects. For this reason,
"! the example might not fully meet the requirements of the RAP BO contract.</li>
"! <li>Find information on <strong>getting started with the example class</strong> and the
"! <strong>disclaimer</strong> in the ABAP Doc comment of class {@link zcl_demo_abap_aux}.</li>
"! </ul>
CLASS zcl_demo_abap_rap_ext_num_u DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES: if_oo_adt_classrun.
CLASS-METHODS:
class_constructor.
protected section.
PRIVATE SECTION.
CLASS-DATA:
failed TYPE RESPONSE FOR FAILED zdemo_abap_rap_ro_u,
reported TYPE RESPONSE FOR REPORTED zdemo_abap_rap_ro_u,
mapped TYPE RESPONSE FOR MAPPED zdemo_abap_rap_ro_u,
op TYPE string.
CLASS-METHODS:
initialize_dbtabs,
"If there are entries in the response parameters following EML
"requests, they should be processed for displaying purposes.
extract_from_reported RETURNING VALUE(messages) TYPE string_table,
extract_from_failed RETURNING VALUE(errors) TYPE string_table,
fill_db_tab.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_RAP_EXT_NUM_U IMPLEMENTATION.
METHOD class_constructor.
initialize_dbtabs( ).
ENDMETHOD.
METHOD extract_from_failed.
CLEAR errors.
LOOP AT failed-root ASSIGNING FIELD-SYMBOL(<err>).
CASE if_abap_behv=>mk-on.
WHEN <err>-%op-%create.
op = `create operation`.
WHEN <err>-%op-%update.
op = `update operation`.
WHEN <err>-%op-%delete.
op = `delete operation`.
WHEN <err>-%op-%assoc-_child.
op = `operation involving the child entity`.
WHEN <err>-%op-%action-multiply_by_2.
op = `executing action multiply_by_2`.
WHEN <err>-%op-%action-multiply_by_3.
op = `executing action multiply_by_3`.
WHEN <err>-%op-%action-set_z.
op = `executing action set_z`.
WHEN OTHERS. op = `operation`.
ENDCASE.
APPEND `Error for instance with ` &&
COND #( WHEN <err>-%cid IS NOT INITIAL THEN `%cid = `
&& <err>-%cid
ELSE `key = ` && <err>-key_field ) &&
`: Fail cause ` && <err>-%fail-cause && ` for ` && op
&& `.` TO errors.
ENDLOOP.
IF failed-child IS NOT INITIAL.
LOOP AT failed-child ASSIGNING FIELD-SYMBOL(<err_ch>).
APPEND `Error for child instance with ` &&
COND #( WHEN <err_ch>-%cid IS NOT INITIAL THEN `%cid = `
&& <err_ch>-%cid
ELSE `key_field = ` && <err_ch>-key_field &&
` and key_ch = ` && <err_ch>-key_ch ) &&
`: Fail cause ` && <err_ch>-%fail-cause && ` for operation.`
TO errors.
ENDLOOP.
ENDIF.
ENDMETHOD.
METHOD extract_from_reported.
CLEAR messages.
LOOP AT reported-root ASSIGNING FIELD-SYMBOL(<rep>).
IF <rep>-%global = if_abap_behv=>mk-on.
APPEND <rep>-%msg->m_severity && ` ` &&
<rep>-%msg->if_t100_dyn_msg~msgv1 TO messages.
ELSE.
APPEND `Message for instance with ` &&
COND #( WHEN <rep>-%cid IS NOT INITIAL
THEN `%cid = ` && <rep>-%cid
ELSE `key = ` && <rep>-key_field ) &&
`: ` && <rep>-%msg->m_severity && ` ` &&
<rep>-%msg->if_t100_dyn_msg~msgv1 TO messages.
ENDIF.
ENDLOOP.
IF reported-child IS NOT INITIAL.
LOOP AT reported-child ASSIGNING FIELD-SYMBOL(<rep_ch>).
APPEND `Message for child instance with key_field = ` &&
<rep_ch>-key_field && ` and key_ch = `
&& <rep_ch>-key_ch && `: ` && <rep_ch>-%msg->m_severity &&
` ` && <rep_ch>-%msg->if_t100_dyn_msg~msgv1 TO messages.
ENDLOOP.
ENDIF.
ENDMETHOD.
METHOD fill_db_tab.
MODIFY zdemo_abap_rapt1 FROM TABLE @( VALUE #(
( key_field = 4
field1 = 'fff'
field2 = 'ggg'
field3 = 40
field4 = 41 ) ) ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
out->write( |ABAP Cheat Sheet Example: RAP BO Operations Using an Unmanaged RAP BO (External Numbering)\n\n| ).
**********************************************************************
*
* Create operation
*
**********************************************************************
out->write( |1) Create Operation\n\n| ).
"Adding an entry to the database table to provoke an error for the
"EML create request.
fill_db_tab( ).
**********************************************************************
* Notes:
* - field4 is purposely not included in the FIELDS list
* - Effect:
* - %control value for field4 is set to if_abap_behv=>mk-off
* - Although the derived type (created inline here) includes a
* value assignment for field4 in an instance, the field value is
* not saved. The initial value is used.
* - The instance with key_field = 4 will not be saved since an entry
* already exists in the database table with the same key.
* - Response parameters are specified to receive information.
* - A COMMIT ENTITIES statement triggers the saving of the instances.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 )
WITH VALUE #( ( %cid = 'cid1'
key_field = 1
field1 = 'aaa'
field2 = 'bbb'
field3 = 10
field4 = 11 ) "Value not respected
( %cid = 'cid2'
key_field = 2
field1 = 'ccc'
field2 = 'ddd'
field3 = 20 )
( %cid = 'cid3'
key_field = 3
field1 = 'X'
field2 = 'eee'
field3 = 30 )
( %cid = 'cid4' "Instance to fail
key_field = 4
field1 = 'error'
field2 = 'error'
field3 = 99 ) )
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving and displaying database content
SELECT FROM zdemo_abap_rapt1
FIELDS key_field, field1, field2, field3, field4
ORDER BY key_field
INTO TABLE @DATA(tab_root).
out->write( data = tab_root name = `tab_root` ).
out->write( |\n| ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
out->write( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
out->write( |\n| ).
out->write( data = mapped-root name = `mapped-root` ).
out->write( |\n| ).
ENDIF.
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Update operations
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `2) Update Operation` ) ).
**********************************************************************
* Notes:
* - The EML request includes a create and an update request. The
* create request is included to have a %cid to refer to for demo
* purposes. This instance has not yet been persisted.
* - The EML statement for the create operation includes the ABAP
* FROM ... (instead of FIELDS ( ... ) WITH ...) for demo purposes.
* Here, the %control values must be set explicitly.
* - The update request purposely excludes field2 so as not to update
* the value of this particular field.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
CREATE FROM VALUE #(
%control-key_field = if_abap_behv=>mk-on
%control-field1 = if_abap_behv=>mk-on
%control-field2 = if_abap_behv=>mk-on
%control-field3 = if_abap_behv=>mk-on
%control-field4 = if_abap_behv=>mk-on
( %cid = 'cid5'
key_field = 5
field1 = 'hhh'
field2 = 'iii'
field3 = 50
field4 = 51 ) )
UPDATE FIELDS ( field1 field3 field4 )
WITH VALUE #(
"Update via cid_ref
( %cid_ref = 'cid5'
field1 = 'up_jjj'
field2 = 'up_kkk' "Value not respected
field3 = 500
field4 = 501 )
"Updates via key
( key_field = 1
field1 = 'up_lll'
field3 = 100
field4 = 101 )
( key_field = 2
field1 = 'up_mmm'
field3 = 200
field4 = 201 )
( key_field = 99 "Instance to fail
field1 = 'error'
field3 = 99
field4 = 99 ) )
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving and displaying database content
SELECT FROM zdemo_abap_rapt1
FIELDS key_field, field1, field2, field3, field4
ORDER BY key_field
INTO TABLE @tab_root.
out->write( data = tab_root name = `tab_root` ).
out->write( |\n| ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
out->write( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
out->write( |\n| ).
out->write( data = mapped-root name = `mapped-root` ).
out->write( |\n| ).
ENDIF.
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Delete operation
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `3) Delete Operation` ) ).
**********************************************************************
* Notes:
* - The EML request includes a create and an delete request. The
* create request is included to have a %cid to refer to for demo
* purposes. This instance has not yet been persisted.
* - EML statements for delete operations can only be used with the
* ABAP word FROM ....
* - Note: Instance authorization is defined in the BDEF. In this
* example, the corresponding handler method is implemented in a way
* that disables the deletion of instances if a field has a certain
* value. If field1 has the value 'X', a deletion is disabled.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_del'
key_field = 6
field1 = 'a'
field2 = 'b'
field3 = 60
field4 = 61 ) )
DELETE FROM VALUE #(
"Deletion via %cid_ref
( %cid_ref = 'cid_del' )
"Deletions via key
( key_field = 4 )
( key_field = 5 )
"Instances to fail
( key_field = 3 ) "Deletion disabled
( key_field = 100 ) ) "Key not available
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving and displaying database content
SELECT FROM zdemo_abap_rapt1
FIELDS key_field, field1, field2, field3, field4
ORDER BY key_field
INTO TABLE @tab_root.
out->write( data = tab_root name = `tab_root` ).
out->write( |\n| ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
out->write( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
out->write( |\n| ).
out->write( data = mapped-root name = `mapped-root` ).
out->write( |\n| ).
ENDIF.
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Action multiply_by_2
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `4) Executing Action mutliply_by_2` ) ).
**********************************************************************
* Notes:
* - The EML request includes a create request and a request to execute
* an action. The create request is included to have a %cid to refer
* to for demo purposes. This instance has not yet been persisted.
* - EML statements for executing actions can only be used with the
* ABAP word FROM ....
* - As the name implies, the action multiplies field
* values (field3 and field4) by 2 for requested instances.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_x2'
key_field = 7
field1 = 'nnn'
field2 = 'ooo'
field3 = 70
field4 = 71 ) )
EXECUTE multiply_by_2 FROM VALUE #(
"Executing action via %cid_ref
( %cid_ref = 'cid_x2' )
"Executing action via key
( key_field = 1 )
( key_field = 2 )
( key_field = 1234 ) ) "Instance to fail
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving and displaying database content
SELECT FROM zdemo_abap_rapt1
FIELDS key_field, field1, field2, field3, field4
ORDER BY key_field
INTO TABLE @tab_root.
out->write( data = tab_root name = `tab_root` ).
out->write( |\n| ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
out->write( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
out->write( |\n| ).
out->write( data = mapped-root name = `mapped-root` ).
out->write( |\n| ).
ENDIF.
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Action multiply_by_3
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `5) Executing Action mutliply_by_3` ) ).
**********************************************************************
* Notes:
* - The EML request includes a create request and a request to execute
* an action. The create request is included to have a %cid to refer
* to for demo purposes. This instance has not yet been persisted.
* - As the name implies, the action multiplies field
* values (field3 and field4) by 3 for requested instances.
* - Note: In the BDEF of this example, this action is defined with
* instance feature control. Here, the action execution is disabled
* if both integer values are 0.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_x3'
key_field = 8
field1 = 'ppp'
field2 = 'qqq'
field3 = 80
field4 = 81 ) )
EXECUTE multiply_by_3 FROM VALUE #(
"Executing action via %cid_ref
( %cid_ref = 'cid_x3' )
"Executing action via key
( key_field = 1 )
( key_field = 2 )
"Instances to fail
( key_field = 3 ) "Action execution disabled
( key_field = 1234 ) ) "Key not available
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving and displaying database content
SELECT FROM zdemo_abap_rapt1
FIELDS key_field, field1, field2, field3, field4
ORDER BY key_field
INTO TABLE @tab_root.
out->write( data = tab_root name = `tab_root` ).
out->write( |\n| ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
out->write( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
out->write( |\n| ).
out->write( data = mapped-root name = `mapped-root` ).
out->write( |\n| ).
ENDIF.
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Action set_z
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `6) Executing ACTION set_z` ) ).
**********************************************************************
* Notes:
* - The EML request includes a create request and a request to execute
* an action. The create request is included to have a %cid to refer
* to for demo purposes. This instance has not yet been persisted.
* - As the name implies, the action sets the value 'Z' for a
* particular field (field2) for requested instances.
* - Note: In the BDEF of this example, this action is defined with
* global feature control. Here, the action execution is disabled
* based on a certain time frame in which you run this example. You
* might want to change the time frame values in the ABP to check the
* effect.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_setz'
key_field = 9
field1 = 'rrr'
field2 = 'sss'
field3 = 90
field4 = 91 ) )
EXECUTE set_z FROM VALUE #(
"Executing action via %cid_ref
( %cid_ref = 'cid_setz' )
"Executing action via key
( key_field = 2 ) )
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving and displaying database content
SELECT FROM zdemo_abap_rapt1
FIELDS key_field, field1, field2, field3, field4
ORDER BY key_field
INTO TABLE @tab_root.
out->write( data = tab_root name = `tab_root` ).
out->write( |\n| ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
out->write( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
out->write( |\n| ).
out->write( data = mapped-root name = `mapped-root` ).
out->write( |\n| ).
ENDIF.
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Create-by-Association Operation (from Root to Child Entity)
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `7) Create-by-Association Operation (from Root to Child Entity)` ) ).
**********************************************************************
* Notes:
* - The EML request includes a create and create-by-association
* request, i. e. a "deep create". An instance is created for the
* root entity and, in the same request and based on this root
* instance, instances are created for the child entity, too.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_cba'
key_field = 10
field1 = 'ttt'
field2 = 'uuu'
field3 = 100
field4 = 101 ) )
CREATE BY \_child
FIELDS ( key_ch field_ch1 field_ch2 ) WITH VALUE #(
"CBA operation via %cid_ref
( %cid_ref = 'cid_cba'
%target = VALUE #( ( %cid = 'cid_ch1'
key_ch = 11
field_ch1 = 'aaa_ch'
field_ch2 = 110 )
( %cid = 'cid_ch2'
key_ch = 12
field_ch1 = 'bbb_ch'
field_ch2 = 120 ) ) )
"CBA operation via root key
( key_field = 1
%target = VALUE #( ( %cid = 'cid_ch3'
key_ch = 1
field_ch1 = 'ccc_ch'
field_ch2 = 11 )
( %cid = 'cid_ch4'
key_ch = 2
field_ch1 = 'ddd_ch'
field_ch2 = 22 ) ) )
( key_field = 2
%target = VALUE #( ( %cid = 'cid_ch5'
key_ch = 3
field_ch1 = 'ccc_ch'
field_ch2 = 33 )
( %cid = 'cid_ch6'
key_ch = 4
field_ch1 = 'ddd_ch'
field_ch2 = 44 ) ) )
"Instance to fail
( key_field = 123
%target = VALUE #( ( %cid = 'cid_ch7'
key_ch = 1
field_ch1 = 'error'
field_ch2 = 2 )
( %cid = 'cid_ch8'
key_ch = 2
field_ch1 = 'error'
field_ch2 = 3 ) ) ) )
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving and displaying database content
SELECT FROM zdemo_abap_rapt1
FIELDS key_field, field1, field2, field3, field4
ORDER BY key_field
INTO TABLE @tab_root.
SELECT FROM zdemo_abap_rapt2
FIELDS key_field, key_ch, field_ch1, field_ch2
ORDER BY key_field, key_ch
INTO TABLE @DATA(tab_child).
out->write( data = tab_root name = `tab_root` ).
out->write( |\n| ).
out->write( data = tab_child name = `tab_child` ).
out->write( |\n| ).
"Displaying response information
IF mapped IS NOT INITIAL.
out->write( `Entries in MAPPED response parameter ` &&
`(root and child entity)` ).
out->write( |\n| ).
out->write( data = mapped name = `mapped` ).
out->write( |\n| ).
ENDIF.
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Read operation
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `8) Read Operation (Root Entity)` ) ).
**********************************************************************
* Notes:
* - The EML request includes a read request. The EML statement uses
* the ABAP words ALL FIELDS WITH. In this case, as the name implies,
* all field values are retrieved. The %control values for all fields
* are set to if_abap_behv=>mk-on.
* - When using the ABAP words FIELDS ( ... ) WITH and specifying the
* concrete fields to be read, only for those fields %control is
* set accordingly.
* - Filling the parameter for RESULT is mandatory.
**********************************************************************
READ ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
ALL FIELDS WITH VALUE #(
( key_field = 1 )
( key_field = 2 )
( key_field = 5 ) ) "Instance to fail
RESULT DATA(result)
FAILED failed
REPORTED reported.
"Displaying the read result and response information
out->write( data = result name = `result` ).
out->write( |\n| ).
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
*********************************************************************
*
* Read operation (child entity)
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `9) Read Operation (Child Entity)` ) ).
**********************************************************************
* Notes:
* - The EML request includes a read request. The read operation is
* executed on the child entity directly by specifying the alias, as
* it is defined in the BDEF, following the ABAP word ENTITY.
* - All field values are read using the addition ALL FIELDS WITH.
**********************************************************************
READ ENTITIES OF zdemo_abap_rap_ro_u
ENTITY child
ALL FIELDS WITH VALUE #(
( key_field = 1 key_ch = 1 )
( key_field = 2 key_ch = 4 )
"Instances to fail
( key_field = 9 )
( key_field = 9 key_ch = 11 ) )
RESULT DATA(read_ch)
FAILED failed
REPORTED reported.
"Displaying read result
out->write( data = read_ch name = `read_ch` ).
"Displaying response information
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Read-by-association operation (from parent to child)
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `10) Read-by-Association Operation (from Parent to Child)` ) ).
**********************************************************************
* Notes:
* - The EML request includes a read-by-association request from the
* parent to the child entity.
* - All field values are read using the addition ALL FIELDS WITH.
* - Specifying the parameter for RESULT is mandatory.
* - Additionally, the optional association links are retrieved.
**********************************************************************
READ ENTITIES OF zdemo_abap_rap_ro_u
ENTITY root
BY \_child
ALL FIELDS WITH VALUE #(
( key_field = 2 )
( key_field = 10 )
( key_field = 111 ) ) "Instance to fail
RESULT DATA(rba_result)
LINK DATA(association_links)
FAILED failed
REPORTED reported.
"Displaying read result and association links
out->write( data = rba_result name = `rba_result` ).
out->write( |\n| ).
out->write( data = association_links name = `association_links` ).
out->write( |\n| ).
"Displaying response information
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Read-by-association operation (from child to parent)
*
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `11) Read-by-Association Operation (from Child to Parent)` ) ).
**********************************************************************
* Notes:
* - The EML request includes a read-by-association request from the
* child to the parent.
* - All field values are read using the addition ALL FIELDS WITH.
* - Specifying the parameter for RESULT is mandatory.
* - Additionally, the optional association links are retrieved.
**********************************************************************
READ ENTITIES OF zdemo_abap_rap_ro_u
ENTITY child
BY \_parent ALL FIELDS WITH VALUE #(
( key_field = 1 key_ch = 1 )
( key_field = 2 key_ch = 4 )
"Instances to fail
( key_field = 1 key_ch = 3 )
( key_field = 543 key_ch = 1 ) )
RESULT DATA(rba_parent)
LINK DATA(association_links_parent)
FAILED failed
REPORTED reported.
"Displaying read result and association links
out->write( data = rba_parent name = `rba_parent` ).
out->write( |\n| ).
out->write( data = association_links_parent name = `association_links_parent` ).
out->write( |\n| ).
"Displaying response information
IF failed IS NOT INITIAL.
out->write( `Entries in FAILED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_failed( ) name = `extract_from_failed( )` ).
out->write( |\n| ).
ENDIF.
IF reported IS NOT INITIAL.
out->write( `Entries in REPORTED response parameter` ).
out->write( |\n| ).
out->write( data = extract_from_reported( ) name = `extract_from_reported( )` ).
out->write( |\n| ).
ENDIF.
**********************************************************************
*
* Excursion: Read and read-by-association operation using dynamic
* EML statements
*
* Note:
* If the parameter for FULL is not flagged, only the association
* links are returned. The parameter for RESULT will be empty.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `12) Excursion: Read and read-by-association ` &&
`operations using dynamic EML` ) ).
DATA:
op_tab TYPE abp_behv_retrievals_tab,
read_dyn TYPE TABLE FOR READ IMPORT zdemo_abap_rap_ro_u,
read_dyn_result TYPE TABLE FOR READ RESULT zdemo_abap_rap_ro_u,