This commit is contained in:
danrega
2023-08-30 14:06:49 +02:00
parent 9a54c7a0a7
commit bef57aa1f9
134 changed files with 32704 additions and 1 deletions

20
.abapgit.xml Normal file
View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DATA>
<MASTER_LANGUAGE>E</MASTER_LANGUAGE>
<STARTING_FOLDER>/src/</STARTING_FOLDER>
<FOLDER_LOGIC>FULL</FOLDER_LOGIC>
<IGNORE>
<item>/.gitignore</item>
<item>/LICENSE</item>
<item>/README.md</item>
<item>/package.json</item>
<item>/.travis.yml</item>
<item>/.gitlab-ci.yml</item>
<item>/abaplint.json</item>
<item>/azure-pipelines.yml</item>
</IGNORE>
</DATA>
</asx:values>
</asx:abap>

201
LICENSE Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

73
LICENSES/Apache-2.0.txt Normal file
View File

@@ -0,0 +1,73 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -1 +1,5 @@
"initial commit"
ABAP cheat sheets for classic ABAP
ABAP version: 757
More information: [https://github.com/SAP-samples/abap-cheat-sheets](https://github.com/SAP-samples/abap-cheat-sheets)

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_ENQU" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DD25V>
<VIEWNAME>EZDEMO_ABAP_LOCK</VIEWNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<AGGTYPE>E</AGGTYPE>
<ROOTTAB>ZDEMO_ABAP_RAPT1</ROOTTAB>
<DDTEXT>Lock on demo table</DDTEXT>
</DD25V>
<DD26E_TABLE>
<DD26E>
<VIEWNAME>EZDEMO_ABAP_LOCK</VIEWNAME>
<TABNAME>ZDEMO_ABAP_RAPT1</TABNAME>
<TABPOS>0001</TABPOS>
<FORTABNAME>ZDEMO_ABAP_RAPT1</FORTABNAME>
<ENQMODE>E</ENQMODE>
</DD26E>
</DD26E_TABLE>
<DD27P_TABLE>
<DD27P>
<VIEWNAME>EZDEMO_ABAP_LOCK</VIEWNAME>
<OBJPOS>0001</OBJPOS>
<VIEWFIELD>CLIENT</VIEWFIELD>
<TABNAME>ZDEMO_ABAP_RAPT1</TABNAME>
<FIELDNAME>CLIENT</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ENQMODE>E</ENQMODE>
</DD27P>
<DD27P>
<VIEWNAME>EZDEMO_ABAP_LOCK</VIEWNAME>
<OBJPOS>0002</OBJPOS>
<VIEWFIELD>KEY_FIELD</VIEWFIELD>
<TABNAME>ZDEMO_ABAP_RAPT1</TABNAME>
<FIELDNAME>KEY_FIELD</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ENQMODE>E</ENQMODE>
</DD27P>
</DD27P_TABLE>
</asx:values>
</asx:abap>
</abapGit>

10
src/package.devc.xml Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DEVC>
<CTEXT>test</CTEXT>
</DEVC>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DEVC>
<CTEXT>ABAP Cheat Sheets: Classic ABAP</CTEXT>
</DEVC>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,139 @@
CLASS zcl_demo_abap_sap_luw_helper DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES log_type TYPE SORTED TABLE OF zdemo_abap_logt WITH UNIQUE KEY id.
CLASS-DATA: itab TYPE STANDARD TABLE OF zdemo_abap_luw_t,
log_entries TYPE STANDARD TABLE OF zdemo_abap_logt.
CLASS-METHODS: get_work_process_info RETURNING VALUE(id_no) TYPE string,
create_log_entries IMPORTING log TYPE log_type,
checking_transaction_state RETURNING VALUE(tx_state) TYPE string,
cc_alv_display IMPORTING container TYPE c
log TYPE abap_bool DEFAULT abap_false,
subr_delete,
subr_insert IMPORTING values TYPE zdemo_abap_luw_t,
subr_update_log IMPORTING log TYPE log_type.
PROTECTED SECTION.
PRIVATE SECTION.
CLASS-DATA: wp_pid TYPE wppid,
wp_index TYPE wpindex.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_SAP_LUW_HELPER IMPLEMENTATION.
METHOD cc_alv_display.
DATA(cont) = NEW cl_gui_custom_container( container_name = container ).
IF log = abap_false.
SELECT key_field, ch, num, time_stamp
FROM zdemo_abap_luw_t
INTO CORRESPONDING FIELDS OF TABLE @Itab
ORDER BY key_field.
TRY.
cl_salv_table=>factory( EXPORTING r_container = cont
container_name = CONV string( container )
IMPORTING r_salv_table = DATA(alv)
CHANGING t_table = itab ).
DATA(columns) = alv->get_columns( ).
DATA(col_tab) = columns->get( ).
LOOP AT col_tab ASSIGNING FIELD-SYMBOL(<column>).
DATA(column) = columns->get_column( <column>-columnname ).
column->set_medium_text( CONV scrtext_m( <column>-columnname ) ).
IF <column>-columnname = 'CLIENT'.
<column>-r_column->set_visible( abap_false ).
ELSE.
<column>-r_column->set_visible( abap_true ).
ENDIF.
ENDLOOP.
alv->display( ).
CATCH cx_salv_msg cx_salv_not_found.
MESSAGE 'ALV display not possible' TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
ELSE.
SELECT id, context, name, details, timestamp
FROM zdemo_abap_logt
INTO CORRESPONDING FIELDS OF TABLE @log_entries
ORDER BY id.
TRY.
cl_salv_table=>factory( EXPORTING r_container = cont
container_name = CONV string( container )
IMPORTING r_salv_table = alv
CHANGING t_table = log_entries ).
columns = alv->get_columns( ).
col_tab = columns->get( ).
LOOP AT col_tab ASSIGNING FIELD-SYMBOL(<col>).
column = columns->get_column( <col>-columnname ).
column->set_medium_text( CONV scrtext_m( <col>-columnname ) ).
IF <col>-columnname = `DETAILS`.
column->set_output_length( 70 ).
ENDIF.
IF <col>-columnname = 'CLIENT'.
<col>-r_column->set_visible( abap_false ).
ELSE.
<col>-r_column->set_visible( abap_true ).
ENDIF.
ENDLOOP.
alv->display( ).
CATCH cx_salv_msg cx_salv_not_found.
MESSAGE 'ALV display not possible' TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
ENDIF.
ENDMETHOD.
METHOD checking_transaction_state.
tx_state = `Tx state: ` &&
`Update task (` && SWITCH #( cl_system_transaction_state=>get_in_update_task( ) WHEN 1 THEN `1)` ELSE `0)` ) &&
` Local update (` && SWITCH #( cl_system_transaction_state=>get_update_task_local( ) WHEN 1 THEN `1)` ELSE `0)` ) &&
` Perf. on commit (` && SWITCH #( cl_system_transaction_state=>get_on_commit( ) WHEN 1 THEN `1)` ELSE `0)` ) &&
` Perf. on rollback (` && SWITCH #( cl_system_transaction_state=>get_on_rollback( ) WHEN 1 THEN `1)` ELSE `0)` ).
ENDMETHOD.
METHOD create_log_entries.
INSERT zdemo_abap_logt FROM TABLE @log.
ENDMETHOD.
METHOD get_work_process_info.
CALL FUNCTION 'TH_GET_OWN_WP_NO'
IMPORTING
wp_pid = wp_pid
wp_index = wp_index.
id_no = |Work process ID: { wp_pid } / work process index: { wp_index }|.
ENDMETHOD.
METHOD subr_delete.
DELETE FROM zdemo_abap_luw_t.
ENDMETHOD.
METHOD subr_insert.
INSERT zdemo_abap_luw_t FROM @values.
ENDMETHOD.
METHOD subr_update_log.
INSERT zdemo_abap_logt FROM TABLE @log.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_SAP_LUW_HELPER</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Helper class for SAP LUW example</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_TABL" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DD02V>
<TABNAME>ZDEMO_ABAP_DBLUW</TABNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<TABCLASS>TRANSP</TABCLASS>
<CLIDEP>X</CLIDEP>
<DDTEXT>Demo database table</DDTEXT>
<MASTERLANG>E</MASTERLANG>
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_DBLUW</TABNAME>
<AS4LOCAL>A</AS4LOCAL>
<TABKAT>0</TABKAT>
<TABART>APPL0</TABART>
<BUFALLOW>N</BUFALLOW>
</DD09L>
<DD03P_TABLE>
<DD03P>
<FIELDNAME>CLIENT</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CLNT</DATATYPE>
<LENG>000003</LENG>
<MASK> CLNT</MASK>
</DD03P>
<DD03P>
<FIELDNAME>KEY_FIELD</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CH</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000020</INTLEN>
<DATATYPE>CHAR</DATATYPE>
<LENG>000010</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>NUM</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>TIME_STAMP</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>p</INTTYPE>
<INTLEN>000008</INTLEN>
<DATATYPE>UTCL</DATATYPE>
<LENG>000027</LENG>
<MASK> UTCL</MASK>
</DD03P>
</DD03P_TABLE>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,826 @@
*&---------------------------------------------------------------------*
*& ABAP cheat sheet: Dynpro
*&
*&-------------------------- PURPOSE ----------------------------------*
*& - Example to demonstrate dynpro-related statements
*& - Topics covered: Dynpro flow logic and related statements (MODULE,
*& FIELD, CHAIN/ENDCHAIN, LOOP/ENDLOOP, CALL SUBSCREEN), ABAP statements
*& for calling and leaving dynpros (SET SCREEN, CALL SCREEN, LEAVE
*& SCREEN), modifying static attributes (LOOP AT SCREEN, MODIFY SCREEN),
*& statements related to the GUI status and title (GET/SET PF-STATUS,
*& SET TITLEBAR), controls (table and tabstrip controls)
*&
*&----------------------- GETTING STARTED -----------------------------*
*& - Open the program with the ABAP development tools for Eclipse (ADT).
*& - Choose F8 to run the program.
*& - Select the radio buttons and/or provide input in input fields etc.
*& to check out dynpro-related syntax in action.
*&
*&----------------------------- NOTE -----------------------------------*
*& The code presented in this class is intended only to support the ABAP
*& cheat sheets. It is not intended for direct use in a production system
*& environment. The code examples in the ABAP cheat sheets are primarily
*& intended to provide a better explanation and visualization of the
*& syntax and semantics of ABAP statements, not to solve concrete
*& programming tasks. For production application programs, you should
*& always work out your own solution for each individual case. There is
*& no guarantee for the correctness or completeness of the code.
*& Furthermore, there is no legal responsibility or liability for any
*& errors or their consequences that may occur when using the the example
*& code.
*&---------------------------------------------------------------------*
REPORT zdemo_abap_dynpro.
DATA:
"OK field
ok_code LIKE sy-ucomm,
"Auxiliary variable for storing the value of the OK field
save_ok LIKE ok_code,
dyn_num LIKE sy-dynnr,
dyn_title LIKE sy-title.
"Note: This demo database table does not have any semantic information
"that may be used for input helps etc.
TABLES zdemo_abap_flsch.
"----- Related to dynpro 9850 (Home page) -----
DATA: screen_elements TYPE abap_bool,
stmts TYPE abap_bool,
stmts2 TYPE abap_bool,
controls TYPE abap_bool.
"----- Related to dynpro 9860 (Screen elements) -----
DATA: "Icons
icon TYPE icons-text,
icon_name TYPE c LENGTH 20,
icon_text TYPE c LENGTH 10,
"check boxes
ch_a TYPE abap_bool,
ch_b TYPE abap_bool,
ch_c TYPE abap_bool,
checkbox_msg TYPE c LENGTH 4,
input_field TYPE c LENGTH 20,
"radio buttons
rb_x TYPE abap_bool,
rb_y TYPE abap_bool,
rb_z TYPE abap_bool,
radiobutton_msg TYPE c LENGTH 1.
"----- Related to dynpro 9870 (Statements I) -----
DATA: call_screen TYPE abap_bool,
call_screen_starting TYPE abap_bool,
call_screen_st_end TYPE abap_bool,
set_screen TYPE abap_bool,
leave_screen_next TYPE abap_bool,
leave_screen_set TYPE abap_bool,
leave_to_screen TYPE abap_bool,
set_pfstatus TYPE abap_bool,
set_pf_excluding TYPE abap_bool,
get_pfstatus TYPE abap_bool,
get_pfstatsus_excl TYPE abap_bool,
set_titlebar TYPE abap_bool,
set_titlebar_with TYPE abap_bool,
with_title TYPE c LENGTH 15,
col1 TYPE i,
lin1 TYPE i,
col2 TYPE i,
lin2 TYPE i,
col3 TYPE i,
lin3 TYPE i,
pf TYPE c LENGTH 1,
pfkey TYPE syst_pfkey,
title TYPE c LENGTH 1.
"Data type and objects for the EXCLUDING addition of GET/SET PF-STATUS
"statements
TYPES fu_key_tab TYPE TABLE OF sy-ucomm WITH NON-UNIQUE KEY table_line.
DATA: excl_list1 TYPE fu_key_tab,
excl_list2 TYPE fu_key_tab,
excl_list3 TYPE fu_key_tab.
"----- Related to dynpro 9880 (Statements II) -----
DATA: loop_modify TYPE abap_bool,
field_stmt TYPE abap_bool,
mod_at_exit TYPE abap_bool,
selected TYPE abap_bool,
set TYPE abap_bool,
field_a TYPE c LENGTH 1,
field_b TYPE c LENGTH 1,
field_c TYPE c LENGTH 1,
field_d TYPE c LENGTH 1,
field_e TYPE c LENGTH 1,
field_f TYPE c LENGTH 1,
output_field_1 TYPE c LENGTH 100,
output_field_2 TYPE c LENGTH 100,
output_field_3 TYPE c LENGTH 100,
field_help TYPE c LENGTH 30,
input_help TYPE c LENGTH 30,
"For GET/SET CURSOR statements
fld TYPE c LENGTH 20,
off TYPE i,
val TYPE string,
len TYPE i.
"For field and input help
TYPES: BEGIN OF values,
carrid TYPE zdemo_abap_flsch-carrid,
connid TYPE zdemo_abap_flsch-connid,
END OF values.
DATA: progname TYPE sy-repid,
dynnum TYPE sy-dynnr,
dynpro_values TYPE TABLE OF dynpread,
field_value LIKE LINE OF dynpro_values,
values_tab TYPE TABLE OF values,
tab TYPE TABLE OF zdemo_abap_flsch-carrid,
carr TYPE zdemo_abap_flsch-carrid,
conn TYPE zdemo_abap_flsch-connid.
DATA itab_flsch TYPE TABLE OF zdemo_abap_flsch-carrid.
TYPES: BEGIN OF carrid_line,
carrid TYPE zdemo_abap_flsch-carrid,
END OF carrid_line.
DATA carrid_list TYPE STANDARD TABLE OF carrid_line.
"----- Related to dynpro 9890 (Exit command) -----
"For demonstration purposes, implementations for the
"related dialog modules are done in methods of a local
"class.
"----- Related to dynpro 9990 (Controls) -----
"For table controls
DATA lines TYPE i.
DATA fill TYPE i.
CONTROLS flights TYPE TABLEVIEW USING SCREEN 9900.
"Internal table to hold data that is to be displayed.
DATA itab_flights TYPE TABLE OF zdemo_abap_flsch WITH EMPTY KEY.
"Filling the internal table
SELECT *
FROM zdemo_abap_flsch
ORDER BY carrid, connid
INTO TABLE @itab_flights.
"For tabstrip controls
CONTROLS tabstr TYPE TABSTRIP.
DATA number LIKE sy-dynnr.
"For ALV Grid control
TYPES: BEGIN OF flight_struc,
carrid TYPE zdemo_abap_flsch-carrid,
connid TYPE zdemo_abap_flsch-connid,
countryfr TYPE zdemo_abap_flsch-countryfr,
cityfrom TYPE zdemo_abap_flsch-cityfrom,
airpfrom TYPE zdemo_abap_flsch-airpfrom,
countryto TYPE zdemo_abap_flsch-countryto,
cityto TYPE zdemo_abap_flsch-cityto,
airpto TYPE zdemo_abap_flsch-airpto,
fltime TYPE zdemo_abap_flsch-fltime,
END OF flight_struc.
DATA itab4alv TYPE TABLE OF flight_struc WITH EMPTY KEY.
"----- For other dialog modules -----
DATA: links TYPE TABLE OF tline,
field_tab TYPE TABLE OF dfies WITH EMPTY KEY.
"----- Local class -----
CLASS local_class DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: provide_fu_keys IMPORTING example TYPE i
RETURNING VALUE(fu_keys) TYPE fu_key_tab,
cc_alv_display IMPORTING container TYPE c,
"Implementations for dialog modules for dynpro 9890
pbo9890,
pai9890,
cancel.
"Variable declarations for dialog modules for dynpro 9890
CLASS-DATA: mandatory_field TYPE c LENGTH 20,
btn_exit_1 TYPE abap_bool,
btn_exit_2 TYPE abap_bool.
ENDCLASS.
CLASS local_class IMPLEMENTATION.
METHOD provide_fu_keys.
CASE example.
WHEN 1.
fu_keys = VALUE #( ( 'CANCEL' ) ( 'SAP' ) ).
WHEN 2.
fu_keys = VALUE #( ( 'CANCEL' ) ).
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
METHOD cc_alv_display.
DATA(cont) = NEW cl_gui_custom_container( container_name = container ).
SELECT carrid, connid, countryfr, cityfrom, airpfrom, countryto, cityto, airpto, fltime
FROM zdemo_abap_flsch
ORDER BY carrid, connid
INTO CORRESPONDING FIELDS OF TABLE @itab4alv.
TRY.
cl_salv_table=>factory( EXPORTING r_container = cont
container_name = CONV string( container )
IMPORTING r_salv_table = DATA(alv)
CHANGING t_table = itab4alv ).
alv->get_columns( )->set_optimize( abap_true ).
alv->get_display_settings( )->set_list_header( 'Flights' ).
LOOP AT alv->get_columns( )->get( ) ASSIGNING FIELD-SYMBOL(<col>).
DATA(column) = <col>-r_column.
column->set_long_text( |{ column->get_columnname( ) }| ).
ENDLOOP.
alv->display( ).
CATCH cx_salv_msg cx_salv_not_found.
MESSAGE `ALV display not possible` TYPE 'I'
DISPLAY LIKE 'E'.
ENDTRY.
ENDMETHOD.
METHOD pai9890.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'CLOSE1'.
MESSAGE `Processing continues. It does so only after the input field is filled.` TYPE 'I'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'CLOSE2'.
MESSAGE `Superfluouse message :)` TYPE 'I'.
WHEN OTHERS.
MESSAGE `Processing continues. It does so only after the input field is filled.` TYPE 'I'.
LEAVE PROGRAM.
ENDCASE.
ENDMETHOD.
METHOD pbo9890.
SET PF-STATUS 'STATUS9890'.
SET TITLEBAR 'TITLE9890'.
dyn_num = sy-dynnr.
ENDMETHOD.
METHOD cancel.
MESSAGE `Module "cancel" was called. The dynpro will be left without the need to fill in the mandatory input field.` TYPE 'I'.
IF ok_code = 'CLOSE2'.
CLEAR: ok_code, mandatory_field.
SET SCREEN 0.
LEAVE SCREEN.
ENDIF.
ENDMETHOD.
ENDCLASS.
END-OF-SELECTION.
"Filling demo database tables
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
CALL SCREEN 9850.
**********************************************************************
***************** Dialog modules for 9850 ****************************
MODULE status_9850 OUTPUT.
SET PF-STATUS 'STATUS9850'.
SET TITLEBAR 'TITLE9850'.
CLEAR: screen_elements, stmts, stmts2.
dyn_num = sy-dynnr.
ENDMODULE.
MODULE user_command_9850 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'ENTER' OR 'GO'.
CASE abap_true.
WHEN screen_elements.
CALL SCREEN 9860.
WHEN stmts.
CALL SCREEN 9870.
WHEN stmts2.
CALL SCREEN 9880.
WHEN controls.
CALL SCREEN 9900.
ENDCASE.
WHEN OTHERS.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
***************** Dialog modules for 9860 ****************************
MODULE status_9860 OUTPUT.
SET PF-STATUS 'STATUS9860'.
SET TITLEBAR 'TITLE9860'.
"Modifying static attributes
IF loop_modify = 'X'.
LOOP AT SCREEN INTO DATA(scr).
IF scr-name = 'ICON3'.
scr-invisible = '1'.
MODIFY SCREEN FROM scr.
ENDIF.
IF scr-name = 'INPUT_FIELD'.
scr-length = 10.
scr-intensified = '1'.
"scr-required = '1'.
MODIFY SCREEN FROM scr.
ENDIF.
IF scr-name = 'RB_Z'.
scr-active = '0'.
MODIFY SCREEN FROM scr.
ENDIF.
IF scr-name = 'CH_B'.
scr-input = '0'.
MODIFY SCREEN FROM scr.
ENDIF.
ENDLOOP.
ENDIF.
dyn_num = sy-dynnr.
ENDMODULE.
MODULE user_command_9860 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
"Icons
WHEN 'ICON1'.
icon_name = 'ICON_GREEN_LIGHT'.
icon_text = `green`.
WHEN 'ICON2'.
icon_name = 'ICON_YELLOW_LIGHT'.
icon_text = `yellow`.
WHEN 'ICON3'.
icon_name = 'ICON_RED_LIGHT'.
icon_text = `red`.
"Input field
WHEN 'BTN_NO'.
MESSAGE |The text "{ input_field }" in the input field has { numofchar( input_field ) } characters. Trailing blanks are ignored.| TYPE 'I'.
"Check boxes
WHEN 'CH_BTN'.
IF ch_a = abap_true.
checkbox_msg = 'A'.
ENDIF.
IF ch_b = abap_true.
checkbox_msg = checkbox_msg && 'B'.
ENDIF.
IF ch_c = abap_true.
checkbox_msg = checkbox_msg && 'C'.
ENDIF.
IF checkbox_msg IS INITIAL.
checkbox_msg = 'None'.
ENDIF.
checkbox_msg = checkbox_msg.
MESSAGE checkbox_msg TYPE 'I'.
CLEAR checkbox_msg.
"Radio buttons
WHEN 'RB_BTN'.
CASE abap_true.
WHEN rb_x.
radiobutton_msg = 'X'.
WHEN rb_y.
radiobutton_msg = 'Y'.
WHEN rb_z.
radiobutton_msg = 'Z'.
WHEN OTHERS.
radiobutton_msg = ' '.
ENDCASE.
MESSAGE radiobutton_msg TYPE 'I'.
CLEAR radiobutton_msg.
WHEN 'HOME'.
SET SCREEN 0.
LEAVE SCREEN.
WHEN OTHERS.
LEAVE PROGRAM.
ENDCASE.
IF save_ok = 'ICON1' OR save_ok = 'ICON2' OR save_ok = 'ICON3'.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = icon_name
text = icon_text
info = 'Status'
add_stdinf = 'X'
IMPORTING
result = icon
EXCEPTIONS
icon_not_found = 1
outputfield_too_short = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE `Issue.` TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
ENDMODULE.
***************** Dialog modules for 9870 ****************************
MODULE status_9870 OUTPUT.
"Control structures in case of calling the dynpro again
IF set_pfstatus IS NOT INITIAL AND pfkey = 'STATUS9870'.
SET PF-STATUS 'DEMOSTATUS'.
ELSEIF set_pfstatus IS NOT INITIAL AND pfkey = 'DEMOSTATUS'.
SET PF-STATUS 'STATUS9870'.
ELSEIF set_pf_excluding IS NOT INITIAL AND pfkey = 'STATUS9870'.
excl_list1 = local_class=>provide_fu_keys( 1 ).
SET PF-STATUS 'DEMOSTATUS' EXCLUDING excl_list1.
ELSEIF set_pf_excluding IS NOT INITIAL AND pfkey = 'DEMOSTATUS'.
excl_list2 = local_class=>provide_fu_keys( 2 ).
SET PF-STATUS 'STATUS9870' EXCLUDING excl_list2.
ELSE.
SET PF-STATUS 'STATUS9870'.
ENDIF.
IF set_titlebar IS NOT INITIAL.
IF dyn_title CS 'Demo title'.
SET TITLEBAR 'TITLE9870'.
ELSE.
SET TITLEBAR 'DEMOTITLE'.
ENDIF.
ELSEIF SET_TITLEBAR_with IS NOT INITIAL.
SET TITLEBAR 'DEMOTITLE' WITH '"' with_title '"'.
ELSE.
SET TITLEBAR 'TITLE9870'.
ENDIF.
"Prepopulating values
col1 = 5.
lin1 = 10.
col2 = 1.
lin2 = 1.
col3 = 80.
lin3 = 20.
dyn_num = sy-dynnr.
dyn_title = sy-title.
ENDMODULE.
MODULE user_command_9870 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'ENTER' OR 'GO'.
CASE abap_true.
WHEN set_screen.
MESSAGE |A SET SCREEN statement is about to get called. The static next dynpro of dynpro { sy-dynnr } is 0.| &&
` It is dynamically overwritten. Another dynpro will be displayed. A new dynpro sequence is not started.` TYPE 'I'.
SET SCREEN 9860.
WHEN call_screen.
MESSAGE `A CALL SCREEN statement is about to get called. You will switch to another dynpro. A new dynpro sequence is started.` TYPE 'I'.
CALL SCREEN 9860.
WHEN call_screen_starting.
IF col1 < 0 OR lin1 < 0.
MESSAGE `Only positive integers can be specified.` TYPE 'E'.
ELSE.
MESSAGE |The statement "CALL SCREEN ... STARTING AT { col1 } { lin1 }." is about to get called. | &&
`Note: In the dialog box that opens, click the icon in the popup footer to remain in the program. Clicking the X leaves the program.` TYPE 'I'.
CALL SCREEN 9860 STARTING AT col1 lin1.
ENDIF.
WHEN call_screen_st_end.
IF col2 < 0 OR lin2 < 0
OR col3 < 0 OR lin3 < 0.
MESSAGE `Only positive integers can be specified.`
TYPE 'E'.
ELSE.
MESSAGE |The statement "CALL SCREEN ... STARTING AT { col2 } { lin2 } ENDING AT { col3 } { lin3 }| &&
`." is about to get called. Note: In the dialog box that opens, click the icon in the popup footer ` &&
`to remain in the program. Clicking the X leaves the program.` TYPE 'I'.
CALL SCREEN 9860 STARTING AT col2 lin2 ENDING AT col3 lin3.
ENDIF.
WHEN leave_screen_next.
MESSAGE `A LEAVE SCREEN statement is about to get called. The current dynpro is exited, and the statically ` &&
`defined next dynpro is called, which is 0 in this case. Hence, the current dynpro sequence is terminated. ` &&
`Since the dynpro sequence is nested, you return to the home page and the parent dynpro sequence.` TYPE 'I'.
LEAVE SCREEN.
WHEN leave_screen_set.
MESSAGE `A LEAVE SCREEN statement is about to get called. In this case, a SET SCREEN statement before the LEAVE ` &&
`SCREEN statement overwrites the next dynpro (0 here). A new dynpro sequence is not started, instead the statement ` &&
`branches to another dynpro in the same sequence.` TYPE 'I'.
SET SCREEN 9900.
LEAVE SCREEN.
WHEN leave_to_screen.
MESSAGE `A LEAVE TO SCREEN statement is about to get called. A new dynpro sequence is not started, instead the ` &&
`statement branches to another dynpro in the same sequence. It has the same effect as the previous example.` TYPE 'I'.
LEAVE TO SCREEN 9900.
WHEN set_pfstatus.
pfkey = sy-pfkey.
MESSAGE |The current GUI status is { pfkey }. The current dynpro { sy-dynnr } will be set as the next dynpro.| &&
` It will have a different GUI status.` TYPE 'I'.
SET SCREEN 9870.
WHEN set_pf_excluding.
GET PF-STATUS pfkey.
MESSAGE |The current GUI status is { pfkey }. The current dynpro will be set as the next dynpro.| &&
` It will have a different GUI status (set at PBO) but excluding function codes (for example, the CANCEL button).` TYPE 'I'.
SET SCREEN 9870.
WHEN get_pfstatus.
GET PF-STATUS pfkey.
MESSAGE |The current GUI status is { pfkey }, which was retrieved using GET-PF-STATUS. Value of sy-pfkey: { sy-pfkey }.| TYPE 'I'.
SET SCREEN 9870.
WHEN get_pfstatsus_excl.
GET PF-STATUS pfkey EXCLUDING excl_list3.
MESSAGE |The current GUI status is { pfkey }. The exluded function codes are: {
COND #( WHEN excl_list3 IS INITIAL THEN `None are excluded. Try to run SET PF-STATUS ... EXCLUDING ... first before this one.`
ELSE concat_lines_of( table = excl_list3 sep = `, ` ) ) }| TYPE 'I'.
SET SCREEN 9870.
CLEAR excl_list3.
WHEN set_titlebar.
MESSAGE |The current title is "{ dyn_title }". The current dynpro is set as the next dynpro.| &&
`The text in the title bar should change.` TYPE 'I'.
SET SCREEN 9870.
WHEN set_titlebar_with.
MESSAGE |The current title is "{ dyn_title }". The current dynpro is set as the next dynpro.| &&
`The text in the title bar should change according to your input in the input field.` TYPE 'I'.
SET SCREEN 9870.
ENDCASE.
WHEN 'SAP'.
cl_gui_frontend_services=>execute( document = 'https://www.sap.com' ).
SET SCREEN 9870.
WHEN 'SAYHI'.
MESSAGE `Hallo ` && sy-uname && `.` TYPE 'I'.
SET SCREEN 9870.
WHEN 'HOME'.
LEAVE TO SCREEN 9850.
WHEN 'LEAVE' OR 'CANCEL'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
***************** Dialog modules for 9880 ****************************
MODULE status_9880 OUTPUT.
SET PF-STATUS 'STATUS9880'.
SET TITLEBAR 'TITLE9880'.
"Clearing variables in case the dynpro is called again
IF field_stmt IS INITIAL.
CLEAR: output_field_1, output_field_2, output_field_3,
field_a, field_b, field_c, field_d, field_e, field_f.
ENDIF.
IF field_d IS INITIAL.
CLEAR output_field_2.
ENDIF.
IF field_e IS INITIAL OR field_f IS INITIAL.
CLEAR output_field_3.
ENDIF.
"Prepopulating fields for input help
progname = sy-repid.
dynnum = sy-dynnr.
CLEAR: field_value, dynpro_values.
field_value-fieldname = 'CARR'.
APPEND field_value TO dynpro_values.
"Setting the cursor field
IF set = abap_true.
SET CURSOR FIELD 'CONN'.
CLEAR set.
ENDIF.
dyn_num = sy-dynnr.
ENDMODULE.
MODULE user_command_9880 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'ENTER' OR 'GO'.
CASE abap_true.
WHEN loop_modify.
MESSAGE `Another dynpro will be set as the next dynpro. This dynpro includes a LOOP AT SCREEN ` &&
` and MODIFY SCREEN statements in the PBO dialog module. Some screen elements have their static ` &&
`attributes changed. For example, they are made invisible or inactive, or the length is changed.` TYPE 'I'.
SET SCREEN 9860.
LEAVE SCREEN.
WHEN field_stmt.
MESSAGE `The current dynpro will be set as the next dynpro. Depending on which checkboxes you ` &&
`have selected, text is displayed in the fields below showing the effect of FIELD statements.` TYPE 'I'.
SET SCREEN 9880.
WHEN mod_at_exit.
SET SCREEN 9890.
ENDCASE.
WHEN 'SELECTED'.
CLEAR conn.
SET SCREEN 9880.
WHEN 'GET'.
GET CURSOR FIELD fld OFFSET off VALUE val LENGTH len.
MESSAGE |Current position of cursor: Field: "{ fld }", value: "{ val }", offset: "{ off }", length "{ len }"| TYPE 'I'.
SET SCREEN 9880.
WHEN 'SET'.
set = abap_true.
MESSAGE `Clicking the pushbutton triggers a SET CURSOR statement to be called at PBO. This sets the cursor on ` &&
`a specific input field (the one in the lower left corner).` TYPE 'I'.
SET SCREEN 9880.
WHEN 'HOME'.
LEAVE TO SCREEN 9850.
WHEN 'LEAVE' OR 'CANCEL'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
***************** Dialog modules for 9890 ****************************
"For demonstration purposes, the dialog module implementations are
"done in methods of a local class.
MODULE status_9890 OUTPUT.
local_class=>pbo9890( ).
ENDMODULE.
MODULE user_command_9890 INPUT.
local_class=>pai9890( ).
ENDMODULE.
***************** Dialog modules for 9900 ****************************
MODULE status_9900 OUTPUT.
SET PF-STATUS 'STATUS9900'.
SET TITLEBAR 'TITLE9900'.
"For vertically scrolling in the table control
"To do this, the LINES component of the scxtab_control structure is set
"to the correct line number. Each time the scroll bar is scrolled, the
"PAI event is triggered with an empty function code, and the top_line
"component of the cxtab_control structure is automatically set to the
"new top line before PBO.
flights-lines = lines( itab_flights ).
"Setting a tab to be active by default in case of calling the
"dynpro again after leaving it.
IF tabstr-activetab IS INITIAL
OR number IS INITIAL.
number = '9920'.
tabstr-activetab = 'TAB2'.
ENDIF.
local_class=>cc_alv_display( 'ALVCONT' ).
dyn_num = sy-dynnr.
ENDMODULE.
MODULE user_command_9900 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'TAB1'.
number = '9910'.
tabstr-activetab = save_ok.
WHEN 'TAB2'.
number = '9920'.
tabstr-activetab = save_ok.
WHEN 'HOME'.
"REFRESH statement: You can check out the effect, for example, by setting
"the vertical scroll bar somewhere. If you then go back and call the dynpro
"again, the control is refreshed (the scroll bar is again at the top).
REFRESH CONTROL 'FLIGHTS' FROM SCREEN sy-dynnr.
CLEAR: number, tabstr-activetab.
SET SCREEN 0.
LEAVE SCREEN.
WHEN 'CANCEL' OR 'LEAVE'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
***************** Further dialog modules to support the example ****************************
MODULE module_1 INPUT.
output_field_1 = 'Available in module_1:' && ` ` &&
COND #( WHEN field_a = abap_true THEN 'A' ELSE '' ) &&
COND #( WHEN field_b = abap_true THEN 'B' ELSE '' ) &&
COND #( WHEN field_c = abap_true THEN 'C' ELSE '' ) &&
' /'.
ENDMODULE.
MODULE module_2 INPUT.
output_field_1 = output_field_1 &&
' Available in module_2:' && ` ` &&
COND #( WHEN field_a = abap_true THEN 'A' ELSE '' ) &&
COND #( WHEN field_b = abap_true THEN 'B' ELSE '' ) &&
COND #( WHEN field_c = abap_true THEN 'C' ELSE '' ) &&
' /'.
ENDMODULE.
MODULE module_3 INPUT.
output_field_1 = output_field_1 &&
' Available in module_3:' && ` ` &&
COND #( WHEN field_a = abap_true THEN 'A' ELSE '' ) &&
COND #( WHEN field_b = abap_true THEN 'B' ELSE '' ) &&
COND #( WHEN field_c = abap_true THEN 'C' ELSE '' ).
CLEAR: field_a, field_b, field_c.
ENDMODULE.
MODULE module_4 INPUT.
output_field_2 = 'module_4 was called because field_d was selected.'.
ENDMODULE.
MODULE module_5 INPUT.
output_field_3 = 'module_5 was called because field_e and field_f were selected.'.
ENDMODULE.
MODULE module_f1 INPUT.
"In this example, a demo object from the ABAP Keyword
"Documentation examples is used.
CALL FUNCTION 'HELP_OBJECT_SHOW'
EXPORTING
dokclass = 'TX'
doklangu = sy-langu
dokname = 'DEMO_FOR_F1_HELP'
TABLES
links = links.
ENDMODULE.
MODULE module_f4 INPUT.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = progname
dynumb = dynnum
translate_to_upper = 'X'
TABLES
dynpfields = dynpro_values.
field_value = dynpro_values[ 1 ].
SELECT carrid, connid
FROM zdemo_abap_flsch
WHERE carrid = @( CONV #( field_value-fieldvalue ) )
INTO CORRESPONDING FIELDS OF TABLE @values_tab.
"Note: To save extra artifacts, this example goes without a dedicated DDIC
"structure with which input help can be created comfortably. Hence, creating
"a table manually for the field_tab parameter of the function module below.
field_tab = VALUE #(
( tabname = 'ZDEMO_ABAP_FLSCH' fieldname = 'CARRID' langu = 'E' position = '1'
offset = '0' leng = '3' intlen = '6' outputlen = '3' datatype = 'CHAR' inttype = 'C' )
( tabname = 'ZDEMO_ABAP_FLSCH' fieldname = 'CONNID' langu = 'E' position = '2'
offset = '6' leng = '4' intlen = '8' outputlen = '4' datatype = 'NUMC' inttype = 'N' ) ).
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CONNID'
dynpprog = progname
dynpnr = dynnum
dynprofield = 'CONN'
value_org = 'S'
window_title = 'Selection'
TABLES
value_tab = values_tab
field_tab = field_tab.
ENDMODULE.
MODULE module_dropdown INPUT.
SELECT DISTINCT carrid
FROM zdemo_abap_flsch
INTO CORRESPONDING FIELDS OF TABLE @carrid_list.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CARRID'
value_org = 'S'
TABLES
value_tab = carrid_list
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
carr = 'LH'.
ENDIF.
ENDMODULE.
MODULE module_fill_table OUTPUT.
TRY.
zdemo_abap_flsch = itab_flights[ flights-current_line ].
CATCH cx_sy_itab_line_not_found.
RETURN.
ENDTRY.
ENDMODULE.
MODULE module_read_table INPUT.
lines = sy-loopc.
MODIFY itab_flights FROM zdemo_abap_flsch INDEX flights-current_line.
ENDMODULE.
MODULE cancel INPUT.
local_class=>cancel( ).
ENDMODULE.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
FUNCTION-POOL ZDEMO_ABAP_FUGR. "MESSAGE-ID ..
* INCLUDE LZDEMO_ABAP_FUGRD... " Local class definition

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<PROGDIR>
<NAME>LZDEMO_ABAP_FUGRTOP</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>I</SUBC>
<APPL>S</APPL>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,15 @@
*******************************************************************
* System-defined Include-files. *
*******************************************************************
INCLUDE LZDEMO_ABAP_FUGRTOP. " Global Declarations
INCLUDE LZDEMO_ABAP_FUGRUXX. " Function Modules
*******************************************************************
* User-defined Include-files (if necessary). *
*******************************************************************
* INCLUDE LZDEMO_ABAP_FUGRF... " Subroutines
* INCLUDE LZDEMO_ABAP_FUGRO... " PBO-Modules
* INCLUDE LZDEMO_ABAP_FUGRI... " PAI-Modules
* INCLUDE LZDEMO_ABAP_FUGRE... " Events
* INCLUDE LZDEMO_ABAP_FUGRP... " Local class implement.
* INCLUDE LZDEMO_ABAP_FUGRT99. " ABAP Unit tests

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<PROGDIR>
<NAME>SAPLZDEMO_ABAP_FUGR</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>F</SUBC>
<APPL>S</APPL>
<RLOAD>E</RLOAD>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_FUGR" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<AREAT>Demo function group</AREAT>
<INCLUDES>
<SOBJ_NAME>LZDEMO_ABAP_FUGRTOP</SOBJ_NAME>
<SOBJ_NAME>SAPLZDEMO_ABAP_FUGR</SOBJ_NAME>
</INCLUDES>
<FUNCTIONS>
<item>
<FUNCNAME>ZDEMO_ABAP_DELETE_FU</FUNCNAME>
<UPDATE_TASK>1</UPDATE_TASK>
<SHORT_TEXT>Demo update function module</SHORT_TEXT>
</item>
<item>
<FUNCNAME>ZDEMO_ABAP_LOG_FU</FUNCNAME>
<UPDATE_TASK>1</UPDATE_TASK>
<SHORT_TEXT>Demo update function module</SHORT_TEXT>
<IMPORT>
<RSIMP>
<PARAMETER>LOG</PARAMETER>
<TYP>ZCL_DEMO_ABAP_SAP_LUW_HELPER=&gt;LOG_TYPE</TYP>
</RSIMP>
<RSIMP>
<PARAMETER>CAUSE_ERROR</PARAMETER>
<DEFAULT>ABAP_FALSE</DEFAULT>
<OPTIONAL>X</OPTIONAL>
<TYP>ABAP_BOOL</TYP>
</RSIMP>
</IMPORT>
<DOCUMENTATION>
<RSFDO>
<PARAMETER>LOG</PARAMETER>
<KIND>P</KIND>
</RSFDO>
<RSFDO>
<PARAMETER>CAUSE_ERROR</PARAMETER>
<KIND>P</KIND>
</RSFDO>
</DOCUMENTATION>
</item>
<item>
<FUNCNAME>ZDEMO_ABAP_MODIFY_FU</FUNCNAME>
<UPDATE_TASK>1</UPDATE_TASK>
<SHORT_TEXT>Demo update function module</SHORT_TEXT>
<IMPORT>
<RSIMP>
<PARAMETER>VALUES</PARAMETER>
<TYP>ZDEMO_ABAP_LUW_T</TYP>
</RSIMP>
</IMPORT>
<DOCUMENTATION>
<RSFDO>
<PARAMETER>VALUES</PARAMETER>
<KIND>P</KIND>
</RSFDO>
</DOCUMENTATION>
</item>
</FUNCTIONS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,34 @@
FUNCTION zdemo_abap_delete_fu.
*"----------------------------------------------------------------------
*"*"Update Function Module:
*"
*"*"Local Interface:
*"----------------------------------------------------------------------
DELETE FROM zdemo_abap_luw_t.
zcl_demo_abap_sap_luw_helper=>create_log_entries(
VALUE #( ( id = 70
context = 'Function module'
name = 'zdemo_abap_delete_fu'
details = `Function module called`
timestamp = utclong_current( ) )
( id = 71
context = 'Function module'
name = 'zdemo_abap_delete_fu'
details = zcl_demo_abap_sap_luw_helper=>get_work_process_info( )
timestamp = utclong_current( ) )
( id = 72
context = 'Function module'
name = 'zdemo_abap_delete_fu'
details = `SAP LUW Key: ` && cl_system_transaction_state=>get_sap_luw_key( )
timestamp = utclong_current( ) )
( id = 73
context = 'Function module'
name = 'zdemo_abap_delete_fu'
details = zcl_demo_abap_sap_luw_helper=>checking_transaction_state( )
timestamp = utclong_current( ) ) ) ).
ENDFUNCTION.

