Saturday, 30 December 2023

Using memoization to optimize pure functions in ABAP

I recently needed to drastically improve performance of a recursive method, and memoization was there to save the day. I’d like to demonstrate the technique, in case you’re not familiar with it, using the recursive Fibonacci sequence as a base.

FAQ:

Q: Was the Fibonacci calculation what I needed to improve performance for?

A: No, but the recursive Fibonacci calculation is a great and simple example that lends very well to memoization demonstration.

Q: Aren’t there better performing ways to calculate the Fibonacci sequence than the recursive method?

A: Well, there are other, but I need somthing “slow” to demonstrate the memoization I have included two other options in the end, for good measure…

Friday, 29 December 2023

How to get stock on posting date: manually and programmatically

Sometimes for planning purposes we need to get logistics stocks by plant/storage location/material for the specific date. In the blog I will describe some ways to solve the problem depending on version of SAP NetWeaver.

Manual approach via tcode MB5B


Transaction MB5B could help us to read stocks. Tcode could be find via menu path Logistics -> Materials Management -> Inventory Management -> Environment -> Stock -> MB5B – Stock for Posting Date. As we could see from the screenshot below there are also some others useful transactions in the menu path.

Wednesday, 27 December 2023

Abap SQL Common Table Expression (CTE)

I this short blog post, I would like share a few useful CTE examples.

Sometimes we require complex sql queries and at that point we have a few options.

  • CDS
  • AMDP
  • CTE

By considering, DRY principle, if we will use it in multiple places, we may prefer to create cds or amdp depending on requirement. But if our requirement is to use it once, than we can use CTE.

Friday, 22 December 2023

How to create a custom field with Custom Field and Logic App and transporting field in SAP S/4HANA

In this blog, I will show you how to create custom fields via the “Custom Field and Logic” app in Fiori and transporting fields in SAP S/4HANA.

First, let’s start with Custom fields.

We can do the following using Custom Field and Logic app.

  • Create your own fields(Choose field type and description)
  • Make your fields available in UIs,reports,email templates, form templates,business scenarios and other languages.
  • Delete fields.
  • Edit fields that have already been published
  • Publish fields to your system.

Wednesday, 20 December 2023

Hierarchies: How to Assign a Hierarchy to a Dimension and How to Consume a Hierarchy in an Analytical Query

CDS offers the possibility to structure hierarchical data. For instance, if you have employee data and would like to organize this data based on their manager, you can structure the data hierarchically. You are then able to query data of employees under each manager (sales, for instance). The general structure of a CDS hierarchy is depicted below:

Monday, 18 December 2023

Using class CL_ABAP_PARALLEL for mass parallel dialog work processes

Using class CL_ABAP_PARALLEL is a convenient way to mass process in parallel dialog work processes. This can be especially powerful in a system with more dialog vs other types of work processes. Due to limited documentation, there was a small learning curve when I first implemented this in an S4/HANA on-premise system on SAP_BASIS version 7.54. I’m writing this blog to help others with their implementation of this class.

Setup overview


In this example there will be two local classes (to make it an easy copy/paste test). The XSTRING data type is used to universally pass different kinds of data between the two classes.

Saturday, 16 December 2023

Release News 2308: Enumerations in ABAP CDS

This blog post explains the new ABAP CDS enumerations.

Release info

  • 2308 SAP BTP ABAP Environment
  • ABAP Release 7.58
  • SAP S/4HANA 2023

Creating a CDS enumerated type


In ADT, an enumerated type is created as a repository object of the type Type. 

Friday, 15 December 2023

SLT – Replication with Additional Fields and Changing Operation Type

I am sure many of you who use SLT (SAP Landscape Transformation) would have encountered a need to add additional fields to their table structure or to modify existing field types. This could be for various reasons. To process certain data, to add additional parameters for the destination system, support data, etc. This is quite common and can be easily achieved using Table and Rule settings on LTRS transaction. One specific need we had was two fold. First, every record replicated should have its timestamp (of replication) and a flag that indicates what operation was performed (Insert, Update or Delete). Some of you I am sure would have probably worked and solved this same scenario or something similar.

Wednesday, 13 December 2023

Effortless Material Creation using Excel Sheets via Fiori App (e.g., SolidWorks’ CAD-Driven Data)

Introduction


Material creation in SAP is simpler using Fiori and Excel, we can tweak data before uploading, even integrating info from CAD software like SolidWorks or any other data source. This connection makes creating new materials in SAP a smoother process. Let’s dive into how this system works seamlessly.

Summary


In this blog, we’re diving into a streamlined material creation process within SAP. We’ll explore the creation of a Fiori app and an OData service designed to seamlessly integrate data from external sources for material creation. For this blog, we will be using data comes from SolidWorks automation.

Saturday, 9 December 2023

How to display photo of employees from PA30 to module pool custom container

In this blog post you will learn how to make a basic Module Pool program using custom container to display image of employee from PA30.

Module pool programming is a special type of programming which is used to create custom SAP screens.

We will first upload the image for the employee on the SAP Server using the transaction OAAD. The name of the image we upload is APPLE and is in black and white (the supported formats are .jpg and .png).

Wednesday, 6 December 2023

Tips about fetching attachment list from Service Notification

If the requirement is to send the PDF files fetched from the attachment list of service notifications once the service order reaches to specific status, how to get those linked document files based on the service order number will be the key. That is the purpose of this article.

Tips about fetching attachment list from Service Notification

Tuesday, 5 December 2023

Alternative option for IMPORT/ EXPORT using Shared Memory SHMA approach.

Motivation:-


In this blog you will learn how to use shared memory as alternative option of ABAP Memory(Import/Export).

