Unmanaged scenario-CREATE BY ASSOCIATION- basic example in RAP

Step 1: Create a table for Header details. 

@EndUserText.label : 'Student header table'

@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE

@AbapCatalog.tableCategory : #TRANSPARENT

@AbapCatalog.deliveryClass : #A

@AbapCatalog.dataMaintenance : #RESTRICTED

define table ztl_ab_stuh_13 {


key client : abap.clnt not null;

key id : sysuuid_x16 not null;

stu_id : abap.dec(10,0);

stu_name : abap.char(25);

stu_age : abap.numc(2);

stu_course : abap.char(30);

stu_cour_dur : abap.numc(2);

stu_status : abap_boolean;

stu_gender : zde_ab_gender;

stu_gen_desc : abap.char(10);

stu_dob : abap.dats;

last_ch_time : timestampl;

last_ch_date : timestampl;


}

Step 2: Create domains, data elements for gender, course, semester and semester results.

        Refer:- Create domains and data elements in RAP

Step 3: Create a table for Item details. 

@EndUserText.label : 'Results table'

@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE

@AbapCatalog.tableCategory : #TRANSPARENT

@AbapCatalog.deliveryClass : #A

@AbapCatalog.dataMaintenance : #RESTRICTED

define table ztl_ab_stui_13 {


key client : abap.clnt not null;

@AbapCatalog.foreignKey.screenCheck : false

key id : sysuuid_x16 not null

with foreign key ztl_ab_stuh_13

where client = ztl_ab_stui_13.client

and id = ztl_ab_stui_13.id;

course : zde_ab_course;

course_desc : abap.char(40);

semester : zde_ab_sem;

semester_desc : abap.char(20);

sem_result : zde_ab_result;

sem_re_desc : abap.char(40);


}

Step 4: Create data definition for domain - Gender.

@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Gender data defintion'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

}

define view entity ZD_AB_STU_GENDER

as select from DDCDS_CUSTOMER_DOMAIN_VALUE_T( p_domain_name: 'ZD_GENDER' )

{

key domain_name,

key value_position,

@Semantics.language: true

key language,

value_low as Value,

@Semantics.text: true

text as Description

}

Step 5: Create data definition for domain - Course.

@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Course data definition'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

}

define view entity ZD_AB_STU_COURSE

as select from DDCDS_CUSTOMER_DOMAIN_VALUE_T( p_domain_name: 'ZD_COURSE' )

{

key domain_name,

key value_position,

@Semantics.language: true

key language,

value_low as Value,

@Semantics.text: true

text as Description

}

Step 6: Create data definition for domain - Semester.

@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Data definition for Semester'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

}

define view entity ZD_AB_STU_SEM

as select from DDCDS_CUSTOMER_DOMAIN_VALUE_T( p_domain_name:'ZD_SEM' )

{

key domain_name,

key value_position,

@Semantics.language: true

key language,

value_low as Value,

@Semantics.text: true

text as Description

}

Step 7: Create data definition for domain - Semester Results.

@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Data definition for Semester RESULTS'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

}

define view entity ZD_AB_STU_SEM_RES

as select from DDCDS_CUSTOMER_DOMAIN_VALUE_T( p_domain_name:'ZD_RESULT' )

{

key domain_name,

key value_position,

@Semantics.language: true

key language,

value_low as Value,

@Semantics.text: true

text as Description

}

Step 8: Create Interface view for Header table.

@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Interface entity view for student header'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

}

define root view entity ZIV_AB_STUH_13

as select from ztl_ab_stuh_13

composition [ 0..*] of ZIV_AB_STUI_13 as _Result

association to ZD_AB_STU_GENDER as _Gender on $projection.StuGender = _Gender.Value

{

key id as Id,

stu_id as StuId,

stu_name as StuName,

stu_age as StuAge,

stu_course as StuCourse,

stu_cour_dur as StuCourDur,

stu_status as StuStatus,

stu_gender as StuGender,

stu_gen_desc as StuGenDesc,

stu_dob as StuDob,

last_ch_time as LastChTime,

last_ch_date as LastChDate,

_Result,

_Gender

}

Step 9: Create Interface view for Item table.

@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Interface entity view for student item'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

}

