cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP RAP - Validation on List records

AbhishekSharma
Active Contributor
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Ramjee_korada
Active Contributor

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

AbhishekSharma
Active Contributor
0 Kudos

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

AbhishekSharma
Active Contributor
0 Kudos

Hi ramjee.korada

Thanks much for help as always... #isolated worked...

Thanks-

Abhishek

Ramjee_korada
Active Contributor
0 Kudos

Glad that it worked .

Answers (3)

Answers (3)

ravenclaw
Participant

Could you explicitly trigger a COMMIT at the end of the logic, Thanks.

All the best,

Ravenclaw.

j_pavan_kumar
Product and Topic Expert
Product and Topic Expert

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

AbhishekSharma
Active Contributor
0 Kudos

Hi Pavan, thanks much for responding… may you guide how can I achieve this scenario any other alternatives ?

I just wanted to show warning messages for some records and other valid records should be saved…


Thanks-

Abhishek

j_pavan_kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Abhishek,

Do not fill the FAILED table rather only send the warning message for those invalid records in the REPORTED table, then the framework would call commit entities there by your valid records are saved.

Thanks,

Pavan

AbhishekSharma
Active Contributor
0 Kudos

Hi pavankumarjagadeesh89

I tried what you suggested but its not saving valid records. Please see my below comment with Error popup.

Thanks-

Abhishek

Rafal_Gryska
Discoverer
0 Kudos

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.