Skip to Content
avatar image
Former Member

Problem With Converting PO Smartform into PDF

Hi All,

I am trying to email the Smartform PO. I developed the program after reading several discuusions and blogs in forum. The PO is successfully created in PDF format and stored in the local directory. When i tried to view the pdf the PO is creatd twice in the PDF. I mean the original pdf is of 3 pages with PO and terms and conditons. But in the pdf which was created it has 6 pages. I am unable to understand why it has 2 copies of same PO.

When i tried to email the pdf as attachement the email is delivered successfully. But when i tried to view the pdf its given an error that "the file is corrupted (For example the attachemnt is not coded properly)or the fle type is not supported. Even in the attachment also i have the two files one is of pdf another is also of the .pdf but the image is showing as Unknown file format.

Any suggestions to resolve these issues.

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Oct 08, 2007 at 07:30 PM

    My code is as follows:

    *********************************************************************************************

    FORM print_form .

    *Calling FM to retrieve the function module associated with the Smartform

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    FORMNAME = 'ZMMS_MEDRUCK_LS'

    • VARIANT = ' '

    • DIRECT_CALL = ' '

    IMPORTING

    FM_NAME = v_form_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.

    control_parameters-langu = sy-langu.

    control_parameters-no_dialog = 'X'.

    control_parameters-getotf = 'X'.

    • Excuting the FM associated with the SmartForm by input required internal tables

    CALL FUNCTION v_form_name

    EXPORTING

    • ARCHIVE_INDEX =

    • ARCHIVE_INDEX_TAB =

    • ARCHIVE_PARAMETERS =

    CONTROL_PARAMETERS = control_parameters

    • MAIL_APPL_OBJ =

    • MAIL_RECIPIENT =

    • MAIL_SENDER =

    OUTPUT_OPTIONS = output_options

    • USER_SETTINGS = 'X'

    IS_NAST = it_nast

    IS_PEKKO = it_pekko

    IMPORTING

    • DOCUMENT_OUTPUT_INFO =

    JOB_OUTPUT_INFO = output_data

    • JOB_OUTPUT_OPTIONS =

    TABLES

    IT_EKPO = it_ekpo

    IT_EKET = it_eket

    IS_EKKO = it_ekko

    IT_DRAW = it_draw

    IT_BUYER = it_buyer

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

    tab_otf_final[] = output_data-otfdata[].

    **removing the initial and final markers from the OTF data*********

    DELETE output_data-otfdata WHERE tdprintcom = '//'.

    • searching for the end-of-page in OTF table************

    DATA : my_tabix TYPE sy-tabix.

    READ TABLE tab_otf_final WITH KEY tdprintcom = 'EP'.

    my_tabix = sy-tabix + 1.

    • appending the modified OTF table to the final OTF table****

    INSERT LINES OF output_data-otfdata INTO tab_otf_final INDEX my_tabix.

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = 'PDF'

    • MAX_LINEWIDTH = 132

    • ARCHIVE_INDEX = ' '

    • COPYNUMBER = 0

    • ASCII_BIDI_VIS2LOG = ' '

    • PDF_DELETE_OTFTAB = ' '

    IMPORTING

    bin_filesize = bin_filesize

    TABLES

    OTF = tab_otf_final

    LINES = lt_lines

    • EXCEPTIONS

    • ERR_MAX_LINEWIDTH = 1

    • ERR_FORMAT = 2

    • ERR_CONV_NOT_POSSIBLE = 3

    • ERR_BAD_OTF = 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.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    BIN_FILESIZE = bin_filesize

    FILENAME = 'D:TEST.PDF'

    FILETYPE = 'BIN'

    • APPEND = ' '

    • WRITE_FIELD_SEPARATOR = ' '

    • HEADER = '00'

    • TRUNC_TRAILING_BLANKS = ' '

    • WRITE_LF = 'X'

    • COL_SELECT = ' '

    • COL_SELECT_MASK = ' '

    • DAT_MODE = ' '

    • CONFIRM_OVERWRITE = ' '

    • NO_AUTH_CHECK = ' '

    • CODEPAGE = ' '

    • IGNORE_CERR = ABAP_TRUE

    • REPLACEMENT = '#'

    • WRITE_BOM = ' '

    • TRUNC_TRAILING_BLANKS_EOL = 'X'

    • WK1_N_FORMAT = ' '

    • WK1_N_SIZE = ' '

    • WK1_T_FORMAT = ' '

    • WK1_T_SIZE = ' '

    • WRITE_EOL = ABAP_TRUE

    IMPORTING

    FILELENGTH = file_size

    TABLES

    DATA_TAB = lt_lines

    • FIELDNAMES =

    • EXCEPTIONS

    • FILE_WRITE_ERROR = 1

    • NO_BATCH = 2

    • GUI_REFUSE_FILETRANSFER = 3

    • INVALID_TYPE = 4

    • NO_AUTHORITY = 5

    • UNKNOWN_ERROR = 6

    • HEADER_NOT_ALLOWED = 7

    • SEPARATOR_NOT_ALLOWED = 8

    • FILESIZE_NOT_ALLOWED = 9

    • HEADER_TOO_LONG = 10

    • DP_ERROR_CREATE = 11

    • DP_ERROR_SEND = 12

    • DP_ERROR_WRITE = 13

    • UNKNOWN_DP_ERROR = 14

    • ACCESS_DENIED = 15

    • DP_OUT_OF_MEMORY = 16

    • DISK_FULL = 17

    • DP_TIMEOUT = 18

    • FILE_NOT_FOUND = 19

    • DATAPROVIDER_EXCEPTION = 20

    • CONTROL_FLUSH_ERROR = 21

    • OTHERS = 22

    .

    IF SY-SUBRC <> 0.

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

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

    ENDIF.

    loop at LT_LINES INTO wa_lines.

    translate wa_LINES using '~'.

    concatenate WA_BUFFER wa_LINES 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.

    • Attachment

    refresh:

    I_RECLIST,

    I_OBJTXT,

    I_OBJBIN,

    I_OBJPACK.

    clear WA_OBJHEAD.

    I_OBJBIN[] = I_RECORD[].

    • APPEND I_RECORD.

    • Create Message Body Title and Description****************

    I_OBJTXT = 'test with pdf-Attachment!'.

    append I_OBJTXT.

    describe table I_OBJTXT lines V_LINES_TXT.

    read table I_OBJTXT index V_LINES_TXT.

    WA_DOC_CHNG-OBJ_NAME = 'smartform'.

    WA_DOC_CHNG-EXPIRY_DAT = SY-DATUM + 10.

    WA_DOC_CHNG-OBJ_DESCR = 'smartform'.

    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 = 'PDF'.

    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.

    I_OBJPACK-BODY_NUM = V_LINES_BIN.

    I_OBJPACK-DOC_TYPE = 'PDF'.

    I_OBJPACK-OBJ_NAME = 'smartform'.

    concatenate I_OBJPACK-OBJ_NAME I_OBJPACK-DOC_TYPE into I_OBJPACK-OBJ_DESCR separated by '.'.

    • I_OBJPACK-OBJ_DESCR = 'test'.

    I_OBJPACK-DOC_SIZE = V_LINES_BIN * 255 .

    append I_OBJPACK.

    • Länge des Attachment ermitteln

    clear I_RECLIST.

    I_RECLIST-RECEIVER = 'balaji.yarlagadda@waukesha.spx.com'.

    I_RECLIST-REC_TYPE = 'U'.

    I_RECLIST-EXPRESS = 'X'.

    data: TAB_LINES like SY-TABIX.

    describe table I_OBJBIN lines TAB_LINES.

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

    ENDFORM. " print_form

    Add comment
    10|10000 characters needed characters exceeded