define view entity ZIV_AB_STUI_13

as select from ztl_ab_stui_13

association to parent ZIV_AB_STUH_13 as _Student on $projection.Id = _Student.Id

association [ 0..1 ] to ZD_AB_STU_COURSE as _Course on $projection.Course = _Course.Value

association [ 0..1 ] to ZD_AB_STU_SEM as _Sem on $projection.Semester = _Sem.Value

association [ 0..1 ] to ZD_AB_STU_SEM_RES as _Semres on $projection.SemResult = _Semres.Value

{

key id as Id,

course as Course,

course_desc as CourseDesc,

semester as Semester,

semester_desc as SemesterDesc,

sem_result as SemResult,

sem_re_desc as SemReDesc,

_Student,

_Course,

_Sem,

_Semres

}

Step 10: Create Consumption/Projection view for Header interface view.

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Consumption view for Header'

@Metadata.ignorePropagatedAnnotations: true

@Metadata.allowExtensions: true

define root view entity ZCV_AB_STUH_13

provider contract transactional_query

as projection on ZIV_AB_STUH_13


{

key Id,

StuId,

StuName,

StuAge,

StuCourse,

StuCourDur,

StuStatus,

StuGender,

StuGenDesc,

StuDob,

LastChTime,

LastChDate,

/* Associations */

_Result : redirected to composition child ZCV_AB_STUI_13

}

Step 11: Create Consumption/Projection view for Item interface view.

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Consumption view for RESULTS'

@Metadata.ignorePropagatedAnnotations: true

@Metadata.allowExtensions: true

define view entity ZCV_AB_STUI_13

//provider contract transactional_query

as projection on ZIV_AB_STUI_13

{

key Id,

Course,

CourseDesc,

Semester,

SemesterDesc,

SemResult,

SemReDesc,

/* Associations */

_Course,

_Sem,

_Semres,

_Student : redirected to parent ZCV_AB_STUH_13

}

Step 12: Create meta data extension for Header consumption view.

@Metadata.layer: #CORE

@UI: {

headerInfo:

{

typeName: 'Student',

typeNamePlural: 'Students',

title: {

type: #STANDARD,

label: 'Student',

value: 'StuId'

}

}

}

annotate entity ZCV_AB_STUH_13

with

{

@UI.facet:

[{

id : 'Student',

purpose: #STANDARD,

type: #IDENTIFICATION_REFERENCE,

label: 'Student',

position: 10

},

{

id : 'Result',

purpose: #STANDARD,

type: #LINEITEM_REFERENCE,

label: 'Results',

position: 20,

targetElement: '_Result'

}

]

@UI:

{

lineItem: [{ position: 10 , label : 'ID'}],

identification: [{ position: 10 , label : 'ID' }],

selectionField: [{ position: 10 }]

}

Id;

@UI:

{

lineItem: [{ position: 20 , label : 'Student ID'}],

identification: [{ position: 20 , label : 'Student ID' }],

selectionField: [{ position: 20 }]

}

StuId;

@UI:

{

lineItem: [{ position: 30 , label : 'Student Name'}],

identification: [{ position: 30 , label : 'Student Name' }],

selectionField: [{ position: 30 }]

}

StuName;

@UI:

{

lineItem: [{ position: 40 , label : 'Student Age'}],

identification: [{ position: 40 , label : 'Student Age' }]

}

StuAge;

@UI:

{

lineItem: [{ position: 50 , label : 'Student Course'}],

identification: [{ position: 50 , label : 'Student Course' }]

}

StuCourse;

@UI:

{

lineItem: [{ position: 60 , label : 'Course Duration'}],

identification: [{ position: 60 , label : 'Course Duration' }]

}

StuCourDur;

@UI:

{

lineItem: [{ position: 70 , label : 'Status'}],

identification: [{ position: 70 , label : 'Status' }]

}

StuStatus;

@UI:

{

lineItem: [{ position: 80 , label : 'Gender'}],

identification: [{ position: 80 , label : 'Gender' }]

}

@Consumption.valueHelpDefinition: [{ entity: { name : 'ZD_AB_STU_GENDER' , element : 'Value' },

distinctValues: true,

additionalBinding: [{ localElement: 'StuGenDesc',

element: 'Description',

usage: #FILTER_AND_RESULT

}]

}]

StuGender;

@UI:

{

lineItem: [{ position: 90 , label : 'Description'}],

identification: [{ position: 90 , label : 'Description' }]

}

StuGenDesc;

@UI:

{

lineItem: [{ position: 100 , label : 'Date of Birth'}],

identification: [{ position: 100 , label : 'Date of Birth' }]

}

StuDob;

/* Associations */

// _Result : re;

}

