Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

Getting Started Store

Community WIKI SAP Community Welcome, Guest Login Register Search the Community

Web Dynpro ABAP

Upload and Download files in Webdynpro ABAP


Created by Former Member, last modified by Moshe Naveh on Oct 12, 2010

Upload and Download Files in Webdynpro ABAP


by Nagendran R, Enteg Infotech, Bangalore, India

Go to T-Code- SE80, Create a Web Dynpro Component(Zfile_upload in this example)

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 1/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

Double click on the view MAIN -> choose Context tab -> right-click on the topmost context and choose Create> Node.

Create two Nodes

Node1: N_UPLOAD

Cardinality 1.1

Attributes Type

FILE_NAME STRING

FILE_TYPE STRING

FILE_SIZE STRING

FILE_CONTENTS XSTRING

Node2: N_FILE_DOWNLOAD

Cardinality is 0.n

Attributes Type

FILE_NAME STRING

FILE_TYPE STRING

FILE_SIZE STRING

FILE_CONTENTS XSTRING

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 2/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 3/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

After creating the two Nodes,


Now go to Layout tab of MAIN view,

1. Create a group.
2. Create the element FileUpload.

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 4/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

After adding the File Upload UI element,

Create a BUTTON UI element with text property as Upload and action property as UPLOAD.

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 5/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 6/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

Afrer creating Button, Create a group and inside group create a UI element TABLE.

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 7/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki
After creating the table right-click on the table UI element and choose Create Binding.

Click on Context and choose the Node N_FILE_DOWNLOAD.

Create binding as below.

Now, in the Table columns choose the column File contents, and in the TEXT property BIND the attribute FILE_NAME OF NODE N_FILE_DOWNLOAD.

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 8/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 9/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki
After Binding, the table look like the table in the below screen shot.

Now, Choose the UI element FILE_UPLOAD and create binding for the property data, Filename, mimetype.

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 10/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

After Binding the UI element FILE UPLOAD,

Create a z-table to store all the attachments that has been uploaded, so that the files can be downloaded later.

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 11/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

The z-table fields and types are mentioned below.


Go to the methods tab and double-click on ONACTIONUPLOADA(action property for UPLOAD button) and place the below code:

method ONACTIONUPLOAD .

DATA lo_nd_n_upload TYPE REF TO if_wd_context_node.


DATA lo_el_n_upload TYPE REF TO if_wd_context_element.
DATA ls_n_upload TYPE wd_this->element_n_upload.

DATA lo_nd_n_file_download TYPE REF TO if_wd_context_node.


DATA lt_n_file_download TYPE wd_this->elements_n_file_download.

data ls_file_upload TYPE ZFILE_UPLOAD1.


* navigate from <CONTEXT> to <N_FILE_DOWNLOAD> via lead selection
lo_nd_n_file_download = wd_context->get_child_node( name = wd_this->wdctx_n_file_download ).

* navigate from <CONTEXT> to <N_UPLOAD> via lead selection


lo_nd_n_upload = wd_context->get_child_node( name = wd_this->wdctx_n_upload ).

* get element via lead selection


lo_el_n_upload = lo_nd_n_upload->get_element( ).
* @TODO handle not set lead selection
IF lo_el_n_upload IS not INITIAL.

* get all declared attributes


lo_el_n_upload->get_static_attributes(
IMPORTING
static_attributes = ls_n_upload ).

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 12/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki
* ls_n_upload will contain the File name file type and file contents *

ls_n_upload-file_size = xstrlen( ls_n_upload-file_contents ).

ls_file_upload-FILE_NAME = ls_n_upload-FILE_NAME.
ls_file_upload-FILE_TYPE = ls_n_upload-FILE_TYPE.
ls_file_upload-FILE_SIZE = ls_n_upload-FILE_SIZE.
ls_file_upload-FILE_CONTENTS = ls_n_upload-FILE_CONTENTS.

insert zfile_upload1 from ls_file_upload.


if sy-subrc = 0.
select file_name
file_type
file_size
file_contents
from zfile_upload1
into TABLE lt_n_file_download.