View File

@@ -0,0 +1,41 @@
FUNCTION ZDEMO_ABAP_LOG_FU.
*"----------------------------------------------------------------------
*"*"Update Function Module:
*"
*"*"Local Interface:
*" IMPORTING
*" VALUE(LOG) TYPE ZCL_DEMO_ABAP_SAP_LUW_HELPER=>LOG_TYPE
*" VALUE(CAUSE_ERROR) TYPE ABAP_BOOL DEFAULT ABAP_FALSE
*"----------------------------------------------------------------------
MODIFY zdemo_abap_logt FROM TABLE @log.
zcl_demo_abap_sap_luw_helper=>create_log_entries(
VALUE #( ( id = 90
context = `Function module`
name = `zdemo_abap_log_fu`
details = `Function module called`
timestamp = utclong_current( ) )
( id = 91
context = `Function module`
name = `zdemo_abap_log_fu`
details = zcl_demo_abap_sap_luw_helper=>get_work_process_info( )
timestamp = utclong_current( ) )
( id = 92
context = `Function module`
name = `zdemo_abap_log_fu`
details = `SAP LUW Key: ` && cl_system_transaction_state=>get_sap_luw_key( )
timestamp = utclong_current( ) )
( id = 93
context = `Function module`
name = `zdemo_abap_log_fu`
details = zcl_demo_abap_sap_luw_helper=>checking_transaction_state( )
timestamp = utclong_current( ) ) ) ).
IF cause_error = abap_true.
DATA(error_not_caught) = 1 / 0.
ENDIF.
ENDFUNCTION.

View File

@@ -0,0 +1,38 @@
FUNCTION ZDEMO_ABAP_MODIFY_FU.
*"----------------------------------------------------------------------
*"*"Update Function Module:
*"
*"*"Local Interface:
*" IMPORTING
*" VALUE(VALUES) TYPE ZDEMO_ABAP_LUW_T
*"----------------------------------------------------------------------
values-time_stamp = utclong_current( ).
MODIFY zdemo_abap_luw_t FROM @values.
zcl_demo_abap_sap_luw_helper=>create_log_entries(
VALUE #( ( id = 80
context = 'Function module'
name = 'zdemo_abap_modify_fu'
details = `Function module called`
timestamp = utclong_current( ) )
( id = 81
context = 'Function module'
name = 'zdemo_abap_modify_fu'
details = zcl_demo_abap_sap_luw_helper=>get_work_process_info( )
timestamp = utclong_current( ) )
( id = 82
context = 'Function module'
name = 'zdemo_abap_modify_fu'
details = `SAP LUW Key: ` && cl_system_transaction_state=>get_sap_luw_key( )
timestamp = utclong_current( ) )
( id = 83
context = 'Function module'
name = 'zdemo_abap_modify_fu'
details = zcl_demo_abap_sap_luw_helper=>checking_transaction_state( )
timestamp = utclong_current( ) ) ) ).
ENDFUNCTION.

View File

@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_TABL" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DD02V>
<TABNAME>ZDEMO_ABAP_LOGT</TABNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<TABCLASS>TRANSP</TABCLASS>
<CLIDEP>X</CLIDEP>
<DDTEXT>Log table</DDTEXT>
<MASTERLANG>E</MASTERLANG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_LOGT</TABNAME>
<AS4LOCAL>A</AS4LOCAL>
<TABKAT>0</TABKAT>
<TABART>APPL0</TABART>
<BUFALLOW>N</BUFALLOW>
</DD09L>
<DD03P_TABLE>
<DD03P>
<FIELDNAME>CLIENT</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CLNT</DATATYPE>
<LENG>000003</LENG>
<MASK> CLNT</MASK>
</DD03P>
<DD03P>
<FIELDNAME>ID</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CONTEXT</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000030</INTLEN>
<DATATYPE>CHAR</DATATYPE>
<LENG>000015</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>NAME</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000040</INTLEN>
<DATATYPE>CHAR</DATATYPE>
<LENG>000020</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>DETAILS</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>g</INTTYPE>
<INTLEN>000008</INTLEN>
<DATATYPE>STRG</DATATYPE>
<MASK> STRG</MASK>
</DD03P>
<DD03P>
<FIELDNAME>TIMESTAMP</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>p</INTTYPE>
<INTLEN>000008</INTLEN>
<DATATYPE>UTCL</DATATYPE>
<LENG>000027</LENG>
<MASK> UTCL</MASK>
</DD03P>
</DD03P_TABLE>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_TABL" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DD02V>
<TABNAME>ZDEMO_ABAP_LUW_T</TABNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<TABCLASS>TRANSP</TABCLASS>
<CLIDEP>X</CLIDEP>
<DDTEXT>Demo database table</DDTEXT>
<MASTERLANG>E</MASTERLANG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_LUW_T</TABNAME>
<AS4LOCAL>A</AS4LOCAL>
<TABKAT>0</TABKAT>
<TABART>APPL0</TABART>
<BUFALLOW>N</BUFALLOW>
</DD09L>
<DD03P_TABLE>
<DD03P>
<FIELDNAME>CLIENT</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CLNT</DATATYPE>
<LENG>000003</LENG>
<MASK> CLNT</MASK>
</DD03P>
<DD03P>
<FIELDNAME>KEY_FIELD</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CH</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000020</INTLEN>
<DATATYPE>CHAR</DATATYPE>
<LENG>000010</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>NUM</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>TIME_STAMP</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>p</INTTYPE>
<INTLEN>000008</INTLEN>
<DATATYPE>UTCL</DATATYPE>
<LENG>000027</LENG>
<MASK> UTCL</MASK>
</DD03P>
</DD03P_TABLE>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,513 @@
*&---------------------------------------------------------------------*
*& ABAP cheat sheet: SAP LUW
*&
*&-------------------------- PURPOSE ----------------------------------*
*& - Example to demonstrate ABAP syntax in the context of the SAP LUW.
*& - Topics covered: Using update function modules and subroutines as
*& bundling techniques, synchronous/asynchronous/local updates
*&
*&----------------------- GETTING STARTED -----------------------------*
*& - Open the program with the ABAP development tools for Eclipse (ADT).
*& - Choose F8 to run the program.
*& - Select the radio buttons and choose 'Go' to progress with the program.
*&
*&----------------------------- NOTE -----------------------------------*
*&* The code presented in this class is intended only to support the ABAP
*&* cheat sheets. It is not intended for direct use in a production system
*&* environment. The code examples in the ABAP cheat sheets are primarily
*&* intended to provide a better explanation and visualization of the
*&* syntax and semantics of ABAP statements, not to solve concrete
*&* programming tasks. For production application programs, you should
*&* always work out your own solution for each individual case. There is
*&* no guarantee for the correctness or completeness of the code.
*&* Furthermore, there is no legal responsibility or liability for any
*&* errors or their consequences that may occur when using the the example
*&* code.
*&---------------------------------------------------------------------*
REPORT zdemo_abap_sap_luw.
DATA: tab_struc TYPE zdemo_abap_luw_t,
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm,
del_insert TYPE abap_bool,
perform TYPE abap_bool,
commit TYPE abap_bool,
commit_wait TYPE abap_bool,
local_update TYPE abap_bool,
err TYPE abap_bool,
rollback TYPE abap_bool,
terminate TYPE abap_bool,
dynnr TYPE sy-dynnr,
counter TYPE i,
log_itab TYPE zcl_demo_abap_sap_luw_helper=>log_type.
CLASS lcl DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF request4log,
log TYPE zdemo_abap_logt,
called TYPE abap_bool,
wp_info TYPE abap_bool,
luw_key TYPE abap_bool,
tx_state TYPE abap_bool,
END OF request4log.
CLASS-METHODS: prep,
create_log_entries IMPORTING req TYPE request4log.
ENDCLASS.
CLASS lcl IMPLEMENTATION.
METHOD prep.
DELETE FROM zdemo_abap_luw_t.
INSERT zdemo_abap_luw_t FROM TABLE @( VALUE #(
( key_field = 1
ch = 'DEMO DATA'
num = 11
time_stamp = utclong_current( ) )
( key_field = 2
ch = 'THAT WAS'
num = 22
time_stamp = utclong_current( ) )
( key_field = 3
ch = 'CREATED'
num = 33
time_stamp = utclong_current( ) )
( key_field = 4
ch = 'IN ADVANCE'
num = 44
time_stamp = utclong_current( ) ) ) ).
DELETE FROM zdemo_abap_logt.
ENDMETHOD.
METHOD create_log_entries.
IF req-called = abap_true.
counter += 1.
INSERT VALUE #( id = counter
context = req-log-context
name = req-log-name
details = `Called!`
timestamp = utclong_current( )
) INTO TABLE log_itab.
ENDIF.
IF req-luw_key = abap_true.
counter += 1.
INSERT VALUE #( id = counter
context = req-log-context
name = req-log-name
details = `SAP LUW key: ` &&
cl_system_transaction_state=>get_sap_luw_key( )
timestamp = utclong_current( )
) INTO TABLE log_itab.
ENDIF.
IF req-wp_info = abap_true.
counter += 1.
INSERT VALUE #( id = counter
context = req-log-context
name = req-log-name
details =
zcl_demo_abap_sap_luw_helper=>get_work_process_info( )
timestamp = utclong_current( )
) INTO TABLE log_itab.
ENDIF.
IF req-tx_state = abap_true.
counter += 1.
INSERT VALUE #(
id = counter
context = req-log-context
name = req-log-name
details =
zcl_demo_abap_sap_luw_helper=>checking_transaction_state( )
timestamp = utclong_current( )
) INTO TABLE log_itab.
ENDIF.
ENDMETHOD.
ENDCLASS.
FORM delete.
zcl_demo_abap_sap_luw_helper=>subr_delete( ).
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'Subroutine'
name = 'delete' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
ENDFORM.
FORM insert.
DATA values TYPE zdemo_abap_luw_t.
IMPORT values = values FROM MEMORY ID 'DEMO_INSERT'.
IF sy-subrc = 0.
values-time_stamp = utclong_current( ).
zcl_demo_abap_sap_luw_helper=>subr_insert( values ).
ENDIF.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'Subroutine'
name = 'insert' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
ENDFORM.
FORM update_log.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'Subroutine'
name = 'update_log' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
zcl_demo_abap_sap_luw_helper=>subr_update_log( log_itab ).
ENDFORM.
FORM call_on_rollback.
"No implementation here. Only to demonstrate that the
"subroutine is called in the event of triggering a
"rollback.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'Subroutine'
name = 'call_on_rollback' )
called = abap_true
luw_key = abap_true
tx_state = abap_true ) ).
ENDFORM.
END-OF-SELECTION.
lcl=>prep( ).
counter += 1.
INSERT VALUE #(
id = counter
context = '-'
name = '-'
details = |Program { sy-repid } has been started.| &&
`The first dynpro is about to be called.`
timestamp = utclong_current( )
) INTO TABLE log_itab.
counter += 1.
INSERT VALUE #( id = counter
context = '-'
name = '-'
details = `SAP LUW Key: ` &&
cl_system_transaction_state=>get_sap_luw_key( )
timestamp = utclong_current( )
) INTO TABLE log_itab.
CALL SCREEN 9750.
**********************************************************************
***************** Dialog modules for 9750 ****************************
MODULE status_9750 OUTPUT.
SET PF-STATUS 'STATUS9750'.
SET TITLEBAR 'TITLE9750'.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'PBO'
name = 'status_9750' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
zcl_demo_abap_sap_luw_helper=>cc_alv_display( 'DBENTRIES' ).
dynnr = sy-dynnr.
ENDMODULE.
MODULE user_command_9750 INPUT.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'PAI'
name = 'user_command_9750' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'GO' OR 'ENTER'.
IF del_insert = abap_true.
CALL FUNCTION 'ZDEMO_ABAP_DELETE_FU' IN UPDATE TASK.
MESSAGE `A function module has been registered ` &&
`that clears the database table.` TYPE 'I'.
ELSEIF local_update = abap_true.
SET UPDATE TASK LOCAL.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'PAI'
name = 'user_command_9750' )
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
CALL FUNCTION 'ZDEMO_ABAP_DELETE_FU' IN UPDATE TASK.
MESSAGE `Local update has been activated. A function ` &&
`module has been registered that clears the database table.` &&
` No matter if you choose COMMIT WORK or COMMIT WORK AND ` &&
`WAIT in the next step, it will be a synchronous update.` TYPE 'I'.
ELSEIF perform = abap_true.
PERFORM delete ON COMMIT.
PERFORM call_on_rollback ON ROLLBACK.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'PAI'
name = 'user_command_9750' )
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
MESSAGE `Subroutines have been registered for commit ` &&
`and rollback.` TYPE 'I'.
ENDIF.
WHEN OTHERS.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
***************** Dialog modules for 9760 ****************************
MODULE status_9760 OUTPUT.
SET PF-STATUS 'STATUS9760'.
SET TITLEBAR 'TITLE9760'.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'PBO'
name = 'status_9760' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
dynnr = sy-dynnr.
ENDMODULE.
MODULE user_command_9760 INPUT.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'PAI'
name = 'user_command_9760' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'GO' OR 'ENTER'.
IF perform = abap_true.
"Registered subroutines cannot have any parameter interface.
"Therefore, data can only be passed through external interfaces,
"for example, the ABAP memory.
EXPORT values = tab_struc TO MEMORY ID 'DEMO_INSERT'.
PERFORM insert ON COMMIT.
MESSAGE `A subroutine that inserts the entries in the ` &&
`database table has been registered. ` &&
`When you select a commit option in the next step, ` &&
`COMMIT WORK and COMMIT WORK AND WAIT have ` &&
`the same effect. The subroutines are executed in ` &&
`the current work process in this case.` TYPE 'I'.
ELSE.
CALL FUNCTION 'ZDEMO_ABAP_MODIFY_FU' IN UPDATE TASK
EXPORTING
values = tab_struc.
MESSAGE `An update function module that inserts the ` &&
`entries in the database table has ` &&
`been registered.` TYPE 'I'.
ENDIF.
WHEN OTHERS.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
***************** Dialog modules for 9770 ****************************
MODULE status_9770 OUTPUT.
SET PF-STATUS 'STATUS9770'.
SET TITLEBAR 'TITLE9770'.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'PBO'
name = 'status_9770' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
dynnr = sy-dynnr.
IF perform = 'X'.
LOOP AT SCREEN INTO DATA(scr).
IF scr-name = 'EXCURSION_WP'
OR scr-name = 'WAIT'
OR scr-name = 'FAIL_LUW'
OR scr-name = 'ERR'
OR scr-name = 'TERMINATE'
OR scr-name = 'ERROR_A'.
scr-invisible = '1'.
MODIFY SCREEN FROM scr.
ENDIF.
ENDLOOP.
ENDIF.
ENDMODULE.
MODULE user_command_9770 INPUT.
lcl=>create_log_entries(
VALUE #( log = VALUE #( context = 'PAI'
name = 'user_command_9770' )
called = abap_true
luw_key = abap_true
tx_state = abap_true
wp_info = abap_true ) ).
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'GO' OR 'ENTER' OR 'OK'.
CASE 'X'.
WHEN commit.
IF perform = abap_false.
CALL FUNCTION 'ZDEMO_ABAP_LOG_FU' IN UPDATE TASK
EXPORTING
log = log_itab.
MESSAGE `An update function module that inserts ` &&
`entries for the log has been registered. ` &&
`COMMIT WORK is about to be executed.` TYPE 'I'.
ELSE.
PERFORM update_log ON COMMIT.
MESSAGE `A subroutine that inserts entries for the ` &&
`log has been registered ` &&
`COMMIT WORK is about to be executed.` TYPE 'I'.
ENDIF.
COMMIT WORK.
SELECT COUNT(*) FROM zdemo_abap_luw_t INTO @DATA(entries).
MESSAGE `COMMIT WORK has been executed. Current ` &&
`number of database table entries: ` &&
entries &&
`. If it is 4 and not 1, the update will be done ` &&
`asynchronously.` TYPE 'I'.
WHEN commit_wait.
IF perform = abap_false.
CALL FUNCTION 'ZDEMO_ABAP_LOG_FU' IN UPDATE TASK
EXPORTING
log = log_itab.
MESSAGE `An update function module that inserts ` &&
`entries for the log has been registered. ` &&
`COMMIT WORK AND WAIT is about to be executed.` TYPE 'I'.
ELSE.
PERFORM update_log ON COMMIT.
MESSAGE `A subroutine that inserts entries for the ` &&
`log has been registered ` &&
`COMMIT WORK AND WAIT is about to be executed.` TYPE 'I'.
ENDIF.
COMMIT WORK AND WAIT.
SELECT COUNT(*) FROM zdemo_abap_luw_t INTO @entries.
MESSAGE `COMMIT WORK AND WAIT has been executed. Current ` &&
`number of database table entries: ` &&
entries &&
`. If it is 1, the update has been done synchronously.` TYPE 'I'.
WHEN rollback.
ROLLBACK WORK.
MESSAGE `ROLLBACK WORK has been executed. A rollback has ` &&
`been triggered. The original database table content ` &&
`should be displayed.`
TYPE 'I'.
MESSAGE `Note: As an exception, and only for this demo ` &&
`example, the sample implementation includes a ` &&
`database update to the log table after the ` &&
`table after the rollback, just to show the progress of the ` &&
`execution up to that point.` TYPE 'I' DISPLAY LIKE 'E'.
"Update log table
zcl_demo_abap_sap_luw_helper=>create_log_entries( log_itab ).
"Log information for triggering a rollback
zcl_demo_abap_sap_luw_helper=>create_log_entries(
VALUE #( ( id = 99
context = '-'
name = '-'
details = `Rollback triggered`
timestamp = utclong_current( ) ) ) ).
WHEN err.
CALL FUNCTION 'ZDEMO_ABAP_LOG_FU' IN UPDATE TASK
EXPORTING
log = log_itab
cause_error = abap_true.
IF local_update = abap_true.
MESSAGE `A function module has been registered that ` &&
`causes an error (zero division). COMMIT WORK AND WAIT ` &&
`is about to be executed. You are directly informed ` &&
`about the error and the program is terminated. All ` &&
`changes are implicitly rolled back. You can check ` &&
`transaction ST22 for the error caused.` TYPE 'I'.
ELSE.
MESSAGE `Function module was registered that ` &&
`causes an error (zero division). COMMIT WORK AND WAIT` &&
` will be excetued. All changes are implicitly rolled back.` &&
` When you start over or leave the example in the next dynpro, ` &&
`you should be informed about the issue in the Business Workplace. ` &&
`Also check ST22.` TYPE 'I'.
ENDIF.
COMMIT WORK AND WAIT.
WHEN terminate.
MESSAGE `This is an error message of type A. ` &&
`It termiantes the program. All changes are ` &&
`implicitly rolled back. ` &&
`You may want to check the database table entries of ` &&
`the example that remain unchanged.` TYPE 'A'.
ENDCASE.
WHEN OTHERS.
LEAVE PROGRAM.
ENDCASE.
SUBMIT ('ZDEMO_ABAP_SAP_LUW_DISPL').
ENDMODULE.

View File

