❌

Normal view

There are new articles available, click to refresh the page.
Before yesterdaySAP Technomaniac / ABAP On HANA

Modify operation Code

 CLASS ycl_modify_practice DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .


PUBLIC SECTION.

INTERFACES if_oo_adt_classrun .

PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.




CLASS ycl_modify_practice IMPLEMENTATION.

METHOD if_oo_adt_classrun~main.

*MODIFY ENTITY, ENTITIES, field_spec

*1->... { FROM fields_tab }

* CREATE, CREATE BY, UP☺DATE, DELETE, EXECUTE

* For DELETE, EXECUTE we can use this option only

* The %control structure must be filled explicitly in the internal table fields_tab for CREATE, CREATE BY and UPDATE

* DATA : lt_book TYPE TABLE FOR CREATE yi_travel_tech_m\_Booking.

* MODIFY ENTITY yi_travel_tech_m

* CREATE FROM VALUE #(

* ( %cid = 'cid1'

* %data-BeginDate = '20240225'

* %control-BeginDate = if_abap_behv=>mk-on

*

* ) )

* CREATE BY \_Booking

* FROM VALUE #( ( %cid_ref = 'cid1'

* %target = VALUE #( ( %cid = 'cid11'

* %data-bookingdate = '20240216'

* %control-Bookingdate = if_abap_behv=>mk-on ) )

*

*

*

* ) )

* FAILED FINAL(it_failed)

* MAPPED FINAL(it_mapped)

* REPORTED FINAL(it_result).


* IF it_failed IS NOT INITIAL.

* out->write( it_failed ).

* ELSE.

* COMMIT ENTITIES.

* ENDIF.



* MODIFY ENTITY yi_booking_tech_m

* DELETE FROM VALUE #( ( %key-TravelId = '0000004187'

* %key-BookingId = '0010' ) )

* FAILED FINAL(it_failed1)

* MAPPED FINAL(it_mapped1)

* REPORTED FINAL(it_result1).

* .

* IF it_failed1 IS NOT INITIAL.

* out->write( it_failed1 ).

* ELSE.

* COMMIT ENTITIES.

* ENDIF.

*☺


*2-> | { AUTO FILL CID WITH fields_tab }

* MODIFY ENTITY yi_travel_tech_m

* CREATE AUTO FILL CID WITH VALUE #(

* ( %data-BeginDate = '20240229'

* %control-BeginDate = if_abap_behv=>mk-on

*

* ) )

* FAILED FINAL(it_failed)

* MAPPED FINAL(it_mapped)

* REPORTED FINAL(it_result).

*

* IF it_failed IS NOT INITIAL.

* out->write( it_failed ).

* ELSE.

** COMMIT ENTITIES.

* ENDIF.

*3-> | { [AUTO FILL CID] FIELDS ( comp1 comp2 ... ) WITH fields_tab }


* MODIFY ENTITIES OF yi_travel_tech_m

* ENTITY yi_travel_tech_m

* UPDATE FIELDS ( BeginDate )

* WITH VALUE #( β™₯m

* DELETE FROM VALUE #( ( TravelId = '0000004188' ) ) .

* COMMIT ENTITIES.

*4-> | { [AUTO FILL CID] SET FIELDS WITH fields_tab } ...☺

MODIFY ENTITY yi_travel_tech_m

UPDATE SET FIELDS WITH VALUE #( ( %key-TravelId = '0000004190'

BeginDate = '20240325' ) ).


COMMIT ENTITIES.


ENDMETHOD.


ENDCLASS.

Read Operation with behavior definition language (BDL) RAP Sample Code

 Read Operation code:- 

CLASS ycl_read_ptactice DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .


PUBLIC SECTION.

INTERFACES if_oo_adt_classrun .


PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.




CLASS ycl_read_ptactice IMPLEMENTATION.

METHOD if_oo_adt_classrun~main.

*sort form read


* READ ENTITY yi_travel_tech_m

* FROM VALUE #( ( %key-TravelId = '0000004172'

* %control = VALUE #( AgencyId = if_abap_behv=>mk-on

* CUSTOMERID = if_abap_behv=>mk-on

* BEGINDATE = if_abap_behv=>mk-on

* )

*

* )

* )

* RESULT DATA(lt_result_short)

* FAILED DATA(lt_failed_sort).

