Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.2.0 #121

Merged
merged 12 commits into from
Jul 12, 2024
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

## Description

An OData ABAP Framework
An OData ABAP Framework, that focuses on a easy and fast way to create OData Services in ABAP. Changes to the OData service are done in the code for data changes and in the customizing for model changes, no need to regenerate the service after changes.
Every entity has it own class, therefore every class can be reused in entities of other services.
It also reduces the mainly unused `CRUD` methods that the `SEGW` will create for every entity.
The purpose of this framework is to create a simple Odata service within a few minutes.
Every service that uses this framework can easy be extended.

## Documentation
The documentation and how to use can be found under [Documentation](https://miggi92.github.io/odata-fw/)
Expand Down
6 changes: 4 additions & 2 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: nav(),
externalLinkIcon: true,
editLink: {
pattern: 'https://github.com/miggi92/odata-fw/edit/master/docs/:path',
text: 'Edit this page on GitHub'
Expand Down Expand Up @@ -74,7 +75,7 @@ export default
},
}
}
);
);

function nav() {
return [
Expand All @@ -85,7 +86,7 @@ function nav() {
items: [
{
text: 'Changelog',
link: 'https://github.com/miggi92/odata-fw/blob/master/CHANGELOG.md'
link: 'https://github.com/miggi92/odata-fw/blob/master/changelog.txt'
},
{
text: 'Contributing',
Expand All @@ -104,6 +105,7 @@ function sidebarDocumentation() {
items: [
{ text: 'Creating a service', link: '/documentation/Creating-a-service' },
{ text: 'DPC boilerplate code', link: '/documentation/DPC-boilerplate-code' },
{ text: 'SADL', link: '/documentation/sadl' },
{
text: 'OData customizing', link: '/documentation/customizing/', collapsed: true,
items: [
Expand Down
5 changes: 5 additions & 0 deletions docs/documentation/DPC-boilerplate-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Implementation:
``` abap
DATA(ls_data_provider) = me->mt_data_providers->get( iv_entity_name ).
ls_data_provider-instance->before_processing( ).
ls_data_provider-instance->set_context( mo_context ). " for SADL features

ls_data_provider-instance->/iwbep/if_mgw_appl_srv_runtime~get_entity(
EXPORTING
Expand Down Expand Up @@ -48,6 +49,8 @@ Implementation:
```abap
DATA(ls_data_provider) = me->mt_data_providers->get( iv_entity_name ).
ls_data_provider-instance->before_processing( ).
ls_data_provider-instance->set_context( mo_context ). " for SADL features

ls_data_provider-instance->/iwbep/if_mgw_appl_srv_runtime~get_entityset(
EXPORTING
iv_entity_name = iv_entity_name
Expand Down Expand Up @@ -79,6 +82,8 @@ Implementation:
METHOD /iwbep/if_mgw_appl_srv_runtime~create_deep_entity.
DATA(ls_data_provider) = me->mt_data_providers->get( iv_entity_name ).
ls_data_provider-instance->before_processing( ).
ls_data_provider-instance->set_context( mo_context ). " for SADL features

ls_data_provider-instance->/iwbep/if_mgw_appl_srv_runtime~create_deep_entity(
EXPORTING
iv_entity_name = iv_entity_name
Expand Down
49 changes: 49 additions & 0 deletions docs/documentation/sadl/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: SADL
---
# {{ $frontmatter.title }}

The Service Adaptation Definition Language or SADL feature was introduced with version [1.2.0](https://github.com/miggi92/odata-fw/releases/tag/v1.2.0) of this framework.
And is used for the [Analytical table](https://experience.sap.com/fiori-design-web/analytical-table-alv/) in UI5.

## SADL XML

The SADL XML is automatically generated by the framework. No need to add there something manually.

## Define Keys

Every `dimension` annoation will be a key in the SADL framework.

Example:
```abap
DATA(lo_entity_type_inv) = model->get_entity_type( 'invoicesDocuments' ).
lo_entity_type_inv->set_semantic( /iwbep/if_ana_odata_types=>gcs_ana_odata_semantic_value-query-aggregate ).

DATA(lo_property_inv) = lo_entity_type_inv->get_property( 'accountingArea' ).
DATA(lo_annotation_inv) =
lo_property_inv->/iwbep/if_mgw_odata_annotatabl~create_annotation(
/iwbep/if_mgw_med_odata_types=>gc_sap_namespace ).
lo_annotation_inv->add(
iv_key = /iwbep/if_ana_odata_types=>gcs_ana_odata_annotation_key-aggregation_role
iv_value = /iwbep/if_ana_odata_types=>gcs_ana_odata_annotation_value-dimension-dimension ).

```


## Structure

In the structure that is used for the entity you should create a property `GENERATED_KEY` in the ABAP and `GeneratedKey` in the odata customizing.
The key value is generated by the SADL framework.

## How it knows when to use SADL?

If you use the `if_sadl_gw_dpc_util~get_dpc` method that is shipped with the `ZCL_ODATA_MAIN` class, the framework will automatically use the SADL framework.

```abap
if_sadl_gw_dpc_util~get_dpc( )->get_entityset(
EXPORTING
io_tech_request_context = io_tech_request_context
IMPORTING
et_data = lt_invoices
es_response_context = es_response_context ).
```
14 changes: 7 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ layout: home
hero:
name: "ABAP OData Framework"
text: "A odata framework for a SAP System. "
tagline: My great project tagline
tagline: Custom reusable framework for OData services in ABAP.
actions:
- theme: brand
text: Documentation
link: /documentation/

features:
- title: Feature A
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature B
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature C
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Reusable
details: The entities created with this framework can be reused in other odata projects.
- title: Quick Service Creation
details: The service creation is very fast and easy.
- title: Focus on developer
details: The framework is focused on the developer, making the development process easier.
---

63 changes: 4 additions & 59 deletions src/zcl_odata_fw_controller.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ CLASS zcl_odata_fw_controller DEFINITION
PRIVATE SECTION.
DATA mo_customizing TYPE REF TO zcl_odata_fw_cust.

"! <p class="shorttext synchronized">Get table type</p>
"! @parameter rv_type | <p class="shorttext synchronized">Table type</p>
METHODS get_table_type
RETURNING VALUE(rv_type) TYPE string.
ENDCLASS.


Expand All @@ -65,62 +61,11 @@ CLASS zcl_odata_fw_controller IMPLEMENTATION.
ENDMETHOD.

METHOD define_sadl_xml.
DATA lt_sadl_entities TYPE zodata_entity_tt.

rv_sadl_xml = |<?xml version="1.0" encoding="utf-16"?>| &
|<sadl:definition xmlns:sadl="http://sap.com/sap.nw.f.sadl" syntaxVersion="V2" >|.

DATA(lt_entities) = mo_customizing->get_entities( ).
DATA(lt_properties) = mo_customizing->get_properties( ).

LOOP AT lt_entities ASSIGNING FIELD-SYMBOL(<ls_entity>) WHERE is_complex = abap_false.

DATA(lv_type) = get_table_type( <ls_entity>-structure ).

if lv_type is initial.
continue.
endif.

rv_sadl_xml = |{ rv_sadl_xml }| &
| <sadl:dataSource type="{ lv_type }" name="{ <ls_entity>-entity_name }Set" binding="{ <ls_entity>-structure }" />|.
APPEND <ls_entity> TO lt_sadl_entities.
ENDLOOP.

rv_sadl_xml = |{ rv_sadl_xml }| & |<sadl:resultSet>|.
LOOP AT lt_sadl_entities ASSIGNING <ls_entity>.

rv_sadl_xml = |{ rv_sadl_xml }| &
|<sadl:structure name="{ <ls_entity>-entity_name }Collection" dataSource="{ <ls_entity>-entity_name }Set" maxEditMode="RO" >| &
| <sadl:query name="EntitySetDefault">| &
| </sadl:query>|.
DATA(lt_properties) = mo_customizing->get_properties( ).
DELETE lt_properties WHERE entity_name <> <ls_entity>-entity_name.

LOOP AT lt_properties ASSIGNING FIELD-SYMBOL(<ls_property>) WHERE is_key = abap_false.
rv_sadl_xml = |{ rv_sadl_xml }| &
| <sadl:attribute name="{ <ls_property>-abap_name }" binding="{ <ls_property>-abap_name }" isOutput="TRUE" isKey="FALSE" />|.
ENDLOOP.
rv_sadl_xml = |{ rv_sadl_xml }| & |</sadl:structure>|.
ENDLOOP.

rv_sadl_xml = |{ rv_sadl_xml }| & |</sadl:resultSet>| &
|</sadl:definition>|.
ENDMETHOD.

METHOD get_table_type.
DATA lo_structure TYPE REF TO cl_abap_structdescr.

lo_structure ?= cl_abap_elemdescr=>describe_by_name( iv_structure ).
IF NOT lo_structure->is_ddic_type( ).
return.
ENDIF.

CASE lo_structure->get_ddic_header( )-tabtype.
WHEN 'B'.
rv_type = 'CDS'.
WHEN 'T'.
rv_type = 'DDIC'.
WHEN OTHERS.
return.
ENDCASE.
DATA(lo_sadl) = NEW zcl_odata_fw_sadl( ).
rv_sadl_xml = lo_sadl->generate_sadl_xml( it_entities = lt_entities
it_properties = lt_properties ).
ENDMETHOD.
ENDCLASS.
88 changes: 88 additions & 0 deletions src/zcl_odata_fw_sadl.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"! <p class="shorttext synchronized">SADL Config</p>
CLASS zcl_odata_fw_sadl DEFINITION
PUBLIC
CREATE PUBLIC.

PUBLIC SECTION.
"! <p class="shorttext synchronized">Generate SADL XML</p>
"!
"! @parameter it_entities | <p class="shorttext synchronized">Entities</p>
"! @parameter it_properties | <p class="shorttext synchronized">Properties</p>
"! @parameter rv_sadl_xml | <p class="shorttext synchronized">SADL XML</p>
METHODS generate_sadl_xml
IMPORTING it_entities TYPE zodata_entity_tt
it_properties TYPE zodata_property_tt
RETURNING VALUE(rv_sadl_xml) TYPE string.

PROTECTED SECTION.

PRIVATE SECTION.
"! <p class="shorttext synchronized">Get table type</p>
"! @parameter iv_structure | <p class="shorttext synchronized">Structure name</p>
"! @parameter rv_type | <p class="shorttext synchronized">Table type</p>
METHODS get_table_type
IMPORTING iv_structure TYPE zodata_entity-structure
RETURNING VALUE(rv_type) TYPE string.
ENDCLASS.


CLASS zcl_odata_fw_sadl IMPLEMENTATION.
METHOD generate_sadl_xml.
DATA lt_sadl_entities TYPE zodata_entity_tt.

rv_sadl_xml = |<?xml version="1.0" encoding="utf-16"?>| &
|<sadl:definition xmlns:sadl="http://sap.com/sap.nw.f.sadl" syntaxVersion="V2" >|.

LOOP AT it_entities ASSIGNING FIELD-SYMBOL(<ls_entity>) WHERE is_complex = abap_false.

DATA(lv_type) = get_table_type( <ls_entity>-structure ).

IF lv_type IS INITIAL.
CONTINUE.
ENDIF.

rv_sadl_xml = |{ rv_sadl_xml }| &
| <sadl:dataSource type="{ lv_type }" name="{ <ls_entity>-entity_name }Set" binding="{ <ls_entity>-structure }" />|.
APPEND <ls_entity> TO lt_sadl_entities.
ENDLOOP.

rv_sadl_xml = |{ rv_sadl_xml }| & |<sadl:resultSet>|.
LOOP AT lt_sadl_entities ASSIGNING <ls_entity>.

rv_sadl_xml = |{ rv_sadl_xml }| &
|<sadl:structure name="{ <ls_entity>-entity_name }Collection" dataSource="{ <ls_entity>-entity_name }Set" maxEditMode="RO" >| &
| <sadl:query name="EntitySetDefault">| &
| </sadl:query>|.

DATA(lt_properties) = it_properties.
DELETE lt_properties WHERE entity_name <> <ls_entity>-entity_name.

LOOP AT lt_properties ASSIGNING FIELD-SYMBOL(<ls_property>) WHERE is_key = abap_false.
rv_sadl_xml = |{ rv_sadl_xml }| &
| <sadl:attribute name="{ <ls_property>-abap_name }" binding="{ <ls_property>-abap_name }" isOutput="TRUE" isKey="FALSE" />|.
ENDLOOP.
rv_sadl_xml = |{ rv_sadl_xml }| & |</sadl:structure>|.
ENDLOOP.

rv_sadl_xml = |{ rv_sadl_xml }| & |</sadl:resultSet>| &
|</sadl:definition>|.
ENDMETHOD.

METHOD get_table_type.
DATA lo_structure TYPE REF TO cl_abap_structdescr.

lo_structure ?= cl_abap_elemdescr=>describe_by_name( iv_structure ).
IF NOT lo_structure->is_ddic_type( ).
RETURN.
ENDIF.

CASE lo_structure->get_ddic_header( )-tabtype.
WHEN 'B'.
rv_type = 'CDS'.
WHEN 'T'.
rv_type = 'DDIC'.
WHEN OTHERS.
RETURN.
ENDCASE.
ENDMETHOD.
ENDCLASS.
60 changes: 60 additions & 0 deletions src/zcl_odata_fw_sadl.clas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_ODATA_FW_SADL</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>SADL Config</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
<DESCRIPTIONS>
<SEOCOMPOTX>
<CMPNAME>GENERATE_SADL_XML</CMPNAME>
<LANGU>E</LANGU>
<DESCRIPT>Generate SADL XML</DESCRIPT>
</SEOCOMPOTX>
<SEOCOMPOTX>
<CMPNAME>GET_TABLE_TYPE</CMPNAME>
<LANGU>E</LANGU>
<DESCRIPT>Get table type</DESCRIPT>
</SEOCOMPOTX>
</DESCRIPTIONS>
<DESCRIPTIONS_SUB>
<SEOSUBCOTX>
<CMPNAME>GENERATE_SADL_XML</CMPNAME>
<SCONAME>IT_ENTITIES</SCONAME>
<LANGU>E</LANGU>
<DESCRIPT>Entities</DESCRIPT>
</SEOSUBCOTX>
<SEOSUBCOTX>
<CMPNAME>GENERATE_SADL_XML</CMPNAME>
<SCONAME>IT_PROPERTIES</SCONAME>
<LANGU>E</LANGU>
<DESCRIPT>Properties</DESCRIPT>
</SEOSUBCOTX>
<SEOSUBCOTX>
<CMPNAME>GENERATE_SADL_XML</CMPNAME>
<SCONAME>RV_SADL_XML</SCONAME>
<LANGU>E</LANGU>
<DESCRIPT>SADL XML</DESCRIPT>
</SEOSUBCOTX>
<SEOSUBCOTX>
<CMPNAME>GET_TABLE_TYPE</CMPNAME>
<SCONAME>IV_STRUCTURE</SCONAME>
<LANGU>E</LANGU>
<DESCRIPT>Structure name</DESCRIPT>
</SEOSUBCOTX>
<SEOSUBCOTX>
<CMPNAME>GET_TABLE_TYPE</CMPNAME>
<SCONAME>RV_TYPE</SCONAME>
<LANGU>E</LANGU>
<DESCRIPT>Table type</DESCRIPT>
</SEOSUBCOTX>
</DESCRIPTIONS_SUB>
</asx:values>
</asx:abap>
</abapGit>
Loading
Loading