cancel
Showing results for 
Search instead for 
Did you mean: 

Get file from unix as an email.

Former Member
0 Kudos

Hi ,

I am working with 46 C and anyone please help me how I can write code to get the file from Unix(dat file) as an email.

Thanks in advance,

Edited by: ramana peddu on Aug 28, 2008 1:47 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Here first you need to get your data & save it into an internal table then you need to send it to email.

1). To Internal Table.

OPEN DATASET p_input FOR INPUT FILTER 'dos2unix'

IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc <> 0.

MESSAGE e018 WITH text-004.

LEAVE LIST-PROCESSING.

ENDIF.

IF g_type = 'TXT'.

DO.

CLEAR: g_record.

READ DATASET p_input INTO g_record.

IF sy-subrc = 4.

CLOSE DATASET p_input.

IF sy-subrc <> 0.

MESSAGE e018 WITH text-005.

ENDIF.

EXIT.

ENDIF.

MOVE g_record TO wa_file.

APPEND wa_file TO tab_file.

CONDENSE wa_file-plant.

wa_mara-matnr = wa_file-material.

wa_mara-werks = wa_file-plant.

APPEND wa_mara TO tab_mara.

CLEAR: wa_file, wa_mara.

ENDDO.

ELSEIF g_type = 'CSV'.

DO.

CLEAR: g_record.

READ DATASET p_input INTO g_record.

IF sy-subrc = 4.

CLOSE DATASET p_input.

IF sy-subrc <> 0.

MESSAGE e018 WITH text-005.

ENDIF.

EXIT.

ENDIF.

  • MOVE g_record TO wa_file.

SPLIT g_record AT ',' INTO wa_file-snr

wa_file-splant

wa_file-material

wa_file-plant

wa_file-qty

wa_file-del_date.

APPEND wa_file TO tab_file.

CONDENSE wa_file-plant.

wa_mara-matnr = wa_file-material.

wa_mara-werks = wa_file-plant.

APPEND wa_mara TO tab_mara.

CLEAR: wa_file, wa_mara.

ENDDO.

ENDIF.

CLOSE DATASET p_input.

2). For email.

agin 3 steps

  • Populate message body text

perform populate_email_message_body.

*--Populate table with details to be entered in .XLS file

PERFORM BUILD_ATTACHMENT.

*--Send file by email as .xls spread sheet.

PERFORM send_file_as_email_attachment tables it_message

it_attach

using 'List of products Information'

'XLS'

'filename'

' '

' '

' '

changing gd_error

gd_reciever.

form populate_email_message_body .

REFRESH it_message.

it_message = 'List of products Information'.

APPEND it_message.

endform. " populate_email_message_body

form BUILD_ATTACHMENT .

class cl_abap_char_utilities definition load.

constants:

con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,

con_cret type c value cl_abap_char_utilities=>CR_LF.

CONCATENATE 'MATNR' 'MAKTX' 'WERKS' 'MANFC'

'LIFNR' 'PRDHA' 'MSTAE' 'MSTAV'

'BESKZ' 'SOBSL' 'DISMM' 'DISPO'

'MATKL'

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

LOOP AT TAB_OUT_MAIL INTO wa_OUT.

CONCATENATE wa_out-matnr wa_out-maktx wa_out-werks

wa_out-manfc wa_out-lifnr wa_out-prdha

wa_out-mstae wa_out-mstav wa_out-beskz

wa_out-sobsl wa_out-dismm wa_out-dispo

wa_out-matkl

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

clear wa_out.

ENDLOOP.

endform. " BUILD_ATTACHMENT

form send_file_as_email_attachment

tables pit_message

pit_attach

using

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_email 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.

  • ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

  • ld_attfilename = p_filename.

ld_attfilename = 'List of Products Information'.

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 = 'List of Products Information'.

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

CLEAR w_doc_data.

describe TABLE it_attach lines 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 = 'List of Products Information'.

w_doc_data-sensitivty = 'F'.

CLEAR t_attachment.

REFRESH t_attachment.

t_attachment[] = pit_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_descr = 'List of Products Information'.

t_packing_list-obj_name = 'List of Products Information'.

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 = wa_dri-email.

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'

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.

refresh: t_attachment,it_message,t_receivers,it_attach.

refresh: tab_out_mail.

