Posted: Sun Oct 14, 2007 8:05 pm Post subject: Takes the spool from a previous job step
Code:
This program takes the spool from a previous job step. It converts this spool to PDF and then inserts this PDF as an attachment in an E-mail.
************************************************************************
* Program Name: KEG Job Sched Run with PDF Output Creation: 03/22/2001
*
* *
* SAP Name : ZESU_JOB_RUN_WITH_PDF_OUTPUT Application: U *
* *
* Author : Thomas Jung Type: 1 *
*______________________________________________________________________*
* Description : This Program will read the spool produced
* by the specified previous job step and converts it to
* PDF. This PDF-Formatted report is then output to a file. *
*______________________________________________________________________*
* Inputs: File name, job step *
* *
* Outputs: File formatted in PDF with the report output. *
*______________________________________________________________________*
* External Routines
* FILE_GET_NAME
* CONVERT_ABAPSPOOLJOB_2_PDF
* CONVERT_OTFSPOOLJOB_2_PDF
* Z_E_OPEN_FILE_FOR_OUTPUT_BIN
* Z_E_WRITE_TO_FILE_WITH_LENGTH
* SO_NEW_DOCUMENT_ATT_SEND_API1
* BAPI_USER_GET_DETAIL
*______________________________________________________________________*
* Return Codes:
* The program uses the standard function modules for File manipulation
* therefore it has all the standard error routines for Files. *
*______________________________________________________________________*
* Ammendments: *
* Programmer Date Req. # Action *
* ================ ========== ====== ===============================*
* Thomas Jung 03/27/2001 ------ Initial Program. *
* *
************************************************************************
*----------------------------------------------------------------------*
* DATA DICTIONARY TABLES *
*----------------------------------------------------------------------*
tables: raldb. "Transfer Structure for Logical Databases
tables: tbtcp.
tables: icon, "Icons table\
bapiadsmtp, "BAPI structure for e-mail addresses (central
bapiadpag.
*----------------------------------------------------------------------*
* TYPE POOLS *
*----------------------------------------------------------------------*
type-pools: sbdst.
*----------------------------------------------------------------------*
* CONSTANTS *
*----------------------------------------------------------------------*
constants: logical_file_name like filename-fileintern
value 'ZEX_STANDARD_FILENAME',
pdf_ext(4) type c
value '.pdf',
pdf_type(3) type c
value 'PDF',
internet(1) type c
value 'U',
dist_list(1) type c
value 'C',
kimball_domain(12) type c value '@kimball.com'.
constants: kim_ftp(80) type c
value
'ftp://kww.kog.kimball.com/webtools/acrobat_reader/acroread40w95.exe'.
constants: ext_ftp(80) type c
value
'http://www.adobe.com/products/acrobat/readermain.html'.
*----------------------------------------------------------------------*
* VARIABLES *
*----------------------------------------------------------------------*
data: length type i.
data: f4_field like trdir-name.
data: pathleng type i,
nameleng type i,
physleng type i.
data jselect like btcselect.
data: report like sy-repid.
data: doc_chng like sodocchgi1.
data: tab_lines like sy-tabix.
*----------------------------------------------------------------------*
* INTERNAL TABLES *
*----------------------------------------------------------------------*
data: begin of html_tab occurs 0.
include structure w3html.
data: end of html_tab.
data: icontab(32) occurs 10 with header line.
data: itab like abaplist occurs 0 with header line.
data: ipdf like tline occurs 0 with header line.
data: objpack like sopcklsti1 occurs 2 with header line.
data: objhead like solisti1 occurs 1 with header line.
data: objbin like solisti1 occurs 10 with header line.
data: objtxt like solisti1 occurs 10 with header line.
data: reclist like somlreci1 occurs 5 with header line.
*----------------------------------------------------------------------*
* SELECTION SCREEN LAYOUT *
*----------------------------------------------------------------------*
selection-screen begin of block one with frame title text-001.
parameters: fileintn like filename-fileintern obligatory
default logical_file_name,
filepath like rlgrap-filename lower case.
parameters: file1 like rlgrap-filename obligatory lower case,
physname like rlgrap-filename lower case.
parameters: date1 as checkbox.
parameters: time1 as checkbox.
selection-screen end of block one.
selection-screen begin of block two with frame title text-002.
parameter: step like tbtcp-stepcount.
parameter: abap radiobutton group one.
parameter: oft radiobutton group one.
selection-screen end of block two.
selection-screen begin of block three with frame title text-003.
parameter: file radiobutton group two.
parameter: email radiobutton group two.
selection-screen skip 1.
parameter: int radiobutton group thre.
parameter: dis radiobutton group thre.
selection-screen skip 1.
parameter: ext_user like somlreci1-receiver.
selection-screen end of block three.
*----------------------------------------------------------------------*
* SELECTION SCREEN PROCESSING - OUTPUT *
*----------------------------------------------------------------------*
at selection-screen output.
perform filename_processing.
loop at screen.
if screen-name eq 'FILEPATH' or
screen-name eq 'PHYSNAME'.
screen-input = 0.
modify screen.
endif.
endloop.
*----------------------------------------------------------------------*
* START OF SELECTION *
*----------------------------------------------------------------------*
start-of-selection.
move sy-repid to report.
perform auth_check.
perform filename_processing.
perform get_spool.
perform convert_list_to_pdf.
if file = 'X'.
perform write_to_file.
else.
perform send_pdf_in_email.
endif.
*&---------------------------------------------------------------------*
*& Form filename_processing
*&---------------------------------------------------------------------*
* Prepair to conver to the logical file name to a physical name
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form filename_processing.
perform get_filename using fileintn file1 physname.
nameleng = strlen( file1 ).
physleng = strlen( physname ).
pathleng = physleng - nameleng.
if pathleng > 0.
filepath = physname(pathleng).
endif.
endform. " filename_processing
*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* Convert the logical file name into a physical file name
*----------------------------------------------------------------------*
* -->P_FILEINTN Input Logical File Name
* -->P_FILE1 Filename selected by input
* -->P_PHYSNAME Output Physical File Name
*----------------------------------------------------------------------*
form get_filename using p_fileintn
p_file1
p_physname.
data: p_file2 like rlgrap-filename.
clear p_file2.
move p_file1 to p_file2.
if date1 = 'X'.
concatenate p_file2
'_'
sy-datum
into p_file2.
endif.
if time1 = 'X'.
concatenate p_file2
'_'
sy-uzeit
into p_file2.
endif.
endform. " get_filename
*&---------------------------------------------------------------------*
*& Form write_to_file
*&---------------------------------------------------------------------*
* TRANSFER PDF DATA TO OUTPUT FILE
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form write_to_file.
data: string_out type string.
describe field objbin length length.
call function 'Z_E_OPEN_FILE_FOR_OUTPUT_BIN'
exporting
filename1 = physname.
loop at objbin.
clear string_out.
move objbin to string_out.
call function 'Z_E_WRITE_TO_FILE_WITH_LENGTH'
exporting
filename1 = physname
length = length
please_open_file = 'NO'
string = string_out.
endloop.
endform. " write_to_file
*&---------------------------------------------------------------------*
*& Form convert_list_to_pdf
*&---------------------------------------------------------------------*
* Convert to Spool to PDF
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form convert_list_to_pdf.
data: spool_id like tsp01-rqident.
move tbtcp-listident to spool_id.
endform. " convert_list_to_pdf
*&---------------------------------------------------------------------*
*& Form get_spool
*&---------------------------------------------------------------------*
* Read the job log to get the spool number for the specified step
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_spool.
clear jselect.
*jselect-jobname = '*'.
jselect-username = '*'.
****Have this program get its own Job Name
call function 'GET_JOB_RUNTIME_INFO'
importing
* EVENTID =
* EVENTPARM =
* EXTERNAL_PROGRAM_ACTIVE =
jobcount = jselect-jobcount
jobname = jselect-jobname
* STEPCOUNT =
exceptions
no_runtime_info = 1
others = 2.
****Read the spool number for this job step.
clear tbtcp.
select single listident from tbtcp
into tbtcp-listident
where jobname = jselect-jobname
and jobcount = jselect-jobcount
and stepcount = step.
if tbtcp-listident = 0.
message i009 with step.
endif.
endform. " get_spool
*&---------------------------------------------------------------------*
*& Form convert_pdf
*&---------------------------------------------------------------------*
* Take the PDF information returned by the function module
* and convert it to a file readable format. It currently is
* in a printable-only format.
*----------------------------------------------------------------------*
* -->P_IPDF PDF Source
* -->P_OBJBIN PDF Destination
*----------------------------------------------------------------------*
form convert_pdf tables t_source_tab structure ipdf
t_target_tab structure objbin.
data: l_hfeld(1600) type c,
l_offset type p,
l_tabix like sy-tabix,
l_max type i,
l_linecount_source type i,
l_length_source type i,
l_length_target type i.
* Zeilenlänge des Quell-PDF-Files
describe field t_source_tab length l_length_source.
* Zeilenlänge der Ziel-Mime-Tabelle
describe field t_target_tab length l_length_target.
endform. " convert_pdf
*&---------------------------------------------------------------------*
*& Form auth_check
*&---------------------------------------------------------------------*
* Perform Authorization Check
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form auth_check.
authority-check object 'Z_ABAP_CHK'
id 'BUKRS' dummy
id 'ACTVT' dummy
id 'WERKS' dummy
id 'REPID' field report.
if sy-subrc ne 0.
message e024.
endif.
endform. " auth_check
*&---------------------------------------------------------------------*
*& Form send_pdf_in_email
*&---------------------------------------------------------------------*
* Transfer the PDF file in an E-Mail
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form send_pdf_in_email.
data: iaddsmtp type bapiadsmtp occurs 0 with header line.
data: ireturn type bapiret2 occurs 0 with header line.
concatenate text-010 jselect-jobname text-011
into doc_chng-obj_descr
separated by space.
clear objtxt.
objtxt = text-012.
append objtxt.
clear objtxt.
objtxt = text-013.
append objtxt.
clear objtxt.
concatenate text-014 jselect-jobname
into objtxt
separated by space.
append objtxt.
clear objtxt.
objtxt = text-015.
append objtxt.
clear objtxt.
objtxt = text-016.
append objtxt.
clear objtxt.
append objtxt.
clear objtxt.
concatenate text-017 kim_ftp
into objtxt
separated by space.
append objtxt.
clear objtxt.
concatenate text-018 ext_ftp
into objtxt
separated by space.
append objtxt.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.