原创 无峰 [ ABAP 技巧与实战 ](javascript:void\(0\);)
一
前言
最近发现常用的会计凭证冲销功能无法使用了. 对常见凭证冲销时会报错
在解决这个问题的过程,有了本文的内容.
**本文主要介绍会计凭证冲销相关的BAPI函数**
二
标准BAPI报错分析
标准BAPI 函数
BAPI_ACC_DOCUMENT_REV_POST
跟踪错误 RW 628 .
在BAPI 开始会执行类型检查逻辑,相关类别(包括 BKPF )都会触发BAPI报错. 执行这些检查的原因不明.
但客观上阻止了这个函数冲销大部分凭证.但FB08可以冲销这个报错的凭证
三
解决方式
BAPI函数无法冲销(也可以考虑强行去掉BAPI函数的凭证类别检查), 就只能采用BDC的方式冲销了. BDC可以用如下三种方式
• 自行录制BDC
• 使用标准函数CALL_FB08
• POSTING_INTERFACE_REVERSE_DOC
其中CALL_FB08调用后无法获取冲销产生的新凭证号,
自行录制的BDC可以通过消息获取生成的凭证,但稳定性可能不足.
最终建议使用函数
POSTING_INTERFACE_REVERSE_DOC冲销会计凭证.
需要注意的是需要依次调用以下三个函数
• POSTING_INTERFACE_START
• POSTING_INTERFACE_REVERSE_DOC
• POSTING_INTERFACE_END
四
凭证分类
根据目前的经验给会计凭证分了两类
• 标准会计凭证(通过前台或者业务过账产生的凭证)
• 清账会计凭证(使用清账程序产生的会计凭证)
其中清账会计凭证可以细分为
• 清账产生的凭证有凭证行, (剩余清账)
• 清账产生的凭证没有凭证行( 完全清账 )
清账凭证通过TCODE FBRA 清除清账信息.
剩余清账-清账产生新的凭证行
完全清账产生的凭证没有凭证行
对于清账产生凭证的冲销,需要先清除清账标记. 完全清账的,清除清账标记即可. 剩余清账的, 清除清账标记后, 还需要再次冲销凭证,
五
封装
基于上述分析把,会计凭证的冲销逻辑封装到函数Z_BC_CANCEL_FB中
先判断会计凭证类别(识别逻辑可能需要优化)
非清账凭证直接冲销
清账凭证先清除清账标记
对于剩余清账的凭证,存在新的凭证行, 则再次调用凭证的冲销.
总结
会计凭证的冲销本身逻辑不复杂. 因为标准BAPI函数的限制及清账凭证的特殊性, 才有了一些复杂性.
函数组FIPI整合了标准BDC调用产生会计凭证的函数. 这些函数中考虑BDC过程中的所有可能的屏幕逻辑, 比自行录制的BDC好用很多 .
** THE **
** END **
**约定**
如果你对这篇文章感兴趣,请帮忙点赞,在看,分享.
syjf1976
sharry_xlp
Yannick_Duan
申请进入公众号讨论群提问或者参与话题讨论
以下内容整理自 SAP 官方 ABAP 速查表(主题:Released ABAP Classes),作为本文的扩展补充资料。
This ABAP cheat sheet contains a selection of released ABAP classes that are available in ABAP for Cloud Development. It serves as a quick introduction, along with code snippets to explore the functionality in action.
[!NOTE] - The cheat sheet is not a comprehensive overview, and the code snippets do not claim to be comprehensive as far as options, methods, or parameters are concerned. It is intended to give you a rough overview, for you to get an idea. It is an invitation to a more in-depth exploration. - For more information and where available, refer to the class documentation (for example, choose F2 when the cursor is on the class name in ADT), the ABAP Keyword Documentation, and the SAP Help Portal documentation. - You might find that different classes can achieve similar or the same results, especially with the Extension Components Library (XCO), a general-purpose development library designed specifically for ABAP for Cloud Development. Choose the classes that best meet your needs. - For XCO classes, the cheat sheet covers released XCO APIs. In Standard ABAP, XCO APIs are also available that do not have CP in the class name. These classes are not covered here. - Disclaimer
If available to you, you have accessed an SAP BTP ABAP Environment using the ABAP development tools for Eclipse (ADT). Access to SAP-provided repository objects is restricted to objects that have been released for ABAP for Cloud Development (released APIs). You can find the released repository objects in the Project Explorer view in ADT under Released Objects. The classes are located in the Source Code Library folder:

