Вы находитесь на странице: 1из 7

*&---------------------------------------------------------------------*

*& Report ZBS_EXCEL


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT

ZBS_EXCEL LINE-COUNT 110.

*REPORT ZMM_PURCHASE_ORDER_RPT LINE-COUNT 110.


*---------------------------------------------------------------------*
*IMPLICIT WORK AREA DECLARATION
*---------------------------------------------------------------------*
TABLES EKKO.
*&---------------------------------------------------------------------*
*&
*&STRUCTURE DECLARATION OF
*&---------------------------------------------------------------------*
TYPES: BEGIN OF X_EKKO,
EBELN TYPE EKKO-EBELN,
BUKRS TYPE EKKO-BUKRS,
BSTYP TYPE EKKO-BSTYP,
BSART TYPE EKKO-BSART,
BSAKZ TYPE EKKO-BSAKZ,
ERNAM TYPE EKKO-ERNAM,
LIFNR TYPE EKKO-LIFNR,
EKORG TYPE EKKO-EKORG,
EKGRP TYPE EKKO-EKGRP,
BEDAT TYPE EKKO-BEDAT,
END OF X_EKKO.
*&---------------------------------------------------------------------*
*&
*& WORK AREA DECLARATION
*&---------------------------------------------------------------------*
DATA WA_EKKO TYPE X_EKKO.
*&---------------------------------------------------------------------*
*&
*&INTERNAL TABLE DECLARATION
*&---------------------------------------------------------------------*
DATA T_EKKO TYPE TABLE OF X_EKKO.

*&---------------------------------------------------------------------*
*&
*&SELECT OPTION DECLARATION

*&---------------------------------------------------------------------*
SELECT-OPTIONS S_EBELN FOR EKKO-EBELN.
SELECTION-SCREEN SKIP.
*PARAMETERS P_FILE TYPE STRING.
PARAMETERS: P_FILE1 LIKE RLGRAP-FILENAME.
*AT SELECTION-SCREEN on VALUE-REQUEST FOR p_file.
DATA P_FILE TYPE STRING.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE1.

*
*
*
*

CALL FUNCTION 'F4_FILENAME'


EXPORTING
PROGRAM_NAME
=
DYNPRO_NUMBER
=
FIELD_NAME
=
IMPORTING
FILE_NAME
= P_FILE1.
IF SY-SUBRC = 0.
P_FILE = P_FILE1.

ENDIF.
*&---------------------------------------------------------------------*
*&
*& START OF SELECTION EVENT : BEGINNING OF EXECUTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
*&---------------------------------------------------------------------*
*&
Form GET_DATA
*&---------------------------------------------------------------------*
FORM GET_DATA .
SELECT * FROM EKKO INTO CORRESPONDING FIELDS OF
TABLE T_EKKO WHERE EBELN IN S_EBELN.
ENDFORM.

" GET_DATA

*&---------------------------------------------------------------------*
*&
Form DISPLAY_DATA
*&---------------------------------------------------------------------*
FORM DISPLAY_DATA .
WRITE:/1 SY-VLINE,3 'EBELN',20 SY-VLINE, 23 'BUKRS',30 SY-VLINE,
33'BSTYP',42 SY-VLINE, 43 'BSART',52 SY-VLINE, 53'BEDAT',
65 SY-VLINE, 67 'ERNAM',78 SY-VLINE, 81'LIFNR', 90 SY-VLINE,

93'EKORG',100 SY-VLINE, 103 'EKGRP',110 SY-VLINE.


ULINE.
LOOP AT T_EKKO INTO WA_EKKO.
WRITE:/1 SY-VLINE,3 WA_EKKO-EBELN,
20 SY-VLINE,WA_EKKO-BUKRS,
30 SY-VLINE,WA_EKKO-BSTYP,
42 SY-VLINE,WA_EKKO-BSART,
52 SY-VLINE,WA_EKKO-BEDAT,
65 SY-VLINE,WA_EKKO-ERNAM,
78 SY-VLINE,WA_EKKO-LIFNR,
90 SY-VLINE,WA_EKKO-EKORG,
100 SY-VLINE,WA_EKKO-EKGRP,
110 SY-VLINE.

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

ULINE.
ENDLOOP.
PERFORM MAIL_SEND.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE
FILENAME
FILETYPE
APPEND
WRITE_FIELD_SEPARATOR
HEADER
TRUNC_TRAILING_BLANKS
WRITE_LF
COL_SELECT
COL_SELECT_MASK
DAT_MODE
CONFIRM_OVERWRITE
NO_AUTH_CHECK
CODEPAGE
IGNORE_CERR
REPLACEMENT
WRITE_BOM
TRUNC_TRAILING_BLANKS_EOL
WK1_N_FORMAT
WK1_N_SIZE
WK1_T_FORMAT
WK1_T_SIZE
IMPORTING
FILELENGTH
TABLES
DATA_TAB
FIELDNAMES
EXCEPTIONS

=
= P_FILE
= 'ASC'
= ' '
= 'X'
= '00'
= ' '
= 'X'
= ' '
= ' '
= ' '
= ' '
= ' '
= ' '
= ABAP_TRUE
= '#'
= ' '
= 'X'
= ' '
= ' '
= ' '
= ' '
=
= T_EKKO
=

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.

