This commit is contained in:
danrega
2024-01-04 17:12:05 +01:00
parent 743c5630cf
commit 4e086b5b5f
156 changed files with 38507 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,20 @@
"Initial commit" [![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/abap-cheat-sheets)](https://api.reuse.software/info/github.com/SAP-samples/abap-cheat-sheets)
# ABAP Cheat Sheets for Classic ABAP
- ABAP version: **7.58**
- More Information: [https://github.com/SAP-samples/abap-cheat-sheets](https://github.com/SAP-samples/abap-cheat-sheets)
## ⚠️ Disclaimer
The code examples presented in this repository are only syntax examples and are not intended for direct use in a production system environment. The code examples 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.
<br>
## 📟 Support
This is not intended to be a contribution repository, so please do not create pull requests. If you like to address issues or suggestions, please create an issue. However, this project is provided "as-is": there is no guarantee that raised issues will be answered or addressed in future releases.
<br>
## 📜 License
Copyright (c) 2022 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the [LICENSE](LICENSE) file.

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,741 @@
***********************************************************************
*
* ABAP cheat sheet: Selection screens and classic lists
* Example: SAP List Viewer (ALV)
*
* -------------------------- PURPOSE ----------------------------------
* Example that demonstrates a selection of SAP List Viewer (ALV)-related
* options:
* - Layout-related options
* - Setting the header title
* - Optimizing column width
* - Setting filter
* - Setting short, medium and long texts of particular columns
* - Setting the text alignment of a particular column
* - Setting the visibility of a particular column
* - Setting the color of table columns
* - Setting the color of table cells
* - Setting the color of table rows
* - Setting table rows to a striped pattern
* - Setting text properties such as alignment and blanks (not zeroes)
* - Displaying horizontal and vertical grid lines
* - Displaying as popup
* - Functionality
* - Single click events/hotspots
* - Double click events
* - Custom functions
* - Generic functions
* - Adding aggregations
* - Sepcifying selection types
* - Specifying tooltips
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the program with the ABAP development tools for Eclipse (ADT).
* - Choose F8 to run 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.
*
***********************************************************************
PROGRAM.
SELECTION-SCREEN: COMMENT 1(70) intro1,
COMMENT /1(70) intro2,
COMMENT /1(70) intro3,
SKIP.
SELECTION-SCREEN BEGIN OF BLOCK layout WITH FRAME TITLE t2.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS setheadr TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t4,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS opt TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t6,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS sort TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t7,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS colheadr TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t8,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS selct TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t10,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS colors TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t11,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS filter TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t12,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS txtprop TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t13,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS lines TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t14,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS tool TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t15,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS popup TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t16,
END OF LINE.
SELECTION-SCREEN END OF BLOCK layout.
SELECTION-SCREEN BEGIN OF BLOCK ev_fu WITH FRAME TITLE t17.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS aggreg TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t18,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS hotspots TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t19,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS doublecl TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t20,
END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS func TYPE c AS CHECKBOX.
SELECTION-SCREEN: COMMENT 3(70) t21,
END OF LINE.
SELECTION-SCREEN END OF BLOCK ev_fu.
"Adding a pushbutton in the application toolbar
TABLES sscrfields.
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN FUNCTION KEY 2.
TYPES: BEGIN OF flight_struc,
carrid TYPE zdemo_abap_fli-carrid,
connid TYPE zdemo_abap_fli-connid,
fldate TYPE zdemo_abap_fli-fldate,
price TYPE zdemo_abap_fli-price,
currency TYPE zdemo_abap_fli-currency,
planetype TYPE zdemo_abap_fli-planetype,
text TYPE string,
seatsmax TYPE zdemo_abap_fli-seatsmax,
seatsocc TYPE zdemo_abap_fli-seatsocc,
seatsfree TYPE i,
occrate TYPE p LENGTH 5 DECIMALS 2,
seatstat TYPE icon_d,
colored TYPE lvc_t_scol,
hotspot TYPE icon_d,
END OF flight_struc.
DATA itab4alv TYPE TABLE OF flight_struc WITH EMPTY KEY.
DATA alv TYPE REF TO cl_salv_table.
DATA already_updated TYPE abap_bool.
**********************************************************************
"Local classes for modularization purposes
"Class to handle events
CLASS lcl_events DEFINITION.
PUBLIC SECTION.
CLASS-METHODS click_hotspot
FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
CLASS-METHODS double_click
FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
CLASS-METHODS func_click
FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function.
ENDCLASS.
CLASS lcl_events IMPLEMENTATION.
METHOD click_hotspot.
READ TABLE itab4alv INDEX row REFERENCE INTO DATA(sc_ref).
IF sy-subrc = 0.
ASSIGN sc_ref->(column) TO FIELD-SYMBOL(<fs_sc>).
MESSAGE `Single click event. ` &&
|Row: { row } { COND #( WHEN column IS NOT INITIAL THEN `Column: ` && column ) } | &&
|{ COND #( WHEN <fs_sc> IS ASSIGNED THEN `Value: ` && <fs_sc> ) }| TYPE 'I'.
ELSE.
MESSAGE `Single click event` TYPE 'I'.
ENDIF.
ENDMETHOD.
METHOD double_click.
READ TABLE itab4alv INDEX row REFERENCE INTO DATA(dc_ref).
IF sy-subrc = 0.
ASSIGN dc_ref->(column) TO FIELD-SYMBOL(<fs_dc>).
MESSAGE `Double click event. ` &&
|Row: { row } { COND #( WHEN column IS NOT INITIAL THEN `Column: ` && column ) } | &&
|{ COND #( WHEN <fs_dc> IS ASSIGNED THEN `Value: ` && <fs_dc> ) }| TYPE 'I'.
ELSE.
MESSAGE `Double click event` TYPE 'I'.
ENDIF.
ENDMETHOD.
METHOD func_click.
"Handling custom functions
CASE e_salv_function.
WHEN 'GET_SELECT'.
"This function gets the selected table rows. A message is displayed
"listing the selected rows, if any.
DATA(selections) = alv->get_selections( ).
DATA(selected_rows) = selections->get_selected_rows( ).
IF lines( selected_rows ) IS INITIAL.
MESSAGE 'None of the rows of the displayed internal table have been selected.' TYPE 'I'.
ELSE.
DATA acc_rows TYPE string.
LOOP AT selected_rows REFERENCE INTO DATA(line).
IF sy-tabix = 1.
acc_rows = line->*.
ELSE.
acc_rows = acc_rows && `,` && line->*.
ENDIF.
ENDLOOP.
CONDENSE acc_rows NO-GAPS.
MESSAGE |Selected row{ COND #( WHEN lines( selected_rows ) > 1 THEN `s` ) }: { acc_rows }| TYPE 'I'.
ENDIF.
WHEN 'CALC'.
"This function performs a calculation. It calculates the number of free seats
"and the occupancy rate of the seats.
"Using the 'refresh' method, the table is refreshed, and the calculated values
"are diplayed in the respective columns.
IF already_updated = abap_true.
MESSAGE 'The values have already been calculated.' TYPE 'I'.
ELSE.
LOOP AT itab4alv REFERENCE INTO DATA(calc).
calc->seatsfree = calc->seatsmax - calc->seatsocc.
TRY.
calc->occrate = |{ CONV decfloat34( ( calc->seatsocc / calc->seatsmax ) * 100 ) DECIMALS = 2 }|.
IF calc->occrate >= 95.
calc->seatstat = icon_red_light.
ELSEIF calc->occrate < 95 AND calc->occrate > 75.
calc->seatstat = icon_yellow_light.
ELSE.
calc->seatstat = icon_green_light.
ENDIF.
CATCH cx_sy_arithmetic_error.
ENDTRY.
ENDLOOP.
MESSAGE 'Values for the SEATSFREE and OCCRATE columns have been calculated and are updated. The SEATSTAT column is updated accordingly.' TYPE 'I'.
already_updated = abap_true.
alv->refresh( ).
ENDIF.
WHEN 'HIDE'.
"This function hides and shows a specific table column.
TRY.
DATA(col) = alv->get_columns( )->get_column( 'HOTSPOT' ).
IF col->is_visible( ).
col->set_visible( abap_false ).
ELSE.
col->set_visible( abap_true ).
ENDIF.
CATCH cx_salv_not_found.
ENDTRY.
ENDCASE.
ENDMETHOD.
ENDCLASS.
**********************************************************************
"Local class to handle the selected checkboxes
CLASS lcl_alv_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS set_header
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS optimize
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS sort
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS misc_column
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS set_filter
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS selection
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS coloring
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS aggregate
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS set_text_properties
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS display_grid_lines
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS display_as_popup
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS use_functions
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS enable_hotspots
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS handle_double_click
IMPORTING checkbox TYPE abap_bool.
CLASS-METHODS tooltips
IMPORTING checkbox TYPE abap_bool.
ENDCLASS.
CLASS lcl_alv_demo IMPLEMENTATION.
METHOD set_header.
IF checkbox = abap_true.
alv->get_display_settings( )->set_list_header( 'Flight Overview' ).
ENDIF.
ENDMETHOD.
METHOD optimize.
IF checkbox = abap_true.
alv->get_columns( )->set_optimize( abap_true ).
ELSE.
alv->get_columns( )->set_optimize( abap_false ).
ENDIF.
ENDMETHOD.
METHOD sort.
IF checkbox = abap_true.
"In this example, a particular column is sorted downwards.
TRY.
alv->get_sorts( )->add_sort( 'CARRID' )->set_sequence( if_salv_c_sort=>sort_down ).
CATCH cx_root.
ENDTRY.
ENDIF.
ENDMETHOD.
METHOD misc_column.
"In this example, several column-related options are covered:
"- Setting short, medium and long texts of particular columns
"- Setting the text alignment of a particular column
"- Setting the visibility of a particular column (here, a column is hidden)
IF checkbox = abap_true.
DATA(columns) = alv->get_columns( )->get( ).
LOOP AT columns REFERENCE INTO DATA(colref).
DATA(column) = colref->r_column.
"Setting short, medium and long texts
column->set_long_text( |{ colref->columnname }| ).
"For testing purposes, you can manually increase the column width for the
"two columns and see how the name changes depending on the column size.
"If optimize is also flagged, all column names are fully displayed.
"In the case of the following two columns, the short text is displayed
"because the values in the column consist of 3 characters only in the example.
IF colref->columnname = 'SEATSMAX'.
column->set_short_text( 'MAX' ).
column->set_medium_text( 'STMAX' ).
ENDIF.
IF colref->columnname = 'SEATSOCC'.
column->set_short_text( 'OCC' ).
column->set_medium_text( 'STOCC' ).
ENDIF.
"Setting the text alignment
IF colref->columnname = 'CURRENCY'.
"Without this setting, the values of the CURRENCY column would be left-aligned by default.
column->set_alignment( if_salv_c_alignment=>right ).
ENDIF.
"Setting the visibility
IF colref->columnname = 'TEXT'.
"without this setting the values of currency column would be left-aligned by default
"left is the default
column->set_visible( abap_false ).
ENDIF.
"Change Position of the Column within the ALV Output
IF colref->columnname = 'SEATSOCC'.
TRY.
DATA(pos) = alv->get_columns( )->get_column_position( 'SEATSMAX' ).
alv->get_columns( )->set_column_position( columnname = 'SEATSOCC' position = pos ).
CATCH cx_salv_not_found.
ENDTRY.
ENDIF.
"The following statements are intended for demonstration purposes. They showcase other
"available methods in this context. You can, for example, set a breakpoint here and
"check the values of the variables in the debugger. Many more methods are available for
"different use cases. The following statements show a selection.
IF colref->columnname = 'CURRENCY'.
DATA(alignm) = column->get_alignment( ).
DATA(col_name) = column->get_columnname( ).
DATA(long_text) = column->get_long_text( ).
DATA(medium_text) = column->get_medium_text( ).
DATA(short_text) = column->get_short_text( ).
DATA(ouput_length) = column->get_output_length( ).
DATA(ddictype) = column->get_ddic_inttype( ).
ENDIF.
ENDLOOP.
ENDIF.
ENDMETHOD.
METHOD set_filter.
IF checkbox = abap_true.
"In this example, a filter is applied on a particular column. Depending on the
"filter setting, table rows are displayed or not.
TRY.
alv->get_filters( )->add_filter( 'PRICE' )->add_selopt( sign = 'I' option = 'BT' low = '0' high = '1100' ).
CATCH cx_salv_existing cx_salv_data_error cx_salv_not_found.
ENDTRY.
ENDIF.
ENDMETHOD.
METHOD aggregate.
IF checkbox = abap_true.
"In this example, an aggregation is added for a particular column.
"In tis case, the average price is calculated. It is displayed in a row added
"to the bottom of the table.
TRY.
alv->get_aggregations( )->add_aggregation( columnname = 'PRICE'
aggregation = if_salv_c_aggregation=>average ).
CATCH cx_salv_data_error cx_salv_not_found cx_salv_existing.
ENDTRY.
ENDIF.
ENDMETHOD.
METHOD selection.
"In this example, the selection type is specified.
DATA(sel) = alv->get_selections( ).
IF checkbox = abap_true.
"Mutliple rows/columns can be selected
sel->set_selection_mode( if_salv_c_selection_mode=>row_column ).
ELSE.
"Individual selection
sel->set_selection_mode( if_salv_c_selection_mode=>single ).
ENDIF.
ENDMETHOD.
METHOD coloring.
"In this example, multiple options are demonstrated to provide color settings:
"- Setting the color of table columns
"- Setting the color of table cells
"- Setting the color of table rows
"- Setting table rows to a striped pattern
IF checkbox = abap_true.
"Setting the color of table columns
TRY.
CAST cl_salv_column_table( alv->get_columns( )->get_column( 'CURRENCY' ) )->set_color( VALUE lvc_s_colo( col = 3 ) ).
CATCH cx_salv_not_found.
ENDTRY.
"Setting the color of table cells
"For this purpose, the internal table has a component of type
"lvc_t_scol, which is used for cell coloring here.
"In the example, the color for cells in a particular column are set
"based on a condition. Intensified and inverse values are explicitly
"set to 'off'.
LOOP AT itab4alv REFERENCE INTO DATA(coloredcell) WHERE price < 300.
APPEND VALUE #( fname = 'PRICE'
color-col = col_positive
color-int = 0
color-inv = 0 ) TO coloredcell->colored.
ENDLOOP.
"Setting the color of table rows
"Also here, the component of type lvc_t_scol is used. When the internal
"table row is added, the name of the field is omitted so that the color is
"set for the entire table row.
LOOP AT itab4alv REFERENCE INTO DATA(coloredrow) WHERE carrid = 'LH'.
APPEND VALUE #( color-col = col_group ) TO coloredrow->colored.
ENDLOOP.
"Applying the color settings
TRY.
alv->get_columns( )->set_color_column( 'COLORED' ).
CATCH cx_salv_data_error.
ENDTRY.
"Setting table rows to a striped pattern
alv->get_display_settings( )->set_striped_pattern( abap_true ).
ENDIF.
ENDMETHOD.
METHOD set_text_properties.
IF checkbox = abap_true.
"In this example, a selection of text property-specific options is demonstrated.
TRY.
"Setting the text alignment of table rows
CAST cl_salv_column( alv->get_columns( )->get_column( 'SEATSOCC' ) )->set_alignment( if_salv_c_alignment=>left ).
"Setting blanks instead of zeroes
CAST cl_salv_column( alv->get_columns( )->get_column( 'SEATSFREE' ) )->set_zero( abap_false ).
CAST cl_salv_column( alv->get_columns( )->get_column( 'OCCRATE' ) )->set_zero( abap_false ).
CATCH cx_salv_not_found.
ENDTRY.
ENDIF.
ENDMETHOD.
METHOD display_grid_lines.
"In this example, horizontal and vertical ALV grid lines are set to be either displayed
"or not.
IF checkbox = abap_true.
alv->get_display_settings( )->set_horizontal_lines( abap_true ).
alv->get_display_settings( )->set_vertical_lines( abap_true ).
ELSE.
alv->get_display_settings( )->set_horizontal_lines( abap_false ).
alv->get_display_settings( )->set_vertical_lines( abap_false ).
ENDIF.
ENDMETHOD.
METHOD display_as_popup.
"In this example, the ALV output is displayed in a dialog box. Demo coordinates
"are provided.
IF checkbox = abap_true.
alv->set_screen_popup( start_column = 10
end_column = 100
start_line = 4
end_line = 15 ).
ENDIF.
ENDMETHOD.
METHOD use_functions.
"In this example, a custom GUI status is set. All functions are set.
"The custom GUI status is included in the cheat sheet example program.
"If the checkbox is not selected, the generic ALV functions are set.
IF checkbox = abap_true.
alv->set_screen_status(
pfstatus = 'DEMO_STATUS_ALV'
report = sy-repid
set_functions = alv->c_functions_all ).
"You can check the results of the following method calls in the debugger.
DATA(getfunc) = alv->get_functions( ).
"Checking the activation status
DATA(is_enabled) = getfunc->is_enabled( 'GET_SELECT' ).
"Checking the visibility
DATA(is_visible) = getfunc->is_visible( 'GET_SELECT' ).
"Registering an event handler for the custom functions
SET HANDLER lcl_events=>func_click FOR alv->get_event( ).
ELSE.
alv->get_functions( )->set_default( abap_true ).
ENDIF.
ENDMETHOD.
METHOD enable_hotspots.
"This example demonstrates hotspots/single click events. Here,
"the cell type of a particular column is set as hotspot. Plus,
"an event handler is registered to handle the hotspot click event.
IF checkbox = abap_true.
TRY.
CAST cl_salv_column_table( alv->get_columns( )->get_column( 'CONNID' ) )->set_cell_type( if_salv_c_cell_type=>hotspot ).
CAST cl_salv_column_table( alv->get_columns( )->get_column( 'HOTSPOT' ) )->set_cell_type( if_salv_c_cell_type=>hotspot ).
SET HANDLER lcl_events=>click_hotspot FOR alv->get_event( ).
CATCH cx_salv_not_found.
ENDTRY.
ENDIF.
ENDMETHOD.
METHOD handle_double_click.
"This example demonstrates the double click event. See the implementation
"in the local class for events. The implementation simlpy raises a
"message.
IF checkbox = abap_true.
SET HANDLER lcl_events=>double_click FOR alv->get_event( ).
ENDIF.
ENDMETHOD.
METHOD tooltips.
"This example demonstrates tooltips for the following use cases:
"- A tooltip is added to a particular column. This column is set as icon column.
" When you hover over the icon in the column, the tooltip is diplayed.
"- Tooltips are added for particular column headers.
IF checkbox = abap_true.
TRY.
"Tooltip for icons
CAST cl_salv_column_table( alv->get_columns( )->get_column( 'HOTSPOT' ) )->set_icon( if_salv_c_bool_sap=>true ).
alv->get_functional_settings( )->get_tooltips( )->add_tooltip( type = cl_salv_tooltip=>c_type_icon
value = CONV lvc_value( icon_abap )
tooltip = `This is a tooltip for an icon` ).
"Tooltips for column headers
CAST cl_salv_column_table( alv->get_columns( )->get_column( 'CARRID' ) )->set_tooltip( 'Tooltip 1' ).
CAST cl_salv_column_table( alv->get_columns( )->get_column( 'CONNID' ) )->set_tooltip( 'Tooltip 2' ).
CAST cl_salv_column_table( alv->get_columns( )->get_column( 'FLDATE' ) )->set_tooltip( 'Tooltip 3' ).
CAST cl_salv_column_table( alv->get_columns( )->get_column( 'PRICE' ) )->set_tooltip( 'Tooltip 4' ).
CATCH cx_salv_not_found cx_salv_existing.
ENDTRY.
ENDIF.
ENDMETHOD.
ENDCLASS.
**********************************************************************
INITIALIZATION.
"Filling demo database tables to select from
zcl_demo_abap_aux=>fill_dbtabs( ).
"Providing text
intro1 = 'This example demonstrates the SAP List Viewer (ALV).'.
intro2 = 'Select checkboxes to determine ALV-related aspects and functionality.'.
intro3 = 'After you have selected checkboxes of your choice, choose Execute/F8.'.
t2 = 'ALV layout-related options'.
t4 = 'Set title'.
t6 = 'Optimize column width'.
t7 = 'Sort a column'.
t8 = 'Misc settings (column names, visibility, positioning)'.
t10 = 'Selection options'.
t11 = 'Set colors'.
t12 = 'Set filter'.
t13 = 'Set text properties'.
t14 = 'Display grid lines'.
t15 = 'Tooltips'.
t16 = 'Display as popup'.
t17 = 'Functions and events'.
t18 = 'Aggregate'.
t19 = 'Hotspots (single-click events)'.
t20 = 'Handle double clicks'.
t21 = 'Use custom functions (else generic functions)'.
sscrfields-functxt_01 = 'Select all checkboxes (no popup)'.
sscrfields-functxt_02 = 'Deselect all checkboxes'.
**********************************************************************
AT SELECTION-SCREEN.
"For convenience, buttons are included that select most checkboxes and
"deselect all checkboxes when clicked.
CASE sscrfields-ucomm.
WHEN 'FC01'.
setheadr = abap_true.
opt = abap_true.
sort = abap_true.
filter = abap_true.
colheadr = abap_true.
selct = abap_true.
colors = abap_true.
filter = abap_true.
txtprop = abap_true.
lines = abap_true.
tool = abap_true.
popup = abap_false.
aggreg = abap_true.
hotspots = abap_true.
doublecl = abap_true.
func = abap_true.
WHEN 'FC02'.
setheadr = abap_false.
opt = abap_false.
sort = abap_false.
filter = abap_false.
colheadr = abap_false.
selct = abap_false.
colors = abap_false.
filter = abap_false.
txtprop = abap_false.
lines = abap_false.
tool = abap_false.
popup = abap_false.
aggreg = abap_false.
hotspots = abap_false.
doublecl = abap_false.
func = abap_false.
ENDCASE.
**********************************************************************
START-OF-SELECTION.
CLEAR alv.
"Populating internal table
SELECT carrid, connid, fldate, price, currency, planetype, seatsmax, seatsocc
FROM zdemo_abap_fli
ORDER BY carrid, connid
INTO CORRESPONDING FIELDS OF TABLE @itab4alv.
"Providing values for a particular column for demo purposes
LOOP AT itab4alv REFERENCE INTO DATA(ref).
ref->hotspot = icon_abap.
ENDLOOP.
"Instantiating an ALV table object
"Note: In this example, the ALV is not included in a container. Therefore,
"the other exporting parameters are irrelevant. The list_display parameter is
"used to set the display type, which is set here based on user input.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = alv
CHANGING
t_table = itab4alv ).
"The following methods include the actual implementations for the ALV display and functionality.
"Based on the selection of the checkboxes on the selection screen, the implementation is either
"used or not. See comments in the method implementations.
lcl_alv_demo=>set_header( setheadr ).
lcl_alv_demo=>optimize( opt ).
lcl_alv_demo=>sort( sort ).
lcl_alv_demo=>misc_column( colheadr ).
lcl_alv_demo=>set_filter( filter ).
lcl_alv_demo=>aggregate( aggreg ).
lcl_alv_demo=>selection( selct ).
lcl_alv_demo=>coloring( colors ).
lcl_alv_demo=>set_text_properties( txtprop ).
lcl_alv_demo=>display_grid_lines( lines ).
lcl_alv_demo=>display_as_popup( popup ).
lcl_alv_demo=>use_functions( func ).
lcl_alv_demo=>enable_hotspots( hotspots ).
lcl_alv_demo=>handle_double_click( doublecl ).
lcl_alv_demo=>tooltips( tool ).
"Displaying the ALV
alv->display( ).
CATCH cx_root INTO DATA(error).
"Note: For simplicity, this example uses the root exception class. Always make
"sure that you use appropriate exception classes.
MESSAGE error->get_text( ) TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.

View File

@@ -0,0 +1,195 @@
<?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_ALV</NAME>
<DBAPL>S</DBAPL>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<CUA>
<ADM>
<ACTCODE>000001</ACTCODE>
<PFKCODE>000001</PFKCODE>
</ADM>
<STA>
<RSMPE_STAT>
<CODE>DEMO_STATUS_ALV</CODE>
<MODAL>D</MODAL>
<ACTCODE>000001</ACTCODE>
<PFKCODE>000001</PFKCODE>
<BUTCODE>0001</BUTCODE>
<INT_NOTE>Demo Status</INT_NOTE>
</RSMPE_STAT>
</STA>
<FUN>
<RSMPE_FUNT>
<CODE>&amp;F03</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<FUN_TEXT>Back</FUN_TEXT>
</RSMPE_FUNT>
<RSMPE_FUNT>
<CODE>&amp;F12</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<TEXT_NAME>ICON_CANCEL</TEXT_NAME>
<ICON_ID>@0W@</ICON_ID>
<FUN_TEXT>Cancel</FUN_TEXT>
</RSMPE_FUNT>
<RSMPE_FUNT>
<CODE>&amp;F15</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<FUN_TEXT>Exit</FUN_TEXT>
</RSMPE_FUNT>
<RSMPE_FUNT>
<CODE>CALC</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<TEXT_NAME>ICON_CALCULATION</TEXT_NAME>
<ICON_ID>@0M@</ICON_ID>
<FUN_TEXT>Calculations</FUN_TEXT>
<ICON_TEXT>Calculate values</ICON_TEXT>
<INFO_TEXT>Perform calculations</INFO_TEXT>
</RSMPE_FUNT>
<RSMPE_FUNT>
<CODE>GET_SELECT</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<TEXT_NAME>ICON_ABAP_LOCAL</TEXT_NAME>
<ICON_ID>@9V@</ICON_ID>
<FUN_TEXT>Selected rows</FUN_TEXT>
<ICON_TEXT>Get selected rows</ICON_TEXT>
<INFO_TEXT>Get selected rows</INFO_TEXT>
</RSMPE_FUNT>
<RSMPE_FUNT>
<CODE>HIDE</CODE>
<TEXTNO>001</TEXTNO>
<TEXT_TYPE>S</TEXT_TYPE>
<TEXT_NAME>ICON_VIEW_TABLE</TEXT_NAME>
<ICON_ID>@XD@</ICON_ID>
<FUN_TEXT>Hide/Show column</FUN_TEXT>
<ICON_TEXT>Hide/Show column</ICON_TEXT>
<INFO_TEXT>Hide/Show HOTSPOT column</INFO_TEXT>
</RSMPE_FUNT>
</FUN>
<BUT>
<RSMPE_BUT>
<PFK_CODE>000001</PFK_CODE>
<CODE>0001</CODE>
<NO>01</NO>
<PFNO>05</PFNO>
</RSMPE_BUT>
<RSMPE_BUT>
<PFK_CODE>000001</PFK_CODE>
<CODE>0001</CODE>
<NO>02</NO>
<PFNO>06</PFNO>
</RSMPE_BUT>
<RSMPE_BUT>
<PFK_CODE>000001</PFK_CODE>
<CODE>0001</CODE>
<NO>03</NO>
<PFNO>07</PFNO>
</RSMPE_BUT>
</BUT>
<PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>03</PFNO>
<FUNCODE>&amp;F03</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>05</PFNO>
<FUNCODE>GET_SELECT</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>06</PFNO>
<FUNCODE>CALC</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>07</PFNO>
<FUNCODE>HIDE</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>12</PFNO>
<FUNCODE>&amp;F12</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
<RSMPE_PFK>
<CODE>000001</CODE>
<PFNO>15</PFNO>
<FUNCODE>&amp;F15</FUNCODE>
<FUNNO>001</FUNNO>
</RSMPE_PFK>
</PFK>
<SET>
<RSMPE_STAF>
<STATUS>DEMO_STATUS_ALV</STATUS>
<FUNCTION>&amp;F03</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>DEMO_STATUS_ALV</STATUS>
<FUNCTION>&amp;F12</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>DEMO_STATUS_ALV</STATUS>
<FUNCTION>&amp;F15</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>DEMO_STATUS_ALV</STATUS>
<FUNCTION>CALC</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>DEMO_STATUS_ALV</STATUS>
<FUNCTION>GET_SELECT</FUNCTION>
</RSMPE_STAF>
<RSMPE_STAF>
<STATUS>DEMO_STATUS_ALV</STATUS>
<FUNCTION>HIDE</FUNCTION>
</RSMPE_STAF>
</SET>
<DOC>
<RSMPE_ATRT>
<OBJ_TYPE>A</OBJ_TYPE>
<OBJ_CODE>000001</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Demo Status</INT_NOTE>
</RSMPE_ATRT>
<RSMPE_ATRT>
<OBJ_TYPE>P</OBJ_TYPE>
<OBJ_CODE>000001</OBJ_CODE>
<MODAL>D</MODAL>
<INT_NOTE>Demo Status</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>Demo Status</INT_NOTE>
</RSMPE_ATRT>
</DOC>
</CUA>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>ABAP Cheat Sheet Example: ALV</ENTRY>
<LENGTH>29</LENGTH>
</item>
</TPOOL>
</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_aux=>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,403 @@
***********************************************************************
*
* ABAP cheat sheet: Selection screens and classic lists
* Example: Event blocks
*
* -------------------------- PURPOSE ----------------------------------
* - Example that demonstrates event blocks
* - The main purpose of the example to visualize the calling of the
* events. Internal tables are filled during the events to log the
* event name and the time stamp when it is called. The tables
* are then output. It is implemented in such a way that it consists
* only of a basic list and a details list. Note the selection screen
* comments displayed.
* Includes:
* - Program constructor: LOAD-OF-PROGRAM
* - Reporting events: INITIALIZATION, START-OF-SELECTION
* - Selection screen events: AT SELECTION-SCREEN ...
* - List events: AT LINE-SELECTION, AT USER-COMMAND, TOP-OF-PAGE,
* END-OF-PAGE
*
* Notes:
* A selection of additions is used. For more additions and details,
* see the ABAP Keyword Documentation.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the program with the ABAP development tools for Eclipse (ADT).
* - Choose F8 to run 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.
*
***********************************************************************
"LINE-COUNT: Specifies the page length for the basic list
"Number in parentheses: Lines that are reserved for the page footer,
"which can be specified in the END-OF-PAGE event block.
PROGRAM LINE-COUNT 20(3).
TYPES: BEGIN OF st,
id TYPE c LENGTH 3,
event_block TYPE c LENGTH 50,
time TYPE utclong,
END OF st.
DATA: counter_line TYPE i,
reporting_and_selscr_log TYPE TABLE OF st WITH EMPTY KEY,
list_log TYPE TABLE OF st WITH EMPTY KEY,
counter TYPE i,
tstmp TYPE utclong.
SELECTION-SCREEN COMMENT /1(70) intro.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK blk.
PARAMETERS: number1 TYPE string DEFAULT `1` VISIBLE LENGTH 5 .
PARAMETERS: number2 TYPE string DEFAULT `2` VISIBLE LENGTH 5 .
SELECTION-SCREEN END OF BLOCK blk.
PARAMETERS: plus RADIOBUTTON GROUP grp DEFAULT 'X',
minus RADIOBUTTON GROUP grp,
multiply RADIOBUTTON GROUP grp,
divide RADIOBUTTON GROUP grp.
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN COMMENT /1(70) note.
"Local class with methods used in the example in various places
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
sel_screen_evt IMPORTING evt TYPE string,
write_line IMPORTING evt TYPE string
utc TYPE utclong,
counter,
list_evt IMPORTING evt TYPE string,
write_rep_sel_log,
write_list_log.
CLASS-DATA: li_wa LIKE LINE OF list_log,
sel_wa LIKE LINE OF reporting_and_selscr_log.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD counter.
IF counter = 0.
counter = 1.
ELSE.
counter += 1.
ENDIF.
ENDMETHOD.
METHOD sel_screen_evt.
counter( ).
APPEND VALUE #( id = counter event_block = evt time = utclong_current( ) ) TO reporting_and_selscr_log.
ENDMETHOD.
METHOD list_evt.
counter( ).
APPEND VALUE #( id = counter event_block = evt time = utclong_current( ) ) TO list_log.
ENDMETHOD.
METHOD write_line.
counter( ).
WRITE: /3(*) counter,
15 evt,
60 utc.
ENDMETHOD.
METHOD write_rep_sel_log.
SKIP.
WRITE / '********** Log entries for reporting and selection screen events **********' COLOR 2.
FORMAT COLOR 2.
WRITE: /3 'ID', 15 'Event Block', 60 'Time' .
FORMAT COLOR OFF.
LOOP AT reporting_and_selscr_log INTO sel_wa.
WRITE: / sel_wa-id UNDER 'ID',
sel_wa-event_block UNDER 'Event Block',
sel_wa-time UNDER 'Time'.
ENDLOOP.
ENDMETHOD.
METHOD write_list_log.
WRITE / '********** Log entries for list events **********' COLOR 2.
FORMAT COLOR 2.
WRITE: /3 'ID', 15 'Event Block', 60 'Time' .
FORMAT COLOR OFF.
LOOP AT list_log INTO li_wa.
WRITE: / li_wa-id UNDER 'ID',
li_wa-event_block UNDER 'Event Block',
li_wa-time UNDER 'Time'.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
**********************************************************************
LOAD-OF-PROGRAM.
"Called when a program is loaded into the internal session
"When you call an executable programs with SUBMIT, it is recommended that
"you use the INITIALIZATION event for initializing data objects, since the
"initial values for parameters and selection criteria are set after LOAD-OF-PROGRAM.
demo=>sel_screen_evt( `LOAD-OF-PROGRAM` ).
**********************************************************************
INITIALIZATION.
"Called immediately after LOAD-OF-PROGRAM and before the selection
"screen processing of an existing standard selection screen.
"You can initialize the input fields of the selection screen here.
demo=>sel_screen_evt( `INITIALIZATION` ).
intro = 'Enter two integers and select a radio button for a calculation.'.
note = 'The Back/Exit/Cancel buttons raise the ON EXIT-COMMAND event.'.
**********************************************************************
AT SELECTION-SCREEN OUTPUT.
"Called by the dynpro event PBO of a selection screen
"Can be used for screen modifications.
demo=>sel_screen_evt( `AT SELECTION-SCREEN OUTPUT` ).
LOOP AT SCREEN INTO DATA(wa).
IF wa-name = 'INTRO'.
wa-intensified = '1'.
MODIFY SCREEN FROM wa.
ENDIF.
ENDLOOP.
**********************************************************************
AT SELECTION-SCREEN ON RADIOBUTTON GROUP grp.
"Called when the values for a radio button group was passed
demo=>sel_screen_evt( `AT SELECTION-SCREEN ON RADIOBUTTON GROUP` ).
CASE 'X'.
WHEN plus.
MESSAGE 'Event AT SELECTION-SCREEN ON RADIOBUTTON GROUP is called. The operator will be +' TYPE 'I'.
WHEN minus.
MESSAGE 'Event AT SELECTION-SCREEN ON RADIOBUTTON GROUP is called. The operator will be -' TYPE 'I'.
WHEN multiply.
MESSAGE 'Event AT SELECTION-SCREEN ON RADIOBUTTON GROUP is called. The operator will be *' TYPE 'I'.
WHEN divide.
MESSAGE 'Event AT SELECTION-SCREEN ON RADIOBUTTON GROUP is called. The operator will be /' TYPE 'I'.
ENDCASE.
**********************************************************************
AT SELECTION-SCREEN ON BLOCK blk.
"Called when all input for a block is passed to the program
demo=>sel_screen_evt( `AT SELECTION-SCREEN ON BLOCK blk` ).
CONDENSE number1 NO-GAPS.
CONDENSE number2 NO-GAPS.
FIND PCRE `\D` IN number1.
DATA(subrc) = sy-subrc.
FIND PCRE `\D` IN number2.
IF subrc = 0
OR sy-subrc = 0.
MESSAGE 'Event AT SELECTION-SCREEN ON BLOCK is called. Provide correct integer values.' TYPE 'E'.
ENDIF.
**********************************************************************
AT SELECTION-SCREEN ON number1.
"Called when values for a parameter (which is the case here) or selection criteria were passed to the program
demo=>sel_screen_evt( `AT SELECTION-SCREEN ON number1.` ).
IF number1 IS INITIAL.
MESSAGE 'Event AT SELECTION-SCREEN ON is called. Please make an entry for number1' TYPE 'E'.
ENDIF.
**********************************************************************
AT SELECTION-SCREEN ON number2.
"Called when values for a parameter (which is the case here) or selection criteria were passed to the program
demo=>sel_screen_evt( `AT SELECTION-SCREEN ON number2.` ).
IF number2 IS INITIAL.
MESSAGE 'Please make an entry for number2' TYPE 'E'.
ENDIF.
**********************************************************************
AT SELECTION-SCREEN ON EXIT-COMMAND.
"Called in case of Back, Exit, or Cancel
MESSAGE 'Event AT SELECTION-SCREEN ON EXIT-COMMAND is called. See you.' TYPE 'I'.
**********************************************************************
AT SELECTION-SCREEN.
"Called as last event in the selection screen processing when all
"input values are passed to the program
demo=>sel_screen_evt( `AT SELECTION-SCREEN` ).
IF number2 = 0 AND
divide = 'X'.
MESSAGE 'Event AT SELECTION-SCREEN is called. Zero division is not possible.' TYPE 'E'.
ENDIF.
**********************************************************************
START-OF-SELECTION.
"Called during the processing of an executable program after selection
"screen processing
"SET USER-COMMAND: The following statement is included for demonstration
"purposes. It programmatically raises a list event with a specified function
"code.
"Such a statement can be used when creating a list. After the list has been
"created, but before the current list is displayed, the runtime
"framework responds as if a user action had been performed in the
"displayed list with the specified function code.
SET USER-COMMAND 'START'.
demo=>sel_screen_evt( `START-OF-SELECTION` ).
WRITE / 'This is the basic list showing the content of a log table (mostly reporting and selection screen events). Double-click a line in this list to display more events in a details list.' COLOR 4.
SKIP.
WRITE / '************************** Calculation result **************************' COLOR 2.
IF plus = 'X'.
WRITE / |{ number1 } + { number2 } = { number1 + number2 }|.
ENDIF.
IF minus = 'X'.
WRITE / |{ number1 } - { number2 } = { number1 - number2 }|.
ENDIF.
IF multiply = 'X'.
TRY.
WRITE / |{ number1 } * { number2 } = { number1 * number2 }|.
CATCH cx_sy_arithmetic_error INTO DATA(error).
WRITE / |{ number1 } * { number2 } = ??? Error in multiplication: { error->get_text( ) }| COLOR COL_NEGATIVE.
ENDTRY.
ENDIF.
IF divide = 'X'.
TRY.
WRITE / |{ number1 } / { number2 } = { CONV decfloat34( number1 / number2 ) DECIMALS = 3 }|.
IF number1 = 0 AND number2 = 0.
WRITE / `No zero division error? Note that ABAP "allows" zero division if the first number is also 0 :)` COLOR COL_NEGATIVE.
ENDIF.
CATCH cx_sy_zerodivide INTO error.
WRITE / |{ number1 } / { number2 } = ??? Error in division: { error->get_text( ) }| COLOR COL_NEGATIVE.
ENDTRY.
ENDIF.
IF reporting_and_selscr_log IS NOT INITIAL.
demo=>write_rep_sel_log( ).
ENDIF.
**********************************************************************
AT LINE-SELECTION.
"Called when
"- a screen list is displayed and
"- the screen cursor is on a list line and
"- a function is selected using the function code PICK
demo=>list_evt( evt = `AT LINE-SELECTION` ).
"SET USER-COMMAND: The following statement is included for demonstration
"purposes. It programmatically raises a list event with a specified function
"code.
SET USER-COMMAND 'LINE'.
IF sy-lsind <= 1.
WRITE / 'This is a details list. It shows the content of another log table (mostly list events). Clicking in this list does nothing meaningful.' COLOR 4.
WRITE / 'You may want to go back to the basic list, double-click a line there to come back here, and see more log entries added for list events.' COLOR 4.
WRITE / 'When the counter reaches 40, the program is restarted :)' COLOR 4.
SKIP.
WRITE / `************** Some sy Components **************` COLOR 2.
WRITE / |Content of clicked line (sy-lisel): "{ sy-lisel }"|.
WRITE / |Number of clicked line (sy-lilli): "{ sy-lilli }"|.
WRITE / |List level of the current list (sy-lsind): "{ sy-lsind }"|.
SKIP.
IF list_log IS NOT INITIAL.
demo=>write_list_log( ).
ENDIF.
ENDIF.
**********************************************************************
AT USER-COMMAND.
"Called when a function with a user-defined function code is selected when a screen list is displayed
"Note: PICK does not raised the AT USER-COMMAND event. Instead, it raises the AT LINE-SELECTION event.
CASE sy-ucomm.
WHEN 'START'.
demo=>list_evt( `AT USER-COMMAND (Function code: START)` ).
MESSAGE |AT USER-COMMAND event raised (Function code: START). Counter value: { counter }.| TYPE 'I'.
WHEN 'LINE'.
demo=>list_evt( `AT USER-COMMAND (Function code: LINE)` ).
MESSAGE |AT USER-COMMAND event raised (Function code: LINE). Counter value: { counter }.| TYPE 'I'.
IF counter >= 40.
MESSAGE |The counter has reached the threshold. The program will be started again using a SUBMIT statement.| TYPE 'I'.
SUBMIT (sy-repid) VIA SELECTION-SCREEN.
ENDIF.
ENDCASE.
**********************************************************************
TOP-OF-PAGE.
"Called when a basic list is created and when a new page begins
tstmp = utclong_current( ).
demo=>counter( ).
APPEND VALUE #( id = counter event_block = |TOP-OF-PAGE| time = tstmp ) TO list_log.
WRITE: / |********************* Title inserted at TOP-OF-PAGE event ({ counter }) *********************|.
**********************************************************************
TOP-OF-PAGE DURING LINE-SELECTION.
"Called when details lists are created
tstmp = utclong_current( ).
demo=>counter( ).
APPEND VALUE #( id = counter event_block = |TOP-OF-PAGE DURING LINE-SELECTION| time = tstmp ) TO list_log.
WRITE: / |********************* Title inserted at TOP-OF-PAGE DURING LINE-SELECTION event ({ counter }) *********************|.
**********************************************************************
END-OF-PAGE.
"Called when the end of a page is reached, for example, if the specified number of lines in the
"LINE-COUNT addition has been reached
tstmp = utclong_current( ).
demo=>counter( ).
APPEND VALUE #( id = counter event_block = |END-OF-PAGE| time = tstmp ) TO list_log.
WRITE: / |********************* Footer inserted at END-OF-PAGE event ({ counter }) *********************|.

View File

@@ -0,0 +1,23 @@
<?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_EVENT_BLOCKS</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Event blocks (ABAP cheat sheet: Selection Screens/Classic Lists)</ENTRY>
<LENGTH>64</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

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,515 @@
***********************************************************************
*
* ABAP cheat sheet: Selection screens and classic lists
* Example: Classic lists
*
* -------------------------- PURPOSE ----------------------------------
* Example that demonstrates various ABAP statements in the context of
* classic lists
* Includes:
* - Creating lists: WRITE, FORMAT, ULINE, SET BLANK LINES, SKIP,
* NEW-LINE, HIDE, HOTSPOT, RESERVE/BACK
* - Reading and modifying in lists: READ LINE, MODIFY LINE
*
* Notes:
* - A selection of additions is used. For more additions and details,
* see the ABAP Keyword Documentation.
* - See the ABAP cheat sheet for other statements used here, for example,
* the ones related to event blocks such as START-OF-SELECTION.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the program with the ABAP development tools for Eclipse (ADT).
* - Choose F8 to run 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.
*
***********************************************************************
PROGRAM.
TYPES: BEGIN OF str,
statement TYPE string,
line_content TYPE string,
END OF str.
DATA: count TYPE i,
line LIKE sy-linno,
linno1 LIKE sy-linno,
linno2 LIKE sy-linno,
linno_int LIKE sy-linno,
linno_copy LIKE sy-linno,
linno_mod1 LIKE sy-linno,
linno_mod2 LIKE sy-linno,
linno_input LIKE sy-linno,
lisel_copy LIKE sy-lisel,
square TYPE i,
cube TYPE i,
int_for_back LIKE sy-colno,
itab TYPE string_table,
str_tab TYPE string_table,
lisel_tab TYPE string_table,
str TYPE string,
input_int TYPE c LENGTH 3 VALUE 3,
read_line TYPE c LENGTH 1,
num TYPE i,
char TYPE c LENGTH 10,
tab TYPE TABLE OF str WITH EMPTY KEY,
var LIKE input_int,
int TYPE i,
li LIKE LINE OF tab,
chck1 TYPE c LENGTH 1 VALUE 'X',
chck2 TYPE c LENGTH 1 VALUE ' ',
input TYPE c LENGTH 20 VALUE 'Make an entry here',
dc34 TYPE decfloat34 VALUE ' 1.2345 ',
txt TYPE string VALUE `abap`,
some_text TYPE string VALUE `Hi, `,
abc TYPE c LENGTH 5 VALUE 'abcde',
dc TYPE decfloat34 VALUE '1.2345'.
**********************************************************************
INITIALIZATION.
itab = VALUE #( ( `a` ) ( `b` ) ( `` ) ( `` ) ( `c` ) ).
**********************************************************************
START-OF-SELECTION.
"WRITE using an unnamed data object
WRITE 'Hello ABAP.'.
"Named data objects
"Note: The text is written right after the previous text in one line.
WRITE some_text && sy-uname.
WRITE / '****************** WRITE: Positioning output ******************'.
"/: Writes to a new line
WRITE / 'new line'.
"Specifying the output position (and output in new line)
WRITE /5 'positioned'.
"Specifying the length, no position specified means the output is
"written from the first column on
WRITE /(3) 'not displayed completely'.
"Specifying both length and position
WRITE /5(30) 'this is displayed completely'.
"Position/length only specified as numeric literals as above, then the
"addition AT can be omitted
WRITE AT /3(12) 'lorem ipsum'.
"Length specifications with * or **. In that case, the output length
"depends on the data type of the data object. There are special rules.
"See the ABAP Kwyword Documentation for the details.
WRITE /(*) dc34.
WRITE /1(**) dc34.
WRITE / '****************** WRITE: Further specification options ******************'.
"There are many further specification options, among them function calls, string
"expressions, method calls to be specified after WRITE.
"String template
WRITE / |{ txt WIDTH = 20 ALIGN = RIGHT CASE = UPPER }|.
"The following statement uses a chained statement with colon.
WRITE: / |{ 1 + 2 }|, "String template includes an arithmetic calculation
/ to_upper( txt ). "Function call
"Concatenation using &&
WRITE / `conc` && `atenated`.
"Method call (returns a random integer between 1 and 10)
"Note the * specification. The returned value is of type i. Specifying *
"for the length means the length required to output the current value
"is used. You may want to try the following code snippet by removing (*).
WRITE /(*) cl_abap_random_int=>create(
seed = cl_abap_random=>seed( )
min = 1
max = 10 )->get_next( ).
WRITE / '****************** WRITE: UNDER addition ******************'.
"UNDER: Puts the output in the position of previous output
"Note: If the output is written in the same line in which the previous output
"is displayed, this output is overwritten.
WRITE /5(5) abc.
WRITE / 'fghij' UNDER abc.
WRITE / '****************** WRITE: NO-GAP addition ******************'.
WRITE / 'g'.
WRITE 'ap1'. "Output: g ap1
WRITE: / 'g' NO-GAP, 'ap2'. "Output: gap2
WRITE / '****************** WRITE: QUICKINFO addition ******************'.
"QUICKINFO: Creates a tooltip for the output
WRITE / 'Hover over the following output and check the tooltip:'.
WRITE: (*) sy-uname QUICKINFO 'User name',
'/',
(*) sy-datum QUICKINFO 'Current date',
'/',
(*) sy-uzeit QUICKINFO 'Current time'.
WRITE / '****************** WRITE: Special list elements ******************'.
"INPUT
WRITE / input INPUT.
linno_input = sy-linno.
"AS CHECKBOX
"The value (blank, X) is stored in the list buffer and can be evaluated during
"a list event.
WRITE: / chck1 AS CHECKBOX, 'Checkbox 1',
/ chck2 AS CHECKBOX, 'Checkbox 2'.
"AS ICON: Outputting icons
"Check the type pool ICON for names of predefined icons.
WRITE / icon_green_light AS ICON.
WRITE / icon_red_light AS ICON.
WRITE / icon_yellow_light AS ICON.
WRITE / icon_activate AS ICON.
"AS SYMBOL: Outputting symbols
"Check the type pool SYM for names of predefined icons.
WRITE / sym_left_hand AS SYMBOL.
WRITE / sym_caution AS SYMBOL.
"AS LINE: Outputting corners, crosses, lines, and T sections
"Check the type pool LINE for names of predefined icons.
WRITE: /10 line_horizontal_line AS LINE NO-GAP,
line_space AS LINE NO-GAP,
line_vertical_line AS LINE NO-GAP.
WRITE / '****************** WRITE: Formatting options ******************'.
"The following examples show a selection. Various other additions are
"available that deal with currency, unit, date and time-related formatting,
"among others. See the ABAP Keyword Documentation.
WRITE /(10) 'X' RIGHT-JUSTIFIED.
WRITE /(10) 'X' CENTERED.
WRITE /(10) ` X`.
WRITE /(10) ` X` LEFT-JUSTIFIED.
WRITE /(*) dc DECIMALS 2.
"Colors
"The commented out value stands for the value that can also be directly
"specified in the syntax (except 0) or contained in a data object.
"There are several additions with many options.
WRITE / 'COL_BACKGROUND (0)' COLOR COL_BACKGROUND. "0 (GUI dependent)
WRITE / 'COL_HEADING (1)' COLOR COL_HEADING. "1 (gray-blue)
WRITE / 'COL_HEADING (1)' COLOR 1.
WRITE / 'COL_NORMAL (2)' COLOR COL_NORMAL. "2 (light gray)
WRITE / 'COL_TOTAL (3)' COLOR COL_TOTAL. "3 (yellow)
WRITE / 'COL_KEY (4)' COLOR COL_KEY. "4 (blue-green)
WRITE / 'COL_POSITIVE (5)' COLOR COL_POSITIVE. "5 (green)
WRITE / 'COL_NEGATIVE (6)' COLOR COL_NEGATIVE. "6 (red)
WRITE / 'COL_GROUP (7)' COLOR COL_GROUP. "7 (purple/orange)
WRITE / 'COLOR 7 OFF' COLOR 7 OFF. "default color
"Setting the intensity of the background color.
WRITE / 'COLOR 7 INTENSIFIED OFF' COLOR 7 INTENSIFIED OFF.
"INVERSE: When ON, the foreground, i.e. the output is displayed
"in the selected color.
WRITE / 'COLOR 7 INVERSE ON' COLOR 7 INVERSE ON.
WRITE / '****************** FORMAT ******************'.
"FORMAT: For applying settings (COLOR, INTENSIFIED, INVERSE ...)
"on all of the following output statements up to a definition
"with new settings
WRITE / '****************** FORMAT: FRAMES addition ******************'.
"FRAMES: Defines whether the - and | characters are converted to line elements,
"producing continuous lines.
FORMAT FRAMES ON.
WRITE: / '----',
/ '| |',
/ '----'.
FORMAT FRAMES OFF.
WRITE / '****************** FORMAT: COLOR addition ******************'.
"This example shows the already covered COLOR addition with FORMAT
"statements.
FORMAT COLOR COL_POSITIVE.
WRITE / 'ABC'.
WRITE / 'DEF'.
WRITE / 'GHI'.
FORMAT COLOR OFF.
WRITE / 'This is the first WRITE after a new setting with FORMAT ... OFF'.
WRITE / '****************** FORMAT: RESET addition ******************'.
"This addition sets all formatting settings for which the corresponding addition is
"not specified in the same FORMAT statement to the state OFF (exception: FRAMES).
"In the following example, note the effect of the RESET addition (apart from
"resetting the previously set COLOR and INVERSE addition:
"- INTENSIFIED ON is the state after the program start by default.
"- Now, with the reset, the state is INTENSIFIED OFF.
"- See the effect for all the WRITE statements that follow and that have
" the COLOR addition specified.
FORMAT COLOR 7 INVERSE ON.
WRITE / 'ABC'.
WRITE / 'DEF'.
FORMAT RESET.
WRITE / 'GHI'.
WRITE / 'JKL'.
WRITE / '****************** ULINE ******************'.
"ULINE: Creating a horizontal line
ULINE.
"More additions are available such as for the position and length.
ULINE AT 5(20).
WRITE / '****************** SET BLANK LINES ******************'.
"SET BLANK LINES: Specifying if blank lines created using WRITE are displayed
WRITE / 'SET BLANK LINES OFF.' COLOR 2.
SET BLANK LINES OFF.
LOOP AT itab INTO DATA(wa).
WRITE / wa.
ENDLOOP.
WRITE / 'SET BLANK LINES ON.' COLOR 3.
SET BLANK LINES ON.
LOOP AT itab INTO wa.
WRITE / wa.
ENDLOOP.
ULINE.
WRITE / '****************** SKIP ******************'.
"SKIP: Positions the list cursor explicitly
WRITE / 'SKIP' COLOR 4.
SKIP.
WRITE / 'SKIP 3' COLOR 5.
SKIP 3.
ULINE.
WRITE / 'SKIP TO LINE' COLOR 6.
WRITE / 'Text A'.
WRITE / 'Text B'.
line = sy-linno. "The line number of the previous output is retrieved.
WRITE / 'Text C'.
SKIP TO LINE line.
WRITE / 'Text D' COLOR 7.
WRITE / 'Text E'.
ULINE.
WRITE / '****************** NEW-LINE ******************'.
"NEW-LINE: Setting list cursor to the first position of the next line.
"Additions are available to affect the scrolling behavior.
WRITE / 'Next statement is NEW-LINE'.
NEW-LINE.
WRITE 'WRITE statement without /'.
ULINE.
WRITE / '****************** HIDE/HOTSPOT ******************'.
"The example contains a DO loop. In this loop, WRITE statements output
"the sy-index value (1 to 10). Based on the sy-index value, calculations
"are performed. The result is hidden using HIDE. When you click a line
"in the basic list in this very section, the hidden values are displayed
"in the details list.
WRITE / 'For the values of square and cube, click a line in this section.'.
linno1 = sy-linno.
FORMAT HOTSPOT ON.
DO 10 TIMES.
square = sy-index ** 2.
cube = sy-index ** 3.
WRITE / sy-index.
"Storing the content of a the variables together with the current list line.
HIDE: square, cube.
ENDDO.
FORMAT HOTSPOT OFF.
linno2 = sy-linno.
WRITE / '****************** RESERVE/BACK ******************'.
"RESERVE is demonstrated here with BACK.
"Consider the RESERVE 5 LINES statements as defining a block of
"5 lines. When using BACK after RESERVE, e.g. after a loop, you
"can put the suqsequent output to the first line of this block of lines.
WRITE / 'RESERVE without BACK:'.
int_for_back = sy-colno.
ULINE AT /(int_for_back).
RESERVE 5 LINES.
DO 5 TIMES.
WRITE / sy-index.
ENDDO.
int_for_back = sy-colno.
WRITE AT int_for_back ' <- This is not number 1.'.
SKIP.
WRITE / 'RESERVE with BACK:'.
int_for_back = sy-colno.
ULINE AT /(int_for_back).
RESERVE 5 LINES.
DO 5 TIMES.
WRITE / sy-index.
ENDDO.
int_for_back = sy-colno.
BACK.
WRITE AT int_for_back ' <- This should be number 1.'.
SKIP 5.
WRITE / '****************** READ LINE ******************'.
"READ LINE: Assigning the content of a line stored in the
"list buffer to the system field sy-lisel. Plus, it allows
"other target fields to be specified.
"In the example, you can provide an integer in an input field
"on whose basis a READ LINE statement is executed.
WRITE / 'Insert a number representing a line number from which to read: '.
FORMAT INPUT.
WRITE / input_int.
linno_int = sy-linno.
FORMAT INPUT OFF.
WRITE / '****************** MODIFY LINE ******************'.
"MODIFY LINE: Overwrites a line stored in the list buffer with the
"content of the sy-lisel system field Plus, it allows additional
"modifications.
"In the example, you can click 7 times in the very section on whose
"basis a MODIFY LINE statement is executed.
WRITE / 'Click 7 times on any line in this section starting from "1 A" to explore the effect of MODIFY LINE statements.'.
SKIP.
linno_mod1 = sy-linno.
DO 10 TIMES.
num += 1.
char &&= 'A'.
WRITE /10(*) num.
WRITE 15 char.
ENDDO.
linno_mod2 = sy-linno.
**********************************************************************
AT LINE-SELECTION.
"The purpose of the following implementation is to avoid multiple
"details lists when clicking lines.
IF sy-lsind = 1
AND sy-lilli BETWEEN linno_mod1 AND linno_mod2.
CASE count.
WHEN 0.
MODIFY CURRENT LINE LINE VALUE FROM 'Overwritten'.
WHEN 1.
MODIFY CURRENT LINE FIELD VALUE char FROM 'BBBB'.
WHEN 2.
MODIFY CURRENT LINE FIELD VALUE num FROM '#' char FROM 'CCCC'.
WHEN 3.
MODIFY CURRENT LINE FIELD FORMAT char COLOR 3.
WHEN 4.
MODIFY CURRENT LINE LINE FORMAT COLOR 4.
WHEN 5.
MODIFY CURRENT LINE FIELD FORMAT num COLOR 5 char COLOR 6
LINE FORMAT COLOR 7.
WHEN 6.
linno_copy = linno_mod1.
WHILE linno_copy <= linno_mod2.
MODIFY LINE linno_copy LINE VALUE FROM ':)' LINE FORMAT COLOR 3.
linno_copy += 1.
IF sy-index = 11.
EXIT.
ENDIF.
ENDWHILE.
WHEN OTHERS.
EXIT.
ENDCASE.
count += 1.
ELSEIF sy-lsind = 1
AND sy-lilli NOT BETWEEN linno_mod1 AND linno_mod2.
WRITE / `************************ Information about the line you clicked ************************` COLOR 7 INTENSIFIED OFF.
SKIP.
WRITE / |Line content (sy-lisel): "{ sy-lisel }"|.
WRITE / |Line number (sy-lilli): "{ sy-lilli }"|.
SKIP.
ULINE.
SKIP.
WRITE / `************************ HIDE statements ************************` COLOR 7 INTENSIFIED OFF.
SKIP.
IF sy-lilli NOT BETWEEN linno1 + 1 AND linno2.
WRITE / |You have clicked on line { sy-lilli } and not on a line between line { linno1 + 1 } and line { linno2 }.|.
WRITE / `For exploring the effect of HIDE and displaying the values of 'square' and 'cube', click a line in the HIDE/HOTSPOT section of the basic list.`.
ELSE.
WRITE: / |square: { square }|.
WRITE: / |cube: { cube }|.
ENDIF.
"READ LINE
CLEAR str_tab.
CLEAR lisel_tab.
SKIP.
ULINE.
SKIP.
WRITE / `************************ READ LINE statements ************************` COLOR 7 INTENSIFIED OFF.
SKIP.
READ CURRENT LINE.
IF sy-subrc <> 0.
lisel_copy = sy-lisel.
APPEND VALUE #( statement = |READ CURRENT LINE. (sy-lisel contains line content)| line_content = |ERROR: Line does not exist| ) TO tab.
ELSE.
lisel_copy = sy-lisel.
APPEND VALUE #( statement = |READ CURRENT LINE. (sy-lisel contains line content)| line_content = |sy-lisel: "{ lisel_copy }"| ) TO tab.
ENDIF.
"Put the entire line content (current line) of the read result in a data object
READ CURRENT LINE LINE VALUE INTO str.
IF sy-subrc <> 0.
APPEND VALUE #( statement = `READ CURRENT LINE LINE VALUE INTO ...` line_content = `ERROR: Line does not exist` ) TO tab.
ELSE.
APPEND VALUE #( statement = `READ CURRENT LINE LINE VALUE INTO ...` line_content = |str: "{ lisel_copy }"| ) TO tab.
ENDIF.
"Specific line
TRY.
"Put concrete field values (specified line) of the read result in data objects
READ LINE linno_int FIELD VALUE input_int INTO var.
APPEND VALUE #( statement = |READ LINE { linno_int } FIELD VALUE ... INTO var. (Line of the input field)| line_content = |var: "{ var }"| ) TO tab.
int = var.
"Read entire line content
READ LINE int.
IF sy-subrc = 0.
lisel_copy = sy-lisel.
APPEND VALUE #( statement = |READ LINE { int }. (sy-lisel contains line content)| line_content = |sy-lisel: "{ lisel_copy }"| ) TO tab.
ELSE.
APPEND VALUE #( statement = |READ LINE { int }.| line_content = |ERROR: Line { int } does not exist| ) TO tab.
ENDIF.
CATCH cx_root.
APPEND VALUE #( statement = |READ LINE { var }.| line_content = |ERROR: That statement does not work. Insert an integer value.| ) TO tab.
ENDTRY.
IF tab IS NOT INITIAL.
LOOP AT tab INTO li.
WRITE: / li-statement COLOR 2,
/ li-line_content.
SKIP.
ENDLOOP.
ENDIF.
CLEAR: tab, input, str.
ULINE.
SKIP.
WRITE / `************************ MODIFY LINE statements ************************` COLOR 7 INTENSIFIED OFF.
SKIP.
WRITE / `To explore MODIFY LINE statements, click the lines in the MODIFY LINE section of the basic list.`.
SKIP.
ENDIF.

View File

@@ -0,0 +1,23 @@
<?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_LISTS</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Classic Lists (ABAP Cheat Sheet: Selection Screens/Classic Lists)</ENTRY>
<LENGTH>65</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

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,103 @@
***********************************************************************
*
* ABAP cheat sheet: Selection screens and classic lists
*
*
* -------------------------- PURPOSE ----------------------------------
* This program can be used for starting the selection screen and
* classic list programs contained in the repository.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the program with the ABAP development tools for Eclipse (ADT).
* - Choose F8 to run 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.
*
***********************************************************************
PROGRAM.
TYPES: BEGIN OF reps_str,
number TYPE i,
report LIKE sy-repid,
END OF reps_str.
DATA: rep LIKE sy-repid,
reports TYPE TABLE OF reps_str WITH EMPTY KEY,
allowed TYPE string.
SELECTION-SCREEN BEGIN OF BLOCK bl WITH FRAME TITLE title.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (25) lbl FOR FIELD report.
PARAMETERS report TYPE i AS LISTBOX VISIBLE LENGTH 60.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK bl.
**********************************************************************
INITIALIZATION.
title = 'Select and run a program'.
lbl = 'Program:'.
reports = VALUE #(
( number = 1 report = 'ZDEMO_ABAP_SELSCR_PARAMETERS' )
( number = 2 report = 'ZDEMO_ABAP_SELSCR_SELECT_OPT' )
( number = 3 report = 'ZDEMO_ABAP_SELSCR_STANDALONE' )
( number = 4 report = 'ZDEMO_ABAP_SELSCR_STMTS_VAR' )
( number = 5 report = 'ZDEMO_ABAP_LISTS' )
( number = 6 report = 'ZDEMO_ABAP_EVENT_BLOCKS' )
( number = 7 report = 'ZDEMO_ABAP_ALV' )
).
**********************************************************************
AT SELECTION-SCREEN OUTPUT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = CONV vrm_id( 'REPORT' )
values = VALUE vrm_values(
( key = 1 text = 'Selection screens: PARAMETERS (zdemo_abap_selscr_parameters)' )
( key = 2 text = 'Selection screens: SELECT-OPTIONS (zdemo_abap_selscr_select_opt)' )
( key = 3 text = 'Selection screens: SELECTION-SCREEN (zdemo_abap_selscr_standalone)' )
( key = 4 text = 'Selection screens: SELECTION-SCREEN Variants (zdemo_abap_selscr_stmts_var)' )
( key = 5 text = 'Lists: Creating Lists (zdemo_abap_lists)' )
( key = 6 text = 'Event blocks (zdemo_abap_event_blocks)' )
( key = 7 text = 'SAP List Viewer (ALV) (zdemo_abap_alv)' ) ).
**********************************************************************
START-OF-SELECTION.
IF report BETWEEN 1 AND 7.
"Dynamic programming check: Only submit program if its name is available
"in the allow list
TRY.
rep = reports[ number = report ]-report.
allowed = cl_abap_dyn_prg=>check_whitelist_tab(
val = rep
whitelist = VALUE #( ( `ZDEMO_ABAP_SELSCR_PARAMETERS` )
( `ZDEMO_ABAP_SELSCR_SELECT_OPT` )
( `ZDEMO_ABAP_SELSCR_STANDALONE` )
( `ZDEMO_ABAP_SELSCR_STMTS_VAR` )
( `ZDEMO_ABAP_LISTS` )
( `ZDEMO_ABAP_EVENT_BLOCKS` )
( `ZDEMO_ABAP_ALV` ) ) ).
SUBMIT (rep) AND RETURN VIA SELECTION-SCREEN.
CATCH cx_root INTO DATA(err).
MESSAGE |Error: { err->get_text( ) }| TYPE 'E'.
ENDTRY.
ELSE.
MESSAGE 'Please select a program.' TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.

View File

@@ -0,0 +1,23 @@
<?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_SELSCR_LISTS_INTRO</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>ABAP Cheat Sheet: Selection Screen/Classic List Examples Intro</ENTRY>
<LENGTH>62</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,224 @@
***********************************************************************
*
* ABAP cheat sheet: Selection screens and classic lists
* Example: PARAMETERS statements
*
* -------------------------- PURPOSE ----------------------------------
* Example that demonstrates PARAMETERS statements in standard selection
* screens
*
* Notes:
* - A selection of additions is used. For more additions and details,
* see the ABAP Keyword Documentation.
* - The MODIF ID addition is possible for PARAMETERS. This is also true
* for SELECTION-SCREEN statements. See the details in that example.
* - See the ABAP cheat sheet for other statements used here, for example,
* the ones related to event blocks such as START-OF-SELECTION.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the program with the ABAP development tools for Eclipse (ADT).
* - Choose F8 to run 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.
*
***********************************************************************
PROGRAM.
****************************** Type options ******************************
"Displaying some explanatory text on the standard selection screen
"The actual text content is assigned to the variable in the INITIALIZATION
"event block.
SELECTION-SCREEN COMMENT /1(70) t1.
"Referring to a built-in type with TYPE
"In this case, a variable length character string can be inserted in the
"generated input field. Note the LOWER CASE addition further down.
PARAMETERS p_str TYPE string.
"Referring to an existing data object with the LIKE addition.
"When referencing to a data type from the ABAP Dictionary after LIKE,
"you can benefit from things such as input help (if available).
DATA dobj TYPE i.
PARAMETERS plikedo LIKE dobj.
"Dynamic spefication of data object in parentheses after LIKE
"You can reference to a data type from the ABAP Dictionary. some_dobj in
"the example may be the name of a component of a database table,
"provided in capital letters.
DATA some_dobj TYPE c LENGTH 50 VALUE 'ZDEMO_ABAP_CARR-CARRID'.
PARAMETERS p_dyn LIKE (some_dobj).
"Length specifications
"Similar to declarations with DATA, the length can be specified for data
"types with generic length (i.e. the types c, n, p, and x).
PARAMETERS p_c1 TYPE c LENGTH 1.
PARAMETERS p_n5 TYPE n LENGTH 5.
"You may also see specifications in which the length is specified in parentheses.
"For better readability, specifying LENGTH explicitly is recommended.
PARAMETERS pbracket(2) TYPE c.
"No length specified means LENGTH 1 by default
PARAMETERS p_no_len TYPE c.
"No explicit type specification means TYPE c by default
PARAMETERS plenonl1(40).
PARAMETERS plenonl2 LENGTH 40.
"No explicit type and length specification means TYPE c LENGTH 1 by default
PARAMETERS pnothing.
****************************** Value options ******************************
SELECTION-SCREEN COMMENT /1(70) t2.
"DEFAULT: Defining a start value (can also be a data object instead of a literal)
PARAMETERS pdefault TYPE i DEFAULT 12345.
"LOWER CASE: Prevents the effect of capitalizing the entry made when the content
"is transported to the data object
PARAMETERS p_upper TYPE string DEFAULT `Hello World`. "Value you insert will be capitalized.
PARAMETERS p_lower TYPE string DEFAULT `Hello World` LOWER CASE.
"Note: There are more additions available, e.g. for linking the parameter to search help,
"or checking against fixed values defined in the domain of the data type, and so on.
"You can also perform your custom input checks in event blocks.
****************************** Screen options ******************************
SELECTION-SCREEN COMMENT /1(70) t3.
"OBLIGATORY: Declaring the input field as a required field
"If there is no entry, the program cannot proceed when choosing Execute.
"A message is displayed.
PARAMETERS p_oblig TYPE string OBLIGATORY.
"NO-DISPLAY: Hiding the input field on the selection screen
"A value can be supplied when calling the program with SUBMIT and the WITH addition.
"Note that with the NO-DISPLAY addition, the parameter can have any data types except
"for reference/enumerated types, unlike in the other additions which require flat
"types (except type string).
PARAMETERS p_nodisp TYPE string NO-DISPLAY.
"VISIBLE LENGTH: Defining the visible length of the field
PARAMETERS p_vislen TYPE c LENGTH 5 VISIBLE LENGTH 3.
"AS CHECKBOX: Displaying input fields as checkbox
"Type c and length 1 is expected, but the explicit length specification is not allowed.
"The checkbox is selected if the value has the value X or x.
PARAMETERS p_check1 AS CHECKBOX. "Implicit type c
"Explicit type specification (but no explicit length), select by default
PARAMETERS p_check2 TYPE c AS CHECKBOX DEFAULT 'X'.
"RADIOBUTTON GROUP: Defining a radio button group for parameters
"Note:
"- Group name can have a maximum of four characters
"- Regarding the data type, the same applies as for AS CHECKBOX
"- Only one parameter can be defined with the DEFAULT addition
"- If DEFAULT is not specified, the first parameter of the group is set to the value X
"- You can also use chained statements
PARAMETERS: p_radio1 RADIOBUTTON GROUP rbgr,
p_radio2 TYPE c RADIOBUTTON GROUP rbgr, "Explicit type specification
p_radio3 RADIOBUTTON GROUP rbgr DEFAULT 'X'. "Set this radio button as selected
"AS LISTBOX VISIBLE LENGTH: Creating a dropdown list box
"You can use the function module VRM_SET_VALUES by passing a suitable list at the
"events AT SELECTION-SCREEN OUTPUT or AT SELECTION-SCREEN ON VALUE-REQUEST.
PARAMETERS plistbox TYPE i AS LISTBOX VISIBLE LENGTH 10 OBLIGATORY.
*********************** Assigning function codes ***********************
"The AS CHECKBOX, RADIOBUTTON GROUP, AS LISTBOX additions can be combined
"with the addition USER-COMMAND. That means, on selection, the event
"AT SELECTION-SCREEN is raised and you can evaluate the function code there.
"Note: To enable it, include the statement 'TABLES sscrfields.' in the code.
"When the button is clicked, the event AT SELECTION-SCREEN is raised and the
"function code ('cmd', 'rbcm' in the example) is passed to the 'ucomm' component
"in the interface work area 'sscrfields' which can be evaluated and reacted upon
"accordingly.
"Before exploring the effect in the example, make entries for the
"obligatory input fields first, then choose the checkbox/radio buttons.
SELECTION-SCREEN COMMENT /1(70) t4.
TABLES sscrfields.
PARAMETERS pchckcmd AS CHECKBOX USER-COMMAND cmd.
PARAMETERS: prad1cmd RADIOBUTTON GROUP grp USER-COMMAND rbcm,
prad2cmd RADIOBUTTON GROUP grp.
**********************************************************************
INITIALIZATION.
t1 = 'PARAMETERS: Demonstrating various type options:'.
t2 = 'Demonstrating value options:'.
t3 = 'Demonstrating screen options:'.
t4 = 'Click these screen elements to explore the USER-COMMAND addition.'.
**********************************************************************
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'CMD'.
MESSAGE |Hallo { sy-uname }.| TYPE 'I'.
WHEN 'RBCM'.
MESSAGE |Today's date: { sy-datum DATE = ISO }| TYPE 'I'.
ENDCASE.
**********************************************************************
AT SELECTION-SCREEN OUTPUT.
"This is relevant for the AS LISTBOX VISIBLE LENGTH addition.
"Note:
"- The function module VRM_SET_VALUES is used
"- Column TEXT: What is displayed in the list box
"- Colum KEY: When a line is selected, the KEY value is added to the
" parameter
"In the example, the numbers 1 - 10 are added as values.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = CONV vrm_id( 'PLISTBOX' )
values = VALUE vrm_values(
FOR i = 1 UNTIL i > 10
( key = i text = |Value { i }| ) ).
**********************************************************************
START-OF-SELECTION.
"Creating a classic list
WRITE / `This list displays the values provided on the selection screen.`.
SKIP.
WRITE / |p_str: "{ p_str }"| .
WRITE / |plikedo: "{ plikedo }"| .
WRITE / |p_dyn: "{ p_dyn }"| .
WRITE / |p_c1: "{ p_c1 }"| .
WRITE / |p_n5: "{ p_n5 }"| .
WRITE / |pbracket: "{ pbracket }"| .
WRITE / |p_no_len: "{ p_no_len }"| .
WRITE / |plenonl1: "{ plenonl1 }"| .
WRITE / |plenonl2: "{ plenonl2 }"| .
WRITE / |pnothing: "{ pnothing }"| .
WRITE / |pdefault: "{ pdefault }"| .
WRITE / |p_upper: "{ p_upper }"| .
WRITE / |p_lower: "{ p_lower }"| .
WRITE / |p_oblig: "{ p_oblig }"| .
WRITE / |p_nodisp: "{ p_nodisp }"| .
WRITE / |p_vislen: "{ p_vislen }"| .
WRITE / |p_check1: "{ p_check1 }"| .
WRITE / |p_check2: "{ p_check2 }"| .
WRITE / |Radio button selected: "{ COND #( WHEN p_radio1 = 'X' THEN 'p_radio1' WHEN p_radio2 = 'X' THEN 'p_radio2' ELSE 'p_radio3' ) }"| .
WRITE / |plistbox: "{ plistbox }"| .
WRITE / |pchckcmd: "{ pchckcmd }"| .
WRITE / |Radio button selected: "{ COND #( WHEN prad1cmd = 'X' THEN 'prad1cmd' ELSE 'prad2cmd' ) }"| .

View File

@@ -0,0 +1,23 @@
<?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_SELSCR_PARAMETERS</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>PARAMETERS (ABAP Cheat Sheet: Selection Screens/Classic Lists)</ENTRY>
<LENGTH>62</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,142 @@
***********************************************************************
*
* ABAP cheat sheet: Selection screens and classic lists
* Example: SELECT-OPTIONS statements
*
* -------------------------- PURPOSE ----------------------------------
* Example that demonstrates SELECT-OPTIONS statements in standard
* selection screens
*
* Notes:
* - A selection of additions is used. For more additions and details,
* see the ABAP Keyword Documentation.
* - See the ABAP cheat sheet for other statements used here, for example,
* the ones related to event blocks such as START-OF-SELECTION.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the program with the ABAP development tools for Eclipse (ADT).
* - Choose F8 to run 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.
*
***********************************************************************
PROGRAM.
DATA int TYPE i.
DATA int_tab TYPE TABLE OF i WITH EMPTY KEY.
DATA selcriteria TYPE string_table.
DATA str TYPE string.
FIELD-SYMBOLS <fs> TYPE ANY TABLE.
"SELECT-OPTIONS statements demonstrating various additions
"The following statement creates two input fields that can be
"used to specify selection criteria on the selection screen.
"In addition, the Multiple Selection button is available to
"further specify the selection criteria, e.g. what to include,
"exclude, etc.. As in all examples, an internal table of type
"TYPE RANGE OF whose contents can be evaluated.
"The FOR addition is followed by an already declared data object.
SELECT-OPTIONS a FOR int.
"NO-DISPLAY: Hides
SELECT-OPTIONS b FOR int NO-DISPLAY.
"NO-EXTENSION: The Multiple Selection button is not created on
"the selection screen
SELECT-OPTIONS c FOR int NO-EXTENSION.
"NO INTERVALS: Only one input field. Intervals can still be
"selected using the Multiple Selection button.
SELECT-OPTIONS d FOR int NO INTERVALS.
"Additions can be combined
SELECT-OPTIONS e FOR int NO-EXTENSION NO INTERVALS.
"DEFAULT ... TO ...: Providing start values for the columns in
"the first line of the selection table (low and high values)
SELECT-OPTIONS f FOR int NO-EXTENSION DEFAULT 3 TO 10.
SELECT-OPTIONS g FOR int DEFAULT 5 TO 9.
"DEFAULT ... OPTION ... SIGN ...: Providing further start values.
"See the details in the ABAP cheat sheet.
SELECT-OPTIONS h FOR int DEFAULT 4 TO 8 OPTION NB SIGN I.
**********************************************************************
INITIALIZATION.
"Providing start values for data objects
"The following internal table is filled and used as a data source
"for a SELECT statement.
int_tab = VALUE #( FOR i = 1 UNTIL i > 20 ( i ) ).
"This table is filled here with the names from above. The table is looped
"over in the START-OF-SELECTION event block to cover all SELECT-OPTIONS
"from above.
selcriteria = VALUE #( ( `A` ) ( `B` ) ( `C` ) ( `D` )
( `E` ) ( `F` ) ( `G` ) ( `H` ) ).
**********************************************************************
START-OF-SELECTION.
"Creating a classic list
WRITE / `Data was retrieved from an internal table using a SELECT statement based on selection criteria.`.
WRITE / `The table has the following content:`.
LOOP AT int_tab INTO int.
WRITE |{ int }|.
ENDLOOP.
SKIP 2.
LOOP AT selcriteria INTO str.
CASE str.
"For historical reasons, the selection table is a table with header line.
"Therefore, if you want to address the table content (beyond the use in a
"SELECT ... WHERE ... IN ... statement), use the syntax `...[]`.
WHEN `A`.
ASSIGN a[] TO <fs>.
WHEN `B`.
ASSIGN b[] TO <fs>.
WHEN `C`.
ASSIGN c[] TO <fs>.
WHEN `D`.
ASSIGN d[] TO <fs>.
WHEN `E`.
ASSIGN e[] TO <fs>.
WHEN `F`.
ASSIGN f[] TO <fs>.
WHEN `G`.
ASSIGN g[] TO <fs>.
WHEN `H`.
ASSIGN h[] TO <fs>.
ENDCASE.
WRITE / |Result for selection options specified for "{ str }":| COLOR 2.
SKIP.
SELECT *
FROM @int_tab AS tab
WHERE table_line IN @<fs>
INTO @int.
WRITE |{ int }|.
ENDSELECT.
IF <fs> IS INITIAL.
WRITE `(No selection criteria were provided. Therefore, all table lines are respected.)`.
ENDIF.
SKIP.
ENDLOOP.

View File

@@ -0,0 +1,23 @@
<?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_SELSCR_SELECT_OPT</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>SELECT-OPTIONS (ABAP Cheat Sheet: Selection Screens/Classic Lists)</ENTRY>
<LENGTH>66</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,218 @@
***********************************************************************
*
* ABAP cheat sheet: Selection screens and classic lists
* Example: Creating standalone selection screens
*
* -------------------------- PURPOSE ----------------------------------
* - Example that demonstrates standalone selection screens
* - In the example, calculations are performed based on user input.
* Includes:
* - Creating selection screens as regular dynpros with
* SELECTION-SCREEN BEGIN/END OF SCREEN ... statements
* - Creating selection screens as subscreen dynpros with the AS SUBSCREEN
* addition
* - Calling standalone selection screen with CALL SELECTION-SCREEN
* statements
* - Using variants of the SELECTION-SCREEN statements that do not create
* selection screens, but are used to modify the layout
* - INCLUDE addition for reusing already created elements
*
* Notes:
* - A selection of additions is used. For more additions and details,
* see the ABAP Keyword Documentation.
* - See the ABAP cheat sheet for other statements used here, for example,
* the ones related to event blocks such as START-OF-SELECTION.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the program with the ABAP development tools for Eclipse (ADT).
* - Choose F8 to run 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.
*
***********************************************************************
PROGRAM.
"Creating standalone selection screens as regular dynpros
"The dynpro number must be unique in the program. Do not use 1000.
SELECTION-SCREEN BEGIN OF SCREEN 9810.
"Here go all PARAMETERS, SELECT-OPTIONS, and SELECTION-SCREEN statements
"to define the screen elements of the standalone selection screen.
SELECTION-SCREEN COMMENT /1(70) t1.
PARAMETERS number1 TYPE i OBLIGATORY.
SELECTION-SCREEN END OF SCREEN 9810.
"AS WINDOW/TITLE: The following selection screen is displayed in a modal
"dialog box. Plus, a title is specified.
SELECTION-SCREEN BEGIN OF SCREEN 9820 TITLE title1 AS WINDOW.
SELECTION-SCREEN COMMENT /1(70) t2.
PARAMETERS number2 TYPE i OBLIGATORY.
SELECTION-SCREEN END OF SCREEN 9820.
"Creating a standalone selection screens as subscreen dynpro
"They can be included in other dynpros or selection screens, or in
"subscreen areas or tab pages. The following example covers the latter.
"Note: The selection screens as subscreen dynpros cannot be called
"explicitly.
"The following two selection screens are included in tab pages
"further down.
SELECTION-SCREEN BEGIN OF SCREEN 9830 AS SUBSCREEN.
PARAMETERS: number3 TYPE i OBLIGATORY,
number4 TYPE i OBLIGATORY.
SELECTION-SCREEN END OF SCREEN 9830.
SELECTION-SCREEN BEGIN OF SCREEN 9840 AS SUBSCREEN.
PARAMETERS: plus AS CHECKBOX DEFAULT 'X',
minus AS CHECKBOX DEFAULT 'X',
multiply AS CHECKBOX DEFAULT 'X',
divide AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF SCREEN 9840.
"The following selection screen (as regular dynpro) is created
"as dummy, i.e. it is not included as the ones above. It is
"used to demonstrate the INCLUDE addition.
SELECTION-SCREEN BEGIN OF SCREEN 9850.
SELECTION-SCREEN COMMENT /1(50) t3.
SELECTION-SCREEN END OF SCREEN 9850.
"The following declaration is required in the context of the
"TABBED BLOCK addition.
TABLES sscrfields.
"The following selection screen (as regular dynpro) is created to
"demonstrate ...
"- the use of subscreen dynpros. In this case, the subscreen dynpros
" are used in the context of tab pages (TABBED BLOCK, TAB additions).
"- the reuse of available screen elements in the program using the
" INCLUDE addition.
SELECTION-SCREEN BEGIN OF SCREEN 9860 TITLE title2.
SELECTION-SCREEN INCLUDE COMMENT /1(70) t3. "Reusing a screen element
SELECTION-SCREEN: BEGIN OF TABBED BLOCK tabs FOR 10 LINES,
"In such a TABBED BLOCK statement, only TAB statements are allowed
"to include subscreen dynpros.
"The USER-COMMAND addition specifies a function code. If a tab is
"selected by users, the function code can be evaluated using the the
"component ucomm of the structure sscrfields after the
"AT SELECTION-SCREEN event.
TAB (20) btn_nums USER-COMMAND uc_num,
TAB (20) btn_op USER-COMMAND uc_op,
END OF BLOCK tabs.
SELECTION-SCREEN END OF SCREEN 9860.
**********************************************************************
INITIALIZATION.
title1 = 'First calculation'.
title2 = 'Second calculation'.
t1 = 'Insert an integer value for the first calculation.'.
t2 = 'Provide the second number for the first calculation.'.
t3 = 'Make entries in the tabs for the second calculation.'.
btn_nums = 'Numbers'.
btn_op = 'Operators'.
"Instead of the following assignements, you can also use the DEFAULT,
"SCREEN, PROGRAM additions of the ... TAB ... statement
tabs-prog = sy-repid.
tabs-dynnr = 9830.
tabs-activetab = 'UC_NUM'.
**********************************************************************
AT SELECTION-SCREEN.
CASE sy-dynnr.
WHEN 9860.
CASE sscrfields-ucomm.
WHEN 'UC_NUM'.
tabs-dynnr = 9830.
WHEN 'UC_OP'.
tabs-dynnr = 9840.
ENDCASE.
ENDCASE.
**********************************************************************
START-OF-SELECTION.
"The following statements call the selection screens.
CALL SELECTION-SCREEN 9810.
IF sy-subrc = 0.
"STARTING AT: Specifies that the selection screen is displayed as a
"modal dialog box.
CALL SELECTION-SCREEN 9820 STARTING AT 10 10.
ENDIF.
IF sy-subrc = 0.
CALL SELECTION-SCREEN 9860.
ENDIF.
IF sy-subrc = 0.
"Creating a classic list
WRITE / |Results of the first calculation using the provided numbers { number1 } and { number2 } (all basic arithmetic operations):| COLOR COL_POSITIVE.
WRITE / |{ number1 } + { number2 } = { number1 + number2 }|.
WRITE / |{ number1 } - { number2 } = { number1 - number2 }|.
TRY.
WRITE / |{ number1 } * { number2 } = { number1 * number2 }|.
CATCH cx_sy_arithmetic_error INTO DATA(error).
WRITE / |{ number1 } * { number2 } = ??? Error in multiplication: { error->get_text( ) }| COLOR COL_NEGATIVE.
ENDTRY.
TRY.
WRITE / |{ number1 } / { number2 } = { CONV decfloat34( number1 / number2 ) DECIMALS = 3 }|.
IF number1 = 0 AND number2 = 0.
WRITE / `No zero division error? Note that ABAP "allows" zero division if the first number is also 0 :)` COLOR COL_NEGATIVE.
ENDIF.
CATCH cx_sy_zerodivide INTO error.
WRITE / |{ number1 } / { number2 } = ??? Error in division: { error->get_text( ) }| COLOR COL_NEGATIVE.
ENDTRY.
SKIP 2.
WRITE / |Results of the second calculation using the provided numbers { number3 } and { number4 } (selected basic arithmetic operations):| COLOR COL_POSITIVE.
IF plus IS INITIAL
AND minus IS INITIAL
AND multiply IS INITIAL
AND divide IS INITIAL.
WRITE / 'You did not select any operators from the tab. No calculation was performed.' COLOR COL_NEGATIVE.
ELSE.
IF plus = 'X'.
WRITE / |{ number3 } + { number4 } = { number3 + number4 }|.
ENDIF.
IF minus = 'X'.
WRITE / |{ number3 } - { number4 } = { number3 - number4 }|.
ENDIF.
IF multiply = 'X'.
TRY.
WRITE / |{ number3 } * { number4 } = { number3 * number4 }|.
CATCH cx_sy_arithmetic_error INTO error.
WRITE / |{ number3 } * { number4 } = ??? Error in multiplication: { error->get_text( ) }| COLOR COL_NEGATIVE.
ENDTRY.
ENDIF.
IF divide = 'X'.
TRY.
WRITE / |{ number3 } / { number4 } = { CONV decfloat34( number3 / number4 ) DECIMALS = 3 }|.
IF number3 = 0 AND number4 = 0.
WRITE / `No zero division error? Note that ABAP "allows" zero division if the first number is also 0 :)` COLOR COL_NEGATIVE.
ENDIF.
CATCH cx_sy_zerodivide INTO error.
WRITE / |{ number3 } / { number4 } = ??? Error in division: { error->get_text( ) }| COLOR COL_NEGATIVE.
ENDTRY.
ENDIF.
ENDIF.
ENDIF.

View File

@@ -0,0 +1,23 @@
<?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_SELSCR_STANDALONE</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Standalone selection screens (ABAP cheat sheet)</ENTRY>
<LENGTH>47</LENGTH>
</item>
</TPOOL>
</asx:values>
</asx:abap>
</abapGit>

View File

@@ -0,0 +1,263 @@
***********************************************************************
*
* ABAP cheat sheet: Selection screens and classic lists
* Example: Variants of SELECTION-SCREEN statements
*
* -------------------------- PURPOSE ----------------------------------
* Example that demonstrates variants of the SELECTION-SCREEN statements
* to modify the layout, create additional screen elements etc.
* Includes:
* - Adding blank lines (SKIP)
* - Creating a horizontal line (ULINE)
* - Providing text (COMMENT)
* - Creating a pushbutton (PUSHBUTTON)
* - Specifying the output position of a screen element (POSITION)
* - Defining a new line with multiple elements (BEGIN OF LINE)
* - Creating blocks (BLOCK)
* - Creating tabbed blocks (TABBED BLOCK/TAB)
* - Assigning a screen element to a modification group (MODIF ID)
* - Adding pushbuttons in the application toolbar (FUNCTION KEY)
*
* Notes:
* - A selection of additions is used. For more additions and details,
* see the ABAP Keyword Documentation.
* - See the ABAP cheat sheet for other statements used here, for example,
* the ones related to event blocks such as START-OF-SELECTION.
*
* ----------------------- GETTING STARTED -----------------------------
* - Open the program with the ABAP development tools for Eclipse (ADT).
* - Choose F8 to run 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.
*
***********************************************************************
PROGRAM.
"The following declaration is required in the context of the
"TABBED BLOCK, FUNCTION KEY, and USER-COMMAND additions.
TABLES sscrfields.
"Creating blocks (BLOCK)
"The WITH FRAME additions draws a frame around a block.
"Note that the block must be ended with a ... END OF BLOCK ... statement.
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME.
"Providing text (COMMENT)
SELECTION-SCREEN COMMENT /30(70) t1.
"Assigning a screen element to a modification group (MODIF ID)
"An identifier can be specified to assign a screen element to a
"modification group. This identifier is assigned to the component
"'group1' of the SCREEN structure. Using MODIFY SCREEN statements,
"the elements can be modified before displaying
"in the AT SELECTION-SCREEN OUTPUT event block.
"Note: The additions is possible for PARAMETERS, SELECT-OPTIONS
"and SELECTION-SCREEN.
PARAMETERS my_name LIKE sy-uname MODIF ID nd.
"Adding blank lines (SKIP)
"Just SKIP, no further addition means it skips one line.
SELECTION-SCREEN SKIP.
PARAMETERS sap_rel LIKE sy-saprl MODIF ID nd.
"Specifying the number of blank lines
SELECTION-SCREEN SKIP 2.
"Creating a horizontal line (ULINE)
SELECTION-SCREEN ULINE /10(40).
PARAMETERS random_i TYPE i MODIF ID nd.
SELECTION-SCREEN END OF BLOCK block1.
SELECTION-SCREEN ULINE.
SELECTION-SCREEN SKIP.
"Defining a new line with multiple elements (BEGIN OF LINE)
"Chained statements are handy.
SELECTION-SCREEN: BEGIN OF LINE,
"Specifying the output position of a screen element (POSITION)
"Only possible within BEGIN/END OF LINE
POSITION 2,
PUSHBUTTON (5) btn1 USER-COMMAND btn_1,
POSITION 9,
COMMENT (25) t2,
POSITION 35,
PUSHBUTTON (5) btn2 USER-COMMAND btn_2,
POSITION 42,
COMMENT (25) t3,
END OF LINE.
SELECTION-SCREEN SKIP.
"Radio buttons in a block with a frame and title
SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE title1.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: rb1 RADIOBUTTON GROUP grp.
SELECTION-SCREEN COMMENT (20) text1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: rb2 RADIOBUTTON GROUP grp.
SELECTION-SCREEN COMMENT (20) text2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK block2.
SELECTION-SCREEN SKIP.
"Further statements with the MODIF ID addition
"The layout of the following screen element should be modified
"using the specified ID.
"Note: Outside of BEGIN/END OF LINE statements, the specified
"format must contain one position (/...)
SELECTION-SCREEN COMMENT /10(70) t4 MODIF ID mod.
SELECTION-SCREEN BEGIN OF BLOCK bl WITH FRAME.
"The layout of the following screen elements should be modified
"using the specified ID.
PARAMETERS: pa1 RADIOBUTTON GROUP gr MODIF ID mbl,
pa2 RADIOBUTTON GROUP gr MODIF ID mbl,
pa3 RADIOBUTTON GROUP gr,
pa4 RADIOBUTTON GROUP gr.
SELECTION-SCREEN END OF BLOCK bl.
"Creating tabbed blocks (TABBED BLOCK/TAB)
"Creating standalone selection screens as subscreen dynpros
"They can be included in other dynpros or selection screens, or in
"subscreen areas or tab pages. This example covers the latter.
SELECTION-SCREEN BEGIN OF SCREEN 9990 AS SUBSCREEN.
PARAMETERS: par_sub1 TYPE c LENGTH 10 LOWER CASE.
SELECTION-SCREEN END OF SCREEN 9990.
SELECTION-SCREEN BEGIN OF SCREEN 9991 AS SUBSCREEN.
PARAMETERS: par_sub2 TYPE c LENGTH 10 LOWER CASE.
SELECTION-SCREEN END OF SCREEN 9991.
SELECTION-SCREEN: BEGIN OF TABBED BLOCK tabs FOR 2 LINES,
"The USER-COMMAND addition specifies a function code.
"If a tab is selected by users, the function code can
"be evaluated using the the component ucomm of the structure
"sscrfields after the AT SELECTION-SCREEN event.
TAB (20) tabtitl1 USER-COMMAND tab1,
TAB (20) tabtitl2 USER-COMMAND tab2,
END OF BLOCK tabs.
"Adding pushbuttons in the application toolbar (FUNCTION KEY)
"There are five inactive pushbuttons to which the function codes FC01, FC02
"up to FC05 are assigned. The ... FUNCTION KEY ... statement activates the
"pushbuttons for the specified codes.
"Note: To enable it, include the statement 'TABLES sscrfields.' in the code.
"When the button is clicked, the event AT SELECTION-SCREEN is raised and the
"function code is passed to the 'ucomm' component in the interface
"work area 'sscrfields' which can be evaluated and reacted upon accordingly,
"e.g. in a CASE control structure.
SELECTION-SCREEN: FUNCTION KEY 1, "Stands for FC01
FUNCTION KEY 2, "FC02
FUNCTION KEY 3, "FC03
FUNCTION KEY 4. "FC04
**********************************************************************
INITIALIZATION.
title1 = 'Block including radio buttons + comments put in one line using BEGIN/END OF LINE'.
t1 = 'This is a selection screen comment included in a block with frame.'.
t2 = '<- Click to get the time'.
t3 = '<- Click to get the date'.
t4 = 'This text and the following radio button group was modified.'.
text1 = 'Radio button A'.
text2 = 'Radio button B'.
btn1 = 'A'.
btn2 = 'B'.
"Relevant to the tabbed blocks
tabtitl1 = 'Selection Screen A'.
tabtitl2 = 'Selection Screen B'.
tabs-prog = sy-repid.
tabs-dynnr = 9990.
tabs-activetab = 'TAB1'.
"Relevant to the function keys
"To provide text for the buttons, assign values to the component functxt_0n
"(while n stands for the numbers 1 - 5). Otherwise, there won't be any button
"text.
sscrfields-functxt_01 = 'Get my name'.
sscrfields-functxt_02 = 'Get ABAP release'.
sscrfields-functxt_03 = 'Get random integer'.
sscrfields-functxt_04 = 'Clear input fields'.
**********************************************************************
AT SELECTION-SCREEN OUTPUT.
"Modifying the layout of screen elements
LOOP AT SCREEN INTO DATA(wa).
IF wa-group1 = 'MOD'.
"Intensify the text output
wa-intensified = '1'.
MODIFY SCREEN FROM wa.
ENDIF.
IF wa-group1 = 'MBL'.
"Make the screen element invisible
wa-invisible = '1'.
MODIFY SCREEN FROM wa.
ENDIF.
IF wa-group1 = 'ND'.
"Disable the input for a field
wa-input = '0'.
MODIFY SCREEN FROM wa.
ENDIF.
ENDLOOP.
**********************************************************************
AT SELECTION-SCREEN.
"Evaluating the function codes relevant to the
"TABBED BLOCK, FUNCTION KEY, and USER-COMMAND additions.
"Evaluating only if sy-dynnr has the value of the standard selection
"screen
CHECK sy-dynnr = 1000.
CASE sscrfields-ucomm.
WHEN 'FC01'.
my_name = sy-uname.
WHEN 'FC02'.
sap_rel = sy-saprl.
WHEN 'FC03'.
random_i = cl_abap_random_int=>create(
seed = cl_abap_random=>seed( ) min = 1
max = 100 )->get_next( ).
WHEN 'FC04'.
CLEAR: my_name, sap_rel, random_i, par_sub1, par_sub2.
WHEN 'BTN_1'.
MESSAGE |You clicked button A. The time is { sy-uzeit TIME = ISO }.| TYPE 'I'.
WHEN 'BTN_2'.
MESSAGE |You clicked button B. The date is { sy-datum DATE = ISO }.| TYPE 'I'.
WHEN 'TAB1'.
tabs-dynnr = 9990.
WHEN 'TAB2'.
tabs-dynnr = 9991.
ENDCASE.
**********************************************************************
START-OF-SELECTION.
"Creating a classic list
WRITE / `This list displays the values provided on the selection screen.`.
SKIP.
WRITE / |my_name: "{ my_name }"|.
WRITE / |sap_rel: "{ sap_rel }"|.
WRITE / |random_i: "{ random_i }"|.
WRITE / |Radio button selected (1): "{ COND #( WHEN rb1 = 'X' THEN 'rb1' ELSE 'rb2' ) }"| .
WRITE / |Radio button selected (2): "{ COND #( WHEN pa1 = 'X' THEN 'pa1' WHEN pa2 = 'X' THEN 'pa2' WHEN pa3 = 'X' THEN 'pa3' ELSE 'pa4' ) }"| .
WRITE / |par_sub1: "{ par_sub1 }"|.
WRITE / |par_sub2: "{ par_sub2 }"|.

View File

@@ -0,0 +1,23 @@
<?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_SELSCR_STMTS_VAR</NAME>
<DBAPL>S</DBAPL>
<DBNA>D$</DBNA>
<SUBC>1</SUBC>
<FIXPT>X</FIXPT>
<LDBNAME>D$S</LDBNAME>
<UCCHECK>X</UCCHECK>
</PROGDIR>
<TPOOL>
<item>
<ID>R</ID>
<ENTRY>Variants of SELECTION-SCREEN statements (ABAP cheat sheet)</ENTRY>
<LENGTH>58</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.
*
* You can also 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,372 @@
***********************************************************************
*
* 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 ABAP Cloud.
* For example, in ABAP Cloud only read-only operations are possible.
* In general, there are more syntax options available in classic
* ABAP. 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_aux=>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.
out->write( `ABAP Cheat Sheet Example: ABAP AMDP` ).
out->write( |\n1) AMDP Procedure\n\n| ).
"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 ).
out->write( data = amdp_proc_res name = `amdp_proc_res` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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).
out->write( error1->get_text( ) ).
ENDTRY.
out->write( data = call_amdp_res name = `call_amdp_res` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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.
out->write( data = 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' ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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).
out->write( data = 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,717 @@
***********************************************************************
*
* 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_aux DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
CLASS-METHODS: clear_dbtabs,
fill_dbtabs,
heading IMPORTING text TYPE string
RETURNING VALUE(output) TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap_aux 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.
METHOD heading.
output = |\n_________________________________________________________________________________\n\n{ text }\n\n|.
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_AUX</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>

View File

@@ -0,0 +1,481 @@
***********************************************************************
*
* 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.
protected section.
private section.
ENDCLASS.
CLASS ZCL_DEMO_ABAP_CDS_VE IMPLEMENTATION.
METHOD class_constructor.
"Filling demo database tables.
zcl_demo_abap_aux=>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.
out->write( |ABAP Cheat Sheet Example: CDS view entities\n\n| ).
out->write( `1) Operands, expressions and built-in functions ` &&
|in a CDS view entity\n\n| ).
"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).
out->write( data = select_from_cds name = `select_from_cds` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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).
out->write( data = agg_expr name = `agg_expr` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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).
out->write( data = cds_joins name = `cds_joins` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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.
out->write( `---------- Inner join ----------` ).
out->write( |\n| ).
out->write( |\n| ).
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).
out->write( data = sql_inner_join name = `sql_inner_join` ).
out->write( |\n| ).
out->write( `---------- Left outer join ----------` ).
out->write( |\n| ).
out->write( |\n| ).
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).
out->write( data = sql_left_outer_join name = `sql_left_outer_join` ).
out->write( |\n| ).
out->write( `---------- Right outer join ----------` ).
out->write( |\n| ).
out->write( |\n| ).
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).
out->write( data = sql_right_outer_join name = `sql_right_outer_join` ).
out->write( |\n| ).
out->write( `---------- Cross join ----------` ).
out->write( |\n| ).
out->write( |\n| ).
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).
out->write( data = sql_cross_join name = `sql_cross_join` ).
out->write( |\n| ).
"Just a check what join example is currently commented in
IF cds_joins = sql_inner_join.
out->write( `In the example CDS view entity, the inner join example is commented in.` ).
ELSEIF cds_joins = sql_left_outer_join.
out->write( `In the example CDS view entity, the left outer join example is commented in.` ).
ELSEIF cds_joins = sql_right_outer_join.
out->write( `In the example CDS view entity, the right outer join example is commented in.` ).
ELSEIF cds_joins = sql_cross_join.
out->write( `In the example CDS view entity, the cross join example is commented in.` ).
ELSE.
out->write( `In the example CDS view entity, there is some other code present.` ).
ENDIF.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `Associations` ) ).
out->write( |5) Selecting data from a CDS view that contains associations\n\n| ).
"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).
out->write( data = assoc name = `assoc` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `Using exposed associations in ABAP SQL statements: ...` ) ).
"The following examples use path expressions to access the association
"targets of exposed associations.
out->write( |6) ... SELECT clause\n\n| ).
"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).
out->write( data = assoc_exp_select name = `assoc_exp_select` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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).
out->write( data = assoc_exp_from name = `assoc_exp_from` ).
out->write( |\n| ).
"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).
out->write( data = sql_repr name = `sql_repr` ).
out->write( |\n| ).
IF sql_repr = assoc_exp_from.
out->write( `The result sets are the same.` ).
ELSE.
out->write( `The result sets are differrent.` ).
ENDIF.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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).
out->write( data = assoc_attr_card name = `assoc_attr_card` ).
out->write( |\n| ).
"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).
out->write( data = assoc_attr_joty name = `assoc_attr_joty` ).
out->write( |\n| ).
"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).
out->write( data = assoc_attr_where name = `assoc_attr_where` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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).
out->write( data = 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>

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>

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,514 @@
***********************************************************************
*
* 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 V4 - 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.
* The effect of side effects can be explored as follows: Make an entry
* in an input field, click another input field (e.g. to make a new entry
* there), and check how the value for the result changes.
*
* ----------------------------- 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.
out->write( `ABAP Cheat Sheet Example: RAP Calculator Using Managed, ` &&
|Draft-Enabled RAP BO (Late Numbering)\n\n| ).
out->write( |1) Creating Instances and Saving to the database\n| ).
"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.
out->write( `Responses after MODIFY operation` ).
out->write( |\n| ).
IF m IS NOT INITIAL.
out->write( data = m name = `m` ).
out->write( |\n| ).
ENDIF.
IF f IS NOT INITIAL.
out->write( data = f name = `f` ).
out->write( |\n| ).
ENDIF.
IF r IS NOT INITIAL.
out->write( data = r name = `r` ).
out->write( |\n| ).
ENDIF.
ENDIF.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `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.
out->write( `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
out->write( |1a) Draft and database tables before ACTIVATE action\n| ).
out->write( `Draft table before activation` ).
out->write( |\n| ).
out->write( data = draft_parent_before_act name = `draft_parent_before_act` ).
out->write( |\n| ).
out->write( `Database table before activation` ).
out->write( |\n| ).
out->write( data = db_tab_root_before_act name = `db_tab_root_before_act` ).
out->write( zcl_demo_abap_aux=>heading( `1b) Draft and database tables after ` &&
`ACTIVATE action` ) ).
out->write( `Draft table after activation` ).
out->write( |\n| ).
out->write( data = draft_parent_afer_act name = `draft_parent_afer_act` ).
out->write( |\n| ).
out->write( `Database table after activation` ).
out->write( |\n| ).
out->write( data = db_tab_root_after_act name = `db_tab_root_after_act` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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.
out->write( data = `Responses after MODIFY operation` ).
out->write( |\n| ).
IF m IS NOT INITIAL.
out->write( data = m name = `m` ).
out->write( |\n| ).
ENDIF.
IF f IS NOT INITIAL.
out->write( data = f name = `f` ).
out->write( |\n| ).
ENDIF.
IF r IS NOT INITIAL.
out->write( data = r name = `r` ).
out->write( |\n| ).
ENDIF.
ENDIF.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `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.
out->write( data = `Responses after MODIFY operation` ).
out->write( |\n| ).
IF m IS NOT INITIAL.
out->write( data = m name = `m` ).
out->write( |\n| ).
ENDIF.
IF f IS NOT INITIAL.
out->write( data = f name = `f` ).
out->write( |\n| ).
ENDIF.
IF r IS NOT INITIAL.
out->write( data = r name = `r` ).
out->write( |\n| ).
ENDIF.
ENDIF.
COMMIT ENTITIES.
IF sy-subrc <> 0.
out->write( `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
out->write( zcl_demo_abap_aux=>heading( `2a) Draft and database tables before ` &&
`ACTIVATE action` ) ).
out->write( `Draft table before activation` ).
out->write( |\n| ).
out->write( data = draft_parent_before_act name = `draft_parent_before_act` ).
out->write( |\n| ).
out->write( `Database table before activation` ).
out->write( |\n| ).
out->write( data = db_tab_root_before_act name = `db_tab_root_before_act` ).
out->write( zcl_demo_abap_aux=>heading( `2b) Draft and database tables after ` &&
`ACTIVATE action` ) ).
out->write( `Draft table after activation` ).
out->write( |\n| ).
out->write( data = draft_parent_afer_act name = `draft_parent_afer_act` ).
out->write( |\n| ).
out->write( `Database table after activation` ).
out->write( |\n| ).
out->write( data = db_tab_root_after_act name = `db_tab_root_after_act` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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.
out->write( `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.
out->write( `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
out->write( data = `Draft and database tables after ` &&
`ACTIVATE action` ).
out->write( |\n| ).
out->write( `Draft table after activation` ).
out->write( |\n| ).
out->write( data = draft_parent_afer_act name = `draft_parent_afer_act` ).
out->write( |\n| ).
out->write( `Database table after activation` ).
out->write( |\n| ).
out->write( data = 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>

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_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,181 @@
***********************************************************************
*
* 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_aux=>fill_dbtabs( ).
ENDMETHOD.
METHOD if_oo_adt_classrun~main.
out->write( |ABAP Cheat Sheet Example: Grouping Internal Tables\n\n| ).
SELECT *
FROM zdemo_abap_flsch
INTO TABLE @DATA(fli_tab).
out->write( |1) Representative Binding\n| ).
out->write( |1a) Grouping by one column\n| ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid.
out->write( wa-carrid ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `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.
out->write( members ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `1c) Grouping by two columns` ) ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom ).
out->write( |{ wa-carrid } { wa-airpfrom }| ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `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.
out->write( members ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `2) Group Key Binding` ) ).
out->write( |2a) Grouping by one column\n| ).
LOOP AT fli_tab INTO wa
GROUP BY wa-carrid
INTO DATA(key).
out->write( key ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `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.
out->write( members ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `2c) Grouping by two columns` ) ).
LOOP AT fli_tab INTO wa
GROUP BY ( key1 = wa-carrid key2 = wa-airpfrom )
INTO DATA(keys).
out->write( keys ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `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.
out->write( members ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `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).
out->write( keysplus ).
out->write( |\n| ).
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,678 @@
***********************************************************************
*
* 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_aux=>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.
out->write( |ABAP Cheat Sheet Example: ABAP Unit Tests\n\n| ).
out->write( `************************************************************************` ).
out->write( `---> Choose Ctrl/Cmd + Shift + F10 to launch all tests in the class <---` ).
out->write( |************************************************************************\n| ).
out->write( |1) get_sum Method\n\n| ).
"This method demonstrates the use of the setup and teardown methods in the test class.
DATA(sum) = get_sum( key = 1 char = 'aaa' ).
out->write( data = sum name = `sum` ).
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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>).
DATA(tabix) = sy-tabix.
get_common_div_and_gcd( EXPORTING a = <a>-num1
b = <a>-num2
IMPORTING common_divisors = DATA(common_divs) gcd = DATA(gcd) ).
out->write( |Common divisors of { <a>-num1 } and { <a>-num2 }\n| ).
out->write( |\n| ).
out->write( data = common_divs name = `common_divs` ).
out->write( |\n| ).
out->write( |Greatest common divisor of { <a>-num1 } and { <a>-num2 }: { gcd } | ).
out->write( |\n| ).
IF tabix < lines( tab ).
out->write( `--------------------------` ).
out->write( |\n| ).
ENDIF.
ENDLOOP.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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> ).
out->write( |The digit sum of { <b> } is { digit_sum }.| ).
out->write( |\n| ).
ENDLOOP.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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 ).
out->write( |The occupancy rate for airline { <c>-carrid } is { occupancy_rate }%.| ).
out->write( |\n| ).
ENDLOOP.
out->write( zcl_demo_abap_aux=>heading( `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) ).
out->write( |The occupancy rate for airline { <d>-carrid } is { occupancy_rate_test_seam }%.| ).
out->write( |\n| ).
out->write( |num1: { num1 }| ).
out->write( |\n| ).
out->write( |num2: { num2 }| ).
out->write( |\n| ).
ENDLOOP.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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 ).
out->write( |The occupancy rate for airline { <e>-carrid } is { occupancy_rate_local_itf }%.| ).
out->write( |\n| ).
ENDLOOP.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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 ).
out->write( |The occupancy rate for airline { <f>-carrid } is { occupancy_rate_global_itf }%.| ).
out->write( |\n| ).
ENDLOOP.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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 ).
out->write( |The occupancy rate for airline { <g>-carrid } is { occupancy_rate_setter_inj }%.| ).
out->write( |\n| ).
ENDLOOP.
**********************************************************************
out->write( zcl_demo_abap_aux=>heading( `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 ).
out->write( |The occupancy rate for airline { <h>-carrid } is { occupancy_rate_param_inj }%.| ).
out->write( |\n| ).
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>

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_XML_JSON</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>ABAP cheat sheet: Working with XML and JSON in ABAP</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</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_demo_abap_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>

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