Application Development and Automation 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: 
Read only

file from application server

Former Member
0 Likes
1,074

Hi Guys,

I want to pick file from application server as an attachment and send as mail.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
966

Hi,

You can use this code.

&----


*& Report ZSD_EXCEL_INT_APP

*&

&----


*&

*&

&----


REPORT ZSD_EXCEL_INT_APP.

parameter: file_nm type localfile.

types : begin of it_tab1,

f1(20),

f2(40),

f3(20),

end of it_tab1.

data : it_tab type table of ALSMEX_TABLINE with header line,

file type rlgrap-filename.

data : it_tab2 type it_tab1 occurs 1,

wa_tab2 type it_tab1,

w_message(100) TYPE c.

at selection-screen on value-request for file_nm.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

u2022 PROGRAM_NAME = SYST-REPID

u2022 DYNPRO_NUMBER = SYST-DYNNR

u2022 FIELD_NAME = ' '

STATIC = 'X'

u2022 MASK = ' '

CHANGING

file_name = file_nm

EXCEPTIONS

MASK_TOO_LONG = 1

OTHERS = 2

.

IF sy-subrc 0.

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

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

ENDIF.

start-of-selection.

refresh it_tab2[].clear wa_tab2.

file = file_nm.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = file

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '10'

i_end_row = '35'

tables

intern = it_tab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 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.

loop at it_tab.

case it_tab-col.

when '002'.

wa_tab2-f1 = it_tab-value.

when '004'.

wa_tab2-f2 = it_tab-value.

when '008'.

wa_tab2-f3 = it_tab-value.

endcase.

at end of row.

append wa_tab2 to it_tab2.

clear wa_tab2.

endat.

endloop.

data : p_file TYPE rlgrap-filename value 'TEST3.txt'.

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

u2022

o

ï‚§

ï‚§ Display error messages if any.

IF sy-subrc NE 0.

MESSAGE e001(zsd_mes).

EXIT.

ELSE.

*---Data is downloaded to the application server file path

LOOP AT it_tab2 INTO wa_tab2.

TRANSFER wa_tab2 TO p_file.

ENDLOOP.

ENDIF.

*--Close the Application server file (Mandatory).

CLOSE DATASET p_file.

loop at it_tab2 into wa_tab2.

write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.

endloop.

Thanks

Sarada

9 REPLIES 9
Read only

Former Member
0 Likes
966

Why don't you search the forums for information or try it yuorself? This has been discussed lots of times before.

Read only

0 Likes
966

first try to understand my question than reply....

Thanks

Read only

0 Likes
966

I understand your question perfectly.

Why don't you try to understand how the search function on SDN works and then maybe help yourself a bit?

Read only

ThomasZloch
Active Contributor
0 Likes
966

Sounds interesting, please tell us how you did it in the end.

Thomas

Read only

Former Member
0 Likes
966

Hi,

Use OPEN_DATASET to fetch the file to internal table and use the FM SO_DOCUMENT_SEND_API1 to send mail with attachment.

Read only

Former Member
0 Likes
967

Hi,

You can use this code.

&----


*& Report ZSD_EXCEL_INT_APP

*&

&----


*&

*&

&----


REPORT ZSD_EXCEL_INT_APP.

parameter: file_nm type localfile.

types : begin of it_tab1,

f1(20),

f2(40),

f3(20),

end of it_tab1.

data : it_tab type table of ALSMEX_TABLINE with header line,

file type rlgrap-filename.

data : it_tab2 type it_tab1 occurs 1,

wa_tab2 type it_tab1,

w_message(100) TYPE c.

at selection-screen on value-request for file_nm.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

u2022 PROGRAM_NAME = SYST-REPID

u2022 DYNPRO_NUMBER = SYST-DYNNR

u2022 FIELD_NAME = ' '

STATIC = 'X'

u2022 MASK = ' '

CHANGING

file_name = file_nm

EXCEPTIONS

MASK_TOO_LONG = 1

OTHERS = 2

.

IF sy-subrc 0.

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

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

ENDIF.

start-of-selection.

refresh it_tab2[].clear wa_tab2.

file = file_nm.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = file

i_begin_col = '1'

i_begin_row = '1'

i_end_col = '10'

i_end_row = '35'

tables

intern = it_tab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 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.

loop at it_tab.

case it_tab-col.

when '002'.

wa_tab2-f1 = it_tab-value.

when '004'.

wa_tab2-f2 = it_tab-value.

when '008'.

wa_tab2-f3 = it_tab-value.

endcase.

at end of row.

append wa_tab2 to it_tab2.

clear wa_tab2.

endat.

endloop.

data : p_file TYPE rlgrap-filename value 'TEST3.txt'.

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

u2022

o

ï‚§

ï‚§ Display error messages if any.

IF sy-subrc NE 0.

MESSAGE e001(zsd_mes).

EXIT.

ELSE.

*---Data is downloaded to the application server file path

LOOP AT it_tab2 INTO wa_tab2.

TRANSFER wa_tab2 TO p_file.

ENDLOOP.

ENDIF.

*--Close the Application server file (Mandatory).

CLOSE DATASET p_file.

loop at it_tab2 into wa_tab2.

write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.

endloop.

Thanks

Sarada

Read only

JoffyJohn
Active Contributor
0 Likes
966

*This program will allowed you to send email with attachment.

  • First, specify the attachment file from your local hardisk and execute.

  • Next, specify the sender email address and click the send button.

*

report z_mail.

data method1 like sy-ucomm.

data g_user like soudnamei1.

data g_user_data like soudatai1.

data g_owner like soud-usrnam.

data g_receipients like soos1 occurs 0 with header line.

data g_document like sood4 .

data g_header like sood2.

data g_folmam like sofm2.

data g_objcnt like soli occurs 0 with header line.

data g_objhead like soli occurs 0 with header line.

data g_objpara like selc occurs 0 with header line.

data g_objparb like soop1 occurs 0 with header line.

data g_attachments like sood5 occurs 0 with header line.

data g_references like soxrl occurs 0 with header line.

data g_authority like sofa-usracc.

data g_ref_document like sood4.

data g_new_parent like soodk.

data: begin of g_files occurs 10 ,

text(4096) type c,

end of g_files.

data : fold_number(12) type c,

fold_yr(2) type c,

fold_type(3) type c.

parameters ws_file(4096) type c default 'c:\debugger.txt'.

  • Can me any file fromyour pc ....either xls or word or ppt etc ...

g_user-sapname = sy-uname.

call function 'SO_USER_READ_API1'

exporting

user = g_user

  • PREPARE_FOR_FOLDER_ACCESS = ' '

importing

user_data = g_user_data

  • EXCEPTIONS

  • USER_NOT_EXIST = 1

  • PARAMETER_ERROR = 2

  • X_ERROR = 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.

fold_type = g_user_data-outboxfol+0(3).

fold_yr = g_user_data-outboxfol+3(2).

fold_number = g_user_data-outboxfol+5(12).

clear g_files.

refresh : g_objcnt,

g_objhead,

g_objpara,

g_objparb,

g_receipients,

g_attachments,

g_references,

g_files.

method1 = 'SAVE'.

g_document-foltp = fold_type.

g_document-folyr = fold_yr.

g_document-folno = fold_number.

g_document-objtp = g_user_data-object_typ.

*g_document-OBJYR = '27'.

*g_document-OBJNO = '000000002365'.

*g_document-OBJNAM = 'MESSAGE'.

g_document-objdes = 'sap-img.com testing by program'.

g_document-folrg = 'O'.

*g_document-okcode = 'CHNG'.

g_document-objlen = '0'.

g_document-file_ext = 'TXT'.

g_header-objdes = 'sap-img.com testing by program'.

g_header-file_ext = 'TXT'.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = sy-uname

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

  • FOLMEM_DATA =

  • RECEIVE_DATA =

.

  • File from the pc to send...

method1 = 'ATTCREATEFROMPC'.

g_files-text = ws_file.

append g_files.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header

.

method1 = 'SEND'.

g_receipients-recnam = 'MK085'.

g_receipients-recesc = 'B'.

g_receipients-sndex = 'X'.

append g_receipients.

call function 'SO_DOCUMENT_REPOSITORY_MANAGER'

exporting

method = method1

office_user = g_owner

ref_document = g_ref_document

new_parent = g_new_parent

importing

authority = g_authority

tables

objcont = g_objcnt

objhead = g_objhead

objpara = g_objpara

objparb = g_objparb

recipients = g_receipients

attachments = g_attachments

references = g_references

files = g_files

changing

document = g_document

header_data = g_header.

*-- End of Program

Read only

JoffyJohn
Active Contributor
0 Likes
966

check this link also

[http://www.abapcode.info/2007/05/convert-spool-request-to-pdf-and-send.html|http://www.abapcode.info/2007/05/convert-spool-request-to-pdf-and-send.html]

Read only

Former Member
0 Likes
966

Hi,

Goto AL11, Select the required file ,then u can see data in the file,then goto the LIST>SAVE/SEND>Then u'l into the another screen " Create document & send "(In attachemnts u can see o/p file) in the recipient column give the mail id & in Reci type specify 'EXTERNAL SCREEN'. Then click on the send.

The mail id which u wann to send is dependent on the version, if it is ecc 6.0 u hav to maintain the mail id in the su01 or u r s/m is ECC 5 no need.

Reagrds,

Narasimhulu P