Posts

Abap predefined function line_index

As part of the ABAP  predefined functions  series, today I wanted to talk about the predefined function  LINE_INDEX . As the name suggests, the function returns the row index of an internal table found using table expressions. Syntax:   result =  line_index ( table_expression). Features : - If the row in question is not found, no exception is raised. The value 0 is returned instead. - Supports table expression chaining as long as the result of the expression is also table-like in     the case of nested tables. - Effectively, a functional replacement of READ TABLE statement followed by sy-tabix check. Notes :  - If a hashed table is specified then the result would be -1.  - If a hash key is specified then the result would be -1.   Example : you might think that it's not that impressive as it's not that hard or frequent to know an index of the row in internal tables till you have to know the index of a deeply nested table. below is an example illu

Abap Predefined function nmax and nmin

As part of the ABAP predefined functions series, today I wanted to talk about numerical Extremum functions: NMIN, and NMAX. These functions return the minimum/maximum values out of the input argument. Syntax: result = nmax|nmin ( val1 = arg1 val2 = arg2....val5 = arg5 ..val9 = arg9 ). Features: - All the input arguments are of type numeric data object/ numeric expressions. - A minimum of two arguments must be passed up to 9. Example: It's elementary to start undermining the function as an extreme of two can be easily calculated with a simple if-else: but what if 3, or 4 or more fields were involved: You can notice how the ifs are increasing but it's a simple method call to NMAX or NMIN to achieve the same. Below is a small ready-to-execute report to calculate the least or highest value of input values of up to 9 variables, As always, I hope this information helps you with your day-to-day work.

ABAP capture result of submitted program using cl_salv_bs_runtime_info

Image
Let's talk about a hypothetical scenario, You are meditating in your fortress of solitude. A wild customer appears virtually/physically.The person shows you a report output and wants you to fetch exact data as the report displays in your current development. Scared , you begin to analyse the code of the report to reuse its logic only to see your fear come out alive i.e. the report has all the logic embedded. Proudly , you suggest refactoring the report, extracting the logic globally, and using it for your objects. Swiftly , your hope helicopter is shot down by the customer's stinger missile of an increase in testing efforts and with support troops of "nearing the deadline" hand a lack of super users to confirm the original report works as intended post refactor. Now, If the above scenario is not so much hypothetical in your experience, you are left with some limited choices. 1. Copy the logic ( Hello dark side) 2. Somehow get

File data conversion made easy using ABAP custom utility class zcl_filedata_convert

In the last post, I talked about how to read XLSX files into an internal table and  convert internal to XLSX files . In this post, I wanted to share a custom utility class that can make tasks of data conversion as simple as a method call. The class is ZCL_FILEDATA_CONVERT. Below are a few of the code snippets showing its capabilities. Let's start with XLSX to the internal table. It automatically handles date and time fields for you. Internal table to XLSX similarly converting data from and to CSV or TSV or special separated file, It handles it all. Here is a link to source : ZCL_FILE_DATA_CONVERT Use it as it is or modify it to suit your needs. As always, hope you like the post and use its information in your day to day work.

SAP application component browser custom tool, Check application component hierarchy of any object

Image
As part of the  custom tools  series, today's post is about a tool that is helpful to both functional and technical counterparts. Have you ever wondered, which table or t-code belonged to which application component in SAP? Recently, I did and thought maybe others want to see that as well. But first, What is an application component? An application component is defined as a modular, deployable, and replaceable part of a software system that encapsulates its behaviour, data and exposes these through a set of interfaces.  In other words, In SAP, all sales and development related functions would be part of the SD application component, similar to other functions such as MM or LO (logistics). Now, coming back to the tool. Here is what the input looks like: You can input the application component name or an object name.  The other input defines what type of objects you want to browse or fetch. Example: I want to know where the MARA table be

ABAP read excel(.XLSX) file to internal table in ABAP using CL_FDT_XL_SPREADSHEET

You are given a requirement to upload data to a custom DB table where the user provides you with the file path of the excel on his PC and the report loads the data from it to the Custom table. For experienced Abapers, the requirement is quite straightforward, except that the user wants to upload an XLSX file. There are not many options to read data from XLSX/XLS file. The TEXT_CONVERT_XLS_TO_SAP  function module is one of them but is a performance killer and uses OLE. In this post, I wanted to showcase How we can read data from the XLSX files using CL_FDT_SPOREADSHEET class. Let's start with uploading the file. Now that we have the file in xstring table, let's pass it to CL_FDT_XL_SPREADSHEET to get its object reference. From the object reference, we can retrieve each worksheet data. The data is returned in the form of an anonymous data object which can be dereferenced into a field symbol and passed to the target internal table. Below is the cod

Easily send emails from ABAP using Custom utility class ZCL_SEND_MAIL

in the previous post,s I shared how to use CL_BCS class to send emails . and I also shared how to use cl_bcs_message class to send email in user-exit and BADI . The standard libraries even though useful, are cumbersome to use so I have created a utility that combines the power of both CL_BCS and CL_BCS_MESSAGE to let you send an email with ease from anywhere in the system. Below are examples and source links to the utility class ZCL_SEND_MAIL A simple example: Sending email from user exit/Badi Link to Source:  ZCL_SEND_MAIL As usual, Hope you like the post and use the information in your day to day work.

ABAP convert internal table to excel (.xlsx) format and Send email or download

Reporting is incomplete without file interfacing. Sometimes the requirement is to send a file via email or download it to a PC. but what to do when the user requests the file in XLSX format? In today's post, I am sharing how to convert an internal table to .xlsx format and then send it to a PC or email. One of the quickest ways I found it been done is using SALV classes. Below is the Code snippet Now once you have the xstring with you, simply pass it to relevant libraries to handle the output. Downloading to PC: Sending via Email It's that simple. Hope you like the post and use it in your day to day work.

Send mail with out using commit work with cl_bcs_message class

 In my last post  Send mail using CL_BCS library  We explored the class to achieve mail sending functionalities. The class is a really powerful tool but it has a shortcoming i.e. it needs to commit work . It's not a problem most of the time unless you are working with User-Exit and BADI. In this post, I wanted to showcase the usage of CL_BCS_MESSAGE class. The class only collects data and depending upon how you set the attributes of the class object, function module SBCS_SEND or SBCS_SEND_UPDATE is called. This means we can use this class to send emails from User-exit or BADI. Below is a sample code. Hope You like the snippet and use this information in your day to day work.

Use CL_BCS library to send email with ABAP

Many a time you need a report for which the output needs to be an email. SO_NEW_DOCUMENT_SEND_API1 is heavily used to achieve the task but let's explore another way of achieving the same using CL_BCS. This post talks about how to use the CL_BCS library provided by SAP to easily send emails. CL_BCS Library The class serves as the interface from BCS to the applications. The methods of the class cater for the send functions. Using CL_BCS, You can: – Attach files to email – Build the HTML/raw of the body. – Set email’s Senders & Receiver – Send an email, etc. Let's see the steps one by one: Initiating CL_BCS: The first thing you need is to initiate a persistent send request. Creating BCS Document: Create the BCS document object which will be sent with the CL_BCS interface to BCS. In this case the Email. SET_DOCUMENT Once we have the document, It needs to be set to the send request. SET_SENDER Assign the sender to the send request. ADD_RECIPIENT Pass