Code: Alles auswählen.
REPORT Z_CV_ABGLEICH_BOM.
TYPE-POOLS:
cpsc. " Definitionen zur Selektion von Plan/Stücklisten Objekten
TABLES: mast.
TYPES: begin of abg_bom,
MATNR TYPE ZCV_BOM_ABG-MATNR,
WERKS TYPE ZCV_BOM_ABG-WERKS,
POSNR TYPE ZCV_BOM_ABG-POSNR,
IDNRK TYPE ZCV_BOM_ABG-IDNRK,
OJTXB TYPE ZCV_BOM_ABG-OJTXB,
AENNR TYPE ZCV_BOM_ABG-AENNR,
stlal TYPE mast-stlal,
text Type C LENGTH 50,
ZEICHEN TYPE C LENGTH 1,
end of abg_bom.
DATA: it_abg_bom TYPE TABLE OF abg_bom.
DATA: wa_abg_bom LIKE LINE OF it_abg_bom.
DATA: ld_fl_warning TYPE CAPIFLAG-FLWARNING,
it_t_stpo TYPE STANDARD TABLE OF STPO_API02,
wa_t_stpo LIKE LINE OF it_t_stpo,
it_t_stko TYPE STANDARD TABLE OF STKO_API02,
wa_t_stko LIKE LINE OF it_t_stko,
lv_matnr_n TYPE ZCV_BOM_ABG-MATNR,
lv_werks TYPE ZCV_BOM_ABG-werks,
lv_posnr TYPE ZCV_BOM_ABG-posnr,
lv_idnrk TYPE ZCV_BOM_ABG-idnrk,
lv_idnrk_new TYPE ZCV_BOM_ABG-idnrk,
lv_idnrk_old TYPE ZCV_BOM_ABG-idnrk,
lv_ojtxb TYPE ZCV_BOM_ABG-ojtxb,
lv_aennr TYPE ZCV_BOM_ABG-aennr,
lv_zeichen TYPE C LENGTH 1,
lv_matnr LIKE mara-matnr,
lv_werk LIKE mast-werks,
lv_plus TYPE C LENGTH 1,
lv_minus TYPE C LENGTH 1.
Data: it_TOPMAT LIKE CSTMAT.
DATA: it_DSTST LIKE CSDATA-XFELD.
DATA: it_STB TYPE TABLE OF STPOX.
DATA: it_MATCAT TYPE TABLE OF CSCMAT.
DATA: wa_stb LIKE LINE OF it_STB.
DATA: it_ZCV_BOM_ABG TYPE TABLE OF ZCV_BOM_ABG.
DATA: wa_ZCV_BOM_ABG LIKE LINE OF it_ZCV_BOM_ABG.
DATA: it_ZCV_BOM_ABG_old TYPE TABLE OF ZCV_BOM_ABG.
DATA: it_ZCV_BOM_ABG_new TYPE TABLE OF ZCV_BOM_ABG.
DATA: wa_ZCV_BOM_ABG_old LIKE LINE OF it_ZCV_BOM_ABG_old.
DATA: wa_ZCV_BOM_ABG_new LIKE LINE OF it_ZCV_BOM_ABG_new.
Data: it_mast Type TABLE OF mast.
DATA: wa_mast Like Line of it_mast.
DATA: lv_stlal TYPE mast-stlal.
data: binary_content type solix_tab.
data: size type so_obj_len.
DATA:
gs_ZCV_BOM_ABG_old TYPE STANDARD TABLE OF ZCV_BOM_ABG,
gs_ZCV_BOM_ABG_new TYPE STANDARD TABLE OF ZCV_BOM_ABG,
gs_ZCV_BOM_ABG_del TYPE STANDARD TABLE OF ZCV_BOM_ABG,
gs_ZCV_BOM_ABG_add TYPE STANDARD TABLE OF ZCV_BOM_ABG,
gs_ZCV_BOM_ABG_mod TYPE STANDARD TABLE OF ZCV_BOM_ABG,
no_change TYPE char1,
key_len TYPE i.
key_len = 5.
DATA: gr_send_request TYPE REF TO cl_bcs.
DATA: gr_document TYPE REF TO cl_document_bcs.
DATA: gr_sender TYPE REF TO cl_sapuser_bcs.
DATA: gr_receiver TYPE REF TO if_recipient_bcs.
DATA: gt_body TYPE soli_tab.
DATA: g_subject TYPE so_obj_des.
DATA: l_line TYPE string.
DATA: textzeile LIKE soli.
DATA: lv_line TYPE string.
*DATA: lv_idnrk TYPE stpo-idnrk.
DATA: gv_text TYPE bcsy_text.
DATA: wa_email LIKE zcv_email.
DATA: it_email TYPE TABLE OF zcv_email.
DATA: gv_email TYPE adr6-smtp_addr.
CONSTANTS:
gc_raw TYPE char03 VALUE 'RAW'.
DATA:
l_version TYPE string, " Version
l_flavour TYPE fpm_file_name, " Flavour
l_sent_to_all TYPE os_boolean,
l_contents_line TYPE xstring, "vac53733 10642
l_i TYPE sood-objlen,
l_file_type TYPE salv_bs_constant,
l_count TYPE so_obj_len," string length of email body
l_count1 TYPE i,
w_line TYPE abg_bom. "work area for data table
DATA: i_fldcat TYPE STANDARD TABLE OF lvc_s_fcat
INITIAL SIZE 0, "Field catalog
i_text TYPE bcsy_text, "report internal table
i_binary_content TYPE solix_tab,
i_att_head TYPE soli_tab,
i_obj_bin TYPE solix_tab, "Binary Internal Table
l_text_line TYPE soli,
l_filename TYPE string.
* DATA: i_line TYPE STANDARD TABLE OF ty_line INITIAL SIZE 0.
DATA: lo_data TYPE REF TO data.
DATA: lo_result_data TYPE REF TO cl_salv_ex_result_data_table.
FIELD-SYMBOLS: <fs_fieldcat> TYPE lvc_s_fcat. "Field catalo
* Mail wird verschickt, wenn es änderungen gibt.
IF lv_plus EQ '+' or lv_minus EQ '-'.
SELECT * FROM zcv_email
INTO wa_email.
APPEND wa_email to it_email.
ENDSELECT.
CLEAR wa_email.
SORT it_abg_bom STABLE BY MATNR ZEICHEN.
* Aufbau Text
IF it_abg_bom IS NOT INITIAL.
CLEAR i_fldcat[].
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'MATNR'. "Fieldname
<fs_fieldcat>-outputlen = 18. "Output length
<fs_fieldcat>-dd_outlen = 18. "Input length
<fs_fieldcat>-reptext = 'Materialnummer'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'WERKS'. "Fieldname
<fs_fieldcat>-outputlen = 4. "Output length
<fs_fieldcat>-dd_outlen = 4. "Input length
<fs_fieldcat>-reptext = 'Werkr'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'POSNR'. "Fieldname
<fs_fieldcat>-outputlen = 4. "Output length
<fs_fieldcat>-dd_outlen = 4. "Input length
<fs_fieldcat>-reptext = 'Nummer der Stücklistenposition'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'IDNRK'. "Fieldname
<fs_fieldcat>-outputlen = 18. "Output length
<fs_fieldcat>-dd_outlen = 18. "Input length
<fs_fieldcat>-reptext = 'Stücklistenkomponente'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'OJTXB'. "Fieldname
<fs_fieldcat>-outputlen = 40. "Output length
<fs_fieldcat>-dd_outlen = 40. "Input length
<fs_fieldcat>-reptext = 'Objektkurztext'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'AENNR'. "Fieldname
<fs_fieldcat>-outputlen = 12. "Output length
<fs_fieldcat>-dd_outlen = 12. "Input length
<fs_fieldcat>-reptext = 'Aenderungsnummer'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'STLAL'. "Fieldname
<fs_fieldcat>-outputlen = 2. "Output length
<fs_fieldcat>-dd_outlen = 2. "Input length
<fs_fieldcat>-reptext = 'Stücklistenalternative'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'TEXT'. "Fieldname
<fs_fieldcat>-outputlen = 50. "Output length
<fs_fieldcat>-dd_outlen = 50. "Input length
<fs_fieldcat>-reptext = 'Text'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
APPEND INITIAL LINE TO i_fldcat
ASSIGNING <fs_fieldcat>.
<fs_fieldcat>-no_out = ''. "Hide
<fs_fieldcat>-fieldname = 'FLAG'. "Fieldname
<fs_fieldcat>-outputlen = 1. "Output length
<fs_fieldcat>-dd_outlen = 1. "Input length
<fs_fieldcat>-reptext = 'Flag'. "Column text
<fs_fieldcat>-edit = 'X'. "Edit
APPEND INITIAL LINE TO i_fldcat.
* GET REFERENCE OF i_line INTO lo_data. it_abg_bom
GET REFERENCE OF it_abg_bom INTO lo_data.
CLEAR: lo_result_data.
lo_result_data =
cl_salv_ex_util=>factory_result_data_table(
r_data = lo_data " internal table data reference
t_fieldcatalog = i_fldcat"field cat
).
* get the version from Abstract Super Class for All Transformations
CLEAR: l_version.
l_version = cl_salv_bs_a_xml_base=>get_version( ).
* Get the file Type
* value 10 for XLSX file type
CLEAR: l_file_type.
l_file_type = if_salv_bs_xml=>c_type_xlsx.
* Get the flavour export
* Flavor for Complete ALV XML
CLEAR: l_flavour.
l_flavour = if_salv_bs_c_tt=>c_tt_xml_flavour_export.
* Transformation of data to XSTRING
CLEAR: l_contents_line.
CALL METHOD cl_salv_bs_tt_util=>if_salv_bs_tt_util~transform
EXPORTING
xml_type = l_file_type
xml_version = l_version
r_result_data = lo_result_data
xml_flavour = l_flavour
gui_type = if_salv_bs_xml=>c_gui_type_gui
IMPORTING
xml = l_contents_line.
* Converting the table contents from xstring to binary
CLEAR i_obj_bin.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = l_contents_line
IMPORTING
output_length = l_count1
TABLES
binary_tab = i_obj_bin.
APPEND LINES OF i_obj_bin TO i_binary_content.
* Four character file extension '.XLSX' is set
l_filename = 'BoM_AENDERUNGEN.XLSX'. " provide the extension in file name
* You can set a file name with a freely selectable file name extension
* separately from the document description. For this, use the header table
* of the document or the attachment with the key word '&SO_FILENAME='.
CONCATENATE '&SO_FILENAME='
l_filename
INTO
l_text_line.
APPEND l_text_line TO i_att_head.
*Calculate the xstring length
l_i = xstrlen( l_contents_line ).
* Mail wird an alle beteiligten verschickt.
* Loop um Mails zu versenden.
LOOP AT it_email INTO wa_email.
gv_email = wa_email-receiver.
textzeile = 'Bitte Anhang auf BoM - Anpassung prüfen.'.
APPEND textzeile TO gv_text.
*<% = abap_var%>
* Sendeauftrag anlegen
gr_send_request = cl_bcs=>create_persistent( ).
* Betreff
g_subject = 'ACHTUNG: BoM - Änderungen'.
** Text für den Mailbody
*HTML-Mail anlegen
gr_document = cl_document_bcs=>create_document( i_type = gc_raw
i_text = gv_text
i_length = '12'
i_subject = g_subject ).
* Create the attachment reference.
CALL METHOD gr_document->add_attachment
EXPORTING
i_attachment_type = 'BIN' " type of data
i_attachment_subject = 'Stücklisten Aenderungen'
i_attachment_size = l_i " XTRING length of l_contents_line
i_att_content_hex = i_binary_content
i_attachment_header = i_att_head. "file details
* Dokument übergeben
gr_send_request->set_document( gr_document ).
* Absender
gr_sender = cl_sapuser_bcs=>create( sy-uname ).
gr_send_request->set_sender( gr_sender ).
* Empfänger
gr_receiver = cl_cam_address_bcs=>create_internet_address( gv_email ).
gr_send_request->add_recipient( gr_receiver ).
* Sofort senden - nicht in SCOT Queue
gr_send_request->set_send_immediately( abap_true ).
* Senden
gr_send_request->send( ).
COMMIT WORK.
ENDLOOP.
ENDIF.
ENDIF.
Code: Alles auswählen.
* store data in kpro
lv_vsi_profile = cl_bcs_vsi_profile=>get_profile( ).
if lv_vsi_profile is initial.
call function 'SDOK_PHIO_STORE_CONTENT'
exporting
object_id = ls_phio
text_as_stream = 'X'
tables
file_access_info = lt_kpro_info
file_content_ascii = lt_kpro_asc
file_content_binary = lt_kpro_bin
exceptions
not_existing = 1
not_allowed = 2
not_authorized = 3
no_content = 4
bad_storage_type = 5
blocked_by_policy = 6
others = 10.
Folgende Benutzer bedankten sich beim Autor charlie01 für den Beitrag:
a-dead-trousers