2007 Apr 12 8:36 AM
Hi,
I'm using this FM (SO_NEW_DOCUMENT_ATT_SEND_API1) for sending an attchment to SAP¨Inbox. My problem is when I'm giving 'TXT' as output format the alignment in the txt file is haphazard and I'm not able to figure out why the alignment is in such a way??? Kindly let me know your feedback on this issue. Have I missed anything in the code??I'm giving my code below:
DATA : gs_docdata TYPE sodocchgi1, "Document Data
gt_conbin LIKE solisti1 occurs 10 with header line, "Contents Bin
gs_mailrec type somlrec90, " Receiver
gt_mailrec TYPE TABLE OF somlrec90, " Receiver
gs_packlist type sopcklsti1, " Paking List
gt_contxt LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE, "Contents Text
gt_packlist type table of sopcklsti1, "Packing List
gt_objhead like solisti1 occurs 1 with header line. "Object Header
TYPES: BEGIN OF g_ty_data,
matnr TYPE mch1-matnr, "Material
charg type mch1-charg, "Batch
vfdat TYPE mch1-vfdat, "Shelf Life Expiry Date
END OF g_ty_data.
DATA: gt_data TYPE TABLE OF g_ty_data,
gs_data TYPE g_ty_data.
DATA: g_date TYPE i,
g_tab_lin type sy-tabix,
g_dat(10) type C,
g_mail_subject type sopcklsti1-obj_descr,
g_mail_language type sopcklsti1-obj_langu.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER p_werks TYPE mcha-werks OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
perform data_selection.
perform calculation.
perform update_mail_data.
perform send_mail.
*&----
*
*& Form data_selection
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form data_selection .
SELECT amatnr bcharg b~vfdat
FROM mcha AS a INNER JOIN mch1 AS b
ON amatnr = bmatnr AND
acharg = bcharg
INTO TABLE gt_data
WHERE a~werks = p_werks.
endform. " data_selection
*&----
*
*& Form calculation
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form calculation .
concatenate 'Materialnumber' ' Batch' 'Expiry Date' into gt_conbin-line separated by space.
append gt_conbin.
Appending the Data in Contents Bin
LOOP AT gt_data INTO gs_data.
IF sy-datum > gs_data-vfdat.
IF gs_data-vfdat IS NOT INITIAL.
g_date = gs_data-vfdat - sy-datum.
IF g_date LE 60.
clear g_dat.
g_dat = gs_data-vfdat.
g_dat0(2) = gs_data-vfdat6(2).
g_dat+2(1) = '.'.
g_dat3(2) = gs_data-vfdat4(2).
g_dat+5(1) = '.'.
g_dat6(4) = gs_data-vfdat0(4).
concatenate gs_data-matnr gs_data-charg g_dat into gt_conbin-line separated by space.
APPEND gt_conbin.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
endform. " calculation
*&----
*
*& Form update_mail_data
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form update_mail_data .
**Subject of the mail
gs_docdata-obj_name = 'Send Attachment'.
gs_docdata-obj_descr = 'Material List'.
gs_docdata-obj_langu = sy-langu.
Object Header
gt_objhead = 'Materials'.
append gt_objhead.
Body of the mail
gt_contxt = 'The List of Materials that are to be expired in the next 60 Days'.
append gt_contxt.
describe table gt_contxt lines g_tab_lin.
read table gt_contxt index g_tab_lin.
gs_docdata-doc_size = ( g_tab_lin - 1 ) * 255 + STRLEN( gt_contxt ).
Creating the entry for the compressed document
CLEAR gs_packlist-TRANSF_BIN.
gs_packlist-head_start = 1.
gs_packlist-head_num = 0.
gs_packlist-body_start = 1.
gs_packlist-body_num = g_tab_lin.
gs_packlist-doc_type = 'RAW'.
append gs_packlist to gt_packlist.
describe table gt_conbin lines g_tab_lin.
Creating the document attachment
gs_packlist-DOC_SIZE = G_TAB_LIN * 255.
gs_packlist-TRANSF_BIN = 'X'.
gs_packlist-HEAD_START = 1.
gs_packlist-HEAD_NUM = 1.
gs_packlist-BODY_START = 1.
gs_packlist-BODY_NUM = g_TAB_LIN.
gs_packlist-DOC_TYPE = 'TXT'.
gs_packlist-OBJ_NAME = 'MATERIAL LIST'.
gs_packlist-OBJ_DESCR = 'MATERIALS.TXT'.
gs_packlist-obj_langu = 'EN'.
APPEND gs_packlist to gt_packlist.
Creation Of Receiver List
*clear gt_mailrec.
*gs_mailrec-receiver = '[email protected]'.
*gs_mailrec-express = 'X'.
*gs_mailrec-rec_type = 'U'.
*append gs_mailrec to gt_mailrec.
gs_mailrec-receiver = 'FRSURC12'.
gs_mailrec-express = 'X'.
gs_mailrec-rec_type = 'B'.
append gs_mailrec to gt_mailrec.
endform. " update_mail_data
*&----
*
*& Form send_mail
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form send_mail .
Sending the Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gs_docdata
put_in_outbox = 'X'
COMMIT_WORK = 'X'
TABLES
packing_list = gt_packlist
object_header = gt_objhead
CONTENTS_BIN = gt_conbin
CONTENTS_TXT = gt_contxt
receivers = gt_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.
ELSE.
Write:/1 'The Mail is successfully sent to the SAP Inbox'.
ENDIF.
endform. " send_mail
Thanks & Regards,
Ramky.G
Hi,
I'm using this FM (SO_NEW_DOCUMENT_ATT_SEND_API1) for sending an attchment to SAP¨Inbox. My problem is when I'm giving 'TXT' as output format the alignment in the txt file is haphazard and I'm not able to figure out why the alignment is in such a way??? Kindly let me know your feedback on this issue. Have I missed anything in the code??I'm giving my code below:
DATA : gs_docdata TYPE sodocchgi1, "Document Data
gt_conbin LIKE solisti1 occurs 10 with header line, "Contents Bin
gs_mailrec type somlrec90, " Receiver
gt_mailrec TYPE TABLE OF somlrec90, " Receiver
gs_packlist type sopcklsti1, " Paking List
gt_contxt LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE, "Contents Text
gt_packlist type table of sopcklsti1, "Packing List
gt_objhead like solisti1 occurs 1 with header line. "Object Header
TYPES: BEGIN OF g_ty_data,
matnr TYPE mch1-matnr, "Material
charg type mch1-charg, "Batch
vfdat TYPE mch1-vfdat, "Shelf Life Expiry Date
END OF g_ty_data.
DATA: gt_data TYPE TABLE OF g_ty_data,
gs_data TYPE g_ty_data.
DATA: g_date TYPE i,
g_tab_lin type sy-tabix,
g_dat(10) type C,
g_mail_subject type sopcklsti1-obj_descr,
g_mail_language type sopcklsti1-obj_langu.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER p_werks TYPE mcha-werks OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
perform data_selection.
perform calculation.
perform update_mail_data.
perform send_mail.
*&----
*
*& Form data_selection
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form data_selection .
SELECT amatnr bcharg b~vfdat
FROM mcha AS a INNER JOIN mch1 AS b
ON amatnr = bmatnr AND
acharg = bcharg
INTO TABLE gt_data
WHERE a~werks = p_werks.
endform. " data_selection
*&----
*
*& Form calculation
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form calculation .
concatenate 'Materialnumber' ' Batch' 'Expiry Date' into gt_conbin-line separated by space.
append gt_conbin.
Appending the Data in Contents Bin
LOOP AT gt_data INTO gs_data.
IF sy-datum > gs_data-vfdat.
IF gs_data-vfdat IS NOT INITIAL.
g_date = gs_data-vfdat - sy-datum.
IF g_date LE 60.
clear g_dat.
g_dat = gs_data-vfdat.
g_dat0(2) = gs_data-vfdat6(2).
g_dat+2(1) = '.'.
g_dat3(2) = gs_data-vfdat4(2).
g_dat+5(1) = '.'.
g_dat6(4) = gs_data-vfdat0(4).
concatenate gs_data-matnr gs_data-charg g_dat into gt_conbin-line separated by space.
APPEND gt_conbin.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
endform. " calculation
*&----
*
*& Form update_mail_data
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form update_mail_data .
**Subject of the mail
gs_docdata-obj_name = 'Send Attachment'.
gs_docdata-obj_descr = 'Material List'.
gs_docdata-obj_langu = sy-langu.
Object Header
gt_objhead = 'Materials'.
append gt_objhead.
Body of the mail
gt_contxt = 'The List of Materials that are to be expired in the next 60 Days'.
append gt_contxt.
describe table gt_contxt lines g_tab_lin.
read table gt_contxt index g_tab_lin.
gs_docdata-doc_size = ( g_tab_lin - 1 ) * 255 + STRLEN( gt_contxt ).
Creating the entry for the compressed document
CLEAR gs_packlist-TRANSF_BIN.
gs_packlist-head_start = 1.
gs_packlist-head_num = 0.
gs_packlist-body_start = 1.
gs_packlist-body_num = g_tab_lin.
gs_packlist-doc_type = 'RAW'.
append gs_packlist to gt_packlist.
describe table gt_conbin lines g_tab_lin.
Creating the document attachment
gs_packlist-DOC_SIZE = G_TAB_LIN * 255.
gs_packlist-TRANSF_BIN = 'X'.
gs_packlist-HEAD_START = 1.
gs_packlist-HEAD_NUM = 1.
gs_packlist-BODY_START = 1.
gs_packlist-BODY_NUM = g_TAB_LIN.
gs_packlist-DOC_TYPE = 'TXT'.
gs_packlist-OBJ_NAME = 'MATERIAL LIST'.
gs_packlist-OBJ_DESCR = 'MATERIALS.TXT'.
gs_packlist-obj_langu = 'EN'.
APPEND gs_packlist to gt_packlist.
Creation Of Receiver List
*clear gt_mailrec.
*gs_mailrec-receiver = '[email protected]'.
*gs_mailrec-express = 'X'.
*gs_mailrec-rec_type = 'U'.
*append gs_mailrec to gt_mailrec.
gs_mailrec-receiver = 'FRSURC12'.
gs_mailrec-express = 'X'.
gs_mailrec-rec_type = 'B'.
append gs_mailrec to gt_mailrec.
endform. " update_mail_data
*&----
*
*& Form send_mail
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form send_mail .
Sending the Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gs_docdata
put_in_outbox = 'X'
COMMIT_WORK = 'X'
TABLES
packing_list = gt_packlist
object_header = gt_objhead
CONTENTS_BIN = gt_conbin
CONTENTS_TXT = gt_contxt
receivers = gt_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.
ELSE.
Write:/1 'The Mail is successfully sent to the SAP Inbox'.
ENDIF.
endform. " send_mail
Thanks & Regards,
Ramky.G
2007 Apr 12 8:43 AM
2007 Apr 12 8:43 AM
HI ,
I think the doc type TXT is not valid.,
You can give doc_type as "RAW"-- ( sap editor document)
for sending attachment in SAP inbox..
there are different document type below
ALI ABAP list document
ARC Archive object (image)
BCS External Document Storage
BIN Binary document
DLI Distribution list
EXT PC document
FAX Fax
FOL Folder
GRA SAP Business Graphics
OBJ Business object
OFO Object folder
OTF OTF document
R3I IDoc
RAW SAP editor document
SCR SAPscript document
URL Link to Internet/Intranet
WIM Work item
XXL Document for list viewer
Hope this helps, reward points if useful,
regards,
nazeer
2007 Apr 12 8:44 AM
Hi Ramakrishnan,
"output format the alignment in the txt file is haphazard" - if you display the file using a proportional font with or witout tab chars, the representation is dependent on your system.
I think the reason is the representation in SAP inbox according to SAPGUI settings.
Regards,
Clemens
2007 Apr 12 8:48 AM
Hi,
Instead of displaying records one by one, the records are getting displayed horizontally.This is the actual problem.
Cheers
Ramky.G
2007 Apr 12 8:49 AM
Hi,
Use the class CL_ABAP_CHAR_UTILITIES=>CR_LF. after every line of of the internal table
Regards
Sudheer
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |