MUNDOSAP

Regresar   MUNDOSAP > DESARROLLO > Programación ABAP IV
Nombre de Usuario
Contraseña
Home Descargas Registrar FAQ Miembros Calendario Buscar Temas de Hoy Marcar Foros Como Leídos




 
Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Viejo 02/12/16, 20:40:27
Avatar de VICHAMA
VICHAMA VICHAMA is offline
Junior Member
 
Fecha de Ingreso: abr 2006
Localización: LIMA
Mensajes: 5
Encriptar PDF para enviar por correo

Hace mucho que teníamos la necesidad de encriptar/ poner contraseña a un smartforms que enviamos vía mail en nuestra compañía.

Nos ayudamos con lo publicado por rlavi en:


Aquí los pasos que seguí:

1. Generar el spool de impresión del smartforms que se desee (lo hice con otro programa).
2. Convertir el spool a PDF.
3. Guardar el PDF en el servidor.
4. Con ayuda del RF SXPG_COMMAND_EXECUTE y SM49 encriptar el PDF.
5. Recuperamos el PDF del servidor y lo adjuntamos al correo.

* Aquí les dejo algo del código.

2. Convertir el spool a PDF.

data: tsp01sys type tsp01sys,
tsp02sys type tsp02sys,
lt_pdf LIKE tline OCCURS 100 WITH HEADER LINE,
lv_pathserve type SAPB-SAPPFAD,
lvi_size type i,
lv_size type NUM12,
lt_epdf type standard table of docs,
lwa_pdf type docs,
client LIKE tst01-dclient,
name LIKE tst01-dname,
objtype LIKE rststype-type,
type LIKE rststype-type,
is_otf type c,
gv_envok type c,
lv_rqidnt1 LIKE TSP01-rqident,
lv_rqident LIKE TSP01_SP0R-RQID_CHAR.

refresh lt_pdf.
call function 'CONVERT_OTFSPOOLJOB_2_PDF'
exporting
src_spoolid = lv_rqidnt1 “Número del spool
no dialog = ' '
importing
pdf_bytecount = lvi_size
tables
pdf = lt_pdf
exceptions
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 5
user_cancelled = 6
err_spoolerror = 7
err_temseerror = 8
err_btcjob_open_failed = 9
err_btcjob_submit_failed = 10
err_btcjob_close_failed = 11.


data: wa_buffer type string,
wa_bufsrv type string.
loop at lt_pdf.
translate lt_pdf using '~'.
concatenate wa_buffer lt_pdf into wa_buffer.
endloop.
translate wa_buffer using '~' .


3. Guardar el PDF en el servidor:
describe table lt_epdf lines v_lineas.
*
if v_lineas > 0.
* pasamos el pdf al sevidor en el dir /tmp (ver AL11)
* descargar pdfbox-app-1.8.12.jar y colocarlo en el servidor en el dir /tmp
concatenate '/tmp/' lv_rqident '.pdf' into lv_pathserve.

lv_size = v_lineas * 1024.
concatenate '/tmp/' lv_rqident '.pdf' into lv_pathserve.
call function 'ARCHIVFILE_TABLE_TO_SERVER'
exporting
targetpath = lv_pathserve
length = lv_size
tables
archivobject = lt_epdf
exceptions
error_file = 1
no_authorization = 2
others = 3.
endif

4. Con ayuda del RF SXPG_COMMAND_EXECUTE y SM49 encriptar el PDF.

data: param1 type sxpgcolist-parameters value '/tmp/pdfbox-app-1.8.12.jar Encrypt -U'.

data: funcstatus type extcmdexex-status.
data: iserveroutput type standard table of btcxpm,
waserveroutput type btcxpm..
data: target type rfcdisplay-rfchost.
data: head type string..
data: tail type string.

target = sy-host.
condense: p_keypdf, p_pathserve NO-GAPS.

* para el ejemplo usaremos como Password ‘nano0502’ .

concatenate param1 ‘nano0502’ '-O' ‘nano0502’ p_pathserve into param1 SEPARATED BY space.

call function 'SXPG_COMMAND_EXECUTE'
exporting
commandname = 'ZKEYPDF'
additional_parameters = param1
operatingsystem = 'AIX' "SXPGCOSTAB-OPSYSTEM
targetsystem = target
stdout = 'X'
stderr = 'X'
terminationwait = 'X'
importing
status = funcstatus
tables
exec_protocol = iserveroutput[]
exceptions
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
others = 15.

5. Recuperamos el PDF del servidor en la tabla lt_epdf y lo cargamos en wa_buffer :

data: lv1_size type NUM12.

refresh lt_epdf. clear: lwa_pdf, p_wa.

CALL FUNCTION 'ZREAD_PDF_FROM_SERVER'
EXPORTING
SOURCEPATH = p_pathserve
* WITHOUT_DELETE = ' '
IMPORTING
LENGTH = lv1_size
TABLES
ARCHIVOBJECT = lt_epdf
EXCEPTIONS
ERROR_FILE = 1
NO_AUTHORITY = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
message e000(oo) with 'An error occurred in PDF_FROM_SERVER:' p_pathserve
', subrc:' sy-subrc.
ELSE.
LOOP AT lt_epdf into lwa_pdf .
TRANSLATE lwa_pdf USING '~'.
CONCATENATE wa_buffer lwa_pdf INTO wa_buffer.
CLEAR lwa_pdf .
ENDLOOP.
TRANSLATE wa_buffer USING '~'.
ENDIF.