Step 13: Create meta data extension for Item consumption view.

@Metadata.layer: #CORE

annotate entity ZCV_AB_STUI_13

with

{

@UI.facet:

[{

id : 'Results',

purpose: #STANDARD,

type: #IDENTIFICATION_REFERENCE,

label: 'Student Results',

position: 10

}

]

@UI:

{

lineItem: [{ position: 10 , label : 'ID'}],

identification: [{ position: 10 , label : 'ID' }]

}

Id;

@UI:

{

lineItem: [{ position: 20 , label : 'Course'}],

identification: [{ position: 20 , label : 'Course' }]

}

@Consumption.valueHelpDefinition: [{ entity: { name : 'ZD_AB_STU_COURSE' , element : 'Value' },

distinctValues: true,

additionalBinding: [{ localElement: 'CourseDesc',

element: 'Description',

usage: #FILTER_AND_RESULT

}]

}]

Course;

@UI:

{

lineItem: [{ position: 30 , label : 'Course Description'}],

identification: [{ position: 30 , label : 'Course Description' }]

}

CourseDesc;

@UI:

{

lineItem: [{ position: 40 , label : 'Semester'}],

identification: [{ position: 40 , label : 'Semester' }]

}

@Consumption.valueHelpDefinition: [{ entity: { name : 'ZD_AB_STU_SEM' , element : 'Value' },

distinctValues: true,

additionalBinding: [{ localElement: 'SemesterDesc',

element: 'Description',

usage: #FILTER_AND_RESULT

}]

}]

Semester;

@UI:

{

lineItem: [{ position: 50 , label : 'Semester Description'}],

identification: [{ position: 50 , label : 'Semester Description' }]

}

SemesterDesc;

@UI:

{

lineItem: [{ position: 60 , label : 'Result'}],

identification: [{ position: 60 , label : 'Result' }]

}

@Consumption.valueHelpDefinition: [{ entity: { name : 'ZD_AB_STU_SEM_RES' , element : 'Value' },

distinctValues: true,

additionalBinding: [{ localElement: 'SemReDesc',

element: 'Description',

usage: #FILTER_AND_RESULT

}]

}]

SemResult;

@UI:

{

lineItem: [{ position: 70 , label : 'Result Description'}],

identification: [{ position: 70 , label : 'Result Description' }]

}

SemReDesc;

/* Associations */

//_Student : red

}

Step 14: Create behavior definition for Header interface view.

unmanaged implementation in class zbp_iv_ab_stuh_13 unique;

strict ( 2 );

with draft;

define behavior for ZIV_AB_STUH_13 alias Student

draft table ZDRA_AB_STUH_13

early numbering

lock master

total etag LastChDate

authorization master ( instance )

etag master LastChDate

{

create ( authorization : global );

update ;

delete ;

field ( readonly ) Id,StuId, StuGenDesc;

association _Result { create;with draft; }

draft action Edit;

draft action Activate optimized;

draft action Discard;

draft action Resume;

draft determine action Prepare;

mapping for ztl_ab_stuh_13 control zstr_up_stuh

{

Id = id;

StuId = stu_id;

StuName = stu_name;

StuAge = stu_age;

StuCourse = stu_course;

StuCourDur = stu_cour_dur;

StuGender = stu_gender;

StuGenDesc = stu_gen_desc;

StuDob = stu_dob;

StuStatus = stu_status;


}

}


define behavior for ZIV_AB_STUI_13 alias Result

draft table ZDRA_AB_STUI_13

early numbering

lock dependent by _Student

authorization dependent by _Student

etag dependent by _Student

