37
SAP ABAP Advanced Cookbook
Advanced Business Application Programming (ABAP) is SAP’s proprietary 4th
Generation Language (4GL). SAP core is written almost entirely in ABAP. ABAP
is a high level programming language used in SAP for development and other
customization processes. This book covers advanced SAP programming applications
with ABAP. It teaches you to enhance SAP applications by developing custom reports
and interfaces with ABAP programming. This cookbook has quick and advanced real
world recipes for programming ABAP.
It begins with the applications of ABAP objects and ALV tips and tricks. It then
covers design patterns and dynamic programming in detail. You will also learn the
usage of quality improvement tools such as transaction SAT, SQL Trace, and the code
inspector. Simple transformations and its application in Excel downloading will also
be discussed, as well as the newest topics surrounding Adobe Interactive Forms and
the consumption and creation of Web services. The book comes to an end by covering
advanced usage of Web Dynpro for ABAP and the latest advancement in
Floorplan Manager.
What This Book Covers
Chapter 1, ABAP Objects, introduces useful recipes related to the object-oriented
programming. This will include useful design patterns, the shared memory, and the
persistent object concept.
Chapter 2, Dynamic Programming, covers facets of dynamic programming as applied
in ABAP, such as Dynamic Open SQL and usage of field symbols and references.
Chapter 3, ALV Tricks, shows how you can get the most out of ALV programs.
Starting with a simple ALV program, we will add code in recipes to fulfill a variety
of user requirements.
Chapter 4, Regular Expressions, guides you on how you can embed regex programming
in your ABAP programs and solve complicated problems in the least possible time and
with minimal code.
Chapter 5, Optimizing Programs, shows the newer feature of secondary indexes and the
transaction SAT (runtime analyzer) along with valuable program optimization tips.
Chapter 6, Doing More with Selection Screens, discusses recipes based on less frequently
applied functionality within ABAP programs’ selection screens, such as the addition of
tabstrips and placement of buttons on toolbar. In addition, we will see how to take folder
and file names as input, followed by a recipe for writing code in search help exits.
For More Information:
www.packtpub.com/sap-advanced-business-application-programming-
cookbook/book
29
Chapter 7, Smart Forms – Tips and Tricks, introduces various recipes based on Smart
forms and fulfilling user’s form printing requirements in the least possible time.
Chapter 8, Working with SQL Trace, provides lesser-known tricks related to the SQL
Trace tool. This will include the performance optimization usage of the SQL trace tool
as well as the use of finding data source of screen fields.
Chapter 9, Code Inspector, shows how to check the quality of custom programs using
standard checks, along with the procedure for creating your own checks.
Chapter 10, Simple Transformations, discusses in detail the Simple Transformation
language and the representation of data variables in it, the application for Excel download
format will also be shown.
Chapter 11, Sending E-mail Using BCS Classes, covers the classes of the Business
Communication Service (BCS) for e-mail generation. This chapter will cover everything
from simple e-mails for SAP users to Internet e-mail addresses, and also the procedure
for adding attachments of various formats.
Chapter 12, Creating and Consuming Web Services, covers the step-by-step procedure
for the creation of Web services based on an ABAP function module using the Inside-Out
approach. The steps required to create a consumer of the Web service will also be shown.
Chapter 13, SAP Interactive Forms by Adobe, shows how to create both print and
interactive forms using the SAP Interactive forms technology. A number of scenarios
such as Offline form processing will also be covered.
Chapter 14, Web Dynpro for ABAP, shows how to create simple and advanced Web
Dynpro for ABAP (WD4A) applications. The advanced topics related to the Web Dynpro
components will also be covered.
Chapter 15, Floorplan Manager, covers newer features of the Floorplan Manager design
used for creating Web Dynpro applications quickly. Both the configuration and coding
for useful Floorplans will also be covered.
For More Information:
www.packtpub.com/sap-advanced-business-application-programming-
cookbook/book
VB.NET PDF: Basic SDK Concept of XDoc.PDF You may add PDF document protection functionality into your VB.NET program. to edit hyperlink of PDF document, including editing PDF url links and quick
add link to pdf; adding a link to a pdf in preview
30
11
Sending E-mail Using
BCS Classes
In this chapter, we will see recipes of e-mail programming using the Business communication
services (BCS). We will look at:
Creating a simple e-mail message
Sending e-mail to Internet e-mail addresses
Adding attachments to your message
Creating HTML e-mail
Running a program and sending its output as an e-mail
Introduction
This chapter explores useful recipes related to the programming of e-mail sending. We will
start with a brief overview of BCS and the various classes available. Then we will see a simple
recipe that will generate an e-mail to an SAP user in his or her inbox. Then, we will show how
the same program may be changed in order to send the e-mail to Internet e-mail addresses.
We will then add attachments such as an Excel (XML fi le) to the e-mail. Creating HTML
documents will also be discussed. Finally, we will create a program that will execute another
ABAP program, convert its output into PDF, and attach the PDF to an e-mail message.
We will see the most important and commonly used classes (and their methods) used
for e-mail creation. In addition to e-mail programming classes such as CL_BCS and
CL_BCS_DOCUMENT, we will also see classes such as CL_CONVERT_BCS that are used
for converting fi les into appropriate formats suitable for attaching to e-mail documents.
For More Information:
www.packtpub.com/sap-advanced-business-application-programming-
cookbook/book
41
Sending E-mail Using BCS Classes
188
Throughout the chapter, the terms e-mail and SAP Offi ce Document will be used
interchangeably.
The BCS classes provide a newer object-oriented means of generating e-mails
programmatically. The function modules should no longer be used for sending
e-mails. The BCS classes are much simpler to program, particularly when we have
attachments involved.
The classes relevant to e-mail programming are discussed as follows:
Class name
Use
CL_BCS
This class is for creating sent requests. The document (e-mail
body and attachments) is assigned to it and recipients are
specified. Finally, the request is sent.
CL_DOCUMENT_BCS
This is the document class for specifying the content of the
e-mail and attachments (if any).
CL_CAM_ADDRESS_BCS
This class provides a number of useful methods. The notable
one uses an Internet e-mail address such as abc@yahoo.
com and returns a recipient user object.
CL_SAPUSER_BCS
This class creates a recipient object based on an SAP user ID
to be used.
CL_BCS_CONVERT
This class converts data from one format to another, such as
conversion of text string to binary table or from a hexadecimal
string to a binary table, and so on.
Creating a simple e-mail message
In this recipe, we will see how we can create a simple program that will send an e-mail (SAP
Offi ce Mail) to an SAP user AJON1. There are no attachments involved in this recipe. However,
we will want the SAP user AJON1 to see a pop-up express message when the e-mail document
is received in his or her inbox.
How to do it...
We will now perform the steps shown as follows:
1. Declare two reference variables sendrequest and myrecpient to the classes
cl_bcs and cl_sapuser_bcs.
For More Information:
www.packtpub.com/sap-advanced-business-application-programming-
cookbook/book
21
Chapter 11
189
2. We will then declare a variable for specifying the content of the e-mail email_text.
This is based on the type bcsy_text. We also declare an object reference to the
class cl_document_bcs with the name document.
3. We call the static factory method create_persistent of the class cl_bcs.
4. The returned reference is stored in the sendrequest reference variable
declared earlier.
5. An SAP user object is then created using the CREATE method. This will be used later
for specifying the e-mail recipient. The returned object is stored in myrecipient
variable. The corresponding object for the user AJON1 is created.
6. Next, we call the add_recipient method of the cl_bcs class for the object
reference sendrequest. We supply the recipient through the myrecipient
object and we pass the value 'X' for the i_express parameter.
7. Next, we create the e-mail text. A simple one-line text My first email content
is added to the internal table email_text. In addition, the factory method
create_document is called for class cl_document_bcs. The type RAW
is specifi ed through the parameter i_type.
For More Information:
www.packtpub.com/sap-advanced-business-application-programming-
cookbook/book
26
Sending E-mail Using BCS Classes
190
8. We then call the SET_DOCUMENT method and pass the document object as
the parameter. The send method of the class cl_bcs for the object reference
sendrequest is also called.
9. Finally, we call the COMMIT WORK statement.
10. The entire code block is placed within a TRY .. ENDTRY statement and the cx_bcs
exception class will be used for catching exceptions.
How it works...
We created object references for the send request and the e-mail document as well for the
recipient user object. The static factory method create_persistent of the cl_bcs class
is called in order to create a send request.
Then, we defi ne appropriate text for the content of the e-mail body and add it to the created
send request along with the subject of the e-mail.
A recipient object (based upon the class cl_sapuser_bcs) is created for the SAP user
AJON1. This recipient is then added to the send request using the method add_recipient
of the cl_bcs class. For the i_express parameter of the add_recipient method ,
the value 'X' is passed so that the user receives an express message when the e-mail is
received in his or her inbox. A new document is created using the static create_document
method of the cl_document_bcs class. The document is having type RAW and relevant
subject and content. The add_document method is then called in order to add the document
to the send request. Finally, the COMMIT WORK statement is called and the e-mail is sent.
An express message is generated as shown in the following screenshot:
For More Information:
www.packtpub.com/sap-advanced-business-application-programming-
cookbook/book
18
Chapter 11
191
The message appears in the document (Unread Documents) of the SAP Business
Workplace (transaction SBWP). The message header for the corresponding message
appears as shown in the following screenshot:
It contains the red icon that denotes an express message has been generated. The title
(Title), author name (Author), and the date received (Date received) are shown as well.
The preview of the document body is shown in the following screenshot:
The My fi rst email content text is the e-mail text, whereas as the my email subject text is the
subject as coded in the program.
There's more...
In case the e-mail is to be sent immediately, the SET_SEND_IMMEDIATELY method of the
cl_bcs class must be called before the SEND method (and the COMMIT WORK statement),
as shown as follows:
SENDREQUEST->SET_SEND_IMMEDIATELY('X').
For More Information:
www.packtpub.com/sap-advanced-business-application-programming-
cookbook/book
Documents you may be interested
Documents you may be interested