Skip to Content
0
Former Member
Mar 17, 2007 at 05:44 AM

OUT PUT ERROR

16 Views

HI

WHEN I AM EXECUTING THE FOLLOWING PROG I AM GETTING AN ERROR "MAXIMUM NUMBER OF INTERNAL SESSIONS REACHED".

DOES ANY ONE HAS ANY IDEA ABT IT.

REPORT ZSPOOL14.

TABLES:TSP01.

PARAMETERS: P_EMAIL1 LIKE SOMLRECI1-RECEIVER,

P_EMAIL2 LIKE SOMLRECI1-RECEIVER,

P_EMAIL3 LIKE SOMLRECI1-RECEIVER,

  • P_SENDER LIKE SOMLRECI1-RECEIVER,

P_DELSPL AS CHECKBOX.

*DATA DECLARATION

DATA: GD_RECSIZE TYPE I.

  • Spool IDs

TYPES: BEGIN OF T_TBTCP.

INCLUDE STRUCTURE TBTCP.

TYPES: END OF T_TBTCP.

DATA: IT_TBTCP TYPE STANDARD TABLE OF T_TBTCP INITIAL SIZE 0,

WA_TBTCP TYPE T_TBTCP.

  • Job Runtime Parameters

DATA: GD_EVENTID LIKE TBTCM-EVENTID,

GD_EVENTPARM LIKE TBTCM-EVENTPARM,

GD_EXTERNAL_PROGRAM_ACTIVE LIKE TBTCM-XPGACTIVE,

GD_JOBCOUNT LIKE TBTCM-JOBCOUNT,

GD_JOBNAME LIKE TBTCM-JOBNAME,

GD_STEPCOUNT LIKE TBTCM-STEPCOUNT,

GD_ERROR TYPE SY-SUBRC,

GD_RECIEVER TYPE SY-SUBRC.

DATA: W_RECSIZE TYPE I.

DATA: GD_SUBJECT LIKE SODOCCHGI1-OBJ_DESCR,

IT_MESS_BOD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

IT_MESS_ATT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

GD_SENDER_TYPE LIKE SOEXTRECI1-ADR_TYP,

GD_ATTACHMENT_DESC TYPE SO_OBJ_NAM,

GD_ATTACHMENT_NAME TYPE SO_OBJ_DES.

  • Spool to PDF conversions

DATA: GD_SPOOL_NR LIKE TSP01-RQIDENT,

GD_DESTINATION LIKE RLGRAP-FILENAME,

GD_BYTECOUNT LIKE TST01-DSIZE,

GD_BUFFER TYPE STRING.

  • Binary store for PDF

DATA: BEGIN OF IT_PDF_OUTPUT OCCURS 0.

INCLUDE STRUCTURE TLINE.

DATA: END OF IT_PDF_OUTPUT.

CONSTANTS:C_DEV LIKE SY-SYSID VALUE 'DEV',

C_NO(1) TYPE C VALUE ' ',

C_DEVICE(4) TYPE C VALUE 'LOCL'.

  • print parameters

DATA:PARAMS LIKE PRI_PARAMS,

DAYS(1) TYPE N VALUE 2,

COUNT(3) TYPE N VALUE 1,

VALID TYPE C,

SPOOL_REQUEST_NAME LIKE PRI_PARAMS-PLIST.

*INITIALIZATION.

************************************************************************

*START-OF-SELECTION.

START-OF-SELECTION.

  • Write statement to represent report output. Spool request is created

  • if write statement is executed in background. This could also be an

  • ALV grid which would be converted to PDF without any extra effort

WRITE 'HAI EVERYONE'.

NEW-PAGE.

COMMIT WORK.

  • NEW-PAGE PRINT OFF.

CONCATENATE SY-REPID+0(8)

SY-UNAME+0(3)

INTO SPOOL_REQUEST_NAME SEPARATED BY '_'.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

ARCHIVE_MODE = '1'

  • ARCHIVE_TEXT = C_CHAR_UNKNOWN

  • AR_OBJECT = C_CHAR_UNKNOWN

  • ARCHIVE_REPORT = C_CHAR_UNKNOWN

  • AUTHORITY = C_CHAR_UNKNOWN