{

update;

delete;

field ( readonly ) Id, CourseDesc, SemesterDesc, SemReDesc;

association _Student{ with draft; }

mapping for ztl_ab_stui_13

{

Id = id;

Course = course;

CourseDesc = course_desc;

Semester = semester;

SemesterDesc = semester_desc;

SemResult = sem_result;

SemReDesc = sem_re_desc;

}

}

Step 15: Double (ctrl+double click) click on any method like create or update and add logic.

CLASS lhc_Student DEFINITION INHERITING FROM cl_abap_behavior_handler.

PRIVATE SECTION.


METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION

IMPORTING keys REQUEST requested_authorizations FOR Student RESULT result.


METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION

IMPORTING REQUEST requested_authorizations FOR Student RESULT result.


METHODS create FOR MODIFY

IMPORTING entities FOR CREATE Student.


METHODS earlynumbering_create FOR NUMBERING

IMPORTING entities FOR CREATE Student.


METHODS update FOR MODIFY

IMPORTING entities FOR UPDATE Student.


METHODS delete FOR MODIFY

IMPORTING keys FOR DELETE Student.


METHODS read FOR READ

IMPORTING keys FOR READ Student RESULT result.


METHODS lock FOR LOCK

IMPORTING keys FOR LOCK Student.


METHODS rba_Result FOR READ

IMPORTING keys_rba FOR READ Student\_Result FULL result_requested RESULT result LINK association_links.


METHODS cba_Result FOR MODIFY

IMPORTING entities_cba FOR CREATE Student\_Result.


METHODS earlynumbering_cba_Result FOR NUMBERING

IMPORTING entities FOR CREATE Student\_Result.


ENDCLASS.


CLASS lhc_Student IMPLEMENTATION.


METHOD get_instance_authorizations.

ENDMETHOD.


METHOD get_global_authorizations.

ENDMETHOD.


METHOD create.

zcl_ab_stuh_13=>get_instance( )->create_student(

EXPORTING

entities = entities

CHANGING

failed = failed

mapped = mapped

reported = reported ).

ENDMETHOD.


METHOD earlynumbering_create.

TRY.

zcl_ab_stuh_13=>get_instance( )->earlynumbering_create(

EXPORTING

entities = entities

CHANGING

failed = failed

mapped = mapped

reported = reported ).

CATCH cx_uuid_error.

"handle exception

ENDTRY.


ENDMETHOD.


METHOD update.

zcl_ab_stuh_13=>get_instance( )->update(

EXPORTING

entities = entities

CHANGING

mapped = mapped

failed = failed

reported = reported

).

ENDMETHOD.


METHOD delete.

zcl_ab_stuh_13=>get_instance( )->delete(

EXPORTING

keys = keys

CHANGING

mapped = mapped

failed = failed

reported = reported

).

ENDMETHOD.


METHOD read.

zcl_ab_stuh_13=>get_instance( )->read_student(

EXPORTING

keys = keys

CHANGING

result = result

failed = failed

reported = reported

).

ENDMETHOD.


METHOD lock.

ENDMETHOD.


METHOD rba_Result.

ENDMETHOD.


METHOD cba_Result.

zcl_ab_stuh_13=>get_instance( )->cba_result_create(

EXPORTING

entities_cba = entities_cba

CHANGING

mapped = mapped

failed = failed

reported = reported

).


ENDMETHOD.


METHOD earlynumbering_cba_Result.

zcl_ab_stuh_13=>get_instance( )->earlynumbering_cba_result(

EXPORTING

entities = entities

CHANGING

mapped = mapped

failed = failed

reported = reported

).

ENDMETHOD.



ENDCLASS.


CLASS lhc_Result DEFINITION INHERITING FROM cl_abap_behavior_handler.

PRIVATE SECTION.


METHODS update FOR MODIFY

IMPORTING entities FOR UPDATE Result.


METHODS delete FOR MODIFY

IMPORTING keys FOR DELETE Result.


METHODS read FOR READ

IMPORTING keys FOR READ Result RESULT result.


METHODS rba_Student FOR READ

IMPORTING keys_rba FOR READ Result\_Student FULL result_requested RESULT result LINK association_links.


ENDCLASS.


CLASS lhc_Result IMPLEMENTATION.


