Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
aathif55
Participant

Overview:-


Many of us have already integrated SAP with SharePoint using SAP Process Integration with REST api. In this blog post i will be explaining how we can use Microsoft Azure Logic App to drop PDF into SharePoint. With Logic App development efforts in SAP PO is reduced.

Implementation:-


In the ECC when a smartform is created a Function Module is generated.

Later smartform FM is called in the actual program to generate OTF, and then with the OTF, PDF is created.

below program returns OTF and then generate PDF.
gs_control_param-getotf      = 'X'. "When get OTF is set to "X" then FM will return OTF 

CALL FUNCTION gv_fm_name "Name of the FM generated by smartforms
EXPORTING
control_parameters = gs_control_param
mail_recipient = lv_recipient
mail_sender = lv_sender
output_options = gs_composer_param
user_settings = ' '
is_nast = nast
IMPORTING
job_output_info = gs_job_output
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc EQ 0.
DATA:gv_pdf_xstring TYPE xstring,
gt_job_output_info TYPE STANDARD TABLE OF itcoo,
lv_base64str TYPE string.

gt_job_output_info[] = gs_job_output-otfdata[].

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_file = gv_pdf_xstring
TABLES
otf = gt_job_output_info
lines = gt_pdf_tab[]
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
IF sy-subrc EQ 0.

cl_http_utility=>if_http_utility~encode_x_base64( EXPORTING unencoded = gv_pdf_xstring RECEIVING encoded = lv_base64str ).

ELSE.




 

With the FM "CONVERT_OTF"  OTF is converted to PFD and then PDF is encoded into base64 string using SAP standard method cl_http_utility=>if_http_utility~encode_x_base64.
DATA: ls_output              TYPE zws_mt_doc_to_spo_rqst, 
ls_input TYPE zws_mt_doc_to_spo_resp.

ls_output-mt_doc_to_spo_rqst-folder_path = 'test/test/'.
ls_output-mt_doc_to_spo_rqst-file_name = 'test.pdf'.
ls_output-mt_doc_to_spo_rqst-file_content_b64str = lv_base64str.

TRY.
DATA(lo_doctospo) = NEW ZWS_CO_SI_DOC_TO_SPO_SYNC( ).
lo_doctospo->si_doc_to_spo_sync_out( EXPORTING output = ls_output IMPORTING input = ls_input ).
CATCH cx_ai_system_fault INTO DATA(lo_exception).
ENDTRY.

The generated base64 string is assigned to a proxy structure (generated in SPROXY) and sent to SAP PO using SOAP sender(proxy) adapter.

 

SAP PO Configuration:-


In SAP PO ESR just 1 to 1 mapping is needed so i have created Data Type, Message Type and Service Interface.

Request Message Type

Response Message Type.

Service Interface

There are multiple ways of sending PDF to SAP PO but i prefer converting PDF into base64 format in ECC itself using standard method in ABAP.

Other methods are as below.


  1. Send PDF as an attachment from ECC along with the payload and then convert attachment into base64 string using UDF in graphical mapping or Java mapping.

  2. using ABAP program generate PDF and save in Application server(AL11) then with FILE adapter in SAP PO pick the PDF(binary file) and convert PDF into base64 string using JAVA Mapping



If I opt above 2 approaches then i need to write a piece of code in SAP PO as well so i thought of performing all the conversion in ABAP itself(why to write java code in SAP PO if ABAP has already got standard class/method to encode/decode Base64 format )

In the Integration Directory we have used SOAP and REST adapter and configured like below.

SOAP sender adapter.

REST Receiver Adapter.

It is a HTTP POST operation.


 

Microsoft Azure Logic App Configuration:-


 

In the Microsoft Azure Portal under resource group create a new Logic App.

Logic App can be found under Integration --> Logic App(Microsoft has already provided document, tutorials and templates so that we can learn/understand and develop our logic App )

Once Logic App is created select Trigger "When HTTP request is received" and under use sample payload to generate JSON Schema paste the JSON structure we developed in SAP PO Data Type(it will be in XML, convert it to JSON and paste here) and it will automatically generate JSON schema .

The REST receiver adapter in SAP PO will convert XML to JSON and send request to below Logic App to perform actions and drop files in SharePoint.

Now click over + button and select Add an action

A menu will appear, type SharePoint in the search box and select SharePoint Create File Action from the result.

There are many other SharePoint actions available in the Logic App, i have selected Create File because i want to drop(create) a file in SharePoint. likewise we can use other actions if we need to do other operations.

Now when the create file appears, enter login details which has got access to SharePoint site where we will be dropping our PDF.


  • A new window will appear, when we simply click over field we can select dynamic content(whatever is there in JSON schema will appear)

  • Whichever site the user has access will appear in the drop-down

  • within site select the folder path where we will be dropping our file(we are sending path from SAP so path is being accessed dynamically here)

  • enter the file name(we are sending filename from SAP so name is being accessed dynamically here)

  • Since we are sending our PDF as base64 string, we will be converting it to binary here by writing expression base64ToBinary(triggerBody()?['FileContentB64Str']) FileContentB64Str has been selected from Dynamic content





  • base64ToBinary is present under Conversion functions under expression





Finally we will be creating last action that is Response(Send back response to SAP PO& ECC)


Once done our Logic App workflow will look like this.

 

Testing:-


When the program is executed proxy program is invoked and data is sent to SAP PO which can be seen in SAP PO message monitor.


Logs can also be viewed in Azure Logic App monitor.

Finally PDF can be seen in SharePoint.

 

Scenario In a Nutshell:-



  1. Return OTF from smartform Function Module, convert it to PDF, encode PDF into Base64 format and finally send out of SAP with SAP PO proxy configuration.

  2. Configure SAP REST Receiver Adapter to call Logic App.

  3. Logic App SharePoint create file action will connect to the SharePoint site and with base64toBinary operation decode Base64 string into binary file.


 

 

 
3 Comments
Labels in this area