Business Scenario:- Many of times we need Import & Export at the time of SAP Enhancement or other requirements so Here use of shared memory which is also alternate option of Import/ Export and as per SAP standard guideline this approach is highly recommended.

Monday, 4 December 2023

Fiori Element: Display Rating Indicator’s & Images

We had the requirement to display the rating indicator to determine the Employee’s ratings based on their performance, skills and their availability. Here I am trying to display rating indicator by using product details, also displaying the Images of respected product by forming the URL Via OData.

Let’s begin with example.

Here RAP Model also involved to preview the Application but the agenda is that we have to display the ratings for each product

Saturday, 2 December 2023

Functional Programming in ABAP Series: PART I (Introduction)

Background

In computer coding, it’s super important to write really good code. Good code doesn’t just make programs run faster, it also helps developers work better. But figuring out what makes code good can be tricky, and it’s not just about making things run quickly.

Good code has things like being easy to test, easy to keep up, easy to use again, and easy to add more stuff to. These things are like measuring sticks for how tough and reliable the code is. But knowing how to make code like that isn’t always clear, so we look into ways to help us write clean code.

Wednesday, 22 November 2023

Tips about Error EA299 ‘Could not write IDoc to file’ for RFFOEDI1

There is one standard IDOC type DIRDEB with Basic type PEXR2003 used to generate EDI payment documents. It worked fine all the time until last week when one user complained one file was missing in the desired AL11 directory even with multiple re-runs.

Tips about Error EA299 ‘Could not write IDoc to file’ for RFFOEDI1

Monday, 20 November 2023

Service Due Indicator for Managers

Background:


In Many Tables there might be a need to provide a quick high-level view of the Pending status of every record for a quick view by Managers.

For example, a Service Team Manager might want to see the list of Service Orders whose Service Due date is in the past (or) Service Due date which is today (or) Service Due date which is in future.

In these scenarios, we can provide an Indicator in the first column so that the Manager will be able to see the status immediately.

Friday, 17 November 2023

Consuming REST API with Basic Authentication- Step-by-Step Guide for the GET Method

In this blog post, I will show you how to consume an API step by step. The API contains various methods, with the most commonly used ones being “Get,” “Post,” and “Delete.”

For the sake of example, in this blog, I will use the “Get” method.

“GET” Method: The “GET” method is used to retrieve information from a web API or query resources (data). This method is used to request data from a specific resource and is typically called with parameters through a URL (web address). A “GET” request typically does not modify data, it only reads it.

Thursday, 9 November 2023

RAP EML Dynamic Operations: Dynamic EML Requests

Introduction


In the world of ABAP development, the RAP framework has revolutionized the way we build robust and flexible applications. One of the key features of RAP is the ability to dynamically generate EML (Entity Manipulation Language) requests. In this blog post, we will explore the dynamic form of MODIFY ENTITIES OPERATIONS, which allows us to perform operations on multiple business objects within a single statement.

Monday, 6 November 2023

Customer Aging and Supplier Aging Reports at the Line Item Level using Analytical Query in S/4HANA Cloud, Public Edition

Introduction


Functional consultant or a business key user can effortlessly generate supplier and customer aging reports using the Custom Analytical Queries App for the scenarios outlined below.

Scenario – Accounts Payable Aging:

Your client requires a supplier aging report that displays the aging at different levels: Supplier level, Reconciliation G/L level, Supplier Region level, and Profit Center level. Additionally, they would like the option to access the aging information at the accounting document level in the same report.

Saturday, 4 November 2023

How to add two or more fields in a range table with FOR Expression

Requirement: To form a range table consuming two or more fields from a table in ABAP.

Old or Traditional way of Coding:

*Define the structures of table
TYPES:
  BEGIN OF lty_comp,
    seqno  TYPE char4,
    wtype1 TYPE char4,
    wtype2 TYPE char4,
    wtype3 TYPE char4,

Friday, 3 November 2023

Traceability Text in VF03 T-code & also on reports FBL5N & FBL3N

Introduction


Requirement: To enhance the functionality of text which is maintained during sales order creation ( VA01 ) under item level. When we pass the sales order ID in ( VF01 ) Billing document is generated. Please check the below screen shot.

SAP ABAP Career, SAP ABAP Guides, SAP ABAP Prep, SAP ABAP Tutorial and Materials, SAP ABAP Prep, SAP ABAP Preparation

Wednesday, 1 November 2023

Create new CO-PA Margin Analysis characteristic with existing table as code list

Introduction


In S/4HANA OP2022 there are several ways to create customer specific characteristics for Margin Analysis. While using transaction KEA5 might seem like the most intuitive and classic way to create new characteristics it will make it very hard to use those with any Fiori applications.

The “new” Fiori enabled way to create characteristics would be by using the Fiori app F1481 “Custom Fields” with the “Market Segment” business context.

Monday, 30 October 2023

How to trigger workflow for MRP Purchase Requisitions

As per standard SAP process, workflow doesn’t trigger for purchase requisitions created through MRP process.

Reason:


Usually, there is a possibility that the PR’s created through MRP can get deleted again by materials planning and due to this, there will be inconsistencies created between PR’s created through MRP and work items.

Wednesday, 25 October 2023

ABAP Console Reloaded

You know the ABAP console of ADT that allows to use out->write in the main method of classes that implement interface if_oo_adt_classrun in order to write the content of ABAP data objects to a text console.

You might also know the interface if_demo_output implemented by class cl_demo_output that also offers a method write that does mostly the same.

What you might don’t know is the fact that the implementations of the ABAP console in ADT and of cl_demo_output are two sides of the same coin. When the ABAP console was introduced some years ago, its internal implementation was copied from cl_demo_output and cl_demo_output_stream (the latter produces an output-friendly XML). But since ADT used an early stage of cl_demo_output, it missed its continuous improvements that took place in the meantime. An example is the implicit retrieval of the data object’s name if no name is passed explicitly.

