cancel
Showing results for 
Search instead for 
Did you mean: 

SAVE Attachments in ABAP Restful programming managed Fiori App

mukeshjadhav08
Explorer
0 Kudos

Hi Experts,

I have created RAP managed Fiori elements app(draft enabled with GUID as key field) with reuse components of attachment service. I can see attachment tab in Fiori app stored in Draft mode, how do we SAVE these attachments.

I have gone through the Help, I am wondering where, I can write the logic in backend, as I don't have draft class or should I call the API methods from the Fiori App?

I have followed maheshkumar.palavalli blog for the UI part, which follows BOPF approach.

https://blogs.sap.com/2019/12/16/attachment-service-to-your-rescue-in-s4hana-fiori-elements-using-re.../

I need a place, where I can implement below method or how to call the Attachment API SAVE method.

/bobf/if_frw_draft~copy_draft_to_active_entity<br>

Any help would be highly appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

DiegoValdivia
Participant

Hi Mukesh,

Since you are using a Managed implementation, I think you could try to use the option "Additional Save" in the behavior Definition. See following link for additional information:

Managed Transactional Apps - Implementing Additional Save

Regards.

mukeshjadhav08
Explorer
0 Kudos

Hi Diego,

Thank you for your answer. I was able to SAVE the attachments from Draft to Active using Additional save method.

define behavior for ...
persistent table Z...
with additional save

Implemented the class

CLASS lcl_save DEFINITION INHERITING FROM cl_abap_behavior_saver.
PROTECTED SECTION.
METHODS save_modified REDEFINITION.
ENDCLASS.

Added below code in SAVE_MODIFIED method.

CLASS lcl_save IMPLEMENTATION.
METHOD save_modified.
DATA:lv_objectkey TYPE objky,
lv_temp_objectkey TYPE objky.
IF create-Entityname IS NOT INITIAL.
DATA(lo_attachment_api) = cl_odata_cv_attachment_api=>get_instance( ).
lv_objectkey = lv_temp_objectkey = COND #( WHEN create-Entityname[ 1 ]-UUID(unique object key) IS NOT INITIAL
THEN cl_soap_wsrmb_helper=>convert_uuid_raw_to_hyphened( create-Entityname [ 1 ]-UUID(unique object key) ).
TRY.
CALL METHOD lo_attachment_api->if_odata_cv_attachment_api~save
EXPORTING
iv_objecttype = 'ZBUSTEMP' " Business Object name
iv_objectkey = lv_objectkey
iv_objecttype_long = 'ZBUSTEMP' " Business Object name
iv_temp_objectkey = lv_temp_objectkey
iv_no_commit = abap_true
IMPORTING
ev_success = DATA(lv_ok)
et_messages = DATA(lt_messages).
CATCH cx_odata_cv_base_exception INTO DATA(lo_excp).
ENDTRY.
ENDIF.
ENDMETHOD.
ENDCLASS.

Note: This works for file upload during create and update( given that few or more fields are changed).

I did raise an OSS message with SAP, but got the response as "Attachment service is not RAP compatible yet". Above solution works, but not sure if there is more to it.

Answers (1)

Answers (1)

DiegoValdivia
Participant
0 Kudos

Hi Mukesh,

I'm glad my answer helped you.

Regarding SAP mentioning "Attachment service is not RAP compatible yet", I guess the person who provided that answer is not quite aware of existing SAP apps. Some weeks ago I did a research on my system S/4 Hana 2022 and found 50 apps that use RAP Odata V2 + Attachment Services. I executed a few and confirmed they worked.

One of those apps is "Manage Maintenance Plans". The BSP name is EAM_MPLANMANS1, the Service Binding Odata V2 is UI_MAINTENANCE_PLAN and the Behavior definition is R_MAINTENANCEPLANTP. They are clearly using attachments service.

Regarding you app saving attachments only if few or more fields are changed. You could implement a determination on Draft Action Prepare, or use Draft Action Activate and add sentence "with additional implementation". With either of both options you could trigger the Attachment save when user pressed save without modifying any field on the screen.

I hope this helps.

mukeshjadhav08
Explorer
0 Kudos

Hi Diego,

Thank you for your reply.

I implemented DRAFT Action Activate, however ~Save API is failing with "Remote function call with update task".

I will take a look at standard RAP based apps(Managed), which are using attachment service and post, how draft attachments are saved.

stefan_m_tf
Discoverer
0 Kudos

Hi Diego,

when I try to read an attachment using the (cloud enabled) attachment api in an unmanaged RAP implementation with language version "ABAP for Cloud Development", then I get a BEHAVIOUR_ILLEGAL_STATEMENT error, because AUTHORITY-CHECK is not allowed in the read phase.

I looked at the implementation of the behaviour definition R_MAINTENANCEPLANTP which uses the same attachment api. SAP worked around this problem by disabling the check for privileged mode and perform the call in priviledged mode. Unfortunately the statement "with priviledged mode disabling NoCheckWhenPriviledged" is not allowed in language version "ABAP for Cloud Development".

So how can I use a Cloud-enabled API within a RAP implementation with language version "ABAP for Cloud Development"?

Thank you and best regards,

Stefan

subbu_potturi
Discoverer
0 Kudos

Hi Diego,

How can find the where used list of one BSP application in another BSP application.

Some weeks ago I did a research on my system S/4 Hana 2022 and found 50 apps that use RAP Odata V2 + Attachment Services

Please let me know the process, how did you find the where used list of attachment service.

Awaiting your reply.

Thanks,

Subrahmanyam