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: 

How to send report output from SUBMIT statement

piyush_mathur
Active Participant
0 Kudos
1,719

Hi,

I need to develop one report whcih can be use to send any report output in mail as attachment in txt of execl format. So i will be using SUBMIT statement to execute the report in my new report and i need to convert the reportout in txt or excel format and need to send as attachment in mail. This new report can be use to execute any report which may have ALV GRid, Normal outout screen. So what could be the best way to develop this kind of report.

Br,

Piyush

13 REPLIES 13

0 Kudos
452

Hi ,

Please go through this link.

http://wiki.sdn.sap.com/wiki/display/ABAP/SendExternalMailwithattachment

0 Kudos
452

Thanks Suresh But i need to first filter output which i will get from SUBMIT statement and then i need to prepare file to send as attachment.

0 Kudos
452

Hello Piyush,

These are the steps you need to follow:

1. SUBMIT the report with the addition EXPORTING LIST TO MEMORY addition.

2. Call the FM 'LIST_FROM_MEMORY' to get the list object exported in Step1.

3. Call the FM 'LIST_TO_ASCI' to convert the listobject from Step2 into ASCII format.

Use the internal table from Step3 to send the mail. Hope i'm clear.

BR,

Suhas

0 Kudos
452

Hi Suhas,

LIST_TO_ASCI will give me data in lines. and its difficult to separate the columns in another internal table for attachment file. As this report is going to use to send any report output so i can not fixed the delimiter. So i am looking some function which can split the data in columns when I am reading from List.

Br,

Piyush

0 Kudos
452

>

> Hi Suhas,

>

> LIST_TO_ASCI will give me data in lines. and its difficult to separate the columns in another internal table for attachment file. As this report is going to use to send any report output so i can not fixed the delimiter. So i am looking some function which can split the data in columns when I am reading from List.

> Br,

> Piyush

No need to seperate nothing additionally, this will come automatically in the attached file. Draft below


DATA list_tab TYPE TABLE OF abaplist.

SUBMIT your_report EXPORTING LIST TO MEMORY
              AND RETURN.

CALL FUNCTION 'LIST_FROM_MEMORY'
  TABLES
    listobject = list_tab
  EXCEPTIONS
    not_found  = 1
    OTHERS     = 2.

DATA string_tab TYPE list_string_table.
"use table type appropriate for attchement
DATA ascii_tab TYPE soli_tab.

CALL FUNCTION 'LIST_TO_ASCI'
 TABLES
   listasci                 = ascii_tab
   listobject               = list_tab.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
    filename = 'C:\test.txt'
    filetype = 'ASC'
  TABLES
    data_tab = ascii_tab.

DATA go_email_doc TYPE REF TO cl_document_bcs.

go_email_doc = cl_document_bcs=>create_document(
                                      i_type = 'TXT'
                                      ... ).

go_email_doc->add_attachment( i_attachment_type = 'TXT'
                              i_attachment_subject = 'My Attachment'
                              i_att_content_text = ascii_tab ).

Regards

Marcin

0 Kudos
452

Hi Marcin,

Its having the same problem. Is there any way to get all the data separated in columns i.e. in txt or excel. I will be runnig normally ALV reports in backgroud.

Br,

Piyush

Former Member
0 Kudos
452

Hi Piyush,

The below code snippet will give you the data of the called program using SUBMIT.

This will also display the data in a separate window.

After that you can add the logic of sendinf the data as mail.

In the below code, you will get the data in the internal table LIST_TAB.

DATA list_tab TYPE TABLE OF abaplist.

SUBMIT <YOURPROGRAM> EXPORTING LIST TO MEMORY
              AND RETURN.

CALL FUNCTION 'LIST_FROM_MEMORY'
  TABLES
    listobject = list_tab
  EXCEPTIONS
    not_found  = 1
    OTHERS     = 2.

CALL FUNCTION 'DISPLAY_LIST'
  TABLES
    listobject                  = list_tab.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Here add the code for sending as mail

For sending as EMAIL you can use the function module

SO_DOCUMENT_SEND_API1

Regards

HM

Former Member
0 Kudos
452

I would suggest to create a Spool of submitted report (Use PRINT NEW-PAGE...). Convert Spool to PDF and send PDF as attachment. It will be difficult to segregate data in structured column format from list / ALV particularly if Structure is not known.

Regards,

Mohaiyuddin

0 Kudos
452

Hi,

But my requirement to get the data in excel or txt format for further processing.

Br,

Piyush

0 Kudos
452

I don't think there is a way to cast the unstructured data in columnar format without knowing it's structure.

Regards,

Mohaiyuddin

piyush_mathur
Active Participant
0 Kudos
452

solved

0 Kudos
452

hey Piyush,

I am also using the submit statement with EXPORTING LIST TO MEMORY AND RETURN.

How did u divide the data which we get into sting format after CALL FUNCTION 'LIST_TO_ASCII' into an internal table whose structure i know ?

Thanks

Solanki Ritesh

Former Member
0 Kudos
452

Hi Piyush,

I have a same requirement . Can you please tell how did you do to filter the data and manage to accept any report in the selection screen.

Your inputs are much appreciated.

Thanks,

Nikhil.