Validations in RAP

                                 Refer - Adding table in object page


Step 1: Refer Old blogposts (For better purpose).

Step 2: Changing Behavior definition- Adding validation.

managed implementation in class zbp_i_ab_rap_stus unique;

strict ( 2 );


define behavior for ZI_AB_RAP_STUS alias Student

persistent table ztl_ab_rap_stus

lock master

authorization master ( instance )

//etag master <field_name>

{

create ( authorization : global );

update;

delete;

association _qualify{ create; }

action ( features : instance ) Selected result [1] $self;

validation validateid on save { field StudentId; create; }

mapping for ztl_ab_rap_stus

{

StudentId = student_id;

StudentName = student_name;

StudentILoc = student_i_loc;

StudentIDate = student_i_date;

StudentStatus = student_status;

StudentGender = student_gender;

Description = description;


}

// field ( mandatory ) StudentId;

}



define behavior for ZI_AB_RAP_STUQ alias Qualification

persistent table ZTL_AB_RAP_STUQ

lock dependent by _student

authorization dependent by _student

{


update;

delete;

association _student;

field ( readonly ) StudentId;

field ( readonly ) QualDesc;

mapping for ZTL_AB_RAP_STUQ

{

StudentId = student_id;

StudentQual = student_qual;

QualDesc = qual_desc;

StudentFrom = student_from;

StudentTo = student_to;

StudentPercent = student_percent;

}


}

Step 3: Check and activate the behavior definition.

Step 4: Implement the method.

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_instance_features FOR INSTANCE FEATURES

IMPORTING keys REQUEST requested_features FOR student RESULT result.


METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION

IMPORTING REQUEST requested_authorizations FOR student RESULT result.


METHODS selected FOR MODIFY

IMPORTING keys FOR ACTION student~selected RESULT result.

METHODS validateid FOR VALIDATE ON SAVE

IMPORTING keys FOR student~validateid.


ENDCLASS.


CLASS lhc_Student IMPLEMENTATION.


METHOD get_instance_authorizations.

ENDMETHOD.



METHOD get_instance_features.

READ ENTITIES OF zi_ab_rap_stus IN LOCAL MODE

ENTITY Student

FIELDS ( StudentStatus ) WITH CORRESPONDING #( keys )

RESULT DATA(selected)

FAILED failed.


result = VALUE #( FOR stus IN selected LET

statusvalue = COND #( WHEN stus-StudentStatus = abap_true

THEN if_abap_behv=>fc-o-disabled

ELSE if_abap_behv=>fc-o-enabled )


IN ( %tky = stus-%tky

%action-Selected = statusvalue )

).

ENDMETHOD.


METHOD get_global_authorizations.

ENDMETHOD.


METHOD Selected.

MODIFY ENTITIES OF zi_ab_rap_stus IN LOCAL MODE

ENTITY Student

UPDATE

FIELDS ( StudentStatus )

WITH VALUE #( FOR key IN keys ( %tky = key-%tky StudentStatus = abap_true ) )

FAILED failed

REPORTED reported.


READ ENTITIES OF zi_ab_rap_stus IN LOCAL MODE

ENTITY Student

ALL FIELDS WITH CORRESPONDING #( keys )

RESULT DATA(studentdata).


result = VALUE #( FOR studentrec IN studentdata ( %tky = studentrec-%tky %param = studentrec ) ).

ENDMETHOD.


METHOD validateid.

READ ENTITIES OF zi_ab_rap_stus IN LOCAL MODE

ENTITY Student

FIELDS ( StudentId ) WITH CORRESPONDING #( keys )

RESULT DATA(StudentsId).

LOOP AT studentsId INTO DATA(studentId).

IF studentid-StudentId IS INITIAL.

APPEND VALUE #( %tky = studentid-%tky ) TO failed-student.

APPEND VALUE #( %tky = keys[ 1 ]-%tky

%msg = new_message_with_text( severity = if_abap_behv_message=>severity-error

text = 'PLEASE ENTER STUDENT ID' ) )

TO reported-student.

ENDIF.

ENDLOOP.

ENDMETHOD.


ENDCLASS.

Step 5: Check and activate the class.

Step 6: Preview the application.

----------------------------------------------------------------------------------------------

Testing:

Step 1: Click on go to see the existed data.

Step 2: Click on create-to-create new student details.


Step 3: Click on create it will throw error.


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