Technical Articles
SAPUI5/Gateway: Read SBWP inbox documents with auto-refresh & progress indicator
Hello @All,
In this Blog post, we’re gonna build a END to END SAPUI5 solution that reads the user’s inbox from SBWP and shows the message body. Please watch the DEMO video: http://bit.ly/2FA1pZA .
Let’s start with the backend:
1 – Create the structures below:
2 – Create the Function Modules(RFC enabled):
function zdemo_docs_read.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" VALUE(IV_DOC_ID) TYPE SO_ENTRYID OPTIONAL
*" TABLES
*" T_OUT STRUCTURE ZDEMO_DOCS_STR OPTIONAL
*"----------------------------------------------------------------------
data: lt_inb type table of somt,
ls_out type zdemo_docs_str,
ls_inb type somt,
ls_data type soudatai1,
ls_user type soudnamei1,
ls_docdata type sofolenti1,
ls_obj type soodk.
if iv_doc_id is initial."Gateway Query...
"Input...
ls_user-sapname = sy-uname.
"Get the users folder...
call function 'SO_USER_READ_API1'
exporting
user = ls_user
importing
user_data = ls_data
exceptions
user_not_exist = 1
parameter_error = 2
x_error = 3
others = 4.
if sy-subrc eq 0.
"Get the Documents...
ls_obj-objtp = ls_data-inboxfol(3).
ls_obj-objyr = ls_data-inboxfol+3(2).
ls_obj-objno = ls_data-inboxfol+5(12).
call function 'SO_FOLDER_READ'
exporting
object_id = ls_obj
owner = sy-uname
tables
folder_cont = lt_inb
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
operation_no_authorization = 5
owner_not_exist = 6
substitute_not_active = 7
substitute_not_defined = 8
system_failure = 9
x_error = 10
others = 11.
if sy-subrc eq 0.
loop at lt_inb into ls_inb.
concatenate
ls_inb-foltp
ls_inb-folyr
ls_inb-folno
ls_inb-doctp
ls_inb-docyr
ls_inb-docno
into ls_out-doc_id.
ls_out-obj_descr = ls_inb-docdes.
ls_out-creat_date = ls_inb-crdat.
ls_out-creat_time = ls_inb-crtim.
ls_out-creat_name = ls_inb-sndnam.
append ls_out to t_out.
endloop.
sort t_out by creat_date descending creat_time descending.
endif.
endif.
else."Gateway Read...
call function 'SO_DOCUMENT_READ_API1'
exporting
document_id = iv_doc_id
importing
document_data = ls_docdata
exceptions
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
others = 4.
if sy-subrc eq 0.
ls_out-doc_id = iv_doc_id.
ls_out-obj_descr = ls_docdata-obj_descr.
ls_out-creat_date = ls_docdata-creat_date.
ls_out-creat_time = ls_docdata-creat_time.
ls_out-creat_name = ls_docdata-creat_name.
append ls_out to t_out.
endif.
endif.
endfunction.
function zdemo_docs_read_text.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" VALUE(IV_DOC_ID) TYPE SO_ENTRYID OPTIONAL
*" TABLES
*" T_TEXT STRUCTURE ZDEMO_DOCS_STR_TXT OPTIONAL
*"----------------------------------------------------------------------
data: lt_cont type table of solisti1,
ls_text type zdemo_docs_str_txt,
lv_line type i,
ls_cont type solisti1.
call function 'SO_DOCUMENT_READ_API1'
exporting
document_id = iv_doc_id
tables
object_content = lt_cont
exceptions
document_id_not_exist = 1
operation_no_authorization = 2
x_error = 3
others = 4.
if sy-subrc eq 0.
loop at lt_cont into ls_cont.
lv_line = lv_line + 1.
ls_text-doc_id = iv_doc_id.
ls_text-line = lv_line.
ls_text-text = ls_cont-line.
append ls_text to t_text.
endloop.
endif.
endfunction.
Now let’s work on the Gateway side:
1 – Create (SEGW) a project called ZDEMO_DOCS, with 2 Entities, one from each RFC created above.
2 – Create the Association between the 2 entities, with the names as showed:
3 – Create the Service Implementations as showed (Query and Read on the First Entity and Query on the Second Entity, both mapped to the RFCs created):
4 – Publish your project/service on the catalog, mapped to your backend(in my case with a SSO RFC destination in my System Alias):
5 – Just testing the Service on the GW Client:
So now, if all the steps above are done correctly, we’re all set to create the SAPUI5 App.
In your Web IDE, setup the source code from my Github account: http://bit.ly/2YhA1Ha. If you want to build your own project, don’t forget to change/adapt the names and Component IDs.
Here is the final layout:
The method responsible for the progress indicator & time label is the update:
The progress turns orange on 50%:
And red on 25%:
Please watch the DEMO Video for a “complete” experience: http://bit.ly/2FA1pZA
After the SAPUI5 App is done, you can publish to your FIORI environment as described here:
https://www.sap.com/documents/2015/08/d2bc1629-5a7c-0010-82c7-eda71af511fa.html
So now you’re all set!
This is a “base” solution that you could explore for more functionalities, like: Create a message from the App, show the read/unread icon from SBWP, etc.
Hope you enjoyed ?
Regards.
Hi Jose, Interesting approach. Just curious why you went for this approach rather than using Fiori My Inbox?
What was the motivation?
Thanks
Hello Jocelyn,
As the My Inbox would represent the Workflows, this Demo represents the Documents section of SBWP, where users(and also the environment/system) can exchange messages with the current user.
But basically the real motivation was to show the Auto-refresh with progress indicator, and to build a end to end SAPUI5/Gateway/ABAP solution on a scenario that “made sense” to implement it, as a “auto refresh documents inbox”.
Regards.
Hello Jocelyn,
The Documents section of sbwp is not shown on the My Inbox App for me. Can you help in finding the settings to activate it.