Précédent   Forum des professionnels en informatique > Logiciels > Solutions d'entreprise > ERP > SAP
SAP Forum d'entraide sur SAP et sur la programmation avec le langage ABAP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 20/08/2007, 18h05   #1
Invité de passage
 
Inscription : avril 2007
Messages : 3
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 3
Points : 0
Points : 0
Par défaut Problème MF SO_OBJECT_SEND

Bonjour, voila mon problème, j'ai créer un programme qui peut soit afficher le résultat dans un ALV, soit écrire dans un fichier UNIX sur le serveur, ce que je voudrais ca serait, qu'une fois que ce fichier est écrit, pouvoir l'envoyer à l'utilisateur via un mail, j'essaye d'utiliser ce MF : SO_OBJECT_SEND, mais je ne comprends pas du tout comment il marche, si quelqu'un avait un exemple simple ca m'aiderait beaucoup, merci.
Jimos est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/08/2007, 00h07   #2
Membre expérimenté

 
SAP for Banking
Inscription : juin 2002
Messages : 539
Détails du profil
Informations personnelles :
Âge : 35
Localisation : France, Paris (Île de France)

Informations professionnelles :
Activité : SAP for Banking
Secteur : Conseil

Informations forums :
Inscription : juin 2002
Messages : 539
Points : 566
Points : 566
Bonjour,
Regarde de ce cote : http://www.sapdevelopment.co.uk/repo.../emailhome.htm

L.
__________________
TRY.
N/A
CATCH cx_root.
ludovic.fernandez est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/09/2007, 08h33   #3
Membre à l'essai
 
Inscription : août 2006
Messages : 40
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 40
Points : 24
Points : 24
Bonjour,

Nous avons développé un module fonction pour utiliser plus simplement le module SO_OBJECT_SEND, avec uniquement une liste de destinataire, un contenu et un objet.

Bonne chance.
Frooty.

En voici les grandes lignes :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Paramètres d'import :
I_EMMETTEUR   LIKE SY-UNAME Emmetteur du message
I_PRIORITE    TYPE SO_OBJ_PRI Priorité du document - > 1(maxi) à 9(mini)
I_SENSIBILITE TYPE SO_OBJ_SNS Objet : sensibilité (privé, fonctionnel,...)
I_DECRIPTIF   TYPE SO_OBJ_DES Brève description du contenu
Tables :
T_DESTINATAIRE	LIKE	YGEN_STRU_DEST	Destinataires pour envoi mail
T_TEXTE	LIKE	SOLI	SAPoffice : Ligne de 255 caractères

Le type de la table YGEN_STRU_DEST :
TYPE	 	CHAR	1     Type de destinataire de mail
NOM_INT	 	CHAR	12    Nom du destinataire
ADR_EXT	 	LCHR	1244 Adresse externe directe comme destinataire
PERNR	 	NUMC	8     Matricule
EN_COPIE	CHAR	1     Envoi: En tant que copie
EN_COPIE_CACHEE	CHAR	1     Envoi : comme copie cachée
ACCUSE		CHAR	1     Accusé de réception requis
Source du module :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  data: lt_receiver like soos1 occurs 0 with header line,
        lt_texte    like soli  occurs 0 with header line.  

  data: ls_hd_change like sood1.

  data: ld_entries  like sy-tabix.

  data : lv_mail like adr6-smtp_addr,               
         lv_adrmail type so_dir_ext.                   

* Destinataires
  refresh lt_receiver[].
  loop at t_destinataire.

*   Selon le type de destinataire, on récupère ou on construit
*   l'adresse email de différentes façons
    clear : lv_mail, lv_adrmail.                        
    case t_destinataire-type.                        

*     On traduit le nom utilisateur SAP en adresse email pour Lotus
*     Notes
      when 'B'.       
        select single smtp_addr into lv_mail
          from adr6 inner join usr21
            on adr6~addrnumber = usr21~addrnumber
           and adr6~persnumber = usr21~persnumber
         where bname = t_destinataire-nom_int
           and flgdefault = 'X'
           and home_flag  = 'X'.

        lv_adrmail = lv_mail.
        lt_receiver-recesc    = 'U'.
        lt_receiver-recnam    = 'U-'.
        lt_receiver-recextnam = lv_adrmail.

*     On lit les données communication du collaborateur (matricule)
      when 'Z'.                                            
        select usrid_long into lv_mail from  pa0105 
          where  pernr  = t_destinataire-pernr       
          and    endda  ge sy-datum                   
          and    begda  le sy-datum                    
          and    usrty  = '0010'.                         
        endselect.                                          
        lv_adrmail = lv_mail.                             
        lt_receiver-recesc    = 'U'.                    
        lt_receiver-recnam    = 'U-'.                  
        lt_receiver-recextnam = lv_adrmail.        