@@ -0,0 +1,864 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<PROGDIR>
<NAME>ZDEMO_ABAP_SAP_LUW</NAME>
<DBAPL>S</DBAPL>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<DYNPROS>
<item>
<HEADER>
<PROGRAM>ZDEMO_ABAP_SAP_LUW</PROGRAM>
<SCREEN>9750</SCREEN>
<LANGUAGE>E</LANGUAGE>
<DESCRIPT>Delete database table entries</DESCRIPT>
<TYPE>N</TYPE>
<NEXTSCREEN>9760</NEXTSCREEN>
<LINES>027</LINES>
<COLUMNS>121</COLUMNS>
</HEADER>
<CONTAINERS>
<RPY_DYCATT>
<TYPE>SCREEN</TYPE>
<NAME>SCREEN</NAME>
</RPY_DYCATT>
<RPY_DYCATT>
<TYPE>RADIOGROUP</TYPE>
<NAME>%A_DEL_INSERT</NAME>
<ELEMENT_OF>SCREEN</ELEMENT_OF>
<LINE>006</LINE>
<COLUMN>004</COLUMN>
<LENGTH>076</LENGTH>
<HEIGHT>003</HEIGHT>
</RPY_DYCATT>
<RPY_DYCATT>
<TYPE>CUST_CTRL</TYPE>
<NAME>DBENTRIES</NAME>
<ELEMENT_OF>SCREEN</ELEMENT_OF>
<LINE>012</LINE>
<COLUMN>005</COLUMN>
<LENGTH>068</LENGTH>
<HEIGHT>007</HEIGHT>
</RPY_DYCATT>
</CONTAINERS>
<FIELDS>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX1</NAME>
<TEXT>The_SAP_LUW_is_started._In_this_example,_all_the_entries_in_a_database_table_(see_below)_are_to_be_deleted.</TEXT>
<LINE>002</LINE>
<COLUMN>004</COLUMN>
<LENGTH>107</LENGTH>
<VISLENGTH>107</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX2</NAME>
<TEXT>The_ABAP_SQL_statement_is_implemented_in_an_update_function_module_and_a_subroutine._</TEXT>
<LINE>003</LINE>
<COLUMN>004</COLUMN>
<LENGTH>085</LENGTH>
<VISLENGTH>085</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX3</NAME>
<TEXT>Choose_one_of_the_following_options:</TEXT>
<LINE>004</LINE>
<COLUMN>004</COLUMN>
<LENGTH>036</LENGTH>
<VISLENGTH>036</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX4</NAME>
<TEXT>Current_database_table_entries:</TEXT>
<LINE>010</LINE>
<COLUMN>004</COLUMN>
<LENGTH>031</LENGTH>
<VISLENGTH>031</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX5</NAME>
<TEXT>Dynpro_number:</TEXT>
<LINE>021</LINE>
<COLUMN>005</COLUMN>
<LENGTH>014</LENGTH>
<VISLENGTH>014</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEMPLATE</TYPE>
<NAME>DYNNR</NAME>
<TEXT>___________</TEXT>
<LINE>021</LINE>
<COLUMN>021</COLUMN>
<LENGTH>011</LENGTH>
<VISLENGTH>011</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<OUTPUT_FLD>X</OUTPUT_FLD>
<OUTPUTONLY>X</OUTPUTONLY>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>OKCODE</TYPE>
<NAME>OK_CODE</NAME>
<TEXT>____________________</TEXT>
<LENGTH>020</LENGTH>
<VISLENGTH>020</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>RADIOGROUP</CONT_TYPE>
<CONT_NAME>%A_DEL_INSERT</CONT_NAME>
<TYPE>RADIO</TYPE>
<NAME>DEL_INSERT</NAME>
<TEXT>Use_update_task_(CALL_FUNCTION_..._IN_UPDATE_TASK_statement)</TEXT>
<LINE>006</LINE>
<COLUMN>004</COLUMN>
<LENGTH>062</LENGTH>
<VISLENGTH>062</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>RADIOGROUP</CONT_TYPE>
<CONT_NAME>%A_DEL_INSERT</CONT_NAME>
<TYPE>RADIO</TYPE>
<NAME>LOCAL_UPDATE</NAME>
<TEXT>Use_update_task_and_perform_local_update_(SET_UPDATE_TASK_LOCAL_statement)</TEXT>
<LINE>007</LINE>
<COLUMN>004</COLUMN>
<LENGTH>076</LENGTH>
<VISLENGTH>076</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>RADIOGROUP</CONT_TYPE>
<CONT_NAME>%A_DEL_INSERT</CONT_NAME>
<TYPE>RADIO</TYPE>
<NAME>PERFORM</NAME>
<TEXT>Use_subroutines_(PERFORM_statement)</TEXT>
<LINE>008</LINE>
<COLUMN>004</COLUMN>
<LENGTH>037</LENGTH>
<VISLENGTH>037</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
</FIELDS>
<FLOW_LOGIC>
<RPY_DYFLOW>
<LINE>PROCESS BEFORE OUTPUT.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW>
<LINE> MODULE STATUS_9750.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW/>
<RPY_DYFLOW>
<LINE>PROCESS AFTER INPUT.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW>
<LINE> MODULE USER_COMMAND_9750.</LINE>
</RPY_DYFLOW>
</FLOW_LOGIC>
</item>
<item>
<HEADER>
<PROGRAM>ZDEMO_ABAP_SAP_LUW</PROGRAM>
<SCREEN>9760</SCREEN>
<LANGUAGE>E</LANGUAGE>
<DESCRIPT>Create database table entry</DESCRIPT>
<TYPE>N</TYPE>
<NEXTSCREEN>9770</NEXTSCREEN>
<LINES>027</LINES>
<COLUMNS>121</COLUMNS>
</HEADER>
<CONTAINERS>
<RPY_DYCATT>
<TYPE>SCREEN</TYPE>
<NAME>SCREEN</NAME>
</RPY_DYCATT>
</CONTAINERS>
<FIELDS>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX7</NAME>
<TEXT>To_create_a_database_table_entry,_make_entries_in_the_following_input_fields:</TEXT>
<LINE>002</LINE>
<COLUMN>003</COLUMN>
<LENGTH>077</LENGTH>
<VISLENGTH>077</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX8</NAME>
<TEXT>KEY_FIELD</TEXT>
<LINE>004</LINE>
<COLUMN>003</COLUMN>
<LENGTH>009</LENGTH>
<VISLENGTH>009</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
<LABELLEFT>X</LABELLEFT>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEMPLATE</TYPE>
<NAME>TAB_STRUC-KEY_FIELD</NAME>
<TEXT>_______.__</TEXT>
<LINE>004</LINE>
<COLUMN>015</COLUMN>
<LENGTH>010</LENGTH>
<VISLENGTH>010</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>INT4</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX11</NAME>
<TEXT>Type_i</TEXT>
<LINE>004</LINE>
<COLUMN>028</COLUMN>
<LENGTH>006</LENGTH>
<VISLENGTH>006</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX9</NAME>
<TEXT>CH</TEXT>
<LINE>006</LINE>
<COLUMN>003</COLUMN>
<LENGTH>002</LENGTH>
<VISLENGTH>002</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
<LABELLEFT>X</LABELLEFT>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEMPLATE</TYPE>
<NAME>TAB_STRUC-CH</NAME>
<TEXT>__________</TEXT>
<LINE>006</LINE>
<COLUMN>015</COLUMN>
<LENGTH>010</LENGTH>
<VISLENGTH>010</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX12</NAME>
<TEXT>Type_c_length_10</TEXT>
<LINE>006</LINE>
<COLUMN>028</COLUMN>
<LENGTH>016</LENGTH>
<VISLENGTH>016</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX10</NAME>
<TEXT>NUM</TEXT>
<LINE>008</LINE>
<COLUMN>003</COLUMN>
<LENGTH>003</LENGTH>
<VISLENGTH>003</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
<LABELLEFT>X</LABELLEFT>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEMPLATE</TYPE>
<NAME>TAB_STRUC-NUM</NAME>
<TEXT>_______.__</TEXT>
<LINE>008</LINE>
<COLUMN>015</COLUMN>
<LENGTH>010</LENGTH>
<VISLENGTH>010</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>INT4</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX13</NAME>
<TEXT>Type_i</TEXT>
<LINE>008</LINE>
<COLUMN>028</COLUMN>
<LENGTH>006</LENGTH>
<VISLENGTH>006</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX14</NAME>
<TEXT>Dynpro_number:</TEXT>
<LINE>011</LINE>
<COLUMN>003</COLUMN>
<LENGTH>014</LENGTH>
<VISLENGTH>014</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEMPLATE</TYPE>
<NAME>DYNNR</NAME>
<TEXT>___________</TEXT>
<LINE>011</LINE>
<COLUMN>019</COLUMN>
<LENGTH>011</LENGTH>
<VISLENGTH>011</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<OUTPUT_FLD>X</OUTPUT_FLD>
<OUTPUTONLY>X</OUTPUTONLY>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>OKCODE</TYPE>
<NAME>OK_CODE</NAME>
<TEXT>____________________</TEXT>
<LENGTH>020</LENGTH>
<VISLENGTH>020</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
</RPY_DYFATC>
</FIELDS>
<FLOW_LOGIC>
<RPY_DYFLOW>
<LINE>PROCESS BEFORE OUTPUT.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW>
<LINE> MODULE STATUS_9760.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW/>
<RPY_DYFLOW>
<LINE>PROCESS AFTER INPUT.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW>
<LINE> MODULE USER_COMMAND_9760.</LINE>
</RPY_DYFLOW>
</FLOW_LOGIC>
</item>
<item>
<HEADER>
<PROGRAM>ZDEMO_ABAP_SAP_LUW</PROGRAM>
<SCREEN>9770</SCREEN>
<LANGUAGE>E</LANGUAGE>
<DESCRIPT>End SAP LUW</DESCRIPT>
<TYPE>N</TYPE>
<NEXTSCREEN>0000</NEXTSCREEN>
<LINES>027</LINES>
<COLUMNS>121</COLUMNS>
</HEADER>
<CONTAINERS>
<RPY_DYCATT>
<TYPE>SCREEN</TYPE>
<NAME>SCREEN</NAME>
</RPY_DYCATT>
<RPY_DYCATT>
<TYPE>RADIOGROUP</TYPE>
<NAME>%A_COMMIT</NAME>
<ELEMENT_OF>SCREEN</ELEMENT_OF>
<LINE>004</LINE>
<COLUMN>003</COLUMN>
<LENGTH>048</LENGTH>
<HEIGHT>005</HEIGHT>
</RPY_DYCATT>
</CONTAINERS>
<FIELDS>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX6</NAME>
<TEXT>Select_one_of_the_following_options_to_proceed:</TEXT>
<LINE>002</LINE>
<COLUMN>003</COLUMN>
<LENGTH>047</LENGTH>
<VISLENGTH>047</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
<LABELLEFT>X</LABELLEFT>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>%#AUTOTEXT009</NAME>
<TEXT>Dynpro_number:</TEXT>
<LINE>012</LINE>
<COLUMN>003</COLUMN>
<LENGTH>014</LENGTH>
<VISLENGTH>014</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEMPLATE</TYPE>
<NAME>DYNNR</NAME>
<TEXT>___________</TEXT>
<LINE>012</LINE>
<COLUMN>018</COLUMN>
<LENGTH>011</LENGTH>
<VISLENGTH>011</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<OUTPUT_FLD>X</OUTPUT_FLD>
<OUTPUTONLY>X</OUTPUTONLY>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>OKCODE</TYPE>
<NAME>OK_CODE</NAME>
<TEXT>____________________</TEXT>
<LENGTH>020</LENGTH>
<VISLENGTH>020</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>RADIOGROUP</CONT_TYPE>
<CONT_NAME>%A_COMMIT</CONT_NAME>
<TYPE>RADIO</TYPE>
<NAME>COMMIT</NAME>
<TEXT>Asynchronous_update_with_COMMIT_WORK</TEXT>
<LINE>004</LINE>
<COLUMN>003</COLUMN>
<LENGTH>038</LENGTH>
<VISLENGTH>038</VISLENGTH>
<HEIGHT>001</HEIGHT>
<GROUP1>1</GROUP1>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>RADIOGROUP</CONT_TYPE>
<CONT_NAME>%A_COMMIT</CONT_NAME>
<TYPE>RADIO</TYPE>
<NAME>COMMIT_WAIT</NAME>
<TEXT>Synchronous_update_with_COMMIT_WORK_AND_WAIT</TEXT>
<LINE>005</LINE>
<COLUMN>003</COLUMN>
<LENGTH>046</LENGTH>
<VISLENGTH>046</VISLENGTH>
<HEIGHT>001</HEIGHT>
<GROUP1>1</GROUP1>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>RADIOGROUP</CONT_TYPE>
<CONT_NAME>%A_COMMIT</CONT_NAME>
<TYPE>RADIO</TYPE>
<NAME>ROLLBACK</NAME>
<TEXT>Rollback_changes_using_ROLLBACK_WORK</TEXT>
<LINE>006</LINE>
<COLUMN>003</COLUMN>
<LENGTH>038</LENGTH>
<VISLENGTH>038</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>RADIOGROUP</CONT_TYPE>
<CONT_NAME>%A_COMMIT</CONT_NAME>
<TYPE>RADIO</TYPE>
<NAME>ERR</NAME>
<TEXT>Cause_a_failure_in_the_current_SAP_LUW</TEXT>
<LINE>007</LINE>
<COLUMN>003</COLUMN>
<LENGTH>040</LENGTH>
<VISLENGTH>040</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>RADIOGROUP</CONT_TYPE>
<CONT_NAME>%A_COMMIT</CONT_NAME>
<TYPE>RADIO</TYPE>
<NAME>TERMINATE</NAME>
<TEXT>Terminate_program_with_error_message_of_type_A</TEXT>
<LINE>008</LINE>
<COLUMN>003</COLUMN>
<LENGTH>048</LENGTH>
<VISLENGTH>048</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
<OUTPUT_FLD>X</OUTPUT_FLD>
</RPY_DYFATC>
</FIELDS>
<FLOW_LOGIC>
<RPY_DYFLOW>
<LINE>PROCESS BEFORE OUTPUT.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW>
<LINE> MODULE STATUS_9770.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW/>
<RPY_DYFLOW>
<LINE>PROCESS AFTER INPUT.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW>
<LINE> MODULE USER_COMMAND_9770.</LINE>
</RPY_DYFLOW>
</FLOW_LOGIC>
</item>
</DYNPROS>
<CUA>
<ADM>
<ACTCODE>000003</ACTCODE>
<PFKCODE>000003</PFKCODE>
</ADM>
<STA>
<RSMPE_STAT>
<CODE>STATUS9750</CODE>
<MODAL>D</MODAL>
<ACTCODE>000001</ACTCODE>
<PFKCODE>000001</PFKCODE>
<BUTCODE>0001</BUTCODE>
<INT_NOTE>Delete database table entries</INT_NOTE>
</RSMPE_STAT>
<RSMPE_STAT>
<CODE>STATUS9760</CODE>
<MODAL>D</MODAL>
<ACTCODE>000002</ACTCODE>
<PFKCODE>000002</PFKCODE>
<BUTCODE>0001</BUTCODE>
<INT_NOTE>Create database table entry</INT_NOTE>
</RSMPE_STAT>
<RSMPE_STAT>
<CODE>STATUS9770</CODE>
<MODAL>D</MODAL>
<ACTCODE>000003</ACTCODE>
<PFKCODE>000003</PFKCODE>
<BUTCODE>0001</BUTCODE>
<INT_NOTE>End SAP LUW</INT_NOTE>
</RSMPE_STAT>
</STA>
<FUN>
<RSMPE_FUNT>
<CODE>ENTER</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<FUN_TEXT>Enter</FUN_TEXT>
</RSMPE_FUNT>
<RSMPE_FUNT>
<CODE>GO</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<TEXT_NAME>ICON_MAPPED_RELATION</TEXT_NAME>
<ICON_ID>@EY@</ICON_ID>
<FUN_TEXT>Go</FUN_TEXT>
<ICON_TEXT>Go</ICON_TEXT>
<INFO_TEXT>Go</INFO_TEXT>
</RSMPE_FUNT>
<RSMPE_FUNT>
<CODE>LEAVE</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<FUN_TEXT>Exit</FUN_TEXT>
</RSMPE_FUNT>
</FUN>
<BUT>
<RSMPE_BUT>
<PFK_CODE>000001</PFK_CODE>
<CODE>0001</CODE>
<NO>01</NO>
<PFNO>08</PFNO>
</RSMPE_BUT>
<RSMPE_BUT>
<PFK_CODE>000002</PFK_CODE>
<CODE>0001</CODE>
<NO>01</NO>
<PFNO>08</PFNO>
</RSMPE_BUT>
<RSMPE_BUT>
<PFK_CODE>000003</PFK_CODE>
<CODE>0001</CODE>
<NO>01</NO>
<PFNO>08</PFNO>
</RSMPE_BUT>
</BUT>
<PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>00</PFNO>
<FUNCODE>ENTER</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>08</PFNO>
<FUNCODE>GO</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>15</PFNO>
<FUNCODE>LEAVE</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000002</CODE>
<PFNO>00</PFNO>
<FUNCODE>ENTER</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000002</CODE>
<PFNO>08</PFNO>
<FUNCODE>GO</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000002</CODE>
<PFNO>15</PFNO>
<FUNCODE>LEAVE</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000003</CODE>
<PFNO>00</PFNO>
<FUNCODE>ENTER</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000003</CODE>
<PFNO>08</PFNO>
<FUNCODE>GO</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000003</CODE>
<PFNO>15</PFNO>
<FUNCODE>LEAVE</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
</PFK>
<SET>
<RSMPE_STAF>
<STATUS>STATUS9750</STATUS>
<FUNCTION>ENTER</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9750</STATUS>
<FUNCTION>GO</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9750</STATUS>
<FUNCTION>LEAVE</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9760</STATUS>
<FUNCTION>ENTER</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9760</STATUS>
<FUNCTION>GO</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9760</STATUS>
<FUNCTION>LEAVE</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9770</STATUS>
<FUNCTION>ENTER</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9770</STATUS>
<FUNCTION>GO</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9770</STATUS>
<FUNCTION>LEAVE</FUNCTION>
</RSMPE_STAF>
</SET>
<DOC>
<RSMPE_ATRT>
<OBJ_TYPE>A</OBJ_TYPE>
<OBJ_CODE>000001</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Delete database table entries</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>P</OBJ_TYPE>
<OBJ_CODE>000001</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Delete database table entries</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>B</OBJ_TYPE>
<OBJ_CODE>000001</OBJ_CODE>
<SUB_CODE>0001</SUB_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Delete database table entries</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>A</OBJ_TYPE>
<OBJ_CODE>000002</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Create database table entry</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>P</OBJ_TYPE>
<OBJ_CODE>000002</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Create database table entry</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>B</OBJ_TYPE>
<OBJ_CODE>000002</OBJ_CODE>
<SUB_CODE>0001</SUB_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Create database table entry</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>A</OBJ_TYPE>
<OBJ_CODE>000003</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>End SAP LUW</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>P</OBJ_TYPE>
<OBJ_CODE>000003</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>End SAP LUW</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>B</OBJ_TYPE>
<OBJ_CODE>000003</OBJ_CODE>
<SUB_CODE>0001</SUB_CODE>
<MODAL>D</MODAL>
<INT_NOTE>End SAP LUW</INT_NOTE>
</RSMPE_ATRT>
</DOC>
<TIT>
<RSMPE_TITT>
<CODE>TITLE9750</CODE>
<TEXT>Delete database table entries</TEXT>
</RSMPE_TITT>
<RSMPE_TITT>
<CODE>TITLE9760</CODE>
<TEXT>Create database table entry</TEXT>
</RSMPE_TITT>
<RSMPE_TITT>
<CODE>TITLE9770</CODE>
<TEXT>End SAP LUW</TEXT>
</RSMPE_TITT>
</TIT>
</CUA>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Demonstrating SAP LUW</ENTRY>
<LENGTH>21</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,139 @@
*&---------------------------------------------------------------------*
*& Demo program used in the context of the SAP LUW ABAP cheat sheet
*&
*&----------------------------- NOTE -----------------------------------*
*& The code presented in this class is intended only to support the ABAP
*& cheat sheets. It is not intended for direct use in a production system
*& environment. The code examples in the ABAP cheat sheets are primarily
*& intended to provide a better explanation and visualization of the
*& syntax and semantics of ABAP statements, not to solve concrete
*& programming tasks. For production application programs, you should
*& always work out your own solution for each individual case. There is
*& no guarantee for the correctness or completeness of the code.
*& Furthermore, there is no legal responsibility or liability for any
*& errors or their consequences that may occur when using the the example
*& code.
*&---------------------------------------------------------------------*
REPORT zdemo_abap_sap_luw_displ.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm,
dynnr LIKE sy-dynnr.
END-OF-SELECTION.
"Checks if program is started separately
SELECT COUNT(*)
FROM zdemo_abap_logt
INTO @DATA(entries).
SELECT SINGLE id
FROM zdemo_abap_logt
WHERE id = 100
INTO @DATA(exists).
IF sy-subrc = 0 OR entries = 0.
DELETE FROM zdemo_abap_logt.
DATA(check) = abap_true.
zcl_demo_abap_sap_luw_helper=>create_log_entries(
VALUE #( ( id = 97
context = '-'
name = '-'
details = `Choose Start over from the menu.`
timestamp = utclong_current( ) ) ) ).
ENDIF.
zcl_demo_abap_sap_luw_helper=>create_log_entries(
VALUE #( ( id = 100
context = '-'
name = '-'
details = |New program executed: { sy-repid }|
timestamp = utclong_current( ) ) ) ).
CALL SCREEN 9780.
**********************************************************************
***************** Dialog modules for 9780 ****************************
MODULE status_9780 OUTPUT.
SET PF-STATUS 'STATUS9780'.
SET TITLEBAR 'TITLE9780'.
"Checks for asynchronous update
IF check = abap_false.
DATA(idx) = 0.
DO 5 TIMES. "A maximum of 5 seconds of waiting time
SELECT SINGLE id, context
FROM zdemo_abap_logt
WHERE
"Entry inserted ...
id = 93 "by the final update function module
OR id = 99 "in case of ROLLBACK WORK
OR id = 96 "in case of the intended failure in SAP LUW
OR context = 'Subroutine' "if subroutines are used
INTO @DATA(wa). "#EC CI_CMPLX_WHERE
IF sy-subrc = 0.
EXIT.
ELSE.
idx = sy-index.
WAIT UP TO 1 SECONDS.
ENDIF.
ENDDO.
IF idx = 5.
MESSAGE `The asynchronous update takes too long. ` &&
`You may want to restart the example and try again.`
TYPE 'I'.
ENDIF.
ENDIF.
zcl_demo_abap_sap_luw_helper=>create_log_entries(
VALUE #(
( id = 101
context = 'PBO'
name = 'status_9780'
details = `Module called`
timestamp = utclong_current( ) )
( id = 102
context = 'PBO'
name = 'status_9780'
details = zcl_demo_abap_sap_luw_helper=>get_work_process_info( )
timestamp = utclong_current( ) )
( id = 103
context = 'PBO'
name = 'status_9780'
details = `SAP LUW Key: ` &&
cl_system_transaction_state=>get_sap_luw_key( )
timestamp = utclong_current( ) )
( id = 104
context = 'PBO'
name = 'status_9780'
details = zcl_demo_abap_sap_luw_helper=>checking_transaction_state( )
timestamp = utclong_current( ) ) ) ).
zcl_demo_abap_sap_luw_helper=>cc_alv_display( 'CC_DB_FINAL' ).
zcl_demo_abap_sap_luw_helper=>cc_alv_display( container = 'CC_WP'
log = abap_true ).
dynnr = sy-dynnr.
ENDMODULE.
MODULE user_command_9780 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'STARTOVER'.
ROLLBACK WORK.
DELETE FROM zdemo_abap_logt.
SUBMIT ('ZDEMO_ABAP_SAP_LUW').
WHEN OTHERS.
DELETE FROM zdemo_abap_logt.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.

View File

@@ -0,0 +1,240 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<PROGDIR>
<NAME>ZDEMO_ABAP_SAP_LUW_DISPL</NAME>
<DBAPL>S</DBAPL>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<DYNPROS>
<item>
<HEADER>
<PROGRAM>ZDEMO_ABAP_SAP_LUW_DISPL</PROGRAM>
<SCREEN>9780</SCREEN>
<LANGUAGE>E</LANGUAGE>
<DESCRIPT>Display database table and log</DESCRIPT>
<TYPE>N</TYPE>
<NEXTSCREEN>9780</NEXTSCREEN>
<LINES>027</LINES>
<COLUMNS>186</COLUMNS>
</HEADER>
<CONTAINERS>
<RPY_DYCATT>
<TYPE>SCREEN</TYPE>
<NAME>SCREEN</NAME>
</RPY_DYCATT>
<RPY_DYCATT>
<TYPE>CUST_CTRL</TYPE>
<NAME>CC_DB_FINAL</NAME>
<ELEMENT_OF>SCREEN</ELEMENT_OF>
<LINE>003</LINE>
<COLUMN>002</COLUMN>
<LENGTH>074</LENGTH>
<HEIGHT>007</HEIGHT>
</RPY_DYCATT>
<RPY_DYCATT>
<TYPE>CUST_CTRL</TYPE>
<NAME>CC_WP</NAME>
<ELEMENT_OF>SCREEN</ELEMENT_OF>
<LINE>013</LINE>
<COLUMN>002</COLUMN>
<LENGTH>156</LENGTH>
<HEIGHT>014</HEIGHT>
</RPY_DYCATT>
</CONTAINERS>
<FIELDS>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX15</NAME>
<TEXT>Database_table_entries:</TEXT>
<LINE>001</LINE>
<COLUMN>002</COLUMN>
<LENGTH>023</LENGTH>
<VISLENGTH>023</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>%#AUTOTEXT003</NAME>
<TEXT>Dynpro_number:</TEXT>
<LINE>001</LINE>
<COLUMN>130</COLUMN>
<LENGTH>014</LENGTH>
<VISLENGTH>014</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEMPLATE</TYPE>
<NAME>DYNNR</NAME>
<TEXT>___________</TEXT>
<LINE>001</LINE>
<COLUMN>146</COLUMN>
<LENGTH>011</LENGTH>
<VISLENGTH>011</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<OUTPUT_FLD>X</OUTPUT_FLD>
<OUTPUTONLY>X</OUTPUTONLY>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>TEXT</TYPE>
<NAME>TX16</NAME>
<TEXT>Log_database_table_entries:</TEXT>
<LINE>011</LINE>
<COLUMN>002</COLUMN>
<LENGTH>027</LENGTH>
<VISLENGTH>027</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<REQU_ENTRY>N</REQU_ENTRY>
</RPY_DYFATC>
<RPY_DYFATC>
<CONT_TYPE>SCREEN</CONT_TYPE>
<CONT_NAME>SCREEN</CONT_NAME>
<TYPE>OKCODE</TYPE>
<NAME>OK_CODE</NAME>
<TEXT>____________________</TEXT>
<LENGTH>020</LENGTH>
<VISLENGTH>020</VISLENGTH>
<HEIGHT>001</HEIGHT>
<FORMAT>CHAR</FORMAT>
<INPUT_FLD>X</INPUT_FLD>
</RPY_DYFATC>
</FIELDS>
<FLOW_LOGIC>
<RPY_DYFLOW>
<LINE>PROCESS BEFORE OUTPUT.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW>
<LINE> MODULE STATUS_9780.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW/>
<RPY_DYFLOW>
<LINE>PROCESS AFTER INPUT.</LINE>
</RPY_DYFLOW>
<RPY_DYFLOW>
<LINE> MODULE USER_COMMAND_9780.</LINE>
</RPY_DYFLOW>
</FLOW_LOGIC>
</item>
</DYNPROS>
<CUA>
<ADM>
<ACTCODE>000001</ACTCODE>
<PFKCODE>000001</PFKCODE>
</ADM>
<STA>
<RSMPE_STAT>
<CODE>STATUS9780</CODE>
<MODAL>D</MODAL>
<ACTCODE>000001</ACTCODE>
<PFKCODE>000001</PFKCODE>
<BUTCODE>0001</BUTCODE>
<INT_NOTE>Display database table and log</INT_NOTE>
</RSMPE_STAT>
</STA>
<FUN>
<RSMPE_FUNT>
<CODE>LEAVE</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<FUN_TEXT>Exit</FUN_TEXT>
</RSMPE_FUNT>
<RSMPE_FUNT>
<CODE>STARTOVER</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<TEXT_NAME>ICON_SYSTEM_UNDO</TEXT_NAME>
<ICON_ID>@2W@</ICON_ID>
<FUN_TEXT>STARTOVER</FUN_TEXT>
<ICON_TEXT>Start over</ICON_TEXT>
<INFO_TEXT>Start over</INFO_TEXT>
</RSMPE_FUNT>
</FUN>
<BUT>
<RSMPE_BUT>
<PFK_CODE>000001</PFK_CODE>
<CODE>0001</CODE>
<NO>01</NO>
<PFNO>08</PFNO>
</RSMPE_BUT>
</BUT>
<PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>08</PFNO>
<FUNCODE>STARTOVER</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>15</PFNO>
<FUNCODE>LEAVE</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
</PFK>
<SET>
<RSMPE_STAF>
<STATUS>STATUS9780</STATUS>
<FUNCTION>LEAVE</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>STATUS9780</STATUS>
<FUNCTION>STARTOVER</FUNCTION>
</RSMPE_STAF>
</SET>
<DOC>
<RSMPE_ATRT>
<OBJ_TYPE>A</OBJ_TYPE>
<OBJ_CODE>000001</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Display database table and log</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>P</OBJ_TYPE>
<OBJ_CODE>000001</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Display database table and log</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>B</OBJ_TYPE>
<OBJ_CODE>000001</OBJ_CODE>
<SUB_CODE>0001</SUB_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Display database table and log</INT_NOTE>
</RSMPE_ATRT>
</DOC>
<TIT>
<RSMPE_TITT>
<CODE>TITLE9780</CODE>
<TEXT>Display database table and log</TEXT>
</RSMPE_TITT>
</TIT>
</CUA>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Demonstrating SAP LUW - Display</ENTRY>
<LENGTH>31</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,20 @@
***********************************************************************
*
* RAP BO provider (i. e. ABAP behavior pool/ABP)
* for a RAP demo scenario
*
* See more information in the CCIMP include (local types tab in ADT).
*
**********************************************************************
"! <p class="shorttext synchronized">Behavior implementation for RAP demo scenario (draft BO)</p>
"! The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario
"! (managed, draft-enabled RAP BO with late numbering).
CLASS zbp_demo_abap_rap_draft_m DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_draft_m.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS ZBP_DEMO_ABAP_RAP_DRAFT_M IMPLEMENTATION.
ENDCLASS.

View File

@@ -0,0 +1,240 @@
***********************************************************************
*
* RAP BO provider (i. e. ABAP behavior pool/ABP)
* for a RAP demo scenario
*
* - RAP scenario: "RAP calculator" (managed, draft-enabled RAP BO with
* late numbering)
* - Data model: Consists of a root entity alone.
* The BDEF defines the behavior for this entity. The definitions in the
* BDEF determine which methods must be implemented in the ABAP behavior
* pool (ABP). Note that the view contains many annotations for the
* SAP Fiori UI.
*
* ----------------------------- NOTE -----------------------------------
* 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.
*
* In newer ABAP releases, you can use side effects to trigger data
* changes (in terms of this example, the recalculation of the calculation
* result) and other things based on data changes in UI scenarios with
* draft-enabled BOs.
*
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
CLASS lhc_calc DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS delete_all FOR MODIFY
IMPORTING keys FOR ACTION calc~delete_all.
METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION
IMPORTING REQUEST requested_authorizations FOR calc RESULT result.
METHODS validate FOR VALIDATE ON SAVE
IMPORTING keys FOR calc~validate.
METHODS det_modify FOR DETERMINE ON MODIFY
IMPORTING keys FOR calc~det_modify.
METHODS calculation FOR MODIFY
IMPORTING keys FOR ACTION calc~calculation.
ENDCLASS.
CLASS lhc_calc IMPLEMENTATION.
METHOD delete_all.
"Purpose: The method deletes all persisted database entries.
DATA all_keys TYPE TABLE FOR DELETE zdemo_abap_rap_draft_m.
SELECT id FROM zdemo_abap_tabca INTO CORRESPONDING FIELDS OF TABLE @all_keys.
READ ENTITIES OF zdemo_abap_rap_draft_m IN LOCAL MODE
ENTITY calc
ALL FIELDS WITH CORRESPONDING #( all_keys )
RESULT DATA(lt_del).
IF lt_del IS NOT INITIAL.
MODIFY ENTITY IN LOCAL MODE zdemo_abap_rap_draft_m
DELETE FROM CORRESPONDING #( lt_del ).
APPEND VALUE #( %msg = new_message_with_text( text = 'All persisted calculations were deleted.'
severity = if_abap_behv_message=>severity-information )
) TO reported-calc.
ELSE.
APPEND VALUE #( %msg = new_message_with_text( text = 'No persisted calculations available.'
severity = if_abap_behv_message=>severity-information )
) TO reported-calc.
ENDIF.
ENDMETHOD.
METHOD get_global_authorizations.
"Purposely kept without implementation.
ENDMETHOD.
METHOD validate.
"Retrieving instances based on requested keys
READ ENTITIES OF zdemo_abap_rap_draft_m IN LOCAL MODE
ENTITY calc
ALL FIELDS
WITH CORRESPONDING #( keys )
RESULT DATA(result_validate)
FAILED DATA(f).
CHECK result_validate IS NOT INITIAL.
"Various calculation errors are handled.
LOOP AT result_validate ASSIGNING FIELD-SYMBOL(<fs>).
APPEND VALUE #( %tky = <fs>-%tky
%state_area = 'VALIDATE_CALCULATION'
) TO reported-calc.
IF <fs>-calc_result = `Wrong operator`.
APPEND VALUE #( %tky = <fs>-%tky ) TO failed-calc.
APPEND VALUE #( %tky = <fs>-%tky
%state_area = 'VALIDATE_CALCULATION'
%msg = new_message_with_text( text = 'Only + - * / P allowed as operators.'
severity = if_abap_behv_message=>severity-error )
"%element highlights the input field
%element-arithm_op = if_abap_behv=>mk-on
) TO reported-calc.
ELSEIF <fs>-calc_result = `Division by 0`.
APPEND VALUE #( %tky = <fs>-%tky ) TO failed-calc.
APPEND VALUE #( %tky = <fs>-%tky
%state_area = 'VALIDATE_CALCULATION'
%msg = new_message_with_text( text = 'Zero division not possible.'
severity = if_abap_behv_message=>severity-error )
%element-arithm_op = if_abap_behv=>mk-on
%element-num2 = if_abap_behv=>mk-on
) TO reported-calc.
ELSEIF <fs>-calc_result = `Overflow error`.
APPEND VALUE #( %tky = <fs>-%tky ) TO failed-calc.
APPEND VALUE #( %tky = <fs>-%tky
%state_area = 'VALIDATE_CALCULATION'
%msg = new_message_with_text( text = 'Check the numbers. Try smaller ones.'
severity = if_abap_behv_message=>severity-error )
%element-num1 = if_abap_behv=>mk-on
%element-num2 = if_abap_behv=>mk-on
) TO reported-calc.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD det_modify.
MODIFY ENTITIES OF zdemo_abap_rap_draft_m IN LOCAL MODE
ENTITY calc
EXECUTE calculation
FROM CORRESPONDING #( keys ).
ENDMETHOD.
METHOD calculation.
READ ENTITIES OF zdemo_abap_rap_draft_m IN LOCAL MODE
ENTITY calc
FIELDS ( num1 num2 arithm_op ) WITH CORRESPONDING #( keys )
RESULT DATA(lt_calc)
FAILED DATA(f).
LOOP AT lt_calc ASSIGNING FIELD-SYMBOL(<calc>).
TRY.
<calc>-calc_result = SWITCH #( <calc>-arithm_op
WHEN `+` THEN <calc>-num1 + <calc>-num2
WHEN `-` THEN <calc>-num1 - <calc>-num2
WHEN `*` THEN <calc>-num1 * <calc>-num2
WHEN `/` THEN <calc>-num1 / <calc>-num2
WHEN `P` THEN ipow( base = <calc>-num1 exp = <calc>-num2 )
ELSE `Wrong operator` ).
"Bringing "-" to the front in case of negative values in the string
IF <calc>-calc_result CA `-`.
<calc>-calc_result = shift_right( val = <calc>-calc_result circular = 1 ).
ENDIF.
"Removing trailing .0 from the string
REPLACE PCRE `\.0+\b` IN <calc>-calc_result WITH ``.
"Handling the fact that ABAP allows division by zero if the dividend itself is zero.
IF <calc>-num1 = 0 AND <calc>-num2 = 0 AND <calc>-arithm_op = `/`.
<calc>-calc_result = `Division by 0`.
ENDIF.
CATCH cx_sy_zerodivide.
<calc>-calc_result = `Division by 0`.
CATCH cx_sy_arithmetic_overflow.
<calc>-calc_result = `Overflow error`.
ENDTRY.
ENDLOOP.
MODIFY ENTITY IN LOCAL MODE zdemo_abap_rap_draft_m
UPDATE FIELDS ( calc_result )
WITH CORRESPONDING #( lt_calc ).
ENDMETHOD.
ENDCLASS.
CLASS lsc_zdemo_abap_rap_draft_m DEFINITION INHERITING FROM cl_abap_behavior_saver.
PROTECTED SECTION.
METHODS adjust_numbers REDEFINITION.
ENDCLASS.
CLASS lsc_zdemo_abap_rap_draft_m IMPLEMENTATION.
METHOD adjust_numbers.
"The newly created entity instances are given their final key
"only shortly before saving in the database in the adjust_numbers method.
"Until then, the business logic uses a temporary key that has to be replaced.
"In this very simplified example, the key 'id' is purposely typed with the
"type sysuuid_x16 which can accept the value used in %pid to finally ensure
"that there is a unique key and the instance can be stored in the database.
"Hence, the final key 'id' is in this example just the value used for %pid.
LOOP AT mapped-calc ASSIGNING FIELD-SYMBOL(<fs>).
<fs>-%key-id = <fs>-%pid.
ENDLOOP.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZBP_DEMO_ABAP_RAP_DRAFT_M</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Behavior implementation for RAP demo scenario (draft BO)</DESCRIPT>
<CATEGORY>06</CATEGORY>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<CLSDEFINT>ZDEMO_ABAP_RAP_DRAFT_M</CLSDEFINT>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,20 @@
***********************************************************************
*
* RAP BO provider (i. e. ABAP behavior pool/ABP)
* for a RAP demo scenario
*
* See more information in the CCIMP include (local types tab in ADT).
*
**********************************************************************
"! <p class="shorttext synchronized">Behavior implementation for RAP demo scenario (managed BO)</p>
"! The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario
"! (managed RAP BO with external numbering).
CLASS zbp_demo_abap_rap_ro_m DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_ro_m.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS ZBP_DEMO_ABAP_RAP_RO_M IMPLEMENTATION.
ENDCLASS.

View File