METHOD update.

ENDMETHOD.


METHOD delete.

ENDMETHOD.


METHOD read.

ENDMETHOD.


METHOD rba_Student.

ENDMETHOD.


ENDCLASS.


CLASS lsc_ZIV_AB_STUH_13 DEFINITION INHERITING FROM cl_abap_behavior_saver.

PROTECTED SECTION.


METHODS finalize REDEFINITION.


METHODS check_before_save REDEFINITION.


METHODS save REDEFINITION.


METHODS cleanup REDEFINITION.


METHODS cleanup_finalize REDEFINITION.


ENDCLASS.


CLASS lsc_ZIV_AB_STUH_13 IMPLEMENTATION.


METHOD finalize.

ENDMETHOD.


METHOD check_before_save.

ENDMETHOD.


METHOD save.

zcl_ab_stuh_13=>get_instance( )->save_data(

CHANGING

reported = reported ).

ENDMETHOD.


METHOD cleanup.

ENDMETHOD.


METHOD cleanup_finalize.

ENDMETHOD.


ENDCLASS.

Step 16: Create global class and implement methods.

CLASS zcl_ab_stuh_13 DEFINITION

PUBLIC

FINAL

CREATE PUBLIC .


PUBLIC SECTION.

TYPES:

tt_create_student TYPE TABLE FOR CREATE ziv_ab_stuh_13,

tt_map_early TYPE RESPONSE FOR MAPPED EARLY ziv_ab_stuh_13,

tt_failed_early TYPE RESPONSE FOR FAILED EARLY ziv_ab_stuh_13,

tt_report_early TYPE RESPONSE FOR REPORTED EARLY ziv_ab_stuh_13,

tt_response_late TYPE RESPONSE FOR REPORTED LATE ziv_ab_stuh_13,


tt_keys_student TYPE TABLE FOR READ IMPORT ziv_ab_stuh_13, "\\student,

tt_result_student TYPE TABLE FOR READ RESULT ziv_ab_stuh_13, "\\student,

tt_update_student TYPE TABLE FOR UPDATE ziv_ab_stuh_13, "\\student,


tt_delete_student TYPE TABLE FOR DELETE ziv_ab_stuh_13,

tt_cba_results TYPE TABLE FOR CREATE ziv_ab_stuh_13\\student\_result.

CLASS-METHODS: get_instance

RETURNING VALUE(r_instance)

TYPE REF TO zcl_ab_stuh_13,

create_student

IMPORTING

entities TYPE tt_create_student

CHANGING

mapped TYPE tt_map_early

failed TYPE tt_failed_early

reported TYPE tt_report_early,

get_next_id

RETURNING VALUE(rv_id) TYPE ziv_ab_stuh_13-StuId,

earlynumbering_create

IMPORTING entities TYPE tt_create_student

CHANGING mapped TYPE tt_map_early

failed TYPE tt_failed_early

reported TYPE tt_report_early

RAISING

cx_uuid_error,

save_data

CHANGING

reported TYPE tt_response_late,

read_student

IMPORTING

keys TYPE tt_keys_student

CHANGING

result TYPE tt_result_student

failed TYPE tt_failed_early

reported TYPE tt_report_early,

update

IMPORTING

entities TYPE tt_update_student

CHANGING

mapped TYPE tt_map_early

failed TYPE tt_failed_early

reported TYPE tt_report_early,

delete

IMPORTING

keys TYPE tt_delete_student

CHANGING

mapped TYPE tt_map_early

failed TYPE tt_failed_early

reported TYPE tt_report_early,

earlynumbering_cba_result

IMPORTING

entities TYPE tt_cba_results

CHANGING

mapped TYPE tt_map_early

failed TYPE tt_failed_early

reported TYPE tt_report_early,

cba_result_create

IMPORTING

entities_cba TYPE tt_cba_results

CHANGING

mapped TYPE tt_map_early

failed TYPE tt_failed_early

reported TYPE tt_report_early.

PROTECTED SECTION.

PRIVATE SECTION.

CLASS-DATA: mo_instance TYPE REF TO zcl_ab_stuh_13,

gt_student TYPE STANDARD TABLE OF ztl_ab_stuh_13, " WITH EMPTY KEY,

