Validate multiple records in RAP

Isolated: Each record is processed on its own. Valid records succeed; invalid records fail without affecting others.

Aspect Change Set Isolated
Processing Mode Multiple records processed at once Multiple records processed at once
Validation All records must be valid (if one fails, all fail) Only valid records are processed; invalid records are skipped
Sessions Single session created for processing all records together Multiple sessions created—one per record
Execution All records processed in one go Each record processed independently
Failure Handling If any record fails, the entire operation fails (atomic) One record failing does not affect others (non-atomic)
Session DependencyRecords are dependent (same transaction) Records are independent (separate transactions)

Step 1: Change meta data extension.

@Metadata.layer: #CORE

@UI: {

headerInfo:

{

typeName: 'Student',

typeNamePlural: 'Students',

title: {

type: #STANDARD,

label: 'Student',

value: 'StuId'

}

}

}

annotate view ZCV_AB_RAP_STU11

with

{

@UI.facet:

[{

id : 'Student',

purpose: #STANDARD,

type: #IDENTIFICATION_REFERENCE,

label: 'Student',

position: 10

}

]

@UI:

{

lineItem: [{ position: 10 , label : 'Update Status',

type: #FOR_ACTION,

dataAction: 'StatusUpdate',

invocationGrouping: #ISOLATED }],

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

selectionField: [{ position: 10 }]

}

StuId;

@UI:

{

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

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

selectionField: [{ position: 20 }]

}

StuName;

@UI:

{

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

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

}

StuAge;

@UI:

{

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

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

}

StuCourse;

@UI:

{

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

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

}

StuCourDur;

@UI:

{

lineItem: [{ position: 60 , label : 'Student Status'}],

identification: [{ position: 60 , label : 'Student Status' }]

}

StuStatus;

@UI:

{

lineItem: [{ position: 70 , label : 'Student Gender'}],

identification: [{ position: 70 , label : 'Student Gender' }]

}

StuGender;

@UI:

{

lineItem: [{ position: 80 , label : 'Student DOB'}],

identification: [{ position: 80 , label : 'Student DOB' }]

}

StuDob;

}

Step 2: Add some additional logic in class.

CLASS lhc_Student DEFINITION INHERITING FROM cl_abap_behavior_handler.

PRIVATE SECTION.


METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION

IMPORTING REQUEST requested_authorizations FOR Student RESULT result.


METHODS StatusUpdate FOR MODIFY

IMPORTING keys FOR ACTION Student~StatusUpdate.


ENDCLASS.


CLASS lhc_Student IMPLEMENTATION.


METHOD get_global_authorizations.

ENDMETHOD.


METHOD StatusUpdate.

READ ENTITIES OF ziv_ab_rap_stu11 IN LOCAL MODE

ENTITY Student

ALL FIELDS WITH CORRESPONDING #( keys )

RESULT DATA(lt_students)

FAILED failed.

SORT lt_students BY StuStatus DESCENDING.

LOOP AT lt_students ASSIGNING FIELD-SYMBOL(<ls_students>).


IF <ls_students>-StuAge < 25.

APPEND VALUE #( %tky = <ls_students>-%tky ) TO failed-student.

APPEND VALUE #( %tky = <ls_students>-%tky

%msg = new_message_with_text(

severity = if_abap_behv_message=>severity-error

text = <ls_students>-StuName && ' has less than 25, status not updated'

) ) TO reported-student.

ELSE.

<ls_students>-StuStatus = abap_true.

ENDIF.

ENDLOOP.

IF failed-student IS INITIAL.

SORT lt_students BY StuStatus DESCENDING.

MODIFY ENTITIES OF ziv_ab_rap_stu11 IN LOCAL MODE

ENTITY Student

UPDATE FIELDS ( StuStatus ) WITH CORRESPONDING #( lt_students ).

ENDIF.

ENDMETHOD.


ENDCLASS.

Step 3:  Check and activate both the objects.

Step 4: Testing

       * Preview the application and click on go to see all the records.

      * Select all records and click on status update.



        * Only 2 records are updated.


********************************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+ ).