Monday, 23 October 2023

Comparison of Report Development in 3SL & 2SL in SAP S/4HANA Cloud, Public Edition – A customer use case study

Last year, SAP officially launched the 3SL in S/4HANA Cloud, public edition. This three-system setup offers scalability in ABAP development in ADT, allowing developers to create projects on SAP S/4HANA Cloud, and leverage the benefits of custom ABAP code for development extensions. From an analytical perspective, what are the advantages of report development under the three-system Landscape compared to the two-system Landscape only has key user extensibility? What limitations of the two-system embedded analytics can be overcome? This blog post will explore the differences in report development under these two using a customer use case.

Friday, 20 October 2023

S/4HANA Multi Level BOM Unboxed: Navigating BOM Hierarchy: A Recursive Adventure – Part1

Introduction


Greetings, fellow SAP enthusiasts! Today, we’re diving into the intricate world of Bill of Materials (BOM) and tackling a challenging yet fascinating user requirement. Our mission? To develop a Report that navigates through the recursive nature of BOM data, providing users with a comprehensive view of the hierarchy.

The Challenge


The provided scenario outlines a case requirement wherein the described approach can be employed whenever recursion is necessary, contingent upon external specifications.

Our user wants to start with a material and a specific field, the serial number, from the STPO table. The goal is to traverse through the BOM data, then explore related tables (STKO, EQST, EQUI) to finally present a detailed hierarchy of BOM and its related Composite Equipment’s info like materials and serial numbers.

Wednesday, 18 October 2023

Writing ABAP UNIT using test double framework(DOC)

Let’s begin with an example.Below method has one function module dependency and one method external method dependency.The Class having this method is CUT(Code Under Test).The aim of the ABAP unit is to validate the code residing in this method,not to validate the code of the dependent function module / other method.

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification

Friday, 13 October 2023

SAP ABAP RAP: Custom Entities with compositions relationship in a Fiori Elements App

Introduction:


ABAP Restful Application Programming is an efficient and cloud-compatible development model that enables rapid creation of Fiori apps.

This programming model facilitates both Managed and Unmanaged Implementation approaches, although the core data source must originate from a CDS view or a table within the same system in both scenarios. However, the non-key fields can be calculated on the fly using virtual elements.

When retrieving data from a remote source through an API or performing complex calculations, managing CDS view entities becomes challenging. Further complexities arise when compositions  are involved.

Wednesday, 11 October 2023

Do not try this at home – performance improvement in the LIME engine

Disclaimer – this post is about changes in the customer namespace, which maybe belong in the standard and it is not a good idea to develop them in a customer project.

But, as we know, necessity is the mother of invention…

Recently within a customer project the customer was experiencing performance issues with the standard /scwm/pi_upload transaction.

The load of a .CSV file would end in a short dump, saying that the current work process was out of memory. And the system limit per WP was around 8G.

The file itself was not big, but even reducing it to a small number of lines, around 20-30, would not help solve the issue.

Saturday, 7 October 2023

FSCM Workflow – Credit Limit Approval Alternative

SAP ABAP Career, SAP ABAP Skills, SAP ABAP Prep, SAP ABAP Preparation, SAP ABAP Certification, SAP ABAP Tutorial and Materials

Sometimes SAP standard does not meet all requirements and that’s where the “Custom Code” comes in…

Friday, 6 October 2023

MDG-S: MDG rule-based workflow

Introduction:


This blog post will describe in detail how to trigger email using using Rule Base Workflow(WS60800086)

Requirement:


  • Bank data in vendor master data when changed (Account no., IBAN, A/C holder name, etc), or deleted, an email notification to be triggered to the vendor
  • Email available in the general section of vendor (LFA1) to be used to send the notification.
  • Email to be triggered to the SPU owners.

Friday, 29 September 2023

Upload transport files from SAP

Introduction


This blog is useful consultants/Admins/functional folks who can’t not have access to operating system to transfer cofiles and data files

This blog describes detailed steps “How to upload and download cofiles/data files directly from SAP” pretty useful. You don’t need to have access to OS.

How to Do: Download and upload Co-files/Data files (Transports) directly from SAP

Monday, 25 September 2023

Fiori PO Approver app Forward button customization from ECC backend

The first part of customization comes on the Forward Button. As per the approval matrix the approvers were maintained in the PPOME structure. The problem occurred when the approver was forwarding the PO to another approver. However, on clicking the Forward button it was displaying all the list of Users from SU01. This was creating a lot of confusion for the approvers. So the initial requirement came as to fix the list that was appearing on clicking the Forward Button.

I will be displaying the 2 possible approach for Forward Button customization from the Backend.

Saturday, 23 September 2023

Managing Updates to abapGit in Shared Development Systems

If you are using abapGit as a tool to facilitate your development processes you at some point have to decide on an update strategy for abapGit itself. Most likely you are only updating abapGit when a feature or bug fix is released that you need or file diffs are displayed that are related to format changes that you want to get rid off. (Or you feel guilty not having updated for a while…) This is a bit of a shame as new features are added all the time and keeping abapGit up-to-date from a technical perspective is extremely easy. There are no notes to implement, no support packages to import, no migrations to do and no dependencies to worry about. Issues rather arise because of processes and communication between teams regarding ongoing developments when you are sharing systems.

Friday, 22 September 2023

How to Navigate Within ABAP CDS Source Code and Between ABAP CDS Objects?

In this blog, I will describe how to …

◉ navigate within ABAP CDS source code,
◉ come to another  CDS/Dictionary object
◉ navigate within the ABAP CDS object you currently work on

