Sei sulla pagina 1di 21

This example, uses couple of UI and different Layouts, shows read / write from / to views etc.

Start SE80, the Object Navigator. Create aWeb Dynpro Comp./Intf.

Use the default Window.

Save it as a local object (as demo).

Create a View.

In the Context tab,


create a node N1 (with all defaults).

Web Dynpro

Muttaqi

Add Attributes to the Node N1 using table VBAK.

Create node HD for Header data.


Put table name.
(To append the structure, in future, with
non-table elements you have to remove the
table name. It can be done later as well in the
Context screen.)

Web Dynpro

Hit
fields from the table.

and select

Muttaqi

Create node TBL1 using table VBAP for line items.


Cardinality must not be 1..1.
Add attributes to the node TBL1.

Web Dynpro

Muttaqi

LAYOUT
As all the nodes and attributes are in place (we can add more if needed).
We now proceed to Layout tab to design the view..
Set the Layout to MatrixLayout.
Create Element GRP1.

And uncheck
to have spaces between elements.

Enter text into CAPTION.

It appears as:

Get node N1 under GRP1.

Web Dynpro

Muttaqi

Create a Button.

The UI Button appears next as another UI


element in a MatrixLayout.

Putting text, the Button gets visible.

Now change it to MatrixHeadData, it will appear at the next line.

If required, (to accommodate more lines below), leave it to MatrixData


Web Dynpro

Muttaqi

Create an Action for the Button.

As an element of Matrix Data it appears next to button Get Details

Changing to MatrixHeadData will do the following alignment.

Web Dynpro

Muttaqi

Make the GRP2 as

So Header Details appears


in two columns

Now Create a
Table element.

Web Dynpro

Muttaqi

As part of
the table appears next
to
element

C
Changing it tp
the tablr will appear
below the

Right click on element

Web Dynpro

, choose

Muttaqi

We are creating the table for display purpose only so

Web Dynpro

Muttaqi

If the Binding of CHARG is unchecked the column Batch dis-appears.

We completed the Design of Layout.

Web Dynpro

10

Muttaqi

CODING
Click on the button

Or

Either way the following screen appears, where CODING has to be done.

Create a blank line

Use Code Wizard to GENERATE CODES.

Web Dynpro

11

Muttaqi

Select Node N1

Generates the Code.


DATA:
node_n1
elem_n1

TYPE REF TO if_wd_context_node,


TYPE REF TO if_wd_context_element

,
*
*
*

stru_n1
TYPE if_view1=>element_n1 .
navigate from <CONTEXT> to <N1> via lead selection
node_n1 = wd_context->get_child_node( name = if_view1=>wdctx_n1 ).
get element via lead selection
elem_n1 = node_n1->get_element(

).

get all declared attributes


elem_n1->get_static_attributes(
IMPORTING
static_attributes = stru_n1 ).

Web Dynpro

12

Muttaqi

Select Node HD

Generates the Code.

DATA:
node_hd
TYPE REF TO if_wd_context_node,
elem_hd
TYPE REF TO if_wd_context_element,
stru_hd
TYPE if_view1=>element_hd .
* navigate from <CONTEXT> to <HD> via lead selection
node_hd = wd_context->get_child_node( name = if_view1=>wdctx_hd ).
* get element via lead selection
elem_hd = node_hd->get_element(

).

* get all declared attributes


elem_hd->get_static_attributes(
IMPORTING
static_attributes = stru_hd ).

Select Node
DATA:
node_tbl1
TYPE REF TO if_wd_context_node,
elem_tbl1
TYPE REF TO if_wd_context_element,
stru_tbl1
TYPE if_view1=>element_tbl1 .
* navigate from <CONTEXT> to <TBL1> via lead selection
node_tbl1 = wd_context->get_child_node( name = if_view1=>wdctx_tbl1 ).
* @TODO handle not set lead selection
IF ( node_tbl1 IS INITIAL ).
ENDIF.
* get element via lead selection
elem_tbl1 = node_tbl1->get_element(

).

* @TODO handle not set lead selection


IF ( elem_tbl1 IS INITIAL ).
ENDIF.
*
*
*
*
*

alternative access via index


Elem_Tbl1 = Node_Tbl1->get_Element( Index = 1 ).
@TODO handle non existant child
if ( Elem_Tbl1 is initial ).
endif.

* get all declared attributes


elem_tbl1->get_static_attributes(
IMPORTING
static_attributes = stru_tbl1 ).

Web Dynpro

13

Muttaqi

From the generated CODE, we identified the followings:


1. stru_n1-vbeln
2. stru_hd
3. elem_hd
4. node_tbl1
Keep the following codes and delete the rest.
DATA:
node_n1
TYPE REF TO if_wd_context_node,
elem_n1
TYPE REF TO if_wd_context_element,
stru_n1
TYPE if_view1=>element_n1 .
* navigate from <CONTEXT> to <N1> via lead selection
node_n1 = wd_context->get_child_node( name = if_view1=>wdctx_n1 ).
* get element via lead selection
elem_n1 = node_n1->get_element(

).

* get all declared attributes


