Update multiple records/ Pass default values to Dialog box in RAP using Unmanaged scenario


                Refer:- Custom entity/Action dialog in RAP using Unmanaged scenario


******************* pass default values to dialog box ********************************

Step 1: Change the abstract entity and add annotation.

@EndUserText.label: 'Abstart entity for status field'

@Metadata.allowExtensions: true

define abstract entity ZA_AB_STUH_13

//with parameters parameter_name : parameter_type

{

@UI.defaultValue: 'X' // Passing always true to dialog box.

stu_status : abap_boolean;

}


Testing: 
            * Preview the application.    

            * Click on go to see all records.
            * Select record and click on update status.
            * Dialog box appears with default value Yes.

******************* END pass default values to dialog box ********************************


******************* Adding course & duration in dialog box ********************************

Step 1: Change the abstract entity.

@EndUserText.label: 'Abstart entity for status field'

@Metadata.allowExtensions: true

define abstract entity ZA_AB_STUH_13

{

stu_status : abap_boolean;

stu_course : abap.char(30);

stu_cour_dur : abap.numc(2);

}

Step 2: Change Meta data extension for above abstract entity.

@Metadata.layer: #CORE

annotate entity ZA_AB_STUH_13 with

{

@EndUserText.label: 'Set Student Status'

stu_status;

@EndUserText.label: 'Set Student Course'

stu_course;

@EndUserText.label: 'Set Course Duration'

stu_cour_dur;


}


Testing: 
            * Preview the application.    

            * Click on go to see all records.

            * Select record and click on update status.

******************* END Adding course & duration in dialog box ********************************

******************* Course & duration screen values to dialog box ********************************

Step 1: Change the abstract entity.

@EndUserText.label: 'Abstart entity for status field'

@Metadata.allowExtensions: true

define abstract entity ZA_AB_STUH_13

//with parameters parameter_name : parameter_type

{

//@UI.defaultValue: 'X' // Passing always true to dialog box.

@UI.defaultValue: #('ELEMENT_OF_REFERENCED_ENTITY: StuStatus' ) // Passing Screen values.

stu_status : abap_boolean;

@UI.defaultValue: #('ELEMENT_OF_REFERENCED_ENTITY: StuCourse' ) // Passing Screen values.

stu_course : abap.char(30);

@UI.defaultValue: #('ELEMENT_OF_REFERENCED_ENTITY: StuCourDur' ) // Passing Screen values.

stu_cour_dur : abap.numc(2);

}


Testing: 
            * Preview the application.    

            * Click on go to see all records.

            * Select record and click on update status.

******************* END Course & duration screen values to dialog box *********************

******************* Course & duration changed values saved to DB ********************************

Step 1: Change the UpdateStudentStatus 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_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 validation_fields FOR VALIDATE ON SAVE

IMPORTING keys FOR Student~validation_fields.

METHODS updatecoursedur FOR DETERMINE ON SAVE"MODIFY

IMPORTING keys FOR Student~updatecoursedur.

METHODS UpdateStudentStatus FOR MODIFY

IMPORTING keys FOR ACTION Student~UpdateStudentStatus RESULT 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.

TRY.

DATA(lv_lock) = cl_abap_lock_object_factory=>get_instance( iv_name = 'EZSTUDENT_13' ).

CATCH cx_abap_lock_failure INTO DATA(exception).

RAISE SHORTDUMP exception.

ENDTRY.

LOOP AT keys ASSIGNING FIELD-SYMBOL(<ls_keys>).

TRY.

lv_lock->enqueue(

it_parameter = VALUE #( ( name = 'ID' value = REF #( <ls_keys>-Id ) ) )


).

CATCH cx_abap_foreign_lock INTO DATA(foreign_lock).

APPEND VALUE #(

id = keys[ 1 ]-Id

%msg = new_message_with_text(

severity = if_abap_behv_message=>severity-error

text = 'Record is Locked By' && foreign_lock->user_name

)

) TO reported-student.

APPEND VALUE #(

id = keys[ 1 ]-Id

) TO failed-student.

CATCH cx_abap_lock_failure INTO exception.

RAISE SHORTDUMP exception.

ENDTRY.

ENDLOOP.

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.


METHOD validation_fields.

READ ENTITIES OF ziv_ab_stuh_13

IN LOCAL MODE

ENTITY Student

ALL FIELDS WITH CORRESPONDING #( keys )

RESULT DATA(lt_student)

REPORTED DATA(lt_reported)

FAILED DATA(lt_failed).


IF lt_student IS NOT INITIAL.

READ TABLE lt_student ASSIGNING FIELD-SYMBOL(<ls_student>) INDEX 1.


IF <ls_student> IS ASSIGNED.

" Clearing duplicates

reported-student = VALUE #(

( %tky = <ls_student>-%tky %state_area = 'STU_NAME' )

( %tky = <ls_student>-%tky %state_area = 'STU_AGE' )

).

IF <ls_student>-StuName IS INITIAL.

reported-student = VALUE #( (

%tky = <ls_student>-%tky

%state_area = 'STU_NAME' " Focussed on that field

