Please check Virtual Element for more details.
@AbapCatalog.sqlViewName: 'ZVPOITEXT'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #CONSUMPTION
@EndUserText.label: 'Purchase Order Item Standard Text in CDS'
@OData: { publish: true } --Publish CDS as OData Service
define view ZPurchaseOrderItemText
as select from I_PurchaseOrderItem --Data Source: Standard CDS(Purchase Document Line items)
{
key PurchaseOrder, --Purchase Document number
key PurchaseOrderItem, --Purchase Document Item number
@ObjectModel.virtualElement: true
@ObjectModel.virtualElementCalculatedBy: 'ZCL_PO_ITEM_TEXT'
cast( '' as abap.char(255)) as item_text1, ---field limited to maximum 255 characters for text
@ObjectModel.virtualElement: true
@ObjectModel.virtualElementCalculatedBy: 'ZCL_PO_ITEM_TEXT'
cast( '' as abap.char(255)) as item_text2 ---field limited to maximum 255 characters for text
};
Implement the method calculate & add below logic to fetch PO Item text
METHOD if_sadl_exit_calc_element_read~calculate.
TRY.
DATA : lt_poitem TYPE STANDARD TABLE OF zvpoitext WITH DEFAULT KEY,
lt_lines TYPE STANDARD TABLE OF tline,
lv_long_text TYPE string.
lt_poitem = CORRESPONDING #( it_original_data ).
LOOP AT lt_poitem ASSIGNING FIELD-SYMBOL(<ls_poitem>).
*--preapre PO item text name
DATA(lv_name) = CONV tdobname( <ls_poitem>-purchaseorder && <ls_poitem>-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>).
lv_long_text = lv_long_text && <ls_lines>-tdline .
ENDLOOP.
*--split text into below field with maximum 255 characters
<ls_poitem>-item_text1 = lv_long_text+0(255).
<ls_poitem>-item_text2 = lv_long_text+255(255).
CLEAR lv_long_text.
ENDIF.
*--return derived text
ct_calculated_data = CORRESPONDING #( lt_poitem ).
ENDLOOP.
*--catch exception to avoid short dump
CATCH cx_root INTO DATA(lo_err).
DATA(lv_msg) = lo_err->get_text( ).
ENDTRY.
ENDMETHOD.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |