Skip to Content
0
Former Member
Jul 19, 2005 at 10:04 AM

attaching text file using SO_NEW_DOCUMENT_ATT_SEND_API1

236 Views

hello guys, i'm a newbie here.

I'm having trouble attaching an existing text file using function 'SO_NEW_DOCUMENT_ATT_SEND_API1'. It seems i can't find the right combination of parameters that are being passed to this function.

first, i'm using WS_UPLOAD to upload the text file to an internal table then i'm creating all the neccessary internal tables that will be use by this function..

By the way, i'm trying to send mail w/ attachments to external mail and SAPids. Below is my code.

REPORT ZHR_TESTEMAIL .

TABLES: USR02, PA0105, SOSU, SOUC, RLGRAP, IBIPPARMS, DYNPREAD, RSCSEL.

DATA: FOLD_YR(2) TYPE C,

FOLD_TYPE(3) TYPE C,

G_HEADER LIKE SOOD2,

G_FOLMAM LIKE SOFM2,

METHOD1 LIKE SY-UCOMM,

G_DOCUMENT LIKE SOOD4,

G_USER LIKE SOUDNAMEI1,

FOLD_NUMBER(12) TYPE C,

G_NEW_PARENT LIKE SOODK,

G_OWNER LIKE SOUD-USRNAM,

G_REF_DOCUMENT LIKE SOOD4,

G_USER_DATA LIKE SOUDATAI1,

G_AUTHORITY LIKE SOFA-USRACC,

G_OBJCNT LIKE SOLI OCCURS 0 WITH HEADER LINE,

G_OBJHEAD LIKE SOLI OCCURS 0 WITH HEADER LINE,

G_OBJPARA LIKE SELC OCCURS 0 WITH HEADER LINE,

G_OBJPARB LIKE SOOP1 OCCURS 0 WITH HEADER LINE,

G_RECIPIENTS LIKE SOOS1 OCCURS 0 WITH HEADER LINE,

G_REFERENCES LIKE SOXRL OCCURS 0 WITH HEADER LINE,

G_ATTACHMENTS LIKE SOOD5 OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF G_FILES OCCURS 10 ,

TEXT(4096) TYPE C,

END OF G_FILES.

DATA: BEGIN OF IT_WS_FILE OCCURS 0,

WS_FILE LIKE RLGRAP-FILENAME,

END OF IT_WS_FILE.

DATA: BEGIN OF IT_SAPID OCCURS 0,

SAPID LIKE USR02-BNAME,

END OF IT_SAPID.

DATA: BEGIN OF IT_EMAIL OCCURS 0,

EMAILADD LIKE PA0105-USRID_LONG,

END OF IT_EMAIL.

DATA: BEGIN OF IT_TSP01 OCCURS 0.

INCLUDE STRUCTURE TSP01.

DATA: END OF IT_TSP01.

DATA: BEGIN OF TAB2 OCCURS 50,

TEXT(200) TYPE C,

END OF TAB2.

DATA: V_DOCDATA TYPE SODOCCHGI1,

V_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

V_OBJHEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

V_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

V_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

V_OBJHEX LIKE SOLIX OCCURS 0 WITH HEADER LINE,

IT_RECVRS TYPE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

IT_CONTNT TYPE SOLISTI1 OCCURS 0 WITH HEADER LINE,

IT_BODY LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,

V_TLIN TYPE I,

V_LINE TYPE I.

DATA: BEGIN OF IT_TEXTLINE OCCURS 500,

TEXTLINE(5000),

END OF IT_TEXTLINE.

DATA: FYL LIKE RLGRAP-FILENAME,

GV_SUBNO LIKE SOSU-SUBNO,

GV_EMAIL LIKE PA0105-USRID_LONG,

GV_NEXTDAY LIKE SY-DATUM,

YEAR(4) TYPE C,

RECFLAG TYPE C.

SELECTION-SCREEN BEGIN OF BLOCK PARAM WITH FRAME TITLE TEXT-001.

PARAMETERS: SUBJ(254) TYPE C OBLIGATORY, "Subject

DESC(254) TYPE C. "Message

SELECT-OPTIONS: SAPID FOR USR02-BNAME NO INTERVALS. "Recipient's SAP ID

SELECT-OPTIONS: EMAILADD FOR PA0105-USRID_LONG NO INTERVALS.