COPIES = COUNT

COVER_PAGE = ''

  • DATA_SET = C_CHAR_UNKNOWN

  • DEPARTMENT = C_CHAR_UNKNOWN

DESTINATION = 'HR04'

EXPIRATION = DAYS

IMMEDIATELY = ''

  • IN_ARCHIVE_PARAMETERS = ' '

  • IN_PARAMETERS = ' '

LAYOUT = 'X_65_32'

LINE_COUNT = 65

LINE_SIZE = 132

LIST_NAME = SPOOL_REQUEST_NAME

  • LIST_TEXT = C_CHAR_UNKNOWN

MODE = 'BATCH'

NEW_LIST_ID = 'X'

  • PROTECT_LIST = C_CHAR_UNKNOWN

NO_DIALOG = 'X'

RECEIVER = ''

  • RELEASE = ''

REPORT = ''

SAP_COVER_PAGE = 'D'

HOST_COVER_PAGE = 'D'

  • PRIORITY = C_NUM1_UNKNOWN

  • SAP_OBJECT = C_CHAR_UNKNOWN

  • TYPE = C_CHAR_UNKNOWN

  • USER = SY-UNAME

  • USE_OLD_LAYOUT = ' '

  • UC_DISPLAY_MODE = C_CHAR_UNKNOWN

  • DRAFT = C_CHAR_UNKNOWN

  • ABAP_LIST = ' '

  • USE_ARCHIVENAME_DEF = ' '

  • DEFAULT_SPOOL_SIZE = C_CHAR_UNKNOWN

  • PO_FAX_STORE = ' '

  • NO_FRAMES = C_CHAR_UNKNOWN

IMPORTING

  • OUT_ARCHIVE_PARAMETERS =

OUT_PARAMETERS = PARAMS

VALID = VALID

  • VALID_FOR_SPOOL_CREATION =

  • EXCEPTIONS

  • ARCHIVE_INFO_NOT_FOUND = 1

  • INVALID_PRINT_PARAMS = 2

  • INVALID_ARCHIVE_PARAMS = 3

  • OTHERS = 4

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF VALID <> SPACE.

SUBMIT ZSPOOL14 TO SAP-SPOOL

SPOOL PARAMETERS PARAMS

WITHOUT SPOOL DYNPRO AND RETURN.

ENDIF.

IF SY-BATCH EQ 'X'.

PERFORM GET_JOB_DETAILS.

PERFORM OBTAIN_SPOOL_ID.

************************************

  • Alternative way could be to submit another program and store spool

  • id into memory.

*submit ZSPOOLTOPDF2

  • to sap-spool

  • spool parameters %_print

  • archive parameters %_print

  • without spool dynpro

  • and return.

************************************

  • Get spool id from program called above

  • IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.

PERFORM CONVERT_SPOOL_TO_PDF.

PERFORM PROCESS_EMAIL.

IF P_DELSPL EQ 'X'.

PERFORM DELETE_SPOOL.

ENDIF.

IF SY-SYSID = C_DEV.

WAIT UP TO 5 SECONDS.

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = 'X'

AND RETURN.

ENDIF.

ELSE.

PERFORM FCONVERT_SPOOL_TO_PDF.

PERFORM PROCESS_EMAIL.

IF P_DELSPL EQ 'X'.

PERFORM DELETE_SPOOL.

ENDIF.

IF SY-SYSID = C_DEV.

WAIT UP TO 5 SECONDS.

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = 'X'

AND RETURN.

ENDIF.

  • SKIP.

  • WRITE:/ 'Program must be executed in background in-order for spool'

*,

  • 'request to be created.'.

ENDIF.

----


  • FORM obtain_spool_id *

----


FORM OBTAIN_SPOOL_ID.

CHECK NOT ( GD_JOBNAME IS INITIAL ).

CHECK NOT ( GD_JOBCOUNT IS INITIAL ).

SELECT * FROM TBTCP

INTO TABLE IT_TBTCP

WHERE JOBNAME = GD_JOBNAME

AND JOBCOUNT = GD_JOBCOUNT