… using ABAP development tools for Eclipse (ADT) a.k.a. ABAP in Eclipse.

Note: When I talk about objects, I mean CDS objects such as data definitions and/or relating ABAP Dictionary objects such as database tables, classic views and so on.

Wednesday, 20 September 2023

New Debugger options

Introduction


The New Debugger is a tool that helps technical consultants execute the program line by line or module by module. It stops the program to check the logic, identify errors, analyze the issue, understand the concept, etc. It has many more options compared to the old debugger. We will see some of the uncommon features that are helpful to the developers and functional consultants in their analysis.

If you want to analyze the program’s data flow, then you need to debug the program. To enable or start the debugger, enter “/h” or “/H” in the command area of SAP.

Monday, 11 September 2023

Delta loading in SAP Datasphere based on the ABAP CDS view

In applications where there is a high volume of data creation, changes, and deletion happens, such as sales orders, it is crucial for the application to have a mechanism that provides delta records and for the extractor that needs to provide delta loading. This means that the application should be able to identify and extract only the new, modified or deleted data, ensuring efficient and accurate data loading.

In some of the cases nightly full uploads are not what we exactly want, as time windows for data extractions are limited. Solution for that is coming with ODP framework.

Friday, 8 September 2023

Radio Buttons In SAP Build Apps

Introduction:

SAP Build is an extensive development suite that offers simple and efficient low-code/no-code solutions for developing software, automating tasks, and building business websites. The suite is made up of three essential tools: SAP Build Apps, SAP Build Process Automation, and SAP Build Work Zone.

SAP Build Apps allows users to create applications with ease, from simple to complex, using its low-code architecture. This means that extensive coding knowledge or experience is not required.

Saturday, 2 September 2023

ALV IDA Using CDS View Long Text using (Calculation Field)

Mostly people facing problem to how to use long text using function module, Call class in CDS while creating ALV IDA from CDS View. In this blog I will share my knowledge of ALV IDA Using CDS View and ALV IDA Calculation field (Mostly is used for virial element). Using Calculation Field in this blog I am going to display Long Text and Other Field

In this blog I will focus on below points.

1. Create CDS View (Generic) with 2 or 3 fields.
2. Create class with interface calculation field.
3. Long Text working in method
4. Creation of ALV IDA Program

Thursday, 31 August 2023

Designing Custom Tree Screen Using Report Program

REPORT ysk_modulepool_tree.

INCLUDE ymodulepool_tree_top.  “data declaration
INCLUDE ymodulepool_tree_cl1.  “class declaration
INCLUDE ymodulepool_tree_o01.  “PBO Modules
INCLUDE ymodulepool_tree_i01.  “PAI Modules
INCLUDE ymodulepool_tree_f01.  “Form Routines

START-OF-SELECTION.

CREATE OBJECT g_application.
SET SCREEN 100.

1. Draw one screen name as 100 and create a custom control name as YCONTROL.

SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Guides, SAP ABAP Learning

2. In the same screen create one more custom control and name as ZPP_CONTOL.

SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Guides, SAP ABAP Learning

*&———————————————————————*
*& Include          YMODULEPOOL_TREE_TOP
*&———————————————————————*

class lcl_application DEFINITION DEFERRED.

class cl_gui_cfw DEFINITION load.

DATA: g_application TYPE REF TO lcl_application,
g_custom_container TYPE REF TO cl_gui_custom_container,
g_tree TYPE REF TO cl_simple_tree_model,
g_ok_code TYPE sy-ucomm.

* Fields on Dynpro 500
DATA: g_event(30),
g_node_key(30) TYPE c.
*——————————————————–
******Data Declarations For Insert Image on Screen.***********
CONSTANTS: cntl_true  TYPE i VALUE 1,
cntl_false TYPE i VALUE 0.
DATA:
h_picture       TYPE REF TO cl_gui_picture,
h_pic_container TYPE REF TO cl_gui_custom_container.
DATA: graphic_size TYPE i.

DATA: BEGIN OF graphic_table OCCURS 0,
line(255) TYPE x,
END OF graphic_table.
DATA: graphic_url(255),
graphic_refresh(1),
g_result    LIKE cntl_true.


*&———————————————————————*
*& Include          YMODULEPOOL_TREE_CL1
*&———————————————————————*

CLASS lcl_application DEFINITION.

PUBLIC SECTION.
METHODS:
handle_node_double_click
FOR EVENT node_double_click
OF cl_simple_tree_model
IMPORTING node_key.
ENDCLASS.                    “lcl_application DEFINITION

CLASS lcl_application IMPLEMENTATION.

METHOD handle_node_double_click.
g_event = ‘NODE_DOUBLE_CLICK’.
g_node_key = node_key.