*

* IF lt_failed_sort IS NOT INITIAL.

* out->write( 'Read failed' ).

*

* ELSE.

* out->write( lt_result_short ).

* ENDIF.


* READ ENTITY yi_travel_tech_m

* by \_Booking

* ALL FIELDS

* WITH VALUE #( ( %key-TravelId = '0000004172' )

* ( %key-TravelId = '0000004136' )

* )

* RESULT DATA(lt_result_short)

* FAILED DATA(lt_failed_sort).

*

* IF lt_failed_sort IS NOT INITIAL.

* out->write( 'Read failed' ).

*

* ELSE.

* out->write( lt_result_short ).

* ENDIF.



* READ ENTITIES OF yi_travel_tech_m

*

* ENTITY yi_travel_tech_m

* ALL FIELDS

* WITH VALUE #( ( %key-TravelId = '0000004172' )

* ( %key-TravelId = '0000004136' )

* )

* RESULT DATA(lt_result_travel)

*

* ENTITY yi_booking_tech_m

* ALL FIELDS WITH VALUE #( ( %key-TravelId = '0000004172'

* %key-BookingId = '0020'

* ) )

* RESULT DATA(lt_result_book)

*

* FAILED DATA(lt_failed_sort).

*

* IF lt_failed_sort IS NOT INITIAL.

* out->write( 'Read failed' ).

*

* ELSE.

* out->write( lt_result_travel ).

* out->write( lt_result_book ).

* ENDIF.


DATA: it_optab TYPE abp_behv_retrievals_tab,

it_travel TYPE TABLE FOR READ IMPORT yi_travel_tech_m,

it_travel_result TYPE TABLE FOR READ RESULT yi_travel_tech_m,

it_booking TYPE TABLE FOR READ IMPORT yi_travel_tech_m\_Booking,

it_booking_result TYPE TABLE FOR READ RESULT yi_travel_tech_m\_Booking.


it_travel = VALUE #( ( %key-TravelId = '0000004172'

%control = VALUE #( AgencyId = if_abap_behv=>mk-on

customerid = if_abap_behv=>mk-on

begindate = if_abap_behv=>mk-on

) ) ).


it_booking = VALUE #( ( %key-TravelId = '0000004172'

%control = VALUE #(

BookingDate = if_abap_behv=>mk-on

BookingStatus = if_abap_behv=>mk-on

BookingId = if_abap_behv=>mk-on

) ) ).


it_optab = VALUE #( ( op = if_abap_behv=>op-r-read

entity_name = 'YI_TRAVEL_TECH_M'

instances = REF #( it_travel )

results = REF #( it_travel_result ) )

( op = if_abap_behv=>op-r-read_ba

entity_name = 'YI_TRAVEL_TECH_M'

sub_name = '_BOOKING'

instances = REF #( it_booking )

results = REF #( it_booking_result )

) ).


READ ENTITIES

OPERATIONS it_optab

FAILED DATA(lt_failed_dy).


IF lt_failed_dy IS NOT INITIAL.

out->write( 'Read failed' ).


ELSE.

out->write( it_travel_result ).

out->write( it_booking_result ).

ENDIF.



ENDMETHOD.

ENDCLASS.

Backup all ADT Objects & Other queries RAP Part 10.1

CLASS zcl_DATA_GENERATOR DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .


PUBLIC SECTION.

INTERFACES:

if_oo_adt_classrun.

PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.




CLASS zcl_DATA_GENERATOR IMPLEMENTATION.



METHOD if_oo_adt_classrun~main.


" delete existing entries in the database table

DELETE FROM ztravel_tech_m.

DELETE FROM zBOOKING_tech_m.

DELETE FROM zbooksupp_tech_m.

COMMIT WORK.

" insert travel demo data

INSERT ztravel_tech_m FROM (

SELECT *

FROM /dmo/travel_m

).

COMMIT WORK.


" insert booking demo data

INSERT zbooking_tech_m FROM (

SELECT *

FROM /dmo/booking_m

* JOIN ztravel_tech_m AS z

* ON booking~travel_id = z~travel_id


).

COMMIT WORK.

INSERT zbooksupp_tech_m FROM (

SELECT *

FROM /dmo/booksuppl_m

* JOIN ztravel_tech_m AS z

* ON booking~travel_id = z~travel_id


).

