versioning documents in webdynpro abap abap
TRANSCRIPT
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
1/17
versioning files in abap
webdynpro...
Step1:Create a Transparent table as shown in the figure.
Note: Make employee Number foreign key from table pa0003.
1
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
2/17
Create a value range for document category.
Step 2:
Create a webdynpro component and create 2 views and 2 windows as shown.
2
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
3/17
DOCNR TYPE ZPHOTO-DOCNR.
DOCVR TYPE ZPHOTO-DOCVR.
EMPID TYPE ZPHOTO-PERNR.
NAME TYPE ZPHOTO-SNAME.
FILE_TYPE TYPE STRING.
FILE_NAME TYPE STRING.
FILE_SIZE TYPE STRING.
CATEGORY TYPE ZPHOTO-DOCUMENT_CAT.
FILE_CONTENTS TYPE XSTRING.
3
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
4/17
sTEP 3:
Design a view as shown.
4
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
5/17
5
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
6/17
Step 4:
Create 2 buttons, one for upload and one more to view all employees and also
create on actions as shown.
6
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
7/17
7
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
8/17
Write the code for respective method to work.
METHOD onactionupload .
DATA lo_nd_n_upload TYPEREFTO if_wd_context_node.
DATA lo_el_n_upload TYPEREFTO if_wd_context_element.
DATA ls_n_upload TYPE wd_this->element_n_upload.
8
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
9/17
DATA lo_nd_n_file_download TYPEREFTO if_wd_context_node.
DATA lt_n_file_download TYPE wd_this->elements_n_file_download.
DATA ls_file_upload TYPE zphoto.
DATA: lv_flag TYPE zphoto-docnr,
lv_flag1 TYPE zphoto-dokvr,
itab TYPETABLEOF zphoto.
* navigate from to via lead selection
lo_nd_n_file_download = wd_context->get_child_node( name = wd_this-
>wdctx_n_file_download ).
* navigate from to 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 ISNOTINITIAL.
* get all declaredattributes
lo_el_n_upload->get_static_attributes(
IMPORTING
static_attributes = ls_n_upload ).
* ls_n_uploadwill contain the File name file type and file contents *
*****************************************************************************
******
SELECTMAX( docnr ) INTO lv_flag FROM zphoto.
ls_n_upload-docnr = lv_flag + 1.************** **************************************************************
*****
ls_n_upload-file_size = XSTRLEN( ls_n_upload-file_contents ).
*****************************************************************************
****
* ls_n_upload-docnr= sy-dbcnt + 1.
*****************************************************************************
****
ls_file_upload-docnr = ls_n_upload-docnr.
ls_file_upload-pernr = ls_n_upload-empid.""
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-document_cat = ls_n_upload-category.
ls_file_upload-sname = ls_n_upload-name.""
9
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
10/17
ls_file_upload-file_contents = ls_n_upload-file_contents.
****Logic for Version Management***
*loop at ls_file_upload.
IF ls_n_upload-file_type = ls_file_upload-file_type AND
ls_n_upload-empid = ls_file_upload-pernr AND
ls_n_upload-category = ls_file_upload-document_cat.
SELECTMAX( dokvr ) INTO lv_flag1 FROM zphoto WHERE
pernr = ls_n_upload-empid
AND FILE_NAME = LS_FILE_UPLOAD-FILE_NAME
AND FILE_TYPE = ls_file_upload-file_type
AND FILE_SIZE = ls_file_upload-file_SIZE
AND document_cat = ls_n_upload-category
AND SNAME = LS_N_UPLOAD-NAME.
* AND FILE_CONTENTS = LS_N_UPLOAD-FILE_CONTENTS.
ls_n_upload-dokvr = lv_flag1 + 1.
ELSE.
ls_n_upload-dokvr = 1.
* else.
*ls_n_upload-dokvr = lv_flag+ 1.
ENDIF.
*
ls_file_upload-dokvr = ls_n_upload-dokvr.
* endloop.
****Logic for Version Management***
INSERT zphoto FROM ls_file_upload.
IF sy-subrc = 0.
SELECT * INTO CORRESPONDING FIELDSOFTABLE lt_n_file_download FROM zph
oto.
lo_nd_n_file_download->bind_table( new_items = lt_n_file_download set_initial_elements = abap_true ).
ENDIF.
ENDIF.
ENDMETHOD.
10
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
11/17
method ONACTIONVIEW_DETAILS .
DATA lo_window_manager TYPEREFTO if_wd_window_manager.
DATA lo_api_component TYPEREFTO if_wd_component.
DATA lo_window TYPEREFTO if_wd_window.
lo_api_component = wd_comp_controller->wd_get_api( ).
lo_window_manager = lo_api_component->get_window_manager( ).lo_window = lo_window_manager->create_window(
window_name = 'POPUPW'
* title =
* close_in_any_case = abap_true
message_display_mode = if_wd_window=>co_msg_display_mo
de_selected
* close_button = abap_true
button_kind = if_wd_window=>co_buttons_ok
message_type = if_wd_window=>co_msg_type_none
default_button = if_wd_window=>co_button_ok
).
lo_window->open( ).
endmethod.
11
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
12/17
Write the below code to initialize the view.
method WDDOINIT .
DATA lo_nd_n_upload TYPEREFTO if_wd_context_node.
DATA lo_el_n_upload TYPEREFTO if_wd_context_element.
DATA ls_n_upload TYPE wd_this->element_n_upload.
DATA lo_nd_n_file_download TYPEREFTO if_wd_context_node.
DATA lt_n_file_download TYPE wd_this->elements_n_file_download.
data ls_file_upload TYPE Zphoto.
* navigate from to via lead selection
lo_nd_n_file_download = wd_context->get_child_node( name = wd_this-
>wdctx_n_file_download ).
* navigate from to 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( ).
select
docnr
dokvr
pernr
12
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
13/17
sname
file_name
file_type
file_size
document_cat
file_contents
from zphoto
intoTABLE lt_n_file_download.
SORT lt_n_file_download BY EMPID ASCENDING.
lo_nd_n_file_download->bind_table( new_items = lt_n_file_download set_initial
_elements = abap_true ).
endmethod.
Step 5:Create a node in the second view as shown.
13
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
14/17
Initialize the view .
method WDDOINIT .
DATA lo_nd_emp TYPEREFTO if_wd_context_node.
DATA lt_emp TYPE wd_this->elements_documentdetails.
14
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
15/17
* navigate from to via lead selection
lo_nd_emp = wd_context->get_child_node( name = wd_this-
>wdctx_documentdetails ).
* @TODO handle non existant child
* IF lo_nd_emp IS INITIAL.
* ENDIF.
* * @TODO compute values
* * e.g. call a model function
*
select * from zphoto intotable lt_emp .
lo_nd_emp->bind_table( new_items = lt_emp set_initial_elements = abap_true
).
endmethod.
Map the first view Main to the first window,
And the second view to the second window(For popup)
15
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
16/17
Create an application and test.
16
-
8/2/2019 Versioning Documents in Webdynpro Abap ABAP
17/17
Note: Upload bmp images only.
Future Scope: To make the same work for all the other file
formats.
Test giving the same employee number, name, and
document category and upload the same file to see the
versioning. You can upload the same file as many times
required making the change in the contents thus satisfying
the need to maintain the files according to category and
versions.
17