*     Addresse externe complète -> pas de modif.
      when 'U'.                                     
        lt_receiver-recesc    = t_destinataire-type. 
        lt_receiver-recnam    = 'U-'.                      
        lt_receiver-recextnam = t_destinataire-adr_ext.

*     Liste de distribution générale SAP-Office
      when 'C'.
        lt_receiver-recesc    = t_destinataire-type..
        lt_receiver-recnam    = t_destinataire-nom_int.
        lt_receiver-adr_name  = t_destinataire-nom_int.
        lt_receiver-dlinam    = t_destinataire-nom_int.

      when others.
        lt_receiver-recesc    = t_destinataire-type.
        lt_receiver-recnam    = t_destinataire-nom_int.
        lt_receiver-recextnam = t_destinataire-adr_ext.
    endcase.                      

*   Priorité
    lt_receiver-sndpri    = i_priorite.
    lt_receiver-sndnam    = i_emmetteur.
    lt_receiver-sndbc     = t_destinataire-en_copie_cachee.
    lt_receiver-sndcp     = t_destinataire-en_copie.        
*   Message express
    lt_receiver-sndex   = 'X'.

*   Retransmission de l'objet impossible
    clear lt_receiver-forfb.                               
*   Impression de l'objet impossible
    clear lt_receiver-prifb.                               
*   Accusé de reception
    lt_receiver-deliver  = t_destinataire-accuse. 
    lt_receiver-read     = space.  " Confirmation de lecture requise
    clear: lt_receiver-acone.
    append lt_receiver.
  endloop.

* Entête de document
  clear ls_hd_change.
  ls_hd_change-objla  = sy-langu.
  ls_hd_change-objsrt = '1'.
  ls_hd_change-objnam = 'MAIL'.
  ls_hd_change-objpri = i_priorite.
  ls_hd_change-objsns = i_sensibilite.
  ls_hd_change-objdes = i_decriptif.
  ls_hd_change-ownnam = i_emmetteur.
  clear ls_hd_change-objcp.    " l'objet ne peut pas être modifié
  clear ls_hd_change-pctrl.    " le titre du doc. ne doit pas être mod.

* Si on se trouve dans un système test, on ajoute une information
* le précisant dans le contenu du mail
  free lt_texte[].
  if sy-sysid ne 'P01'.
    clear lt_texte.
    concatenate text-l02 sy-sysid into lt_texte-line separated by space.      
    append lt_texte.
    clear lt_texte-line.
    append lt_texte.
    loop at t_texte.
      lt_texte-line = t_texte-line.
      append lt_texte.
    endloop.
    free t_texte[].
    t_texte[] = lt_texte[].
  endif.

* Contenu du message
  describe table t_texte lines ld_entries.

  read table t_texte index ld_entries.

  ls_hd_change-objlen = ( ld_entries - 1 ) * 255 + strlen( t_texte ).

  call function 'SO_OBJECT_SEND'
    exporting
      object_hd_change                 = ls_hd_change
      object_type                      = 'RAW'              " CPK120506
      owner                            = i_emmetteur
    tables
      objcont                          = t_texte
      receivers                        = lt_receiver
    exceptions
      active_user_not_exist            = 1
      communication_failure            = 2
      component_not_available          = 3
      folder_not_exist                 = 4
      folder_no_authorization          = 5
      forwarder_not_exist              = 6
      note_not_exist                   = 7
      object_not_exist                 = 8
      object_not_sent                  = 9
      object_no_authorization          = 10
      object_type_not_exist            = 11
      operation_no_authorization       = 12
      owner_not_exist                  = 13
      parameter_error                  = 14
      substitute_not_active            = 15
      substitute_not_defined           = 16
      system_failure                   = 17
      too_much_receivers               = 18
      user_not_exist                   = 19
      originator_not_exist             = 20
      x_error                          = 21
      others                           = 22.

  case sy-subrc.
    when '0'.
    when '1'.
      raise active_user_not_exist.
    when '2'.
      raise communication_failure.
    when '3'.
      raise component_not_available.
    when '4'.
      raise folder_not_exist.
    when '5'.
      raise folder_no_authorization.
    when '6'.
      raise forwarder_not_exist.
    when '7'.
      raise note_not_exist.
    when '8'.
      raise object_not_exist.
    when '9'.
      raise object_not_sent.
    when '10'.
      raise object_no_authorization.
    when '11'.
      raise object_type_not_exist.
    when '12'.
      raise operation_no_authorization.
    when '13'.
      raise owner_not_exist.
    when '14'.
      raise parameter_error.
    when '15'.
      raise substitute_not_active.
    when '16'.
      raise substitute_not_defined.
    when '17'.
      raise system_failure.
    when '18'.
      raise too_much_receivers.
    when '19'.
      raise user_not_exist.
    when '20'.
      raise originator_not_exist.
    when '21'.
      raise x_error.
  endcase.

  commit work.