IF g_node_key EQ ‘Vendor Sampling'(001).
CALL TRANSACTION ‘ZQM_VNSMPL’.
ELSEIF g_node_key EQ ‘Trim Audit'(003).
CALL TRANSACTION ‘ZQM_TRIM’.
ELSEIF g_node_key EQ ‘Out Source'(004).
CALL TRANSACTION ‘ZQM_OUTSOURCE’.“
ELSEIF g_node_key EQ ‘Final Goods'(005).
CALL TRANSACTION ‘ZQM_FG_FINAL’..
ELSEIF g_node_key EQ ‘Inspection’.
CALL TRANSACTION ‘ZQM_FINISHGOODS’.“
ELSEIF g_node_key EQ ‘Fout Source’.
CALL TRANSACTION ‘ZFOUTSOURCE’.
ELSEIF g_node_key EQ ‘Finish goods’.
CALL TRANSACTION ‘ZQM_FINISHGOODS’.
ELSEIF g_node_key EQ ‘FVNSMPL’.
CALL TRANSACTION ‘ZFVNSMPL’.“‘
ELSEIF g_node_key EQ ‘VNSMPL’.
CALL TRANSACTION ‘ZVNSMPL’.
ELSEIF g_node_key EQ ‘TRIMAUDIT’.
CALL TRANSACTION ‘ZTRIMAUDIT’.
ELSEIF g_node_key EQ ‘FINAL INS’.
CALL TRANSACTION ‘ZQM_FINAL_INS’.
ELSEIF g_node_key EQ ‘ZQM_TRIM’.
CALL TRANSACTION   ‘ZQM_TRIM’.
ELSEIF g_node_key EQ ‘ZTRIMAUDIT’.
CALL TRANSACTION ‘ZTRIMAUDIT’.
ELSEIF g_node_key EQ ‘ZQM_OUTSOURCE’.
CALL TRANSACTION ‘ZQM_FINISHED’.
ELSEIF g_node_key EQ ‘ZQM_INSPECTION’.
CALL TRANSACTION ‘ZQM_FINISHGOODS’.
ELSEIF g_node_key EQ ‘ZFOUTSOURCE’.
CALL TRANSACTION ‘ZQM_FINAL_INS’.
ELSEIF g_node_key EQ ‘ZQM_FG_FINAL’.
CALL TRANSACTION ‘ZQM_FG_FINAL’.
ELSEIF g_node_key EQ ‘ZQM_FINISHGOODS’.
CALL TRANSACTION ‘ZQM_INSPECTION’.
ELSEIF g_node_key EQ ‘ZQM_FINAL_INS’.
CALL TRANSACTION ‘ZFOUTSOURCE’.
ELSEIF g_node_key EQ ‘ZQM_TRIMADOBE’.
CALL TRANSACTION ‘ZQM_TRIMADOBE’.
ENDIF.
ENDMETHOD.                    “handle_node_double_click
ENDCLASS.                    “lcl_application IMPLEMENTATION

*&———————————————————————*
*& Include          YMODULEPOOL_TREE_O01
*&———————————————————————*
*&———————————————————————*
*& Module STATUS_0100 OUTPUT
*&———————————————————————*
*&
*&———————————————————————*
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘YTREE’.
SET TITLEBAR ‘YTREET’.
IF g_tree IS INITIAL.
PERFORM create_and_init_tree. “calling subroutine
ENDIF.

* ———————————-THIS LOGIC FOR WALLPAPER IMAGE —————
DATA: l_graphic_xstr TYPE xstring,
l_graphic_conv TYPE i,
l_graphic_offs TYPE i.

CALL METHOD cl_ssf_xsf_utilities=>get_bds_graphic_as_bmp
EXPORTING
p_object  = ‘GRAPHICS’
p_name    = ‘MCFL’ “IMAGE NAME – Image name from SE78
p_id      = ‘BMAP’
p_btype   = ‘BCOL’  “(BMON = black&white, BCOL = colour)
RECEIVING
p_bmp     = l_graphic_xstr
EXCEPTIONS
not_found = 1
OTHERS    = 2.

graphic_size = XSTRLEN( l_graphic_xstr ).
CHECK graphic_size > 0.

l_graphic_conv = graphic_size.
l_graphic_offs = 0.

WHILE l_graphic_conv > 255.
graphic_table-line = l_graphic_xstr+l_graphic_offs(255).
APPEND graphic_table.
l_graphic_offs = l_graphic_offs + 255.
l_graphic_conv = l_graphic_conv – 255.
ENDWHILE.

graphic_table-line = l_graphic_xstr+l_graphic_offs(l_graphic_conv).
APPEND graphic_table.

CALL FUNCTION ‘DP_CREATE_URL’
EXPORTING
type                 = ‘image’                    “#EC NOTEXT
subtype              = cndp_sap_tab_unknown ” ‘X-UNKNOWN’
size                 = graphic_size

lifetime             = cndp_lifetime_transaction  “‘T’
TABLES
data                 = graphic_table
CHANGING
url                  = graphic_url
EXCEPTIONS
dp_invalid_parameter = 1
dp_error_put_table   = 2
dp_error_general     = 3
OTHERS               = 4 .
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.

CREATE OBJECT h_pic_container
EXPORTING container_name =  ‘ZPP_CONTROL’.
CREATE OBJECT h_picture EXPORTING parent = h_pic_container.

CALL METHOD h_picture->load_picture_from_url
EXPORTING
url    = graphic_url
IMPORTING
RESULT = g_result.

————————————-END CODE OF IMAGE —————————-
ENDMODULE.


*&———————————————————————*
*& Include          YMODULEPOOL_TREE_I01
*&———————————————————————*
*&———————————————————————*
*&      Module  USER_COMMAND_0100  INPUT
*&———————————————————————*
*       text
*———————————————————————-*
MODULE user_command_0100 INPUT.
DATA: return_code TYPE i.
* CL_GUI_CFW=>DISPATCH must be called if events are registered
* that trigger PAI
* this method calls the event handler method of an event
CALL METHOD cl_gui_cfw=>dispatch
IMPORTING return_code = return_code.
IF return_code <> cl_gui_cfw=>rc_noevent.
” a control event occured => exit PAI
*    CLEAR g_ok_code.
EXIT.
ENDIF.

CASE SY-UCOMM.   “g_ok_code.
WHEN ‘BACK’.                       ” Finish program
IF NOT g_custom_container IS INITIAL.

“Destroy tree container (destroys contained tree control, too)
CALL METHOD g_custom_container->free
EXCEPTIONS
cntl_system_error = 1
cntl_error        = 2.
IF sy-subrc <> 0.
**          MESSAGE a000.
ENDIF.
CLEAR g_custom_container.
CLEAR g_tree.
ENDIF.
LEAVE PROGRAM.
WHEN ‘EXIT’.
LEAVE TO SCREEN 0.
WHEN ‘CANCEL’.
LEAVE TO SCREEN 0.
ENDCASE.
* CAUTION: Clear ok code!
CLEAR g_ok_code.
ENDMODULE.