You can also programmatically get the released objects. You can use specific XCO classes or a CDS view, as shown in the example code snippet below.
SELECT ReleasedObjectType, ReleasedObjectName, ReleaseState
FROM i_apisforclouddevelopment
WHERE releasestate = 'RELEASED'
AND ReleasedObjectType = 'CLAS'
ORDER BY ReleasedObjectName
INTO TABLE @DATA(released_classes).The I_APIsWithCloudDevSuccessor view provides information on objects that cannot or should no longer be used in ABAP for Cloud Development along with their successors that can be used.
SELECT * FROM I_APIsWithCloudDevSuccessor
INTO TABLE @DATA(successors_all).
SELECT * FROM I_APIsWithCloudDevSuccessor
WHERE PredecessorObjectType = 'TABL'
INTO TABLE @DATA(successors_tables).
SELECT SINGLE * FROM I_APIsWithCloudDevSuccessor
WHERE PredecessorObjectName = 'TADIR'
INTO @DATA(successor_tadir).The table includes the IF_OO_ADT_CLASSRUN interface.
| Interface/Class | Details/Code Snippet |
IF_OO_ADT_CLASSRUN |
|
CL_DEMO_CLASSRUN | As an alternative to using the IF_OO_ADT_CLASSRUN interface for displaying output in the console, you can also use the CL_DEMO_CLASSRUN class, which offers more methods. For more information, refer to this blog. The following example makes use of the CL_DEMO_CLASSRUN class. A structure and an internal table are displayed in the console. A structure component is a reference variable, which is automatically dereferenced. Plus, the write_xml method is shown, which displays XML data. |
CL_XCO_CP_ADT_SIMPLE_CLASSRUN |
XCO alternative for output in the ADT console |
[!TIP] - TheCL_DEMO_OUTPUT_CLOUDclass is available for demo purposes only. It wraps the output functionalities of theCL_DEMO_OUTPUTclass that is available in Standard ABAP and used for demo display purposes, especially useful for displaying internal table content. - As an excursion, find examples using the class in Creating and Using IDE Actions. - Find more information in this blog.
| Class | Details/Code Snippet |
CL_SYSTEM_UUID | Creating and converting system UUIDs with various algorithms |
XCO_CP XCO_CP_UUID | Creating UUIDs and transforming between different UUID formats using XCO |
| Class | Details/Code Snippet |
XCO_CP |
|
| Class | Details/Code Snippet |
CL_ABAP_BEHV_AUX | A utility class for retrieving information about RAP handler implementations, such as the current context of RAP handler/saver methods, the handler kind, and the current RAP transactional phase (e.g., RAP interaction phase. |
CL_ABAP_BEHAVIOR_HANDLER | Used for RAP handler classes that inherit from class CL_ABAP_BEHAVIOR_HANDLER. |
CL_ABAP_BEHAVIOR_SAVER | Used as base class from which a RAP saver class in an ABAP behavior pool (ABP) inherits. The RAP saver class must be defined in the CCIMP include of an ABP. |
CL_ABAP_BEHAVIOR_SAVER_FAILED |
|
CL_ABAP_BEHAVIOR_EVENT_HANDLER | It is used as base class from which a RAP event handler class in its CCIMP include inherits. Its purpose is to locally consume RAP business events. More information: ABAP for RAP Business Events. |
| Class | Details/Code Snippet |
CL_ABAP_TX |
|
| Class | Details/Code Snippet |
CL_ABAP_MATH | For operations with (decimal) floating point numbers and for providing constants for minimum and maximum values. |
CL_ABAP_DECFLOAT | For handling decimal floating point numbers. |
CL_ABAP_BIGINT | For calculations with integers of any size (e.g. to avoid the risk of an arithmetic overflow). Find more information in this blog, and check out the different methods available. |
CL_ABAP_RATIONAL | For calculations with rational numbers without precision loss and rounding errors. | CL_ABAP_RANDOM* | For generating arbitrary numbers for different numeric types: CL_ABAP_RANDOM_INT (type i), CL_ABAP_RANDOM_INT8 (int8), CL_ABAP_RANDOM_FLOAT (f), CL_ABAP_RANDOM_PACKED (p), CL_ABAP_RANDOM_PACKED_DEC1 - CL_ABAP_RANDOM_PACKED_DEC14 (p with 1 to 14 decimal places), CL_ABAP_RANDOM_DECFLOAT16 (decfloat16), CL_ABAP_RANDOM_DECFLOAT34 (decfloat34) The following example explores the generation of arbitrary numeric values.
|
CL_ABAP_PROB_DISTRIBUTIONCL_ABAP_PROB_DISTRIBUTION_DF34 |
|
| Class | Details/Code Snippet |
CL_ABAP_CHAR_UTILITIES | Provides utilities for string processing, such as attributes that represent new lines and horizontal tabs. |
CL_ABAP_STRING_UTILITIES | For processing text strings, such as handling trailing blanks in character strings (i.e. data objects of type string). |
XCO_CP | Offers various options to process strings using the XCO Library; see a selection in the code snippet |
| Class | Details/Code Snippet |
CL_ABAP_GZIP* | (De)compressing character strings and byte strings using GZIP: CL_ABAP_GZIP, CL_ABAP_GZIP_BINARY_STREAM, CL_ABAP_GZIP_TEXT_STREAM, CL_ABAP_UNGZIP_BINARY_STREAM, CL_ABAP_UNGZIP_TEXT_STREAM |
CL_ABAP_CONV_CODEPAGE | For handling code pages, converting strings to the binary representation of different code pages and vice versa. |
XCO_CP | Converting strings to xstrings using a codepage using the XCO Library |
XCO_CP | Base64 decoding/encoding using XCO |
CL_WEB_HTTP_UTILITY | Endcoding strings/xstrings in Base64 and decoding Base64-encoded strings/xstrings |
| Class | Details/Code Snippet | CL_ABAP_REGEX CL_ABAP_MATCHER |
|
[!NOTE] In ABAP for Cloud Development, do not use the date and time-related system fields such assy-datumandsy-uzeit, and others. User-related time and date values can be retrieved using the XCO library. For code snippets, see the Date, Time, and Time Stamp cheat sheet.
| Class | Details/Code Snippet |
CL_ABAP_CONTEXT_INFO | Provides context information relevant to the current ABAP session. |
CL_ABAP_DATFM | For conversions between the external and the internal representation of a date specification
|
CL_ABAP_TIMEFM | For conversions between the external and the internal representation of a time specification
|
CL_ABAP_UTCLONG | For handling time stamps in time stamp fields (data objects with type utclong). |
CL_ABAP_TSTMP | For calculating and converting time stamps in packed numbers (types timestamp and timestampl) |
XCO_CP_TIMEXCO_CP | Class of the XCO time library that provides abstractions for getting and working with date and time information. Find more details here. |
| Class | Details/Code Snippet |
CL_FHC_CALENDAR_RUNTIME |
The following example explores accessing calendar-related information (factory and holiday calendars). Find more information in the SAP Help Portal documentation. Note the released CDS views in that context. |
CL_SCAL_UTILS | Calendar utilities for getting month names, year and week of a date, first day of a week, name and number of the weekday for a specified date
|
| Class | Details/Code Snippet |
CL_ABAP_TYPEDESCR | RTTS represent a hierarchy of type description classes containing methods for:
Apart from CL_ABAP_TYPEDESCR |
| Class | Details/Code Snippet |
CL_ABAP_CORRESPONDING |
For assignments of components between structures or between internal tables with dynamically specified mapping rules. For more information, you can refer to the ABAP Keyword Documentation. The example shows simple assignments with structures. |
| Class | Details/Code Snippet |
CL_ABAP_STRUCT_UTILITIES | Provides methods to get information about filled components in structures allowing an efficient processing of non-initial components of a structure. |
| Class | Details/Code Snippet |
CL_ABAP_DIFF | Using the methods diff and diff_with_line_ref of the CL_ABAP_DIFF class, you can compare the content of two compatible index tables. The returning parameter is an internal table showing how the content of one internal table can be modified to match another one. diff_with_line_ref also returns a reference to the original table lines. Various importing parameters are available to adjust the comparison. Find more information in the class documentation and in the ABAP Keyword Documentation.
|
| Class | Details/Code Snippet |
CL_ABAP_DYN_PRG | For validating input for dynamic specifications. |
| Class | Details/Code Snippet |
CL_ABAP_CONTEXT_INFO | Provides context information relevant to the current ABAP session. |
XCO_CP |
|
| Class | Details |
CL_IXML_ CL_SXML_ |
|
XCO_CP_JSON | Handling JSON data using the XCO library |
/UI2/CL_JSON |
|
[!IMPORTANT] - Note that the XCO CP Edition (many of the released XCO APIs include CP in the class name) features released classes specifically designed for cloud usage, particularly in the SAP BTP ABAP Environment. - While these classes can theoretically be used in other system environments, there is no guarantee of API functionality. This is especially true for the classes in this section that provide information about repository objects. Only SAP- and customer-released repository objects are supported. Find more information here. - The following two example snippets use the XCO APIsxco_cp_abap_repositoryandxco_abap_repository(without CP, applicable in Standard ABAP). The assumption is that you have access to a system that supports classic ABAP, thexco_abap_repositoryAPI is available, and you have imported the ABAP cheat sheet repository (or you might use another custom database table). You can use the following to visualize the aforementioned disclaimer. In a class flagged for ABAP for Cloud Development, the following snippet is usable, in principle. However, you may find that it does not verify the existence of the demo database table (as it is not released). If you have imported the ABAP cheat sheet repository into an SAP BTP ABAP Environment, the snippet will return true there. ``"xco_cp_abap_repository DATA(tabl) = xco_cp_abap_repository=>object->tabl->database_table->for( 'ZDEMO_ABAP_CARR' ). DATA(tabl_exists) = tabl->exists( ).`Usingxco_abap_repositoryin a class flagged for use with Standard ABAP, the snippet returns true.`"xco_abap_repository DATA(tabl_2) = xco_abap_repository=>object->tabl->database_table->for( 'ZDEMO_ABAP_CARR' ). DATA(tabl_2_exists) = tabl_2->exists( ).``
| Class | Details/Code Snippet |
XCO_CP_ABAPXCO_CP_ABAP_REPOSITORYXCO_CP_ABAP_DICTIONARY |
|
| Class | Details/Code Snippet |
XCO_CP_GENERATION | For creating, updating and deleting ABAP repository objects. More information: Generation APIs The rudimentary snippet is taken from the executable example of the ABAP for Cloud Development cheat sheet. |
| Class | Details/Code Snippet |
XCO_CPXCO_CP_CALL_STACK | Getting the current ABAP call stack programmatically. See more information here. |
| Class | Details/Code Snippet |
CL_BCS_MAIL_MESSAGE |
The following snippet includes some file attachments: |
| Class | Details/Code Snippet |
XCO_CPXCO_CP_TENANT | For obtaining various information about the currently active tenant. |
| Class | Details/Code Snippet |
CX_* |
Exception classes are special classes, usually starting with the name |
| Class | Details/Code Snippet |
CL_ABAP_PARALLEL | For performing the parallel processing for instances of ABAP Objects. For more information, refer to the class documentation. The following example class demonstrates parallel processing using the
Notes on the example:
|
| Class | Details/Code Snippet |
CL_BALI_LOG | For creating and reading application logs. Refer to this documentation for more information and code snippets. |
XCO_CP_BAL | The XCO module XCO_CP_BAL is available to deal with the business application log. For more information, see here. |
| Class | Details/Code Snippet |
CL_BGMC_PROCESS_FACTORY |
Example 1: Using bgPF without transactional control
Example 2: Using bgPF with transactional control
This example is similar to example 1. Unlike example 1, example 2 executes operations under transactional control. The transactional phase is explicitly switched using the |
| Class | Details/Code Snippet |
CL_ABAP_LOCK_OBJECT_FACTORY | For activating lock objects. Note that you can also use the DEQUEUE_ALL method to remove all locks in the current SAP LUW. The following example code snippet uses artifacts from the ABAP cheat sheet repository. |
| Class | Details/Code Snippet |
CL_WEB_HTTP_CLIENT_MANAGERCL_HTTP_DESTINATION_PROVIDER |
To check out examples in demo classes, expand the collapsible sections below.
[!WARNING] - The following self-contained and oversimplified example is not a representative best practice example, nor does it cover a meaningful use case. It only explores method calls and is intended to give a rough idea of the functionality. - The example uses the
[!WARNING] - As stated for the previous example, also note for this example: Before using the GitHub APIs, make sure that you have consulted the following documentation: GitHub Docs, Render a Markdown document, Rate limits for the REST API - To try it out, create a demo class named
|
| Class | Details/Code Snippet |
XCO_CP_XLSX |
The XCO library offers classes such as Expand the following collapsible sections for further information and example code.
The following example demonstrates a selection of methods and includes the following steps:
[!NOTE] - Note this repository's disclaimer and the disclaimer in the documentation about XCO for security considerations when importing and processing external content. - IDE actions represent a simple way of file import. Find more information in section Excursion: Exploring Demo Display Class Using IDE Actions. Prerequisite Steps for the XLSX Content Import into the SAP BTP ABAP Environment The XLSX XCO module works with XLSX content in the form of an xstring. The following example assumes that you have XLSX content available as xstring. To try out the example, you can proceed as follows:
[!NOTE] - If there are issues with the UI (e.g. you cannot upload), try out UI V2. - Create a new service definition, e.g. right-click the Service Definition folder and choose New Service Definition. - Provide a name (e.g. 📝 Example XLSX content Exploring the XCO XLSX Module Assuming you have the XLSX content created and uploaded above on your system, you can explore the following example using the XCO classes/methods. To try it out, create a demo class named [!NOTE] - Refer to the comments in the code for information. - If you have used different names than those in this example, make sure to replace those names in the code. - If your artifacts have a different setup, names, or XLSX content, the example class will not function properly. You willl need to modify the class code to match your specific requirements. |
| Class | Details/Code Snippet |
CL_ABAP_ZIP |
The following example creates a zip file and adds three txt files with sample content. Note that the example snippet for |
| Class | Details/Code Snippet |
CL_ABAP_UNIT_ASSERT |
Provides methods to verify test expectations in ABAP Unit tests. For more information, see the ABAP Unit Tests cheat sheet. |
CL_ABAP_TESTDOUBLECL_OSQL_TEST_ENVIRONMENTCL_CDS_TEST_ENVIRONMENTCL_BOTD_TXBUFDBL_BO_TEST_ENVCL_BOTD_MOCKEMLAPI_BO_TEST_ENV |
|
| Class | Details/Code Snippet |
CL_UOM_DIM_MAINTENANCE |
|
CL_UOM_MAINTENANCE |
|
CL_UOM_CONVERSION |
|
| Class | Details/Code Snippet |
CL_SATC_API |
|
| Class | Details/Code Snippet |
CL_NUMBERRANGE_OBJECTSCL_NUMBERRANGE_INTERVALSCL_NUMBERRANGE_RUNTIME |
|
| Class | Details/Code Snippet |
CL_ABAP_API_STATE |
|
| Class | Details/Code Snippet |
CL_APJ_DT_CREATE_CONTENTCL_APJ_RT_API |
Notes on the example:
The example does not cover several aspects (check the documentation for more information), including:
Before running the example class, check the values of the constants in the public section of the class. In particular, ensure you have valid values for these constants:
|
| Class | Details/Code Snippet |
CL_AIC_ISLM_COMPL_API_FACTORYCL_AIC_ISLM_PROMPT_TPL_FACTORY |
|
| Class | Details/Code Snippet |
XCO_CP_CTS |
The following code snippet uses the
[!NOTE] - The example is simplified and non-semantic, exploring various functionalities offered by the XCO APIs. See the repository's disclaimer. - For more information and code snippets, refer to the SAP Help documentation. - The example assumes you have a transportable package, represented by the
|
| Class | Details/Code Snippet |
CL_HTMLTIDY |
The following example explores some of the capabilities of the
To try the example out, create a demo class named |
IF_AIA_ACTION and classes (which are not detailed out here, and some of which are used by the demo examples) are usable in the context of IDE actions.[!NOTE] - Find more information on IDE actions and examples: - in the SAP documentation. - in this Devtoberfest session. - Your user must be assigned to the SAP_A4C_BC_DEV_AIA_PC business catalog.
[!IMPORTANT] - The examples are simplified and only intended for exploration, experimentation, and demonstration, to get a high-level idea. They do not represent best practices or role model approaches for IDE action implementation. - The examples useCL_DEMO_OUTPUT_CLOUDto retrieve HTML output of data objects. Note that this class is intended for demo purposes only. The examples use the class's HTML capabilities for display. When you execute the example IDE actions, they present data objects in HTML within the IDE action result dialog. You may recognize this HTML presentation from theCL_DEMO_OUTPUTclass that is available in Standard ABAP and used for demo display purposes, especially useful for displaying internal table content. - The use of IDE actions is your responsibility. Development and use are up to you. Refer to this repository's disclaimer and the disclaimer in the IDE action documentation. - Be particularly mindful of the potential security risks when importing external content, which the simplified example code below does not address. The example code also uses dynamic programming techniques. They can pose a security risk. Refer to the Dynamic Programming cheat sheet and the ABAP Keyword Documentation.
The (non-AI-related) experiments include these IDE actions for demo purposes:
| IDE Action | Notes |
|---|---|
|
File uploader and downloader |
|
|
Class runner and data object displayer |
|
|
Method runner and parameter displayer |
|
|
XLSX file importer and content displayer |
|
The class setup is similar across all examples:
ZCL_DEMO_ABAP)Expand the following collapsible sections for descriptions and example code:
🟢 1) File uploader and downloader
Demo Purpose
This demo IDE action lets you upload and process files, as well as download them. It showcases the upload and processing of JSON and XLSX files, along with download and display options for XML, JSON, TXT, and HTML content.
Setup Steps
ZCL_DEMO_ABAP_IDE_IMP_EXP_IMPLZCL_DEMO_ABAP_IDE_IMP_EXP_UICLAS (choose Add and filter for CLAS)ZCL_DEMO_ABAP_IDE_IMP_EXP_UI class also requires code in the CCIMP include/Local Types tab in ADT. ZIF_DEMO_ABAP_IDE_IMP_EXP and use the code below. Implementing ZIF_DEMO_ABAP_IDE_IMP_EXP is essential for checking out the IDE action. process_import and export, which include custom logic to process content for upload and download. For example, the example demonstrates uploading an XLSX file. The process_import method implementation in the ZCL_DEMO_ABAP class is specifically tailored for this example, allowing XLSX content to be uploaded and processed using the XLSX XCO API. The export method is designed to provide content for download based on the selected operation in the IDE action dialog. zcl_demo_abap. If it already exists, reuse it. Otherwise, create a new class with a different name. Paste the code into it. If you choose a different class name, update the class name in the code snippet accordingly. ZDEMO_ABAP_CARR database table by reusing the code from the repository (see below). You can run this class using F9 in ADT to initialize the demo database table and add entries for testing. Refer to the comments in the class code, as you need to comment out a section of the code beforehand. @EndUserText.label : 'Demo table: Airline'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zdemo_abap_carr {
key mandt : abap.clnt not null;
key carrid : abap.char(3) not null;
carrname : abap.char(20) not null;
currcode : abap.cuky not null;
url : abap.char(255) not null;
}zif_demo_abap_ide_imp_exp~process_import method of the ZCL_DEMO_ABAP class: carriers.json, and insert the following content: [
{
"MANDT": "000",
"CARRID": "ZZ",
"CARRNAME": "ZZ Airlines",
"CURRCODE": "USD",
"URL": "some_url_zz_airlines"
},
{
"MANDT": "000",
"CARRID": "YY",
"CARRNAME": "YY Airways",
"CURRCODE": "EUR",
"URL": "some_url_yy_airways"
},
{
"MANDT": "000",
"CARRID": "XX",
"CARRNAME": "Air XX",
"CURRCODE": "JPY",
"URL": "some_url_air_xx"
}
]carriers.xlsx, and insert the following content: | 100 | AB | AB Airlines | EUR | some_url_ab_airlines |
| 100 | CD | CD Airways | USD | some_url_cd_airways |
| 100 | EF | Air EF | JPY | some_url_air_ef |
Demo Execution Steps
ZCL_DEMO_ABAP (or browse). The demo expects a class to be specified that implements the ZIF_DEMO_ABAP_IDE_IMP_EXP interface.carriers.json) as described above. zif_demo_abap_ide_imp_exp~process_import method of the ZCL_DEMO_ABAP class. Also, comment out the code for XLSX content processing.message parameter.carriers.xlsx) as described above. zif_demo_abap_ide_imp_exp~process_import method of the ZCL_DEMO_ABAP class. Also, comment out the code for JSON content processing.zif_demo_abap_ide_imp_exp~export method of the ZCL_DEMO_ABAP class is called. Depending on the selection, demo code is executed. This is realized by an enumerated type, defined in the interface. An importing parameter is typed with this enumerated type. Its value determines what code is executed, realized by a CASE statement.SELECT statement. Using a CALL TRANSFORMATION statement, the internal table content is transformed (to asXML) and returned.SELECT statement. Using the /UI2/CL_JSON class, the internal table content is converted to JSON and returned.SELECT statement. Using the CL_DEMO_OUTPUT_CLOUD class, the internal table content is converted to HTML and returned.*.xml. | Class (include)/Interface | Code |
|---|---|
|
|
|
|
|
|
|
|
|
|
Interface to check out the IDE action |
|
|
Class to check out the IDE action |
|
🟢 2) Class runner and data object displayer
Demo Purpose
This demo IDE action runs classes and displays the content of data objects in an IF_OO_ADT_CLASSRUN-like style. Instead of plain text in the ADT console, it presents the results as HTML in an IDE action result dialog in ADT.
Steps
ZCL_DEMO_ABAP_ACTION_OUTPUTZCL_DEMO_ABAP_ACTION_OUTPUT_UICLAS (choose Add and filter for CLAS)ZIF_DEMO_ABAP_OUTPUT and use the code from below. ZIF_DEMO_ABAP_OUTPUT is essential to be implemented for checking out the IDE action. zcl_demo_abap. The code contains a collection of various data objects that should be displayed. ZCL_DEMO_ABAP (or any class implementing the interface).ZCL_DEMO_ABAP (or browse, or you have run the action in a class filling the input field automatically).out->write( ... ). and other methods that the CL_DEMO_OUTPUT_CLOUD class offers..| Class (include)/Interface | Code |
|---|---|
|
|
|
|
|
|
|
|
|
|
Interface to check out the IDE action |
|
|
Class to check out the IDE action |
|
🟢 3) Method runner and parameter displayer
Demo Purpose
CL_DEMO_OUTPUT_CLOUD, including any of the input and output parameters and their values (if any).Steps
ZCL_DEMO_ABAP_ACTION_METHODRUNZCL_DEMO_ABAP_ACTION_M_RUN_UICLASZCL_DEMO_ABAP to check out the IDE action.ZCL_DEMO_ABAP (or any class implementing the interface).| Class (include) | Code |
|---|---|
|
|
|
|
|
|
|
|
|
|
Class to check out the IDE action |
|
🟢 4) XLSX file importer and content displayer
Demo Purpose
CL_DEMO_OUTPUT_CLOUD in the IDE action result dialog. Steps
ZCL_DEMO_ABAP_ACTION_IMPORTZCL_DEMO_ABAP_ACTION_IMPORT_UICLAS (choose Add and filter for CLAS)ZCL_DEMO_ABAP to check out the IDE action for this example.[!WARNING] Since the example IDE action lets you import a local file, be mindful of the potential security risks when importing external content. Refer to this repository's disclaimer and to the disclaimer in the documentation about XCO.
| Subject/Class | Notes/Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example XLSX content and demo execution steps |
First Example
Second Example
Third Example
|
| Classes | Details/Code Snippet |
CL_FP_ADS_UTILCL_RSPO_PDF_MERGER |
These classes are used in the context of output management. In this context, multiple classes and methods are available. The example code snippet illustrates these:
Find more information here.
Notes on the example:
|
| Class | Details/Code Snippet |
CL_CSV_FACTORY |
|
CL_ABAP_GARBAGE_COLLECTOR class provides the collect method. cl_abap_garbage_collector=>collect( ).CL_MESSAGE_HELPER class offers several helper methods for handling messages. 🟢 Click to expand for example code
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
DATA error TYPE REF TO cx_root.
*&---------------------------------------------------------------------*
*& get_latest_t100_exception
*& Gets the most recent T100 exception from an exception object chain
*&---------------------------------------------------------------------*
out->write( |\n---------- get_latest_t100_exception method ----------\n\n| ).
DO 5 TIMES.
TRY.
RAISE EXCEPTION TYPE zcx_demo_abap_error_a
EXPORTING
textid = zcx_demo_abap_error_a=>error_003
p_003_a = `Error no.`
p_003_b = CONV #( sy-index )
previous = error.
CATCH zcx_demo_abap_error_a INTO error.
ENDTRY.
ENDDO.
DATA(t100_exc) = cl_message_helper=>get_latest_t100_exception( error ).
IF t100_exc IS BOUND.
DATA(t100key) = t100_exc->t100key.
out->write( t100key ).
IF t100_exc->t100key <> if_t100_message=>default_textid.
DATA(error_text) = t100_exc->if_message~get_text( ).
out->write( error_text ).
ENDIF.
ELSE.
out->write( `not bound` ).
ENDIF.
out->write( |\n{ repeat( val = `-` occ = 50 ) }\n| ).
DATA prev TYPE REF TO cx_root.
prev = error->previous.
WHILE prev IS NOT INITIAL.
t100_exc = cl_message_helper=>get_latest_t100_exception( prev ).
IF t100_exc IS BOUND.
error_text = t100_exc->if_message~get_text( ).
t100key = t100_exc->t100key.
out->write( error_text ).
out->write( t100key ).
ELSE.
out->write( `not bound` ).
ENDIF.
out->write( |\n{ repeat( val = `-` occ = 15 ) }\n| ).
prev = prev->previous.
ENDWHILE.
out->write( |\n{ repeat( val = `*` occ = 80 ) }\n| ).
*&---------------------------------------------------------------------*
*& set_msg_vars_for_if_msg
*& Sets sy-msg* variables based on reference of type IF_MESSAGE
*&---------------------------------------------------------------------*
out->write( |\n---------- set_msg_vars_for_if_msg method ----------\n\n| ).
"Sets MESSAGE Variables,
"Extracts message variables from objects implementing the IF_MESSAGE interface and sets them into system variables (&1, &2, etc.)
TRY.
RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE e005(zdemo_abap_messages) WITH 'Lorem' 'ipsum' 'dolor' 'sit'.
CATCH zcx_demo_abap_error_b INTO error.
DATA(msgid) = sy-msgid.
DATA(msgno) = sy-msgno.
DATA(msgv1) = sy-msgv1.
DATA(msgv2) = sy-msgv2.
DATA(msgv3) = sy-msgv3.
DATA(msgv4) = sy-msgv4.
DATA sytab TYPE string_table.
sytab = VALUE #( ( |sy-msgid: "{ msgid }"| ) ( |sy-msgno: "{ msgno }"| ) ( |sy-msgv1: "{ msgv1 }"| )
( |sy-msgv2: "{ msgv2 }"| ) ( |sy-msgv3: "{ msgv3 }"| ) ( |sy-msgv4: "{ msgv4 }"| ) ).
out->write( |\n--- sy-msg* variables before ---\n\n| ).
out->write( sytab ).
out->write( |\n{ repeat( val = `-` occ = 15 ) }\n| ).
cl_message_helper=>set_msg_vars_for_if_msg( error ).
msgid = sy-msgid.
msgno = sy-msgno.
msgv1 = sy-msgv1.
msgv2 = sy-msgv2.
msgv3 = sy-msgv3.
msgv4 = sy-msgv4.
sytab = VALUE #( ( |sy-msgid: "{ msgid }"| ) ( |sy-msgno: "{ msgno }"| ) ( |sy-msgv1: "{ msgv1 }"| )
( |sy-msgv2: "{ msgv2 }"| ) ( |sy-msgv3: "{ msgv3 }"| ) ( |sy-msgv4: "{ msgv4 }"| ) ).
out->write( |\n--- sy-msg* variables after ---\n\n| ).
out->write( sytab ).
out->write( |\n{ repeat( val = `-` occ = 15 ) }\n| ).
MESSAGE ID msgid
TYPE 'E'
NUMBER msgno
WITH msgv1 msgv2 msgv3 msgv4
INTO DATA(msg).
out->write( msg ).
ENDTRY.
out->write( |\n{ repeat( val = `*` occ = 80 ) }\n| ).
*&---------------------------------------------------------------------*
*& set_msg_vars_for_clike
*& Sets sy-msg* variables based on text
*&---------------------------------------------------------------------*
out->write( |\n---------- set_msg_vars_for_clike method ----------\n\n| ).
DATA(some_message) = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, ` &&
`sed eiusmod tempor incidunt ut labore et dolore magna aliqua. This is some long example text ` &&
`that is split into sy-msg* fields.`.
cl_message_helper=>set_msg_vars_for_clike( some_message ).
msgid = sy-msgid.
msgno = sy-msgno.
msgv1 = sy-msgv1.
msgv2 = sy-msgv2.
msgv3 = sy-msgv3.
msgv4 = sy-msgv4.
sytab = VALUE #( ( |sy-msgv1: "{ msgv1 }"| )
( |sy-msgv2: "{ msgv2 }"| ) ( |sy-msgv3: "{ msgv3 }"| ) ( |sy-msgv4: "{ msgv4 }"| ) ).
out->write( sytab ).
out->write( |\n{ repeat( val = `-` occ = 15 ) }\n| ).
MESSAGE ID 'ZDEMO_ABAP_MESSAGES'
TYPE 'E'
NUMBER '005'
WITH msgv1 msgv2 msgv3 msgv4
INTO msg.
out->write( msg ).
out->write( |\n{ repeat( val = `*` occ = 80 ) }\n| ).
*&---------------------------------------------------------------------*
*& get_text_for_message
*& Returns short text for parameters
*&---------------------------------------------------------------------*
out->write( |\n---------- get_text_for_message method ----------\n\n| ).
TRY.
RAISE EXCEPTION TYPE zcx_demo_abap_error_b MESSAGE e005(zdemo_abap_messages) WITH 'This' 'is' 'some' 'text'.
CATCH zcx_demo_abap_error_b INTO error.
cl_message_helper=>get_text_for_message(
EXPORTING
text = error
RECEIVING
result = DATA(res)
).
out->write( res ).
ENDTRY.
ENDMETHOD.
ENDCLASS.CL_CONVERSION_EXT_INT class provides several methods to convert from ISO to SAP internal format and vice versa. 🟢 Click to expand for example code
CLASS zcl_demo_abap DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_demo_abap IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
*&---------------------------------------------------------------------*
*& Currency code conversion
*&---------------------------------------------------------------------*
TRY.
DATA(curr_code_conv) = cl_conversion_ext_int=>get_instance( ).
"Conversion of ISO currency code into SAP internal currency key
curr_code_conv->currency_code_ext_to_int(
EXPORTING
iso_code = 'EUR'
IMPORTING
sap_code = DATA(sap_code)
is_unique = DATA(unique)
).
out->write( |SAP code: { sap_code }| ).
out->write( |Is unique: "{ unique }"| ).
out->write( |\n| ).
"Conversion of SAP internal currency key into ISO currency code
curr_code_conv->currency_code_int_to_ext(
EXPORTING
sap_code = 'EUR'
IMPORTING
iso_code = DATA(curr_code_iso)
).
out->write( |ISO code: { curr_code_iso }| ).
CATCH cx_conversion_ext_int INTO DATA(error_curr_code_conv).
out->write( error_curr_code_conv->get_text( ) ).
ENDTRY.
out->write( |\n| ).
out->write( repeat( val = `*` occ = 80 ) ).
out->write( |\n| ).
*&---------------------------------------------------------------------*
*& Currency amount conversion
*&---------------------------------------------------------------------*
TRY.
DATA(curr_amount_conv) = cl_conversion_ext_int=>get_instance( ).
"Conversion of ISO currency amount into the SAP internal currency amount
curr_amount_conv->currency_amount_ext_to_int(
EXPORTING
currency = 'JPY'
bapi_amount = CONV #( '15' )
IMPORTING
sap_amount = DATA(sap_curr_amount)
).
out->write( |SAP currency amount: { sap_curr_amount } | ).
out->write( |\n| ).
"Conversion of SAP internal currency amount into ISO currency amount
curr_amount_conv->currency_amount_int_to_ext(
EXPORTING
currency = 'JPY'
sap_amount = CONV #( '0.1500' )
IMPORTING
bapi_amount = DATA(iso_curr_amount)
).
out->write( |ISO currency amount: { iso_curr_amount } | ).
CATCH cx_conversion_ext_int INTO DATA(error_curr_amount_conv).
out->write( error_curr_amount_conv->get_text( ) ).
ENDTRY.
out->write( |\n| ).
out->write( repeat( val = `*` occ = 80 ) ).
out->write( |\n| ).
*&---------------------------------------------------------------------*
*& Language code conversion
*&---------------------------------------------------------------------*
TRY.
DATA(lang_code_conv) = cl_conversion_ext_int=>get_instance( ).
"Conversion of ISO language code into the SAP internal format
lang_code_conv->language_code_ext_to_int(
EXPORTING
iso_code = 'EN'
IMPORTING
sap_code = DATA(sap_lang_code)
).
out->write( |SAP language code: { sap_lang_code } | ).
out->write( |\n| ).
"Conversion of SAP internal format into ISO language code
lang_code_conv->language_code_int_to_ext(
EXPORTING
sap_code = 'E'
IMPORTING
iso_code = DATA(iso_lang_code)
).
out->write( |ISO language code: { iso_lang_code } | ).
CATCH cx_conversion_ext_int INTO DATA(error_lang_code_conv).
out->write( error_lang_code_conv->get_text( ) ).
ENDTRY.
out->write( |\n| ).
out->write( repeat( val = `*` occ = 80 ) ).
out->write( |\n| ).
*&---------------------------------------------------------------------*
*& Conversion of units of measurement
*&---------------------------------------------------------------------*
TRY.
DATA(uom_conv) = cl_conversion_ext_int=>get_instance( ).
"Conversion of ISO code for the unit of measurement into the SAP internal format
uom_conv->unit_of_measure_ext_to_int(
EXPORTING
iso_code = 'MTR'
IMPORTING
sap_code = DATA(sap_uom_code)
).
out->write( |SAP UoM code: { sap_uom_code } | ).
out->write( |\n| ).
"Conversion of the SAP internal format into the ISO code for the unit of measurement
uom_conv->unit_of_measure_int_to_ext(
EXPORTING
sap_code = 'KM'
IMPORTING
iso_code = DATA(iso_uom_code)
).
out->write( |ISO UoM code: { iso_uom_code } | ).
CATCH cx_conversion_ext_int INTO DATA(error_uom_conv).
out->write( error_uom_conv->get_text( ) ).
ENDTRY.
ENDMETHOD.
ENDCLASS.22_Released_ABAP_Classes.md。版权归原作者所有。