COMMIT WORK.


out->write( 'Travel and booking demo data inserted.').



ENDMETHOD.

ENDCLASS.

Calling CDS in AMDP Part -3



CLASS zcl_amdp_client DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .

PUBLIC SECTION.

INTERFACES if_amdp_marker_hdb.


TYPES : tt_zcds_sample_01 TYPE TABLE OF zvsql_sample_01.

CLASS-METHODS get_data_cds

AMDP OPTIONS

CDS SESSION CLIENT iv_clnt

IMPORTING VALUE(iv_clnt) TYPE sy-mandt

EXPORTING VALUE(et_so) TYPE tt_zcds_sample_01.


PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.


CLASS zcl_amdp_client IMPLEMENTATION.

METHOD get_data_cds BY DATABASE PROCEDURE

FOR HDB

LANGUAGE SQLSCRIPT

USING zcds_sample_01.

et_so = select *

from zcds_sample_01

WHERE mandt = :iv_clnt;

* Where mandt = session_context( 'CDS_CLIENT' );

ENDMETHOD.


ENDCLASS.




**********************************************************************



**********************************************************************

*AMDP does not support implicit client handling.

*We should pass client in parameter interface


*Exception :- When we are calling another CDS view which is using

* @ClientHandling.algorithm:#SESSION_VARIABLE.

* In this case CDS_CLIENT is used in where condition which came

*from AMDP OPTIONS CDS SESSION CLIENT .

*If it is not specified or passed from importing

*parameter then and it is different from CDS_CLIENT

*we will get empty result




@AbapCatalog.sqlViewName: 'ZVSQL_SAMPLE_01'

@EndUserText.label: 'This is my fist DDIC based CDS'

@AbapCatalog.preserveKey: true