ENDFORM.
" DISPLAY_DATA
*&---------------------------------------------------------------------*
*&
Form MAIL_SEND
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM MAIL_SEND .
DATA: DOCDATA LIKE SODOCCHGI1,
OBJPACK LIKE SOPCKLSTI1 OCCURS 1 WITH HEADER LINE,
OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
OBJBIN1 LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
OBJBIN2 LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
OBJBIN_FINAL LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
RECLIST LIKE SOMLRECI1 OCCURS 1 WITH HEADER LINE,
TAB_LINES TYPE SY-TABIX,
N TYPE I.

CONSTANTS: CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF ,


CON_TAB TYPE C VALUE
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB ,
CON_TAB1 TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>VERTICAL_TAB.
DATA: C_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
C_RET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
DOCDATA-OBJ_NAME = 'Mail_Excel_File'.
DOCDATA-OBJ_DESCR = 'Sample Mail'.
OBJTXT
APPEND
OBJTXT
APPEND
OBJTXT
APPEND
OBJTXT
APPEND
OBJTXT
APPEND
OBJTXT
APPEND

= 'Dear Sir/Madam'.
OBJTXT.
= ' '.
OBJTXT.
= ' Kindly find attached documents '.
OBJTXT.
= ' '.
OBJTXT.
= 'Thanks and Regards'.
OBJTXT.
= 'Process Weaver'.
OBJTXT.

LOOP AT T_EKKO INTO WA_EKKO.


CONCATENATE WA_EKKO-BUKRS WA_EKKO-BSTYP WA_EKKO-BSART WA_EKKO-BEDAT WA_EKK
O-ERNAM
WA_EKKO-LIFNR WA_EKKO-EKORG WA_EKKO-EKGRP
INTO OBJBIN1 SEPARATED BY C_TAB.
CONCATENATE CON_CRET OBJBIN1 INTO OBJBIN1.
*
APPEND iattach.
APPEND OBJBIN1 ."to objbin_final.
ENDLOOP.
OBJBIN_FINAL[] = OBJBIN1[].
*BREAK-POINT.
DOCDATA-DOC_SIZE = 1.
* Populate the subject/generic message attributes
DOCDATA-OBJ_LANGU = SY-LANGU.
DOCDATA-OBJ_NAME = 'SAPRPT'.
DOCDATA-OBJ_DESCR = 'Sample Report' .
* Fill the document data and get size of attachment
CLEAR DOCDATA.
DATA XCNT TYPE I.
READ TABLE OBJTXT INDEX XCNT.
DOCDATA-DOC_SIZE =
( XCNT - 1 ) * 255 + STRLEN( OBJTXT ).
DOCDATA-OBJ_LANGU = SY-LANGU.
DOCDATA-OBJ_NAME
= 'SAPRPT'.
DOCDATA-OBJ_DESCR = 'Sample Report'.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.


READ TABLE OBJTXT INDEX TAB_LINES.
DOCDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).
CLEAR OBJPACK-TRANSF_BIN.
OBJPACK-TRANSF_BIN = SPACE.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 0.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'RAW'.
APPEND OBJPACK.
*CLEAR objpack-transf_bin.
* objpack-transf_bin = 'X'.
* objpack-head_start = 1.
* objpack-head_num = 0.
* objpack-body_start = 1.
* DESCRIBE TABLE objbin_final LINES objpack-body_num.
** objpack-body_num = tab_lines.
* objpack-doc_type = '.XLS'.
* APPEND objpack.
**************************Attachment
N = 1.
CLEAR TAB_LINES.
DESCRIBE TABLE OBJBIN_FINAL LINES TAB_LINES.
OBJPACK-DOC_SIZE = TAB_LINES * 255.
OBJPACK-TRANSF_BIN = 'X'.
OBJPACK-HEAD_START = 1.
OBJPACK-HEAD_NUM = 1.
OBJPACK-BODY_START = 1.
OBJPACK-BODY_NUM = TAB_LINES.
OBJPACK-DOC_TYPE = 'XLS'.
DOCDATA-OBJ_NAME = 'Sample Mail'.
OBJPACK-OBJ_DESCR = 'Sample Mail'.
APPEND OBJPACK.
*wa_disp
* LOOP AT it_disp INTO wa_disp WHERE chk = 'X'.
RECLIST-RECEIVER = 'balajighanta87@gmail.com'.
RECLIST-REC_TYPE = 'U'.
RECLIST-EXPRESS = 'X'.
RECLIST-COM_TYPE = 'INT'.
RECLIST-NOTIF_DEL = 'X'.
RECLIST-NOTIF_NDEL = 'X'.
APPEND RECLIST.
* ENDLOOP.
IF RECLIST[] IS INITIAL.
MESSAGE 'Please Choose The Vendor Email Id' TYPE 'I' DISPLAY LIKE 'E'.
EXIT.

ENDIF.

*Send the e-mail


CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA
= DOCDATA
PUT_IN_OUTBOX
= 'X'
COMMIT_WORK
= 'X'
TABLES
PACKING_LIST
= OBJPACK[]
CONTENTS_BIN
= OBJBIN_FINAL[]
CONTENTS_TXT
= OBJTXT
RECEIVERS
= 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.
COMMIT WORK.
IF SY-SUBRC = 0.
MESSAGE 'Email has been sent Successfully!!!' TYPE 'S'.
LEAVE TO SCREEN 0.
ENDIF.
"process_email
*ENDFORM.
" SEND_MAIL
ENDFORM.
" MAIL_SEND