AND STEPCOUNT = GD_STEPCOUNT

AND LISTIDENT <> '0000000000'

ORDER BY JOBNAME

JOBCOUNT

STEPCOUNT.

READ TABLE IT_TBTCP INTO WA_TBTCP INDEX 1.

IF SY-SUBRC = 0.

  • MESSAGE S004(ZDD) WITH GD_SPOOL_NR.

GD_SPOOL_NR = WA_TBTCP-LISTIDENT.

  • MESSAGE S004(ZDD) WITH GD_SPOOL_NR.

ELSE.

MESSAGE S005(ZDD).

ENDIF.

ENDFORM. "obtain_spool_id

----


  • FORM get_job_details *

----


FORM GET_JOB_DETAILS.

  • Get current job details

CALL FUNCTION 'GET_JOB_RUNTIME_INFO'

IMPORTING

EVENTID = GD_EVENTID

EVENTPARM = GD_EVENTPARM

EXTERNAL_PROGRAM_ACTIVE = GD_EXTERNAL_PROGRAM_ACTIVE

JOBCOUNT = GD_JOBCOUNT

JOBNAME = GD_JOBNAME

STEPCOUNT = GD_STEPCOUNT

EXCEPTIONS

NO_RUNTIME_INFO = 1

OTHERS = 2.

ENDFORM. "get_job_details

----


  • FORM convert_spool_to_pdf *

----


FORM CONVERT_SPOOL_TO_PDF.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = GD_SPOOL_NR

NO_DIALOG = C_NO

DST_DEVICE = C_DEVICE

IMPORTING

PDF_BYTECOUNT = GD_BYTECOUNT

TABLES

PDF = IT_PDF_OUTPUT

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.

  • Transfer the 132-long strings to 255-long strings

LOOP AT IT_PDF_OUTPUT.

TRANSLATE IT_PDF_OUTPUT USING ' ~'.

CONCATENATE GD_BUFFER IT_PDF_OUTPUT INTO GD_BUFFER.

ENDLOOP.

TRANSLATE GD_BUFFER USING '~ '.

DO.

IT_MESS_ATT = GD_BUFFER.

APPEND IT_MESS_ATT.

SHIFT GD_BUFFER LEFT BY 255 PLACES.

IF GD_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

ENDFORM. "convert_spool_to_pdf

----


  • FORM process_email *

----


FORM PROCESS_EMAIL.

DESCRIBE TABLE IT_MESS_ATT LINES GD_RECSIZE.

CHECK GD_RECSIZE > 0.

PERFORM SEND_EMAIL USING P_EMAIL1 P_EMAIL2 P_EMAIL3.

  • perform send_email using p_email2.

ENDFORM. "process_email

----


  • FORM send_email *

----


  • --> p_email *

----


FORM SEND_EMAIL USING P_EMAIL P_EMAIL4 P_EMAIL5.

CHECK NOT ( P_EMAIL IS INITIAL ).

CHECK NOT ( P_EMAIL4 IS INITIAL ).

CHECK NOT ( P_EMAIL5 IS INITIAL ).

REFRESH IT_MESS_BOD.

  • Default subject matter

GD_SUBJECT = 'Subject'.

GD_ATTACHMENT_DESC = 'Attachname'.

CONCATENATE 'ebdit' ' ' INTO GD_ATTACHMENT_NAME.

IT_MESS_BOD = 'Message Body text, line 1'.

APPEND IT_MESS_BOD.

IT_MESS_BOD = 'Message Body text, line 2...'.

APPEND IT_MESS_BOD.

  • If no sender specified - default blank

  • IF P_SENDER EQ SPACE.

  • GD_SENDER_TYPE = SPACE.

  • ELSE.

  • GD_SENDER_TYPE = 'INT'.

  • ENDIF.

  • Send file by email as .xls speadsheet

PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT

TABLES IT_MESS_BOD

IT_MESS_ATT

USING P_EMAIL

P_EMAIL4

P_EMAIL5

'ebdit output'

'PDF'

GD_ATTACHMENT_NAME

GD_ATTACHMENT_DESC

  • P_SENDER

