on 07-20-2012 12:12 PM
Hi Everyone,
My issue is that I want to download the contents which are displayed in the WEBDYNPRO output into a PDF file on click of Download Button. Can anyone help me on this.
I am Fetching the data through a FM and have linked the output table to the dynpro table. Its displaying the output correctly but now my task is to make a button which on clicking downloads the data displayed in a PDF file. We don't have to use ALV/SCRIPT/SMARTFORMS/ADOBEFORMS for that
I have fetched the Data in Internal Table but don't know how to save it as PDF
the Code which I have written under BUTTON "EXPORT TO PDF" is given below kindly check and tell me what to change:
method ONACTIONEXPORT_TO_PDF .
DATA LO_ND_ZBAPI_SALESVARUNTEST TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LO_ND_CHANGING TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LO_ND_ILINE TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LO_EL_ILINE TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA LT_ILINE TYPE WD_THIS->ELEMENTS_ILINE.
DATA LS_ILINE TYPE WD_THIS->ELEMENT_ILINE.
DATA TEXT TYPE STRING.
DATA XTEXT TYPE XSTRING.
* DATA VTEXT TYPE XSTRING.
DATA NTEXT TYPE STRING.
* navigate from <CONTEXT> to <ZBAPI_SALESVARUNTEST> via lead selection
LO_ND_ZBAPI_SALESVARUNTEST = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_ZBAPI_SALESVARUNTEST ).
* navigate from <ZBAPI_SALESVARUNTEST> to <CHANGING> via lead selection
LO_ND_CHANGING = LO_ND_ZBAPI_SALESVARUNTEST->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_CHANGING ).
* navigate from <CHANGING> to <ILINE> via lead selection
LO_ND_ILINE = LO_ND_CHANGING->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_ILINE ).
* @TODO handle not set lead selection
IF LO_ND_ILINE IS INITIAL.
ENDIF.
* get element via lead selection
LO_EL_ILINE = LO_ND_ILINE->GET_ELEMENT( ).
* @TODO handle not set lead selection
IF LO_EL_ILINE IS INITIAL.
ENDIF.
* alternative access via index
* lo_el_iline = lo_nd_iline->get_element( index = 1 ).
* @TODO handle non existant child
* IF lo_el_iline IS INITIAL.
* ENDIF.
* get all declared attributes
LO_EL_ILINE->GET_STATIC_ATTRIBUTES(
IMPORTING
STATIC_ATTRIBUTES = LS_ILINE ).
*APPEND LS_ILINE TO LT_ILINE.
CALL METHOD LO_ND_ILINE->GET_STATIC_ATTRIBUTES_TABLE
* EXPORTING
* FROM = 1
* TO = 2147483647
IMPORTING
TABLE = LT_ILINE
.
LOOP AT LT_ILINE INTO LS_ILINE.
NTEXT = LS_ILINE-ZMENG.
CONCATENATE TEXT LS_ILINE-VBELN
LS_ILINE-POSNR
LS_ILINE-WERKS
NTEXT
LS_ILINE-MEINS
CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO TEXT SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
ENDLOOP.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = TEXT
IMPORTING
BUFFER = XTEXT.
CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE (
EXPORTING I_FILENAME = 'output.pdf'
I_CONTENT = XTEXT
I_MIME_TYPE = 'PDF'
I_IN_NEW_WINDOW = ABAP_TRUE ).
endmethod.
Hi Varun,
Were you able to solve the above problem?
If yes, how did you do it?
I am facing similar issue and have tried implementing same conversion. Text to Binary to Xstring.
As pointed out earlier, when I open the downloaded PDF file in Excel, it opens perfectly fine. So, the problem should be with the conversion.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
where you able to solve this Problem with Output PDF?
(http://sap.ittoolbox.com/groups/technical-functional/sap-abap/download-webdynpro-output-4857857)
I have the same Problem, ...i can download it, but if i want to open the PDF-File, than i receive a error Message "File can`t open because of wrong type oder something else..."
I think, the Problem is the wrong convertion from 1.Text => Binary and 2.Binary => XString!
Kind Regards
ETN
You have replied to a pretty old post. I'd recommend to create a new thread.
The problem is, you cannot create texts to string, convert string to xstring and attach the binary content to PDF MIME type. It might work for XLS output for not for PDF. Either have a PDF input form through SFP or generate one from ABAP spool, convert spool to xstring (lots of documentation available) and attach the binary to element to generate the PDF.
Hi Varun,
Could you please explain what is the current issue.
CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE should download to whatever mime type you declare here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The problem is then with the conversion and it means then the data is not formatted to the adobe ouptut.
I had used converted bin to xsting and this same requirement I had implemented in my proj
Can you try with converting to bin from string and then to xstring.
Here's some sample code for help.
Reward points if helpful.
data:lv_xstr type xstring.
data : lo_conv type ref to cl_abap_conv_obj.
create object lo_conv.
loop at li_bin into wa_bin.
call method lo_conv->convert
exporting
inbuff = wa_bin
outbufflg = 25000
importing
outbuff = lv_xstr.
if sy-tabix eq 1.
li_content_new = lv_xstr.
else.
concatenate li_content_new lv_xstr into li_content_new in byte mode.
endif.
endloop.
* l_filename = ls_structuremap-doknr.
concatenate ls_structuremap-doknr l_doc_id
into l_filename separated by '.'.
data : l_mime type string default 'PDF'.
call method cl_wd_runtime_services=>attach_file_to_response
exporting
i_filename = l_filename
i_content = li_content_new
i_mime_type = l_mime
i_in_new_window = abap_true.
* .
Hi Soumya,
Its still not working. I tried converting from string to Bin and then from Bin to Xstring. Getting the same result as before and downloaded file is still not getting opened.
I have now written this Code. Kindly check and tell what to rectify or change in order to make it run properly.
LOOP AT LT_ILINE INTO LS_ILINE.
NTEXT = LS_ILINE-ZMENG.
CONCATENATE VTEXT-TEXT LS_ILINE-VBELN
LS_ILINE-POSNR
LS_ILINE-WERKS
NTEXT
LS_ILINE-MEINS
CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO VTEXT-TEXT SEPARATED BY
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
APPEND VTEXT TO TSTR.
ENDLOOP.
*start of test
CALL FUNCTION 'SCMS_TEXT_TO_BINARY'
EXPORTING
* FIRST_LINE = 0
* LAST_LINE = 0
* APPEND_TO_TABLE = ' '
* MIMETYPE = ' '
* ENCODING =
*
IMPORTING
OUTPUT_LENGTH = ILEN
TABLES
TEXT_TAB = TSTR
BINARY_TAB = BTAB
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = ILEN
* FIRST_LINE = 0
* LAST_LINE = 0
IMPORTING
BUFFER = XTEXT
TABLES
BINARY_TAB = BTAB
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*end of test
* CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
* EXPORTING
* TEXT = TEXT
* IMPORTING
* BUFFER = XTEXT.
*
CL_WD_RUNTIME_SERVICES=>ATTACH_FILE_TO_RESPONSE(
EXPORTING I_FILENAME = 'output.pdf'
I_CONTENT = XTEXT
I_MIME_TYPE = 'pdf'
I_IN_NEW_WINDOW = ABAP_FALSE
I_INPLACE = ABAP_FALSE ).
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.