Open Document returns error (SOFFICEINTEGRATION) - abap

I'm trying to open a Excel file with SOFFICEINTEGRATION to modify the file inplace.
But I always get the CALL_NOT_FLUSHED error, I tried several code snippets (with no_flush = X and no_flush = ' ')
The error "CALL_NOT_FLUSHED" is appearing after calling proxy->open_document
My current code:
DATA proxy TYPE REF TO i_oi_document_proxy.
PARAMETERS dummy.
AT SELECTION-SCREEN OUTPUT.
IF proxy IS NOT BOUND.
CALL METHOD c_oi_container_control_creator=>get_container_control
IMPORTING
control = DATA(lo_container_control)
retcode = DATA(l_rc).
CALL METHOD lo_container_control->init_control
EXPORTING
r3_application_name = 'EXCEL' "#EC NOTEXT
inplace_enabled = 'X'
inplace_scroll_documents = 'X'
parent = cl_gui_container=>screen0
IMPORTING
retcode = l_rc.
CALL METHOD lo_container_control->get_document_proxy
EXPORTING
document_type = 'EXCEL.SHEET'
IMPORTING
document_proxy = proxy.
CALL METHOD proxy->open_document
EXPORTING
document_url = 'file://C:\Users\yourusername\Documents\test.xlsx'
open_inplace = 'X'
IMPORTING
error = DATA(openerr).
ENDIF.

Related

Changes in lua language cause error in ai script

