Skip to Content
author's profile photo Former Member
Former Member

Payslip to be sent as email - pdf attachment

I written a program to send payslip through email as pdf attachement. Everything is working fine. I am able to recieve the email aslo, but unable to open the attchment, Iam getting the following error

Adobe reader could not open the PDF file because it is either not a supported file or because the file has been damaged (for example it was sent as an email attachement and was not correctly decoded)

Cany any one pl. guide me where I went worng.

Here is my ABAP CODE

REPORT zacg_bnkpayst

NO STANDARD PAGE HEADING

LINE-SIZE 255

LINE-COUNT 65.

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

  • Global Types *

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

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

  • Tables *

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

TABLES:pa0001.

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

*--DECLARATION OF INTERNAL TABLES USED FOR ALV DISPLAY. *

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

*---INTERNAL TABLE USED FOR FIELD CATALOG

DATA : BEGIN OF rgdir OCCURS 0.

INCLUDE STRUCTURE pc261.

DATA : END OF rgdir.

DATA : country LIKE t001p-molga VALUE 'IN',

v_pabrj LIKE t549q-pabrj,

v_pabrp LIKE t549q-pabrp,

v_vabrj LIKE t549q-vabrj,

v_vabrp LIKE t549q-vabrp,

v_fpper1 LIKE rgdir-fpper,

v_fpper2 LIKE rgdir-fpper,

return LIKE BAPIRETURN1,

PAYSLIP LIKE BAPI7004_PAYSLIP OCCURS 0 WITH HEADER LINE,

  • PAYSLIP type xstring,

BIN_FILE type xstring,

PDF_FSIZE TYPE I,

v_srno like pa0000-pernr.

DATA: BEGIN OF i_pernr OCCURS 0,

pernr LIKE pa0000-pernr,

seqnr LIKE hrpy_rgdir-seqnr,

fpper LIKE hrpy_rgdir-fpper,

inper LIKE hrpy_rgdir-inper,

ipend LIKE hrpy_rgdir-ipend,

END OF i_pernr.

DATA result TYPE pay99_result.

DATA ihrpy LIKE hrpy_rgdir OCCURS 0.

DATA whpr TYPE hrpy_rgdir.

DATA : bt_header TYPE LINE OF hrpay99_bt,

rt_header TYPE LINE OF hrpay99_rt.

DATA: I_OTF TYPE ITCOO OCCURS 0 WITH HEADER LINE,

I_TLINE TYPE TABLE OF TLINE WITH HEADER LINE,

I_RECEIVERS TYPE TABLE OF SOMLRECI1 WITH HEADER LINE,

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,

WA_BUFFER TYPE STRING, "To convert from 132 to 255

  • Variables declarations

V_FORM_NAME TYPE RS38L_FNAM,

V_LEN_IN LIKE SOOD-OBJLEN,

V_LEN_OUT LIKE SOOD-OBJLEN,

V_LEN_OUTN TYPE I,

V_LINES_TXT TYPE I,

V_LINES_BIN TYPE I.

DATA : w_repid LIKE sy-repid,

w_dynpro LIKE sy-dynnr.

SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN BEGIN OF BLOCK blk1 .

SELECTION-SCREEN SKIP 1.

PARAMETERS: p_rad1 RADIOBUTTON GROUP gr1 ,

p_rad2 RADIOBUTTON GROUP gr1 .

PARAMETERS : p_bukrs LIKE pa0001-bukrs OBLIGATORY.

SELECT-OPTIONS:s_date FOR pa0001-begda NO-EXTENSION OBLIGATORY,

s_werks FOR pa0001-werks NO-EXTENSION NO INTERVALS,

s_BTRTL FOR pa0001-BTRTL NO-EXTENSION NO INTERVALS,

s_ABKRS FOR pa0001-ABKRS OBLIGATORY,

s_persg FOR pa0001-persg,

s_pernr FOR pa0001-pernr.

SELECTION-SCREEN END OF BLOCK blk1.

LOAD-OF-PROGRAM.

MOVE sy-repid TO w_repid.

MOVE sy-dynnr TO w_dynpro.

