in einem nächsten Schritt meiner langsam wachsenden Erfahrungen mit Web Dynpro möchte ich gerne den Inhalt einer Tabelle (UI Element) per Knopfdruck ausdrucken.
Hierzu habe ich schon Coding-Schnipsel gefunden und zwar diese hier (in der Methode des Button-Drucks eingefügt):
method ONACTIONPRINT_LIST .
* create local data variable to access context information
Data: context_node type ref to if_wd_context_node.
* Data: it_att_board TYPE STANDARD TABLE OF if_main=>element_TABLE.
* wa_att_board like line of it_att_board.
*
* DATA: index type i.
*
* context_node = wd_context->get_child_node( name = 'TABLE').
* refresh: it_att_board.
*
** Get data contained within ABAP web dynpro table
* context_node->get_static_attributes_table(
* importing
* table = it_att_board ).
*
** Get data contained in a Specific row of an ABAP web dynpro table
* index = 1. "Get row 1
* context_node->GET_STATIC_ATTRIBUTES(
* exporting index = index
* importing STATIC_ATTRIBUTES = wa_att_board ).
*
** Print web dynpro table using ALV object print functionality
* data it_datatab type ref to data.
*
** assign table containing data to it_datatab
* get reference of it_att_board into it_datatab.
*
* FIELD-SYMBOLS: <tab> TYPE table.
* ASSIGN it_datatab->* TO <tab>. "assign data table to field symbol
*
* DATA: it_alvtable TYPE REF TO cl_salv_table.
* DATA: ld_prnt_params TYPE pri_params,
* ld_valid(1) TYPE c.
*
** Get print parameters
* CALL FUNCTION 'GET_PRINT_PARAMETERS'
* EXPORTING
* copies = '1' "print_options-copies
* layout = 'X_65_255'
* no_dialog = abap_true
* IMPORTING
* out_parameters = ld_prnt_params
* valid = ld_valid
* EXCEPTIONS
* archive_info_not_found = 1
* invalid_print_params = 2
* invalid_archive_params = 3
* OTHERS = 4.
* IF sy-subrc ne 0 OR ld_valid NE abap_true.
** invalid print parameters
* return.
* ENDIF.
*
** Start List Processing using generated print parameters
* NEW-PAGE PRINT ON PARAMETERS ld_prnt_params NO DIALOG.
*
** If you insert ABAP write statements here they will apear on your printout
** write: 'HelloWorld'.
*
** Create the ALV Object
* DATA: error_string TYPE string.
*
* cl_salv_table=>factory(
* EXPORTING
* list_display = abap_true
* IMPORTING
* r_salv_table = it_alvtable
* CHANGING
* t_table = ).
*
** Process the ALV Columns
* DATA: columns TYPE REF TO cl_salv_columns_table.
*
** Reference ALV columns object
* columns = it_alvtable->get_columns( ).
** Set columns to optimised width.
* columns->set_optimize( abap_false ).
*
**Set ALV to print in the background
* it_alvtable->display( ).
* NEW-PAGE PRINT OFF.
*
** Display print complete message
endmethod.
Leider komme ich gar nicht so weit, es zu testen, denn die Syntaxprüfung knallt immer bei der Zeile
* Data: it_att_board TYPE STANDARD TABLE OF if_main=>element_TABLE.
mit der Meldung "Der Typ "ELEMENT_TABLE" ist unbekannt."
Soweit ich es aber verstanden hatte, referenziere ich so auf die Tabelle (die auch wirklich TABLE heisst und der View, in dem sie sich befindet "MAIN") oder was mache ich falsch?
Danke schon einmal für jeden Tipp!
Viele Grüße,
Dirk
ERGÄNZUNG vom 12.06.2014:
Bzw. würde ich gerne auf die Tabelle, die schon existiert und in das TABLE UI-Element eingelesen wird, ein SELECT machen und das Ergebnis in eine neue Tabelle schreiben und diese dann ausgeben.
Ich befürchte aber, dass dies nicht so einfach ist bzw. dass ich wieder auf den Fehler bei der Deklaration stoßen werde, den ich oben schon beschrieben habe - oder kann mir jemand mit diesem ersten Schritt (SELECT auf TABLE) weiterhelfen? Danke!
Um dein Coding syntaktisch korrekt zu machen musst du folgendes tun.
1. Anstatt "if_main=>element_table" musst du den Strukturnamen von deinem Context Knoten der Tabelle angeben.
2. Du musst in der Zeile "context_node = wd_context->get_child_node( name = 'TABLE')." das Literal 'TABLE' mit den Namen deines Context Knoten ersetzen.