gs_student TYPE ztl_ab_stuh_13,

gs_mmaped TYPE tt_map_early,

gr_student_d TYPE RANGE OF ztl_ab_stuh_13-id,

gt_results TYPE STANDARD TABLE OF ztl_ab_stui_13.

ENDCLASS.




CLASS zcl_ab_stuh_13 IMPLEMENTATION.

METHOD get_instance.

mo_instance = r_instance = COND #( WHEN mo_instance IS BOUND

THEN mo_instance

ELSE NEW #( ) ).

ENDMETHOD.


METHOD get_next_id.

SELECT MAX( stu_id ) FROM ztl_ab_stuh_13 INTO @DATA(lv_id1).

rv_id = lv_id1 + 1.

ENDMETHOD.


METHOD earlynumbering_create.

DATA(ls_mapped) = gs_mmaped.

DATA(lv_id) = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).

DATA(lv_stuid) = get_next_id( ).

READ TABLE gt_student ASSIGNING FIELD-SYMBOL(<gs_student>) INDEX 1.

IF <gs_student> IS ASSIGNED.

<gs_student>-id = lv_stuid.

UNASSIGN <gs_student>.

ENDIF.


mapped-student = VALUE #(

FOR ls_entities IN entities WHERE ( id IS INITIAL )

(

%cid = ls_entities-%cid

%is_draft = ls_entities-%is_draft

Id = lv_id ) ) .

ENDMETHOD.


METHOD create_student.

gt_student = CORRESPONDING #( entities MAPPING FROM ENTITY ).

IF gt_student IS NOT INITIAL.

gt_student[ 1 ]-stu_id = get_next_id( ).


ENDIF.

LOOP AT entities ASSIGNING FIELD-SYMBOL(<ls_entities>).

mapped-student = VALUE #( (

%cid = <ls_entities>-%cid

%key = <ls_entities>-%key

%is_draft = <ls_entities>-%is_draft

) ) .

ENDLOOP.

ENDMETHOD.


METHOD save_data.

IF NOT gt_student[] IS INITIAL.

MODIFY ztl_ab_stuh_13 FROM TABLE @gt_student.

ENDIF.


IF NOT gr_student_d IS INITIAL.

DELETE FROM ztl_ab_stuh_13 WHERE id IN @gr_student_d.

ENDIF.


IF NOT gt_results IS INITIAL.

MODIFY ztl_ab_stui_13 FROM TABLE @gt_results.

ENDIF.

ENDMETHOD.


METHOD read_student.

SELECT * FROM ztl_ab_stuh_13

FOR ALL ENTRIES IN @keys

WHERE id = @keys-Id

INTO TABLE @DATA(lt_read_student).


result = CORRESPONDING #( lt_read_student MAPPING TO ENTITY ).

ENDMETHOD.


METHOD update.

DATA: lt_stu_update TYPE STANDARD TABLE OF ztl_ab_stuh_13,

lt_stu_update_x TYPE STANDARD TABLE OF zstr_up_stuh.


lt_stu_update = CORRESPONDING #( entities MAPPING FROM ENTITY ).

lt_stu_update_x = CORRESPONDING #( entities MAPPING FROM ENTITY USING CONTROL ).


IF NOT lt_stu_update IS INITIAL.

SELECT * FROM ztl_ab_stuh_13

FOR ALL ENTRIES IN @lt_stu_update

WHERE id = @lt_stu_update-Id

INTO TABLE @DATA(lt_stu_old).

ENDIF.

gt_student = VALUE #(

"FOR idx=1 idx <= lines( lt_stu_update )

LET

ls_control_flag = VALUE #( lt_stu_update_x[ 1 ] OPTIONAL )

ls_student_new = VALUE #( lt_stu_update[ 1 ] OPTIONAL )

ls_student_old = VALUE #( lt_stu_old[ id = ls_student_new-id ] OPTIONAL )

IN

(

id = ls_student_new-id

stu_id = COND #( WHEN ls_control_flag-stu_id IS NOT INITIAL

THEN ls_student_new-stu_id

ELSE ls_student_old-stu_id )

stu_name = COND #( WHEN ls_control_flag-stu_name IS NOT INITIAL