lo_nd_n_file_download->bind_table( new_items = lt_n_file_download set_initial_elements = abap_true ).

endif.

ENDIF.

endmethod.

Activate all the Web Dynpro components .Create a Web Ddynpro Application and test it,

The Output Will be,

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 13/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

Click on Browse -> Choose a file for Upload -> Click on Upload.

After Uploading,file details can be seen in the Table and a Link to Download will be availablle.

Click on the Link to download the Uploaded file.

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 14/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

The Download file can be viewed in a Pop-up window.

web dynpro file download abap webdynpro files upload

12 Comments
Guest
Good one Mr. Nagendran....

Guest
Very useful Mr. Nagendran

Guest
Looks like you forgot to erase the URL in the second screenshot mate, Nice Blog !!!

Guest
hI,Superb

Miltiadis Kouvaras
Very useful how-to article!

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 15/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

Former Member

Very Nice

Former Member
The mimetype should be bind to the file type in the download file table

Former Member

Hi there,

Nice article, .png and .PDF works fine with this approach. However .msg/.txt/.docx/.ppt doesnt. Since I am using a generic application, can not use GOS ,any way around using for these file
type.

Thanks

Mohinder

Former Member
Hi Mohinder,

As you say it does not work for docx do you know how to do it?

Regards

Former Member
Hi All

I tried this, But it is working for Uploading the File. But When i am clicking on the file name to download, It is not getting download, It is in the different :

