Skip to Content
avatar image
Former Member

Issue in 'SO_NEW_DOCUMENT_ATT_SEND_API1' for PDF attachment

Hi experts,

I am using ht e function module 'SO_NEW_DOCUMENT_ATT_SEND_API1' for sending email with the samartform output as PDF attachment. It is working fine. But when I try to openthe PDF attachment in the email, Its showing an error message that 'A number is out of range.' . I am attaching the source code below.

DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

L_IT_PDF TYPE TABLE OF TLINE WITH HEADER LINE,

I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE, "#EC *

I_RECORD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

  • Objects to send mail.

I_OBJPACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

I_OBJTXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_OBJBIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

I_RECLIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

  • Work Area declarations

WA_OBJHEAD TYPE SOLI_TAB,

W_CTRLOP TYPE SSFCTRLOP,

W_COMPOP TYPE SSFCOMPOP,

W_RETURN TYPE SSFCRESCL,

WA_DOC_CHNG TYPE SODOCCHGI1,

W_DATA TYPE SODOCCHGI1, "#EC *

WA_BUFFER TYPE STRING, "To convert from 132 to 255

  • Variables declarations

FM_NAME TYPE RS38L_FNAM,

  • V_LEN_IN LIKE SOOD-OBJLEN, "#EC *

V_LEN_IN TYPE I, "#EC *

V_LEN_OUT LIKE SOOD-OBJLEN, "#EC *

V_LEN_OUTN TYPE I, "#EC *

V_LINES_TXT TYPE I,

V_LINES_BIN TYPE I.

DATA: EMAIL_LINE1 TYPE STRING.

DATA: L_PARAB1 LIKE TLINE OCCURS 0 WITH HEADER LINE.

DATA: L_SUB1(20).

DATA: L_SUB2(50).

DATA: L_DATE(10).

DATA: L_NAME LIKE THEAD-TDNAME.

DATA: L_DAT_TEXT TYPE TLINE-TDLINE.

DATA: L_MONTHS(9).

CLEAR FM_NAME.

*===============Calling The smartforms========================

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

FORMNAME = 'ZFI_SF_INV_EMAIL'

IMPORTING

FM_NAME = FM_NAME

EXCEPTIONS

NO_FORM = 1

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

CLEAR W_CTRLOP.

CLEAR W_COMPOP.

W_CTRLOP-GETOTF = 'X'.

W_CTRLOP-NO_DIALOG = 'X'.

W_COMPOP-TDNOPREV = 'X'.

  • W_COMPOP-TDNOPREV = ''.

CALL FUNCTION FM_NAME

EXPORTING

CONTROL_PARAMETERS = W_CTRLOP

OUTPUT_OPTIONS = W_COMPOP

USER_SETTINGS = 'X'

GS_ITEM = GT_FINAL

IMPORTING

JOB_OUTPUT_INFO = W_RETURN

  • TABLES

  • GT_ITEM =

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

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

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

ENDIF.

