Code: Alles auswählen.
*&---------------------------------------------------------------------*
REPORT ZTA_AUSWERTUNG_BELEGDATEN.
TABLES: bkpf, bseg.
TYPES : BEGIN OF st_beleg,
bukrs TYPE bkpf-bukrs,
belnr TYPE bkpf-belnr,
blart TYPE bkpf-blart,
gjahr TYPE bkpf-gjahr,
bldat TYPE bkpf-bldat,
budat TYPE bkpf-budat,
cpudt TYPE bkpf-cpudt,
xblnr TYPE bkpf-xblnr,
abper TYPE bseg-abper,
END OF st_beleg.
TYPES: it_beleg TYPE TABLE OF st_beleg.
DATA: wa_beleg TYPE st_beleg.
DATA: t_beleg TYPE it_beleg.
*DATA: it_beleg TYPE TABLE OF st_beleg.
*DATA: wa_beleg LIKE LINE OF it_beleg.
TYPES: t_solisti1 TYPE TABLE OF solisti1,
t_sopcklsti1 TYPE TABLE OF sopcklsti1,
t_somlreci1 TYPE TABLE OF somlreci1.
DATA: file LIKE rlgrap-filename.
DATA: BEGIN OF it_file OCCURS 0,
zeile(955),
END OF it_file.
DATA: tab_lines LIKE sy-tabix.
*
DATA: p_sent_to_all TYPE sy-binpt,
p_new_object_id TYPE sofolenti1-object_id,
pt_header TYPE solisti1 OCCURS 1 WITH HEADER LINE,
* pt_content_bin TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE,
pt_content_bin TYPE soli_tab,
pt_content_text TYPE solisti1 OCCURS 10 WITH HEADER LINE,
* pt_content_text TYPE soli_tab,
pt_receiver TYPE t_somlreci1,
pt_packing_list TYPE t_sopcklsti1,
pt_content_hex TYPE solix_tab,
ps_document_data TYPE sodocchgi1,
p_subject TYPE solisti1-line,
g_soli-line TYPE soli-line,
g_solix TYPE solix,
p_content_lines TYPE i,
l_content_lines TYPE i.
DATA: ls_packing_list TYPE sopcklsti1.
DATA: ls_receiver TYPE somlreci1.
DATA: ls_content TYPE solisti1.
DATA: lineno TYPE i,
length TYPE i,
size TYPE i.
DATA: g_num TYPE i.
DATA: g_start TYPE i.
DATA: g_daten TYPE c.
DATA: g_datum TYPE sy-datum.
DATA: g_titel(200) TYPE c VALUE 'Auswertung' .
*-----------------------------------------------------------------------
* SELECTION SCREEN
*-----------------------------------------------------------------------
*
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME
TITLE text-001.
PARAMETERS: pbukrs LIKE bkpf-bukrs OBLIGATORY.
SELECTION-SCREEN SKIP.
PARAMETERS: senden AS CHECKBOX.
SELECTION-SCREEN SKIP.
PARAMETERS: empf TYPE somlreci1-receiver LOWER CASE DEFAULT '########################'.
PARAMETERS: copy TYPE somlreci1-receiver LOWER CASE DEFAULT '##########################'.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN SKIP.
PARAMETERS: bl_copy TYPE somlreci1-receiver DEFAULT '''###########################'.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN END OF BLOCK 1.
****************************************************************************************************
****************************************************************************************************
*LOAD-OF-PROGRAM.
****************************************************************************************************
LOAD-OF-PROGRAM.
g_datum = sy-datum.
g_datum = g_datum - 32. "Einen Monat zurück rechnen**************************************************************************************
****************************************************************************************************
****************************************************************************************************
*START-OF-PROGRAM.
****************************************************************************************************
START-OF-SELECTION.
CLEAR g_daten.
PERFORM daten_sammeln USING g_daten
g_titel.
*
*
PERFORM xls_mail_ini USING g_titel.
PERFORM append_attachment USING 'XLS'
'Belegdaten_Liste'.
PERFORM absenden.
*---------------------------------------------------------------------*
* FORM Daten_sammeln *
*---------------------------------------------------------------------*
* Anhand der Eingebenen Belegnummer Daten selektieren
*
*---------------------------------------------------------------------*
*FORM daten_sammeln USING g_daten
* g_titel.
*---------------------------------------------------------------------*
* FORM Daten_sammeln *
*---------------------------------------------------------------------*
* Anhand der Eingebenen Belegnummer Daten selektieren
*
*---------------------------------------------------------------------*
FORM daten_sammeln USING g_daten
g_titel.
DATA: moff TYPE i,
mlen TYPE i.
SELECT * FROM bkpf INTO CORRESPONDING FIELDS OF wa_beleg
WHERE bukrs = pbukrs
and gjahr = '2012'
and blart = 'ER' OR blart = 'KR'.
SELECT SINGLE abper FROM bseg INTO wa_beleg-abper
WHERE bukrs = pbukrs
and belnr = wa_beleg-belnr.
APPEND wa_beleg TO t_beleg.
CLEAR wa_beleg.
ENDSELECT.
LOOP AT t_beleg INTO wa_beleg WHERE bukrs = pbukrs AND gjahr eq '2012'.
if wa_beleg-abper IS INITIAL.
CONCATENATE 'Per:' wa_beleg-budat+5(1) INTO wa_beleg-abper.
ENDIF.
WRITE:/ pbukrs UNDER 'Buchungskreis',
wa_beleg-belnr UNDER 'Belegnummer',
wa_beleg-gjahr UNDER 'Geschaeftsjahr',
wa_beleg-blart UNDER 'Belegart',
wa_beleg-bldat UNDER 'Belegdatum',
wa_beleg-budat UNDER 'Buchungstdatum',
wa_beleg-abper UNDER 'Buchungsperiode',
wa_beleg-cpudt UNDER 'Erfassungsdatum',
wa_beleg-xblnr UNDER 'Referenznummer'.
ENDLOOP.
ENDFORM.
TOP-OF-PAGE.
FORMAT COLOR COL_POSITIVE.
SKIP TO LINE 4.
ULINE.
WRITE:/ 'Buchungskreis', 15'Belegnummer', 30'Geschaeftsjahr', 45'Belegart',60'Belegdatum', 72'Buchungsdatum', 90'Buchungsperiode',
110'Erfassungsdatum',135'Referenznummer'.
ULINE.
*---------------------------------------------------------------------*
* FORM XLS_MAIL *
*---------------------------------------------------------------------*
* Die Tabelle wird mit den ausgewählten Feldern als XLS Datei
* aufbereitet und per E-Mail verschickt.
* Felder:
* titel: Beschreibungstext der E-Mail (Titel)
* Empfaenger: Empfängerliste durch Leerzeichen getrennt (SAP
* USERNAME).
* Mailtyp: B = SAP Mail
* Express: X = Expressmail!
* header: X = Kopfzeile mit ausgeben!
* anhang_text = Text des Attachments
* description = Beschreibung - welche Liste
*---------------------------------------------------------------------*
FORM xls_mail_ini USING g_titel.
DESCRIBE TABLE pt_content_text LINES tab_lines.
READ TABLE pt_content_text INDEX tab_lines.
* ps_document_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( pt_content_text ).
ps_document_data-doc_size = ( tab_lines - 1 ) * 510 + STRLEN( pt_content_text ).
ls_packing_list-transf_bin = ''.
ls_packing_list-head_start = 1.
ls_packing_list-head_num = 0.
ls_packing_list-body_start = 1.
ls_packing_list-body_num = tab_lines.
ls_packing_list-doc_type = 'RAW'.
APPEND ls_packing_list TO pt_packing_list.
CLEAR ls_packing_list.
ps_document_data-obj_descr = g_titel.
ls_receiver-receiver = bl_copy.
ls_receiver-blind_copy = 'X'.
* receiver address type (internet address)
ls_receiver-rec_type = 'U'.
* communication type (send via internet)
* ls_receiver-com_type = 'INT'.
APPEND ls_receiver TO pt_receiver.
CLEAR: ls_receiver.
IF senden = 'X'.
ls_receiver-receiver = empf.
ls_receiver-rec_type = 'U'.
APPEND ls_receiver TO pt_receiver.
CLEAR: ls_receiver.
ls_receiver-receiver = copy.
ls_receiver-copy = 'X'.
ls_receiver-rec_type = 'U'.
APPEND ls_receiver TO pt_receiver.
CLEAR: ls_receiver.
ENDIF.
ENDFORM. " sendMail
*&--------------------------------------------------------------------*
*& Form Absenden
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
form absenden.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = ps_document_data
put_in_outbox = 'X'
commit_work = 'X'
importing
sent_to_all = p_sent_to_all
new_object_id = p_new_object_id
tables
packing_list = pt_packing_list
object_header = pt_header
* contents_bin = pt_content_bin
contents_txt = pt_content_text
contents_hex = pt_content_hex
* OBJECT_PARA =
* OBJECT_PARB =
receivers = pt_receiver
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
.
write:/.
if sy-subrc <> 0.
write: 'FEHLER bei SENDMAIL:' ,sy-subrc.
exit.
else.
write: 'Mail wurde versendet'.
endif.
endform . "Absenden
*&--------------------------------------------------------------------*
*& Form append_attachment
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
form append_attachment using anhang_name
anhang_text.
data: t(200).
data: l_delimiter type x value '09'.
data: l_char1 type string.
data: l_char2 type string.
data: l_char3 type string.
data: l_char4 type string.
data: l_init(1) type c.
data: lv_mime_type type c value 'APPLICATION/MSEXCEL; charset=UTF-8',
lv_row_text type string,
lv_row_hex type xstring.
constants:c_tab type c value cl_abap_char_utilities=>horizontal_tab.
constants:c_newline type c value cl_abap_char_utilities=>newline.
constants:c_cr_lf type c value cl_abap_char_utilities=>cr_lf.
LOOP AT t_beleg INTO wa_beleg.
CLEAR pt_content_bin.
IF l_init IS INITIAL.
l_init = 'X'.
CONCATENATE 'Bukrs' 'Belnr' 'Geschaeftsjahr'
'Belegart' 'Belegdatum' 'Buchungsdatum' 'Buchungsperide' 'Erfassungsdatum' 'Referenznummer'
c_cr_lf
INTO g_soli-line SEPARATED BY c_tab.
ELSE.
concatenate pbukrs wa_beleg-belnr wa_beleg-gjahr wa_beleg-blart wa_beleg-bldat wa_beleg-budat wa_beleg-abper wa_beleg-cpudt wa_beleg-xblnr
c_cr_lf
into g_soli-line separated by c_tab.
ENDIF.
CONCATENATE g_soli-line c_newline INTO g_soli-line.
MOVE g_soli-line TO lv_row_text.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = lv_row_text
mimetype = lv_mime_type
IMPORTING
buffer = lv_row_hex.
MOVE lv_row_hex TO g_solix-line.
APPEND g_solix TO pt_content_hex.
ENDLOOP.
* Creating the document to be sent
* ps_document_data-obj_descr = anhang_text.
DESCRIBE TABLE pt_content_hex LINES tab_lines.
pt_header = 'Belegdaten.XLS'. APPEND pt_header.
* Creating the document attachment
ls_packing_list-transf_bin = 'X'.
ls_packing_list-head_start = 1.
ls_packing_list-head_num = 1.
ls_packing_list-body_start = 1.
ls_packing_list-body_num = tab_lines.
ls_packing_list-doc_type = 'XLS'.
ls_packing_list-obj_name = anhang_name.
ls_packing_list-obj_descr = anhang_text.
* ls_packing_list-doc_size = tab_lines * 255.
ls_packing_list-doc_size = tab_lines * 510.
APPEND ls_packing_list TO pt_packing_list.
ENDFORM.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag:
jeyloeso
Code: Alles auswählen.
refresh lt_gjahr.
loop at so_datum assigning <ls_datum>.
append initial line to lt_gjahr assigning <ls_gjahr>.
move-corresponding <ls_datum> to <ls_gjahr>.
endloop.
Code: Alles auswählen.
IF l_init IS INITIAL.
l_init = 'X'.
CONCATENATE 'Bukrs' 'Belnr' 'Geschaeftsjahr'
'Belegart' 'Belegdatum' 'Buchungsdatum' 'Buchungsperiode' 'Erfassungsdatum' 'Referenznummer'
c_cr_lf
INTO g_soli-line SEPARATED BY c_tab.
ELSE.
concatenate pbukrs wa_beleg-belnr wa_beleg-gjahr wa_beleg-blart wa_beleg-bldat wa_beleg-budat wa_beleg-abper wa_beleg-cpudt wa_beleg-xblnr
c_cr_lf
into g_soli-line separated by c_tab.
ENDIF.
CONCATENATE g_soli-line c_newline INTO g_soli-line.
MOVE g_soli-line TO lv_row_text.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = lv_row_text
mimetype = lv_mime_type
IMPORTING
buffer = lv_row_hex.
MOVE lv_row_hex TO g_solix-line.
APPEND g_solix TO pt_content_hex.
DESCRIBE TABLE pt_content_hex LINES tab_lines.
pt_header = 'Belegdaten.XLS'. APPEND pt_header.
* Creating the document attachment
ls_packing_list-transf_bin = 'X'.
ls_packing_list-head_start = 1.
ls_packing_list-head_num = 1.
ls_packing_list-body_start = 1.
ls_packing_list-body_num = tab_lines.
ls_packing_list-doc_type = 'XLS'.
ls_packing_list-obj_name = anhang_name.
ls_packing_list-obj_descr = anhang_text.
* ls_packing_list-doc_size = tab_lines * 255.
ls_packing_list-doc_size = tab_lines * 510.
APPEND ls_packing_list TO pt_packing_list.