Using the GOS (Generic Object Services) Class within ABAP WebDynpro applications
Linked From Document: http://scn.sap.com/docs/DOC-41921
This second example demonstrates how to use the GOS class from within ABAP WebDynpro applications.
Basic Setup
Create a WebDynpro program with one view.
Open the COMPONENTCONTROLLER context and Add two nodes: FILE_UPLOAD and FILE_DOWNLOAD
Note: All attributes are string type except:
FCONTENTS=XSTRING
FDOCTP=SO_OBJ_TP
FDOCYR=SO_OBJ_YR
FDOCNO=SO_OBJ_NO
In the View, map the two nodes from above to the views context.
On the View Layout, add a FileUpload control, a Table control, and a button for upload and delete like the following:
Column “Type” Properties:
Column “Size” Properties:
Column “Download Link” Properties:
FileUpload Properties:
Table Properties:
Listing Attachments
method wddomodifyview .
data: lo_nd_file_download type ref to if_wd_context_node, lt_file_download type wd_this->elements_file_download.
data: ls_lporb type sibflporb, lv_objtyp type so_obj_tp, lt_bapirettab type bapirettab.
data: t_files type z_tt_sood, wa_files like line of t_files, mimetype type w3conttype.
data: wa_lt_file_download like line of lt_file_download.
if first_time eq ‘X’.
lv_objtyp = ‘EXT’.
ls_lporb-typeid = ‘BUS1065’.
ls_lporb-instid = ‘00000111’.
call method zcl_oh_my_gos_new=>gos_get_file_list
exporting
is_lporb = ls_lporb
importing
t_attachments = t_files
rt_messages = lt_bapirettab.
lo_nd_file_download = wd_context->get_child_node( name = wd_this->wdctx_file_download ).
loop at t_files into wa_files.
call method zcl_oh_my_gos_new=>gos_get_file_xstring
exporting
folder_region = ‘B’
doctp = wa_files-objtp
docyr = wa_files-objyr
docno = wa_files-objno
importing
o_content_hex = wa_lt_file_download-fcontents
o_mimetype = mimetype
rt_messages = lt_bapirettab.
concatenate wa_files-objdes ‘.’ wa_files-acnam into wa_lt_file_download-fname.
wa_lt_file_download-ftype = wa_files-acnam.
wa_lt_file_download-fsize = wa_files-objlen.
wa_lt_file_download-fmimetype = mimetype.
wa_lt_file_download-fdoctp = wa_files-objtp.
wa_lt_file_download-fdocyr = wa_files-objyr.
wa_lt_file_download-fdocno = wa_files-objno.
append wa_lt_file_download to lt_file_download.
endloop.
lo_nd_file_download->bind_table( new_items = lt_file_download set_initial_elements = abap_true ).
endif.
endmethod.
Uploading Attachments, Downloading Attachments, Deleting Attachments
method onactionbeginupload .
data: lo_nd_file_upload type ref to if_wd_context_node, lo_el_file_upload type ref to if_wd_context_element.
data: lo_nd_file_download type ref to if_wd_context_node, lt_file_download type wd_this->elements_file_download.
data: ls_file_upload type wd_this->element_file_upload, it_content type standard table of soli.
data: l_file_name type avwctxcont, wa_lt_file_download like line of lt_file_download.
data: ls_lporb type sibflporb, lv_objtyp type so_obj_tp, lt_bapirettab type bapirettab.
data: t_files type z_tt_sood, wa_files like line of t_files, mimetype type w3conttype.
lo_nd_file_upload = wd_context->get_child_node( name = wd_this->wdctx_file_upload ).
lo_el_file_upload = lo_nd_file_upload->get_element( ).
if not ( lo_el_file_upload is initial ).
lo_el_file_upload->get_static_attributes( importing static_attributes = ls_file_upload ).
if not ( ls_file_upload is initial ).
lv_objtyp = ‘EXT’.
ls_lporb-typeid = ‘BUS1065’.
ls_lporb-instid = ‘00000111’.
call method zcl_oh_my_gos_new=>gos_attach_file_xstring
exporting
iv_name = ls_file_upload-fname
iv_content_hex = ls_file_upload-fcontents
is_lporb = ls_lporb
iv_objtp = lv_objtyp
receiving
rt_messages = lt_bapirettab.
call method zcl_oh_my_gos_new=>gos_get_file_list
exporting
is_lporb = ls_lporb
importing
t_attachments = t_files
rt_messages = lt_bapirettab.
lo_nd_file_download = wd_context->get_child_node( name = wd_this->wdctx_file_download ).
loop at t_files into wa_files.
call method zcl_oh_my_gos_new=>gos_get_file_xstring
exporting
folder_region = ‘B’
doctp = wa_files-objtp
docyr = wa_files-objyr
docno = wa_files-objno
importing
o_content_hex = wa_lt_file_download-fcontents
o_mimetype = mimetype
rt_messages = lt_bapirettab.
concatenate wa_files-objdes ‘.’ wa_files-acnam into wa_lt_file_download-fname.
wa_lt_file_download-ftype = wa_files-acnam.
wa_lt_file_download-fsize = wa_files-objlen.
wa_lt_file_download-fmimetype = mimetype.
wa_lt_file_download-fdoctp = wa_files-objtp.
wa_lt_file_download-fdocyr = wa_files-objyr.
wa_lt_file_download-fdocno = wa_files-objno.
append wa_lt_file_download to lt_file_download.
endloop.
lo_nd_file_download->bind_table( new_items = lt_file_download set_initial_elements = abap_true ).
* Avoid Duplication – clear out the upload information
clear ls_file_upload.
lo_el_file_upload->set_static_attributes( static_attributes = ls_file_upload ).
endif.
endif.
endmethod.
method onactiondelete .
data: lo_nd_file_download type ref to if_wd_context_node.
data: lo_el_file_download type ref to if_wd_context_element.
data: ls_file_download type wd_this->element_file_download.
data: ls_lporb type sibflporb, lt_bapirettab type bapirettab.
data: lo_nd_file_upload type ref to if_wd_context_node.
data: lo_el_file_upload type ref to if_wd_context_element.
data: t_files type z_tt_sood, wa_files like line of t_files, mimetype type w3conttype.
data: lt_file_download type wd_this->elements_file_download.
data: l_file_name type avwctxcont, wa_lt_file_download like line of lt_file_download.
lo_nd_file_download = wd_context->get_child_node( name = wd_this->wdctx_file_download ).
lo_el_file_download = lo_nd_file_download->get_element( ).
if not ( lo_el_file_download is initial ).
lo_el_file_download->get_static_attributes( importing static_attributes = ls_file_download ).
ls_lporb-typeid = ‘BUS1065’.
ls_lporb-instid = ‘00000111’.
call method zcl_oh_my_gos_new=>gos_delete_file
exporting
folder_region = ‘B’
doctp = ls_file_download-fdoctp
docyr = ls_file_download-fdocyr
docno = ls_file_download-fdocno
is_lporb = ls_lporb
importing
rt_messages = lt_bapirettab.
* Refresh File List
call method zcl_oh_my_gos_new=>gos_get_file_list
exporting
is_lporb = ls_lporb
importing
t_attachments = t_files
rt_messages = lt_bapirettab.
lo_nd_file_download = wd_context->get_child_node( name = wd_this->wdctx_file_download ).
loop at t_files into wa_files.
call method zcl_oh_my_gos_new=>gos_get_file_xstring
exporting
folder_region = ‘B’
doctp = wa_files-objtp
docyr = wa_files-objyr
docno = wa_files-objno
importing
o_content_hex = wa_lt_file_download-fcontents
o_mimetype = mimetype
rt_messages = lt_bapirettab.
concatenate wa_files-objdes ‘.’ wa_files-acnam into wa_lt_file_download-fname.
wa_lt_file_download-ftype = wa_files-acnam.
wa_lt_file_download-fsize = wa_files-objlen.
wa_lt_file_download-fmimetype = mimetype.
wa_lt_file_download-fdoctp = wa_files-objtp.
wa_lt_file_download-fdocyr = wa_files-objyr.
wa_lt_file_download-fdocno = wa_files-objno.
append wa_lt_file_download to lt_file_download.
endloop.
lo_nd_file_download->bind_table( new_items = lt_file_download set_initial_elements = abap_true ).
endif.
endmethod.
RESULT
Thanks Philip.
Really a great series of documents.
I have a requirement to read attached document (Any type of document) and display it in browser.
Please guide me on this.
Thanks,
Manoj