elem_n1->get_static_attributes(
IMPORTING
static_attributes = stru_n1 ).
*======
DATA:
node_hd
TYPE REF TO if_wd_context_node,
elem_hd
TYPE REF TO if_wd_context_element,
stru_hd
TYPE if_view1=>element_hd .
* navigate from <CONTEXT> to <HD> via lead selection
node_hd = wd_context->get_child_node( name = if_view1=>wdctx_hd ).
* get element via lead selection
elem_hd = node_hd->get_element( ).
*======
DATA:
node_tbl1
TYPE REF TO if_wd_context_node,
elem_tbl1
TYPE REF TO if_wd_context_element,
stru_tbl1
TYPE if_view1=>element_tbl1 .
* navigate from <CONTEXT> to <TBL1> via lead selection
node_tbl1 = wd_context->get_child_node( name = if_view1=>wdctx_tbl1 ).
*======

Add Codings:
* Manual Coding--------------* Collect Header Data--------SELECT SINGLE vbeln erdat vbtyp netwr vkorg vtweg spart
FROM vbak
INTO CORRESPONDING FIELDS OF stru_hd
WHERE vbeln EQ stru_n1-vbeln.
* Collect Item
SELECT vbeln
INTO TABLE
FROM vbap
WHERE vbeln

Web Dynpro

Data----------posnr matnr charg arktx


itab_ln
EQ stru_n1-vbeln.

14

Muttaqi

BINDING
*-----------Binding----------* Populate Header Data-------CALL METHOD elem_hd->set_static_attributes
EXPORTING
static_attributes = stru_hd
.
* Populate Item Data---------CALL METHOD node_tbl1->bind_table
EXPORTING
new_items
= itab_ln
*
SET_INITIAL_ELEMENTS = ABAP_TRUE
*
INDEX
=
.

Web Dynpro

15

Muttaqi

CALL METHOD elem_hd->set_static_attributes


EXPORTING
static_attributes = stru_hd
.

Web Dynpro

16

Muttaqi

BINDING ITEM DATA


DATA:
node_ln
elem_ln
stru_ln
itab_ln
select
into
from
where

TYPE
TYPE
TYPE
TYPE

REF TO if_wd_context_node,
REF TO if_wd_context_element,
if_view1=>element_ln,
if_view1=>elements_ln. "EM

vbeln posnr matnr charg arktx


table itab_ln
vbap
vbeln eq stru_n1-vbeln.

CALL METHOD node_ln->bind_table


EXPORTING
new_items
= itab_ln
"EM
*
SET_INITIAL_ELEMENTS = ABAP_TRUE
*
INDEX
=
.

====================================
====================================
====================================

Web Dynpro

17

Muttaqi

METHOD onactionget_details .
DATA:
node_n1
TYPE REF TO if_wd_context_node,
elem_n1
TYPE REF TO if_wd_context_element,
stru_n1
TYPE if_view1=>element_n1 .
* navigate from <CONTEXT> to <N1> via lead selection
node_n1 = wd_context->get_child_node( name = if_view1=>wdctx_n1 ).
* get element via lead selection
elem_n1 = node_n1->get_element(

).

* get all declared attributes


elem_n1->get_static_attributes(
IMPORTING
static_attributes = stru_n1 ).
*===========================
DATA:
node_hd
elem_hd
stru_hd
*
navigate from <CONTEXT> to <HD> via
node_hd = wd_context->get_child_node(

TYPE
TYPE
TYPE
lead
name

REF TO if_wd_context_node,
REF TO if_wd_context_element,
if_view1=>element_hd .
selection
= if_view1=>wdctx_hd ).

get element via lead selection


elem_hd = node_hd->get_element( ).
*======================================
DATA:
node_tbl1
TYPE REF TO if_wd_context_node,
elem_tbl1
TYPE REF TO if_wd_context_element,
stru_tbl1
TYPE if_view1=>element_tbl1,
itab_ln
TYPE if_view1=>elements_tbl1. "EM
*
navigate from <CONTEXT> to <TBL1> via lead selection
node_tbl1 = wd_context->get_child_node( name = if_view1=>wdctx_tbl1 ).
*======================================================================
* Manual Coding---------------------* Collect Header Data---------------SELECT SINGLE vbeln erdat vbtyp netwr vkorg vtweg spart
FROM vbak
INTO CORRESPONDING FIELDS OF stru_hd
WHERE vbeln EQ stru_n1-vbeln.
* Collect Item
SELECT vbeln
INTO TABLE
FROM vbap
WHERE vbeln

Data---------------posnr matnr charg arktx


itab_ln
EQ stru_n1-vbeln.

* Populate Header Data---------------CALL METHOD elem_hd->set_static_attributes


EXPORTING
static_attributes = stru_hd.
* Populate Item Data-----------------CALL METHOD node_tbl1->bind_table
EXPORTING
new_items
= itab_ln
*
SET_INITIAL_ELEMENTS = ABAP_TRUE
*
INDEX
=
.
ENDMETHOD.

Web Dynpro

18

Muttaqi

COPY VIEWS TO WINDOW

Web Dynpro

19

Muttaqi

CREATE WEB DYNPRO APPLICATION

Web Dynpro

20

Muttaqi

TEST THE APPLICATION

Web Dynpro

21

Muttaqi

Potrebbero piacerti anche