Hello All,
I'm having some unusual issues with my BSP page that I can't seem to work around. Any input would be greatly appreciated. I'll give as much detail as possible, because the issue only exists at a certain point.
Overview: I'm creating a simple bsp with input fields that once filled the user hits a 'submit' button and the field entries are sent back to SAP via ajax in an simple 'POST'. The fields are read into SAP and a report is generated and converted to xstring. This xstring is then sent back to the BSP using the cl_bsp_utility=>download. Herein lies the problem. The webpage responds to this as a 'message'. If I test this functionality on initialization it is fine, but as a response it doesn't work. Very odd.
Here is my html: (Don't critique the hard-coded values, I'm not worried about that yet).
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>
</title>
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<link rel="stylesheet" href="usl_cc_01.css" />
<style>
/* App custom styles */
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.1.1/jquery.mobile-1.1.1.min.js">
</script>
<script src="usl_cc_01.js"></script>
<script src="usl_cc_02.js"></script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="page1">
<div data-theme="b" data-role="header">
<h3>
Cost Center Reporting
</h3>
</div>
<form id="target">
<div data-role="content">
<div data-role="fieldcontain">
<label for="userId">
Name
</label>
<input name="userId" id="userId" placeholder="" value="" type="text" class="required" />
</div>
<div data-role="fieldcontain">
<label for="password">
Password
</label>
<input name="password" id="password" placeholder="" value="" type="password" class="required"/>
</div>
<div data-role="fieldcontain">
<label for="reportType" class="select" data-mini="true">Report Type</label>
<select name="reportType" id="reportType">
<option selected="selected">Actual</option>
<option>Plan/Forecast</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="period">
Period
</label>
<select name="period" id="period">
<option selected="selected">001</option>
<option>002</option>
<option>003</option>
<option>004</option>
<option>005</option>
<option>006</option>
<option>007</option>
<option>008</option>
<option>009</option>
<option>010</option>
<option>011</option>
<option>012</option>
<option>013</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="year">
Year
</label>
<select name="year" id="year">
<option selected="selected">2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
</select>
</div>
<div data-role="fieldcontain">
<label for="version">
Version
</label>
<select name="version" id="version">
<option>PF - USL Plan Version Final</option>
<option>R1 - USL Rolling Forecast April - December</option>
<option>R2 - USL Rolling Forecast July - December</option>
<option>R3 - USL Rolling Forecast October - December</option>
</select>
</div>
<input id="submitToSap" type="button" data-icon="search" data-iconpos="left" value="Submit to SAP" />
<input id="emailMePass" type="button" data-icon="info" data-iconpos="left" value="Email Password" />
</div>
</form>
</div>
<script>
</script>
</body>
</html>
My simple js is just this:
// JavaScript Document
$(document).ready(function() {
$('#submitToSap').click(function() {
// Compile data to send to SAP server
var cc_data_string =
'&purpose=view' +
'&userId=' + $("input#userId").val() +
'&password=' + $("input#password").val() +
'&reportType=' + $("select#reportType").val() +
'&period=' + $("select#period").val() +
'&year=' + $("select#year").val() +
'&version=' + $("select#version").val();
$.ajax({
type: "POST",
url: "usl_cc_01_control.do",
data: cc_data_string,
success: function(ret){
alert(ret);
}
});
});
});
My Controller has a simple DO_REQUEST.
DATA: l_view TYPE REF TO if_bsp_page,
lt_fields TYPE tihttpnvp.
request->get_form_fields( CHANGING fields = lt_fields ).
IF lt_fields IS INITIAL.
l_view = create_view( view_name = 'usl_cc_01.html').
call_view( l_view ).
ELSE.
process_input( lt_fields ).
ENDIF.
And the Process_input:
DATA: l_view TYPE REF TO if_bsp_page,
ls_field TYPE ihttpnvp.
* Refresh model if necessary
IF m_cc_model IS NOT BOUND.
do_init( ).
ENDIF.
READ TABLE lt_fields INTO ls_field WITH KEY name = 'purpose'.
"Here is where I do my simple ABAP logic to generate a report, send it to the spooler, convert to pdf and then convert to xstring.
"My xstring is outputx
CONCATENATE cl_abap_char_utilities=>byte_order_mark_little outputx INTO outputx IN BYTE MODE.
DATA: app_type TYPE string VALUE 'APPLICATION/PDF;charset=utf-16le'.
CALL METHOD cl_bsp_utility=>download
EXPORTING
object_s = outputx
content_type = app_type
content_disposition = 'attachment;filename=your_cc.pdf'
response = server->response
navigation = navigation.
However...the webpage responds with a dialog that says 'message from webpage'. ???
I've created a test webpage that does the download dialog from the start and it works fine and generates the pdf, but as a response to an input it responds with 'message from webpage' and not the dialogue. Any help would be so greatly appreciated, I'm spinning my wheels here. All the 'pieces' are fairly simple, but something is amiss as a whole.
Thanks for any help,
Greg
PS. I'm still working on it, if I find the solution I'll make sure to post it.