I_OTF[] = W_RETURN-OTFDATA[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 132

IMPORTING

BIN_FILESIZE = V_LEN_IN

TABLES

OTF = I_OTF

LINES = I_TLINE

EXCEPTIONS "#EC *

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

ENDIF.

LOOP AT I_TLINE.

TRANSLATE I_TLINE USING '~'.

CONCATENATE WA_BUFFER I_TLINE INTO WA_BUFFER.

ENDLOOP.

TRANSLATE WA_BUFFER USING '~'.

DO.

I_RECORD = WA_BUFFER.

APPEND I_RECORD.

SHIFT WA_BUFFER LEFT BY 255 PLACES.

IF WA_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

  • EXPORTING

  • LINE_WIDTH_SRC = '132'

  • LINE_WIDTH_DST = '255'

  • TABLES

  • CONTENT_IN = I_TLINE[]

  • CONTENT_OUT = L_IT_PDF[]

  • EXCEPTIONS

  • ERR_LINE_WIDTH_SRC_TOO_LONG = 1

  • ERR_LINE_WIDTH_DST_TOO_LONG = 2

  • ERR_CONV_FAILED = 3

  • OTHERS = 4.

*

*======================== Attachment=========================

REFRESH: I_RECLIST,

I_OBJTXT,

I_OBJBIN,

I_OBJPACK.

CLEAR WA_OBJHEAD.

I_OBJBIN[] = I_RECORD[].

*======================Read Mail Body========================

CALL FUNCTION 'READ_TEXT'

EXPORTING

ID = 'ST'

LANGUAGE = SY-LANGU

NAME = 'ZFI_ST_INV_MAIL_BODY' "Email Body

OBJECT = 'TEXT'

TABLES

LINES = L_PARAB1

EXCEPTIONS

ID = 1

LANGUAGE = 2

NAME = 3

NOT_FOUND = 4

OBJECT = 5

REFERENCE_CHECK = 6

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

ENDIF.

CONCATENATE 'Dear' GT_FINAL-VERAK ',' INTO I_OBJTXT SEPARATED BY SPACE.

  • I_OBJTXT = 'Dear Sir,'.

APPEND I_OBJTXT.

I_OBJTXT = ' '.

APPEND I_OBJTXT.

PERFORM DATE_FORMAT USING GT_FINAL-DATE CHANGING L_DAT_TEXT L_MONTHS.

CONCATENATE 'Please find the above attached invoice towards Consulting fees for the services of the"'

GT_FINAL-KTEXT '"for the month of' L_MONTHS GT_FINAL-DATE(4)

INTO EMAIL_LINE1 SEPARATED BY SPACE.

I_OBJTXT = EMAIL_LINE1.

APPEND I_OBJTXT.

LOOP AT L_PARAB1.

I_OBJTXT = L_PARAB1-TDLINE.

APPEND I_OBJTXT.

ENDLOOP.

CLEAR EMAIL_LINE1.

I_OBJTXT = ''.

APPEND I_OBJTXT.

  • CONCATENATE '* Note: Please reply to' GT_FINAL-BEMAIL INTO EMAIL_LINE1 SEPARATED BY SPACE.

I_OBJTXT = EMAIL_LINE1.

APPEND I_OBJTXT.

*===================Mail Title=============================================

L_SUB1 = 'Invoice for'.

CONCATENATE L_SUB1 L_MONTHS GT_FINAL-DATE(4) INTO L_SUB2 SEPARATED BY SPACE.

DESCRIBE TABLE I_OBJTXT LINES V_LINES_TXT.

READ TABLE I_OBJTXT INDEX V_LINES_TXT.

WA_DOC_CHNG-OBJ_NAME = L_SUB2.

WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

WA_DOC_CHNG-OBJ_DESCR = L_SUB2.

WA_DOC_CHNG-SENSITIVTY = 'F'.

WA_DOC_CHNG-DOC_SIZE = V_LINES_TXT * 255.

*====================== Main Text==============================

CLEAR I_OBJPACK-TRANSF_BIN.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 0.

I_OBJPACK-BODY_START = 1.

I_OBJPACK-BODY_NUM = V_LINES_TXT.

I_OBJPACK-DOC_TYPE = 'RAW'.

APPEND I_OBJPACK.

*============= Attachment (pdf-Attachment)=====================

I_OBJPACK-TRANSF_BIN = 'X'.

I_OBJPACK-HEAD_START = 1.

I_OBJPACK-HEAD_NUM = 1.

I_OBJPACK-BODY_START = 1.

DESCRIBE TABLE I_OBJBIN LINES V_LINES_BIN.

READ TABLE I_OBJBIN INDEX V_LINES_BIN.

I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

I_OBJPACK-BODY_NUM = V_LINES_BIN.

I_OBJPACK-DOC_TYPE = 'PDF'.

I_OBJPACK-OBJ_NAME = L_SUB2.

I_OBJPACK-OBJ_DESCR = L_SUB2.

APPEND I_OBJPACK.

CLEAR I_RECLIST.

*============Recipiant's mail id================================

I_RECLIST-RECEIVER = GT_FINAL-EMAIL."'Recipiants's Mail Id.

I_RECLIST-REC_TYPE = 'U'.

APPEND I_RECLIST.

CLEAR I_RECLIST.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WA_DOC_CHNG

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = I_OBJPACK

OBJECT_HEADER = WA_OBJHEAD

CONTENTS_BIN = I_OBJBIN

CONTENTS_TXT = I_OBJTXT

RECEIVERS = I_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:/ 'Error When Sending the File', SY-SUBRC.

ELSE.

WRITE:/ 'Mail sent'.

ENDIF.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jun 04, 2010 at 12:54 PM

    > DO.

    > I_RECORD = WA_BUFFER.

    > APPEND I_RECORD.

    > SHIFT WA_BUFFER LEFT BY 255 PLACES.

    > IF WA_BUFFER IS INITIAL.

    > EXIT.

    > ENDIF.

    > ENDDO.

    as I_RECORD is 255 characters, but WA_BUFFER was a string of chunks of 134 characters, that's pretty easy to understand the issue!

    Why don't you use the code you commented, below? (replace L_IT_PDF\[] with I_RECORD\[] of course)

    > * CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

    > * EXPORTING

    > * LINE_WIDTH_SRC = '132'

    > * LINE_WIDTH_DST = '255'

    > * TABLES

    > * CONTENT_IN = I_TLINE[]

    > * CONTENT_OUT = L_IT_PDF[]

    > * EXCEPTIONS

    > * ERR_LINE_WIDTH_SRC_TOO_LONG = 1

    > * ERR_LINE_WIDTH_DST_TOO_LONG = 2

    > * ERR_CONV_FAILED = 3

    > * OTHERS = 4.

    Add comment
    10|10000 characters needed characters exceeded