Frooty est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/09/2007, 16h26   #4
Invité de passage
 
Inscription : avril 2007
Messages : 3
Détails du profil
Informations forums :
Inscription : avril 2007
Messages : 3
Points : 0
Points : 0
Merci bien, et pour le fichier joint c'est impossible ?
Jimos est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/09/2007, 20h41   #5
Membre à l'essai
 
Inscription : août 2006
Messages : 40
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 40
Points : 24
Points : 24
C'est certainement possible, mais nous ne l'avons pas utilisé dans notre module
Je regarderais dès que j'aurais accès à un système SAP.

Si jamais, tu peux aussi envoyer un lien sur ton fichier directement dans le corps du mail, pour autant que le fichier créé soit sur un serveur auquel le destinataire du mail à accès. Tu code dans le texte du mail :

file:Chemin_complet_du_fichier

Ce lien apparaît en surbrillance dans le mail et permet au destinataire de l'ouvrir directement et de le sauvegarder où il veut par la suite.

@+
Frooty.
Frooty est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/09/2007, 16h16   #6
Membre du Club
 
Inscription : août 2005
Messages : 60
Détails du profil
Informations personnelles :
Âge : 41
Localisation : France, Nord (Nord Pas de Calais)

Informations forums :
Inscription : août 2005
Messages : 60
Points : 43
Points : 43
Envoyer un message via MSN à balawoo
Bonjour,

j'ai récupéré mais je ne sais plus d'ou ce bout de code qui permet d'envoyer un ordre spool en piece jointe dans un mail depuis SAP.

bon courage,

Philippe
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
*&---------------------------------------------------------------------*
*& Report  Z_SEND_SPOOL_MAIL                                           *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  z_send_spool_mail                       .
*----------------------------------------------------------------------*
PARAMETERS : p_spool TYPE tsp01-rqident OBLIGATORY .
PARAMETERS : p_mail  TYPE char100 OBLIGATORY .
PARAMETERS : p_mail1  TYPE char100  .
PARAMETERS : p_title TYPE char100.
*----------------------------------------------------------------------*
TYPES : ty_line TYPE string.

DATA: it_attachment TYPE soli OCCURS 0 WITH HEADER LINE.
DATA: it_attachment_long TYPE ty_line OCCURS 0 WITH HEADER LINE.
DATA: lv_pdf_size        TYPE i.
DATA: lt_pdf             TYPE STANDARD TABLE OF tline WITH HEADER LINE.

*---------------------------------------------------------------------*

PERFORM send_email USING p_spool p_mail p_mail1.

*---------------------------------------------------------------------*
*  FORM send_email
*---------------------------------------------------------------------*
*  -->  X_SPOOL_ID
*  -->  X_EMAIL
*---------------------------------------------------------------------*

FORM send_email USING x_spool_id x_email x_email1.

  DATA: lt_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,
        lt_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,
        lt_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,
        lt_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,
        lt_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE,
        lv_document_data TYPE sodocchgi1.

  DATA: l_att_lines TYPE i.

  DATA : lv_spool_desc(68) TYPE c.

  CHECK NOT ( x_email IS INITIAL ).

  CLEAR: lt_reclist, lt_reclist[],
  lt_objhead, lt_objhead[],
  lt_objtxt, lt_objtxt[],
  lt_objbin, lt_objbin[],
  lt_objpack, lt_objpack[].

  CLEAR lv_document_data.

* Read spool and get the pdf internal table and name of spool
  PERFORM read_spool USING x_spool_id lv_spool_desc.

  CHECK NOT ( lt_pdf[] IS INITIAL ).

* Convert pdf itab to 255 line itab.
  DATA :lv_counter  TYPE i.
  DATA :lv_from     TYPE i.

  LOOP AT lt_pdf.
    TRANSLATE  lt_pdf USING ' ~' .
    CONCATENATE it_attachment_long lt_pdf INTO it_attachment_long.
  ENDLOOP.
  TRANSLATE  it_attachment_long USING '~ ' .
  APPEND it_attachment_long.
  CLEAR : lv_counter.

  DO.
    lv_counter = STRLEN( it_attachment_long ).
    IF lv_counter GE 255.
      it_attachment = it_attachment_long(255).
      APPEND it_attachment.
      SHIFT it_attachment_long BY 255 PLACES.
    ELSE.
      it_attachment = it_attachment_long(lv_counter).
      APPEND it_attachment.
      EXIT.
    ENDIF.

  ENDDO.

