Upload
werathep-chaladee
View
46
Download
5
Embed Size (px)
Citation preview
Displaying a Smart form as PDF in Enterprise portal using WebDynpro for Java
By Nagaraju Donikena
I have seen many questions on how a smart form should be displayed in portal. To answer this question a person should have both Portal and ABAP knowledge. By giving this basic information I want to make sure that displaying a smart form as PDF is a simple task.
Let me start from R/3 side
Create a smart form. Here I have created a simple smart form which displays “Welcome to SAP Smart forms”.
Now create a function module with the following export parameter:
Place the following code in the function module
data :
lv_fnam type RS38L_FNAM,
gs_control TYPE ssfctrlop,
gs_output_options TYPE ssfcompop,
gs_otfdata TYPE itcoo,
gs_job_output_info TYPE ssfcrescl,
gt_otfdata TYPE STANDARD TABLE OF itcoo INITIAL SIZE 0.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'YNAG_TEST_PDF'
IMPORTING
FM_NAME = lv_fnam
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3 .
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR gs_job_output_info.
CLEAR gs_job_output_info-otfdata.
MOVE :
'X' TO gs_control-no_dialog,
'X' TO gs_control-getotf,
'LOCL'(047) TO GS_OUTPUT_OPTIONS-TDDEST.
CALL FUNCTION lv_fnam
EXPORTING
CONTROL_PARAMETERS = gs_control
OUTPUT_OPTIONS = gs_output_options
USER_SETTINGS = space
IMPORTING
JOB_OUTPUT_INFO = gs_job_output_info
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5 .
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Populate OTF data table
LOOP AT gs_job_output_info-otfdata INTO gs_otfdata.
APPEND gs_otfdata TO gt_otfdata.
CLEAR gs_otfdata.
ENDLOOP. " LOOP AT t_outtab-otfdata
DATA: lv_bytes TYPE p,
lv_bin_file type xstring,
gt_pdfdata TYPE STANDARD TABLE
OF tline
INITIAL SIZE 0.
* Convert OTF into PDF
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 255
IMPORTING
bin_filesize = lv_bytes
BIN_FILE = bin_file
TABLES
otf = gt_otfdata
lines = gt_pdfdata
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
Make sure that the function module is marked remote enabled.
With this we are done on the R/3 side.
In NWDS (Net Weaver Developer Studio) create an Adaptive RFC model which points to the FM created in R/3.
Give model name
Now create an application to display the PDF
Insert a frame inside the view
Internal is a value node and url is value attribute of type string.
Place the following code in Init method
public void wdDoInit()
{
//@@begin wdDoInit()
Ynag_Test_Pdf_1_Input input = new Ynag_Test_Pdf_Input();
wdContext.nodeYnag_Test_Pdf_Input().bind(input);
try {
wdContext.currentYnag_Test_Pdf_InputElement().modelObject().execute();
} catch (WDDynamicRFCExecuteException e) {
e.printStackTrace();
wdContext.currentContextElement().setSdfgdsfsd(e.getMessage());
} wdContext.currentInternalElement().setUrl(convertXStringToUrl(wdContext.currentOutputElement().getBin_File()));
//@@end
}
//@@begin others
public String convertXStringToUrl(byte[] doc_content){
String url = "";
WDWebResourceType webResType = WDWebResourceType.PDF;
IWDWebResource webResource = WDWebResource.getWebResource(doc_content, webResType);
try {
url = webResource.getURL();
} catch (WDURLException e) {
e.printStackTrace();
}
return url;
}
//@@end
If you are using single sign on make sure to enable User authentication in the application parameters.
User details are required for this as it is using Single sign on to connect to R/3.
In this case we have hard coded the Smart form to be used.
If you want it in dynamic way FM interfaces need to be changed accordingly.