Hier gefunden: https://erlebe-software.de/sap-entwickl ... _too_long/...Da wir dem Funktionsbaustein REUSE_ALV_FIELDCATALOG_MERGE den Namen der internen Tabelle und des Reports mitgeben, liest der Baustein das komplette Coding, intern in eine interne Tabelle. Deren Zeilen haben aber eine maximale Zeilenlänge von 72 Zeichen. Besitzt unser Report nun Zeilen, die länger als 72 Zeichen sind, tritt der Laufzeitfehler auf....
Folgende Benutzer bedankten sich beim Autor DeathAndPain für den Beitrag:
cuncon
Die ALV gibt's schon seit (fast) immer und ewig.DeathAndPain hat geschrieben:Das muss in irgendeinem 4er-Release gewesen sein. Unter 3.1i gab es nach meiner Erinnerung noch keine ALVs, und später war die erlaubte Zeilenlänge größer.
Was mich irritiert, ist die Tatsache, dass die Funktionsgruppe SALV, zu der dieser Baustein gehört, laut Funktionsbausteineigenschaften schon am 16.07.1997 intern freigegeben worden ist. Das wäre noch vor 3.1i gewesen. Gab es damals doch schon ALVs, und sie sind mir nur komplett entgangen!? Im Standard habe ich jedenfalls keine gesehen.
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag:
cuncon
Folgende Benutzer bedankten sich beim Autor black_adept für den Beitrag (Insgesamt 2):
cuncon • DeathAndPain
Folgende Benutzer bedankten sich beim Autor a-dead-trousers für den Beitrag:
cuncon
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report ZTEST88 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZTEST88 .
INCLUDE <icon>.
DATA it_data TYPE TABLE OF sflight.
DATA lv_layperm(1) VALUE space.
DATA dyname TYPE d020s-prog VALUE sy-repid.
DATA dynumb TYPE d020s-dnum VALUE '0100'.
* Grid Parameter
DATA: ok_code LIKE sy-ucomm,
g_container TYPE scrfname VALUE 'CC1',
grid1 TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container,
g_splitter TYPE REF TO cl_gui_splitter_container,
* Reference to html container
g_html_cntrl TYPE REF TO cl_gui_html_viewer,
* Reference to document
g_dyndoc_id TYPE REF TO cl_dd_document,
* Reference to html container
g_parent_html TYPE REF TO cl_gui_container,
* Reference to grid container
g_parent_grid TYPE REF TO cl_gui_container,
is_variant TYPE disvariant.
*--- Field catalog table
DATA gt_fieldcat TYPE lvc_t_fcat WITH HEADER LINE.
*--- Layout structure
DATA gs_layout TYPE lvc_s_layo .
* LT_EXCLUDE => Tabelle zum Ausschliessen von Funktionen innerhalb
* der Toolbar des ALV-Grid
DATA: lt_exclude TYPE ui_functions,
ls_exclude TYPE ui_func.
*---------------------------------------------------------------------*
* MAIN *
*---------------------------------------------------------------------*
INITIALIZATION.
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
*--To add new functional buttons to the ALV toolbar
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive ,
*--To implement user commands
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm ,
top_of_page FOR EVENT top_of_page "event handler
OF cl_gui_alv_grid
IMPORTING e_dyndoc_id.
*--To be triggered before user commands
*handle_before_user_command
*FOR EVENT before_user_command OF cl_gui_alv_grid
*IMPORTING e_ucomm.
*--Double-click control
*handle_double_click
*FOR EVENT double_click OF cl_gui_alv_grid
*IMPORTING e_row e_column es_row_no.
PRIVATE SECTION.
ENDCLASS. "lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION .
*--Handle Toolbar
METHOD handle_toolbar.
PERFORM handle_toolbar USING e_object e_interactive .
ENDMETHOD . "handle_toolbar
*--Handle User Command
METHOD handle_user_command .
PERFORM handle_user_command USING e_ucomm .
ENDMETHOD. "handle_user_command
*--Handle Before User Command JG
* METHOD handle_before_user_command .
* PERFORM handle_before_user_command USING e_ucomm .
* ENDMETHOD . "handle_before_user_command
METHOD top_of_page. "implementation
* Top-of-page event
PERFORM event_top_of_page USING g_dyndoc_id.
ENDMETHOD. "top_of_page
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA gr_event_handler TYPE REF TO lcl_event_handler .
* Eingabe und Auswertung ---------------------------------------------*
START-OF-SELECTION.
SELECT * FROM sflight INTO TABLE it_data.
CALL SCREEN 100.
EXIT.
*&---------------------------------------------------------------------*
*& Module PBO OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container.
* Create TOP-Document
CREATE OBJECT g_dyndoc_id
EXPORTING
style = 'ALV_GRID'.
* Create Splitter for custom_container
CREATE OBJECT g_splitter
EXPORTING
parent = g_custom_container
rows = 2
columns = 1.
* Split the custom_container to two containers and move the reference
* to receiving containers g_parent_html and g_parent_grid
"i am allocating the space for grid and top of page
CALL METHOD g_splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = g_parent_html.
CALL METHOD g_splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = g_parent_grid.
* Set height for g_parent_html
CALL METHOD g_splitter->set_row_height
EXPORTING
id = 1
height = 10.
CREATE OBJECT grid1
EXPORTING
i_parent = g_parent_grid.
*--Creating an instance for the event handler
CREATE OBJECT gr_event_handler .
*----Preparing field catalog.
PERFORM prepare_field_catalog TABLES gt_fieldcat[] .
*----Preparing layout structure
PERFORM prepare_layout CHANGING gs_layout .
*----Preparing Disable Toolbar Buttons
PERFORM change_buttons .
is_variant-report = dyname.
*'X': global saving only
*'U': user-specific saving only
*'A': corresponds to 'X' and 'U'
*SPACE: no saving
* Prüfe auf Berechtigung BENUTZERPFLEGE SU01
* dann ist Layout-Anpassung erlaubt
lv_layperm = 'A'.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
is_variant = is_variant
i_save = lv_layperm
* i_save = ' '
is_layout = gs_layout
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = it_data[]
it_fieldcatalog = gt_fieldcat[].
*--Registering handler methods to handle ALV Grid events JG
SET HANDLER gr_event_handler->handle_toolbar FOR grid1.
SET HANDLER gr_event_handler->handle_user_command FOR grid1.
SET HANDLER gr_event_handler->top_of_page FOR grid1.
* setting focus for created grid control
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = grid1.
* Initializing document
CALL METHOD g_dyndoc_id->initialize_document.
* Processing events
CALL METHOD grid1->list_processing_events
EXPORTING
i_event_name = 'TOP_OF_PAGE'
i_dyndoc_id = g_dyndoc_id.
* Die Toolbar des Grids muss noch auf interactive
* geschaltet werden. Dadurch werden die
* definierten Buttons angezeigt und die
* oben im PERFORM change_buttons ausgeschalteten
* Buttons heraus genommen werden
CALL METHOD grid1->set_toolbar_interactive.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Der GRID1 wird noch refreshed
CALL METHOD grid1->refresh_table_display.
ENDIF.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'AUSW' WITH text-001.
ENDMODULE. " PBO OUTPUT
*&---------------------------------------------------------------------*
*& Module PAI INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pai INPUT.
* to react on oi_custom_events:
CALL METHOD cl_gui_cfw=>dispatch.
CASE ok_code.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
* do nothing
ENDCASE.
CLEAR ok_code.
ENDMODULE. " PAI INPUT
*&--------------------------------------------------------------------*
*& Form prepare_field_catalog
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->PT_FIELDCATtext
*---------------------------------------------------------------------*
FORM prepare_field_catalog TABLES pt_fieldcat TYPE lvc_t_fcat .
DATA ls_fcat TYPE lvc_s_fcat .
* DATA lv_depth TYPE i.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = pt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
* DELETE pt_fieldcat WHERE
* fieldname EQ 'BENUTZER'.
LOOP AT pt_fieldcat INTO ls_fcat .
ls_fcat-col_pos = sy-tabix.
CASE ls_fcat-fieldname.
WHEN 'PROGNAME' .
ls_fcat-coltext = 'Name des Reports'.
ls_fcat-key = space.
ls_fcat-emphasize = space.
WHEN 'TEXT' .
ls_fcat-coltext = 'Beschreibung'.
ENDCASE.
MODIFY pt_fieldcat FROM ls_fcat .
ENDLOOP.
ENDFORM . "prepare_field_catalog
*&--------------------------------------------------------------------*
*& Form prepare_layout
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->PS_LAYOUT text
*---------------------------------------------------------------------*
FORM prepare_layout CHANGING ps_layout TYPE lvc_s_layo.
ps_layout-zebra = 'X' .
* ps_layout-cwidth_opt ='X'.
ps_layout-numc_total = ' '.
ps_layout-no_merging = 'X'.
ps_layout-no_rowmark = 'X'.
ps_layout-sel_mode = 'A'.
ps_layout-no_toolbar = ' '.
* ps_layout-grid_title = 'Flights' .
* ps_layout-smalltitle = 'X' .
ENDFORM. "prepare_layout
*&--------------------------------------------------------------------*
*& Form handle_toolbar
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->I_OBJECT text
*---------------------------------------------------------------------*
FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set
e_interactive .
DATA: ls_toolbar TYPE stb_button.
* Paltzhalter / Seperator
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO i_object->mt_toolbar.
* Button MARKIEREN
CLEAR ls_toolbar.
MOVE 'MARK' TO ls_toolbar-function. "#EC NOTEXT
MOVE icon_execute_object TO ls_toolbar-icon.
MOVE 'Programm ausführen'(201) TO ls_toolbar-quickinfo.
MOVE ' Programm ausführen'(201) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled. "#EC NOTEXT
APPEND ls_toolbar TO i_object->mt_toolbar.
ENDFORM . "handle_toolbar
*&--------------------------------------------------------------------*
*& Form Change_buttons
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM change_buttons .
* Kein Symbol für Drucken / Graphik / Info
ls_exclude = cl_gui_alv_grid=>mc_fc_print_back.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_info.
APPEND ls_exclude TO lt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_mb_subtot.
* APPEND ls_exclude TO lt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_mb_sum.
* APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_view.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_detail.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_find.
APPEND ls_exclude TO lt_exclude.
ENDFORM. "Change_buttons
*&--------------------------------------------------------------------*
*& Form handle_user_command
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->I_UCOMM text
*---------------------------------------------------------------------*
FORM handle_user_command USING i_ucomm TYPE syucomm .
DATA lt_selected_rows TYPE lvc_t_roid .
DATA ls_selected_row TYPE lvc_s_roid .
CASE i_ucomm .
WHEN 'MARK' .
CALL METHOD grid1->get_selected_rows
IMPORTING
et_row_no = lt_selected_rows.
* War was selektiert ?
* READ TABLE lt_selected_rows INTO ls_selected_row INDEX 1 .
*
* IF sy-subrc NE 0 .
* MESSAGE s000(su) WITH 'Bitte eine Zeile selektieren !'(205).
* ELSE.
* LOOP AT lt_selected_rows INTO ls_selected_row.
* IF ls_selected_row-row_id NE 0.
* READ TABLE it_data INDEX ls_selected_row-row_id.
* PERFORM run_report USING it_data-progname.
* EXIT.
* ENDIF.
* ENDLOOP.
* Falls die Tabelle yuserprog von hier aus gepflegt wird (Sonderfall)
* REFRESH it_data.
* SELECT * FROM yuserprog APPENDING TABLE it_data
* WHERE benutzer = sy-uname.
* CALL METHOD grid1->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
* EXCEPTIONS
* finished = 1
* OTHERS = 2 .
*
* ENDIF .
ENDCASE .
ENDFORM. "handle_user_command
*&---------------------------------------------------------------------*
*& Form EVENT_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->DG_DYNDOC_ID text
*----------------------------------------------------------------------*
FORM event_top_of_page USING r_top TYPE REF TO cl_dd_document.
*this is more clear.....check it
*first add text, then pass it to comentry write fm
* siehe DD_ALV_FREE_TOP
DATA: text TYPE sdydo_text_element.
DATA: s_table TYPE REF TO cl_dd_table_element.
DATA: col_key TYPE REF TO cl_dd_area.
DATA: col_info TYPE REF TO cl_dd_area.
DATA: a_logo TYPE REF TO cl_dd_area.
DATA: logo TYPE sdydo_value.
* CALL METHOD r_top->set_document_background
* EXPORTING
* picture_id = 'SIWB_WALLPAPER'.
** split TOP-Document
* CALL METHOD r_top->vertical_split
* EXPORTING split_area = r_top
* split_width = '50%'
* IMPORTING right_area = a_logo.
** fill TOP-Document
* text = 'Example of a Heading'(201).
* call method r_top->add_text exporting text = text
* sap_style = 'HEADING'.
* CALL METHOD r_top->new_line.
* CALL METHOD r_top->new_line.
CALL METHOD r_top->add_table EXPORTING no_of_columns = 2
with_heading = ' '
border = '0'
IMPORTING table = s_table.
CALL METHOD s_table->add_column IMPORTING column = col_key.
CALL METHOD s_table->add_column IMPORTING column = col_info.
text = 'A key value marked'(202).
CALL METHOD col_key->add_text EXPORTING text = text
sap_emphasis = 'Strong'.
CALL METHOD col_info->add_gap EXPORTING width = 6.
text = 'ABCDEG45644444444444' .
CALL METHOD col_info->add_text EXPORTING text = text
sap_style = 'Key'.
CALL METHOD col_info->add_gap EXPORTING width = 3.
text = 'Block brick units'(203).
CALL METHOD col_info->add_text EXPORTING text = text.
CALL METHOD s_table->new_row.
text = 'Storage Bin'(204).
CALL METHOD col_key->add_text EXPORTING text = text
sap_emphasis = 'Strong'.
CALL METHOD col_info->add_gap EXPORTING width = 7.
text = 'C-A-004'.
CALL METHOD col_info->add_text EXPORTING text = text.
CALL METHOD s_table->new_row.
text = 'Warehouse number'(206) .
CALL METHOD col_key->add_text EXPORTING text = text
sap_emphasis = 'Strong'.
CALL METHOD col_info->add_gap EXPORTING width = 6.
text = '200' .
CALL METHOD col_info->add_text EXPORTING text = text
sap_style = 'Success'.
CALL METHOD col_info->add_gap EXPORTING width = 3.
text = 'marked success'(210).
CALL METHOD col_info->add_text EXPORTING text = text.
* CALL METHOD s_table->new_row.
*
* CALL METHOD r_top->new_line.
* text = 'This last line is a comment in italics.'(211).
* CALL METHOD r_top->add_text EXPORTING text = text
* sap_emphasis = 'EMPHASIS'.
PERFORM html.
ENDFORM. "EVENT_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form HTML
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM html.
DATA : dl_length TYPE i, " Length
dl_background_id TYPE sdydo_key
VALUE 'SIWB_WALLPAPER'. " Background_id
* Creating html control
IF g_html_cntrl IS INITIAL.
CREATE OBJECT g_html_cntrl
EXPORTING
parent = g_parent_html.
ENDIF.
* Reuse_alv_grid_commentary_set
CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
EXPORTING
document = g_dyndoc_id
bottom = space
IMPORTING
length = dl_length.
* Get TOP->HTML_TABLE ready
CALL METHOD g_dyndoc_id->merge_document.
* Set wallpaper
CALL METHOD g_dyndoc_id->set_document_background
EXPORTING
picture_id = dl_background_id.
* Connect TOP document to HTML-Control
g_dyndoc_id->html_control = g_html_cntrl.
* Display TOP document
CALL METHOD g_dyndoc_id->display_document
EXPORTING
reuse_control = 'X'
parent = g_parent_html
EXCEPTIONS
html_display_error = 1.
IF sy-subrc NE 0.
* MESSAGE I999 WITH 'Error in displaying top-of-page'(036).
ENDIF.
ENDFORM. " HTML
Dann war der Unterschied nur, dass wir in meiner damaligen Firma ab 4.7 gezwungen waren, es zu nutzen, weil in dem Upgradeschritt 3.1i -> 4.7 die Performance des WRITE-Befehls so spektakulär in den Keller gegangen ist, dass viele unserer Programme kaum noch zu gebrauchen waren. Da waren wir gezwungen, nach Alternativen zu suchen und haben die ALVs gefunden, die - zumindest unter 4.7 - bedeutend performanter waren. (Keine Ahnung, ob die SAP das später wieder gefixt hat oder ob die miese WRITE-Performance durch die Fortschritte in der Hardware egal geworden ist.)black_adept hat geschrieben:Die ALV gibt's schon seit (fast) immer und ewig.
Das ist auf jeden Fall nützlich, vielen Dank! Nur eine Sache gefällt mir daran nicht:black_adept hat geschrieben:Aber Łukasz Pęgiel hat eine extrem! gute Alternative in seinem Blog. Du musst dir nur sein Coding in eine Serviceklasse im DDIC definieren und kannst danach einfach eine Tabelle übergeben und bekommst den zugehörigen Feldkatalog aufbereitet zurück - egal wo/wie du die Tabelle definiert hast.
http://abapblog.com/articles/how-to/76- ... rnal-table
Code: Alles auswählen.
catch cx_root.
endtry.
Ich versuche gerade, einen SLIS-Feldkatalog zu erhalten, indem ich den Code dieses Blogs nutze. Nur leider funktioniert er nicht. 😦 Die Methode cl_salv_controller_metadata=>get_slis_fieldcatalog fällt selbst mit einem anderen Dump auf die Nase, und zwar dem, dass in r_columns->r_controller des Parameters r_columns das Attribut r_adapter leer ist.black_adept hat geschrieben: ↑07.05.2018 18:08@cuncon: Das Erstellen mit dem ..._MERGE Bausteinen ( da gibt es ja noch mehrere ) für interne Tabellen ist etwas mühselig. Aber Łukasz Pęgiel hat eine extrem! gute Alternative in seinem Blog. Du musst dir nur sein Coding in eine Serviceklasse im DDIC definieren und kannst danach einfach eine Tabelle übergeben und bekommst den zugehörigen Feldkatalog aufbereitet zurück - egal wo/wie du die Tabelle definiert hast.
http://abapblog.com/articles/how-to/76- ... rnal-table