clear: w_doc_data.

endform. " send_file_as_email_attachment

Go to transaction SOST there you will find your attacattachment select it and press the execute button you will get the mail in xls.

Thanks,

Phani.

Answers (2)

Answers (2)

Former Member
0 Kudos

UPLOAD_DATA_FROM_UNIX.

*&

tables : zppt_tran_001,zppt_tran_002.

data: xout type string.

data: iout type table of string.

field-symbols: <fs>.

data: begin of itab occurs 0,

rec(1000) type c,

end of itab.

data: p_file type localfile,

p_file1 type localfile.

data : v_dummy type string.

data: ifile type table of salfldir with header line.

data: sout type table of string with header line.

data : p_path type salfile-longname value '/touchscreen/download/'.

data : p_path1 type salfile-longname value '/touchscreen/archive/'.

data : s_file(10) type c value '*.txt'.

data : begin of I_FINAL occurs 0,

ZDOENTRY like ZPPT_TRAN_001-ZDOENTRY,

ZTENTRY like ZPPT_TRAN_001-ZTENTRY,

ZPRDDT like ZPPT_TRAN_001-zprddt,

ZZMACHINE like ZPPT_TRAN_001-ZZMACHINE,

MATNR like ZPPT_TRAN_001-MATNR,

WERKS like ZPPT_TRAN_001-WERKS,

VERID like ZPPT_TRAN_001-VERID,

zzdecision like zppt_tran_001-zzdecision,

ZZPOTTER like ZPPT_TRAN_001-ZZPOTTER,

ZZINSPECTOR like ZPPT_TRAN_001-ZZINSPECTOR,

ZZGLAZER like ZPPT_TRAN_001-ZZGLAZER,

ZZSORTER like ZPPT_TRAN_001-ZZSORTER,

ZZSTOPPER like ZPPT_TRAN_001-ZZSTOPPER,

ZKODE1 like ZPPT_TRAN_001-ZKODE1,

ZKODE2 like ZPPT_TRAN_001-ZKODE2,

ZKODE3 like ZPPT_TRAN_001-ZKODE3,

ZZPOSTED like ZPPT_TRAN_001-ZZPOSTED,

MBLNR like ZPPT_TRAN_001-MBLNR,

zzreason like zppt_tran_001-zzreason,

count type i,

end of I_FINAL.

data : wa_final like i_final.

start-of-selection.

call function 'RZL_READ_DIR_LOCAL'

exporting

name = p_path

tables

file_tbl = ifile

exceptions

argument_error = 1

not_found = 2

others = 3.

loop at ifile.

SEARCH ifile-name FOR '.txt'.

if sy-subrc = 0.

concatenate p_path ifile-name into p_file.

open dataset p_file for input in text mode encoding default.

if sy-subrc = 0.

do.

read dataset p_file into xout.

if sy-subrc <> 0.

exit.

endif.

SPLIT XOUT AT cl_abap_char_utilities=>horizontal_tab

INTO: wa_FINAL-ZDOENTRY wa_FINAL-ZTENTRY wa_FINAL-ZPRDDT

wa_FINAL-ZZMACHINE wa_FINAL-MATNR wa_FINAL-WERKS

wa_FINAL-VERID wa_FINAL-zzdecision wa_FINAL-ZZPOTTER

wa_FINAL-ZZINSPECTOR wa_FINAL-ZZGLAZER wa_FINAL-ZZSORTER

wa_FINAL-ZZSTOPPER wa_FINAL-ZKODE1 wa_FINAL-ZKODE2

wa_FINAL-ZKODE3 v_dummy.

append wa_final to i_final.

append xout to sout.

enddo.

endif.

close dataset p_file.

  • Copy to temp folder

concatenate p_path1 ifile-name into p_file1.

open dataset p_file1 for output in text mode encoding default.

loop at sout.

transfer sout to p_file1.

endloop.

close dataset p_file1.

DELETE DATASET p_file.

Former Member
0 Kudos

Hi Ramana,

Try to be clear with the question.

As per my understanding unix in SAP is nothing but the application server.

Use open dataset, read dataset into itab and close dataset.

Now u will have data in itab.

send it to mail by using the below FM

SO_NEW_DOCUMENT_ATT_SEND_API1

Regards,

Subbu