Restrictions:
Using the concept of calculated field, standard text can be displayed in ALV with IDA, which uses CDS/table as the data source using calculated fields.
@AbapCatalog.sqlViewName: 'ZPOITEXT'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #BASIC
@EndUserText.label: 'Purchase Order Item Standard Text in CDS'
define view ZPOITEMTEXT as select from ekko
inner join ekpo on ekko.ebeln = ekpo.ebeln
and ekko.bstyp = 'F' --purchase order
and matnr <> ' ' --Must have material
and ekko.loekz = ' ' --PO not marked for deletion
and ekpo.loekz = ' ' --Item not marked for deletion
{
key ekpo.ebeln as PurchaseOrder,
key ekpo.ebelp as PurchaseOrderItem,
matnr as Material,
menge as Quantity,
meins as Unit,
ekko.aedat as PuchaseDocument
}
where ekko.aedat between '20200101' and '20200430';
REPORT zsalv_ida_standard_text.
*&---------------------------------------------------------------------*
*& Report ZSALV_IDA_STANDARD_TEXT
*&---------------------------------------------------------------------*
CLASS lc_salv_ida_standard_text DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
"! Main method to call IDA
main.
INTERFACES: if_salv_ida_calc_field_handler . "IDA API: Handler for Calculated Fields
METHODS:
"! Set coulmn header for new field
set_column_header_texts
IMPORTING io_field_catalog TYPE REF TO if_salv_gui_field_catalog_ida.
PRIVATE SECTION.
TYPES:
"! the additional field item_text will be added to structure in ALV at runtime
BEGIN OF lty_calc_field,
item_text TYPE c LENGTH 255,
END OF lty_calc_field .
DATA:
"! internal table for calculated fields
lt_calc_field_name TYPE if_salv_ida_types=>yts_field_name.
ENDCLASS.
CLASS lc_salv_ida_standard_text IMPLEMENTATION.
METHOD if_salv_ida_calc_field_handler~get_calc_field_structure.
*--define additional fields by returning the structure description
DATA ls_calc_field TYPE lty_calc_field.
ro_calc_field_structure ?= cl_abap_structdescr=>describe_by_data( ls_calc_field ).
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~get_requested_fields.
*--for additional ITEM_TEXT the CDS fields PURCHASEORDER and PURCHASEORDERITEM are required
IF line_exists( its_calc_field_name[ table_line = |ITEM_TEXT| ] ).
rts_db_field_name = VALUE #( ( |PURCHASEORDER| )
( |PURCHASEORDERITEM| ) ).
ENDIF.
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~start_page.
*--buffer which of the calculated fields are displayed
*--later calculate values only for these fields to save performance
lt_calc_field_name = its_calc_field_name.
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~calculate_line.
DATA: lt_lines TYPE STANDARD TABLE OF tline,
ls_calc_field TYPE lty_calc_field.
REFRESH lt_lines.
TRY.
*--read CDS fields
DATA(ls_po_item) = CORRESPONDING zpoitemtext( is_data_base_line ).
IF line_exists( lt_calc_field_name[ table_line = |ITEM_TEXT| ] ).
*--prepare Item text name
DATA(lv_name) = CONV tdobname( ls_po_item-purchaseorder && ls_po_item-purchaseorderitem ).
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = 'F01'
language = sy-langu
name = lv_name
object = 'EKPO'
TABLES
lines = lt_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc IS INITIAL.
LOOP AT lt_lines ASSIGNING FIELD-SYMBOL(<ls_lines>).
*--concatenate text lines
ls_calc_field-item_text = ls_calc_field-item_text && <ls_lines>-tdline.
ENDLOOP.
ENDIF.
ENDIF.
*--return values in added structure
es_calculated_fields = ls_calc_field.
CATCH cx_root INTO DATA(lo_err).
DATA(lv_msg) = lo_err->get_text( ).
ENDTRY.
ENDMETHOD.
METHOD if_salv_ida_calc_field_handler~end_page.
" do nothing.
ENDMETHOD.
METHOD set_column_header_texts.
*--set column header for additional field ITEM_TEXT
io_field_catalog->set_field_header_texts( iv_field_name = 'ITEM_TEXT'
iv_header_text = 'PO Item text'
iv_tooltip_text = 'PO Item text' ).
ENDMETHOD.
METHOD main.
*--create object
DATA(lo_calc_field_handler) = NEW lc_salv_ida_standard_text( ).
*--call ALV using CDS as data source
DATA(lo_alv_display) = cl_salv_gui_table_ida=>create_for_cds_view( iv_cds_view_name = |ZPOITEMTEXT|
io_calc_field_handler = lo_calc_field_handler )."
*--set field catalogue
lo_calc_field_handler->set_column_header_texts( lo_alv_display->field_catalog( ) ).
*--display full screen alv in GUI
lo_alv_display->fullscreen( )->display( ).
ENDMETHOD.
ENDCLASS.
END-OF-SELECTION.
*--start processing
lc_salv_ida_standard_text=>main( ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |