Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Converting SPool information into HTML Format

Former Member
0 Kudos
810

Hi Friends,

How to Converting SPool information into HTML Format

and send this HTML INFORMATION INTO MAIL..

can anyone send program for this issue pls.

it is an urgent issue

regards,

7 REPLIES 7

former_member194669
Active Contributor
0 Kudos
224

Hi,

1) Read spool data into text file


CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'
EXPORTING
rqident = v_rqident "Spool Number
TABLES
buffer = i_spool "Internal table output

2). then call function module


  call function 'WWW_HTML_FROM_LISTOBJECT'
    exporting
      template_name = 'WEBREPORTING_REPORT'
    tables
      html          = report_html
      listobject    = report_list. "<< Pass i_spool internal table

you will get report_html internal table . this you need to pass Email send function module

0 Kudos
224

Hi Freinds,

i am generating below code.. but its giviing Runtime Error..

when passing report_html paramter into FM SO_NEW_DOCUMENT_ATT_SEND_API1'.

PLS. SEE BELOW CODE..

DATA IT_MAIL LIKE TSP01 OCCURS 0 WITH HEADER LINE.

data report_html like W3HTML OCCURS 0 WITH HEADER LINE.

DATA: G_ICONS(32) OCCURS 10 WITH HEADER LINE.

DATA LISTOBJECT LIKE ABAPLIST OCCURS 0 WITH HEADER LINE.

DATA sent_to_all like sonv-flag.

data : RECEIVER(30),

  • spoolid type tsp01-rqident,

it_buffer like SOLI occurs 10 with header line.

----


  • TABLE DECLARATIONS *

----


TABLES : TSP01.

----


  • INTERNAL TABLE DECLARATIONS

----


*data : begin of it_mail OCCURS 0,

  • RQIDENT like tsp01-RQIDENT,

  • end of it_mail.

*DATA IT_MAIL LIKE TSP01 OCCURS 0 WITH HEADER LINE.

----


  • SELECTION-SCREEN *

----


SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECTION-SCREEN: SKIP.

PARAMETERS : RQ2NAME LIKE TSP01-RQ2NAME .

  • RQIDENT like TSP01-RQIDENT.

SELECT-OPTIONS : S_RECVR FOR RECEIVER NO INTERVALS.

SELECTION-SCREEN: SKIP.

SELECTION-SCREEN: END OF BLOCK B1.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

  • PERFORM SEND_TO_SPOOL.

PERFORM GET_SPOOL_ID.

loop at it_mail.

PERFORM CONVERT_SPOOL_TO_PDF.

PERFORM SEND_MAIL.

endloop.

&----


*& Form GET_SPOOL_ID

&----


  • Getting the Latest Spool Request Number

----


FORM GET_SPOOL_ID.

SELECT *

FROM TSP01 INTO TABLE IT_MAIL

  • and RQIDENT = RQIDENT.

WHERE RQ2NAME = RQ2NAME .

ENDFORM. " GET_SPOOL_ID

&----


*& Form CONVERT_SPOOL_TO_PDF

&----


  • Converting the Spool to PDF Document

----


FORM CONVERT_SPOOL_TO_PDF.

*--Assigning the Spool number

WRITE 😕 IT_MAIL-RQIDENT.

spoolid = IT_MAIL-RQIDENT.

*--Converting the Spool to PDF

CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'

EXPORTING

RQIDENT = spoolid

  • FIRST_LINE = 1

  • LAST_LINE =

TABLES

BUFFER = it_buffer

  • EXCEPTIONS

  • NO_SUCH_JOB = 1

  • NOT_ABAP_LIST = 2

  • JOB_CONTAINS_NO_DATA = 3

  • SELECTION_EMPTY = 4

  • NO_PERMISSION = 5

  • CAN_NOT_ACCESS = 6

  • READ_ERROR = 7

  • OTHERS = 8

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

LISTOBJECT = IT_BUFFER.

CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'

EXPORTING

  • REPORT_NAME =

TEMPLATE_NAME = 'WEBREPORTING_REPORT'

TABLES

HTML = report_html

LISTOBJECT = LISTOBJECT

LISTICONS = G_ICONS.

ENDFORM. " CONVERT_SPOOL_TO_PDF

FORM SEND_MAIL.

regards,

LOOP AT S_RECVR.

reclist-receiver = S_RECVR-LOW.

reclist-rec_type = 'U'.

append reclist.

ENDLOOP.

*--Send the document by calling the SAPoffice API1 module for sending

*--documents with attachments

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = doc_chng

importing

sent_to_all = sent_to_all

tables

packing_list = report_html "objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

receivers = reclist

exceptions

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

others = 99.

case sy-subrc.

when 0.

write:/ 'Mail sent successfully'.

when 2.

WRITE:/ 'Error Generated while sending the mail'.

when 4.

WRITE:/ 'You Do not have authorization to send mail'.

when 99.

WRITE:/ 'Unknown Error'.

endcase.

ENDFORM. " SEND_MAIL

regards,

Former Member
0 Kudos
224

Hi,

Check this link in Wiki.

https://wiki.sdn.sap.com/wiki/display/Snippets/ABAP-Sendthespooldatatoanemail+address.

Thanks

Naren

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
224

Here is a very simple example of a program which produces a list output, converts it to HTML and emails it, all in one shot.



report zrich_0003 .

data: list type table of  abaplist with header line.
data: htmllines type table of w3html with header line.

data: maildata   like sodocchgi1.
data: mailtxt    like solisti1 occurs 10 with header line.
data: mailrec    like somlrec90 occurs 0  with header line.

start-of-selection.

* Produce a list
  do 100 times.
    write:/ sy-index, at 30 sy-index, at 50 sy-index.
  enddo.

* Save the list
  call function 'SAVE_LIST'
       tables
            listobject         = list
       exceptions
            list_index_invalid = 1
            others             = 2.

* Convert the list
  call function 'WWW_LIST_TO_HTML'
       tables
            html = htmllines.

* Send mail
  maildata-obj_name = 'TEST'.
  maildata-obj_descr = 'Test Subject'.

  loop at htmllines.
    mailtxt = htmllines.
    append mailtxt.
  endloop.

  mailrec-receiver = 'you@yourcompany.com'.
  mailrec-rec_type  = 'U'.
  append mailrec.

  call function 'SO_NEW_DOCUMENT_SEND_API1'
       exporting
            document_data              = maildata
            document_type              = 'HTM'
            put_in_outbox              = 'X'
       tables
            object_header              = mailtxt
            object_content             = mailtxt
            receivers                  = mailrec
       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.
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.


Regards,

Rich Heilman

0 Kudos
224

Hi Rich,

thanks for ur reply...

but i want to Send a perticular SPOOL INFORAMTION INTO HTML and ..SEND THIS HTML INFORMATION INTO A PERTICULAR PERSON MAIL..

pls. can you send me ASAP.. it is very urgent.

best regards,

venu

0 Kudos
224

I think you can use a combination of example code in this thread to come up with your solution, it appears that aRs has some code there that you could use to get the contents of the spool and convert it to HTML, you can simply plug that code into my example, and that should be it right?

Regards,

Rich Heilman

0 Kudos
224

Hi Rich,

once again thanks for your kindly reply.

but i am developing below Code.. that HTMAL AATCHMENTS ARE NOT COMING IN MAIL.

PLS can you you verify the below code.

*

*

----


  • DATA DECLARATIONS *

----


DATA: I_LIST LIKE ABAPLIST OCCURS 0 WITH HEADER LINE,

VARIANT LIKE RSVAR-VARIANT,

DOC_CHNG LIKE SODOCCHGI1,

RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE,

data: spoolid type tsp01-rqident.