@AbapCatalog: {

buffering: {

status:#SWITCHED_OFF,

type: #NONE,

numberOfKeyFields: 000

},


viewEnhancementCategory: [#PROJECTION_LIST,#UNION],

compiler: {

compareFilter: true

},

dataMaintenance: #RESTRICTED

}

@AccessControl.authorizationCheck: #CHECK

@ClientHandling: {

type: #INHERITED,

algorithm:#SESSION_VARIABLE

}


define view zcds_sample_01 --( SO, Kunnr, curr,netwr,clnt,sydate,syslang)

as select from vbak

association [1..*] to vbap as _item on vbak.vbeln = _item.vbeln

{


key vbeln as so,

kunnr as cust,

waerk,

netwr,

vkorg,

vbtyp,

ernam ,

$session.client as syst_client,

$session.system_date as syst_date,

$session.system_language as syst_lang,

_item


}













/*define view zcds_sample_01

as select

key vbeln as so,

kunnr as cust

from vbak; */

// Commentsingle

-- vndvld

/*

DataAging Annotations

ObjectModel.usageType

//@Metadata.ignorePropagatedAnnotations: true

//@ObjectModel.usageType:{

// serviceQuality: #X,

// sizeCategory: #S,

// dataClass: #MIXED

//}

This information is especially important in regards of performance

that can be expected by the consumer of the view.



Create a view use in select report to display results.





/*When an object defined in the CDS source code is activated,

the annotations defined in the CDS annotation syntax these are saved in

internal system tables. These tables can then be accessed to evaluate the data.


We use below class for evaluation of annatation

CL_DD_DDL_ANNOTATION_SERVICE

-> First it gets data from metadata extension though it's method

-> Then CDS Entity itself to evaluate


-> Annotation devided in three parts

1. Metadata extension

2. Direct Annotation (GET_DIRECT_ANNOS_ )

3. indirect Annotation ( Derived and inheritate )

inheritate -> CDS entities which accessed in thid cds

Derived -> It derived from data element if it is not define in cds

*/

AMDP ( ABAP Managed Database Procedure ) Part - 1



CLASS zcl_amdp_class DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .


PUBLIC SECTION.

INTERFACES if_amdp_marker_hdb.

TYPES: BEGIN OF ty_cust,

cust_name TYPE kna1-name1,

netwr TYPE vbak-netwr,

END OF ty_cust,

tt_cust TYPE TABLE OF ty_cust.


TYPES:

BEGIN OF session_variables,

client TYPE sy-mandt,

cds_client TYPE sy-mandt,

uname TYPE sy-uname,

langu TYPE sy-langu,

datum TYPE sy-datum,

END OF session_variables .


CLASS-METHODS get_session_variables_amdp

AMDP OPTIONS READ-ONLY

CDS SESSION CLIENT iv_clnt

IMPORTING

VALUE(iv_clnt) TYPE sy-mandt

EXPORTING

VALUE(clnt) TYPE session_variables-client

VALUE(cds_clnt) TYPE session_variables-cds_client

VALUE(unam) TYPE session_variables-uname

VALUE(lang) TYPE session_variables-langu

VALUE(date) TYPE session_variables-datum

RAISING

cx_amdp_error .


METHODS get_cust_detail

IMPORTING

VALUE(et_num) TYPE i

VALUE(mandt) TYPE mandt

EXPORTING

VALUE(top_cust) TYPE tt_cust

VALUE(flop_cust) TYPE tt_cust.

PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.




CLASS zcl_amdp_class IMPLEMENTATION.

METHOD get_cust_detail BY DATABASE PROCEDURE

FOR HDB

LANGUAGE SQLSCRIPT

USING vbak kna1.



top_cust = SELECT top :et_num cust.name1 as cust_name,

sum (so_head.netwr) as netwr

from vbak as so_head

INNER JOIN kna1 as cust

ON so_head.kunnr = cust.kunnr

GROUP BY name1

ORDER BY netwr desc;


flop_cust = SELECT top :et_num cust.name1 as cust_name,

sum (so_head.netwr) as netwr

from vbak as so_head

INNER JOIN kna1 as cust

ON so_head.kunnr = cust.kunnr

GROUP BY name1

ORDER BY netwr asc;






ENDMETHOD.


METHOD get_session_variables_amdp BY DATABASE PROCEDURE

FOR HDB

LANGUAGE SQLSCRIPT

.

clnt := SESSION_CONTEXT('CLIENT');

cds_clnt := SESSION_CONTEXT('CDS_CLIENT');

UNAM := SESSION_CONTEXT('APPLICATIONUSER');

LANG := SESSION_CONTEXT('LOCALE_SAP');

DATE := SESSION_CONTEXT('SAP_SYSTEM_DATE');



ENDMETHOD.


ENDCLASS.


*An AMDP Method => database procedure.

*It can be static or instance method

*It can be declare in any visibility section

*In declaration part we can’t say it is AMDP method or not

*return values cannot be declared using RETURNING.

*β—ΎThe parameters must be declared using VALUE for pass by value

*The database objects of the current database schema accessed in the AMDP method must be declared using an addition USING.

*the AMDP framework does not support automatic client handling


*The following restrictions apply to method implementation:

*AMDP Method for β—ΎAMDP procedure implementations

*methods without a return value

*β€’AMDP procedure implementations with the addition BY DATABASE PROCEDURE

*β—ΎAn AMDP method must not be empty.

*β—ΎWrites cannot be performed on database tables where table buffering is switched on, since SQLScript accesses are ignored by buffer synchronizations.

*β—ΎAMDP methods do not have any implicit enhancement options

*β—ΎDDL statements are not allowed for creating, changing or deleting database objects

*β—Ύno database commits and database rollbacks using COMMIT and ROLLBACK statements are allowed


*CLIENT

*CDS_CLIENT

*APPLICATIONUSER

*LOCALE_SAP

*SAP_SYSTEM_DATE

***********************************************************************

*Parameter interface of an AMDP procedure implementation:

*β—ΎThe typing of the parameters must not be generic.

* >>Only elementary data types and table types with a structured row type can be used.

* >>The row type of a tabular type can only contain elementary data types as components


*β—ΎOnly input parameters can be flagged as optional parameters.

* >>Each elementary optional input parameter must have a replacement parameter declared using DEFAULT.

* >>An optional tabular input parameter cannot have any replacement parameters and must be made optional instead using OPTIONAL.



* It will create SQLScript procedure YCL_AMDP_INTRODUCTION=>GET_VBAK

* in the ABAP DB schema

*How to access another AMDP procedure

*CALL "CLASS=>METH"( f1 => a1, f2 => a2, ... );

*The parameter interface of an SQLScript procedure supports input

*IN, OUT, INOUT(It can be only scalar)

*AMDP -> SQL script Conversion parameter interface

* IMPORTING => IN

* EXPORTING => OUT

* CHANGING (SCALAR) => INOUT

* CHANGING (Tabular) => IN and OUT two parameter

* Since SQL script not support INOUT tabular parameter

* NAme OUT = Changing parameter name

* IN = Changing_parameter_IN_


From CDS View to OData Service: Simplifying the Process Part 23


CRUD:- Create Read Update Delete
Read -
    /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet + GET =>  employeeset_get_entityset.
    /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet(2) + GET => EMPLOYEESET_GET_ENTITY
Create :-
    /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet + POST + Payload => employeeset_create_entity
Update
    /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet(6) + PUT + Payload  => 'EMPLOYEESET_UPDATE_ENTITY' 
Delete
   /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet(6) + DELETE => 'EMPLOYEESET_DELETE_ENTITY' 
************************************************************************************************************

Access data through navigation
   /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4969')/Items
   /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderItems => salesorderitems_get_entityset

Read with navigation path
/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaderS + Get
     =>salesorderheader_get_entityset

/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaderS('4970')/OrderToItem_nav + Get
      => salesorderitems_get_entityset

/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderItemS      => salesorderitems_get_entityset     

***************************************************************************************************************
Expand Query option :-
  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$expand=Items
     salesorderheader_get_entityset  => 100
     salesorderitems_get_entityset   => 7970 ....100 times

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4970')?$expand=Items
   salesorderheader_get_entity => 4970
   salesorderitems_get_entityset    => one time

If we have implemented this then we have to implement 

/IWFND/TRACES
/IWFND/CACHE_CLEANUP

http://host:POrt/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$expand=Items&$format=json
****************************************************************************************************************

They are automatically available in the framework, no further actions needed by development.
$format
  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$format=json
$expand
  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$expand=Items
$select
  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$select=SalesOrder,SalesOrg,Vtweg&$format=json
$count
  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders/$count
$links
  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4970')/$links/Items
ZC_SALESORDER_CDS/ZC_SalesOrder('180')/$links/to_items
$value
  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4970')/Bstnk/
  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4970')/Bstnk/$value
**************************************************************************************************

They are available, but they require implementation efforts from development.

Without implementation query option :- 
$select :-
/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$select=SalesOrder,Auart&$format=json 

$count :-
/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaders/$count

$link :-
/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaders('764')/$links/Items

value :-
/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaders('764')/Auart?$format=json
$value
/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaders('764')/Auart/$value

$skiptoken
*************************************************************************************************

$batch :-

GET EmployeeSet?
$skip=0&
$top=20&
$select=EmployeeId%2cName%2cCity%2cCompanyName%2cDepartment%2cStratDate%2cEndDate%2cSalary%2cCurrency&
$inlinecount=allpages

http://183.82.1.220:8073/sap/opu/odata/sap/ZEMPLOYEE_002_SRV

*************************************************************************************************************
$orderby
/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$orderby=SalesOrder desc&$format=json
/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$orderby=Kunnr asc,SalesOrder desc&$format=json

$filter
/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$filter=Kunnr eq '1390'
/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$filter=( Kunnr eq '1390' or Kunnr eq '1175')
/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$filter=( Kunnr eq '1390' or Kunnr eq '1175') and Vtweg eq '10'

List report page
/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$top
/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$skip

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$inlinecount

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$skiptoken

***********************************************************************************

/sap/opu/odata/sap/ZSALESORDER_001_SRV/
Function Import:-
so_count_by_status

Importing :-
 Customer
Exporting :-
 Customer
 NotProcesed
 CompleteProcess
 NotRelvent
*******************************************************************
Media Handling (Image, Audio, Video, PDF, ZIP, Excel Sheet, Text Files):- 
1. Set Entity type as media in SEGW   :- METADATA (hasStream)
2. Mime type property set as contetnt type in MPC_EXT
3. create_stream  :- /sap/opu/odata/SAP/ZMEDIA_SRV/MediaSet                + POST + Payload + SLUG variable
4. get_stream     :- /sap/opu/odata/SAP/ZMEDIA_SRV/MediaSet('ram3')/$value + GET  
5. update_stream  :- /sap/opu/odata/SAP/ZMEDIA_SRV/MediaSet('ram3')/$value + PUT + Payload 
6. delete_stream  :- /sap/opu/odata/SAP/ZMEDIA_SRV/MediaSet('ram3')/$value + DELETE

Smartform pdf send to front end system 

/sap/opu/odata/SAP/ZMEDIA_SRV/MediaSet('LH')/$value
*****************************


How To Master Media Handling with SAP OData Part 20


Code detail :- 

class ZCL_ZMEDIA_MPC_EXT definition

public

inheriting from ZCL_ZMEDIA_MPC

create public .


public section.

METHODS: define REDEFINITION.

protected section.

private section.

ENDCLASS.




CLASS ZCL_ZMEDIA_MPC_EXT IMPLEMENTATION.

METHOD DEFINE.

super->define( ).

* CATCH /iwbep/cx_mgw_med_exception.


model->get_entity_type( iv_entity_name = 'Media'

)->get_property( iv_property_name = 'Mimetype'

)->set_as_content_type( ).

* CATCH /iwbep/cx_mgw_med_exception..

* CATCH /iwbep/cx_mgw_med_exception..

* CATCH /iwbep/cx_mgw_med_exception.


ENDMETHOD.


ENDCLASS.



**************************************************************

CLASS zcl_zmedia_dpc_ext DEFINITION

PUBLIC

INHERITING FROM zcl_zmedia_dpc

CREATE PUBLIC .


PUBLIC SECTION.

METHODS : /iwbep/if_mgw_appl_srv_runtime~create_stream REDEFINITION.

METHODS : /iwbep/if_mgw_appl_srv_runtime~get_stream REDEFINITION.

METHODS : /iwbep/if_mgw_appl_srv_runtime~update_stream REDEFINITION.

METHODS : /iwbep/if_mgw_appl_srv_runtime~delete_stream REDEFINITION.

PROTECTED SECTION.

PRIVATE SECTION.

ENDCLASS.




CLASS zcl_zmedia_dpc_ext IMPLEMENTATION.

METHOD /iwbep/if_mgw_appl_srv_runtime~create_stream.

DATA(ls_media_ram) = VALUE zcl_zmedia_mpc=>ts_media(

client = sy-mandt

filename = iv_slug

mimetype = is_media_resource-mime_type

value = is_media_resource-value ).


INSERT zmedia_ram FROM @ls_media_ram.


IF sy-subrc IS INITIAL.

copy_data_to_ref(

EXPORTING

is_data = ls_media_ram

CHANGING

cr_data = er_entity

).

ENDIF.


ENDMETHOD.



METHOD /iwbep/if_mgw_appl_srv_runtime~get_stream.


DATA(it_keys) = io_tech_request_context->get_keys( ).


DATA(lv_key) = VALUE #( it_keys[ 1 ]-value OPTIONAL ).


IF lv_key IS NOT INITIAL.

SELECT SINGLE *

FROM zmedia_ram

INTO @DATA(ls_zmedia_ram)

WHERE filename = @lv_key.

IF sy-subrc IS INITIAL.

DATA(ls_s_media_resource) = VALUE ty_s_media_resource( mime_type = ls_zmedia_ram-mimetype

value = ls_zmedia_ram-value ).


copy_data_to_ref(

EXPORTING

is_data = ls_s_media_resource

CHANGING

cr_data = er_stream

).

ENDIF.



ENDIF.

ENDMETHOD.


METHOD /iwbep/if_mgw_appl_srv_runtime~update_stream.

DATA(it_keys) = io_tech_request_context->get_keys( ).


DATA(lv_key) = VALUE #( it_keys[ 1 ]-value OPTIONAL ).



DATA(ls_zmedia_ram) = VALUE zcl_zmedia_mpc=>ts_media( client = sy-mandt

filename = VALUE #( it_keys[ 1 ]-value OPTIONAL )

mimetype = is_media_resource-mime_type

value = is_media_resource-value ).


MODIFY zmedia_ram FROM ls_zmedia_ram.



ENDMETHOD.


METHOD /iwbep/if_mgw_appl_srv_runtime~delete_stream.


DATA(it_keys) = io_tech_request_context->get_keys( ).


DELETE FROM zmedia_ram WHERE filename = @( VALUE #( it_keys[ 1 ]-value OPTIONAL ) ).


ENDMETHOD.


ENDCLASS.

tag:blogger.com,1999:blog-4281849726649730935.post-815621051428987875

CRUD:- Create Read Update Delete

Read -

    /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet + GET =>  employeeset_get_entityset.

    /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet(2) + GET => EMPLOYEESET_GET_ENTITY

Create:-

    /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet + POST => employeeset_create_entity

Update

    /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet(6) + PUT => 'EMPLOYEESET_UPDATE_ENTITY' 

Delete

   /sap/opu/odata/sap/ZEMPLOYEE_002_SRV/EmployeeSet(6) + DELETE => 'EMPLOYEESET_DELETE_ENTITY' 


Access data through navigation

   /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4969')/Items

   /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderItems => salesorderitems_get_entityset


Read with navigation path

/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaderS + Get

     =>salesorderheader_get_entityset


/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaderS('4970')/OrderToItem_nav + Get

      => salesorderitems_get_entityset


/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderItemS      => salesorderitems_get_entityset     



Expand Query option :-

  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$expand=Items

     salesorderheader_get_entityset  => 100

     salesorderitems_get_entityset   => 7970 ....100 times


/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4970')?$expand=Items

   salesorderheader_get_entity => 4970

   salesorderitems_get_entityset    => one time


If we have implemented this then we have to implement 


/IWFND/TRACES

/IWFND/CACHE_CLEANUP


/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$expand=Items&$format=json


They are automatically available in the framework, no further actions needed by development.

$format

  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$format=json

$expand

  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$expand=Items

$select

  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$select=SalesOrder,SalesOrg,Vtweg&$format=json

$count

  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders/$count

$links

  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4970')/$links/Items

$value

  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4970')/Bstnk/

  /sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders('4970')/Bstnk/$value


They are available, but they require implementation efforts from development.






Without implementation query option :- 

$select :-

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$select=SalesOrder,Auart&$format=json 


$count :-

/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaders/$count


$link :-

/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaders('764')/$links/Items


value :-

/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaders('764')/Auart?$format=json

$value

/sap/opu/odata/sap/ZSALESORDER_001_SRV/SalesOrderHeaders('764')/Auart/$value



$skiptoken














$batch :-


GET EmployeeSet?

$skip=0&

$top=20&

$select=EmployeeId%2cName%2cCity%2cCompanyName%2cDepartment%2cStratDate%2cEndDate%2cSalary%2cCurrency&

$inlinecount=allpages


http://183.82.1.220:8073/sap/opu/odata/sap/ZEMPLOYEE_002_SRV

****************************************************************************

Content-Type   multipart/mixed; boundary=batch


--batch_01

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/json


GET SalesOrderHeaders('4970') HTTP/1.1



--batch_01--

********************************************************************************

--batch_01

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/json


GET SalesOrderHeaders('4970') HTTP/1.1



--batch_01

Content-Type: application/http

Content-Transfer-Encoding: binary

Accept: application/json


GET SalesOrderHeaders('4969') HTTP/1.1



--batch_01--

********************************************************************************

To perform changeset operations, we have two ways:

To redefine respective operations & handle all operations there itself. :- which we have done

Enable defer mode & handle all changeset operations in one place. 


--batch_01

Content-Type:multipart/mixed; boundary=changeset


--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary


PUT EmployeeSet(12) HTTP/1.1

Content-Type: application/json


{

    "EmployeeId" : 12,

    "Name" : "Ram",

    "City" : "New Jaipur 1",

    "CompanyName" : "SAP Technomaniac",

    "Department" : "SAP Technomaniac",

    "StratDate" : "\/Date(1643500800000)\/",

    "EndDate" : "\/Date(1706054400000)\/",

    "Salary" : "2400000.00",

    "Currency" : "INR"}


--changeset--


--batch_01--

******************************************************************************

--batch_01

Content-Type:multipart/mixed; boundary=changeset


--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary


DELETE EmployeeSet(12) HTTP/1.1



--changeset--


--batch_01--

*****************************************************************************

--batch_01

Content-Type:multipart/mixed; boundary=changeset


--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary


PUT EmployeeSet(12) HTTP/1.1

Content-Type: application/json


{

    "EmployeeId" : 12,

    "Name" : "Ram",

    "City" : "New Jaipur 2",

    "CompanyName" : "SAP Technomaniac",

    "Department" : "SAP Technomaniac",

    "StratDate" : "\/Date(1643500800000)\/",

    "EndDate" : "\/Date(1706054400000)\/",

    "Salary" : "2400000.00",

    "Currency" : "INR"}



--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary


DELETE EmployeeSet(12) HTTP/1.1




--changeset--


--batch_01--





*********************************************************

$orderby

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$orderby=SalesOrder desc&$format=json

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$orderby=Kunnr asc,SalesOrder desc&$format=json


$filter

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$filter=Kunnr eq '1390'

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$filter=( Kunnr eq '1390' or Kunnr eq '1175')

/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$filter=( Kunnr eq '1390' or Kunnr eq '1175') and Vtweg eq '10'

List report page



$top

$skip

$inlinecount

$skiptoken


****************************************************

*Skiptoken

*/sap/opu/odata/sap/ZSALESORDER_002_SRV/SalesOrderHeaders?$skiptoken=98

      DATA: lv_page_size   TYPE i VALUE 50.

      DATA: lt_entityset TYPE zcl_zsalesorder_002_mpc=>tt_salesorderheader .


      DATA(lv_skiptoken) = io_tech_request_context->get_skiptoken( ).



      IF lv_skiptoken IS NOT INITIAL.

*Clear skiptoken value, if internal table is empty

        DATA(lv_table_size) = lines( et_entityset )."Count the number of records

        IF lv_table_size IS INITIAL.

          CLEAR es_response_context-skiptoken.

          EXIT.

        ENDIF.

*If the table size is less than the predefined page size, send all data

        IF lv_table_size < lv_page_size.

*Send all data

        ELSE.

          DATA(lv_index_start) = lv_skiptoken.

          DATA(lv_index_end)   = lv_skiptoken + lv_page_size.

        ENDIF.


*Show the output

        LOOP AT et_entityset INTO DATA(ls_entityset).

          IF sy-tabix > lv_index_start AND

             sy-tabix <= lv_index_end.

            APPEND ls_entityset TO lt_entityset.

          ENDIF.

        ENDLOOP.

        et_entityset = lt_entityset.

* Generate Next Link

        es_response_context-skiptoken = lv_index_end + 1.

        CONDENSE es_response_context-skiptoken.


      ENDIF.


Master Function Imports in SAP OData Part 19



Function Import:-
so_count_by_status

Importing :-
 Customer
Exporting :-
 Customer
 NotProcesed
 CompleteProcess
 NotRelvent



*******************************************************************




    CASE  iv_action_name .
      WHEN 'get_so_status'.
        TYPES:BEGIN OF ty_tab,
               vbeln TYPE vbeln,
               kunnr TYPE kunnr,
               rfstk TYPE rfstk,
              END OF ty_tab.
        DATA: it_tab TYPE TABLE OF ty_tab,
              lv_kunnr TYPE kunnr,
              ls_count TYPE zcl_zsalesorder_001_mpc=>ts_count,
              lt_count TYPE zcl_zsalesorder_001_mpc=>tt_count.

        DATA(lt_para)  =   io_tech_request_context->get_parameters( ).

        lv_kunnr = lt_para[ 1 ]-value .
        lv_kunnr = |{ lv_kunnr ALPHA = IN } |.



        SELECT so~vbeln
               so~kunnr
               sta~rfstk
          FROM vbak AS so
          LEFT OUTER JOIN vbuk AS sta
          ON so~vbeln = sta~vbeln
          INTO TABLE it_tab
          WHERE so~kunnr = lv_kunnr.
        IF sy-subrc IS INITIAL.
          ls_count-customer = lv_kunnr.
          LOOP AT it_tab ASSIGNING FIELD-SYMBOL(<ls_tab>).
            CASE <ls_tab>-rfstk.
              WHEN 'C'.
                ls_count-completeprocess = ls_count-completeprocess + 1.
              WHEN 'A'.
                ls_count-notprocesed  = ls_count-notprocesed + 1.
              WHEN ' '.
                ls_count-notrelvent =  ls_count-notrelvent  + 1.
            ENDCASE.

          ENDLOOP.
          APPEND ls_count to lt_count.

          /iwbep/if_mgw_conv_srv_runtime~copy_data_to_ref(
            EXPORTING
              is_data = lt_count
            CHANGING
              cr_data = er_data
          ).
        ENDIF.
    ENDCASE.

❌
❌