Thursday, October 31, 2013

Convert ALV to Excel and send it by email

One of the most requested abilities for an report is the possibility to run it as a job and send the output to a given user. However, the spool output of most ALV reports is unusable as is. To solve this problem, I'll show a simple class that takes an internal table, a fieldcatalog and a user email to create a xml excel file from the field catalog with the contents of the internal table and forward it to the email supplied.
I should warn that the excel output isn't something fancy. It's just a simple table. The class can be greatly enhanced.

1 - Create a class:



2 - Create the class atributes:





3 - Create the class methods:

4 - Create the method parameters:










5 - Insert the appropriate code in each method:


Friday, October 25, 2013

Talking ABAP

Just for fun, you can make sap talk to the user or, for more serious work, you can give hearing aids to alert the users for some event or to help them be more aware of what is happening.


As a final thought, I should say that, this is a simple example. As most of the times, you have plenty of room to improve.
Don't forget that this is an instanciation of a windows object. It will only work with SAP Gui for windows.

Remark: depending on the security settings of your SAP GUI configuration, a popup can appear asking for authorization to instanciate a windows object.

Thursday, October 24, 2013

Batch Input with Objects

Some times, we get such a requirement that forces us to use batch input for creation/changing of some SAP object/document. Usually, the resulting code isn't that elegant. In this post, I'll show how to use a ABAP Class to process call transaction and allow to future improvements that afects every program that uses it, without the need to change those same programs.
Those improvements could be:
  • Create Batch input in DB for latter processing
  • Create Enhanced Logs
  • Start Workflows
  • Etc

1 - Create an ABAP Class in transaction SE24, select an apropriate package:

















2 - Create the following attributes:

3 - Create these methods:









4 - Pick the relevant code for the each method:


5 - Save and activate the class.

6 - To help generate the code, the following program can be used:



The input for this program is the SHDB record and the program variable name.

7 - Example:
  • SHDB Record:


8 - Program Input

9 - Generated Code:


Final remarks:
As you can see, the code is more understable and simplier to use.
The SHDB record name, must be unique, since it is selected by name.
With the generated code, you must add the coding for variable selection and remove unecessary inputs. The program only creates code for the relevant batch input lines.