DATA IT_MAIL LIKE TSP01 OCCURS 0 WITH HEADER LINE.

data report_html like W3HTML OCCURS 0 WITH HEADER LINE.

DATA: G_ICONS(32) OCCURS 10 WITH HEADER LINE.

DATA LISTOBJECT LIKE ABAPLIST OCCURS 0 WITH HEADER LINE.

DATA sent_to_all like sonv-flag.

data : RECEIVER(30),

  • spoolid type tsp01-rqident,

it_buffer like SOLI occurs 10 with header line.

data: list type table of abaplist with header line.

data: htmllines type table of w3html with header line.

data: maildata like sodocchgi1.

data: mailtxt like solisti1 occurs 10 with header line.

data: mailrec like somlrec90 occurs 0 with header line.

----


  • TABLE DECLARATIONS *

----


TABLES : TSP01.

----


  • SELECTION-SCREEN *

----


SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECTION-SCREEN: SKIP.

PARAMETERS : RQ2NAME LIKE TSP01-RQ2NAME .

  • RQIDENT like TSP01-RQIDENT.

SELECT-OPTIONS : S_RECVR FOR RECEIVER NO INTERVALS.

SELECTION-SCREEN: SKIP.

SELECTION-SCREEN: END OF BLOCK B1.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

  • PERFORM SEND_TO_SPOOL.

PERFORM GET_SPOOL_ID.

loop at it_mail.

PERFORM CONVERT_SPOOL_TO_PDF.

PERFORM SEND_MAIL.

endloop.

  • Save the list

call function 'SAVE_LIST'

tables

listobject = list

exceptions

list_index_invalid = 1

others = 2.

&----


*& Form GET_SPOOL_ID

&----


  • Getting the Latest Spool Request Number

----


FORM GET_SPOOL_ID.

SELECT *

FROM TSP01 INTO TABLE IT_MAIL

  • and RQIDENT = RQIDENT.

WHERE RQ2NAME = RQ2NAME .

ENDFORM. " GET_SPOOL_ID

&----


*& Form CONVERT_SPOOL_TO_PDF

&----


  • Converting the Spool to PDF Document

----


FORM CONVERT_SPOOL_TO_PDF.

*--Assigning the Spool number

WRITE 😕 IT_MAIL-RQIDENT.

spoolid = IT_MAIL-RQIDENT.

*--Converting the Spool to PDF

CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'

EXPORTING

RQIDENT = spoolid

  • FIRST_LINE = 1

  • LAST_LINE =

TABLES

BUFFER = it_buffer

  • EXCEPTIONS

  • NO_SUCH_JOB = 1

  • NOT_ABAP_LIST = 2

  • JOB_CONTAINS_NO_DATA = 3

  • SELECTION_EMPTY = 4

  • NO_PERMISSION = 5

  • CAN_NOT_ACCESS = 6

  • READ_ERROR = 7

  • OTHERS = 8

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

LISTOBJECT = IT_BUFFER.

CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'

EXPORTING

  • REPORT_NAME =

TEMPLATE_NAME = 'WEBREPORTING_REPORT'

TABLES

HTML = report_html

LISTOBJECT = LISTOBJECT

LISTICONS = G_ICONS.

ENDFORM. " CONVERT_SPOOL_TO_PDF

FORM SEND_MAIL.

call function 'WWW_LIST_TO_HTML'

tables

html = htmllines.

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test Subject'.

loop at htmllines.

mailtxt = htmllines.

append mailtxt.

endloop.

LOOP AT S_RECVR.

reclist-receiver = S_RECVR-LOW.

reclist-rec_type = 'U'.

append reclist.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'HTM'

put_in_outbox = 'X'

tables

object_header = report_html "mailtxt

object_content = mailtxt

receivers = reclist "mailrec

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.

if sy-subrc = 0.

write 'mail sent'.

endif.

ENDLOOP.

regards,

venu.