* Body of email
  MOVE '<b>bonjour</b><br>' TO lt_objtxt.
  APPEND lt_objtxt.
  CLEAR lt_objtxt-line.
  APPEND lt_objtxt.

  MOVE 'Votre état' TO lt_objtxt.
  APPEND lt_objtxt.
  CLEAR lt_objtxt-line.
  APPEND lt_objtxt.

  MOVE 'l équipe SAP' TO lt_objtxt.

  APPEND lt_objtxt.

  lv_document_data-obj_name = 'SpoolMail'.

* Title of the email as spool name
  lv_document_data-obj_descr = lv_spool_desc.
  lv_document_data-sensitivty = 'O'.
  lv_document_data-expiry_dat = sy-datum + 15.
  lv_document_data-doc_size = STRLEN( lt_objtxt ).

* e-mail body
  CLEAR lt_objpack.
  lt_objpack-head_start = 1.
  lt_objpack-head_num = 0.
  lt_objpack-body_start = 1.
  lt_objpack-body_num = 10.
  lt_objpack-doc_type = 'HTML'.
  lt_objpack-doc_size = STRLEN( lt_objtxt ).
  APPEND lt_objpack.

* For e-mail attachment
  DESCRIBE TABLE it_attachment LINES l_att_lines.

  READ TABLE it_attachment INDEX l_att_lines.

  CLEAR lt_objpack.
  lt_objpack-transf_bin = 'X'.
  lt_objpack-head_start = 1.
  lt_objpack-head_num = 1.
  lt_objpack-body_start = 1.
  lt_objpack-body_num = l_att_lines.
  lt_objpack-doc_type = 'PDF'.
  lt_objpack-obj_name = 'email'.
  lt_objpack-obj_descr = lv_spool_desc.
  lt_objpack-doc_size = ( 255 * ( l_att_lines - 1 ) ) + STRLEN(
  it_attachment-line ).
  APPEND lt_objpack.

* make recipient list
  lt_reclist-receiver = x_email.
  lt_reclist-rec_type = 'U'. "To external email id

  APPEND lt_reclist.
  lt_reclist-receiver = x_email1.
  lt_reclist-rec_type = 'U'. "To external email id

  APPEND lt_reclist.

** send mail with attachment
*
*  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
*    EXPORTING
*      document_data              = LV_DOCUMENT_DATA
*      put_in_outbox              = ' '
*      commit_work                = 'X'
*    TABLES
*      packing_list               = LT_OBJPACK
*      object_header              = LT_OBJHEAD
*      contents_bin               = IT_ATTACHMENT
*      contents_txt               = LT_OBJTXT
*      receivers                  = LT_RECLIST
*    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.
* Send the e-mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = lv_document_data
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = lt_objpack
      contents_bin               = it_attachment
      contents_txt               = lt_objtxt
      receivers                  = lt_reclist
    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:/ 'Message sent'.
  ELSE.
    WRITE:/ 'Error encountered'.
  ENDIF.

ENDFORM. " send_email
*&---------------------------------------------------------------------*
*&      Form  read_spool
*&---------------------------------------------------------------------*

FORM read_spool USING x_spool_id y_spool_desc.

  DATA : lv_spool_type TYPE tsp01-rqdoctype,
         w_spool TYPE n.

  SELECT SINGLE rqdoctype rqtitle
           INTO (lv_spool_type, y_spool_desc)
           FROM tsp01
          WHERE rqident EQ x_spool_id.
*  IF Y_SPOOL_DESC IS INITIAL.
*    Y_SPOOL_DESC = 'Impression en provenance de SAP'.
*  ENDIF.

  y_spool_desc = p_title.
  IF lv_spool_type EQ 'LIST'.   " If spool is  a list

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
      EXPORTING
        src_spoolid                    = x_spool_id
*   NO_DIALOG                      =
*   DST_DEVICE                     =
*   PDF_DESTINATION                =
      IMPORTING
        pdf_bytecount                  = lv_pdf_size
*   PDF_SPOOLID                    =
*   LIST_PAGECOUNT                 =
*   BTC_JOBNAME                    =
*   BTC_JOBCOUNT                   =
      TABLES
        pdf                            = lt_pdf
     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
              .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  ELSE.            " If spool is OTF

    CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
      EXPORTING
        src_spoolid                    = x_spool_id
*   NO_DIALOG                      =
*   DST_DEVICE                     =
*   PDF_DESTINATION                =
     IMPORTING
       pdf_bytecount                  = lv_pdf_size
*   PDF_SPOOLID                    =
*   OTF_PAGECOUNT                  =
*   BTC_JOBNAME                    =
*   BTC_JOBCOUNT                   =
     TABLES
       pdf                            = lt_pdf
     EXCEPTIONS
       err_no_otf_spooljob            = 1
       err_no_spooljob                = 2
       err_no_permission              = 3
       err_conv_not_possible          = 4
       err_bad_dstdevice              = 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
              .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.

ENDFORM.                    " read_spool
balawoo est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 09h12.


 
 
 
 
Partenaires

Hébergement Web