RFC conver spool to a PDF document

Tips by: Moises Moreno

This code are for RFC.
 
This RFC conver spool to a PDF document:
 
FUNCTION ZGVK_CONVERT_SPOOL_TO_PDF .

*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(SPOOL_ID) TYPE RQIDENT
*" EXPORTING
*" REFERENCE(BYTE_SIZE) TYPE RSTSBYTNO
*" TABLES
*" PDF_OUTPUT STRUCTURE SOLISTI1
*"----------------------------------------------------------------------

PERFORM CONVIERTE_SPOOL_TO_PDF TABLES PDF_OUTPUT

USING SPOOL_ID

CHANGING BYTE_SIZE.

ENDFUNCTION.

FORM CONVIERTE_SPOOL_TO_PDF TABLES PAR_PDFOUT STRUCTURE GVK_PDF_OUT

USING PAR_SPOOLID

CHANGING PAR_SIZE.

DATA: GVK_ID LIKE TSP01-RQIDENT.

REFRESH: GVK_PDF_CONT, GVK_PDF_OUT, PAR_PDFOUT.

CLEAR GVK_ID.

GVK_ID = PAR_SPOOLID.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = GVK_ID

* NO_DIALOG = C_NO
* DST_DEVICE = C_DEVICE

IMPORTING

PDF_BYTECOUNT = GVK_BYTECOUNT

TABLES

PDF = GVK_PDF_CONT

EXCEPTIONS

ERR_NO_ABAP_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

ERR_BAD_DESTDEVICE = 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

OTHERS = 12.

CHECK SY-SUBRC = 0.

PAR_SIZE = GVK_BYTECOUNT.

LOOP AT GVK_PDF_CONT.

TRANSLATE GVK_PDF_CONT USING ' ~'.

CONCATENATE GVK_BUFFER GVK_PDF_CONT INTO GVK_BUFFER.

ENDLOOP.

TRANSLATE GVK_BUFFER USING '~ '.

DO.

PAR_PDFOUT = GVK_BUFFER.

APPEND PAR_PDFOUT.

SHIFT GVK_BUFFER LEFT BY 255 PLACES.

IF GVK_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

ENDFORM.

* Form CONVIERTE_SPOOL_TO_PDF *
*----------------------------------------------------------------------*
This, take the PDF document and send to external SAP mail 
FUNCTION ZGVK_SEND_ATTPDF_EXTERNAL_MAIL.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(SENDER) TYPE SOOS1-RECEXTNAM
*" EXPORTING
*" REFERENCE(OBJECT_ID_NEW) LIKE SOODK STRUCTURE SOODK
*" REFERENCE(SENT_TO_ALL) LIKE SONV-FLAG
*" REFERENCE(SENDER_ID) LIKE SOUDK STRUCTURE SOUDK
*" TABLES
*" PDF_CONT STRUCTURE SOLISTI1
*" DESTINOS STRUCTURE SOOS1
*"----------------------------------------------------------------------

PERFORM LLENA_ESTRUCTURAS TABLES PDF_CONT DESTINOS.

PERFORM ENVIA_DOCUMENTO.

ENDFUNCTION.

*----------------------------------------------------------------------*

* Form LLENA_ESTRUCTURAS *

FORM LLENA_ESTRUCTURAS TABLES PAR_PDFCONTE STRUCTURE ATTCONT_TAB

PAR_DESTINOS STRUCTURE REC_TABLE.

DATA: W_CNT TYPE I.

REFRESH: OBJCONT,

OBJHEAD,

OBJECT_PARA,

OBJECT_PARB,

NEW_PACK_LIST,

ATTHEAD_TAB,

ATTCONT_TAB,

REC_TABLE.

CLEAR: OBJCONT,

OBJHEAD,

OBJECT_PARA,

OBJECT_PARB,

NEW_PACK_LIST,

ATTHEAD_TAB,

ATTCONT_TAB,

REC_TABLE,

OBJECT_FL_CHANGE,

OBJECT_HD_CHANGE,

OBJECT_TYPE,

PUT_IN_OUTBOX,

ORIGINATOR,

ORIGINATOR_TYPE,

OBJECT_ID_NEW,

SENT_TO_ALL,

SENDER_ID.

 

ATTCONT_TAB[] = PAR_PDFCONTE[].

READ TABLE PAR_PDFCONTE INDEX W_CNT.

OBJECT_HD_CHANGE-OBJLEN = ( W_CNT - 1 ) * 255 +

STRLEN( PAR_PDFCONTE ).

OBJECT_HD_CHANGE-OBJLA = 'E'.

OBJECT_HD_CHANGE-OBJNAM = 'SAPRPT'.

OBJECT_HD_CHANGE-OBJDES = 'Antigüedad de Saldos Galvacer'.

OBJECT_HD_CHANGE-OBJSNS = 'F'.

* OBJECT_HD_CHANGE-OBJLEN = '235-'. "VERIFICAR COMO SE CALCULA

OBJECT_TYPE = 'RAW'.

PUT_IN_OUTBOX = 'X'.

ORIGINATOR = SY-UNAME.

