Requirement: User wants a certain text to be send in mail as
PDF attachment.
Solution: We create a SO10 standard text for that text.
Further we can have 2 approaches.
First
approach: Embed that standard
text in a window of a new script. Call that script in a usual manner
using OPEN_FORM, WRITE_FORM, CLOSE_FORM function module. In the
calling of CLOSE_FORM we will get the OTF format of that script in
suitable type of internal table. Convert that OTF format into PDF
format internal table and use that as an attachment in mailing
functionality.
Second
approach: Our aim is to have
the final text in PDF format in suitable in internal table so that we
can use in attachment in mail. This we achieved through usual script
manner in the previous approach. Now we will use another way.
There
are 2 facts that we will use in this second approach. First is
whenever we write something on screen, a spool automatically get's
created for that. We can see that spool no using the system variable
SY-SPONO. Another is
that we have Function module to convert any ABAP spool into PDF. So
we will see how that works.
First
we will read that text using READ_TEXT function module and get the
text content in one internal table of type TLINE. Further we will use
function module GET_PRINT_PARAMETERS following a loop on internal
table and in each iteration print it's TDLINE column on screen. This
will create a spool whose number we can have in system variable
SY-SPONO. Further export that spool no using EXPORT TO DATABASE INDX.
EXPORT TO MEMORY ID won't work here because we are going to call this
program in background from the next program we will create.
Create
another program. Here we will be creating a job in background. In
that background job we will insert a process by submitting our
earlier created program and finally we will close that background
job. Further we will use function module named
'CONVERT_ABAPSPOOLJOB_2_PDF' to
convert the spool number, which we will be importing(which we have
exported in our earlier program) in this program, into PDF format.
Below
is the code snapshot.
REPORT 1:
REPORT 2:
Test this report by executing it and checking the newly created entry in SOST.
By: Reetika Patel
No comments:
Post a Comment