%PDF-1.4 %âãÏÓ 3 0 obj <> /Contents 4 0 R>> endobj 4 0 obj <> stream xœíZKoÇpâÙ‹ âcÚ€aÙŠ5ìw÷ø@ˆŽ¬µåX±% ç@/õr–zP²ý•\r ò«¨’¯ª3³\rIIF‚@¦wfº¦»ÞU]Õ#ñXHñL8ÙI-Eè}
çŒÂö 4±lì¤<4V :åhºëzïÄBXßikàb/¬ë¬R<”Æk» <†¶3¦§éä4¦óÖ k:ëé½î¢24”=V]/=M×Xï ]ß÷4tÌ,˜V¡#±œ§ÀCâ}9bçœ-è<¤p¡’ó Á{^ŸØg]p}aÖãÞëP„¡¡6š¦'a=–9¨,«ÂƒJuQ ½4=©’Ú¨¢h÷Ùe¸FšÌ|‚,
± “ªBŒÑTŒFÂHý˜¤‘¡Ó}¨<;¥ûÊ2 £6#™Œ„îT¨B¾‚©:¡±µýHi‰ÚV¥²$IéÃ8YeQ!ÅpË’-[pêƒg¾Šë¾‹gÉ×+²ß,º)®[´7øvÑoqþ¢ÿÅBe¼X ¦%B,ZÕE =ˆu Ë ‘ã0Ø)A†x ðo*N«B¼ùl/·N€Z@.t Â:¬!
ƒ«@æ:£+BU¤áB¬êameä¢cft°9[ú¾dË\¥l‰ü.¯µÊ'R¹2Ò¹2Ò§TFo²í›lû&Û¾þl[*#ÅËø:TFe6b7wAÞ•.hRÁ߸’rž;Ÿƒ ÔÄä!±V¥SHY´\Ų‰ÇélíuÎGÀkG< -®Ï(ñlöٮغ¦„JXvïˆÏwgéùî,É8Ÿm¥–-
®Á¼ÃÙ_ÿA÷ë;ðÔ»Úê¾ÓÔ•Á%¨W'¹ÿÛúR‰«ÁEY÷ÿv?Ñ:NsœáCÃ줢ËÖ~0ΆÅ:vžz`è“ÖÝO_‹b>öÃZ ž ]7œe±§Ô‚~ÑBTH!{YM\ê„Å í”BXWK:"Ы«gÉ Ñ° | Ahu™ÇHMgQk£3ÚQkã¥/B Ó
ÌG=\ÓR1bÄî¾µ[íg/n´ßÔº6]hu#Ú߶Ûíí6žbûÖÑULÙþXìþ`y +›èTfHãÁ¸NºÍŸ›ÍýæçævsØ'DMÇç‚Ú§SVm= =¶˜Ô ˜èÒÉap|Nh æƒ=Å+†sB/ÄltPH ¥˜ÙÔ™j å”–Î*͈¦¥£*S(F½U•gþv¡«P
xk=h”ìÏj ©¡ªMWëÍõYÿ˜Åj N€:ÙcþçJC*ܱ[Q7à ÞtÑqsq–Úpe5u(h¦.«´n¨ÐP¨+ëb”{„댋ûÔ‰–ÅŠz[³†ôú³æÌ6ê"ê¨ÆÄ ÕÃNnZ\I—Õ…ôêêS5F®ÆúŽã^nÃb£xqå;P÷åΪ²²ºð}¦Õ™´u®³½ñm:¿ÑZe1 Ú
—]ŒB )£u¸®u¼có *6w4 EfÖÔ;Ž®ãJÓ…ì,Iòc¡½†ÊF”0~ïWPª&rõJ«Â5 Fuëck™žàDÆkè'¤I¥¦=µÔÜ žMŒ+£‘i-sŽDž9ÆJ GÍôTTÜG9Ñ5wÑKüŒ;`'nƯßbÚbg3«ú}5“idxCžœ?q
•ä¾rVù ÛQCŽ> éÏgÈ5ýª}Õ~eˆÇÎé š{÷Jýª=] ¢ ç(ÔÙ~u ÷ ³Å†cxEQéÏÕ‡næä˜Î¤®WíÔ´Ç—) öUg_Cƒ>¾l®r©¿dý; û=ÈÁ×û<ƒÕö²»)”À©¢ZI›Î†X4v&jQ÷é3Ãõ0ç+™Eãa Ã&ÿ©uLUº—õˆ1?j:
‰('p؆SÂVoÊlkf $²&‘•¸Žß ‚áZ<k&ßœs êYé[F_4sôOjIÛ·SÄ"¤aùO î¹ôÒ¿úSYÓ?ŸÓ¤²_a¼ýuS'ݾ tOÝ‹ áúaëÛm¤¤-NEïåûûí¼ý?½Ó^j¯´ï¶¿o S×´€é£ïÚ‹œ¼>}ºícþTc:°è ãêÞiþ¶ªxÅð©–
ÆÃáT ‡S’§ Ê|85Ð̇S…©|8Ux·SE¨óNý‘•• endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 8 0 obj <> stream /CIDInit /ProcSet findresource begin
12 dict begin begincmap /CIDSystemInfo <> def /CMapName /Adobe-Identity-UCS def /CMapType 2 def 1 begincodespacerange <0000> endcodespacerange 1 beginbfrange
<0000> <0000> endbfrange endcmap CMapName currentdict /CMap defineresource pop end end endstream endobj 9 0 obj <> endobj 10 0 obj < >> /FontFile2 12 0 R >> endobj 11 0 obj <>
stream xœíÏçV@á{JVD²"”Ù¢lÉÈ&« ¼ÿCðõà ï{€{ÎMÚÖöv4Ð`;jW»ÛÓÞö5Üþ4ÒÁ5ÚáÆ:ÒÑŽu¼ w²SMtº3 m²©Îu¾]lºK]n¦+]íZ×»ÑÍnu»Ùît·¹æ»×ýô°G=îIO[èY‹=ïE/{ÕR¯{ÓÛÞõ¾}ìSŸ[îK_ûÖ÷~
´Òjk÷³_ýnc³óÿüÙ‚ü'þVñ endstream endobj 12 0 obj <> stream xœÍ| \TUßÿ9÷Ü;ì.•zqIeÄ]ce÷t`˜ apfQq_pßqGKSS+5-K+ÓžÔzÊ6³35³½Þgi™Ãÿwν3d>Ïç}
ßÿçÿgºsÏ=Ë÷·ÿÎï\0„B h>"hZVnlœéÈ Ë¡ç¸ò-ú ßM¾Ÿ!„SàÒÎpÈkµ‡FHH‡çMEÅ–¯çÿã „ÈM˜¿²Xo¯@^ðAb<û—U•}žò9<ÏD¨ó©£Þðkw«¡È>0Þ¿:œ^Ṟ»–X3 nŠ|žWþª2k¡ÞV ô¢:ÀøE‹~f…
ø:I€gFO.×[Œ³ŸIš†P7xÿ Âjw4-@ñ¯°+*«5¿Â3`H #LŽâuH„¶VÚ:+wr mA* F#i$A¿DBS6º{ÏWD2 ¡ì" % ¹©IJCñv/¾ dw߸Š”¢ÞQÛ À7æw ,HwŒ4íijb¼±{Óí¦s|–‚ " æy!oäƒ|‘òG`™6(£¶(…
¢0ÔµGPGôz°;¡Î¨`…£‰º¢(PDwÔõD ¢^(õF1(õA}QÒ¢~(õGÐ@4 FCÐP4 G \‰( %£¤C©h‰ÒÐ(4¥£”‰²P6ƒrP.ÊCcQ>‡Æ£ ãIh2š‚GSÑ4¤GLì‹ì ã)ô6|>„V:2£éhÚí;h6ï]ôfèùTbs?D§pO˜'°Ž½
8Z»ó‹àyà³ñòÿl'ïUH ÙÐÊæ+ö Sdˆ(’w”‹¯zä{bméTórÐUø$ú(t}Š¡}ø ªA«‘]dt¾ÒàÅŒ ¤+üów ’Qf}féŠ&(™AÎ3€¾OéÇ=q™FŠðx PÀ‡ÈHè]‚Ìâ4øtçŸ.Ÿ"ƒ Ìúª¼èa²ÐSìŽFãÀ?„†¿EÀéH¸Æ?ùí!
þÀaGéu4Êk”Æk¼jÀ"šM´x»¦X¡†äB&ôF™ø*P—yA#‰DÀ(Z:*D¥Ž&Œ/_œÞ;ºÕ£ä%EÙGªåSMMÙãŇ¥ G¥GŽ’(ï£bTä?¼Õ;ztöxùè%]ŠŠª›–}¹ã¡Éž úu)½·X"€@k#¿Jû #$8<8*<8|2ÙÖø®ðWg?
Zçøû?mšž|Õ½¦Ûø{° ÄЯ¿6®]X¨&2¢[ˆ–„EÆßÓiû¦¦öÕêÄo†YKff ™!=Õøvc£Bõ9$ì€õœŽj‘Á8e-þjtÅyEèÅ.˜·rÃéU˜×æE’p?¬áaáüŠ‰„+<>œ_äMǸÿd:eûã8Œ^…¦ç§ì˜Ú4eûdú4Š~‰{œ,
¡ÇÉ2ªÇ»©~;=¾ àz

Please help me, How i can convert this data to actual File.

Akshay Rajpurohit
Hi ,

I am facing same issue as marked by Arjun Gupta.

Please let me know if any one got solution for this - this is not working for excel/pdf/docx file .

Former Member
Hi,

it seems to be a Problem with the MIME-TYPE. The Data Element for FILE_TYPE with length char10 in this example can not save the full Name of the MIME-TYPE for .docx
(application/vnd.openxmlformats-officedocument.wordprocessingml.document), .doc (application/msword), .pptx (application/vnd.openxmlformats-
officedocument.presentationml.presentation), .xlsx (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet).

Try it with another data element like CMX_TYPES_MIMETYPE (char 128)

With IE it's working for me.

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 16/17
1/16/2019 Upload and Download files in Webdynpro ABAP - Web Dynpro ABAP - SCN Wiki

Contact Us SAP Help Portal


Privacy Terms of Use Legal Disclosure Copyright Cookie Preferences Follow SCN

https://wiki.scn.sap.com/wiki/display/WDABAP/Upload+and+Download+files+in+Webdynpro+ABAP 17/17

You might also like