@@ -0,0 +1,124 @@
***********************************************************************
*
* RAP BO provider (i. e. ABAP behavior pool/ABP)
* for a RAP demo scenario
*
* - RAP scenario: managed RAP BO, external numbering
* - 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 this ABAP behavior pool (ABP).
*
* ----------------------------- NOTE -----------------------------------
* 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 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.
*
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
CLASS lhc_root DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION
IMPORTING REQUEST requested_authorizations FOR root RESULT result.
METHODS multiply_by_2 FOR MODIFY
IMPORTING keys FOR ACTION root~multiply_by_2.
METHODS det_add_text FOR DETERMINE ON SAVE
IMPORTING keys FOR root~det_add_text.
METHODS val FOR VALIDATE ON SAVE
IMPORTING keys FOR root~val.
ENDCLASS.
CLASS lhc_root IMPLEMENTATION.
METHOD get_global_authorizations.
ENDMETHOD.
METHOD multiply_by_2.
"Retrieving instances based on requested keys
READ ENTITIES OF zdemo_abap_rap_ro_m IN LOCAL MODE
ENTITY root
FIELDS ( field3 field4 ) WITH CORRESPONDING #( keys )
RESULT DATA(result)
FAILED failed.
"If read result is initial, stop further method execution.
CHECK result IS NOT INITIAL.
"Multiply integer values by 2
MODIFY ENTITIES OF zdemo_abap_rap_ro_m IN LOCAL MODE
ENTITY root
UPDATE FIELDS ( field3 field4 ) WITH VALUE #( FOR key IN result ( %tky = key-%tky
field3 = key-field3 * 2
field4 = key-field4 * 2 ) ).
ENDMETHOD.
METHOD det_add_text.
READ ENTITIES OF zdemo_abap_rap_ro_m IN LOCAL MODE
ENTITY root
FIELDS ( field2 ) WITH CORRESPONDING #( keys )
RESULT DATA(lt_res).
"If read result is initial, stop further method execution.
CHECK lt_res IS NOT INITIAL.
"field2 is changed
MODIFY ENTITIES OF zdemo_abap_rap_ro_m IN LOCAL MODE
ENTITY root
UPDATE FIELDS ( field2 )
WITH VALUE #( FOR key IN lt_res ( %tky = key-%tky
field2 = |{ key-field2 }_#| ) ).
ENDMETHOD.
METHOD val.
READ ENTITIES OF zdemo_abap_rap_ro_m IN LOCAL MODE
ENTITY root
FIELDS ( field3 ) WITH CORRESPONDING #( keys )
RESULT DATA(lt_res).
"If read result is initial, stop further method execution.
CHECK lt_res IS NOT INITIAL.
LOOP AT lt_res ASSIGNING FIELD-SYMBOL(<fs_res>).
IF <fs_res>-field3 > 1000.
APPEND VALUE #( %tky = <fs_res>-%tky
%fail-cause = if_abap_behv=>cause-disabled
)
TO failed-root.
APPEND VALUE #( %tky = <fs_res>-%tky
%msg = new_message_with_text(
severity = if_abap_behv_message=>severity-error
text = 'Validation failed!' )
) TO reported-root.
ENDIF.
ENDLOOP.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZBP_DEMO_ABAP_RAP_RO_M</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Behavior implementation for RAP demo scenario (managed BO)</DESCRIPT>
<CATEGORY>06</CATEGORY>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<CLSDEFINT>ZDEMO_ABAP_RAP_RO_M</CLSDEFINT>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,20 @@
***********************************************************************
*
* RAP BO provider (i. e. ABAP behavior pool/ABP)
* for a RAP demo scenario
*
* See more information in the CCIMP include (local types tab in ADT).
*
**********************************************************************
"! <p class="shorttext synchronized">Behavior implementation for RAP demo scenario (unmanaged BO)</p>
"! The class represents a RAP BO provider (i. e. an ABAP behavior pool/ABP) for a RAP demo scenario
"! (unmanaged RAP BO with external numbering).
CLASS zbp_demo_abap_rap_ro_u DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zdemo_abap_rap_ro_u.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS ZBP_DEMO_ABAP_RAP_RO_U IMPLEMENTATION.
ENDCLASS.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZBP_DEMO_ABAP_RAP_RO_U</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Behavior implementation for RAP demo scenario (unmanaged BO)</DESCRIPT>
<CATEGORY>06</CATEGORY>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<CLSDEFINT>ZDEMO_ABAP_RAP_RO_U</CLSDEFINT>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,376 @@
***********************************************************************
*
* ABAP cheat sheet: AMDP
*
* -------------------------- PURPOSE ----------------------------------
* - Example to demonstrate AMDP procedures and functions. It includes
* a CDS table function.
* - NOTE:
* - The example covers basics regarding AMDP method declarations
* and implementations.
* - The purpose is to give you a rough idea about AMDP. Therefore,
* the SQLScript code used in the method implementations is
* fairly simple. AMDP is not needed in simple cases like these.
* - The example is primarily intended for the SAP BTP ABAP
* environment. For example, in SAP BTP ABAP environment only
* read-only operations are possible. In general, there are more
* syntax options available in the unrestricted ABAP language scope
* in on-premise ABAP systems. Check the ABAP Keyword Documentation
* for more details and examples.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, check the notes
* included in the class as comments or refer to the respective topic
* in the ABAP Keyword Documentation.
* - Due to the amount of output in the console, the examples include
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
* sections. Plus, the variable name is displayed in most cases. Hence,
* to easier and faster find the relevant output in the console, just
* search in the console for the number/variable name (CTRL+F in the
* console) or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">ABAP cheat sheet: AMDP</p>
"! Example to demonstrate AMDP procedures and functions.<br>Choose F9 in ADT to run the class.
CLASS zcl_demo_abap_amdp DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES:
if_oo_adt_classrun, "Interface for displaying output
if_amdp_marker_hdb. "This interface specification is mandatory for an AMDP class
"Various internal table type specifications for the parameters of AMDP methods
"Note: Only table and elementary data types are possible for the parameters.
TYPES carr_tab TYPE STANDARD TABLE OF zdemo_abap_carr WITH EMPTY KEY.
TYPES fli_tab TYPE STANDARD TABLE OF zdemo_abap_fli WITH EMPTY KEY.
TYPES:
"Structured data type as basis for the table type below
BEGIN OF carr_fli_struc,
carrname TYPE zdemo_abap_carr-carrname,
connid TYPE zdemo_abap_flsch-connid,
cityfrom TYPE zdemo_abap_flsch-cityfrom,
cityto TYPE zdemo_abap_flsch-cityto,
END OF carr_fli_struc,
"Internal table type
carr_fli_tab TYPE STANDARD TABLE OF carr_fli_struc WITH EMPTY KEY,
"Structured data type as basis for the table type below
BEGIN OF fli_struc,
carrid TYPE zdemo_abap_flsch-carrid,
connid TYPE zdemo_abap_flsch-connid,
cityfrom TYPE zdemo_abap_flsch-cityfrom,
cityto TYPE zdemo_abap_flsch-cityto,
fltime TYPE zdemo_abap_flsch-fltime,
END OF fli_struc,
"Internal table type
flsch_tab TYPE STANDARD TABLE OF zdemo_abap_flsch WITH EMPTY KEY.
"Various instance method declarations
"The selection for instance and static methods is irrelevant for the example.
"It is just meant to visualize that AMDP methods can be declared as either of them.
"AMDP procedure
"It's a simple AMDP procedure having only an output parameter with tabular type.
"Note the parameter declaration that includes the mandatory passing by value.
"This is true for all of the AMDP method declarations.
METHODS select_carriers
EXPORTING VALUE(carr_tab) TYPE carr_tab.
"AMDP procedure to call an AMDP table function
"As can be seen in the implementation part, this example method calls the
"AMDP table function get_carr_fli. AMDP table functions can only be called
"by other AMDP methods.
METHODS select_get_carr_fli
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid
EXPORTING VALUE(carr_fli_tab) TYPE carr_fli_tab.
"Various static method declarations
"The purpose of the implementation of the static constructor in this example is to
"fill a demo database table to have data to work with in the example.
CLASS-METHODS class_constructor.
"AMDP procedure
"This method demonstrates the calling of an AMDP procedure from SQLScript.
"In this example, the selection of data is 'delegated' to another AMDP method get_flights_amdp
"in the same AMDP class. The method declaration includes the addition RAISING with an
"exception class for AMDP-specific exceptions.
CLASS-METHODS get_flights
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid
EXPORTING VALUE(fli_tab) TYPE fli_tab
RAISING cx_amdp_execution_error.
"AMDP Table Function for CDS Table Function
"Note that, in this case, a static method declaration is required along with the special
"syntax FOR TABLE FUNCTION. Plus, there are no parameters specified and the declaration
"is made in the PUBLIC visibility section.
CLASS-METHODS flight_analysis FOR TABLE FUNCTION zdemo_abap_table_function.
PROTECTED SECTION.
PRIVATE SECTION.
"AMDP procedure
"This method demonstrates the calling of an AMDP procedure from SQLScript as mentioned above.
CLASS-METHODS get_flights_amdp
IMPORTING VALUE(carrid) TYPE zdemo_abap_fli-carrid
EXPORTING VALUE(fli_tab) TYPE fli_tab
RAISING cx_amdp_execution_error.
"AMDP table function
"AMDP table functions can only be called by other AMDP methods. In this example,
"the AMDP procedure select_get_carr_fli calls this AMDP table function.
METHODS get_carr_fli
IMPORTING VALUE(carrid) TYPE zdemo_abap_flsch-carrid
RETURNING VALUE(carr_fli_tab) TYPE carr_fli_tab.
CONSTANTS nl TYPE string value cl_abap_char_utilities=>newline.
ENDCLASS.
CLASS zcl_demo_abap_amdp IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
ENDMETHOD.
METHOD flight_analysis
BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_flsch "Two database tables are used and must both be specified here.
zdemo_abap_carr.
* Reading data from two database tables
itab_cities =
select DISTINCT
zdemo_abap_flsch.mandt as client,
zdemo_abap_flsch.carrid as carrier_id,
zdemo_abap_flsch.airpfrom as airport_from,
zdemo_abap_flsch.airpto as airport_to,
zdemo_abap_flsch.fltime as flight_time,
zdemo_abap_flsch.distance as flight_distance,
zdemo_abap_flsch.distid as unit
from zdemo_abap_flsch;
itab_carrier_names =
select distinct
zdemo_abap_carr.mandt as client,
zdemo_abap_carr.carrid as carrier_id,
zdemo_abap_carr.carrname as carrier_name
from zdemo_abap_carr;
* Returning joined data using an inner join
return
select fl.client, fl.carrier_id, ca.carrier_name,
* Departure and destination airports are concatenated; then all results are joined by string aggregation
string_agg( concat(concat(fl.airport_from,' -> '),fl.airport_to), ', ' ORDER BY fl.airport_from) AS connections,
* Retrieving the average flight time of all flights by carrier
AVG( fl.flight_time ) as avg_flight_time,
* Retrieving the average flight distance of all flights by carrier; miles are converted to kilometers
avg( case 'MI'
when fl.unit then fl.flight_distance * 1.609
ELSE fl.flight_distance
END ) AS avg_distance
FROM :itab_cities AS fl
INNER JOIN :itab_carrier_names AS ca
ON ca.client = fl.client
AND ca.carrier_id = fl.carrier_id
WHERE fl.client = ca.client AND fl.carrier_id = ca.carrier_id
GROUP BY fl.client, ca.carrier_name, fl.carrier_id;
ENDMETHOD.
METHOD get_carr_fli
BY DATABASE FUNCTION
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_carr zdemo_abap_flsch.
* AMDP table function to be called by other AMDP methods only.
* In the example, joined data from two database table are returned.
RETURN
SELECT ca.carrname, fl.connid, fl.cityfrom, fl.cityto
FROM zdemo_abap_carr as ca
INNER JOIN zdemo_abap_flsch as fl
ON ca.carrid = fl.carrid
WHERE fl.carrid = :carrid
ORDER BY ca.mandt, ca.carrname, fl.connid;
ENDMETHOD.
METHOD get_flights
BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zcl_demo_abap_amdp=>get_flights_amdp.
* Another AMDP procedure is called from SQLScript
CALL "ZCL_DEMO_ABAP_AMDP=>GET_FLIGHTS_AMDP"(
carrid => :carrid,
fli_tab => :fli_tab );
ENDMETHOD.
METHOD get_flights_amdp
BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_fli.
* Simple data selection
fli_tab = SELECT *
FROM "ZDEMO_ABAP_FLI"
WHERE carrid = :carrid
ORDER BY carrid;
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: ABAP AMDP` ).
output->display( `1) AMDP procedure` ).
"Declaring an internal table to store the data that are
"returned by the following method.
"You could also choose to create the internal table inline
"within the method call,
"i. e. like ... IMPORTING carr_tab = DATA(tab) ).
DATA amdp_proc_res TYPE zcl_demo_abap_amdp=>carr_tab.
"Since the method is declared as an instance method, an instance
"has to be created. Here, the instance constructor NEW is used
"in a standalone method call that includes a chained method call.
NEW zcl_demo_abap_amdp( )->select_carriers(
IMPORTING carr_tab = amdp_proc_res ).
output->display( input = amdp_proc_res name = `amdp_proc_res` ).
**********************************************************************
output->next_section( `2) Calling an AMDP Procedure from SQLScript` ).
"As can be seen in the method implementation part, this AMDP procedure
"includes an AMDP procedure call from SQLScript.
"In this example, the AMDP procedure get_flights_amdp is called by
"get_flights which is meant to select data from a database table.
"The returned result is displayed.
TRY.
zcl_demo_abap_amdp=>get_flights( EXPORTING carrid = 'LH'
IMPORTING fli_tab = DATA(call_amdp_res) ).
CATCH cx_amdp_execution_error INTO DATA(error1).
output->display( error1->get_text( ) ).
ENDTRY.
output->display( input = call_amdp_res name = `call_amdp_res` ).
**********************************************************************
output->next_section( `3) AMDP Table Function for AMDP Method` ).
"The AMDP procedure select_get_carr_fli calls the AMDP table function
"get_carr_fli in the implementation part. AMDP table functions can
"only be called by other AMDP methods.
TRY.
NEW zcl_demo_abap_amdp( )->select_get_carr_fli(
EXPORTING carrid = 'LH'
IMPORTING carr_fli_tab = DATA(amdp_tab_func) ).
CATCH cx_amdp_execution_error INTO DATA(error2).
out->write( error2->get_text( ) ).
ENDTRY.
output->display( input = amdp_tab_func name = `amdp_tab_func` ).
"Note: When commented in, the following code results in a runtime
"error since you cannot call an AMDP function in ABAP directly.
* NEW zcl_demo_abap_amdp( )->get_carr_fli(
* EXPORTING carrid = 'LH' ).
**********************************************************************
output->next_section( `4) AMDP Table Function for CDS Table Function` ).
"The example demonstrates that a CDS table function can be used as a
"data source of ABAP SQL read statements.
"You might want to navigate to the DDL source after FROM by holding
"CTRL and clicking the DDL source name in ADT to see the details.
"Or, just check out the F2 help.
"In this example, the CDS table function is implemented in a way to
"return accumulated data.
"In the method implementation for flight_analysis, first two kinds of
"data sets from two database tables are gathered. These data sets are
"joined using an inner join. There, some expressions are included
"(strings are aggregated, average values are determined).
SELECT * FROM zdemo_abap_table_function
INTO TABLE @DATA(cds_tab_func).
output->display( input = cds_tab_func name = `cds_tab_func` ).
ENDMETHOD.
METHOD select_carriers
BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zdemo_abap_carr.
* Simple data selection
carr_tab = SELECT *
FROM "ZDEMO_ABAP_CARR"
ORDER BY carrid;
ENDMETHOD.
METHOD select_get_carr_fli
BY DATABASE PROCEDURE
FOR HDB
LANGUAGE SQLSCRIPT
OPTIONS READ-ONLY
USING zcl_demo_abap_amdp=>get_carr_fli.
* AMDP procedure to call an AMDP table function as specified after USING
carr_fli_tab = SELECT *
FROM "ZCL_DEMO_ABAP_AMDP=>GET_CARR_FLI"(
carrid => :carrid );
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_AMDP</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: AMDP</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,465 @@
***********************************************************************
*
* ABAP cheat sheet: CDS View Entities
*
* -------------------------- PURPOSE ----------------------------------
* - Example to demonstrate CDS view entities. See the CDS view entities
* that are used in the example for more details.
* - Topics covered: Operands, expressions, and built-in functions in the
* element list of CDS view entities, input parameters, joins,
* associations
* - Note: In ADT, check out the CDS view entities used in this example
* by holding down CTRL and clicking on the CDS view entity. This will
* take you to the artifact. There you can choose F8 to open the data
* preview.
* ----------------------- GETTING STARTED -----------------------------
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">ABAP cheat sheet: CDS view entities</p>
"! Example to demonstrate CDS view entities.<br>Choose F9 in ADT to run the class.
CLASS zcl_demo_abap_cds_ve DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES:
if_oo_adt_classrun.
CLASS-METHODS class_constructor.
ENDCLASS.
CLASS zcl_demo_abap_cds_ve IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
"Some more database table insertions for this particular example
MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
( carrid = 'SQ'
carrname = 'Singapore Airlines'
currcode = 'SGD'
url = 'http://www.singaporeair.com ' )
( carrid = 'QF'
carrname = 'Qantas Airways'
currcode = 'AUD'
url = 'http://www.qantas.com.au' ) ) ).
MODIFY zdemo_abap_flsch FROM TABLE @( VALUE #(
( carrid = 'UA'
connid = 3517
countryfr = 'DE'
cityfrom = 'FRANKFURT'
airpfrom = 'FRA'
countryto = 'US'
cityto = 'NEW YORK'
airpto = 'JFK'
fltime = 495
deptime = '104000'
arrtime = '125500'
distance = 6162
distid = 'KM'
fltype = ''
period = 0 ) ) ).
MODIFY zdemo_abap_fli FROM TABLE @( VALUE #( ( carrid = 'UA' ) ) ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: CDS view entities` ).
output->display( `1) Operands, expressions and built-in functions ` &&
`in a CDS view entity` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
"uses many operands, expressions and built-in functions to demonstrate
"various syntax options. In addition, the view contains an input
"parameter that must be provided with an actual parameter and
"specified in the ABAP SQL SELECT statement.
"In ADT, check out the CDS view entity by holding down CTRL and clicking
"on the CDS view entity. This will take you to the artifact. There you
"can choose F8 to open the data preview.
SELECT *
FROM zdemo_abap_cds_ve_sel( p_smax = 20 )
ORDER BY CarrierId
INTO TABLE @DATA(select_from_cds).
output->display( input = select_from_cds name = `select_from_cds` ).
**********************************************************************
output->next_section( `2) Aggregate Expressions` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
"uses aggregate expressions.
SELECT *
FROM zdemo_abap_cds_ve_agg_exp
ORDER BY carrid
INTO TABLE @DATA(agg_expr).
output->display( input = agg_expr name = `agg_expr` ).
**********************************************************************
output->next_section( `3) Joins` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
"contains multiple joins.
"The CDS view entity is designed to contain different join variants
"in one artifact. There, you can comment in/out code sections to
"check out the individual join variants. Therefore, the result of
"the following SELECT statement depends on which section you have
"commented in in the CDS view entity.
SELECT *
FROM zdemo_abap_cds_ve_joins
ORDER BY carrid
INTO TABLE @DATA(cds_joins).
output->display( input = cds_joins name = `cds_joins` ).
**********************************************************************
output->next_section( `4) Excursion: ABAP SQL and joins` ).
"The following ABAP SQL SELECT statements are intended to reproduce
"the different joins that are performed by the CDS view entity.
"Inner, left and right outer, and cross joins are covered. The data
"sources for the SELECT statements are the database tables.
"Note:
"- The prefix ~ is used in the ABAP SQL statements instead of . in
" the CDS view entity.
"- To demonstrate the handling of null values, some SELECT statements
" contain the coalesce function and CASE expressions similar to the
" CDS view entity.
output->display( `---------- Inner join ----------` ).
SELECT _carr~carrid,
_carr~carrname,
_flsch_in~cityfrom AS cityfr_in,
_flsch_in~cityto AS cityto_in
FROM zdemo_abap_carr AS _carr
INNER JOIN zdemo_abap_flsch AS _flsch_in
ON _carr~carrid = _flsch_in~carrid
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_inner_join).
output->display( input = sql_inner_join name = `sql_inner_join` ).
output->display( `---------- Left outer join ----------` ).
SELECT _carr~carrid,
_carr~carrname,
_flsch_lo~cityfrom AS cityfr_lo,
coalesce( _flsch_lo~cityto, '???' ) AS cityto_lo
FROM zdemo_abap_carr AS _carr
LEFT OUTER JOIN zdemo_abap_flsch AS _flsch_lo
ON _carr~carrid = _flsch_lo~carrid
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_left_outer_join).
output->display( input = sql_left_outer_join name = `sql_left_outer_join` ).
output->display( `---------- Right outer join ----------` ).
SELECT _carr~carrid,
_carr~carrname,
CASE WHEN _carr~url IS NOT NULL THEN _carr~url
ELSE '!!!'
END AS url_ro,
_flsch_ro~cityfrom AS cityfr_ro,
_flsch_ro~cityto AS cityto_ro
FROM zdemo_abap_carr AS _carr
RIGHT OUTER JOIN zdemo_abap_flsch AS _flsch_ro
ON _carr~carrid = _flsch_ro~carrid
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_right_outer_join).
output->display( input = sql_right_outer_join name = `sql_right_outer_join` ).
output->display( `---------- Cross join ----------` ).
SELECT _carr~carrid,
_carr~carrname,
_flsch_cr~cityfrom AS cityfr_cr,
_flsch_cr~cityto AS cityto_cr
FROM zdemo_abap_carr AS _carr
CROSS JOIN zdemo_abap_flsch AS _flsch_cr
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_cross_join).
output->display( input = sql_cross_join name = `sql_cross_join` ).
"Just a check what join example is currently commented in
IF cds_joins = sql_inner_join.
output->display( `In the example CDS view entity, the inner join example is commented in.` ).
ELSEIF cds_joins = sql_left_outer_join.
output->display( `In the example CDS view entity, the left outer join example is commented in.` ).
ELSEIF cds_joins = sql_right_outer_join.
output->display( `In the example CDS view entity, the right outer join example is commented in.` ).
ELSEIF cds_joins = sql_cross_join.
output->display( `In the example CDS view entity, the cross join example is commented in.` ).
ELSE.
output->display( `In the example CDS view entity, there is some other code present.` ).
ENDIF.
**********************************************************************
output->next_section( `Associations` ).
output->display( `5) Selecting data from a CDS view that contains associations` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved. The sample CDS view entity
"contains multiple associations.
"Some fields of some associations are used in the element list of the
"CDS view entity. This data is included in the result set. Some
"associations are exposed but no fields of those associations are
"included in the element list. Therefore, no join is instantiated on
"the database and no data from these exposed assocations is included
"in the result set.
SELECT *
FROM zdemo_abap_cds_ve_assoc
ORDER BY carrier
INTO TABLE @DATA(assoc).
output->display( input = assoc name = `assoc` ).
**********************************************************************
output->next_section( `Using exposed associations in ABAP SQL statements: ...` ).
"The following examples use path expressions to access the association
"targets of exposed associations.
output->display( `6) ... SELECT clause` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. The statement uses an exposed association.
"The SELECT list contains fields from the exposed association. Only in
"this case (when a consumer, such as an ABAP SQL statement, requests
"data) is the join instantiated on the database.
"Note:
"- No attributes are specified for the path expression (attributes
" are covered in examples further down). In particular, a join type is
" not explicitly specified. In such a case, the join type depends on
" the place where the path expression is used. Since the path expression
" is used in the SELECT list of an ABAP SQL SELECT statement (where
" fields are specified), a LEFT OUTER JOIN is used by default.
"- The coalesce function is included for a field to handle null values.
SELECT carrier,
\_carr3-carrname,
coalesce( \_carr3-url, '###' ) AS cityto_lo
FROM zdemo_abap_cds_ve_assoc
ORDER BY carrier
INTO TABLE @DATA(assoc_exp_select).
output->display( input = assoc_exp_select name = `assoc_exp_select` ).
**********************************************************************
output->next_section( `7) ... FROM clause` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. All data is retrieved.
"In this case, an exposed association is used in the FROM clause.
"Note:
"- No join type is explicitly specified. As mentioned above, the
" position of the path expression is important. In this case (when
" used in the FROM clause), an INNER JOIN is used by default.
"- You can open the data preview for the CDS view entity used and
" compare the result set with the output here. Due to the inner
" join, non-existent 'carrid' values in the association target are
" not contained in the result set.
SELECT *
FROM zdemo_abap_cds_ve_assoc\_carr3 AS _exp
ORDER BY carrid
INTO TABLE @DATA(assoc_exp_from).
output->display( input = assoc_exp_from name = `assoc_exp_from` ).
"The following ABAP SQL SELECT statement is intended to reproduce
"the data retrieval as above.
"The statement uses the same CDS view entity as data source that
"is used by the CDS view entity above as data source.
"An inner join is performed on a database table (the _carr3
"association from above has this table defined as the association
"target in the CDS view entity) since the inner join is used by
"default above so as to reproduce the effect. The result set
"should be the same as above.
SELECT _carr~mandt,
_carr~carrid,
_carr~carrname,
_carr~currcode,
_carr~url
FROM zdemo_abap_cds_ve_assoc_e AS _cds
JOIN zdemo_abap_carr AS _carr ON _cds~carrid = _carr~carrid
ORDER BY _carr~carrid
INTO TABLE @DATA(sql_repr).
output->display( input = sql_repr name = `sql_repr` ).
IF sql_repr = assoc_exp_from.
output->display( `The result sets are the same.` ).
ELSE.
output->display( `The result sets are differrent.` ).
ENDIF.
**********************************************************************
output->next_section( `8) ... Specifying attributes` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. The statement uses an exposed association.
"The SELECT list contains a path expression that is specified with
"an attribute.
"Note:
"- Cardinality, join types, and filter conditions can be used as
" attributes.
"- In the example, only the cardinality is specified.
"- The cardinality can be specified to prevent syntax warnings/errors
" in cases where the cardinality of the association does not match
" the way it is used in a path expression.
"- The example does not explicitly specify a join type. As mentioned
" above, if not explicitly specified, the join type depends on where
" the path expression is used. Here, a column is specified in the
" SELECT list. This means that a LEFT OUTER JOIN is used by default.
"- The result set should contain an entry for 'UA' having an initial
" value for 'fldate'.
SELECT carrid,
connid,
cityfrom,
cityto,
"Without specifying the cardinality, the following warning
"occurs: Using association "_FLI" can increase the cardinality
"of the results set
"\_fli-fldate AS flightdate
\_fli[ (*) ]-fldate AS flightdate
"The specification above corresponds to the following specification
"that includes an explicit specification of LEFT OUTER
"\_fli[ (*) LEFT OUTER ]-fldate AS flightdate
FROM zdemo_abap_cds_ve_assoc_e
ORDER BY carrid, connid, flightdate
INTO TABLE @DATA(assoc_attr_card).
output->display( input = assoc_attr_card name = `assoc_attr_card` ).
"Specifying the join type explicitly
"- INNER, LEFT/RIGHT OUTER are possible
"- The join type can only be specified together with the cardinality.
"- In the result set of the example, the 'UA' entry should not be
" contained.
SELECT carrid,
connid,
cityfrom,
cityto,
\_fli[ (*) INNER ]-fldate AS flightdate
FROM zdemo_abap_cds_ve_assoc_e
ORDER BY carrid, connid, flightdate
INTO TABLE @DATA(assoc_attr_joty).
output->display( input = assoc_attr_joty name = `assoc_attr_joty` ).
"Specifying conditions
"- Filter conditions can be specified for the current association
"- The addition WHERE is optional in cases where the filter condition
" is the only attribute specified in the square brackets.
"- When the association is instantiated as a join, the filter condition
" is transformed into an extended condition for the join.
"- In the example, a specific 'carrid' value is filtered for. LEFT OUTER
" is specified as join type explicitly. Not specifying the join type here
" has the same effect. The 'fldate' value is only retrieved for 'DL'
" entries. The other ones have initial values.
SELECT carrid,
connid,
cityfrom,
cityto,
\_fli[ (*) LEFT OUTER WHERE carrid = 'DL' ]-fldate AS flightdate
"The following has the same effect in this example
"\_fli[ (*) WHERE carrid = 'DL' ]-fldate as flightdate
FROM zdemo_abap_cds_ve_assoc_e
ORDER BY carrid, connid, flightdate
INTO TABLE @DATA(assoc_attr_where).
output->display( input = assoc_attr_where name = `assoc_attr_where` ).
**********************************************************************
output->next_section( `9) ... WHERE clause` ).
"The following ABAP SQL SELECT statement uses a CDS view entity as
"the data source. The statement uses an exposed association.
"The SELECT list and the WHERE clause contain a path expression.
SELECT carrid,
connid,
countryfr,
countryto,
\_carr_exp-carrname
FROM zdemo_abap_cds_ve_assoc_e
WHERE \_carr_exp-carrid LIKE 'A_'
ORDER BY carrid, connid
INTO TABLE @DATA(assoc_exp_where).
output->display( input = assoc_exp_where name = `assoc_exp_where` ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_CDS_VE</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: CDS view entities</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,27 @@
CLASS local_class DEFINITION.
PUBLIC SECTION.
METHODS: constructor IMPORTING txt TYPE string,
double IMPORTING int TYPE
REF TO i RETURNING VALUE(res) TYPE i.
DATA: timestamp TYPE string,
text TYPE string.
CLASS-DATA: no_of_instances TYPE i READ-ONLY.
ENDCLASS.
CLASS local_class IMPLEMENTATION.
METHOD constructor.
"Number of instances of the class are counted.
no_of_instances = no_of_instances + 1.
"Set a time stamp.
DATA: ts TYPE timestampl.
GET TIME STAMP FIELD ts.
timestamp = |{ ts TIMESTAMP = SPACE }|.
text = |{ txt }, { sy-uname }.|.
ENDMETHOD.
METHOD double.
res = int->* * 2.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_CONSTRUCTOR_EXPR</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Constructor expressions</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,160 @@
***********************************************************************
*
* Class for ABAP cheat sheet examples designed to support displaying
* output in the ADT console
*
* -------------------------- NOTE -------------------------------------
* This helper class is only used to display complex types contained in
* the example classes of the ABAP cheat sheets in older ABAP releases.
* In newer ABAP releases, this helper class is, in principle, not needed.
* You can use the write method of the classrun interface directly and
* display all types.
*
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">Class supporting ABAP cheat sheet examples</p>
"! The class supports displaying output of the ABAP cheat sheet examples in the ADT console.
CLASS zcl_demo_abap_display DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
METHODS:
constructor
IMPORTING
io_out TYPE REF TO if_oo_adt_classrun_out,
display
IMPORTING
input TYPE data
name TYPE string DEFAULT ``
RETURNING
VALUE(output) TYPE string,
next_section
IMPORTING
heading TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
DATA:
mo_out TYPE REF TO if_oo_adt_classrun_out,
offset TYPE i.
CONSTANTS nl TYPE string VALUE cl_abap_char_utilities=>newline.
ENDCLASS.
CLASS zcl_demo_abap_display IMPLEMENTATION.
METHOD constructor.
mo_out = io_out.
ENDMETHOD.
METHOD display.
"Checking data type
DATA(type_descr) = cl_abap_typedescr=>describe_by_data( input ).
CASE type_descr->kind.
WHEN cl_abap_typedescr=>kind_struct.
DATA(struct_descr) = CAST cl_abap_structdescr( type_descr ).
"Checking for complex output
IF struct_descr->struct_kind = cl_abap_structdescr=>structkind_nested
OR line_exists( struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_table ] )
OR line_exists( struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_dref ] )
OR line_exists( struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_oref ] ).
DATA(to_be_serialized) = abap_true.
ELSE.
DATA(display) = mo_out->get( data = input name = name ).
ENDIF.
WHEN cl_abap_typedescr=>kind_table.
DATA(table_descr) = CAST cl_abap_tabledescr( type_descr ).
TRY.
DATA(line_type_struct_descr) = CAST cl_abap_structdescr( table_descr->get_table_line_type( ) ).
"Checking for complex output
IF line_type_struct_descr->struct_kind = cl_abap_structdescr=>structkind_nested
OR line_exists( line_type_struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_table ] )
OR line_exists( line_type_struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_dref ] )
OR line_exists( line_type_struct_descr->components[ type_kind = cl_abap_typedescr=>typekind_oref ] ).
to_be_serialized = abap_true.
ELSE.
display = mo_out->get( data = input name = name ).
ENDIF.
CATCH cx_sy_move_cast_error.
to_be_serialized = abap_true.
ENDTRY.
WHEN cl_abap_typedescr=>kind_class.
to_be_serialized = abap_true.
WHEN cl_abap_typedescr=>kind_intf.
to_be_serialized = abap_true.
WHEN cl_abap_typedescr=>kind_elem.
display = mo_out->get( data = COND string( WHEN name IS INITIAL THEN input ELSE `"` && name && `":` && nl && input ) ).
WHEN cl_abap_typedescr=>kind_ref.
"Checking for data references
IF type_descr->type_kind = cl_abap_typedescr=>typekind_dref.
"Checking type of dereferenced data object
DATA(type_check_dref) = cl_abap_typedescr=>describe_by_data( input->* ).
"Processing (non-)elementary types
IF type_check_dref->kind = type_descr->kind_elem.
display = mo_out->get( data = COND string( WHEN name IS INITIAL THEN input->* ELSE `"` && name && `":` && nl && input->* ) ).
ELSE.
to_be_serialized = abap_true.
ENDIF.
ELSE.
to_be_serialized = abap_true.
ENDIF.
ENDCASE.
"Processing complex output by serializiation
FIND SUBSTRING `Data type not yet supported ...` IN display MATCH OFFSET DATA(off) MATCH LENGTH DATA(len).
IF sy-subrc = 0 OR to_be_serialized = abap_true.
"ABAP JSON serializing
DATA(json) = /ui2/cl_json=>serialize( data = input
pretty_name = /ui2/cl_json=>pretty_mode-low_case
compress = abap_false
hex_as_base64 = abap_false
format_output = abap_true
assoc_arrays = abap_true
assoc_arrays_opt = abap_true ).
IF to_be_serialized = abap_true.
IF name IS INITIAL.
REPLACE PCRE `^` IN display WITH json && nl.
ELSE.
REPLACE PCRE `^` IN display WITH `"` && name && `":` && nl && json && nl.
ENDIF.
"substring found
ELSE.
IF name IS INITIAL.
REPLACE SECTION OFFSET off LENGTH len OF display WITH json && nl.
ELSE.
REPLACE SECTION OFFSET off LENGTH len OF display WITH `"` && name && `":` && nl && json && nl.
ENDIF.
ENDIF.
mo_out->write( display && nl ).
ELSE.
mo_out->write( display && nl ).
ENDIF.
ENDMETHOD.
METHOD next_section.
mo_out->write( `_________________________________________________________________________________`
&& nl
&& nl
&& heading
&& nl
&& nl ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_DISPLAY</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Class supporting ABAP cheat sheet examples</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_DTYPE_DOBJ</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP Cheat Sheet: Data Types and Data Objects</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,437 @@
CLASS lcl_det_at_runtime DEFINITION.
PUBLIC SECTION.
CLASS-DATA: string1 TYPE string,
string2 TYPE string,
string3 TYPE string,
dyn_meth_call_result TYPE string.
TYPES: type_p TYPE p LENGTH 8 DECIMALS 2, "elementary type
type_struc TYPE zdemo_abap_carr, "structure type
"internal table type
type_itab TYPE SORTED TABLE OF zdemo_abap_flsch WITH NON-UNIQUE KEY carrid connid "primary key
WITH UNIQUE SORTED KEY cities COMPONENTS cityfrom cityto, "secondary key
type_ref TYPE REF TO lcl_det_at_runtime. "reference type
TYPES: BEGIN OF struc_builtin,
builtin_type TYPE c LENGTH 10,
len TYPE i,
dec TYPE i,
END OF struc_builtin.
TYPES: BEGIN OF struc_dyn,
table TYPE string,
select_list TYPE string,
where_clause TYPE string_table,
order_by TYPE string,
target TYPE REF TO data,
rows TYPE i,
END OF struc_dyn.
CLASS-METHODS:
get_dyn_table_name RETURNING VALUE(tab) TYPE string,
get_dyn_dobj RETURNING VALUE(dobj) TYPE string,
get_dyn_field RETURNING VALUE(field) TYPE string,
get_dyn_select_list RETURNING VALUE(list) TYPE string,
get_dyn_where_clause RETURNING VALUE(clause_tab) TYPE string_table,
get_random_type RETURNING VALUE(random_type) TYPE string,
get_builtin_type RETURNING VALUE(builtin_type) TYPE struc_builtin,
get_dyn_class_meth EXPORTING cl TYPE string
meth TYPE string
ptab TYPE abap_parmbind_tab,
get_dyn_syntax_elements RETURNING VALUE(syntax_elements) TYPE struc_dyn,
fill_string.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS lcl_det_at_runtime IMPLEMENTATION.
METHOD get_dyn_table_name.
"Providing DDIC table names in a string table to be selected from.
DATA(flight_tables) = VALUE string_table(
( `ZDEMO_ABAP_CARR` ) ( `ZDEMO_ABAP_FLSCH` ) ( `ZDEMO_ABAP_FLI` ) ).
"Getting random number to determine the table index at runtime.
DATA(idx) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = lines( flight_tables ) )->get_next( ).
"Returning parameter to receive the random table name.
tab = VALUE #( flight_tables[ idx ] DEFAULT `ZDEMO_ABAP_CARR` ).
ENDMETHOD.
METHOD get_builtin_type.
"Providing the names of built-in types in a string table to be selected from.
TYPES tabtyp TYPE TABLE OF struc_builtin-builtin_type WITH EMPTY KEY.
DATA(built) = VALUE tabtyp(
( 'd' )
( 'decfloat16' )
( 'decfloat34' )
( 'f' )
( 'i' )
( 'string' )
( 't' )
( 'xstring' )
( 'c' )
( 'n' )
( 'x' )
( 'p' )
).
"Getting random number to determine the table index at runtime
DATA(idx) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = lines( built ) )->get_next( ).
"Providing the returning parameter with a random type name
TRY.
builtin_type = VALUE #( builtin_type = built[ idx ] dec = idx len = idx ).
CATCH cx_sy_itab_line_not_found.
builtin_type = VALUE #( builtin_type = `p` dec = 5 len = 5 ).
ENDTRY.
ENDMETHOD.
METHOD get_dyn_dobj.
"Providing strings with demo content
string1 = |Hallo, { sy-uname }. | &&
|This is string1.|.
string2 = |Hallo, { sy-uname }. | &&
|This is string2.|.
string3 = |Hallo, { sy-uname }. | &&
|This is string3.|.
"Filling table with data object names
DATA(str_tab) = VALUE string_table(
( `STRING1` ) ( `STRING2` ) ( `STRING3` ) ).
"Getting random number to determine the table index at runtime
DATA(idx) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = lines( str_tab ) )->get_next( ).
"Providing the returning parameter with a random data object name
dobj = VALUE #( str_tab[ idx ] DEFAULT |Hallo, { sy-uname }. This is a string.| ).
ENDMETHOD.
METHOD get_dyn_field.
"Getting list of components of DDIC type zdemo_abap_carr
DATA(comp) = CAST cl_abap_structdescr(
cl_abap_typedescr=>describe_by_name(
'ZDEMO_ABAP_CARR' )
)->components.
"Getting random number to determine the table index at runtime;
"starting from 2 to exclude MANDT field
DATA(idx) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 2
max = lines( comp ) )->get_next( ).
"Providing the returning parameter with a random component name
field = VALUE #( comp[ idx ]-name DEFAULT `CARRID` ).
ENDMETHOD.
METHOD get_dyn_select_list.
"Providing SELECT lists in a string table to be selected from
DATA sel_list_tab TYPE string_table.
sel_list_tab = VALUE #(
( `CARRID, CONNID, COUNTRYFR, COUNTRYTO` )
( `CARRID, CONNID, CITYFROM, CITYTO` )
( `CARRID, CONNID, AIRPFROM, AIRPTO` )
( `CARRID, CONNID, AIRPFROM, AIRPTO, ` &&
`FLTIME, DEPTIME, ARRTIME, DISTANCE` )
).
"Getting random number to determine the table index at runtime
DATA(idx) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = lines( sel_list_tab ) )->get_next( ).
"Providing the returning parameter with a random SELECT list
list = VALUE #( sel_list_tab[ idx ] DEFAULT `CARRID, CONNID, COUNTRYFR, COUNTRYTO` ).
ENDMETHOD.
METHOD get_dyn_where_clause.
"Providing WHERE clauses in a table to be selected from
DATA: BEGIN OF where_struc,
where_clause_tab TYPE string_table,
END OF where_struc.
DATA where_itab LIKE TABLE OF where_struc WITH EMPTY KEY.
where_itab = VALUE #(
( where_clause_tab = VALUE #( ( `CARRID = 'LH'` )
( `OR CARRID = 'AA'` ) ) )
( where_clause_tab = VALUE #( ( `CONNID BETWEEN 0 AND 300` ) ) )
( where_clause_tab = VALUE #( ( `CITYFROM LIKE '%FRA%'` ) ) )
( where_clause_tab =
VALUE #( ( `DISTANCE > 500 AND DISTID = 'KM'` ) ) ) ).
"Getting random number to determine the table index at runtime
DATA(idx) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = lines( where_itab ) )->get_next( ).
"Providing the returning parameter with a random WHERE clause
clause_tab = VALUE #( where_itab[ idx ]-where_clause_tab DEFAULT VALUE #( ( `CARRID = 'LH'` ) ( `OR CARRID = 'AA'` ) ) ).
ENDMETHOD.
METHOD get_random_type.
"Providing names of classes in a string table to be selected from
"In this example, some types are defined in the public section
"of a local class. The class name is added here since the names
"are used in the global class.
DATA(str_tab) = VALUE string_table(
( `LCL_DET_AT_RUNTIME=>TYPE_P` )
( `LCL_DET_AT_RUNTIME=>TYPE_STRUC` )
( `LCL_DET_AT_RUNTIME=>TYPE_ITAB` )
( `LCL_DET_AT_RUNTIME=>TYPE_REF` )
( `LCL_DET_AT_RUNTIME` )
( `IF_OO_ADT_CLASSRUN` )
).
"Getting random number to determine the table index at runtime
DATA(idx) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = lines( str_tab ) )->get_next( ).
"Providing the returning parameter with a random type name
random_type = VALUE #( str_tab[ idx ] DEFAULT `LCL_DET_AT_RUNTIME=>TYPE_STRUC` ).
ENDMETHOD.
METHOD get_dyn_class_meth.
"Providing class names in a string table to be selected from
DATA(class_tab) = VALUE string_table(
( `LCL_DEMO1` )
( `LCL_DEMO2` ) ).
"Getting random number to determine the table index at runtime
DATA(idx) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = lines( class_tab ) )->get_next( ).
"Provide the exporting parameter with the random class name
cl = VALUE #( class_tab[ idx ] DEFAULT `LCL_DEMO1` ).
"Getting method names using RTTI
DATA(methods) = CAST cl_abap_classdescr( cl_abap_typedescr=>describe_by_name( cl ) )->methods.
"Getting random number to determine the table index at runtime
idx = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = lines( methods ) )->get_next( ).
"Provide the exporting parameter with the random method name
meth = VALUE #( methods[ idx ]-name DEFAULT `METH_A` ).
"Data reference objects for the value parameter in the parameter table
DATA(ref_imp) = NEW string( `hi` ).
DATA(ref_exp) = NEW string( `hallo` ).
DATA(ref_ch) = NEW string( `salut` ).
DATA(ref_ret) = NEW string( `ciao` ).
"Filling the parameter tables
"Note: If the method signature has an importing parameter,
"it must be specified as exporting parameter here.
"Same is true for the exporting parameter in the signature
"that must be specified as importing parameter.
CASE meth.
WHEN `METH_A`.
ptab = VALUE #( ( name = 'A'
kind = cl_abap_objectdescr=>exporting
value = ref_exp )
( name = 'B'
kind = cl_abap_objectdescr=>importing
value = ref_imp ) ).
WHEN `METH_B`.
ptab = VALUE #( ( name = 'C'
kind = cl_abap_objectdescr=>changing
value = ref_ch )
( name = 'D'
kind = cl_abap_objectdescr=>returning
value = ref_ret ) ).
WHEN `METH_C`.
ptab = VALUE #( ( name = 'E'
kind = cl_abap_objectdescr=>exporting
value = ref_exp )
( name = 'F'
kind = cl_abap_objectdescr=>importing
value = ref_imp ) ).
WHEN `METH_D`.
ptab = VALUE #( ( name = 'G'
kind = cl_abap_objectdescr=>changing
value = ref_ch )
( name = 'H'
kind = cl_abap_objectdescr=>returning
value = ref_ret ) ).
ENDCASE.
ENDMETHOD.
METHOD fill_string.
dyn_meth_call_result = |Hallo { sy-uname }. The string was filled at { utclong_current( ) }.|.
ENDMETHOD.
METHOD get_dyn_syntax_elements.
"FROM clause
DATA(flight_tables) = VALUE string_table(
( `ZDEMO_ABAP_CARR` ) ( `ZDEMO_ABAP_FLSCH` ) ( `ZDEMO_ABAP_FLI` ) ).
"Getting random number to determine the table index at runtime.
DATA(idx_table) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( )
min = 1
max = lines( flight_tables ) )->get_next( ).
syntax_elements-table = VALUE #( flight_tables[ idx_table ] DEFAULT `ZDEMO_ABAP_CARR` ).
"SELECT list
DATA(comp) = CAST cl_abap_structdescr(
cl_abap_typedescr=>describe_by_name( syntax_elements-table ) )->components.
"At least 3 components
DATA(idx_comp) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( )
min = 3
max = lines( comp ) )->get_next( ).
DELETE comp FROM idx_comp + 1 TO lines( comp ).
LOOP AT comp ASSIGNING FIELD-SYMBOL(<comp>).
syntax_elements-select_list = syntax_elements-select_list && `, ` && <comp>-name.
ENDLOOP.
"Replacing initial comma
REPLACE PCRE `^,\s` IN syntax_elements-select_list WITH ``.
"WHERE clause
"Excluding the client field
DELETE comp WHERE name = 'MANDT'.
"A maximum of 4 fields are to be respected because that is the maximum of possible fields
"available in table zdemo_abap_carr (without the client field)
DATA(idx_where) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( )
min = 1
max = 4 )->get_next( ).
"In the example, the WHERE clause consists of an internal table of type string.
"The clause is set up with fields and only IS NOT INITIAL to be on the safe side for a
"somewhat 'meaningful' clause and in the interest of simplicity.
LOOP AT comp ASSIGNING FIELD-SYMBOL(<where>) TO idx_where.
IF sy-tabix = 1.
APPEND <where>-name && ` IS NOT INITIAL` TO syntax_elements-where_clause.
ELSE.
APPEND `OR ` && <where>-name && ` IS NOT INITIAL` TO syntax_elements-where_clause.
ENDIF.
ENDLOOP.
"ORDER BY clause
DATA(idx_order) = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( )
min = 1
max = lines( comp ) )->get_next( ).
syntax_elements-order_by = VALUE #( comp[ idx_order ]-name DEFAULT `CARRID` ).
"INTO clause
CREATE DATA syntax_elements-target TYPE TABLE OF (syntax_elements-table).
"UP TO ... ROWS
"A minimum of 2 and a maximum of 6 rows are to be retrieved by the SELECT statement
syntax_elements-rows = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( )
min = 2
max = 5 )->get_next( ).
ENDMETHOD.
ENDCLASS.
CLASS lcl_demo1 DEFINITION.
"Note that this is just a demo class with demo methods to work with in the example.
PUBLIC SECTION.
CLASS-METHODS:
meth_a IMPORTING a TYPE string
EXPORTING b TYPE string,
meth_b CHANGING c TYPE string
RETURNING VALUE(d) TYPE string.
ENDCLASS.
CLASS lcl_demo1 IMPLEMENTATION.
METHOD meth_a.
b = |Hallo from meth_a. '{ a }' was input.|.
"Filling an attribute for the output in the global class.
lcl_det_at_runtime=>dyn_meth_call_result = b.
ENDMETHOD.
METHOD meth_b.
c = `#` && c && `#`.
d = |Hallo from meth_b. Actual parameter of changing parameter: '{ c }'|.
"Filling an attribute for the output in the global class.
lcl_det_at_runtime=>dyn_meth_call_result = d.
ENDMETHOD.
ENDCLASS.
CLASS lcl_demo2 DEFINITION.
"Note that this is just a demo class with demo methods to work with in the example.
PUBLIC SECTION.
CLASS-METHODS:
meth_c IMPORTING e TYPE string
EXPORTING f TYPE string,
meth_d CHANGING g TYPE string
RETURNING VALUE(h) TYPE string.
ENDCLASS.
CLASS lcl_demo2 IMPLEMENTATION.
METHOD meth_c.
f = |Hallo from meth_c. '{ e }' was input.|.
"Filling an attribute for the output in the global class.
lcl_det_at_runtime=>dyn_meth_call_result = f.
ENDMETHOD.
METHOD meth_d.
g = `*` && g && `*`.
h = |Hallo from meth_d. Actual parameter of changing parameter: '{ g }'|.
"Filling an attribute for the output in the global class.
lcl_det_at_runtime=>dyn_meth_call_result = h.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_DYNAMIC_PROG</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Dynamic programming</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,711 @@
***********************************************************************
*
* Class for ABAP cheat sheet examples designed to clear and populate
* demo database tables
*
* -------------------------- NOTE -------------------------------------
* The code presented in this class is only meant for supporting the ABAP
* cheat sheets. It is not intended for direct use in a
* production system environment. The code examples in the ABAP cheat
* sheets are primarily intended to provide a better explanation and
* visualization of the syntax and semantics of ABAP statements and not to
* solve concrete programming tasks. For production application programs,
* a dedicated solution should therefore always be worked out for each
* individual case. There is no guarantee for either the correctness or
* the completeness of the code. In addition, there is no legal
* responsibility or liability for possible errors or their consequences
* which occur through the use of the example code.
*
***********************************************************************
"! <p class="shorttext synchronized">Class supporting ABAP cheat sheet examples</p>
"! The class supports the ABAP cheat examples by clearing and populating demo database tables that are used there.
"! The demo database tables contain airline and flight information.
CLASS zcl_demo_abap_flight_tables DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
CLASS-METHODS: clear_dbtabs,
fill_dbtabs.
protected section.
private section.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_FLIGHT_TABLES IMPLEMENTATION.
METHOD clear_dbtabs.
DELETE FROM zdemo_abap_flsch.
DELETE FROM zdemo_abap_carr.
DELETE FROM zdemo_abap_fli.
ENDMETHOD.
METHOD fill_dbtabs.
"Clearing db tables before filling
clear_dbtabs( ).
"Filling db table
MODIFY zdemo_abap_flsch FROM TABLE @( VALUE #(
( carrid = 'AA'
connid = 0017
countryfr = 'US'
cityfrom = 'NEW YORK'
airpfrom = 'JFK'
countryto = 'US'
cityto = 'SAN FRANCISCO'
airpto = 'SFO'
fltime = 361
deptime = '110000'
arrtime = '140100'
distance = 2572
distid = 'MI'
fltype = ''
period = 0 )
( carrid = 'AA'
connid = 0064
countryfr = 'US'
cityfrom = 'SAN FRANCISCO'
airpfrom = 'SFO'
countryto = 'US'
cityto = 'NEW YORK'
airpto = 'JFK'
fltime = 321
deptime = '090000'
arrtime = '172100'
distance = 2572
distid = 'MI'
fltype = ''
period = 0 )
( carrid = 'AZ'
connid = 0555
countryfr = 'IT'
cityfrom = 'ROME'
airpfrom = 'FCO'
countryto = 'DE'
cityto = 'FRANKFURT'
airpto = 'FRA'
fltime = 125
deptime = '190000'
arrtime = '210500'
distance = 845
distid = 'MI'
fltype = ''
period = 0 )
( carrid = 'AZ'
connid = 0788
countryfr = 'IT'
cityfrom = 'ROME'
airpfrom = 'FCO'
countryto = 'JP'
cityto = 'TOKYO'
airpto = 'TYO'
fltime = 775
deptime = '120000'
arrtime = '085500'
distance = 6130
distid = 'MI'
fltype = ''
period = 1 )
( carrid = 'AZ'
connid = 0789
countryfr = 'JP'
cityfrom = 'TOKYO'
airpfrom = 'TYO'
countryto = 'IT'
cityto = 'ROME'
airpto = 'FCO'
fltime = 940
deptime = '114500'
arrtime = '192500'
distance = 6130
distid = 'MI'
fltype = ''
period = 0 )
( carrid = 'AZ'
connid = 0790
countryfr = 'IT'
cityfrom = 'ROME'
airpfrom = 'FCO'
countryto = 'JP'
cityto = 'OSAKA'
airpto = 'KIX'
fltime = 815
deptime = '103500'
arrtime = '081000'
distance = 6030
distid = 'MI'
fltype = 'X'
period = 1 )
( carrid = 'DL'
connid = 0106
countryfr = 'US'
cityfrom = 'NEW YORK'
airpfrom = 'JFK'
countryto = 'DE'
cityto = 'FRANKFURT'
airpto = 'FRA'
fltime = 475
deptime = '193500'
arrtime = '093000'
distance = 3851
distid = 'MI'
fltype = ''
period = 1 )
( carrid = 'DL'
connid = 1699
countryfr = 'US'
cityfrom = 'NEW YORK'
airpfrom = 'JFK'
countryto = 'US'
cityto = 'SAN FRANCISCO'
airpto = 'SFO'
fltime = 382
deptime = '171500'
arrtime = '203700'
distance = 2572
distid = 'MI'
fltype = ''
period = 0 )
( carrid = 'DL'
connid = 1984
countryfr = 'US'
cityfrom = 'SAN FRANCISCO'
airpfrom = 'SFO'
countryto = 'US'
cityto = 'NEW YORK'
airpto = 'JFK'
fltime = 325
deptime = '100000'
arrtime = '182500'
distance = 2572
distid = 'MI'
fltype = ''
period = 0 )
( carrid = 'JL'
connid = 0407
countryfr = 'JP'
cityfrom = 'TOKYO'
airpfrom = 'NRT'
countryto = 'DE'
cityto = 'FRANKFURT'
airpto = 'FRA'
fltime = 725
deptime = '133000'
arrtime = '173500'
distance = 9100
distid = 'KM'
fltype = ''
period = 0 )
( carrid = 'JL'
connid = 0408
countryfr = 'DE'
cityfrom = 'FRANKFURT'
airpfrom = 'FRA'
countryto = 'JP'
cityto = 'TOKYO'
airpto = 'NRT'
fltime = 675
deptime = '202500'
arrtime = '154000'
distance = 9100
distid = 'KM'
fltype = 'X'
period = 1 )
( carrid = 'LH'
connid = 0400
countryfr = 'DE'
cityfrom = 'FRANKFURT'
airpfrom = 'FRA'
countryto = 'US'
cityto = 'NEW YORK'
airpto = 'JFK'
fltime = 444
deptime = '101000'
arrtime = '113400'
distance = 6162
distid = 'KM'
fltype = ''
period = 0 )
( carrid = 'LH'
connid = 0401
countryfr = 'US'
cityfrom = 'NEW YORK'
airpfrom = 'JFK'
countryto = 'DE'
cityto = 'FRANKFURT'
airpto = 'FRA'
fltime = 435
deptime = '183000'
arrtime = '074500'
distance = 6162
distid = 'KM'
fltype = ''
period = 1 )
( carrid = 'LH'
connid = 0402
countryfr = 'DE'
cityfrom = 'FRANKFURT'
airpfrom = 'FRA'
countryto = 'US'
cityto = 'NEW YORK'
airpto = 'JFK'
fltime = 455
deptime = '133000'
arrtime = '150500'
distance = 6162
distid = 'KM'
fltype = 'X'
period = 0 )
( carrid = 'LH'
connid = 2402
countryfr = 'DE'
cityfrom = 'FRANKFURT'
airpfrom = 'FRA'
countryto = 'DE'
cityto = 'BERLIN'
airpto = 'SXF'
fltime = 65
deptime = '103000'
arrtime = '113500'
distance = 555
distid = 'KM'
fltype = ''
period = 0 ) ) ).
"Filling db table
MODIFY zdemo_abap_carr FROM TABLE @( VALUE #(
( carrid = 'AA'
carrname = 'American Airlines'
currcode = 'USD'
url = 'http://www.aa.com' )
( carrid = 'LH'
carrname = 'Lufthansa'
currcode = 'EUR'
url = 'http://www.lufthansa.com' )
( carrid = 'JL'
carrname = 'Japan Airlines'
currcode = 'JPY'
url = 'http://www.jal.co.jp' )
( carrid = 'DL'
carrname = 'Delta Airlines'
currcode = 'USD'
url = 'http://www.delta-air.com' )
( carrid = 'AZ'
carrname = 'ITA Airways'
currcode = 'EUR'
url = 'http://www.ita-airways.com' ) ) ).
"Filling db table
MODIFY zdemo_abap_fli FROM TABLE @( VALUE #(
( carrid = 'AA'
connid = 0017
fldate = '20230923'
price = '464.35'
currency = 'USD'
planetype = '747-400'
seatsmax = 385
seatsocc = 369
paymentsum = '191993.87'
seatsmax_b = 31
seatsocc_b = 31
seatsmax_f = 21
seatsocc_f = 19 )
( carrid = 'AA'
connid = 0017
fldate = '20230929'
price = '464.35'
currency = 'USD'
planetype = '747-400'
seatsmax = 385
seatsocc = 372
paymentsum = '193537.52'
seatsmax_b = 31
seatsocc_b = 30
seatsmax_f = 21
seatsocc_f = 20 )
( carrid = 'AA'
connid = 0017
fldate = '20231111'
price = '464.35'
currency = 'USD'
planetype = '747-400'
seatsmax = 385
seatsocc = 374
paymentsum = '193651.77'
seatsmax_b = 31
seatsocc_b = 29
seatsmax_f = 21
seatsocc_f = 21 )
( carrid = 'AA'
connid = 0064
fldate = '20220131'
price = '464.35'
currency = 'USD'
planetype = 'A340-600'
seatsmax = 330
seatsocc = 313
paymentsum = '168469.88'
seatsmax_b = 30
seatsocc_b = 30
seatsmax_f = 20
seatsocc_f = 19 )
( carrid = 'AA'
connid = 0064
fldate = '20220215'
price = '464.35'
currency = 'USD'
planetype = 'A340-600'
seatsmax = 330
seatsocc = 157
paymentsum = '84846.15'
seatsmax_b = 30
seatsocc_b = 15
seatsmax_f = 20
seatsocc_f = 10 )
( carrid = 'AZ'
connid = 0555
fldate = '20230721'
price = '226.41'
currency = 'EUR'
planetype = 'A319-100'
seatsmax = 120
seatsocc = 114
paymentsum = '26519.75'
seatsmax_b = 8
seatsocc_b = 8
seatsmax_f = 8
seatsocc_f = 8 )
( carrid = 'AZ'
connid = 0555
fldate = '20230728'
price = '226.41'
currency = 'EUR'
planetype = 'A319-100'
seatsmax = 120
seatsocc = 115
paymentsum = '16695.50'
seatsmax_b = 8
seatsocc_b = 8
seatsmax_f = 8
seatsocc_f = 8 )
( carrid = 'AZ'
connid = 0788
fldate = '20230922'
price = '1071.41'
currency = 'EUR'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 456
paymentsum = '548722.20'
seatsmax_b = 30
seatsocc_b = 30
seatsmax_f = 20
seatsocc_f = 20 )
( carrid = 'AZ'
connid = 0788
fldate = '20230722'
price = '1071.41'
currency = 'EUR'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 455
paymentsum = '544674.30'
seatsmax_b = 30
seatsocc_b = 28
seatsmax_f = 20
seatsocc_f = 20 )
( carrid = 'AZ'
connid = 0789
fldate = '20231025'
price = '1071.41'
currency = 'EUR'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 455
paymentsum = '545704.30'
seatsmax_b = 30
seatsocc_b = 30
seatsmax_f = 20
seatsocc_f = 19 )
( carrid = 'AZ'
connid = 0789
fldate = '20230221'
price = '1071.41'
currency = 'EUR'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 459
paymentsum = '549226.90'
seatsmax_b = 30
seatsocc_b = 30
seatsmax_f = 20
seatsocc_f = 20 )
( carrid = 'AZ'
connid = 0790
fldate = '20231228'
price = '1055.41'
currency = 'EUR'
planetype = '747-400'
seatsmax = 385
seatsocc = 370
paymentsum = '462373.86'
seatsmax_b = 31
seatsocc_b = 30
seatsmax_f = 21
seatsocc_f = 21 )
( carrid = 'AZ'
connid = 0790
fldate = '20231201'
price = '1055.41'
currency = 'EUR'
planetype = '747-400'
seatsmax = 385
seatsocc = 367
paymentsum = '463661.64'
seatsmax_b = 31
seatsocc_b = 31
seatsmax_f = 21
seatsocc_f = 21 )
( carrid = 'DL'
connid = 0106
fldate = '20230209'
price = '652.42'
currency = 'USD'
planetype = 'A340-600'
seatsmax = 330
seatsocc = 178
paymentsum = '136750.33'
seatsmax_b = 30
seatsocc_b = 17
seatsmax_f = 20
seatsocc_f = 10 )
( carrid = 'DL'
connid = 0106
fldate = '20240102'
price = '652.42'
currency = 'USD'
planetype = 'A340-600'
seatsmax = 330
seatsocc = 16
paymentsum = '12892.33'
seatsmax_b = 30
seatsocc_b = 2
seatsmax_f = 20
seatsocc_f = 10 )
( carrid = 'DL'
connid = 1699
fldate = '20230921'
price = '464.35'
currency = 'USD'
planetype = '767-200'
seatsmax = 260
seatsocc = 250
paymentsum = '126636.91'
seatsmax_b = 21
seatsocc_b = 20
seatsmax_f = 11
seatsocc_f = 11 )
( carrid = 'DL'
connid = 1699
fldate = '20230511'
price = '464.35'
currency = 'USD'
planetype = '767-200'
seatsmax = 260
seatsocc = 251
paymentsum = '126493.06'
seatsmax_b = 21
seatsocc_b = 20
seatsmax_f = 11
seatsocc_f = 11 )
( carrid = 'DL'
connid = 1984
fldate = '20230719'
price = '464.35'
currency = 'USD'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 460
paymentsum = '225427.35'
seatsmax_b = 30
seatsocc_b = 29
seatsmax_f = 20
seatsocc_f = 19 )
( carrid = 'DL'
connid = 1984
fldate = '20230213'
price = '464.35'
currency = 'USD'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 458
paymentsum = '225088.83'
seatsmax_b = 30
seatsocc_b = 30
seatsmax_f = 20
seatsocc_f = 19 )
( carrid = 'JL'
connid = 0407
fldate = '20231128'
price = '1102.77'
currency = 'JPY'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 458
paymentsum = '563231.65'
seatsmax_b = 30
seatsocc_b = 27
seatsmax_f = 20
seatsocc_f = 20 )
( carrid = 'JL'
connid = 0407
fldate = '20231019'
price = '1102.77'
currency = 'JPY'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 452
paymentsum = '553552.12'
seatsmax_b = 30
seatsocc_b = 28
seatsmax_f = 20
seatsocc_f = 19 )
( carrid = 'JL'
connid = 0408
fldate = '20231128'
price = '1102.77'
currency = 'JPY'
planetype = '747-400'
seatsmax = 385
seatsocc = 365
paymentsum = '470129.20'
seatsmax_b = 31
seatsocc_b = 28
seatsmax_f = 21
seatsocc_f = 20 )
( carrid = 'JL'
connid = 0408
fldate = '20230123'
price = '1102.77'
currency = 'JPY'
planetype = '747-400'
seatsmax = 385
seatsocc = 372
paymentsum = '487715.90'
seatsmax_b = 31
seatsocc_b = 31
seatsmax_f = 21
seatsocc_f = 20 )
( carrid = 'LH'
connid = 0400
fldate = '20230628'
price = '1184.54'
currency = 'EUR'
planetype = 'A340-600'
seatsmax = 330
seatsocc = 319
paymentsum = '270822.24'
seatsmax_b = 30
seatsocc_b = 30
seatsmax_f = 20
seatsocc_f = 20 )
( carrid = 'LH'
connid = 0400
fldate = '20230323'
price = '1184.54'
currency = 'EUR'
planetype = 'A340-600'
seatsmax = 330
seatsocc = 312
paymentsum = '262597.14'
seatsmax_b = 30
seatsocc_b = 28
seatsmax_f = 20
seatsocc_f = 19 )
( carrid = 'LH'
connid = 0401
fldate = '20231128'
price = '669.20'
currency = 'EUR'
planetype = '767-200'
seatsmax = 260
seatsocc = 246
paymentsum = '195417.72'
seatsmax_b = 21
seatsocc_b = 19
seatsmax_f = 11
seatsocc_f = 10 )
( carrid = 'LH'
connid = 0401
fldate = '20231229'
price = '669.20'
currency = 'EUR'
planetype = '767-200'
seatsmax = 260
seatsocc = 252
paymentsum = '199300.50'
seatsmax_b = 21
seatsocc_b = 19
seatsmax_f = 11
seatsocc_f = 11 )
( carrid = 'LH'
connid = 0402
fldate = '20230617'
price = '669.20'
currency = 'EUR'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 461
paymentsum = '353526.12'
seatsmax_b = 30
seatsocc_b = 29
seatsmax_f = 20
seatsocc_f = 18 )
( carrid = 'LH'
connid = 0402
fldate = '20230313'
price = '669.20'
currency = 'EUR'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 450
paymentsum = '349223.76'
seatsmax_b = 30
seatsocc_b = 29
seatsmax_f = 20
seatsocc_f = 19 )
( carrid = 'LH'
connid = 2402
fldate = '20231028'
price = '245.20'
currency = 'EUR'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 451
paymentsum = '127197.62'
seatsmax_b = 30
seatsocc_b = 29
seatsmax_f = 20
seatsocc_f = 19 )
( carrid = 'LH'
connid = 2402
fldate = '20231223'
price = '245.20'
currency = 'EUR'
planetype = 'A380-800'
seatsmax = 475
seatsocc = 458
paymentsum = '18944.86'
seatsmax_b = 30
seatsocc_b = 30
seatsmax_f = 20
seatsocc_f = 20 ) ) ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_FLIGHT_TABLES</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Class supporting ABAP cheat sheet examples</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_INTERNAL_TABLES</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Internal tables</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,556 @@
*&--------------------------------------------------------------------*
*& Custom exception classes
*&--------------------------------------------------------------------*
CLASS cx_afternoon DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.
CLASS cx_night DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.
*&--------------------------------------------------------------------*
*& Class to demonstrate various method parameters
*& All formal parameters are passed by reference except the
*& returning parameter.
*&--------------------------------------------------------------------*
CLASS lcl_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
"No parameters
hallo_static_ext,
"One importing parameter
powers_of_two IMPORTING i_pow TYPE i,
"Two importing parameters
"Specifying REFERENCE(p) is optional; a formal parameter
"without VALUE(p) or REFERENCE(p) is REFERENCE(p) by default
addition IMPORTING i_add1 TYPE i
REFERENCE(i_add2) TYPE i,
"Two importing parameters, one of them is optional.
addition_optional IMPORTING i_add_mand TYPE i
i_add_opt TYPE i OPTIONAL,
"Importing and exporting parameters
subtraction IMPORTING i_sub1 TYPE i
i_sub2 TYPE i
EXPORTING e_sub_result TYPE i,
"One exporting parameter
exporting_hallo EXPORTING text TYPE string,
"Changing parameter
square_root CHANGING i_sqr TYPE decfloat34,
"Importing and returning parameters
multiplication IMPORTING i_mult1 TYPE i
i_mult2 TYPE i
RETURNING VALUE(r_mult_result) TYPE i,
"Importing and exporting parameters
"for comparing the signature with method 'multiplication'
multiplication_exp_param IMPORTING i_multa TYPE i
i_multb TYPE i
EXPORTING e_mult_result TYPE i,
"Includes RAISING
division IMPORTING i_div1 TYPE i
i_div2 TYPE i
RETURNING VALUE(r_div_result) TYPE decfloat34
RAISING cx_sy_arithmetic_error,
check_daytime IMPORTING time TYPE t
EXPORTING greetings TYPE string
RAISING cx_afternoon cx_night,
"Include parameters with generic types
generic_data IMPORTING i_data TYPE data,
generic_tab IMPORTING i_anytab TYPE ANY TABLE.
CLASS-DATA: calc_result TYPE i,
string TYPE string,
some_data TYPE REF TO data.
ENDCLASS.
CLASS lcl_demo IMPLEMENTATION.
METHOD hallo_static_ext.
string = |Hallo { sy-uname }. | &&
|I'm a static method of class lcl_demo.|.
ENDMETHOD.
METHOD square_root.
i_sqr = sqrt( i_sqr ).
ENDMETHOD.
METHOD powers_of_two.
calc_result = i_pow * i_pow.
ENDMETHOD.
METHOD addition.
calc_result = i_add1 + i_add2.
ENDMETHOD.
METHOD addition_optional.
calc_result = i_add_mand + i_add_opt.
ENDMETHOD.
METHOD subtraction.
e_sub_result = i_sub1 - i_sub2.
ENDMETHOD.
METHOD exporting_hallo.
text = |Hallo { sy-uname }. | && |I'm a static method of class lcl_demo with one exporting parameter.|.
ENDMETHOD.
METHOD multiplication.
r_mult_result = i_mult1 * i_mult2.
ENDMETHOD.
METHOD multiplication_exp_param.
e_mult_result = i_multa * i_multb.
ENDMETHOD.
METHOD division.
CLEAR string.
TRY.
r_div_result = i_div1 / i_div2.
CATCH cx_sy_arithmetic_error INTO DATA(exc).
string = exc->get_text( ).
ENDTRY.
ENDMETHOD.
METHOD check_daytime.
CLEAR string.
"Morning: 5 am to 12 pm
IF time BETWEEN '050001' AND '120000'.
DATA(subrc) = 0.
ENDIF.
"Afternoon: 12 pm to 5 pm.
IF time BETWEEN '120001' AND '170000'.
subrc = 11.
ENDIF.
"Evening 5 pm to 9 pm.
"Commented out on purpose to have a time range for OTHERS :)
"IF time BETWEEN '170001' AND '210000'.
" subrc = 22.
"ENDIF.
"Night: 9 pm to 4 am.
IF time BETWEEN '210001' AND '050000'.
subrc = 33.
ENDIF.
IF subrc <> 0.
CASE subrc.
WHEN 11.
greetings = |Good afternoon.|.
WHEN 33.
greetings = |Good night.|.
WHEN OTHERS.
greetings = |It's neither morning, afternoon or night. | &&
|Hence, wishing you a good evening.|.
ENDCASE.
ELSE.
greetings = |Good morning.|.
ENDIF.
ENDMETHOD.
METHOD generic_data.
"A data reference variable is created that has the type of the
"imported variable. Its content is store in the variable
"some_data in the public section to be able to access the content.
CREATE DATA some_data LIKE i_data.
some_data->* = i_data.
ENDMETHOD.
METHOD generic_tab.
"See implementation of generic_data.
"Here, an internal table is handled.
CREATE DATA some_data LIKE i_anytab.
some_data->* = i_anytab.
ENDMETHOD.
ENDCLASS.
*&--------------------------------------------------------------------*
*& Class to demonstrate basics in the global class
*&--------------------------------------------------------------------*
CLASS local_class DEFINITION.
PUBLIC SECTION.
METHODS: constructor.
DATA: num_inst TYPE i,
uuid TYPE sysuuid_x16,
timestamp TYPE timestampl.
CLASS-DATA: no_of_instances TYPE i READ-ONLY,
num_stat TYPE i VALUE 33.
CONSTANTS: const_number TYPE i VALUE 11.
TYPES type_i TYPE i.
ENDCLASS.
CLASS local_class IMPLEMENTATION.
METHOD constructor.
"Number of instances of the class are counted.
no_of_instances = no_of_instances + 1.
"Set a time stamp.
GET TIME STAMP FIELD timestamp.
"Increase the number.
num_inst = num_inst + 1.
"Get a random UUID.
TRY.
uuid = cl_system_uuid=>create_uuid_x16_static( ) .
CATCH cx_uuid_error.
ENDTRY.
ENDMETHOD.
ENDCLASS.
*&--------------------------------------------------------------------*
*& Class to demonstrate events
*&--------------------------------------------------------------------*
CLASS lcl_events DEFINITION.
PUBLIC SECTION.
DATA: greets TYPE string.
"Events declaration.
EVENTS: morning, afternoon, evening, night.
"Event handler methods
METHODS: morning_greets FOR EVENT morning OF lcl_events,
afternoon_greets FOR EVENT afternoon OF lcl_events,
evening_greets FOR EVENT evening OF lcl_events,
night_greets FOR EVENT night OF lcl_events.
"Method to raise events
METHODS: greetings.
ENDCLASS.
CLASS lcl_events IMPLEMENTATION.
METHOD greetings.
DATA(syst_time) = cl_abap_context_info=>get_system_time( ).
"Morning: 5 am to 12 pm
IF syst_time BETWEEN '050001' AND '120000'.
RAISE EVENT morning.
"Afternoon: 12 pm to 5 pm.
ELSEIF syst_time BETWEEN '120001' AND '170000'.
RAISE EVENT afternoon.
"Evening 5 pm to 9 pm.
ELSEIF syst_time BETWEEN '170001' AND '210000'.
RAISE EVENT evening.
"Night: 9 pm to 5 am.
ELSEIF syst_time BETWEEN '210001' AND '050000'.
RAISE EVENT night.
ENDIF.
ENDMETHOD.
METHOD morning_greets.
greets = |Good morning, { sy-uname }.|.
ENDMETHOD.
METHOD afternoon_greets.
greets = |Good afternoon, { sy-uname }.|.
ENDMETHOD.
METHOD evening_greets.
greets = |Good evening, { sy-uname }.|.
ENDMETHOD.
METHOD night_greets.
greets = |Good night, { sy-uname }.|.
ENDMETHOD.
ENDCLASS.
*&--------------------------------------------------------------------*
*& Class to demonstrate constructors
*&--------------------------------------------------------------------*
CLASS lcl_constructors DEFINITION.
PUBLIC SECTION.
METHODS: constructor IMPORTING num1 TYPE i
num2 TYPE i RAISING cx_sy_zerodivide.
DATA: uuid TYPE sysuuid_x16,
in_div_result TYPE i,
in_text TYPE string.
CLASS-METHODS: class_constructor,
add_1.
CLASS-DATA: no_of_instances TYPE i READ-ONLY,
stat_number TYPE i,
stat_text TYPE string.
ENDCLASS.
CLASS lcl_constructors IMPLEMENTATION.
METHOD constructor.
"Get time stamp.
DATA(ts1) = utclong_current( ).
"Provide message.
in_text = |The instance constructor of the class | &&
|lcl_constructors was called on { ts1 }.|.
"Count number of instances.
no_of_instances = no_of_instances + 1.
"Get random UUID.
TRY.
uuid = cl_system_uuid=>create_uuid_x16_static( ) .
CATCH cx_uuid_error.
ENDTRY.
CLEAR in_div_result.
"Do calculation.
in_div_result = num1 / num2.
ENDMETHOD.
METHOD class_constructor.
"Set a number.
stat_number = 999.
"Get time stamp.
DATA(ts2) = utclong_current( ).
"Provide message.
stat_text = |The static constructor of the class | &&
|lcl_constructors was called on { ts2 } and the | &&
|value for the variable 'stat_number' was set to | &&
|{ stat_number }.|.
ENDMETHOD.
METHOD add_1.
stat_number += 1.
ENDMETHOD.
ENDCLASS.
*&--------------------------------------------------------------------*
*& Classes to demonstrate inheritance, polymorphism and casting
*&--------------------------------------------------------------------*
"Class 1
CLASS lcl_class1 DEFINITION.
PUBLIC SECTION.
"Note: All methods are purposely included in the public section.
"Otherwise, it cannot be called in the demo's main class.
METHODS: constructor IMPORTING i_obj TYPE string OPTIONAL,
get_string RETURNING VALUE(str) TYPE string,
get_obj_name RETURNING VALUE(obj) TYPE string.
PRIVATE SECTION.
DATA: obj_name TYPE string.
ENDCLASS.
CLASS lcl_class1 IMPLEMENTATION.
METHOD constructor.
obj_name = i_obj.
ENDMETHOD.
METHOD get_obj_name.
obj = obj_name.
ENDMETHOD.
METHOD get_string.
str = `Hallo`.
ENDMETHOD.
ENDCLASS.
"Class 2a
CLASS lcl_class2a DEFINITION INHERITING FROM lcl_class1.
PUBLIC SECTION.
METHODS: get_string REDEFINITION,
get_number_2a RETURNING VALUE(num) TYPE i..
ENDCLASS.
CLASS lcl_class2a IMPLEMENTATION.
METHOD get_string.
str = |{ super->get_string( ) }, { sy-uname }!|.
ENDMETHOD.
METHOD get_number_2a.
num = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1 max = 100 )->get_next( ).
ENDMETHOD.
ENDCLASS.
"Class 2b
CLASS lcl_class2b DEFINITION INHERITING FROM lcl_class1 FINAL.
PUBLIC SECTION.
METHODS: get_string REDEFINITION,
get_number_2b RETURNING VALUE(num) TYPE i.
ENDCLASS.
CLASS lcl_class2b IMPLEMENTATION.
METHOD get_string.
str = |{ super->get_string( ) } from lcl_class2b, { sy-uname }!|.
ENDMETHOD.
METHOD get_number_2b.
num = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1 max = 100 )->get_next( ).
ENDMETHOD.
ENDCLASS.
"Class 3a
CLASS lcl_class3a DEFINITION INHERITING FROM lcl_class2a FINAL.
PUBLIC SECTION.
METHODS: get_string REDEFINITION.
ENDCLASS.
CLASS lcl_class3a IMPLEMENTATION.
METHOD get_string.
str = |{ super->get_string( ) } How are you doing?|.
ENDMETHOD.
ENDCLASS.
*&--------------------------------------------------------------------*
*& Classes to demonstrate a factory method in a singleton
*& and an abstract class.
*&--------------------------------------------------------------------*
"Using the addition CREATE PRIVATE, objects can only be created by the class itself.
CLASS lcl_singleton DEFINITION CREATE PRIVATE.
PUBLIC SECTION.
METHODS: constructor,
"Methods for setting and getting a time stamp.
get_timestamp RETURNING VALUE(res_timestamp)
TYPE timestampl,
set_timestamp.
CLASS-METHODS:
"Factory method that returns an instance of the class.
get_instance RETURNING VALUE(res_instance) TYPE REF TO lcl_singleton.
CLASS-DATA: "Holds the number of overall instances.
no_of_instances TYPE i READ-ONLY.
PRIVATE SECTION.
CLASS-DATA: obj TYPE REF TO lcl_singleton.
DATA: timestamp TYPE timestampl.
ENDCLASS.
CLASS lcl_singleton IMPLEMENTATION.
METHOD get_instance.
"Checking if an instance of the class already exists.
"An instance should only be created if no instance exists
"to make sure that there is only a single instance overall.
IF obj IS NOT BOUND.
obj = NEW #( ).
ENDIF.
"In case an instance already exists, the existing one is
"always returned.
res_instance = obj.
ENDMETHOD.
METHOD constructor.
"Counts the number of instances of the class.
no_of_instances = no_of_instances + 1.
ENDMETHOD.
METHOD get_timestamp.
res_timestamp = timestamp.
ENDMETHOD.
METHOD set_timestamp.
GET TIME STAMP FIELD timestamp.
ENDMETHOD.
ENDCLASS.
CLASS lcl_sub DEFINITION DEFERRED.
CLASS lcl_abstract DEFINITION ABSTRACT.
PUBLIC SECTION.
CLASS-METHODS: factory_method IMPORTING check_num TYPE i
RETURNING VALUE(obj) TYPE REF TO lcl_abstract.
CLASS-DATA: message TYPE string.
"Abstract method: There's no implementation in this class.
METHODS: return_string ABSTRACT
IMPORTING i_str TYPE string
RETURNING VALUE(res_string) TYPE string.
ENDCLASS.
CLASS lcl_sub DEFINITION INHERITING FROM lcl_abstract.
PUBLIC SECTION.
METHODS: return_string REDEFINITION.
ENDCLASS.
CLASS lcl_abstract IMPLEMENTATION.
METHOD factory_method.
"Purpose of factory method: An instance can only be created
"if a certain condition is met.
CASE check_num.
WHEN 1.
obj = NEW lcl_sub( ).
message = `Great! I was able to create an instance.`.
WHEN OTHERS.
message = `What a pity. I'm not allowed to create an instance.`.
ENDCASE.
ENDMETHOD.
ENDCLASS.
CLASS lcl_sub IMPLEMENTATION.
METHOD return_string.
res_string = |I'm a returned string. | &&
|The object reference variable is { i_str }.|.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_OBJECTS</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: ABAP object orientation</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,46 @@
***********************************************************************
*
* Class supporting an ABAP cheat sheet example
*
* ----------------------------- NOTE -----------------------------------
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">Class supporting ABAP cheat sheet example</p>
"! The class supports the ABAP cheat sheet example about object orientation.
CLASS zcl_demo_abap_objects_friend DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
CLASS-METHODS get_strings RETURNING VALUE(res_string) TYPE string_table.
protected section.
private section.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_OBJECTS_FRIEND IMPLEMENTATION.
METHOD get_strings.
"Getting the strings and adding them to the string table.
"Accessing an attribute in a public visibility section.
APPEND zcl_demo_abap_objects=>public_string TO res_string.
"Accessing an attribute in a protected visibility section.
APPEND zcl_demo_abap_objects=>protected_string TO res_string.
"Accessing an attribute in a private visibility section.
APPEND zcl_demo_abap_objects=>private_string TO res_string.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_OBJECTS_FRIEND</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Class supporting ABAP cheat sheet example</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
CLASS lcx_calc_error DEFINITION INHERITING FROM cx_no_check.
ENDCLASS.
CLASS lcx_some_error DEFINITION INHERITING FROM cx_no_check.
ENDCLASS.
CLASS lcx_invalid_email DEFINITION INHERITING FROM cx_no_check.
ENDCLASS.
CLASS lcx_static_exc_class DEFINITION INHERITING FROM cx_static_check.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_PROG_FLOW_LOGIC</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Program flow logic</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,507 @@
***********************************************************************
*
* RAP BO consumer for a RAP demo scenario
* ABAP EML in use: RAP calculator (managed, draft-enabled RAP BO with
* late numbering
*
* -------------------------- PURPOSE ----------------------------------
* - This class is the RAP BO consumer for a RAP demo scenario that
* represents a calculator using RAP concepts, i. e. using ABAP EML in
* the context of a managed and draft-enabled RAP business object with
* RAP late numbering to carry out simple calculations. Here, a RAP BO
* instance consists of a calculation ID (which is the key that is finally
* set not until the RAP save sequence), two operands (having integer
* values), the arithmetic operator and the result plus other
* draft-related fields.
* - Underlying data model: Consists of a root entity alone.
* The BDEF defines the behavior for this entity. The definitions in the
* BDEF determine which methods must be implemented in the ABAP behavior
* pool (ABP). Note that the view contains many annotations for the SAP
* Fiori UI.
* - ABP for this scenario: zbp_demo_abap_rap_draft_m
*
* ----------------------- GETTING STARTED (1) -------------------------
* ----------------- Using this class as RAP BO consumer ---------------
*
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, check the notes
* included in the class as comments or refer to the respective topic
* in the ABAP Keyword Documentation.
* - Due to the amount of output in the console, the examples include
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
* sections. Plus, the variable name is displayed in most cases. Hence,
* to easier and faster find the relevant output in the console, just
* search in the console for the number/variable name (CTRL+F in the
* console) or use the debugger.
*
* ----------------------- GETTING STARTED (2) -------------------------
* Using the preview version of an SAP Fiori Elements UI as RAP BO consumer
*
* Create a service binding:
* 1. Find the service definition ZDEMO_ABAP_RAP_CALC_SD in the imported
* package in Business Services -> Service Definitions.
* 2. Right-click the service definition and choose New Service Binding.
* 3. In the New Service Binding pop-up, make the following entries:
* - Name: ZDEMO_ABAP_RAP_CALC_SB
* - Description: Service binding for demo
* - Binding type: OData V2 - UI
* - Service Definition: ZDEMO_ABAP_RAP_CALC_SD (should be already filled)
* 4. Choose Next.
* 5. Assign a transport request and choose Finish.
* 6. The service binding ZDEMO_ABAP_RAP_CALC_SB is opened. Activate the
* service binding.
* 7. In the Service Version Details section, choose the Publish button
* for the Local Service Endpoint. Once the service has been published,
* you should see ZDEMO_ABAP_RAP_DRAFT_M in the Entity Set and Association
* section.
* 8. Activate the service binding once the service has been published.
* 9. Select ZDEMO_ABAP_RAP_DRAFT_M and choose the Preview button.
* 10. The preview version of an SAP Fiori Elements app is displayed. If
* prompted, provide your credentials.
* 11. The app and the managed, draft-enabled RAP BO can be explored. If no
* columns are displayed, choose the 'Settings' button and select the
* desired columns.
* Choosing the 'Go' button refreshes the list. At first use, there
* might not be any entry. You can create an entry choosing the 'Create'
* button.
* The late numbering aspects enter the picture when you, for
* example, create a new instance, i. e. create a new calculation, and
* you keep a draft version of it instead of saving it to the database.
* The calculation ID which represents the key of the instance has an
* initial value. Only when you save the instance to the database, the
* final key is set.
*
* ----------------------------- NOTE -----------------------------------
* 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.
*
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP EML in a RAP scenario (draft BO)</p>
"! Example to demonstrate ABAP EML in the context of a RAP demo scenario (managed and draft-enabled RAP business object with RAP late numbering).
"! The class represents a RAP BO consumer.<br>Choose F9 in ADT to run the class.
CLASS zcl_demo_abap_rap_draft_ln_m DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES: if_oo_adt_classrun.
CLASS-METHODS:
class_constructor.
protected section.
PRIVATE SECTION.
CLASS-DATA:
activate_tab TYPE TABLE FOR ACTION IMPORT
zdemo_abap_rap_draft_m~activate,
activate_tab2 TYPE TABLE FOR ACTION IMPORT
zdemo_abap_rap_draft_m~activate,
activate_tab3 TYPE TABLE FOR ACTION IMPORT
zdemo_abap_rap_draft_m~activate,
edit_tab TYPE TABLE FOR ACTION IMPORT
zdemo_abap_rap_draft_m~edit,
read_tab TYPE TABLE FOR READ IMPORT zdemo_abap_rap_draft_m,
f TYPE RESPONSE FOR FAILED zdemo_abap_rap_draft_m,
r TYPE RESPONSE FOR REPORTED zdemo_abap_rap_draft_m,
m TYPE RESPONSE FOR MAPPED zdemo_abap_rap_draft_m.
CLASS-METHODS:
initialize_dbtabs.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_RAP_DRAFT_LN_M IMPLEMENTATION.
METHOD class_constructor.
initialize_dbtabs( ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: RAP Calculator Using Managed, ` &&
`Draft-Enabled RAP BO (Late Numbering)` ).
output->display( `1) Creating Instances and ` &&
`Saving to the database` ).
"Creating instances; draft indicator %is_draft is enabled
MODIFY ENTITY zdemo_abap_rap_draft_m
CREATE AUTO FILL CID
FIELDS ( num1 arithm_op num2 )
WITH VALUE #(
( %is_draft = if_abap_behv=>mk-on
num1 = 1 arithm_op = '+' num2 = 2 )
( %is_draft = if_abap_behv=>mk-on
num1 = 2 arithm_op = '*' num2 = 4 )
( %is_draft = if_abap_behv=>mk-on
num1 = 3 arithm_op = '-' num2 = 5 )
( %is_draft = if_abap_behv=>mk-on
num1 = 1 arithm_op = '/' num2 = 4 )
( %is_draft = if_abap_behv=>mk-on
num1 = 2 arithm_op = 'P' num2 = 5 ) )
FAILED f
REPORTED r
MAPPED m.
"Displaying responses only if FAILED and REPORTED
"response parameters are not initial
IF f IS NOT INITIAL OR r IS NOT INITIAL.
output->display( `Responses after MODIFY operation` ).
IF m IS NOT INITIAL.
output->display( input = m name = `m` ).
ENDIF.
IF f IS NOT INITIAL.
output->display( input = f name = `f` )..
ENDIF.
IF r IS NOT INITIAL.
output->display( input = r name = `r` ).
ENDIF.
ENDIF.
COMMIT ENTITIES.
IF sy-subrc <> 0.
output->display( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving draft table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time, draftentitycreationdatetime,
draftentitylastchangedatetime
FROM zdemo_abap_draft
ORDER BY id
INTO TABLE @DATA(draft_parent_before_act).
"Retrieving database table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time
FROM zdemo_abap_tabca
ORDER BY id
INTO TABLE @DATA(db_tab_root_before_act).
"Filling the derived type for the ACTIVATE method by
"getting %pid values
LOOP AT m-calc
ASSIGNING FIELD-SYMBOL(<fs>).
APPEND VALUE #( %pid = <fs>-%pid )
TO activate_tab.
ENDLOOP.
MODIFY ENTITY zdemo_abap_rap_draft_m
EXECUTE activate AUTO FILL CID WITH activate_tab
MAPPED m
FAILED f
REPORTED r.
COMMIT ENTITIES.
IF sy-subrc <> 0.
output->display( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving draft table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time, draftentitycreationdatetime,
draftentitylastchangedatetime
FROM zdemo_abap_draft
ORDER BY id
INTO TABLE @DATA(draft_parent_afer_act).
"Retrieving database table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time
FROM zdemo_abap_tabca
ORDER BY id
INTO TABLE @DATA(db_tab_root_after_act).
"Displaying entries
output->display( `1a) Draft and database tables before ` &&
`ACTIVATE action` ).
output->display( `Draft table before activation` ).
output->display( input = draft_parent_before_act name = `draft_parent_before_act` ).
output->display( `Database table before activation` ).
output->display( input = db_tab_root_before_act name = `db_tab_root_before_act` ).
output->next_section( `1b) Draft and database tables after ` &&
`ACTIVATE action` ).
output->display( `Draft table after activation` ).
output->display( input = draft_parent_afer_act name = `draft_parent_afer_act` ).
output->display( `Database table after activation` ).
output->display( input = db_tab_root_after_act name = `db_tab_root_after_act` ).
**********************************************************************
output->next_section( `2) Creating Invalid Instances` ).
"Purposely creating invalid instances;
"draft indicator %is_draft is enabled
MODIFY ENTITY zdemo_abap_rap_draft_m
CREATE AUTO FILL CID
FIELDS ( num1 arithm_op num2 )
WITH VALUE #(
( %is_draft = if_abap_behv=>mk-on
num1 = 1 arithm_op = 'a' num2 = 1 ) "wrong operator
( %is_draft = if_abap_behv=>mk-on
num1 = 1 arithm_op = '/' num2 = 0 ) "0 division
( %is_draft = if_abap_behv=>mk-on
num1 = 2 arithm_op = 'P' num2 = 12345 ) ) "arithmetic overflow
FAILED f
REPORTED r
MAPPED m.
"Displaying responses only if FAILED and REPORTED
"response parameters are not initial.
IF f IS NOT INITIAL OR r IS NOT INITIAL.
output->display( input = `Responses after MODIFY operation` ).
IF m IS NOT INITIAL.
output->display( input = m name = `m` ).
ENDIF.
IF f IS NOT INITIAL.
output->display( input = f name = `f` )..
ENDIF.
IF r IS NOT INITIAL.
output->display( input = r name = `r` ).
ENDIF.
ENDIF.
COMMIT ENTITIES.
IF sy-subrc <> 0.
output->display( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving draft table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time, draftentitycreationdatetime,
draftentitylastchangedatetime
FROM zdemo_abap_draft
ORDER BY id
INTO TABLE @draft_parent_before_act.
"Retrieving database table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time
FROM zdemo_abap_tabca
ORDER BY id
INTO TABLE @db_tab_root_before_act.
"Filling the derived type for the ACTIVATE method by
"getting %pid values; here, another table is filled for later use
LOOP AT m-calc
ASSIGNING FIELD-SYMBOL(<fs2>).
APPEND VALUE #( %pid = <fs2>-%pid )
TO activate_tab2.
APPEND VALUE #( %pid = <fs2>-%pid )
TO activate_tab3.
ENDLOOP.
MODIFY ENTITY zdemo_abap_rap_draft_m
EXECUTE activate AUTO FILL CID WITH activate_tab2
MAPPED m
FAILED f
REPORTED r.
"Displaying responses only if FAILED and REPORTED
"response parameters are not initial.
IF f IS NOT INITIAL OR r IS NOT INITIAL.
output->display( input = `Responses after MODIFY operation` ).
IF m IS NOT INITIAL.
output->display( input = m name = `m` ).
ENDIF.
IF f IS NOT INITIAL.
output->display( input = f name = `f` )..
ENDIF.
IF r IS NOT INITIAL.
output->display( input = r name = `r` ).
ENDIF.
ENDIF.
COMMIT ENTITIES.
IF sy-subrc <> 0.
output->display( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving draft table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time, draftentitycreationdatetime,
draftentitylastchangedatetime
FROM zdemo_abap_draft
ORDER BY id
INTO TABLE @draft_parent_afer_act.
"Retrieving database table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time
FROM zdemo_abap_tabca
ORDER BY id
INTO TABLE @db_tab_root_after_act.
"Displaying entries
output->next_section( `2a) Draft and database tables before ` &&
`ACTIVATE action` ).
output->display( `Draft table before activation` ).
output->display( input = draft_parent_before_act name = `draft_parent_before_act` ).
output->display( `Database table before activation` ).
output->display( input = db_tab_root_before_act name = `db_tab_root_before_act` ).
output->next_section( `2b) Draft and database tables after ` &&
`ACTIVATE action` ).
output->display( `Draft table after activation` ).
output->display( input = draft_parent_afer_act name = `draft_parent_afer_act` ).
output->display( `Database table after activation` ).
output->display( input = db_tab_root_after_act name = `db_tab_root_after_act` ).
**********************************************************************
output->next_section( `3) Correcting and Updating Invalid Instances` ).
"Preparing the derived type for the read operation to
"retrieve the field values; the draft indicator is enabled
LOOP AT activate_tab3 ASSIGNING FIELD-SYMBOL(<fs3>).
APPEND VALUE #( %pky = <fs3>-%pky
%is_draft = if_abap_behv=>mk-on
%control-id = if_abap_behv=>mk-on
%control-num1 = if_abap_behv=>mk-on
%control-arithm_op = if_abap_behv=>mk-on
%control-num2 = if_abap_behv=>mk-on
%control-calc_result = if_abap_behv=>mk-on
%control-crea_date_time = if_abap_behv=>mk-on
%control-lchg_date_time = if_abap_behv=>mk-on
) TO read_tab.
ENDLOOP.
"Retrieving the entries of the invalid instances
READ ENTITY zdemo_abap_rap_draft_m
ALL FIELDS WITH read_tab
RESULT DATA(result).
"Correcting and updating the invalid instances
MODIFY ENTITY zdemo_abap_rap_draft_m
UPDATE FROM VALUE #(
FOR wa IN result (
%pid = wa-%pid
%is_draft = if_abap_behv=>mk-on
num2 = SWITCH #( wa-calc_result
WHEN `Division by 0` THEN 2
WHEN `Overflow error` THEN 3 )
arithm_op = SWITCH #( wa-calc_result
WHEN `Wrong operator` THEN '+' )
%control-num2 = SWITCH #( wa-calc_result
WHEN `Division by 0` THEN if_abap_behv=>mk-on
WHEN `Overflow error` THEN if_abap_behv=>mk-on
ELSE if_abap_behv=>mk-off )
%control-arithm_op = SWITCH #( wa-calc_result
WHEN `Wrong operator` THEN if_abap_behv=>mk-on
ELSE if_abap_behv=>mk-off ) ) )
FAILED f
REPORTED r
MAPPED m.
COMMIT ENTITIES.
IF sy-subrc <> 0.
output->display( `An issue occurred in the RAP save sequence.` ).
ENDIF.
MODIFY ENTITY zdemo_abap_rap_draft_m
EXECUTE activate AUTO FILL CID WITH activate_tab3
MAPPED m
FAILED f
REPORTED r.
COMMIT ENTITIES.
IF sy-subrc <> 0.
output->display( `An issue occurred in the RAP save sequence.` ).
ENDIF.
"Retrieving draft table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time, draftentitycreationdatetime,
draftentitylastchangedatetime
FROM zdemo_abap_draft
ORDER BY id
INTO TABLE @draft_parent_afer_act.
"Retrieving database table entries
SELECT id, num1, arithm_op, num2, calc_result, crea_date_time,
lchg_date_time
FROM zdemo_abap_tabca
ORDER BY id
INTO TABLE @db_tab_root_after_act.
"Displaying entries
output->display( input = `Draft and database tables after ` &&
`ACTIVATE action` ).
output->display( `Draft table after activation` ).
output->display( input = draft_parent_afer_act name = `draft_parent_afer_act` ).
output->display( `Database table after activation` ).
output->display( input = db_tab_root_after_act name = `db_tab_root_after_act` ).
ENDMETHOD.
METHOD initialize_dbtabs.
DELETE FROM zdemo_abap_tabca.
DELETE FROM zdemo_abap_draft.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_RAP_DRAFT_LN_M</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: ABAP EML in a RAP scenario (draft BO)</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,973 @@
***********************************************************************
*
* RAP BO consumer for a RAP demo scenario:
* ABAP EML in use: Managed RAP BO with external numbering
*
* -------------------------- PURPOSE ----------------------------------
* - 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 a managed RAP business
* object with RAP external numbering.
* - Topics covered: RAP BO operations like create (including a
* determination on save), update, delete, executing an action, validation,
* create-by-association (parent to child), read (root entity),
* read-by-association (parent to child), read (child entity),
* read-by-association (child to parent)
* - 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).
* - ABP for this scenario: zbp_demo_abap_rap_ro_m
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, check the notes
* included in the class as comments or refer to the respective topic
* in the ABAP Keyword Documentation.
* - Due to the amount of output in the console, the examples include
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
* sections. Plus, the variable name is displayed in most cases. Hence,
* to easier and faster find the relevant output in the console, just
* search in the console for the number/variable name (CTRL+F in the
* console) or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* 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.
*
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP EML in a RAP scenario (managed BO)</p>
"! Example to demonstrate ABAP EML in the context of a RAP demo scenario (managed RAP BO with external numbering).
"! The class represents a RAP BO consumer.<br>Choose F9 in ADT to run the class.
CLASS zcl_demo_abap_rap_ext_num_m 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_m,
reported TYPE RESPONSE FOR REPORTED zdemo_abap_rap_ro_m,
mapped TYPE RESPONSE FOR MAPPED zdemo_abap_rap_ro_m.
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_M IMPLEMENTATION.
METHOD class_constructor.
initialize_dbtabs( ).
ENDMETHOD.
METHOD extract_from_failed.
CLEAR errors.
LOOP AT failed-root ASSIGNING FIELD-SYMBOL(<err>).
DATA op TYPE string.
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 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 key_field = ` &&
<err_ch>-key_field && ` and key_ch = ` &&
<err_ch>-key_ch && `: Fail cause `
&& <err_ch>-%fail-cause && `.` 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 = 'ggg'
field2 = 'hhh'
field3 = 40
field4 = 41 ) ) ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: RAP BO Operations Using a Managed ` &&
`RAP BO` ).
**********************************************************************
*
* Create operation
*
**********************************************************************
output->display( `1) Create operation` ).
"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.
* - The example BDEF includes the definition of a determination on
* save for create operations. In this case, the determination
* adds some text to the value in field2.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_m
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 considered
( %cid = 'cid2'
key_field = 2
field1 = 'ccc'
field2 = 'ddd'
field3 = 20 )
( %cid = 'cid3'
key_field = 3
field1 = 'eee'
field2 = 'fff'
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.
output->display( `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).
output->display( input = tab_root name = `tab_root` ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
output->display( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
output->display( input = mapped-root name = `mapped-root` ).
ENDIF.
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
**********************************************************************
*
* Update operations
*
**********************************************************************
output->next_section( `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_m
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 = 'iii'
field2 = 'jjj'
field3 = 50
field4 = 51 ) )
UPDATE FIELDS ( field1 field3 field4 )
WITH VALUE #(
"Update via cid_ref
( %cid_ref = 'cid5'
field1 = 'up_kkk'
field2 = 'up_lll' "Value not considered
field3 = 500
field4 = 501 )
"Updates via key
( key_field = 1
field1 = 'up_mmm'
field3 = 100
field4 = 101 )
( key_field = 2
field1 = 'up_ooo'
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.
output->display( `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.
output->display( input = tab_root name = `tab_root` ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
output->display( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
output->display( input = mapped-root name = `mapped-root` ).
ENDIF.
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
**********************************************************************
*
* Delete operation
*
**********************************************************************
output->next_section( `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 ....
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_m
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_del'
key_field = 6
field1 = 'mmm'
field2 = 'nnn'
field3 = 60
field4 = 61 ) )
DELETE FROM VALUE #(
"Deletion via %cid_ref
( %cid_ref = 'cid_del' )
"Deletions via key
( key_field = 4 )
( key_field = 5 )
"Instance to fail
( key_field = 100 ) ) "Key not available
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES.
IF sy-subrc <> 0.
output->display( `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.
output->display( input = tab_root name = `tab_root` ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
output->display( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
output->display( input = mapped-root name = `mapped-root` ).
ENDIF.
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
**********************************************************************
*
* Action multiply_by_2
*
**********************************************************************
output->next_section( `4) Action execution: 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_m
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_x2'
key_field = 7
field1 = 'ooo'
field2 = 'ppp'
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.
output->display( `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.
output->display( input = tab_root name = `tab_root` ).
"Displaying response information
IF mapped-root IS NOT INITIAL.
output->display( `Entries in MAPPED response parameter ` &&
`(root entity)` ).
output->display( input = mapped-root name = `mapped-root` ).
ENDIF.
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
**********************************************************************
*
* Create-by-association operation (from root to child entity)
*
**********************************************************************
output->next_section( `5) Create-by-association operation (from parent to child)` ).
**********************************************************************
* Notes:
* - The EML request includes a create and create-by-association
* request, i. e. a "deep create". An instance is created for the
* parent entity and, in the same request and based on this
* instance, instances are created for the child entity, too.
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_m
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_cba'
key_field = 9
field1 = 'qqq'
field2 = 'rrr'
field3 = 90
field4 = 91 ) )
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 = 9
field_ch1 = 'aaa_ch'
field_ch2 = 99 )
( %cid = 'cid_ch2'
key_ch = 10
field_ch1 = 'bbb_ch'
field_ch2 = 100 ) ) )
"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.
output->display( `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).
output->display( input = tab_root name = `tab_root` ).
output->display( input = tab_child name = `tab_child` ).
"Displaying response information
IF mapped IS NOT INITIAL.
output->display( `Entries in MAPPED response parameter ` &&
`(root and child entity)` ).
output->display( input = mapped name = `mapped` ).
ENDIF.
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
**********************************************************************
*
* Validation val
*
**********************************************************************
output->next_section( `6) Validation val` ).
**********************************************************************
* Notes:
* - The EML request includes a create request. The validation's
* handler method is implementation in a way that the saving of
* instances is disabled if a field value is not allowed. In this
* example, the value of the integer in field3 shall not exceed 1000.
* Here, the third instance will fail for the validation.
* Consequently, all instances of this request are not saved to the
* database. Either all is ok and will be saved or nothing.
* - Note that the response information for the validation is only
* available in the response parameters of the COMMIT ENTITIES
* statement. Here, the BDEF derived type is
* ... TYPE RESPONSE FOR ... LATE ....
**********************************************************************
MODIFY ENTITIES OF zdemo_abap_rap_ro_m
ENTITY root
CREATE FIELDS ( key_field field1 field2 field3 field4 )
WITH VALUE #(
( %cid = 'cid_val1'
key_field = 123
field1 = 'sss'
field2 = 'ttt'
field3 = 1
field4 = 2 )
( %cid = 'cid_val2'
key_field = 456
field1 = 'uuu'
field2 = 'vvv'
field3 = 3
field4 = 4 )
( %cid = 'cid_val3'
key_field = 789
field1 = 'www'
field2 = 'xxx'
field3 = 1001
field4 = 5 ) )
MAPPED mapped
FAILED failed
REPORTED reported.
COMMIT ENTITIES RESPONSES
FAILED DATA(failed_late)
REPORTED DATA(reported_late).
IF sy-subrc <> 0.
output->display( `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.
output->display( input = tab_root name = `tab_root` ).
"Displaying response information
IF mapped IS NOT INITIAL.
output->display( `Entries in MAPPED response parameter ` &&
`(root and child entity)` ).
output->display( input = mapped name = `mapped` ).
ENDIF.
IF failed_late IS NOT INITIAL.
output->display( `Entries in FAILED LATE response parameter` ).
output->display( input = failed_late name = `failed_late` ).
ENDIF.
IF reported_late IS NOT INITIAL.
output->display( `Entries in REPORTED LATE response parameter` ).
output->display( input = reported_late name = `reported_late` ).
ENDIF.
**********************************************************************
*
* Read operation (root entity)
*
**********************************************************************
output->next_section( `7) 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_m
ENTITY root
ALL FIELDS WITH VALUE #(
( key_field = 1 )
( key_field = 2 )
( key_field = 7 )
( key_field = 5 ) ) "Instance to fail
RESULT DATA(result)
FAILED failed
REPORTED reported.
"Displaying the read result
output->display( input = result name = `result` ).
"Displaying response information
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
*********************************************************************
*
* Read operation (child entity)
*
**********************************************************************
output->next_section( `8) 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_m
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
output->display( input = read_ch name = `read_ch` ).
"Displaying response information
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
**********************************************************************
*
* Read-by-association operation (from parent to child)
*
**********************************************************************
output->next_section( `9) Read-by-association operation (from parent to child)` ).
**********************************************************************
* Notes:
* - The EML request includes a read-by-association request from the
* parent to the child.
* - 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_m
ENTITY root
BY \_child
ALL FIELDS WITH VALUE #(
( key_field = 2 )
( key_field = 9 )
( key_field = 999 ) ) "Instance to fail
RESULT DATA(rba_result)
LINK DATA(association_links)
FAILED failed
REPORTED reported.
"Displaying read result and association links
output->display( input = rba_result name = `rba_result` ).
output->display( input = association_links name = `association_links` ).
"Displaying response information
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
**********************************************************************
*
* Read-by-association operation (from child to parent)
*
**********************************************************************
output->next_section( `10) 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_m
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
output->display( input = rba_parent name = `rba_parent` ).
output->display( input = association_links_parent name = `association_links_parent` ).
"Displaying response information
IF failed IS NOT INITIAL.
output->display( `Entries in FAILED response parameter` ).
output->display( input = extract_from_failed( ) name = `extract_from_failed( )` ).
ENDIF.
IF reported IS NOT INITIAL.
output->display( `Entries in REPORTED response parameter` ).
output->display( input = extract_from_reported( ) name = `extract_from_reported( )` ).
ENDIF.
**********************************************************************
*
* Excursion: Read and read-by-association operation using a dynamic
* EML statement
*
**********************************************************************
output->next_section( `11) 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_m,
read_dyn_result TYPE TABLE FOR READ RESULT zdemo_abap_rap_ro_m,
rba_dyn TYPE TABLE FOR READ IMPORT
zdemo_abap_rap_ro_m\_child,
rba_dyn_result TYPE TABLE FOR READ RESULT
zdemo_abap_rap_ro_m\_child,
rba_dyn_link TYPE TABLE FOR READ LINK zdemo_abap_rap_ro_m\_child.
read_dyn = VALUE #(
( %key-key_field = 1
%control = VALUE #(
field1 = if_abap_behv=>mk-on
field2 = if_abap_behv=>mk-on
field3 = if_abap_behv=>mk-on
field4 = if_abap_behv=>mk-on ) )
( %key-key_field = 2
%control = VALUE #(
field1 = if_abap_behv=>mk-on
field2 = if_abap_behv=>mk-on
field3 = if_abap_behv=>mk-on
field4 = if_abap_behv=>mk-on ) ) ).
rba_dyn = VALUE #(
( %key-key_field = 1
%control = VALUE #(
key_ch = if_abap_behv=>mk-on
field_ch1 = if_abap_behv=>mk-on
field_ch2 = if_abap_behv=>mk-on ) )
( %key-key_field = 2
%control = VALUE #(
key_ch = if_abap_behv=>mk-on
field_ch1 = if_abap_behv=>mk-on
field_ch2 = if_abap_behv=>mk-on ) ) ).
op_tab = VALUE #(
( op = if_abap_behv=>op-r-read
entity_name = 'ZDEMO_ABAP_RAP_RO_M'
instances = REF #( read_dyn )
results = REF #( read_dyn_result ) )
( op = if_abap_behv=>op-r-read_ba
entity_name = 'ZDEMO_ABAP_RAP_RO_M'
sub_name = '_CHILD'
full = abap_true
instances = REF #( rba_dyn )
results = REF #( rba_dyn_result )
links = REF #( rba_dyn_link ) ) ).
READ ENTITIES OPERATIONS op_tab.
output->display( `Read result (root)` ).
output->display( input = read_dyn_result name = `read_dyn_result` ).
output->display( `Read result (read-by-association)` ).
output->display( input = rba_dyn_result name = `rba_dyn_result` ).
output->display( `Links` ).
output->display( input = rba_dyn_link name = `rba_dyn_link` ).
ENDMETHOD.
METHOD initialize_dbtabs.
DELETE FROM zdemo_abap_rapt1.
DELETE FROM zdemo_abap_rapt2.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_RAP_EXT_NUM_M</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: ABAP EML in a RAP scenario (managed BO)</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_RAP_EXT_NUM_U</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: ABAP EML in a RAP scenario (unmanaged BO)</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_SQL</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: ABAP SQL</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,175 @@
***********************************************************************
*
* ABAP cheat sheet: ABAP SQL - Grouping Internal Tables
*
* -------------------------- PURPOSE ----------------------------------
* Example to demonstrate syntax options when grouping internal tables.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, refer to the
* notes included in the class as comments or refer to the respective
* topic in the ABAP Keyword Documentation.
* - Due to the amount of console output, the examples contain numbers
* (e.g. 1) ..., 2) ..., 3) ...) for the individual example sections.
* Also, the variable name is displayed in most cases. So to find
* the relevant output in the console easier and faster, just search
* for the number/variable name in the console (CTRL+F in the console)
* or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">ABAP cheat sheet: ABAP SQL - Grouping internal tables</p>
"! Example to demonstrate grouping internal tables.<br>Choose F9 in ADT to run the class.
CLASS zcl_demo_abap_sql_group_by DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES: if_oo_adt_classrun.
CLASS-METHODS: class_constructor.
protected section.
PRIVATE SECTION.
CLASS-DATA:
wa TYPE zdemo_abap_flsch,
member TYPE zdemo_abap_flsch,
members TYPE STANDARD TABLE OF zdemo_abap_flsch WITH EMPTY KEY.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_SQL_GROUP_BY IMPLEMENTATION.
METHOD class_constructor.
"Fill demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: Grouping Internal Tables` ).
SELECT *
FROM zdemo_abap_flsch
INTO TABLE @DATA(fli_tab).
output->display( `1) Representative Binding` ).
output->display( `1a) Grouping by one column` ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid.
output->display( wa-carrid ).
ENDLOOP.
output->next_section( `1b) Members of one column groups` ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid.
CLEAR members.
LOOP AT GROUP wa INTO member.
members = VALUE #( BASE members ( member ) ).
ENDLOOP.
output->display( members ).
ENDLOOP.
output->next_section( `1c) Grouping by two columns` ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
output->display( |{ wa-carrid } { wa-airpfrom }| ).
ENDLOOP.
output->next_section( `1d) Members of two column groups` ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
CLEAR members.
LOOP AT GROUP wa INTO member.
members = VALUE #( BASE members ( member ) ).
ENDLOOP.
output->display( members ).
ENDLOOP.
output->next_section( `2) Group Key Binding` ).
output->display( `2a) Grouping by one column` ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid
INTO DATA(key).
output->display( key ).
ENDLOOP.
output->next_section( `2b) Members of one column groups` ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid
INTO key.
CLEAR members.
LOOP AT GROUP key INTO member.
members = VALUE #( BASE members ( member ) ).
ENDLOOP.
output->display( members ).
ENDLOOP.
output->next_section( `2c) Grouping by two columns` ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
INTO DATA(keys).
output->display( keys ).
ENDLOOP.
output->next_section( `2d) Members of two column groups` ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
INTO keys.
CLEAR members.
LOOP AT GROUP keys INTO member.
members = VALUE #( BASE members ( member ) ).
ENDLOOP.
output->display( members ).
ENDLOOP.
output->next_section( `2e) Two column groups without members` ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom
index = GROUP INDEX size = GROUP SIZE )
WITHOUT MEMBERS
INTO DATA(keysplus).
output->display( keysplus ).
ENDLOOP.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_SQL_GROUP_BY</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: ABAP SQL - Grouping internal tables</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_STRING_PROC</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: String processing</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_STRUCTURES</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Structures</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,686 @@
***********************************************************************
*
* ABAP Cheat Sheet: ABAP Unit Tests
*
* -------------------------- PURPOSE ----------------------------------
* - Example to demonstrate ABAP unit tests.
* - Topics covered: Test classes and test methods, special methods,
* implementing and injecting test doubles (constructor injection,
* back door injection, test seams)
*
* ----------------------- RUN ABAP UNIT TEST---------------------------
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class.
* You can also right-click somewhere in the class and choose
* Run as -> ABAP Unit Test.
* - The results of a test run are displayed in the ABAP Unit tab in ADT
* and can be evaluated. The Failure Trace section provides information
* on errors found.
* - If you are interested in test coverage, you can choose
* Ctrl/Cmd + Shift + F11, or make a right-click, choose Run as ->
* ABAP Unit Test With..., select the Coverage checkbox and choose
* Execute. You can then check the results in the ABAP Coverage tab,
* what code is tested and what not.
*
* ----------------------- RUN CLASS -----------------------------
* - Open the class with the ABAP development tools for Eclipse (ADT).
* - Choose F9 to run the class.
* - Check the console output.
* - To understand the context and the ABAP syntax used, check the notes
* included in the class as comments or refer to the respective topic
* in the ABAP Keyword Documentation.
* - Due to the amount of output in the console, the examples include
* numbers (e. g. 1) ..., 2) ..., 3) ...) for the individual example
* sections. Plus, the variable name is displayed in most cases. Hence,
* to easier and faster find the relevant output in the console, just
* search in the console for the number/variable name (CTRL + F in the
* console) or use the debugger.
*
* ----------------------------- NOTE -----------------------------------
* The code presented in this class is intended only to support the ABAP
* cheat sheets. It is not intended for direct use in a production system
* environment. The code examples in the ABAP cheat sheets are primarily
* intended to provide a better explanation and visualization of the
* syntax and semantics of ABAP statements, not to solve concrete
* programming tasks. For production application programs, you should
* always work out your own solution for each individual case. There is
* no guarantee for the correctness or completeness of the code.
* Furthermore, there is no legal responsibility or liability for any
* errors or their consequences that may occur when using the the example
* code.
*
***********************************************************************
"! <p class="shorttext synchronized">ABAP cheat sheet: Unit tests</p>
"! Example to demonstrate ABAP unit tests.<br>Choose F9 in ADT to run the class.
"! To run all unit tests of the class, choose Ctrl/Cmd + Shift + F10.
CLASS zcl_demo_abap_unit_test DEFINITION
PUBLIC
CREATE PUBLIC.
PUBLIC SECTION.
INTERFACES: if_oo_adt_classrun.
CLASS-METHODS: class_constructor.
"Optional parameter for the instance constructor for the purpose of
"constructor injection
METHODS constructor
IMPORTING iref_data_prov TYPE REF TO zdemo_abap_get_data_itf OPTIONAL.
PROTECTED SECTION.
TYPES carr_tab TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY.
METHODS: select_flight_data IMPORTING carrier TYPE zdemo_abap_fli-carrid
RETURNING VALUE(flight_data) TYPE carr_tab.
PRIVATE SECTION.
TYPES: int_tab_so TYPE SORTED TABLE OF i WITH UNIQUE KEY table_line,
int_tab_st TYPE STANDARD TABLE OF i WITH EMPTY KEY,
occ_rate TYPE p LENGTH 4 DECIMALS 2,
BEGIN OF nums_struc,
num1 TYPE i,
num2 TYPE i,
END OF nums_struc,
nums_tab TYPE TABLE OF nums_struc WITH EMPTY KEY.
DATA: seats_table TYPE zdemo_abap_get_data_itf=>carr_tab,
flight_tab TYPE TABLE OF zdemo_abap_fli,
"Reference variable for back door injection
"Note: In the example, it is a local interface declared in the
"Local Types tab (the CCIMP include). To make the type known to
"the global class, see the Class-relevant Local Types tab (the CCDEF include).
data_provider_local_itf TYPE REF TO lif_get_data,
"Reference variable for constructor injection
"In the example, the type refers to a global interface.
data_provider_global_itf TYPE REF TO zdemo_abap_get_data_itf,
"For demonstrating setter injection
data_provider_setter_inj TYPE REF TO zdemo_abap_get_data_itf,
"For demonstrating parameter injection
data_provider_param_inj TYPE REF TO zdemo_abap_get_data_itf..
METHODS:
"Calculates the sum of two numbers
"This method demonstrates the use of the setup and teardown methods in the test class.
get_sum IMPORTING key TYPE zdemo_abap_tab1-key_field
char TYPE zdemo_abap_tab1-char1
RETURNING VALUE(sum) TYPE i,
"Calculates the common divisors and the greatest common divisor of two numbers
get_common_div_and_gcd IMPORTING a TYPE i
b TYPE i
EXPORTING common_divisors TYPE int_tab_so
gcd TYPE i,
"Calculates the digit sum of a number
get_digit_sum IMPORTING num TYPE i
RETURNING VALUE(digit_sum) TYPE i,
"Multiple methods that all do the same (they calculate the occupancy rate of flights)
"but serve different demonstration purposes for the ABAP unit tests in the example.
"The method implementations involve a depended-on component (DOC). In this case,
"it is a database access.
"The methods are intentionally implemented in a similar way. Therefore, almost
"all of the following methods will display the same output in the console when the
"class is executed using F9.
"Method to demonstrate test double injection using inheritance and method redefinition
get_occ_rate_using_meth IMPORTING carrier_id TYPE zdemo_abap_fli-carrid
RETURNING VALUE(occupancy_rate) TYPE occ_rate,
"Method to demonstrate test double injection using test seams
get_occ_rate_test_seam IMPORTING carrier_id TYPE zdemo_abap_fli-carrid
EXPORTING occupancy_rate TYPE occ_rate
num1 TYPE i
num2 TYPE i,
"Method to demonstrate test double injection using back door injection and a local interface
get_occ_rate_local_itf IMPORTING carrier_id TYPE zdemo_abap_fli-carrid
RETURNING VALUE(occupancy_rate) TYPE occ_rate,
"Method to demonstrate test double injection using constructor injection and a global interface
get_occ_rate_global_itf IMPORTING carrier_id TYPE zdemo_abap_fli-carrid
RETURNING VALUE(occupancy_rate) TYPE occ_rate,
"Method to demonstrate test double injection using setter injection and a global interface
get_occ_rate_setter_inj IMPORTING carrier_id TYPE zdemo_abap_fli-carrid
RETURNING VALUE(occupancy_rate) TYPE occ_rate,
"Method for setter injection
setter_meth IMPORTING data_prov TYPE REF TO zdemo_abap_get_data_itf,
"Method to demonstrate test double injection using parameter injection and a global interface
"An optional parameter is specified for passing the test double if the method is tested.
get_occ_rate_param_inj IMPORTING carrier_id TYPE zdemo_abap_fli-carrid
data_prov TYPE REF TO zdemo_abap_get_data_itf OPTIONAL
RETURNING VALUE(occupancy_rate) TYPE occ_rate.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_UNIT_TEST IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_flight_tables=>fill_dbtabs( ).
"Preparing a demo database table for this example (get_sum method)
DELETE FROM zdemo_abap_tab1.
INSERT zdemo_abap_tab1 FROM @(
VALUE #( key_field = 1 char1 = 'aaa' char2 = 'bbb' num1 = 25 num2 = 75 ) ).
ENDMETHOD.
METHOD constructor.
"For demonstrating the back door injection
data_provider_local_itf = NEW lcl_data_prov_local_itf( ).
"For demonstrating the constructor injection
IF iref_data_prov IS BOUND.
"Note: The parameter is only bound when you run the unit test.
"When you run the unit test and you debug, you will see that iref_data_prov
"has a type reference to LTD_TEST_DATA_GLOBAL_INTF.
data_provider_global_itf = iref_data_prov.
ELSE.
data_provider_global_itf = NEW lcl_data_prov_glo_itf( ).
ENDIF.
"Object creation for the method call in the get_occ_rate_setter_inj method
data_provider_setter_inj = NEW lcl_data_prov_glo_itf( ).
ENDMETHOD.
METHOD get_common_div_and_gcd.
"Calculates the common divisors and the greatest common divisor of two numbers
CLEAR: common_divisors, gcd.
CHECK a >= 1.
CHECK b >= 1.
IF a >= b.
DATA(greater_num) = a.
DATA(lower_num) = b.
ELSE.
greater_num = b.
lower_num = a.
ENDIF.
"Getting common divisors
DATA(div) = 1.
WHILE div <= lower_num.
IF lower_num MOD div = 0.
DATA(divisor) = lower_num / div.
INSERT divisor INTO TABLE common_divisors.
ENDIF.
div += 1.
ENDWHILE.
LOOP AT common_divisors ASSIGNING FIELD-SYMBOL(<i>).
IF greater_num MOD <i> <> 0.
DELETE common_divisors WHERE table_line = <i>.
ENDIF.
ENDLOOP.
"Extracting the greatest common divisor from the list of common divisors
gcd = common_divisors[ lines( common_divisors ) ].
ENDMETHOD.
METHOD get_digit_sum.
"Calculates the digit sum of a number
CLEAR digit_sum.
CHECK num >= 0.
DATA(converted_int) = CONV string( num ).
DATA(len) = strlen( converted_int ).
DO len TIMES.
DATA(idx) = sy-index - 1.
digit_sum = digit_sum + converted_int+idx(1).
ENDDO.
ENDMETHOD.
METHOD get_occ_rate_global_itf.
"Method to demonstrate test double injection using constructor injection
"and a global interface
DATA total_seatsmax_global_itf TYPE i.
DATA total_seatsocc_global_itf TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"When the class is executed using F9, the object used here refers to type lcl_data_prov_glo_itf.
"When the unit test is executed, the object used here refers to type ltd_test_data_global_intf,
"i.e. the local test double is injected.
DATA(flight_data) = data_provider_global_itf->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<l>).
total_seatsmax_global_itf = total_seatsmax_global_itf + <l>-seatsmax.
total_seatsocc_global_itf = total_seatsocc_global_itf + <l>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_global_itf / total_seatsmax_global_itf * 100.
ENDMETHOD.
METHOD get_occ_rate_local_itf.
"Method to demonstrate test double injection using back door
"injection and a local interface
DATA total_seatsmax_local_itf TYPE i.
DATA total_seatsocc_local_itf TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing - a global interface
"is not available - a local interface is created, and
"an interface method is implemented. In this example, the local interface is
"created in the local types tab (CCIMP include): lif_get_data
"A local class (lcl_data_prov_local_itf) is also created in the CCIMP include. It
"implements the local interface.
"When the class is executed using F9, the object used here refers to type lcl_data_prov_local_itf.
"When the unit test is executed, the object used here refers to type ltd_test_data_local_itf,
"i.e. the local test double is injected.
DATA(flight_data) = data_provider_local_itf->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<k>).
total_seatsmax_local_itf = total_seatsmax_local_itf + <k>-seatsmax.
total_seatsocc_local_itf = total_seatsocc_local_itf + <k>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_local_itf / total_seatsmax_local_itf * 100.
ENDMETHOD.
METHOD get_occ_rate_param_inj.
"This method demonstrates test double injection using parameter injection.
DATA total_seatsmax_param_inj TYPE i.
DATA total_seatsocc_param_inj TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"The method has an optional importing parameter. When the unit test is executed,
"the parameter is bound. An object of the test double class is passed in that case.
"Otherwise, when the class is executed using F9, an object of the actual data provider
"is created.
IF data_prov IS BOUND.
data_provider_param_inj = data_prov.
ELSE.
data_provider_param_inj = NEW lcl_data_prov_glo_itf( ).
ENDIF.
DATA(flight_data) = data_provider_param_inj->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<o>).
total_seatsmax_param_inj = total_seatsmax_param_inj + <o>-seatsmax.
total_seatsocc_param_inj = total_seatsocc_param_inj + <o>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_param_inj / total_seatsmax_param_inj * 100.
ENDMETHOD.
METHOD get_occ_rate_setter_inj.
"This method demonstrates test double injection using setting injection.
"See the setter_meth method.
DATA total_seatsmax_setter_inj TYPE i.
DATA total_seatsocc_setter_inj TYPE i.
"Assumption: The original code in this method was as follows (the line commented out).
"It was identified as DOC (reading data from a database table).
"DATA(flight_data) = select_flight_data( carrier = carrier_id ).
"Instead of a method call like above and for a proper unit testing, a global interface
"is provided.
"In the example, an interface method is implemented in a local class in the local types
"tab (CCIMP include): lcl_data_prov_glo_itf
"See the comment in the setter_meth method
DATA(flight_data) = data_provider_setter_inj->select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<n>).
total_seatsmax_setter_inj = total_seatsmax_setter_inj + <n>-seatsmax.
total_seatsocc_setter_inj = total_seatsocc_setter_inj + <n>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_setter_inj / total_seatsmax_setter_inj * 100.
ENDMETHOD.
METHOD get_occ_rate_test_seam.
"Method to demonstrate test double injection using test seams
"Note: The code is just for demonstration purposes. Of course, the result can be
"achieved more elegantly using SQL expressions, for example.
TEST-SEAM select_flights.
"DOC
SELECT seatsmax, seatsocc
FROM zdemo_abap_fli
WHERE carrid = @carrier_id
INTO CORRESPONDING FIELDS OF TABLE @seats_table.
END-TEST-SEAM.
DATA total_seatsmax_tm TYPE i.
DATA total_seatsocc_tm TYPE i.
LOOP AT seats_table ASSIGNING FIELD-SYMBOL(<j>).
total_seatsmax_tm = total_seatsmax_tm + <j>-seatsmax.
total_seatsocc_tm = total_seatsocc_tm + <j>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_tm / total_seatsmax_tm * 100.
"Further examples for test seams
DATA(var) = 0.
"Empty test seam; code is injected during unit test
"Check the output when running the class using F9 and
"the test results when running the unit test.
TEST-SEAM num1.
END-TEST-SEAM.
IF var = 0.
num1 = 1.
ELSE.
num1 = 999.
ENDIF.
num2 = 0.
"Empty injection
"See the test class: The code that is included in the test
"seam should be excluded from the test. Therefore, the
"test injection block in the test class is empty.
"Check the output when running the class using F9 and
"the test results when running the unit test.
TEST-SEAM num2.
num2 = 123.
END-TEST-SEAM.
ENDMETHOD.
METHOD get_occ_rate_using_meth.
"This method demonstrates test double injection using inheritance and method redefinition.
DATA total_seatsmax_no TYPE i.
DATA total_seatsocc_no TYPE i.
"During the unit test, the redefined method in the test class is called.
DATA(flight_data) = select_flight_data( carrier = carrier_id ).
LOOP AT flight_data ASSIGNING FIELD-SYMBOL(<m>).
total_seatsmax_no = total_seatsmax_no + <m>-seatsmax.
total_seatsocc_no = total_seatsocc_no + <m>-seatsocc.
ENDLOOP.
occupancy_rate = total_seatsocc_no / total_seatsmax_no * 100.
ENDMETHOD.
METHOD get_sum.
"The method selects a record from a database table and sums the values
"of two fields, both are of type i.
SELECT SINGLE
FROM zdemo_abap_tab1
FIELDS num1 + num2 AS sum
WHERE key_field = @key
AND char1 = @char
INTO @sum.
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
"Note: The example includes a couple of implementations for the methods
"declared above. And by choosing F9 in ADT, you can run the class and check the
"output in the console.
"However, the focus of the example is unit tests. Therefore, check the
"test classes and methods in the test include (Test Classes tab in ADT).
"Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class and check the
"test results in the ABAP Unit tab in ADT.
DATA(output) = NEW zcl_demo_abap_display( out ).
output->display( `ABAP Cheat Sheet Example: ABAP Unit Tests` ).
output->display( `************************************************************************` ).
output->display( `---> Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class <---` ).
output->display( `************************************************************************` ).
output->display( `1) get_sum Method` ).
"This method demonstrates the use of the setup and teardown methods in the test class.
DATA(sum) = get_sum( key = 1 char = 'aaa' ).
output->display( input = sum name = `sum` ).
**********************************************************************
output->next_section( `2) get_common_div_and_gcd Method` ).
"Filling an internal table with numbers on whose bases the common divisors and the
"greatest common divisor are to be calculated
DATA(tab) = VALUE nums_tab( ( num1 = 10 num2 = 20 )
( num1 = 100 num2 = 200 )
( num1 = 12 num2 = 6 )
( num1 = 5 num2 = 1 )
( num1 = 50 num2 = 50 )
( num1 = 4 num2 = 8 ) ).
LOOP AT tab ASSIGNING FIELD-SYMBOL(<a>).
get_common_div_and_gcd( EXPORTING a = <a>-num1
b = <a>-num2
IMPORTING common_divisors = DATA(common_divs) gcd = DATA(gcd) ).
output->display( |Common divisors of { <a>-num1 } and { <a>-num2 }| ).
output->display( input = common_divs name = `common_divs` ).
output->display( |Greatest common divisor of { <a>-num1 } and { <a>-num2 }: { gcd } | ).
ENDLOOP.
**********************************************************************
output->next_section( `3) get_digit_sum Method` ).
"Filling an internal table with numbers on whose bases the digit sum is to be calculated
DATA(tab_i) = VALUE int_tab_so( ( 12 )
( 123 )
( 3 )
( 8246 )
( 1001001 )
( 0 ) ).
LOOP AT tab_i ASSIGNING FIELD-SYMBOL(<b>).
DATA(digit_sum) = get_digit_sum( <b> ).
output->display( |The digit sum of { <b> } is { digit_sum }.| ).
ENDLOOP.
**********************************************************************
output->next_section( `4) get_occ_rate_using_meth Method` ).
"In the test class, this method demonstrates test double injection
"using inheritance and method redefinition.
"Filling an internal table with carrier ids on whose bases the occupancy
"rate is to be calculated.
DATA(tab_str) = VALUE zdemo_abap_get_data_itf=>carr_tab( ( carrid = 'LH' )
( carrid = 'AA' )
( carrid = 'DL' ) ).
LOOP AT tab_str ASSIGNING FIELD-SYMBOL(<c>).
DATA(occupancy_rate) = get_occ_rate_using_meth( <c>-carrid ).
output->display( |The occupancy rate for airline { <c>-carrid } is { occupancy_rate }%.| ).
ENDLOOP.
output->next_section( `5) get_occ_rate_test_seam Method` ).
"This method demonstrates test double injection using test seams.
LOOP AT tab_str ASSIGNING FIELD-SYMBOL(<d>).
get_occ_rate_test_seam( EXPORTING carrier_id = <d>-carrid
IMPORTING occupancy_rate = DATA(occupancy_rate_test_seam)
num1 = DATA(num1)
num2 = DATA(num2) ).
output->display( |The occupancy rate for airline { <d>-carrid } is { occupancy_rate_test_seam }%.| ).
output->display( |num1: { num1 }| ).
output->display( |num2: { num2 }| ).
ENDLOOP.
**********************************************************************
output->next_section( `6) get_occ_rate_local_itf Method` ).
"This method demonstrates test double injection using back door
"injection and a local interface.
LOOP AT tab_str ASSIGNING FIELD-SYMBOL(<e>).
DATA(occupancy_rate_local_itf) = get_occ_rate_local_itf( <e>-carrid ).
output->display( |The occupancy rate for airline { <e>-carrid } is { occupancy_rate_local_itf }%.| ).
ENDLOOP.
**********************************************************************
output->next_section( `7) get_occ_rate_global_itf Method` ).
"This method demonstrates test double injection using constructor
"injection and a global interface.
LOOP AT tab_str ASSIGNING FIELD-SYMBOL(<f>).
DATA(occupancy_rate_global_itf) = get_occ_rate_global_itf( <f>-carrid ).
output->display( |The occupancy rate for airline { <f>-carrid } is { occupancy_rate_global_itf }%.| ).
ENDLOOP.
**********************************************************************
output->next_section( `8) get_occ_rate_setter_inj Method` ).
"This method demonstrates test double injection using setter injection and a global interface.
LOOP AT tab_str ASSIGNING FIELD-SYMBOL(<g>).
DATA(occupancy_rate_setter_inj) = get_occ_rate_setter_inj( <g>-carrid ).
output->display( |The occupancy rate for airline { <g>-carrid } is { occupancy_rate_setter_inj }%.| ).
ENDLOOP.
**********************************************************************
output->next_section( `9) get_occ_rate_param_inj Method` ).
"This method demonstrates test double injection using parameter injection and a global interface.
LOOP AT tab_str ASSIGNING FIELD-SYMBOL(<h>).
DATA(occupancy_rate_param_inj) = get_occ_rate_param_inj( carrier_id = <h>-carrid ).
output->display( |The occupancy rate for airline { <h>-carrid } is { occupancy_rate_param_inj }%.| ).
ENDLOOP.
ENDMETHOD.
METHOD select_flight_data.
"Method that is identified as DOC in the method implementations above.
"This method is also used for demonstrating test double injection and method redefinition.
SELECT seatsmax, seatsocc
FROM zdemo_abap_fli
WHERE carrid = @carrier
INTO CORRESPONDING FIELDS OF TABLE @flight_data.
ENDMETHOD.
METHOD setter_meth.
"Method to demonstrate the test double injection using setter injection
"When the unit test is executed, an object of the test double class is passed as
"a parameter. Then, the object used here refers to type ltd_test_data_setter_inj,
"i.e. the local test double is injected.
data_provider_setter_inj = data_prov.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,4 @@
*"* use this source file for any type of declarations (class
*"* definitions, interfaces or type declarations) you need for
*"* components in the private section
INTERFACE lif_get_data DEFERRED.

View File

@@ -0,0 +1,73 @@
******************************************************
* Local interface
******************************************************
INTERFACE lif_get_data.
TYPES: carr_tab TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY,
occ_rate TYPE p LENGTH 4 DECIMALS 2.
METHODS:
select_flight_data IMPORTING carrier TYPE zdemo_abap_fli-carrid
RETURNING VALUE(flight_data) TYPE carr_tab,
"This method is included to demonstrate the PARTIALLY IMPLEMENTED
"addition in the test class when implementing the test double
say_hello RETURNING VALUE(hi) TYPE string.
ENDINTERFACE.
******************************************************
* Local class
* The class implements the local interface.
******************************************************
CLASS lcl_data_prov_local_itf DEFINITION.
PUBLIC SECTION.
INTERFACES lif_get_data.
ENDCLASS.
CLASS lcl_data_prov_local_itf IMPLEMENTATION.
METHOD lif_get_data~select_flight_data.
SELECT seatsmax, seatsocc
FROM zdemo_abap_fli
WHERE carrid = @carrier
INTO CORRESPONDING FIELDS OF TABLE @flight_data.
ENDMETHOD.
METHOD lif_get_data~say_hello.
hi = `Hello, ` && sy-uname && `.`.
ENDMETHOD.
ENDCLASS.
******************************************************
* Local class that implements a global interface
* It serves the purpose of a data provider. It can be
* imagined as a global class, and a method that is
* implemented there and called by the class under test
* is identified as DOC. A local class is used in the
* example to keep the number of separate artifacts small.
******************************************************
CLASS lcl_data_prov_glo_itf DEFINITION.
PUBLIC SECTION.
INTERFACES zdemo_abap_get_data_itf.
ENDCLASS.
CLASS lcl_data_prov_glo_itf IMPLEMENTATION.
METHOD zdemo_abap_get_data_itf~select_flight_data.
SELECT seatsmax, seatsocc
FROM zdemo_abap_fli
WHERE carrid = @carrier
INTO CORRESPONDING FIELDS OF TABLE @flight_data.
ENDMETHOD.
METHOD zdemo_abap_get_data_itf~say_hello.
hi = `Hello, ` && sy-uname && `.`.
ENDMETHOD.
ENDCLASS.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_DEMO_ABAP_UNIT_TEST</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Unit tests</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_TABL" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DD02V>
<TABNAME>ZDEMO_ABAP_CARR</TABNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<TABCLASS>TRANSP</TABCLASS>
<CLIDEP>X</CLIDEP>
<DDTEXT>Demo table: Airline</DDTEXT>
<MASTERLANG>E</MASTERLANG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_CARR</TABNAME>
<AS4LOCAL>A</AS4LOCAL>
<TABKAT>0</TABKAT>
<TABART>APPL0</TABART>
<BUFALLOW>N</BUFALLOW>
</DD09L>
<DD03P_TABLE>
<DD03P>
<FIELDNAME>MANDT</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CLNT</DATATYPE>
<LENG>000003</LENG>
<MASK> CLNT</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CARRID</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000003</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CARRNAME</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000040</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000020</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CURRCODE</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000010</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CUKY</DATATYPE>
<LENG>000005</LENG>
<MASK> CUKY</MASK>
</DD03P>
<DD03P>
<FIELDNAME>URL</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000510</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000255</LENG>
<MASK> CHAR</MASK>
</DD03P>
</DD03P_TABLE>
<TABL_EXTRAS>
<TDDAT>
<TABNAME>ZDEMO_ABAP_CARR</TABNAME>
<CCLASS>CUS_DEV_SUP_DA</CCLASS>
</TDDAT>
</TABL_EXTRAS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,63 @@
// ABAP CDS cheat sheet example:
// Aggregate expressions in the element list of CDS view entities
//
//////////////////////////------ NOTES ------//////////////////////////////////
// - CDS view entity selects from a demo database table
// - Demonstrates various aggregate expressions in the element list
// - As a prerequisite, run the class zcl_abap_demo_cds_ve to populate the
// database tables of the example. Otherwise, no data is displayed.
//
//////////////////////------ DATA PREVIEW ------///////////////////////////////
// - Choose F8 in ADT to open the data preview and check out the data displayed
// - For comparing and checking the output, you can also open the data preview
// for the database table. In ADT, press and hold CTRL and click the database
// table name. In the opened table artifact, choose F8 to open the data preview.
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS view entity: Aggregate expressions'
define view entity zdemo_abap_cds_ve_agg_exp
as select from zdemo_abap_fli
{
// The element list intentionally includes few fields only to focus on the effect of aggregate expressions.
key carrid,
currency,
// -------- Aggregate expressions --------
// - Aggregate expressions can be used as elements of an element list. Other positions are possible.
// - An alias name must be specified.
// - A GROUP BY clause is required. It must list all non-aggregated fields from the element list.
// - Additions: If ALL is used, all rows in the result set are respected. This is the default setting.
// If DISTINCT is used, only distinct values of an argument are respected.
// - Note: There may or may not be spaces between the parentheses following avg, min, etc., and the
// content specified within.
// AVG (Returns the average value of an argument)
avg( seatsocc as abap.dec(15,2)) as avg_seats_occ,
avg( cast(paymentsum as abap.dec(15, 2)) as abap.dec(15,2)) as avg_paysum,
// SUM (Returns the sum of an argument)
// Since a currency field is used in the example, an annotatin is required.
@Semantics.amount.currencyCode: 'currency'
sum(paymentsum) as total_paysum,
// MIN (Returns the least value of an argument)
min( seatsocc ) as min_occ_seats,
// MAX (Returns the greatest value of an argument)
max( seatsocc ) as max_occ_seats,
max( all seatsocc ) as max_occ_seats_all, //Same result as above, ALL is optional
// COUNT (Returns counted lines)
count(*) as cnt, // * means that all lines are respected
count(distinct planetype) as cnt_planetype //DISTINCT means that the number of dinstinct values if an argument is counted;
//e.g. if 3 is returned, it means there are 3 different plane types among the result set
}
//GROUP BY clause that lists all non-aggregated fields from the element list
group by
carrid,
currency

View File

@@ -0,0 +1,19 @@
{
"BASEINFO":
{
"FROM":
[
"ZDEMO_ABAP_FLI"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZDEMO_ABAP_CDS_VE_AGG_EXP</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>CDS view entity: Aggregate expressions</DDTEXT>
<SOURCE_TYPE>W</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,144 @@
// ABAP CDS cheat sheet example: Associations
//
//////////////////////////------ NOTES ------//////////////////////////////////
// - CDS view entity that selects from a demo CDS view entity and demonstrates
// associations. A selection of use cases of associations is covered. For
// more information and examples, see the ABAP Keyword Documentation.
// - As a prerequisite, run the class zcl_abap_demo_cds_ve to populate the
// database tables of the example. Otherwise, no data is displayed.
// - For further notes on associations, see the commented out information further
// down.
// - To see how the joins are realized on the database, you can right-click anywhere
// in the source code and choose 'Show SQL Create Statement'. The example
// includes associations where only left outer joins are performed.
//
//////////////////////------ DATA PREVIEW ------///////////////////////////////
// - Choose F8 in ADT to open the data preview and check out the data displayed
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS view entity: Associations 1'
define view entity zdemo_abap_cds_ve_assoc
// In this example, the data source, from which data is read, is another CDS view entity.
// This source CDS view entity selects all fields from the demo database table zdemo_abap_flsch.
// It also contains exposed associations that are used here.
as select from zdemo_abap_cds_ve_assoc_e as _flsch
// 1) One use case of assocations, which is not covered here, can be the use in the FROM clause.
// - That is, you can use an association as data source by specifying a path expression.
// - For example, the CDS view entity zdemo_abap_cds_ve_assoc_e exposes an association
// _carr_exp. Therefore, a FROM clause as follows is possible:
// ... as select from zdemo_abap_cds_ve_assoc_e._carr_exp as _flsch ...
// 2) Adding fields of an association target to the element list (of the same CDS view entity)
// - In this case, since data is requested, a join is carried out.
// - The data preview (choose F8) shows the values for the added fields.
// - In this example, the association is used, but not exposed. Therefore, it cannot be used
// in path expressions in other CDS entities as shown in 3).
association [1..1] to zdemo_abap_carr as _carr1 on _flsch.Carrid = _carr1.carrid
association [1..1] to zdemo_abap_carr as _carr2 on _flsch.Carrid = _carr2.carrid
association [1..*] to zdemo_abap_fli as _fli on _flsch.Carrid = _fli.carrid
// 3) Exposing associations
// - In this example, no fields of the association target are added to the element list.
// But the assocation is exposed in the element list. Therefore, it can be used
// in path expressions in other CDS entities.
// - In this case, since data is not requested, a join is not carried out. It is up to
// to the consumer (e.g. an ABAP SQL statement or other CDS view entities) to request
// fields (one field, multiple fields, all fields ...). Only then, a join is performed.
// - The data preview (choose F8) does not show any data of the association target.
// - Compare the ON condition to the ones above. For demonstration purposes, the carrid
// field is specified with an alias name in the element list. To refer to this name,
// the prefix $projection. is required. As above, you can also use the original name.
association [1..1] to zdemo_abap_carr as _carr3 on $projection.carrier = _carr3.carrid
{
// Including fields from the data source
// The prefix _flsch. is actually not necessary here in the example. It's intentionally included to emphasize the data source.
key _flsch.Carrid as carrier,
key _flsch.Connid as connection_id,
_flsch.Cityfrom,
_flsch.Cityto,
// Regarding 2) Adding fields of an association target to the element list
// - Two fields are added in the element list.
// - You can make a right-click and choose 'Show SQL Create Statement' to check how the join is performed.
// - Because a left outer join is performed, the coalesce function is included for a field.
// If there are null values, the specified character literal is inserted.
// - Only these two fields are respected from the association target.
_carr1.carrname as carrier_name,
coalesce(_carr1.url, 'NULL') as carr_url,
// Regarding 3) Exposing associations
// - The association is exposed in the element list (but no fields of the association target).
// - As demonstrated in the executable class of this cheat sheet, an ABAP SQL statement
// can request data of the association target.
// - The data preview does not include any fields from the association target. Likewise,
// the 'SQL Create Statement' does not show any join with this assocation.
_carr3,
// 4) Using associations that are exposed in external views
// - The CDS view entity that is used as data source in the SELECT list exposes
// associations.
// - Such an association is used in a path expression here to include a field from the
// association target in the element list. In this case, this CDS view entity is
// a consumer of the association. A join is performed, as can be seen in the
// 'SQL Create Statement' view.
_flsch._carr_exp.currcode as curr_exposed,
// 5) Attributes of path expression
// - Attributes are specified in angle brackets after each CDS association to define
// further properties. These can be the cardinality, join type that is implemented when used,
// and filter conditions
// Speciying filter conditions and the join type
// - Only if a join type is specified explicitly, the addition WHERE must be specified
// - The example specifies the join type. Therefore, WHERE is required. Here in the example,
// the specification can also be the one commented out below because it implicitly has
// the same effect. Here, a left outer join is performed by default.
// - The operand specified on the left side of the condition must be a field of the association target.
_carr2[left outer where $projection.carrier = 'LH'].url as fcond_url,
//_carr2[$projection.carrier = 'LH'].url as fcond_url
// Specifying the cardinality of the current CDS association
// - The values 1: (current CDS association is declared as unique) and *: (non-unique) are possible.
// - You can use 1: to prevent a syntax warning in case of a path specified with filter conditions, for example.
// - In the example, an association is specified with to many (there can be multiple flights for a flight route).
// Without the cardinality specification 1:, a warning would be displayed ("The association _fli can modify
// the cardinality of the results set").
// - Similar to the example above, the first line commented out below is also possible in this example.
// The second line commented out results in a syntax warning because it does not specify the
// cardinality 1:.
_fli[1:$projection.connection_id = connid].fldate as fcond_fldate
//_fli[1:left outer where $projection.connection_id = connid].fldate as fcond_fldate
//_fli[$projection.connection_id = connid].fldate as fcond_fldate
}
////////////////////////// --------- Notes on associations --------- /////////////////////////////////////////
// - They offer an advanced modelling capability for CDS data models. They define relationships between
// CDS entities (association source and target). On the database, associations are internally transformed into joins.
// - Compared to regular joins, associations differ in the following respects:
// - Joins are only performed on demand, i.e. when data is requested from the assocation by a consumer, e.g.
// using another CDS view entity or an ABAP SQL statement. In the regular joins (e.g. inner, outer joins), the
// join is always performed. When a CDS association is instantiated as join on the database, the association
// source represents the left side and the association target represents the right side of the join.
// - In the SELECT list, specifying the data source as a prefix is mandatory for all fields of the association.
// For joins, it is mandatory only for for non-unique names.
// - Unlike regular joins, associations can be reused in different positions and basically replace very complex
// join expressions.
// - Use of associations:
// - Including fields from the association target in the current view
// - Exposing associations so that they can be used in other CDS entities or in ABAP SQL
// - Associations can be used in path expressions (a sequence of associations) at different operand positions.
// - Associations can be specified with additional semantic information, such as cardinality.
// - Specifying the (optional) cardinality is a means of documenting the semantics of the data model.
// - Cardinality is specified in square brackets [ ]. Minimum and maximum can be specified, for example
// one to one [1..1], one to many [1..*]. The default is [0..1]. Specifying the minimum value is optional (the
// default value is 0), i.e. [0..1] is [1], [0..*] is [*]. The minimum cannot be *, the maximum not 0.
// - Maximum values greater than 1 can lead to syntax errors or warnings. Generally, a non-matching cardinality
// usually produces a warning.
// - If the cardinality is not specified, it is to one by default [x..1].
// - Compositions and to-parent associations are special kinds of CDS associations. See the ABAP Keyword Documentation.

View File

@@ -0,0 +1,23 @@
{
"BASEINFO":
{
"FROM":
[
"ZDEMO_ABAP_CDS_VE_ASSOC_E",
"ZDEMO_ABAP_CARR",
"ZDEMO_ABAP_FLI"
],
"ASSOCIATED":
[
"ZDEMO_ABAP_CARR"
],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZDEMO_ABAP_CDS_VE_ASSOC</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>CDS view entity: Associations</DDTEXT>
<SOURCE_TYPE>W</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,40 @@
// ABAP CDS cheat sheet example: Associations
//
//////////////////////////------ NOTES ------//////////////////////////////////
// - CDS view entity that selects from a demo database table.
// - The purpose of this CDS view entity is to demonstrate associations. The view
// is used as a data source in another CDS view entity.
// - As a prerequisite, run the class zcl_abap_demo_cds_ve to populate the
// database tables of the example. Otherwise, no data is displayed.
//
//////////////////////------ DATA PREVIEW ------///////////////////////////////
// - Choose F8 in ADT to open the data preview and check out the data displayed
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS view entity: Associations'
define view entity zdemo_abap_cds_ve_assoc_e
as select from zdemo_abap_flsch as _flsch
association [1..1] to zdemo_abap_carr as _carr_exp on _flsch.carrid = _carr_exp.carrid
association [1..*] to zdemo_abap_fli as _fli on _flsch.carrid = _fli.carrid and _flsch.connid = _fli.connid
{
key _flsch.carrid as Carrid,
key _flsch.connid as Connid,
_flsch.countryfr as Countryfr,
_flsch.cityfrom as Cityfrom,
_flsch.airpfrom as Airpfrom,
_flsch.countryto as Countryto,
_flsch.cityto as Cityto,
_flsch.airpto as Airpto,
_flsch.fltime as Fltime,
_flsch.deptime as Deptime,
_flsch.arrtime as Arrtime,
_flsch.distance as Distance,
_flsch.distid as Distid,
_flsch.fltype as Fltype,
_flsch.period as Period,
_carr_exp,
_fli
}

View File

@@ -0,0 +1,22 @@
{
"BASEINFO":
{
"FROM":
[
"ZDEMO_ABAP_FLSCH"
],
"ASSOCIATED":
[
"ZDEMO_ABAP_CARR",
"ZDEMO_ABAP_FLI"
],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZDEMO_ABAP_CDS_VE_ASSOC_E</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>CDS view entity: Associations</DDTEXT>
<SOURCE_TYPE>W</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,132 @@
// ABAP CDS cheat sheet example: Joins
//
//////////////////////////------ NOTES ------//////////////////////////////////
// - CDS view entity selects from a demo database table
// - Demonstrates various joins
// - As a prerequisite, run the class zcl_abap_demo_cds_ve to populate the
// database tables of the example. Otherwise, no data is displayed.
// It is particularly needed in this case because it contains entries to
// visualize the effect of outer joins.
// - HOW TO:
// - To reduce the number of separate artifacts, this example CDS view entity
// contains the code for multiple joins, which is commented out.
// - To test out various joins, you can comment out and comment in the
// respective code sections (select the lines and choose CTRL + 7).
// - The example for inner joins is commented in by default. The relevant
// code sections are marked with "COMMENT IN/OUT ... START" and
// "COMMENT IN/OUT ... END" in both SELECT and element list
// (inner joins -> 1a / 1b). To test the left outer joins, for example,
// comment out the respective sections of the inner join and comment in
// the sections for left outer joins (2a, 2b), and so on.
// - Once done, activate the view and choose F8 to open the data preview.
// You must activate the view and choose F8 again for every change here
// because the alias names are different.
//
//////////////////////------ DATA PREVIEW ------///////////////////////////////
// - Choose F8 in ADT to open the data preview and check out the data displayed
// - Note the hints above regarding commenting in/out of code.
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS view entity: Joins'
define view entity zdemo_abap_cds_ve_joins
as select from zdemo_abap_carr as _carr
// Notes on joins:
// - Joins combine two data sources into one result set, consisting of columns of both data sources
// - Rows of the result set are determined by the join type and by join conditions between columns of the data sources
// - Joins can be nested
// - Inner or outer join must contain a join condition after ON
// - Each element of the SELECT list must have the name of its data source as prefix
// - When joins are used, a WHERE condition affects the result set
// - The cardinality can be specified for left outer joins. For more details, see the ABAP Keyword Documentation.
/////////////////// ----- Example for INNER JOIN ----- /////////////////////////////////
// Notes:
// - Joins all entries of the data sources whose fields match the ON condition
// - In the table zdemo_abap_carr, there are entries in carrid that are not present in zdemo_abap_flsch.
// The same is true the other way round. The result only contains those entries that exist in both data sources
// based on the ON condition.
//// ----> COMMENT IN/OUT 1a START <-----
inner join zdemo_abap_flsch as _flsch_in on _carr.carrid = _flsch_in.carrid
//// ----> COMMENT IN/OUT 1a END <-----
//Alternative syntax: Specifying 'inner' is optional
// join zdemo_abap_flsch
// as _flsch_in on _carr.carrid = _flsch_in.carrid
/////////////////// ----- Example for LEFT OUTER JOIN ----- /////////////////////////////////
// Notes:
// - The join selects all entries on the left side. Entries that match the ON condition have the same content as in the inner join.
// In entries that do not match the ON condition, the elements on the right side have the null value.
// - To demonstrate the effect, the table zdemo_abap_carr contains entries for carrid that are not present in zdemo_abap_flsch.
// - Example in the element list:
// - The coalesce function can be used to prevent null values in the result set.
// - In the example, the function is used for an element to prevent null values.
//// ----> COMMENT IN/OUT 2A START <-----
// left outer join zdemo_abap_flsch as _flsch_lo on _carr.carrid = _flsch_lo.carrid
//// ----> COMMENT IN/OUT 2A END <-----
/////////////////// ----- Example for RIGHT OUTER JOIN ----- /////////////////////////////////
// Notes:
// - The join selects all entries on the right side. Entries that match the ON condition have the same content as in the inner join.
// In entries that do not match the ON condition, the elements on the left side have the null value.
// - To demonstrate the effect, the table zdemo_abap_carr contains entries for carrid that are not present in zdemo_abap_flsch.
// - Example in the element list:
// - Instead of the coalesce function, you can also use a CASE expression using a logical expression with IS [NOT] NULL
// to prevent null values in the result set.
// - In the example, a CASE expression is used for an element to prevent null values.
//// ----> COMMENT IN/OUT 3A START <-----
// right outer join zdemo_abap_flsch as _flsch_ro on _carr.carrid = _flsch_ro.carrid
//// ----> COMMENT IN/OUT 3A END <-----
/////////////////// ----- Example for CROSS JOIN ----- /////////////////////////////////
// Notes:
// - All entries on the left side are combined with all entries on the right side.
// - It is not possible to specify an ON condition.
//- The number of lines of the result is the number of left lines multiplied by the number of lines of the right table.
//// ----> COMMENT IN/OUT 4A START <-----
// cross join zdemo_abap_flsch as _flsch_cr
//// ----> COMMENT IN/OUT 4A END <-----
{
key _carr.carrid,
_carr.carrname,
/////////////////// ----- Example for INNER JOIN ----- /////////////////////////////////
// ----> COMMENT IN/OUT 1b START <-----
_flsch_in.cityfrom as cityfr_in,
_flsch_in.cityto as cityto_in
// ----> COMMENT IN/OUT 1b END <-----
/////////////////// ----- Example for LEFT OUTER JOIN ----- /////////////////////////////////
//// ----> COMMENT IN/OUT 2b START <-----
// _flsch_lo.cityfrom as cityfr_lo,
// coalesce(_flsch_lo.cityto, '???') as cityto_lo
//// ----> COMMENT IN/OUT 2b END <-----
/////////////////// ----- Example for RIGHT OUTER JOIN ----- /////////////////////////////////
//// ----> COMMENT IN/OUT 3b START <-----
// case when _carr.url is not null then _carr.url
// else '!!!'
// end as url_ro,
// _flsch_ro.cityfrom as cityfr_ro,
// _flsch_ro.cityto as cityto_ro
//// ----> COMMENT IN/OUT 3b END <-----
/////////////////// ----- Example for CROSS JOIN ----- /////////////////////////////////
//// ----> COMMENT IN/OUT 4b START <-----
// _flsch_cr.cityfrom as cityfr_cr,
// _flsch_cr.cityto as cityto_cr
//// ----> COMMENT IN/OUT 4b END <-----
}

View File

@@ -0,0 +1,20 @@
{
"BASEINFO":
{
"FROM":
[
"ZDEMO_ABAP_CARR",
"ZDEMO_ABAP_FLSCH"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZDEMO_ABAP_CDS_VE_JOINS</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>CDS view entity: Joins</DDTEXT>
<SOURCE_TYPE>W</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,237 @@
// ABAP CDS cheat sheet example:
// Operands and expressions in CDS view entities
//
//////////////////////////------ NOTES ------//////////////////////////////////
// - CDS view entity selects from a demo database table
// - Demonstrates various syntax options regarding operands and expressions
// - As a prerequisite, run the class zcl_abap_demo_cds_ve to populate the
// database tables of the example. Otherwise, no data is displayed.
//
//////////////////////------ DATA PREVIEW ------///////////////////////////////
// - Choose F8 in ADT to open the data preview and check out the data displayed
// - The example includes parameters. Therefore, you are prompted to insert a
// value. In this example, the parameter (maximum seats in a plane) is used for
// the WHERE clause (the lower the number entered, the more entries in the result
// set).
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////------ Annotations ------///////////////////////////////
// Annotations add metadata to a CDS object that expands the syntax options of SQL.
// There's a predefined set of SAP annotations. Their specification is optional.
// Example for a view entity annotation (only possible in CDS view entities)
// The following annotation defines implicit access control when ABAP SQL is used
// to access the CDS view entity. Here, it is determined that no access control
// is required.
@AccessControl.authorizationCheck: #NOT_REQUIRED
// Example for an entity annotation (annotations that can be used in all CDS entities)
// The following annotation provides a translatable short text of the CDS entity.
@EndUserText.label: 'CDS view entity: Operands/Expressions'
define view entity zdemo_abap_cds_ve_sel
with parameters
p_smax : abap.int4 //Input parameter typed with an elementary data type;
//can also be a DDIC data element
as select from zdemo_abap_fli //Selection from a demo database table;
//an alias name can be also specified ... as _fli, for example
// The following element list demonstrates possible elements, operands and expressions.
// Note: Many of the operands and expressions demonstrated below can occur in multiple positions.
// Refer to the ABAP Keyword Documentation for the details.
{
// -------- Specifying fields of the data source --------
//- Multiple fields of the data source from which to be selected are specified.
//- Field names can be prefixed with the name of the data source (or, if specified, with the alias name).
//- Alias names can be specified for the elements. Note: In case of joins (selection from multiple sources)
// all elements must be prefixed with the name of the data source. See the view entity demonstrating joins.
//- KEY defines the current element as a key element; must be placed at the beginning; in CDS entities the key
// elements are mainly used to document the semantics of the data model (Note: They do not define unique lines
// in its result with regard to the key.)
key carrid as CarrierId, //Alias name specified
key zdemo_abap_fli.connid as Connid, //Element prefixed with data source; alias name specified
key fldate,
price,
currency,
paymentsum,
planetype,
seatsmax,
seatsocc,
// -------- Literals --------
// Typed literals (cover most built-in types of the ABAP Dictionary)
// As is true for all of the following elements, an alias name must be specified.
abap.int4'12345' as int4, //Typed numeric literal
abap.char'hallo' as c5, //Typed character literal
abap.dats'20240101' as date_lit, //Date
// Note: In case of a currency or quantity field specified with a typed literal, a reference
// to a currency key or unit is mandatory, which requires an annotation. The currency example
// here uses the following annotation. The element 'currency' from above is referenced.
@Semantics.amount.currencyCode: 'currency'
abap.curr'12.34' as curr,
abap.dec'0.9' as discnt,
abap.unit'KM' as kilometers,
// Untyped literals
'Minutes' as fltime_ut, //Untyped character literal
1 as num_lit, //Untyped numeric literal
// -------- Parameters --------
// Parameters can be specified in an operand position.
// The name of the parameter must be prefixed by $parameters.
$parameters.p_smax as param,
// -------- Session variables --------
// Among other sesion variables, there are built-in session variables available.
$session.user as usr,
$session.client as clnt,
$session.system_language as langu,
$session.system_date as sys_date,
$session.user_timezone as usr_time,
$session.user_date as usr_date,
// -------- Expressions --------
//Note: Aggregate and path expressions are covered in a separate CDS view entity.
// -------- Cast expressions --------
// Convert the value of operands to a specified type after as
// The examples use built-in data types only.
// Note: Regarding which conversion combinations of types are possible, see the ABAP Keyword Documentation.
// There are special conversion rules for every combination.
cast( price as abap.dec(15,2) ) as cast_curr2dec,
// The following example uses the prefix $projection. which defines reuse expressions.
// That is, you can refer to an element defined previously in the element list of the same CDS view entity.
// Note that this is only possible in dedicated positions. One of them is a cast expression.
cast( $projection.date_lit as abap.char(8) ) as cast_dats2c,
// -------- Arithmetic expressions --------
seatsocc_b + seatsocc_f as occ_seats_classes,
seatsmax - seatsocc as free_seats,
2 * 2 as mult,
9 / 3 as div,
//Arithmetic expressions using cast and reuse expressions
cast( paymentsum as abap.dec(17,2) ) * abap.dec'0.75' as discount_1,
$projection.cast_curr2dec * $projection.discnt as discount_2,
cast( seatsocc / seatsmax * 100 as abap.dec(10, 2) ) as occupancy_rate,
// -------- Case expressions --------
// Simple case distinction for comparing values of operands with other operands.
// The first operand specified after THEN for which the comparison is true is
// returned as a result. No match: Result is determined by the ELSE branch.
case currency
when 'EUR' then 'X'
when 'USD' then 'Y'
else 'Z'
end as case1,
// In newer ABAP releases, you can use the ELSE NULL addition that returns the null value.
// Note: If ELSE is not specified, the null value is returned as a result.
// case $projection.case1
// when 'X' then 'A'
// else null
// end as case2,
// Complex case distinction (searched case) for evaluating conditions
case
when seatsmax <= 150 then 'small'
when seatsmax > 150 and seatsmax < 300 then 'middle'
when seatsmax >= 300 then 'large'
else '?'
end as case3,
// -------- Excursion: Logical expressions --------
// The following nonsense example using a CASE expression just visualizes the rich variety of options.
//Comparison operators
// Boolean operators AND, OR, NOT as well as parenthesized expressions are possible.
case
when seatsmax = 385 and not ( seatsocc > 380 and seatsocc <> 379 or seatsocc <= 120 or paymentsum >= 200000 ) then 'A'
//Interval comparisons
when seatsmax between 250 and 350 and seatsocc not between 1 and 100 then 'B'
//Pattern comparisons ('%' -> wildcard character, represents any character string, '_' -> stands for any character)
when carrid like '_L' then 'C'
//Checking for null and initial value
when currency is not null or carrid is not initial then 'D'
else '?'
end as case4,
// -------- Built-in functions --------
// SQL functions (only a selection is covered here)
// Numeric functions
// The example uses typed and untyped literals only as arguments.
abs( abap.int4'-1' ) as nf_abs,
ceil( abap.decfloat34'3.333' ) as nf_ceil,
floor( abap.decfloat34'3.333' ) as nf_floor,
div( 25, 5 ) as nf_div,
mod( 11, 3 ) as nf_mod,
division( 1, 3, 2 ) as nf_division,
round( abap.decfloat34'1.337', 2 ) as nf_round,
// String functions
concat(planetype, '-#') as sf_concat,
concat_with_space(carrid, '#', 1) as sf_conc_ws, //3rd argument: number of spaces
instr(currency, 'U') as sf_instr, //Position of the first occurrence of the string from the substring in the argument (case-sensitive)
left(currency, 2) as sf_left, //String of length n starting from the left of an expression
length(planetype) as sf_len, //Number of characters in an argument ignoring trailing blanks
lower(carrid) as sf_lower, //String with a length of an argument in which all uppercase letters are transformed to lowercase letters
lpad(carrid, 5, '#') as sf_lpad, //String of a length with the right-aligned content of an argument without trailing blanks and in which leading blanks produced by the expanded string are replaced by the characters from an argument (respecting all blanks)
ltrim(planetype, 'A') as sf_ltrim, //String with the content of an argument in which all trailing blanks and leading characters are removed that match the specified character.
replace(currency, 'U', '#') as sf_repl, //String in which all instances of the second argument are replaced by the content from the third argument
replace_regexpr(PCRE => '\\d', //More optional parameters are possible; the example replaces all digits
VALUE => planetype,
WITH => '#',
RESULT_LENGTH => 10) as sf_repl_regex,
right(currency, 2) as sf_right, //String of length n starting from the right of an expression
rpad(carrid, 5, '#') as sf_rpad, //See lpad; here, right-algined content
rtrim(planetype, '0') as sf_rtrim, //See ltrim; here, from the right
substring(planetype, 4, 3) as sf_sub, //Returns a substring; second argument: position from where to start; third argument: length of the extracted substring
upper( 'abap' ) as sf_upper, //Transforms to upper case
// Coalesce function
// Checks whether the argument contains a null value. If it contains it, it returns the value of the second argument
// Otherwise, it returns the value of the first argument.
// This example has no null values in carrid, therefore the carrid value is output. See the example view about joins.
coalesce(carrid, 'N') as coalesced,
// Special functions
// Type conversion functions
fltp_to_dec( abap.fltp'12.34' as abap.dec(10,1) ) as fltp2dec,
// Unit conversion
// In the following example, the number that is input as parameter is used as the value for a distance in miles. It is converted to kilometers.
@Semantics.quantity.unitOfMeasure: 'kilometers'
unit_conversion( quantity => $parameters.p_smax,
source_unit => abap.unit'MI',
target_unit => $projection.kilometers ) as converted_value,
// Date/Time functions
// The function in the example calculates the days between to dates. The actual parameters must have the built-in data type DATS.
dats_days_between(fldate,$projection.date_lit) as days_bw1,
// The following example is similar to the example above. Here, the function expects the type DATN.
// It also shows the use of another function (dats_to_datn) that converts the types.
// Note: Only literals can be passed to the final two parameters on_error, on_initial.
datn_days_between(dats_to_datn(fldate,'INITIAL','INITIAL') , dats_to_datn($session.user_date,'INITIAL','INITIAL')) as days_bw2,
// The following function adds days to a date. Here, the date a week from today is calculated.
dats_add_days($session.user_date,7,'INITIAL') as in1week,
// Time stamp functions
// Getting the current time stamp
utcl_current() as ts,
// Adding seconds to a time stamp
utcl_add_seconds($projection.ts,60) as in1minute
}
// -------- Clauses for the SELECT statement --------
// SELECT statements of a CDS view entitiy can be specified with optional clauses
// Among them, there are WHERE (to restrict the rows of the result set), GROUP BY (grouping the result set(
// HAVING (further restriction after the GROUP BY clause) clauses and other set operators like EXCEPT, INTERSECT and UNION.
// This example uses a simple WHERE clause. It uses a condition that includes the input parameter to restrict the result set.
where seatsmax > $parameters.p_smax

View File

@@ -0,0 +1,19 @@
{
"BASEINFO":
{
"FROM":
[
"ZDEMO_ABAP_FLI"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DDLS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DDLS>
<DDLNAME>ZDEMO_ABAP_CDS_VE_SEL</DDLNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<DDTEXT>CDS view entity: Operands and expressions</DDTEXT>
<SOURCE_TYPE>W</SOURCE_TYPE>
</DDLS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_TABL" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DD02V>
<TABNAME>ZDEMO_ABAP_DRAFT</TABNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<TABCLASS>TRANSP</TABCLASS>
<CLIDEP>X</CLIDEP>
<LANGDEP>X</LANGDEP>
<DDTEXT>Draft table for RAP calculator</DDTEXT>
<MASTERLANG>E</MASTERLANG>
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_DRAFT</TABNAME>
<AS4LOCAL>A</AS4LOCAL>
<TABKAT>0</TABKAT>
<TABART>APPL0</TABART>
<BUFALLOW>N</BUFALLOW>
</DD09L>
<DD03P_TABLE>
<DD03P>
<FIELDNAME>CLIENT</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CLNT</DATATYPE>
<LENG>000003</LENG>
<MASK> CLNT</MASK>
</DD03P>
<DD03P>
<FIELDNAME>ID</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ROLLNAME>SYSUUID_X16</ROLLNAME>
<ADMINFIELD>0</ADMINFIELD>
<NOTNULL>X</NOTNULL>
<COMPTYPE>E</COMPTYPE>
</DD03P>
<DD03P>
<FIELDNAME>DRAFTUUID</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ROLLNAME>SYSUUID_X16</ROLLNAME>
<ADMINFIELD>0</ADMINFIELD>
<NOTNULL>X</NOTNULL>
<COMPTYPE>E</COMPTYPE>
</DD03P>
<DD03P>
<FIELDNAME>NUM1</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>ARITHM_OP</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000002</INTLEN>
<DATATYPE>CHAR</DATATYPE>
<LENG>000001</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>NUM2</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CALC_RESULT</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>g</INTTYPE>
<INTLEN>000008</INTLEN>
<DATATYPE>STRG</DATATYPE>
<MASK> STRG</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CREA_DATE_TIME</FIELDNAME>
<ROLLNAME>TIMESTAMPL</ROLLNAME>
<ADMINFIELD>0</ADMINFIELD>
<COMPTYPE>E</COMPTYPE>
</DD03P>
<DD03P>
<FIELDNAME>LCHG_DATE_TIME</FIELDNAME>
<ROLLNAME>TIMESTAMPL</ROLLNAME>
<ADMINFIELD>0</ADMINFIELD>
<COMPTYPE>E</COMPTYPE>
</DD03P>
<DD03P>
<FIELDNAME>.INCLUDE</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<PRECFIELD>SYCH_BDL_DRAFT_ADMIN_INC</PRECFIELD>
<MASK> S</MASK>
<DDTEXT>Standard Include for Draft Administration (BDL Syntax Check)</DDTEXT>
<COMPTYPE>S</COMPTYPE>
<GROUPNAME>%ADMIN</GROUPNAME>
</DD03P>
</DD03P_TABLE>
<TABL_EXTRAS>
<TDDAT>
<TABNAME>ZDEMO_ABAP_DRAFT</TABNAME>
<CCLASS>CUS_DEV_SUP_DA</CCLASS>
</TDDAT>
</TABL_EXTRAS>
</asx:values>
</asx:abap>
</abapGit>

182
src/zdemo_abap_fli.tabl.xml Normal file
View File

@@ -0,0 +1,182 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_TABL" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DD02V>
<TABNAME>ZDEMO_ABAP_FLI</TABNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<TABCLASS>TRANSP</TABCLASS>
<CLIDEP>X</CLIDEP>
<DDTEXT>Demo table: Flight</DDTEXT>
<MASTERLANG>E</MASTERLANG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_FLI</TABNAME>
<AS4LOCAL>A</AS4LOCAL>
<TABKAT>0</TABKAT>
<TABART>APPL0</TABART>
<BUFALLOW>N</BUFALLOW>
</DD09L>
<DD03P_TABLE>
<DD03P>
<FIELDNAME>MANDT</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CLNT</DATATYPE>
<LENG>000003</LENG>
<MASK> CLNT</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CARRID</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000003</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CONNID</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>N</INTTYPE>
<INTLEN>000008</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>NUMC</DATATYPE>
<LENG>000004</LENG>
<MASK> NUMC</MASK>
</DD03P>
<DD03P>
<FIELDNAME>FLDATE</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>D</INTTYPE>
<INTLEN>000016</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>DATS</DATATYPE>
<LENG>000008</LENG>
<MASK> DATS</MASK>
<SHLPORIGIN>T</SHLPORIGIN>
</DD03P>
<DD03P>
<FIELDNAME>PRICE</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>P</INTTYPE>
<INTLEN>000008</INTLEN>
<REFTABLE>ZDEMO_ABAP_FLI</REFTABLE>
<REFFIELD>CURRENCY</REFFIELD>
<DATATYPE>CURR</DATATYPE>
<LENG>000015</LENG>
<DECIMALS>000002</DECIMALS>
<MASK> CURR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CURRENCY</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000010</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CUKY</DATATYPE>
<LENG>000005</LENG>
<MASK> CUKY</MASK>
</DD03P>
<DD03P>
<FIELDNAME>PLANETYPE</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000020</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000010</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>SEATSMAX</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>SEATSOCC</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>PAYMENTSUM</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>P</INTTYPE>
<INTLEN>000009</INTLEN>
<REFTABLE>ZDEMO_ABAP_FLI</REFTABLE>
<REFFIELD>CURRENCY</REFFIELD>
<NOTNULL>X</NOTNULL>
<DATATYPE>CURR</DATATYPE>
<LENG>000017</LENG>
<DECIMALS>000002</DECIMALS>
<MASK> CURR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>SEATSMAX_B</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>SEATSOCC_B</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>SEATSMAX_F</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>SEATSOCC_F</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
</DD03P_TABLE>
<TABL_EXTRAS>
<TDDAT>
<TABNAME>ZDEMO_ABAP_FLI</TABNAME>
<CCLASS>CUS_DEV_SUP_DA</CCLASS>
</TDDAT>
</TABL_EXTRAS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,199 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_TABL" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DD02V>
<TABNAME>ZDEMO_ABAP_FLSCH</TABNAME>
<DDLANGUAGE>E</DDLANGUAGE>
<TABCLASS>TRANSP</TABCLASS>
<CLIDEP>X</CLIDEP>
<DDTEXT>Demo table: Flight schedule</DDTEXT>
<MASTERLANG>E</MASTERLANG>
<MAINFLAG>X</MAINFLAG>
<CONTFLAG>A</CONTFLAG>
<EXCLASS>1</EXCLASS>
</DD02V>
<DD09L>
<TABNAME>ZDEMO_ABAP_FLSCH</TABNAME>
<AS4LOCAL>A</AS4LOCAL>
<TABKAT>0</TABKAT>
<TABART>APPL0</TABART>
<BUFALLOW>N</BUFALLOW>
</DD09L>
<DD03P_TABLE>
<DD03P>
<FIELDNAME>MANDT</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CLNT</DATATYPE>
<LENG>000003</LENG>
<MASK> CLNT</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CARRID</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000003</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CONNID</FIELDNAME>
<KEYFLAG>X</KEYFLAG>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>N</INTTYPE>
<INTLEN>000008</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>NUMC</DATATYPE>
<LENG>000004</LENG>
<MASK> NUMC</MASK>
</DD03P>
<DD03P>
<FIELDNAME>COUNTRYFR</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<DATATYPE>CHAR</DATATYPE>
<LENG>000003</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CITYFROM</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000040</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000020</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>AIRPFROM</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000003</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>COUNTRYTO</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<DATATYPE>CHAR</DATATYPE>
<LENG>000003</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>CITYTO</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000040</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000020</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>AIRPTO</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000003</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>FLTIME</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000004</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT4</DATATYPE>
<LENG>000010</LENG>
<MASK> INT4</MASK>
</DD03P>
<DD03P>
<FIELDNAME>DEPTIME</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>T</INTTYPE>
<INTLEN>000012</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>TIMS</DATATYPE>
<LENG>000006</LENG>
<MASK> TIMS</MASK>
<SHLPORIGIN>T</SHLPORIGIN>
</DD03P>
<DD03P>
<FIELDNAME>ARRTIME</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>T</INTTYPE>
<INTLEN>000012</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>TIMS</DATATYPE>
<LENG>000006</LENG>
<MASK> TIMS</MASK>
<SHLPORIGIN>T</SHLPORIGIN>
</DD03P>
<DD03P>
<FIELDNAME>DISTANCE</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>P</INTTYPE>
<INTLEN>000005</INTLEN>
<REFTABLE>ZDEMO_ABAP_FLSCH</REFTABLE>
<REFFIELD>DISTID</REFFIELD>
<NOTNULL>X</NOTNULL>
<DATATYPE>QUAN</DATATYPE>
<LENG>000009</LENG>
<DECIMALS>000004</DECIMALS>
<MASK> QUAN</MASK>
</DD03P>
<DD03P>
<FIELDNAME>DISTID</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000006</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>UNIT</DATATYPE>
<LENG>000003</LENG>
<MASK> UNIT</MASK>
</DD03P>
<DD03P>
<FIELDNAME>FLTYPE</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>C</INTTYPE>
<INTLEN>000002</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>CHAR</DATATYPE>
<LENG>000001</LENG>
<MASK> CHAR</MASK>
</DD03P>
<DD03P>
<FIELDNAME>PERIOD</FIELDNAME>
<ADMINFIELD>0</ADMINFIELD>
<INTTYPE>X</INTTYPE>
<INTLEN>000001</INTLEN>
<NOTNULL>X</NOTNULL>
<DATATYPE>INT1</DATATYPE>
<LENG>000003</LENG>
<MASK> INT1</MASK>
</DD03P>
</DD03P_TABLE>
<TABL_EXTRAS>
<TDDAT>
<TABNAME>ZDEMO_ABAP_FLSCH</TABNAME>
<CCLASS>CUS_DEV_SUP_DA</CCLASS>
</TDDAT>
</TABL_EXTRAS>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,31 @@
***********************************************************************
* ---------------------------- PURPOSE --------------------------------
* Interface to support the ABAP cheat sheet: ABAP Unit Tests
*
* ----------------------------- NOTE ----------------------------------
* The code presented in this class is only meant for supporting the ABAP
* cheat sheets. It is not intended for direct use in a
* production system environment. The code examples in the ABAP cheat
* sheets are primarily intended to provide a better explanation and
* visualization of the syntax and semantics of ABAP statements and not to
* solve concrete programming tasks. For production application programs,
* a dedicated solution should therefore always be worked out for each
* individual case. There is no guarantee for either the correctness or
* the completeness of the code. In addition, there is no legal
* responsibility or liability for possible errors or their consequences
* which occur through the use of the example code.
*
***********************************************************************
"! <p class="shorttext synchronized">Interface for ABAP cheat sheet example</p>
"! The interface supports the ABAP cheat sheet: ABAP Unit Tests.
INTERFACE zdemo_abap_get_data_itf
PUBLIC.
TYPES: carr_tab TYPE TABLE OF zdemo_abap_fli WITH EMPTY KEY,
occ_rate TYPE p LENGTH 4 DECIMALS 2.
METHODS: select_flight_data IMPORTING carrier TYPE zdemo_abap_fli-carrid
RETURNING VALUE(flight_data) TYPE carr_tab,
say_hello RETURNING VALUE(hi) TYPE string.
ENDINTERFACE.

Some files were not shown because too many files have changed in this diff Show More