In this recipe, we will see how we can create a small program that will run another ABAP program and will send the second program's output as an e-mail attachment in PDF form. The basic steps for creating the send request and defining the recipient will remain the same as mentioned in the previous recipes. This recipe will emphasize on the additional portion required in order to run the program, capture its output, and convert the output into PDF form. The second program (program to be called) is created first and we have named it ZST_6_CALLED_PROGRAM
.
We will now list the steps needed:
SUBMIT
statement that will call another program zst_6_called_program
(which simply prints Hello World
). The EXPORTING LIST TO MEMORY AND RETURN
addition is used along with the SUBMIT
statement.abaplist
. We then call the LIST_FROM_MEMORY
function module and use the prog_output
object for storing the list fetched from the memory.binary_tab
of dictionary type solix
. The function module TABLE_COMPRESS
is then called that converts the program output into a table of binary format solix
.SX_OBJECT_CONVERT_ALI_PDF
. Before the call of the function module, we define necessary variables and internal tables necessary for the function module call. The various parameters should be provided with appropriate values. The format_src
parameter should be assigned value ALI
( meaning ABAP list), the format_dst
parameter is assigned PDF
, whereas the funcpara
parameter is assigned the value DELETE
. The address type addr_type
is passed PRT
, whereas devtype
is passed PDF1
.add attachment
method of the class cl_bcs_document
for the document object. The type is specified as PDF
and the binary_tab
value is passed as the cotent of the file to be attached. We have used the SUBMIT
statement in order to run the other program. The output of the program is generated and sent to the memory using the SUBMIT
statement. The function module list_from_memory
then fetches the program's output from the memory and stores it in the internal table prog_output
. We then use the function module table_compress
in order to convert the ABAP list into an internal table of binary data format based on the dictionary structure solix
.
The function module sx_object_convert_ali_pdf
is then called. We supply it with the necessary parameters and the necessary variables and internal table. The ALI corresponds to the ABAP list format (for the source format) whereas the target format is specified as PDF. The function module converts the ABAP list stored in the binary format into PDF. After the function module execution is complete, the PDF generated is stored in the internal table named binary_tab
. For the parameters of the function module addr_type
and device type devtype
, the values PRT
(meaning printer name) and PDF1
are passed, respectively. The funcpara
parameter is supplied with DELETE
. This is to delete the spool request created by this function module created during the PDF conversion process.
This PDF content stored in the internal table binary_tab
is then attached to the e-mail document using the add attachment
method. We specify the type as PDF and pass the binary_tab
for the method's importing parameter i_att_content_hex
.
The PDF output generated will be attached to the e-mail document.
This is one of the ways of capturing the output of a program. We may also use the SEND TO SAP-SPOOL
addition for the SUBMIT
statement. This allows the generated list to be sent to the SAP spool, which can then be turned into a PDF.
Also, we covered a scenario where a simple program is called. The called program may contain a number of selection screen input fields. You may supply appropriate values for these selection screen parameters while calling the program using the SUBMIT
statement. This may be done, for example, using the WITH SEL1 EQ VAL1
addition of the SUBMIT
statement.
18.118.200.154