SELECTION-SCREEN END OF BLOCK PARAM.

SELECTION-SCREEN BEGIN OF BLOCK PARAM2 WITH FRAME TITLE TEXT-002.

SELECT-OPTIONS: WS_FILE FOR DYNPREAD-FIELDNAME NO INTERVALS.

SELECTION-SCREEN END OF BLOCK PARAM2.

SELECTION-SCREEN BEGIN OF BLOCK PARAM3 WITH FRAME TITLE TEXT-003.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: RBUT1 RADIOBUTTON GROUP A USER-COMMAND BUT. "Local PC

SELECTION-SCREEN COMMENT 5(20) FOR FIELD RBUT1.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: RBUT2 RADIOBUTTON GROUP A. "Server

SELECTION-SCREEN COMMENT 5(20) FOR FIELD RBUT2.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS: RBUT3 RADIOBUTTON GROUP A. "Spool

SELECTION-SCREEN COMMENT 5(20) FOR FIELD RBUT3.

PARAMETERS: SPOOLNUM LIKE RSPOTYPE-RQNUMBER. "Spool Number

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK PARAM3.

SELECTION-SCREEN BEGIN OF BLOCK PROC WITH FRAME TITLE TEXT-004.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETER: BPROC AS CHECKBOX USER-COMMAND BCK. "Background Processing

SELECTION-SCREEN COMMENT 5(50) FOR FIELD BPROC.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK PROC.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR WS_FILE-LOW.

DATA: WS_FILE_TEMP TYPE IBIPPARMS-PATH.

CLEAR: WS_FILE_TEMP.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SY-REPID

DYNPRO_NUMBER = SY-DYNNR

FIELD_NAME = 'WS_FILE'

IMPORTING

FILE_NAME = WS_FILE_TEMP.

WS_FILE-LOW = WS_FILE_TEMP.

AT SELECTION-SCREEN.

SELECT SAPNAM FROM SOUC

INTO TABLE IT_SAPID

WHERE SAPNAM IN SAPID

AND DELETED = ''.

GV_NEXTDAY = SY-DATUM + 1.

LOOP AT EMAILADD.

IT_EMAIL-EMAILADD = EMAILADD-LOW.

APPEND IT_EMAIL.

CLEAR: IT_EMAIL.

ENDLOOP.

IF NOT BPROC IS INITIAL.

CLEAR: RBUT1, RBUT3.

RBUT2 = 'X'.

ELSE.

CLEAR: RBUT2.

ENDIF.

IF NOT RBUT3 IS INITIAL.

REFRESH: WS_FILE.

ENDIF.

IF SAPID IS INITIAL AND EMAILADD IS INITIAL.

MESSAGE E000(ZZ) WITH TEXT-201.

ELSEIF NOT SAPID IS INITIAL AND EMAILADD IS INITIAL.

CLEAR IT_SAPID.

READ TABLE IT_SAPID.

SELECT SINGLE SUBNO FROM SOSU

INTO GV_SUBNO

WHERE USRNO IN ( SELECT USRNO FROM SOUC

WHERE SAPNAM = IT_SAPID-SAPID ).

IF SY-SUBRC NE 0.

MESSAGE E000(ZZ) WITH TEXT-202.

ENDIF.

CLEAR: IT_SAPID.

ELSEIF NOT SAPID IS INITIAL AND NOT EMAILADD IS INITIAL.

CLEAR: IT_SAPID, IT_EMAIL.

READ TABLE IT_SAPID.

READ TABLE IT_EMAIL.

SELECT SINGLE SUBNO FROM SOSU

INTO GV_SUBNO

WHERE USRNO IN ( SELECT USRNO FROM SOUC

WHERE SAPNAM = IT_SAPID-SAPID ).

IF SY-SUBRC NE 0.

SUBMIT RSSOADM0 WITH USRNAM EQ IT_SAPID-SAPID

WITH NEW_SUBS EQ IT_EMAIL-EMAILADD

WITH SUB_ESC EQ 'U'

WITH EDAT EQ SY-DATUM

WITH BDAT EQ SY-DATUM

  • WITH BDAT EQ GV_NEXTDAY

  • WITH EDAT EQ '99991231'

WITH BTIM EQ SY-UZEIT