*&———————————————————————*
*& Include          YMODULEPOOL_TREE_F01
*&———————————————————————*
*&———————————————————————*
*& Form create_and_init_tree
*&———————————————————————*
*& text
*&———————————————————————*
*& –>  p1        text
*& <–  p2        text
*&———————————————————————*
FORM create_and_init_tree .” defined form logic
DATA: event  TYPE cntl_simple_event,
events TYPE cntl_simple_events.

* Create a simple tree model instance
CREATE OBJECT g_tree
EXPORTING
node_selection_mode         = cl_simple_tree_model=>node_sel_mode_single
EXCEPTIONS
illegal_node_selection_mode = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* Create a container for the tree control
CREATE OBJECT g_custom_container
EXPORTING      ” The container is linked to the custom control with the
” name ‘TREE_CONTAINER’ on the Dynpro
container_name              = ‘YCONTROL’ “custom container name

EXCEPTIONS
cntl_error                        = 1
cntl_system_error           = 2
create_error                   = 3
lifetime_error                 = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* create the view (control) of the tree model

CALL METHOD g_tree->create_tree_control
EXPORTING
parent                       = g_custom_container
EXCEPTIONS
lifetime_error               = 1
cntl_system_error            = 2
create_error                 = 3
failed                       = 4
tree_control_already_created = 5.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* define the events which will be passed to the backend
” node double click
event-eventid = cl_simple_tree_model=>eventid_node_double_click.
event-appl_event = ‘X’.              ” process PAI if event occurs
APPEND event TO events.

CALL METHOD g_tree->set_registered_events
EXPORTING
events                    = events
EXCEPTIONS
illegal_event_combination = 1
unknown_event             = 2.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* assign event handlers in the application class to each desired event
SET HANDLER g_application->handle_node_double_click FOR g_tree.

* add nodes to the tree model
PERFORM add_nodes.

* expand the root node
CALL METHOD g_tree->expand_node
EXPORTING
node_key       = ‘PP’                                 “#EC NOTEXT
EXCEPTIONS

node_not_found = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.
ENDFORM.
*&———————————————————————*
*& Form add_nodes
*&———————————————————————*
*& text
*&———————————————————————*
*& –>  p1        text
*& <–  p2        text
*&———————————————————————*
FORM add_nodes .
* Node with key ‘Root’
CALL METHOD g_tree->add_node
EXPORTING
node_key = ‘PP’                                       “#EC NOTEXT
isfolder = ‘X’
text     = ‘Quality Management’                       “#EC NOTEXT
EXCEPTIONS
OTHERS   = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

*————————— Vendor Sampling ————————*
CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘Vendor Sampling1’                             “#EC NOTEXT
relative_node_key = ‘PP’
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘X’
text              = ‘Vendor Sampling’
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

* Node with key Vendor Sampling
CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘Vendor Sampling’
relative_node_key = ‘Vendor Sampling1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Create Vendor Sampling Inspection’

“#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘FVNSMPL’
relative_node_key = ‘Vendor Sampling1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Print Form’           “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘VNSMPL’
relative_node_key = ‘Vendor Sampling1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Report’           “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

*&———->Trim Audit Inspection
CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_TRIM1’                             “#EC NOTEXT
relative_node_key = ‘PP’
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘X’
text              = ‘Trim Audit Inspection’
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.

ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_TRIM’
relative_node_key = ‘ZQM_TRIM1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Create Trim Audit Inspection’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZTRIMAUDIT’
relative_node_key = ‘ZQM_TRIM1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Report’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_TRIMADOBE’
relative_node_key = ‘ZQM_TRIM1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Print Form’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

*&————->  Outsource Goods Inspection
CALL METHOD g_tree->add_node
EXPORTING

node_key          = ‘ZQM_OUTSOURCE1’                             “#EC NOTEXT
relative_node_key = ‘PP’
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘X’
text              = ‘Outsource Goods Inspection’
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_OUTSOURCE’
relative_node_key = ‘ZQM_OUTSOURCE1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Create Outsource Goods Inspection’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_INSPECTION’
relative_node_key = ‘ZQM_OUTSOURCE1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Report’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZFOUTSOURCE’
relative_node_key = ‘ZQM_OUTSOURCE1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Print Form’

C NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

*&————->Finished Goods Inspection
CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_FG_FINAL1’                             “#EC NOTEXT
relative_node_key = ‘PP’
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘X’
text              = ‘Finished Goods Inspection
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_FG_FINAL’
relative_node_key = ‘ZQM_FG_FINAL1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Create Finished Goods Inspection’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_FINISHGOODS’
relative_node_key = ‘ZQM_FG_FINAL1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Report’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.

CALL METHOD g_tree->add_node
EXPORTING
node_key          = ‘ZQM_FINAL_INS’
relative_node_key = ‘ZQM_FG_FINAL1’                             “#EC NOTEXT
relationship      = cl_simple_tree_model=>relat_last_child
isfolder          = ‘ ‘
image             = ‘@0Y@’
text              = ‘Print Form’            “#EC NOTEXT
EXCEPTIONS
OTHERS            = 1.
IF sy-subrc <> 0.
**    MESSAGE a001.
ENDIF.
ENDFORM.

Output:


SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Jobs, SAP ABAP Guides, SAP ABAP Learning

Monday, 28 August 2023

Tutorial. How to create custom PIVB ALV report based on a CDS with parameters

This post is about a simple tutorial how to create own ALV PIVB report based on data from own custom CDS with input parameters.

What is PIVB reports?


PIVB reports allows you to generate reports (totals or items report) and add analytics (i.e. columns) to the report on the fly. While adding columns – system recalculates the data in the report, i.e. the number of rows may changes. In simple words, it works in the same way as the PivotTable mechanism in MS Excel. For example, you can see standard SAP reports such as FAGLL03H, FBL1H, etc.

These reports can be identified by the presence of a sidebar on the right (it can be moved to the left), and the new layout mechanism for working with reports, which allows you to generate a set of columns on the fly (ad-hoc).

An example of a report (FAGLL03h):

SAP ABAP Certification, SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Job, SAP ABAP Learning

How to create own PIVB report


Here’s a simple step-by-step guide how to create a PIVB report

CDS with data

You need a table or CDS with data for the report. In the example below, I will use Z CDS (based on ACDOCA) with input parameters (fiscal year and start date):

SAP ABAP Certification, SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Job, SAP ABAP Learning

Create a custom report

Create a custom program for the report (for example, you can use the RFPIVB_EX_SFLIGHT_01 report as a reference). In the program, specify selection screen:

REPORT zfi_glrep_items_pivb.
TABLES: zvfi_acdoc_i.

SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE TEXT-001.
  SELECT-OPTIONS: so_rldnr FOR zvfi_acdoc_i-rldnr NO INTERVALS DEFAULT '0L',
                  so_bukrs FOR zvfi_acdoc_i-rbukrs MEMORY ID buk,
                  so_gjahr FOR zvfi_acdoc_i-gjahr OBLIGATORY no-EXTENSION NO INTERVALS DEFAULT sy-datum+0(4),
                  so_budat FOR zvfi_acdoc_i-budat OBLIGATORY NO-EXTENSION,
                  so_racct FOR zvfi_acdoc_i-racct,
                  so_KTOKS FOR zvfi_acdoc_i-ktoks,
                  so_LOKKT FOR zvfi_acdoc_i-lokkt,
                  so_koart FOR zvfi_acdoc_i-koart.
SELECTION-SCREEN END OF BLOCK bl1.

SELECTION-SCREEN BEGIN OF BLOCK bl2 WITH FRAME TITLE TEXT-002.
  PARAMETERS: p_sb AS CHECKBOX.
  PARAMETERS: p_disvar TYPE  slis_vari MODIF ID p_d.
SELECTION-SCREEN END OF BLOCK bl2.

Add processing of the layouts (field P_DISVAR) search help:

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_disvar.
* service FM PIVB_F4
  CALL FUNCTION 'PIVB_F4'
    EXPORTING
      i_report_catalog  = con_catalog
      i_report_scenario = con_scenario
    IMPORTING
      e_layout          = p_disvar
      e_result_status   = g_result_status
      e_layout_name     = g_layout_name
    CHANGING
      ct_field          = gt_column
    EXCEPTIONS
      error_message     = 4.
  IF sy-subrc = 4.
    "Do nothing, same error will be also raised during execution
    "(and is not possible raise messages in F4 Help event)
  ENDIF.

* update screen with description of the selected layout
  IF g_result_status = if_pivb_c_f4=>result_field.
    MESSAGE i014(pivb) INTO g_txt.
    g_layout_name = g_txt.
    MESSAGE i013(pivb) INTO g_txt.
    PERFORM update_screen.
  ELSEIF g_result_status = if_pivb_c_f4=>result_layout.
    MESSAGE i012(pivb) INTO g_txt.
    PERFORM update_screen.
  ENDIF.


FORM update_screen.
  DATA:
    ls_dynpfield TYPE dynpread,
    lt_dynpfield TYPE TABLE OF dynpread.

  CLEAR: lt_dynpfield[], ls_dynpfield.

  ls_dynpfield-fieldname = 'P_DISVAR'.
  ls_dynpfield-fieldvalue = p_disvar.
  APPEND ls_dynpfield TO lt_dynpfield.

  CALL FUNCTION 'DYNP_VALUES_UPDATE'
    EXPORTING
      dyname     = sy-repid
      dynumb     = sy-dynnr
    TABLES
      dynpfields = lt_dynpfield.
ENDFORM.

PIVB ALV layouts search help, with ad-hoc functionality, looks like:

SAP ABAP Certification, SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Job, SAP ABAP Learning

SAP ABAP Certification, SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Job, SAP ABAP Learning

And at the main part of the report – add a transfer data from the selection screen to the PIVB functionality (via FM PIVB_CONV_RANGE_TO_SELTAB)

* convert the entered values into standard PIVB format
  PERFORM convert_to_seltab USING 'RBUKRS' so_bukrs[]  CHANGING gt_seltab.
  PERFORM convert_to_seltab USING 'RLDNR' so_rldnr[]  CHANGING gt_seltab.
  PERFORM convert_to_seltab USING 'BUDAT' so_budat[]  CHANGING gt_seltab.
  PERFORM convert_to_seltab USING 'RACCT' so_racct[]  CHANGING gt_seltab.
  PERFORM convert_to_seltab USING 'KTOKS' so_KTOKS[]  CHANGING gt_seltab.
  PERFORM convert_to_seltab USING 'LOKKT' so_LOKKT[]  CHANGING gt_seltab.
  PERFORM convert_to_seltab USING 'KOART' so_koart[]  CHANGING gt_seltab.

FORM convert_to_seltab USING
                         us_fname   TYPE rsdstabs-prim_fname
                         fs_table   TYPE ANY TABLE
                       CHANGING
                         ct_seltab  TYPE rsds_frange_t.
  CALL FUNCTION 'PIVB_CONV_RANGE_TO_SELTAB'
    EXPORTING
      i_fname   = us_fname
      it_table  = fs_table
    CHANGING
      ct_seltab = ct_seltab.
