Web Dynpro programming

web dynpro programming for reading nodes, attributes without using code wizard

+ -
Most of the times we use code wizard to read a node or attribute, but is very important for us to write code manually or reading a node or attribute or table, by the end of this lesson you will be able to understand manual code writing.

Code generated using code wizard:

The below is used to read static attributes of a node(one record).

    DATA LO_ND_NODE_NAME TYPE REF TO IF_WD_CONTEXT_NODE.

    DATA LO_EL_NODE_NAME TYPE REF TO IF_WD_CONTEXT_ELEMENT.
    DATA LS_NODE_NAME TYPE WD_THIS->ELEMENT_NODE_NAME.

*   navigate from <context> to <node_name> via lead selection
    LO_ND_NODE_NAME = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_NODE_NAME ).

*   @TODO handle non existant child
*   IF lo_nd_node_name IS INITIAL.
*   ENDIF.

*   get element via lead selection
    LO_EL_NODE_NAME = LO_ND_NODE_NAME->GET_ELEMENT( ).
*   @TODO handle not set lead selection
    IF LO_EL_NODE_NAME IS INITIAL.
    ENDIF.

*   get all declared attributes
    LO_EL_NODE_NAME->GET_STATIC_ATTRIBUTES(
      IMPORTING
        STATIC_ATTRIBUTES = LS_NODE_NAME ).

Manually writing code to read static attributes

Step1: Data decelerations for node instance, element instance, work area and other variables.

DATA : <NODE> TYPE REF TO IF_WD_CONTEXT_NODE. "node declaration

DATA : <ELEMENT> TYPE REF TO IF_WD_CONTEXT_ELEMENT. "element declaration

DATA : <WA> TYPE IF_<VIEW_NAME>=>ELEMENT_<NODE_NAME>. "work area declaration

DATA : <ITAB> TYPE IF_<VIEW_NAME>=>ELEMENTS_<NODE_NAME>. "work area deceleration
DATA : <LV_VAR> TYEP MARA-MATNR.

Step2:Create an instance for the node using root node instance and by using method get_child_node .

CALL METHOD WD_CONTEXT->GET_CHILD_NIDE(
                             EXPORTING
                                NAME = '<NODE_NAME>'
                             IMPORTING
                                INSTANCE = <NODE> ).

Step3: Get element instance using node instance and method get_element.

CALL METHOD <NODE>->GET_ELEMENT(
                      *EXPORTING
                      *  INDEX = <INDEX> "by default lead selection
                      RETURNING
                        INSTANCE = <ELEMENT>).

Step4: Now read node or attribute into work area or internal table using node and element instance.

To read a single attribute .

CALL METHOD <ELEMENT>->GET_ATTRIBUTE(
                         EXPORTING
                            NAME = <ATTRIBUTE_NAME> ex: MATNR in MARA node
                         IMPORTING
                            VALUE = <LV_VAL>).

Read all attributes into work area.

CALL METHOD <ELEMENT>->GET_STATIC_ATTRIBUTES(
                            IMPORTING
                               STATIC_ATTRIBUTES = <WA>).

Read whole node into an internal table.

CALL METHOD <NODE>->GET_STATIC_ATTRIBUTES_TABLE(
                           IMPORTING
                              NEW_ITEMS = <ITAB>).

If you found any difficulties in understanding this lesson, please ask a question by clicking on ask question.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 32 People out of 34 think this lesson helpful


    Lesson Navigation

    Hook Methods in webdynpro ABAP← Previous Lesson
    Next Chapter →