WITH ETIM EQ '240000'

WITH FORW_ALL EQ 'X'

WITH PSTHR2 EQ ''

AND RETURN.

ENDIF.

CLEAR: IT_SAPID.

ELSEIF NOT EMAILADD IS INITIAL AND SAPID IS INITIAL.

RECFLAG = 'X'.

ENDIF.

START-OF-SELECTION.

PERFORM B_SENDMAIL.

FORM B_SENDMAIL.

YEAR = SY-DATUM+0(4).

LOOP AT WS_FILE.

CLEAR: FYL.

FYL = WS_FILE-LOW.

REFRESH: TAB2.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = FYL

FILETYPE = 'BIN'

TABLES

DATA_TAB = TAB2.

IT_TEXTLINE[] = TAB2[].

  • DOCUMENT_DATA (SUBJECT OF MAIL)

----


V_DOCDATA-OBJ_NAME = DESC.

V_DOCDATA-OBJ_DESCR = SUBJ.

V_DOCDATA-OBJ_LANGU = SY-LANGU.

V_DOCDATA-SENSITIVTY = 'C'.

V_DOCDATA-OBJ_PRIO = '1'.

----


  • BODY OF MAIL

----


IT_BODY-LINE = 'Collection Report'.

APPEND IT_BODY.

----


  • CONTENTS_TXT (Attachments)

----


IT_CONTNT[] = IT_TEXTLINE[].

DESCRIBE TABLE IT_CONTNT LINES V_LINE.

READ TABLE IT_CONTNT INDEX V_LINE.

----


  • PACKING_LIST

----


V_OBJPACK-DOC_SIZE = ( V_LINE - 1 ) * 255 + STRLEN( IT_CONTNT ).

V_OBJPACK-TRANSF_BIN = 'X'.

V_OBJPACK-HEAD_START = 1.

V_OBJPACK-HEAD_NUM = 0.

V_OBJPACK-BODY_START = 1.

V_OBJPACK-BODY_NUM = V_LINE.

V_OBJPACK-DOC_TYPE = 'TXT'.

V_OBJPACK-OBJ_NAME = 'ATTACHMENT'.

V_OBJPACK-OBJ_DESCR = 'Attached Document'.

APPEND V_OBJPACK.

CLEAR V_OBJPACK.

----


  • RECEIVERS of mail

----


IF RECFLAG IS INITIAL.

LOOP AT IT_SAPID.

IT_RECVRS-RECEIVER = IT_SAPID-SAPID.

IT_RECVRS-REC_TYPE = 'B'.

IT_RECVRS-COM_TYPE = ''.

IT_RECVRS-EXPRESS = 'X'.

IT_RECVRS-NO_FORWARD = ''.

IT_RECVRS-NO_PRINT = ''.

APPEND IT_RECVRS.

CLEAR IT_RECVRS.

ENDLOOP.

ELSE.

LOOP AT EMAILADD.

IT_RECVRS-RECEIVER = EMAILADD-LOW.

IT_RECVRS-REC_TYPE = 'U'.

IT_RECVRS-COM_TYPE = 'INT'.

IT_RECVRS-EXPRESS = 'X'.

APPEND IT_RECVRS.

CLEAR IT_RECVRS.

ENDLOOP.

ENDIF.

----


  • OBJECT_HEADER (Filename)

----


CONCATENATE 'Collection Report' '_'

SY-DATUM+4(4) YEAR '.TXT'

INTO V_OBJHEAD-LINE.

  • V_OBJHEAD-LINE = FYL+16(25).

APPEND V_OBJHEAD.

CLEAR V_OBJHEAD.

----


  • Function Module For Sending Mail with Attachment

----


CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = V_DOCDATA

TABLES

PACKING_LIST = V_OBJPACK

OBJECT_HEADER = V_OBJHEAD

CONTENTS_HEX = IT_CONTNT

CONTENTS_TXT = IT_BODY

RECEIVERS = IT_RECVRS

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 S000(ZZ) WITH TEXT-005.

ELSE.

MESSAGE S000(ZZ) WITH TEXT-006.

ENDIF.

----


ENDLOOP.

  • end of my code *

please help me guys... when i run this program, DOCUMENT_NOT_SENT is what i always get..

waiting for ur reply... thank you vey much and godbless.