%element-stuname = if_abap_behv=>mk-on

%msg = new_message(

id = 'SY'

number = '02'

severity = if_abap_behv_message=>severity-error

v1 = 'Name is mandatory field'

)

) ).


failed-student = VALUE #( ( %tky = <ls_student>-%tky ) ).

ENDIF.

IF <ls_student>-StuAge IS INITIAL.

reported-student = VALUE #( BASE reported-student (

%tky = <ls_student>-%tky

%state_area = 'STU_AGE' " Focussed on that field

%element-stuage = if_abap_behv=>mk-on

%msg = new_message(

id = 'SY'

number = '02'

severity = if_abap_behv_message=>severity-error

v1 = 'Age is mandatory field'

)

) ).


failed-student = VALUE #( ( %tky = <ls_student>-%tky ) ).

ENDIF.

ENDIF.

ENDIF.



ENDMETHOD.


METHOD updatecoursedur.

READ ENTITIES OF ziv_ab_stuh_13

IN LOCAL MODE

ENTITY Student

ALL FIELDS WITH CORRESPONDING #( keys )

RESULT DATA(lt_student)

REPORTED DATA(lt_reported)

FAILED DATA(lt_failed).

LOOP AT lt_student ASSIGNING FIELD-SYMBOL(<ls_student>).

IF <ls_student> IS ASSIGNED.

IF <ls_student>-StuCourse = 'ITI'.

MODIFY ENTITIES OF ziv_ab_stuh_13

IN LOCAL MODE

ENTITY Student

UPDATE FIELDS ( StuCourDur )

WITH VALUE #( (

%tky = <ls_student>-%tky

StuCourDur = 2

) ).

ELSE.

MODIFY ENTITIES OF ziv_ab_stuh_13

IN LOCAL MODE

ENTITY Student

UPDATE FIELDS ( StuCourDur )

WITH VALUE #( (

%tky = <ls_student>-%tky

StuCourDur = 4

) ).

ENDIF.


ENDIF.

ENDLOOP.

ENDMETHOD.


METHOD UpdateStudentStatus.

DATA(lt_keys) = keys.

READ ENTITIES OF ziv_ab_stuh_13

IN LOCAL MODE

ENTITY Student

FIELDS ( StuStatus StuCourse StuCourDur ) WITH CORRESPONDING #( keys )

RESULT DATA(lt_student).

DATA(lf_new_status) = lt_keys[ 1 ]-%param-stu_status.

DATA(lf_new_course) = lt_keys[ 1 ]-%param-stu_course.

DATA(lf_new_duration) = lt_keys[ 1 ]-%param-stu_cour_dur.


MODIFY ENTITIES OF ziv_ab_stuh_13

IN LOCAL MODE

ENTITY Student

UPDATE FIELDS ( StuStatus StuCourse StuCourDur )

WITH VALUE #( (

%tky = lt_student[ 1 ]-%tky

StuStatus = lf_new_status

StuCourse = lf_new_course

StuCourDur = lf_new_duration


) ).

READ ENTITIES OF ziv_ab_stuh_13

IN LOCAL MODE

ENTITY Student

ALL FIELDS WITH CORRESPONDING #( keys )

RESULT DATA(lt_student1).

result = VALUE #(

FOR <lr_student1> IN lt_student1

(

%tky = <lr_student1>-%tky

%param = <lr_student1>

)

).

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.

DATA: lt_student TYPE STANDARD TABLE OF ztl_ab_stuh_13.

lt_student = zcl_ab_stuh_13=>get_instance( )->gt_student.

IF lt_student IS NOT INITIAL.

READ TABLE lt_student ASSIGNING FIELD-SYMBOL(<ls_student>) INDEX 1.

IF <ls_student> IS ASSIGNED.


IF <ls_student>-stu_age < 18.

APPEND VALUE #( id = <ls_student>-id

%msg = new_message_with_text(

severity = if_abap_behv_message=>severity-error

text = 'Age is less than 18. Creation is not allowed'

) ) TO reported-student.

APPEND VALUE #( id = <ls_student>-id ) TO failed-student.

ENDIF.


* IF <ls_student>-stu_status EQ abap_false.

* APPEND VALUE #( id = <ls_student>-id

* %msg = new_message_with_text(

* severity = if_abap_behv_message=>severity-error

* text = 'Please select status'

* ) ) TO reported-student.

* APPEND VALUE #( id = <ls_student>-id ) TO failed-student.

* ENDIF.


ENDIF.

ENDIF.


ENDMETHOD.


METHOD save.

zcl_ab_stuh_13=>get_instance( )->save_data(

CHANGING

reported = reported ).

ENDMETHOD.


METHOD cleanup.

ENDMETHOD.


METHOD cleanup_finalize.

ENDMETHOD.


ENDCLASS.


Testing: 
            * Preview the application.    

            * Click on go to see all records.

            * Select record and click on update status.


        * I am changing the status to No, and course to Civil and duration to 4.


        * Click on Update Status- New values are updated.



******************* END Course & duration changed values saved to DB *********************



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