2009 Mar 21 6:45 AM
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
2009 Mar 21 6: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
2009 Mar 21 6: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
2009 Mar 21 7:52 AM
Hi,
I had the same issue,problem is in ur conversion to PDF.Just follow the below code,I used it to send PO :
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.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
FORMNAME = 'ZMM_PORDER'
IMPORTING
FM_NAME = V_FORM_NAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
W_CTRLOP-GETOTF = 'X'.
W_CTRLOP-NO_DIALOG = 'X'.
W_COMPOP-TDNOPREV = 'X'.
CALL FUNCTION V_FORM_NAME
EXPORTING
CONTROL_PARAMETERS = W_CTRLOP
OUTPUT_OPTIONS = W_COMPOP
USER_SETTINGS = 'X'
W_NAMEV = KNVK-NAMEV
W_NAME1 = KNVK-NAME1
W_TELF1 = KNVK-TELF1
W_ABTNR = KNVK-ABTNR
W_AEDAT = EKKO-AEDAT
W_UNSEZ = EKKO-UNSEZ
W_WAERS = EKKO-WAERS
W_ZTERM = EKKO-ZTERM
W_TELF = EKKO-TELF1
W_BANFN = EKPO-BANFN
W_EBELN = EKPO-EBELN
WA_T001W = T001W
W_ADRNR = W_ADRNR
W_ADRNR1 = W_ADRNR1
W_PSPID = W_PSPID
SPELL = W_SPELL
W_NETWR = W_NETWR
W_CST = W_CST
W_VAT = W_VAT
W_SERT = W_SERT
W_ED_R = W_ED_R
W_ED_A = W_ED_A
W_ECESS_R = W_ECESS_R
W_ECESS_A = W_ECESS_A
W_HCESS_R = W_HCESS_R
W_HCESS_A = W_HCESS_A
W_VAT_R = W_VAT_R
W_VAT_A = W_VAT_A
W_CST_R = W_CST_R
W_CST_A = W_CST_A
W_FR_R = W_FR_R
W_FR_A = W_FR_A
W_OCT_R = W_OCT_R
W_OCT_A = W_OCT_A
W_PF_R = W_PF_R
W_PF_A = W_PF_A
W_ST_R = W_ST_R
W_ST_A = W_ST_A
W_GT_R = W_GT_R
W_GT_A = W_GT_A
WA_ADRC = ADRC
W_POST1 = W_POST1
W_BANFN1 = W_BANFN1
W_TEXT = W_TEXT
IMPORTING
JOB_OUTPUT_INFO = W_RETURN
TABLES
IT_FINAL = IT_FINAL1
IT_F01 = IT_TEXT
IT_F02 = IT_F02
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
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
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
OTHERS = 4.
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.
* Attachment
REFRESH: I_RECLIST,
I_OBJTXT,
I_OBJBIN,
I_OBJPACK.
CLEAR WA_OBJHEAD.
I_OBJBIN[] = I_RECORD[].
* Create Message Body Title and Description
CONCATENATE 'Please Find attached purchase order' P_EBELN INTO I_OBJTXT
SEPARATED BY SPACE.
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 = 'Purchase Order from Sterling & Wilson'.
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 = P_EBELN."'test'.
APPEND I_OBJPACK.
CLEAR I_RECLIST.
I_RECLIST-RECEIVER = W_MAIL_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 I000 WITH 'Error When Sending the File'.
ELSE.
MESSAGE I000 WITH 'Mail succesfully sent to ' W_MAIL_ID.
ENDIF.
2009 Mar 21 8:29 AM
Dear all
I tried the above 3 options suggested by you, still I am getting the same error.
regards
satya
2009 Mar 22 10:54 AM
2009 Mar 31 9:36 PM
2009 Apr 01 2:57 AM
I first converted the output in to pdf format using the below code.
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.
Then I conveted this output into SO_RAW255 (255 char lentgh) and appended to the table objhex
whose structure is defined like data : objhex LIKE SOLIX OCCURS 0 WITH HEADER LINE.
.
x = PDF_FSIZE / 255.
z = PDF_FSIZE - 255.
DO X times.
if x1 > z .
exit.
endif.
objhex1-line = payslip+x1(255).
append objhex1 to objhex.
*objbin1-line = lv_buffer+x1(255).
*append objbin1 to objbin.
x1 = x1 + 255.
ENDDO.
y = PDF_FSIZE - x1 .
objhex1-line = payslip+x1(y) .
append objhex1 to objhex.
This table then passed to the FM SO_NEW_DOCUMENT_ATT_SEND_API1 as
tables CONTENTS_HEX = objhex.
These is code I changed in the code which I posted as my question.
2009 Apr 20 9:51 AM
Dear Satyanarayana,
I have used almost same as the logic you have given below , iam getting in my inbox as pdf attachment only , however iam not able to open the the pdf attachment which came to my company mail inbox . Could you please let me knwo what i have to do in order get the attachment opened in my personnel id inbox .
As when i trying to open the attachment in the inbox it is giving eror as "Adobe Reader could not open "test.pdf" because it is either not supported
file type or because the file has been damaged". Please help me what i have to do to get the attachment opened.
regards
vamsi.
2009 Apr 20 1:16 PM
Dear Friend
I am herewith attaching my latest code which worked successfully. pl. go through the same.
&----
*& Report ZACG_PSLIPMAIL
*&Y. SATYANARAYANA
&----
*&SALARY SLIP TO EMAIL 18.03.2009
*&
&----
REPORT ZACG_PSLIPMAIL
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,
x TYPE I,
x1 TYPE I,
v_srno like pa0000-pernr.
DATA: BEGIN OF i_pernr OCCURS 0,
pernr LIKE pa0000-pernr,
seqnr LIKE hrpy_rgdir-seqnr,
ABKRS LIKE hrpy_rgdir-ABKRS,
fpper LIKE hrpy_rgdir-fpper,
inper LIKE hrpy_rgdir-inper,
ipend LIKE hrpy_rgdir-ipend,
USRID_LONG LIKE pa0105-USRID_LONG,
nachn LIKE pa0002-nachn,
vorna LIKE pa0002-vorna,
anred LIKE pa0002-anred,
ename LIKE pa0001-ename,
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 : objhex LIKE SOLIX OCCURS 0 WITH HEADER LINE,
objhex1 type solix.
data: y type i ,
z type i,
mname type string.
data: mail_attachment_lines type i,
lv_tablines LIKE sy-tabix.
DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: i_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE,
wa_reclist type somlreci1 .
DATA: doc_chng LIKE sodocchgi1,
l_date(10) TYPE c,
l_time(8) TYPE c.
DATA: objhead TYPE soli_tab.
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.
WRITE: sy-datum TO l_date,
sy-uzeit TO l_time.
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.
CASE v_pabrp.
WHEN '01'.
concatenate 'APRIL' s_date-high+0(4) INTO mname
separated by space.
WHEN '02'.
concatenate 'MAY' s_date-high+0(4) INTO mname
separated by space.
WHEN '03'.
concatenate 'JUNE' s_date-high+0(4) INTO mname
separated by space.
WHEN '04'.
concatenate 'JULY' s_date-high+0(4) INTO mname
separated by space.
WHEN '05'.
concatenate 'AUGUST' s_date-high+0(4) INTO mname
separated by space.
WHEN '06'.
concatenate 'SEPTEMBER' s_date-high+0(4) INTO mname
separated by space.
WHEN '07'.
concatenate 'OCTOBER' s_date-high+0(4) INTO mname
separated by space.
WHEN '08'.
concatenate 'NOVEMEBR' s_date-high+0(4) INTO mname
separated by space.
WHEN '09'.
concatenate 'DECEMBER' s_date-high+0(4) INTO mname
separated by space.
WHEN '10'.
concatenate 'JANUARY' s_date-high+0(4) INTO mname
separated by space.
WHEN '11'.
concatenate 'FEBRUARY' s_date-high+0(4) INTO mname
separated by space.
WHEN '12'.
concatenate 'MARCH' s_date-high+0(4) INTO mname
separated by space.
ENDCASE.
hrpy_rgdir table is getting filled once the payroll is run.
SELECT hrpy_rgdir~pernr
hrpy_rgdir~seqnr
hrpy_rgdir~ABKRS
hrpy_rgdir~fpper
hrpy_rgdir~inper
hrpy_rgdir~ipend
pa0105~USRID_LONG
pa0002~nachn
pa0002~vorna
pa0002~anred
pa0001~ename
FROM hrpy_rgdir
JOIN pa0105
ON hrpy_rgdirpernr = pa0105pernr
AND subty = '0010'
JOIN pa0002
on hrpy_rgdirpernr = pa0002pernr
JOIN pa0001
ON hrpy_rgdirpernr = pa0001pernr
INTO CORRESPONDING FIELDS OF TABLE i_pernr
WHERE inper > v_fpper2
AND inper <= v_fpper1
AND FPPER > v_fpper2
AND FPPer <= v_fpper1
AND hrpy_rgdir~pernr IN s_pernr
AND SRTZA = 'A'
AND pa0105~endda >= s_date-high
AND pa0002~endda >= s_date-high
AND pa0001~endda >= s_date-high
AND pa0001~bukrs = p_bukrs
AND pa0001~werks in s_werks
AND pa0001~BTRTL in s_BTRTL
AND pa0001~ABKRS in s_ABKRS
AND pa0001~persg IN s_persg.
LOOP AT i_pernr.
refresh : objhex , objpack , objtxt ,i_reclist.
clear : objhex1, y,z,x1,x, mail_attachment_lines,
wa_reclist, doc_chng , objhead.
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.
*I_OTF[] = PAYSLIP[].
*
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
IMPORTING
BIN_FILESIZE = V_LEN_IN
TABLES
OTF = I_OTF
LINES = I_TLINE
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
OTHERS = 4.
Convert OTF to PDF
x = PDF_FSIZE / 255.
z = PDF_FSIZE - 255.
DO X times.
if x1 > z .
exit.
endif.
objhex1-line = payslip+x1(255).
append objhex1 to objhex.
*objbin1-line = lv_buffer+x1(255).
*append objbin1 to objbin.
x1 = x1 + 255.
ENDDO.
y = PDF_FSIZE - x1 .
objbin1-line = lv_buffer+z(y) .
*append objbin1 to objbin.
objhex1-line = payslip+x1(y) .
append objhex1 to objhex.
DESCRIBE TABLE objhex LINES mail_attachment_lines.
*mail_attachment_lines = mail_attachment_lines * 255.
*READ TABLE objhex INTO objhex1 INDEX mail_attachment_lines.
doc_chng-obj_name = 'PAYSLIP'.
concatenate 'PAYSLIP FOR' mname INTO doc_chng-obj_descr
separated by space .
*doc_chng-doc_size = ( mail_attachment_lines - 1 ) * 255 + 255.
objtxt-line = 'Dear Sir / Madam,'.
CASE i_pernr-anred.
WHEN 1.
CONCATENATE 'Dear' 'Mr.' i_pernr-vorna i_pernr-nachn
INTO objtxt-line SEPARATED BY ' '.
WHEN 2.
CONCATENATE 'Dear' 'Ms.' i_pernr-vorna i_pernr-nachn
INTO objtxt-line SEPARATED BY ' '.
WHEN 3.
CONCATENATE 'Dear' 'Dr.' i_pernr-vorna i_pernr-nachn
INTO objtxt-line SEPARATED BY ' '.
WHEN OTHERS.
CONCATENATE 'Dear' i_pernr-vorna i_pernr-nachn
INTO objtxt-line SEPARATED BY ' '.
ENDCASE.
CONCATENATE 'Dear' i_pernr-ename
INTO objtxt-line SEPARATED BY space.
APPEND objtxt.
CLEAR objtxt.
APPEND objtxt.
CONCATENATE 'Please find attached payslip for'
mname
INTO objtxt-line SEPARATED BY space.
APPEND objtxt.
CLEAR objtxt.
*--FOR EMPTY LINE
APPEND objtxt.
WRITE: sy-datum TO l_date,
sy-uzeit TO l_time.
CONCATENATE 'SAP System generated statement (on'
l_date
'At'
l_time
'IST) enclosed which does not REQUIRE SIGNATURE.'
INTO objtxt-line
SEPARATED BY space.
APPEND objtxt.
CLEAR objtxt.
*--FOR EMPTY LINE
APPEND objtxt.
objtxt-line = 'Regards,'.
APPEND objtxt.
CLEAR objtxt.
objtxt-line = 'TEAM HR.'.
APPEND objtxt.
CLEAR objtxt.
CASE i_pernr-abkrs.
WHEN '01'.
objtxt-line = 'ACPL Kandivili'.
WHEN '02'.
objtxt-line = 'ACG Pharmapack Pvt Ltd'.
WHEN '03'.
objtxt-line = 'ALCAN INDIA PVT LTD.'.
WHEN '04'.
objtxt-line = 'PAM'.
WHEN '05'.
objtxt-line = 'PAM PAC'.
WHEN '06'.
objtxt-line = 'PAM GLATT'.
WHEN '07'.
objtxt-line = 'AJAS'.
WHEN '08'.
objtxt-line = 'SCITECH'.
WHEN '09'.
objtxt-line = 'ACPL-Shirwal'.
WHEN '10'.
objtxt-line = 'ACPL-Dahanu'.
WHEN '11'.
objtxt-line = 'Corporate - ACG'.
WHEN OTHERS.
objtxt-line = ''.
endcase.
APPEND objtxt.
CLEAR objtxt.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES lv_tablines.
READ TABLE objtxt INDEX lv_tablines TRANSPORTING ALL FIELDS.
doc_chng-doc_size = ( lv_tablines - 1 ) * 255 + STRLEN( objtxt ).
doc_chng-doc_size = ( mail_attachment_lines - 1 ) * 255 +
STRLEN( objtxt ).
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = lv_tablines.
objpack-doc_type = 'RAW'.
APPEND objpack.
Pack to PDF.
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 1.
objpack-body_start = 1.
objpack-body_num = mail_attachment_lines.
objpack-doc_type = 'PDF'.
objpack-obj_name = 'Noti'.
objpack-doc_size = PDF_FSIZE.
objpack-obj_descr = 'payslip.pdf'.
APPEND objpack.
CLEAR: wa_reclist.
REFRESH i_reclist[].
CLEAR wa_reclist.
wa_reclist-receiver = i_pernr-USRID_LONG.
wa_reclist-rec_type = 'U'.
APPEND wa_reclist TO i_reclist.
CLEAR wa_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
tables
packing_list = objpack
OBJECT_HEADER =
CONTENTS_BIN = objbin
CONTENTS_TXT = objtxt
CONTENTS_HEX = objhex
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 I000 WITH 'Error When Sending the File'.
ELSE.
WAIT UP TO 5 SECONDS.
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " SELECT_DATA
2010 May 19 9:37 AM
Dear Satya Narayana,
i want to display that pdf in landscape format.
can you tell me how to do this.
Regards,
Chandu.
2010 Aug 13 10:19 AM
2011 Nov 02 12:31 PM
Hi Satyanarayana,
i have developed the program for sending the payslip as PDF as same as your program.
but i am getting the same errror what ever u have got the earlier.
Can u please help me
2011 Nov 26 7:37 AM
Hi Satyanarayan....
Your code is working fine but i dont want the payslip in that format(means dotted lines an all)...
I want the payslip which will u get after running "pc00_m40_cedt".
please help...