THEN ls_student_new-stu_name

ELSE ls_student_old-stu_name )

stu_age = COND #( WHEN ls_control_flag-stu_age IS NOT INITIAL

THEN ls_student_new-stu_age

ELSE ls_student_old-stu_age )

stu_course = COND #( WHEN ls_control_flag-stu_course IS NOT INITIAL

THEN ls_student_new-stu_course

ELSE ls_student_old-stu_course )

stu_cour_dur = COND #( WHEN ls_control_flag-stu_cour_dur IS NOT INITIAL

THEN ls_student_new-stu_cour_dur

ELSE ls_student_old-stu_cour_dur )

stu_status = COND #( WHEN ls_control_flag-stu_status IS NOT INITIAL

THEN ls_student_new-stu_status

ELSE ls_student_old-stu_status )

stu_gender = COND #( WHEN ls_control_flag-stu_gender IS NOT INITIAL

THEN ls_student_new-stu_gender

ELSE ls_student_old-stu_gender )

stu_gen_desc = COND #( WHEN ls_control_flag-stu_gen_desc IS NOT INITIAL

THEN ls_student_new-stu_gen_desc

ELSE ls_student_old-stu_gen_desc )


stu_dob = COND #( WHEN ls_control_flag-stu_dob IS NOT INITIAL

THEN ls_student_new-stu_dob

ELSE ls_student_old-stu_dob )



) ).


ENDMETHOD.


METHOD delete.

DATA: lt_stu_delete TYPE TABLE OF ztl_ab_stuh_13.


lt_stu_delete = CORRESPONDING #( keys MAPPING FROM ENTITY ).


gr_student_d = VALUE #(

FOR ls_student IN lt_stu_delete

sign = 'I'

option = 'EQ'

( low = ls_student-id )


).


ENDMETHOD.


METHOD earlynumbering_cba_result.

LOOP AT entities ASSIGNING FIELD-SYMBOL(<ls_entities>).

LOOP AT <ls_entities>-%target ASSIGNING FIELD-SYMBOL(<ls_results>).

mapped-result = VALUE #( (

%cid = <ls_results>-%cid

%is_draft = <ls_results>-%is_draft

%key = <ls_results>-%key ) ) .

ENDLOOP.

ENDLOOP..

ENDMETHOD.


METHOD cba_result_create.

gt_results = VALUE #(

FOR ls_entities IN entities_cba

FOR ls_result IN ls_entities-%target

LET

ls_rap_results = CORRESPONDING ztl_ab_stui_13( ls_result MAPPING FROM ENTITY )

IN

(

ls_rap_results

)

).


mapped = VALUE #(

result = VALUE #(

FOR x = 1 WHILE x <= lines( entities_cba )

LET

lt_results = VALUE #( entities_cba[ x ]-%target OPTIONAL )

IN

FOR y = 1 WHILE y <= lines( lt_results )

LET

ls_curr_res = VALUE #( lt_results[ y ] OPTIONAL )

IN

(

%cid = ls_curr_res-%cid

%key = ls_curr_res-%key

Id = ls_curr_res-Id

)

) ).

ENDMETHOD.


ENDCLASS.

Step 17: Create behavior definition for Header consumption view.

projection;

strict ( 2 );

use draft;


define behavior for ZCV_AB_STUH_13 alias Student

{

use create;

use update;

use delete;


use action Edit;

use action Activate;

use action Discard;

use action Resume;

use action Prepare;


use association _Result { create; with draft; }

}


define behavior for ZCV_AB_STUI_13 alias Result

{

use update;

use delete;


use association _Student { with draft; }

}

Step 18: Create service definition and expose consumption header and item views.

@EndUserText.label: 'Service definition for Student'

define service ZSD_AB_STUH_13 {

expose ZCV_AB_STUH_13;

expose ZCV_AB_STUI_13;

}

Step 19: Create service binding for above service definition.

            * Check, activate and publish the service.



Testing
        * Preview the application.
        * Click on go to see all records.

        * Navigate to object page.

      * Click on edit and create entries for item.


        * Click on apply and click on save.

        * Item details are created successfully.



******************************Thank you*******************************

Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).