on 01-19-2023 10:09 PM
Hi,
I am trying to validate multiple records in Fiori List Object page application. Validation is needed when user tries to update status for multiple records in List control at once through Action button.
I want to update Status column with Yes with condition Age Column (value > 25) and show warning messages for remaining 2 records (Age = 23 and 20). Please refer below screen for reference.
Below is current code.
METHOD statusUpdate.
//Reading Entity
READ ENTITIES OF zrap_i_student_5001 IN LOCAL MODE
ENTITY Student
ALL FIELDS WITH CORRESPONDING #( keys )
RESULT DATA(students)
FAILED failed.
SORT students BY Status DESCENDING.
// Filling Invalid records to failed-student
LOOP AT students ASSIGNING FIELD-SYMBOL(<lfs_students>).
IF <lfs_students>-Age < 25.
APPEND VALUE #( %tky = <lfs_students>-%tky ) TO failed-student.
ELSE.
<lfs_students>-Status = abap_true.
ENDIF.
ENDLOOP.
// If we get any Invalid records per condition. sending those to reported-student
IF failed-student IS NOT INITIAL.
LOOP AT failed-student ASSIGNING FIELD-SYMBOL(<lfs_error_rec>).
APPEND VALUE #( %tky = <lfs_error_rec>-%tky
%msg = new_message_with_text(
severity = if_abap_behv_message=>severity-warning
text = <lfs_students>-Firstname && ' has Age less then 25, status not Updated '
) ) TO reported-student.
ENDLOOP.
ENDIF.
// Delete Invalid records
SORT students by Status DESCENDING.
DELETE students WHERE Status is INITIAL.
// Finally Modify the remaining Valid records
MODIFY ENTITIES OF zrap_i_student_5001 IN LOCAL MODE
ENTITY Student
UPDATE FIELDS ( Status ) WITH CORRESPONDING #( students )/
ENDMETHOD.
Below errors are getting displayed correctly (Ignore the q, its just value is not updated)
but Once I click on Close I am seeing below error message and correct record is not getting updated...
ramjee.korada
Please help...
Thanks-
Abhishek
Hi Abhishek,
I believe you are doing batch processing.
In this case, I suggest to throw error instead of warning message in Reported and fill Failed structures.
Modify only when all entries are valid and error free. This way data is committed once.
If you want to process other valid records, then you have to use #isolated for invocation grouping annotation.
Then every record is executed independent sessions and Valid data can be committed to database by framework.
Best wishes,
Ramjee Korada
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ramjee.korada
Thanks for responding... I followed what you have suggested to throw Error message and save all when all records are valid...
Now I am seeing error message but still seeing another popup. please refer below screen shots for reference.
When I click on Close button on this error popup I see below another error popup.
Please help...
Thanks-
Abhishek
Could you explicitly trigger a COMMIT at the end of the logic, Thanks.
All the best,
Ravenclaw.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Abhishek,
If the failed table is populated with the keys if there are any errors, then the framework will not fire the commit entities and that's the reason why the records are not updated in your case.
Thanks,
Pavan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I am implementing Managed scenario for OData V4. There I have a Validate action. In this action implementation I am only populating REPORTED table with error messages and at the end I am calling MODIFY ENTITIES ... UPDATE just like You.
This works fine for me, the COMMIT operation is executed by RAP.
Make sure the FAILED table is not populated with any data. Also check if your MODIFY ENTITIES statement does not return any failed records. And finally check if your "students" internal table has proper data for MODIFY ENTITIES ( you are using CORRESPONDING #). In my case I am using VALUE # and I am populating only %key and %data-... for updated fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.