When I run script in game, I got an error message like this:
.\AI\haick.lua:104: bad argument #1 to 'find' (string expected, got nill)
local haick = {}
haick.type = type
haick.tostring = tostring
haick.require = require
haick.error = error
haick.getmetatable = getmetatable
haick.setmetatable = setmetatable
haick.ipairs = ipairs
haick.rawset = rawset
haick.pcall = pcall
haick.len = string.len
haick.sub = string.sub
haick.find = string.find
haick.seed = math.randomseed
haick.max = math.max
haick.abs = math.abs
haick.open = io.open
haick.rename = os.rename
haick.remove = os.remove
haick.date = os.date
haick.exit = os.exit
haick.time = GetTick
haick.actors = GetActors
haick.var = GetV
--> General > Seeding Random:
haick.seed(haick.time())
--> General > Finding Script Location:
local scriptLocation = haick.sub(_REQUIREDNAME, 1, haick.find(_REQUIREDNAME,'/[^\/:*?"<>|]+$'))
Last line (104 in file) causes error and I don`t know how to fix it.
There are links to .lua files below:
https://drive.google.com/file/d/1F90v-h4VjDb0rZUCUETY9684PPGw7IVG/view?usp=sharing
https://drive.google.com/file/d/1fi_wmM3rg7Ov33yM1uo7F_7b-bMPI-Ye/view?usp=sharing
Help, pls!
When you use a function in Lua, you are expected to pass valid arguments for the function.
To use a variable, you must first define it, _REQUIREDNAME in this case is not available, haick.lua file is incomplete. The fault is of the author of the file.
Lua has a very useful reference you can use if you need help, see here

Send multiple files in HTTP response

I have created an ICF handler class which sends files to the sender. The thing is, it works fine with single file where i am reading the data in binary format and attaching the same in body part using set_data.
But when I try to add more than 1 file, I am unable to add 2 files separately. i am using IF_HTTP_EXTENSION and do not have NTW GATEWAY component yet.
I am also using MULTIPART feature, but dont konw exactly on how to add 2 files separately. Can you please help me ?
//file1
server->response->set_header_field( name = 'Content-Type' value = 'multipart/mixed').
CONCATENATE 'form-data;name="file"; filename="' filename+5(9) '"' INTO lv_header_value.
server->response->set_header_field( name = 'content-disposition' value = lv_header_value ).
server->response->set_data( data = attach_xstring ).
//file2
server->response->add_multipart( ).
CONCATENATE 'form-data;name="file"; filename="' filename+5(9) '"' INTO lv_header_value.
server->response->set_header_field( name = 'content-disposition' value = lv_header_value ).
server->response->set_data( data = attach_xstring ).
You need to use add_multipart() method. Try like this:
cl_http_client=>create( EXPORTING host = host service = port scheme = scheme
IMPORTING client = lo_http_client ).
lo_http_client->request->set_header_field( name = 'Content-Type' value = 'multipart/form-data' ). "#EC NOTEXT
lo_request_part = lo_http_client->request->add_multipart( ).
lo_request_part->set_content_type( 'application/xml' ).
lv_content_disposition = |form-data; name="item"; filename="item_data.xml" |.
lo_request_part->set_header_field( name = `Content-Disposition` value = lv_content_disposition ).
lo_request_part->set_data( data = lv_create_item_xml ).
LOOP AT mt_files ASSIGNING <attachment>.
lo_request_part = lo_http_client->request->add_multipart( ).
lo_request_part->set_content_type( <attachment>-content_type ). "#EC NOTEXT
lv_content_disposition = |form-data; name="{ <attachment>-part_name }"; filename="{ <attachment>-filename }" |.
lo_request_part->set_header_field( name = `Content-Disposition` value = lv_content_disposition ).
lo_request_part->set_data( <attachment>-file ).
ENDLOOP.
It is sample for request, but for response the scheme should be the same. Here initially xml-file added to request and them multiple attachments are processed in loop.

Download an Excel document built with class CL_XLSX_DOCUMENT

My program below creates an Excel document built with the class CL_XLSX_DOCUMENT, which contains two sheets.
How can I download the Excel document on my laptop ?
lo_worksheetpart ?= lo_workbookpart->get_worksheetparts( )->get_part( lv_line_no_loop ).
lo_worksheetpart_1 ?= lo_workbookpart->add_worksheetpart( ).
lv_sheetxml = lo_worksheetpart->get_data( ).
lv_sheetxml_2 = lo_worksheetpart_1->get_data( ).
lo_sharedstringspart = lo_workbookpart->get_sharedstringspart( ).
lv_sharedxml = lo_sharedstringspart->get_data( ).
"Parse and replace
if lt_nameval is not initial.
lv_resultxml = update_shared_string_1(
EXPORTING
iv_xml = lv_sharedxml
iv_node = co_shared_string
it_nameval = lt_nameval ).
"write new excel
lo_sharedstringspart->feed_data( lv_resultxml ).
lv_resultxml = update_sheet_data_1(
EXPORTING
iv_xml = lv_sheetxml
iv_node = co_sheet_data
it_days = lt_days
it_nameval = lt_nameval ).
"write new excel
lo_worksheetpart->feed_data( lv_resultxml ).
endif.
I use the following:
DATA:
lv_fsize TYPE i,
lt_data TYPE tsfixml,
lv_resultxml TYPE xstring.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_resultxml
IMPORTING
output_length = lv_fsize
TABLES
binary_tab = lt_data.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = lv_fsize
filetype = 'BIN'
filename = 'C:\Temp\filename.xlsx
CHANGING
data_tab = lt_data

Add new emails Customer at XD02 from CALL METHOD cmd_ei_api=>maintain_bapi

I need to add a new email address on customers in XD02 from an xls.
That's all ok, but, when I CALL METHOD cmd_ei_api=>maintain_bapi
this really change the email but delete all the emails on XD02, and it's not what I want, I want to add a new email put this one default, but I want to keep the old ones.
My code :
FORM data_to_bapi.
DATA: gs_correct TYPE cmds_ei_main,
gt_customers TYPE cmds_ei_main,
gs_address TYPE bapiad1vl,
gs_addressx TYPE bapiad1vlx,
gs_company_code_st TYPE cmds_ei_company,
gs_company_code TYPE cmds_ei_cmd_company,
gt_smtp TYPE cvis_ei_smtp_t,
gs_smtp LIKE LINE OF gt_smtp,
gs_comm TYPE cvis_ei_cvi_communication,
gs_customers TYPE cmds_ei_extern,
gs_defective TYPE cmds_ei_main,
gs_msg_correct TYPE cvis_message,
gs_msg_error TYPE cvis_message,
iv_test_run TYPE c.
LOOP AT lt_data INTO wa_data.
"Controlo
gs_customers-header-object_instance-kunnr = wa_data-kunnr. "kunnr
gs_customers-header-object_task = 'U'. "Update this kunnr
gs_smtp-contact-task = 'I'. " Insert New Email
gs_smtp-contact-data-e_mail = wa_data-email. " New email
gs_smtp-contact-datax-e_mail = 'X'.
APPEND gs_smtp TO gt_smtp.
gs_comm-smtp-smtp = gt_smtp[].
gs_customers-central_data-address-communication = gs_comm.
gs_customers-central_data-address-task = 'I'. " Insert new communication
APPEND gs_customers TO gt_customers-customers.
**********************************************************************
* CALL BAPI *
**********************************************************************
CHECK gt_customers-customers IS NOT INITIAL.
gv_collect_messages = abap_true.
cmd_ei_api=>initialize( ).
iv_test_run = ' '.
CALL METHOD cmd_ei_api=>maintain_bapi
EXPORTING
iv_test_run = iv_test_run
iv_collect_messages = gv_collect_messages
is_master_data = gt_customer
" Master Data
IMPORTING
es_master_data_correct = gs_correct
es_message_correct = gs_msg_correct
es_master_data_defective = gs_defective
es_message_defective = gs_msg_error.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CLEAR wa_data.
ENDLOOP.
ENDFORM. "data_to_bapi
Thanks !

Call AFIP MTXCA web-service properly from SAP ECC

I am trying to call the AFIP WebService MTXCA directly from SAP ECC.
There is no problem with that. The thing is when I try to get the TOKEN and SIGN from the first WS
https://wsaahomo.afip.gov.ar/ws/services/LoginCms?WSDL
I can not sign the XML to build the right CMS to get the proper answer from AFIP.
cl_secxml_helper=>upload_file( EXPORTING filename = p_xml
IMPORTING bindata = DATA(lv_xml) ).
DATA(lo_object) = cl_sec_sxml_dsignature=>create_reader_instance( if_input = lv_xml ).
lo_object->m_ssf_hash_algorithm = 'SHA1'.
lo_object->m_dsig_hash_algorithm = 'SHA1'.
lo_object->m_dsig_method = 'RSA'.
lo_object->m_signature_ns_prefix = ''.
lo_object->sign_xml( EXPORTING if_ssf_app = 'OAUTH'
if_add_keyinfo = abap_true
if_add_keyinfo_ex = abap_true
IMPORTING ef_signature_xml = DATA(lf_result)
es_signer = DATA(ls_signer) ).
lo_object->embed_signature( EXPORTING if_xml = lv_xml
if_signature = lf_result
if_embed_as_child = abap_true
if_embed_at_end = abap_true
is_signer = ls_signer
IMPORTING ef_result = lf_result ).
cl_soap_xml_helper=>xml_show( xdoc = lf_result ).
ls_request-in0 = lf_result.