GD_SENDER_TYPE

CHANGING GD_ERROR

GD_RECIEVER.

ENDFORM. "send_email

----


  • FORM delete_spool *

----


FORM DELETE_SPOOL.

DATA: LD_SPOOL_NR TYPE TSP01_SP0R-RQID_CHAR.

LD_SPOOL_NR = GD_SPOOL_NR.

CHECK P_DELSPL <> C_NO.

CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'

EXPORTING

SPOOLID = LD_SPOOL_NR.

ENDFORM. "delete_spool

&----


*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


  • Send email

----


FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES IT_MESSAGE

IT_ATTACH

USING P_EMAIL

P_EMAIL4

P_EMAIL5

P_MTITLE

P_FORMAT

P_FILENAME

P_ATTDESCRIPTION

  • P_SENDER_ADDRESS

P_SENDER_ADDRES_TYPE

CHANGING P_ERROR

P_RECIEVER.

DATA: LD_ERROR TYPE SY-SUBRC,

LD_RECIEVER TYPE SY-SUBRC,

LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,

LD_EMAIL1 LIKE SOMLRECI1-RECEIVER,

LD_EMAIL2 LIKE SOMLRECI1-RECEIVER,

LD_EMAIL3 LIKE SOMLRECI1-RECEIVER,

LD_FORMAT TYPE SO_OBJ_TP ,

LD_ATTDESCRIPTION TYPE SO_OBJ_NAM ,

LD_ATTFILENAME TYPE SO_OBJ_DES ,

LD_SENDER_ADDRESS LIKE SOEXTRECI1-RECEIVER,

LD_SENDER_ADDRESS_TYPE LIKE SOEXTRECI1-ADR_TYP,

LD_RECEIVER LIKE SY-SUBRC.

DATA: T_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

T_CONTENTS LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

T_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

T_ATTACHMENT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

T_OBJECT_HEADER LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

W_CNT TYPE I,

W_SENT_ALL(1) TYPE C,

W_DOC_DATA LIKE SODOCCHGI1.

LD_EMAIL1 = P_EMAIL.

LD_EMAIL2 = P_EMAIL4.

LD_EMAIL3 = P_EMAIL5.

LD_MTITLE = P_MTITLE.

LD_FORMAT = P_FORMAT.

LD_ATTDESCRIPTION = P_ATTDESCRIPTION.

LD_ATTFILENAME = P_FILENAME.

  • LD_SENDER_ADDRESS = P_SENDER_ADDRESS.

LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE.

  • Fill the document data.

W_DOC_DATA-DOC_SIZE = 1.

  • Populate the subject/generic message attributes

W_DOC_DATA-OBJ_LANGU = SY-LANGU.

W_DOC_DATA-OBJ_NAME = 'SAPRPT'.

W_DOC_DATA-OBJ_DESCR = LD_MTITLE .

W_DOC_DATA-SENSITIVTY = 'F'.

  • Fill the document data and get size of attachment

CLEAR W_DOC_DATA.

READ TABLE IT_ATTACH INDEX W_CNT.

W_DOC_DATA-DOC_SIZE =

( W_CNT - 1 ) * 255 + STRLEN( IT_ATTACH ).

W_DOC_DATA-OBJ_LANGU = SY-LANGU.

W_DOC_DATA-OBJ_NAME = 'SAPRPT'.

W_DOC_DATA-OBJ_DESCR = LD_MTITLE.

W_DOC_DATA-SENSITIVTY = 'F'.

CLEAR T_ATTACHMENT.

REFRESH T_ATTACHMENT.

T_ATTACHMENT[] = IT_ATTACH[].

  • Describe the body of the message.

CLEAR T_PACKING_LIST.

REFRESH T_PACKING_LIST.

T_PACKING_LIST-TRANSF_BIN = SPACE.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 0.

T_PACKING_LIST-BODY_START = 1.

DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.

  • T_PACKING_LIST-DOC_TYPE = 'RAW'.

APPEND T_PACKING_LIST.

  • Create attachment notification

T_PACKING_LIST-TRANSF_BIN = 'X'.

T_PACKING_LIST-HEAD_START = 1.