START-OF-SELECTION.

PERFORM select_data.

&----


*& Form SELECT_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM select_data .

SELECT SINGLE pabrj

pabrp

vabrj

vabrp

FROM t549q

INTO (v_pabrj,v_pabrp,v_vabrj,v_vabrp)

WHERE permo = '67'

AND begda >= s_date-low

AND endda <= s_date-high.

CONCATENATE v_pabrj v_pabrp INTO v_fpper1.

CONCATENATE v_vabrj v_vabrp INTO v_fpper2.

  • hrpy_rgdir table is getting filled once the payroll is run.

if p_rad1 = 'X'.

SELECT pernr

seqnr

fpper

inper

ipend

FROM hrpy_rgdir

INTO CORRESPONDING FIELDS OF TABLE i_pernr

WHERE inper > v_fpper2

AND inper <= v_fpper1

AND FPPER > v_fpper2

AND FPPer <= v_fpper1

AND pernr IN s_pernr

AND SRTZA = 'A'.

else.

SELECT pernr

seqnr

fpper

inper

ipend

FROM hrpy_rgdir

INTO CORRESPONDING FIELDS OF TABLE i_pernr

WHERE fpbeg >= s_date-low

AND fpend <= s_date-high

AND OCRSN = '0002'

AND pernr IN s_pernr

AND payty = 'A'.

endif.

LOOP AT i_pernr.

CALL FUNCTION 'BAPI_GET_PAYSLIP'

EXPORTING

employeenumber = i_pernr-pernr

sequencenumber = i_pernr-seqnr

payslipvariant = 'ZP1Y'

  • IMPORTING

  • RETURN =

tables

payslip = PAYSLIP .

  • CALL FUNCTION 'BAPI_GET_PAYSLIP_PDF'

  • EXPORTING

  • employeenumber = i_pernr-pernr

  • sequencenumber = i_pernr-seqnr

  • payslipvariant = 'ZP1Y'

  • IMPORTING

  • RETURN =

  • PAYSLIP = PAYSLIP

  • PDF_FSIZE = PDF_FSIZE.

  • .

    IF sy-subrc <> 0.

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

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

    ELSE.

    LOOP AT PAYSLIP.

    TRANSLATE PAYSLIP USING '~'.

    CONCATENATE WA_BUFFER PAYSLIP 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[].

    *I_OBJBIN[] = PAYSLIP[].

    • 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 = 'RAW'.

    APPEND I_OBJPACK.

    • Attachment (pdf-Attachment)

    I_OBJPACK-TRANSF_BIN = 'X'.

    I_OBJPACK-HEAD_START = 1.

    I_OBJPACK-HEAD_NUM = 0.

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

    I_OBJPACK-OBJ_DESCR = 'test'.

    APPEND I_OBJPACK.

    CLEAR I_RECLIST.

    I_RECLIST-RECEIVER = 'email id'.

    I_RECLIST-REC_TYPE = 'U'.

    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.

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

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

    ELSE.

    WAIT UP TO 5 SECONDS.

    SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.

    ENDIF.

    ENDIF.

    ENDLOOP.

    ENDFORM. " SELECT_DATA

    Add a comment
    10|10000 characters needed characters exceeded

    Assigned Tags

    Related questions

    2 Answers

    • author's profile photo Former Member
      Former Member
      Posted on Mar 21, 2009 at 06:53 AM

      Hi,

      Refer to the following link.

      http://searchsap.techtarget.com/featuredTopic/0,290042,sid21_gci1161956,00.html

      Hope it helps.

      Regards

      Rajesh Kumar

      Add a comment
      10|10000 characters needed characters exceeded

    • author's profile photo Former Member
      Former Member
      Posted on Mar 21, 2009 at 06:54 AM

      Hi,

      Refer to the following link.

      http://searchsap.techtarget.com/featuredTopic/0,290042,sid21_gci1161956,00.html

      Hope it helps.

      Regards

      Rajesh Kumar

      Add a comment
      10|10000 characters needed characters exceeded

    Before answering

    You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
    You must be Logged in to submit an answer.

    Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.