ENDFORM.

Let’s declare constants with the name of the report, they will need to be registered in the PIVB customizing tables and in the BAdI PIVB implementation, it will be further at post

CONSTANTS con_catalog         TYPE pivb_report_catalog  VALUE 'ZVFI_ACDOC_I'.
CONSTANTS con_scenario        TYPE pivb_report_scenario VALUE 'ZVFI'.

And call the main FM PIVB_CONV_RANGE_TO_SELTAB to retrieve data and show the PIVB ALV report

* call the main PIVB FM with all necessary parameters
  CALL FUNCTION 'PIVB_SELECT_AND_DISPLAY'
    EXPORTING
      i_report_catalog     = con_catalog
      i_report_scenario    = con_scenario
      it_seltab            = gt_seltab
      i_layout             = p_disvar
      it_column_visibility = gt_column
      it_param             = lt_par.

Thats it with the report. But, also, customizing and PIVB BAdI implementation needed.

Customizing

There are 4 main customizing tables:

◉ PIVB_CATALOG Report catalogs
◉ PIVB_FEATURE Pivot Browser features
◉ PIVB_FIELD Fieldcatalog data
◉ PIVB_FIELDMAP Field Mapping

For a simple example, it is enough to define our report only in PIVB_CATALOG (via SM30):

SAP ABAP Certification, SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Job, SAP ABAP Learning

Implement PIVB BAdI


Next, let’s create an implementation of the PIVB enhancement point (se18/19), there is a standard template of implementation – SAP_SFLIGHT_01. Let’s create own implementation and specify the values from PIVB_CATALOG customizing into the BAdI implementation filter:

SAP ABAP Certification, SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Job, SAP ABAP Learning

For a simple report, it’s only need to implement the IF_EX_PIVB~SELECT method in which I override the data selection mechanism for example, it will be like this:

method if_ex_pivb~select.
  data lt_trange                  type rsds_trange.
  data lt_trange_and              type pivb_trange_t.
  data lt_select                  type standard table of string.
  data lt_group_by                type standard table of string.
  data lt_group_by_checked        type standard table of string.
  data lt_field_mapping           type pivb_fieldmap_short_t.
  data l_column                   type string.
  data l_tabname                  type tabname.
  data oref                       type ref to cx_root.
  data lt_where                   type rsds_where_tab.
  field-symbols <fs_item>         type any.
  constants lc_tabname            type tabname  value 'ZVFI_ACDOC_I'.
  constants lc_devclass           type devclass value 'ZFI_DEV'. "package of the table

  me->get_security_metadata( i_report_catalog = i_report_catalog ).

  call function 'PIVB_SQL_GET_CLAUSE'
    exporting
      i_report_catalog            = i_report_catalog
      i_report_scenario           = i_report_scenario
      it_seltab                   = it_seltab
      it_and_seltab               = it_and_seltab
      it_column                   = it_column
      it_column_metadata          = it_column_metadata
      i_tabname                   = lc_tabname
      it_table_sec                = me->mt_secure_whitelist
      ut_fieldmap                 = lt_field_mapping
      I_STRICT_MODE               = 'X'
    importing
      et_select                   = lt_select
      et_group_by                 = lt_group_by
      et_trange                   = lt_trange[]
      et_trange_and               = lt_trange_and[].

  LOOP AT lt_select ASSIGNING FIELD-SYMBOL(<sel>).
    CHECK <sel>+0(4) = 'SUM('.
    REPLACE '(' in <sel> WITH `( `.
    REPLACE ')' in <sel> WITH ' )'.
  ENDLOOP.

**********************************************************************
  call function 'PIVB_CONV_RANGE_TO_WHERE'
    exporting
      it_trange           = lt_trange[]
      it_trange_and       = lt_trange_and[]
    importing
      et_where            = lt_where[].

* GROUP BY
  loop at lt_group_by into l_column.
    append l_column to lt_group_by_checked.
  endloop.
  free lt_group_by.

* DO SELECT
***********************************************************************
  DATA: st_date TYPE dats,
        fy TYPE gjahr.
  LOOP AT CT_PARAM ASSIGNING FIELD-SYMBOL(<fs_p>).
    CASE <fs_p>-PARAMNAME.
      WHEN 'ST_DATE'.
        st_date = <fs_p>-CUSTOM.
      WHEN 'FY'.
        fy = <fs_p>-CUSTOM.
      WHEN OTHERS.
    ENDCASE.
  ENDLOOP.
  try.
    select (lt_select)
      from ZVFI_ACDOC_ITEMS( st_date = @st_date,
                             fy = @fy )
      where (lt_where)
      group by (lt_group_by_checked)
      into corresponding fields of TABLE @ct_outtab.
  catch cx_sy_open_sql_db into oref.
    data: l_txt type string.
    l_txt = oref->get_text( ) ##MG_MISSING.
    message e017(pivb) with lc_tabname l_txt space space raising sql_error.
  endtry ##MG_MISSING.
endmethod.

Please note that to use the new query syntax, you need to set the parameter I_STRICT_MODE = ‘X’ and slightly adjust the functionality for filling the internal table lt_select (add spaces to the dynamic parameters of the query).

In the IF_EX_PIVB~GRID_METADATA_CHANGE method, you can change the ALV display parameters (fieldcatalog), for example, set own column header texts, colors, display options, as follows:

SAP ABAP Certification, SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Job, SAP ABAP Learning

Activate the implementation of the enhancement, activate report etc. Everything done!

How it works


Adding columns to PIVB report:

SAP ABAP Certification, SAP ABAP Certification, SAP ABAP Career, SAP ABAP Skills, SAP ABAP Job, SAP ABAP Learning