OBJCONT-LINE = 'Estimado Cliente:'.

APPEND OBJCONT.

CLEAR OBJCONT.

APPEND OBJCONT.

CLEAR OBJCONT.

CONCATENATE ' Con el objetivo de brindarle un mayor servicio, nos'

'permitimos hacerle llegar de manera oportuna información'

INTO OBJCONT-LINE SEPARATED BY SPACE.

APPEND OBJCONT.

CLEAR OBJCONT.

MOVE 'referente a su Estado de Cuenta Galvacer.'

TO OBJCONT-LINE.

APPEND OBJCONT.

CLEAR OBJCONT.

APPEND OBJCONT.

CLEAR OBJCONT.

CONCATENATE ' El Estado de Cuenta es un nuevo y útil servicio sin'

'costo, mediante el cual usted obtiene un reporte que'

INTO OBJCONT-LINE SEPARATED BY SPACE.

APPEND OBJCONT.

CLEAR OBJCONT.

CONCATENATE 'incluye los vencimientos y saldos registrados en su'

'cuenta, al día último del mes anterior.'

INTO OBJCONT-LINE SEPARATED BY SPACE.

APPEND OBJCONT.

CLEAR OBJCONT.

APPEND OBJCONT.

CLEAR OBJCONT.

CONCATENATE ' Se requiere tener instalado el Acrobat Reader, para'

'poder leer el archivo adjunto. Si Usted no cuenta'

INTO OBJCONT-LINE SEPARATED BY SPACE.

APPEND OBJCONT.

CLEAR OBJCONT.

CONCATENATE 'con la aplicación, lo puede descargar gratuitamente'

'en la siguiente dirección web:'

INTO OBJCONT-LINE SEPARATED BY SPACE.

APPEND OBJCONT.

CLEAR OBJCONT.

OBJCONT-LINE =

'http://www.adobe.com/products/acrobat/readstep2.html'.

APPEND OBJCONT.

CLEAR OBJCONT.

APPEND OBJCONT.

CLEAR OBJCONT.

CONCATENATE ' Para cualquier información adicional, por favor'

'comuníquese con su ejecutivo de cuenta o llame sin'

INTO OBJCONT-LINE SEPARATED BY SPACE.

APPEND OBJCONT.

CLEAR OBJCONT.

CONCATENATE 'costo al 01 800 284 25 82 de lunes a viernes de'

'8:00 a 18:00 hrs. y sábados de 10:00 a 13:00 hrs.'

INTO OBJCONT-LINE SEPARATED BY SPACE.

APPEND OBJCONT.

 

NEW_PACK_LIST-TRANSF_BIN = 'X'.

NEW_PACK_LIST-HEAD_START = 1.

NEW_PACK_LIST-HEAD_NUM = 1.

NEW_PACK_LIST-BODY_START = 1.

NEW_PACK_LIST-OBJTP = 'PDF'.

NEW_PACK_LIST-OBJDES = 'Attachname'.

DESCRIBE TABLE ATTCONT_TAB LINES NEW_PACK_LIST-BODY_NUM.

NEW_PACK_LIST-OBJLEN = NEW_PACK_LIST-BODY_NUM * 255.

APPEND NEW_PACK_LIST.

ATTHEAD_TAB-LINE = '&SO_FORMAT=BIN'.

REC_TABLE[] = PAR_DESTINOS[].

ENDFORM.

* Form LLENA_ESTRUCTURAS *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Form ENVIA_DOCUMENTO *

FORM ENVIA_DOCUMENTO.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

* EXTERN_ADDRESS = ' '

* FOLDER_ID = ' '

* FORWARDER = ' '

OBJECT_FL_CHANGE = OBJECT_FL_CHANGE

OBJECT_HD_CHANGE = OBJECT_HD_CHANGE

* OBJECT_ID = ' '

OBJECT_TYPE = OBJECT_TYPE

OUTBOX_FLAG = PUT_IN_OUTBOX

ORIGINATOR = ORIGINATOR

ORIGINATOR_TYPE = ORIGINATOR_TYPE

* OWNER = ' '

* STORE_FLAG = ' '

IMPORTING

OBJECT_ID_NEW = OBJECT_ID_NEW

SENT_TO_ALL = SENT_TO_ALL

ORIGINATOR_ID = SENDER_ID

TABLES

OBJCONT = OBJCONT

OBJHEAD = OBJHEAD

OBJPARA = OBJECT_PARA

OBJPARB = OBJECT_PARB

PACKING_LIST = NEW_PACK_LIST

ATT_HEAD = ATTHEAD_TAB

ATT_CONT = ATTCONT_TAB

RECEIVERS = REC_TABLE

EXCEPTIONS

OBJECT_NOT_SENT = 15

OBJECT_TYPE_NOT_EXIST = 17

OPERATION_NO_AUTHORIZATION = 21

PARAMETER_ERROR = 23

TOO_MUCH_RECEIVERS = 73

OTHERS = 1000.

ENDFORM.

* Form ENVIA_DOCUMENTO *
*----------------------------------------------------------------------*

More Function Module
Functions / SAP Script / ALV

Tables
Database Table

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.