T_PACKING_LIST-HEAD_NUM = 1.

T_PACKING_LIST-BODY_START = 1.

DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.

T_PACKING_LIST-DOC_TYPE = LD_FORMAT.

T_PACKING_LIST-OBJ_DESCR = LD_ATTDESCRIPTION.

T_PACKING_LIST-OBJ_NAME = LD_ATTFILENAME.

T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.

APPEND T_PACKING_LIST.

  • Add the recipients email address

CLEAR T_RECEIVERS.

REFRESH T_RECEIVERS.

T_RECEIVERS-RECEIVER = LD_EMAIL1.

T_RECEIVERS-REC_TYPE = 'U'.

T_RECEIVERS-COM_TYPE = 'INT'.

T_RECEIVERS-NOTIF_DEL = 'X'.

T_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND T_RECEIVERS.

CLEAR T_RECEIVERS.

  • REFRESH T_RECEIVERS.

T_RECEIVERS-RECEIVER = LD_EMAIL2.

T_RECEIVERS-REC_TYPE = 'U'.

T_RECEIVERS-COM_TYPE = 'INT'.

T_RECEIVERS-NOTIF_DEL = 'X'.

T_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND T_RECEIVERS.

CLEAR T_RECEIVERS.

  • REFRESH T_RECEIVERS.

T_RECEIVERS-RECEIVER = LD_EMAIL3.

T_RECEIVERS-REC_TYPE = 'U'.

T_RECEIVERS-COM_TYPE = 'INT'.

T_RECEIVERS-NOTIF_DEL = 'X'.

T_RECEIVERS-NOTIF_NDEL = 'X'.

APPEND T_RECEIVERS.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = W_DOC_DATA

PUT_IN_OUTBOX = 'X'

  • SENDER_ADDRESS = LD_SENDER_ADDRESS

SENDER_ADDRESS_TYPE = LD_SENDER_ADDRESS_TYPE

COMMIT_WORK = 'X'

IMPORTING

SENT_TO_ALL = W_SENT_ALL

TABLES

PACKING_LIST = T_PACKING_LIST

CONTENTS_BIN = T_ATTACHMENT

  • CONTENTS_TXT = IT_MESSAGE

RECEIVERS = T_RECEIVERS

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

DOCUMENT_TYPE_NOT_EXIST = 3

OPERATION_NO_AUTHORIZATION = 4

PARAMETER_ERROR = 5

X_ERROR = 6

ENQUEUE_ERROR = 7

OTHERS = 8.

  • Populate zerror return code

LD_ERROR = SY-SUBRC.

  • Populate zreceiver return code

LOOP AT T_RECEIVERS.

LD_RECEIVER = T_RECEIVERS-RETRN_CODE.

ENDLOOP.

ENDFORM. "send_file_as_email_attachment

&----


*& Form FCONVERT_SPOOL_TO_PDF

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM FCONVERT_SPOOL_TO_PDF .

SELECT *

FROM TSP01

WHERE RQOWNER EQ SY-UNAME

ORDER BY RQCRETIME ASCENDING.

ENDSELECT.

GD_SPOOL_NR = TSP01-RQIDENT.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = GD_SPOOL_NR

NO_DIALOG = C_NO

DST_DEVICE = C_DEVICE

IMPORTING

PDF_BYTECOUNT = GD_BYTECOUNT

TABLES

PDF = IT_PDF_OUTPUT

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.

FREE GD_BUFFER.

  • Transfer the 132-long strings to 255-long strings

LOOP AT IT_PDF_OUTPUT.

TRANSLATE IT_PDF_OUTPUT USING ' ~'.

CONCATENATE GD_BUFFER IT_PDF_OUTPUT INTO GD_BUFFER.

ENDLOOP.

TRANSLATE GD_BUFFER USING '~ '.

FREE IT_MESS_ATT.

DO.

IT_MESS_ATT = GD_BUFFER.

APPEND IT_MESS_ATT.

SHIFT GD_BUFFER LEFT BY 255 PLACES.

IF GD_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

*clear:

ENDFORM. " FCONVERT_SPOOL_TO_PDF