*----------------------------------------------------------------------
*La función ZREAD_PDF_FROM_SERVER es copia ARCHIVFILE_SERVER_TO_TABLE. (En mi caso daba error la estándar).


FUNCTION ZREAD_PDF_FROM_SERVER.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" VALUE(SOURCEPATH) LIKE SAPB-SAPPFAD
*" REFERENCE(WITHOUT_DELETE) OPTIONAL
*" EXPORTING
*" REFERENCE(LENGTH) LIKE SAPB-LENGTH
*" TABLES
*" ARCHIVOBJECT STRUCTURE DOCS
*" EXCEPTIONS
*" ERROR_FILE
*" NO_AUTHORITY
*" ACTIVITY_UNKNOWN
*"----------------------------------------------------------------------
data: loc_length type p,
bin_filesize type p,
count_table type p,
line like archivobject-lines,
check_filename type authb-filename,
slen type i.
CONSTANTS gc_fname TYPE fileintern VALUE 'ARCHIVLINK_FILE_READ'.
field-symbols: <f1>.
* check authority for file access
slen = strlen( sourcepath ).
if slen <= 60.
check_filename(60) = sourcepath.
call function 'AUTHORITY_CHECK_DATASET'
exporting
* PROGRAM =
activity = 'READ'
filename = check_filename

exceptions
no_authority = 1
activity_unknown = 2
others = 3.
case sy-subrc.
when 0.
when 1.
message e046 raising no_authority.
when others.
message e414 with sourcepath raising error_file.
endcase.
endif.
* open file on applicationserver
CALL FUNCTION 'FILE_VALIDATE_NAME'
EXPORTING
LOGICAL_FILENAME = gc_fname
CHANGING
PHYSICAL_FILENAME = sourcepath
EXCEPTIONS
LOGICAL_FILENAME_NOT_FOUND = 1
VALIDATION_FAILED = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
open dataset sourcepath for input in binary mode.
if sy-subrc <> 0.
message e414 with sourcepath raising error_file.
endif.
* read in information
refresh archivobject.
clear bin_filesize.
do.
read dataset sourcepath into archivobject length loc_length.
if sy-subrc = 0.
append archivobject.
bin_filesize = bin_filesize + loc_length.
else.
if sy-subrc = 8.
* open not possible
message e414 with sourcepath raising error_file.
else.
* end of file reached
if loc_length ne 0.
append archivobject.
bin_filesize = bin_filesize + loc_length.
endif.
exit.
endif.
endif.
enddo.
* close file on apllication server
close dataset sourcepath.
* correct last line
describe table archivobject lines count_table.
if count_table <> 0.
read table archivobject index count_table.
clear line.
length = loc_length.
if length > 0 and length < 1025.
assign archivobject-lines(length) to <f1>.
line = <f1>.
clear archivobject-lines.
archivobject-lines = line.
modify archivobject index count_table.
endif.
endif.
length = bin_filesize.
if without_delete <> 'X'.
delete dataset sourcepath.
endif.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
raising error_file.
endif.
 Finalmente pasamos desde wa_buffer a lt_contents_bin para adjuntarlo a la función 'SO_DOCUMENT_SEND_API1'
clear lt_contents_bin. refresh lt_contents_bin.
do.
lt_contents_bin = wa_buffer.
append lt_contents_bin.
clear lt_contents_bin.
shift wa_buffer left by 255 places.
if wa_buffer is initial.
exit.
endif.
enddo.
Imágenes Adjuntas
Tipo de Archivo: jpg SM49_ZKEYPDF.jpg (91.7 KB, 71 visitas)
Responder Con Cita
  #2  
Viejo 28/05/19, 16:54:15
CarlosAvalosAndrade22 CarlosAvalosAndrade22 is offline
Junior Member
 
Fecha de Ingreso: may 2019
Mensajes: 1
Ejecución de comando externo no funciona

Hola buenos días:
consulta he seguido todos los pasos que indicas en el post pero el proceso de ejecutar el comando externo java no está funcionando. He creado el comando externo tal cual la imagen adjunta al post con los parámetros indicados. Pero al momento que se ejecuta la sentencia sale el siguiente error:
Can't exec external program (2) External program terminated with exit code 1
Desde cmd con archivos locales de la laptop si funciona el encriptado, pero al ejecutar la misma sentencia desde ABAP no funciona.
No se si hay algunos pre-requisitos que se deben configurar en SAP para que se puedan ejecutar comandos externos java. Como por ejemplo en la laptop se debe contrar con el SDK para que se pueda ejecutar el comando java -jar.

Quedo atento a su colaboración, gracias
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Reglas de Mensajes
no puedes crear nuevos temas
no puedes responder temas
no puedes adjuntar archivos
no puedes editar tus mensajes

El código vB está On
Las caritas están On
Código [IMG] está On
Código HTML está Off
Saltar a Foro


Husos Horarios son GMT. La hora en este momento es 20:31:30.


www.mundosap.com 2006 - Spain
software crm, crm on demand, software call center, crm act, crm solutions, crm gratis, crm web