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  to  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 :  TYPE REF TO IF_WD_CONTEXT_NODE. "node declaration

DATA :  TYPE REF TO IF_WD_CONTEXT_ELEMENT. "element declaration

DATA :  TYPE IF_=>ELEMENT_. "work area declaration

DATA :  TYPE IF_=>ELEMENTS_. "work area deceleration
DATA :  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 = ''
                             IMPORTING
                                INSTANCE =  ).

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

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

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

To read a single attribute .

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

Read all attributes into work area.

CALL METHOD ->GET_STATIC_ATTRIBUTES(
                            IMPORTING
                               STATIC_ATTRIBUTES = ).

Read whole node into an internal table.

CALL METHOD ->GET_STATIC_ATTRIBUTES_TABLE(
                           IMPORTING
                              NEW_ITEMS = ).

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 36 People out of 39 think this lesson helpful


    Lesson Navigation

    Hook Methods in webdynpro ABAP← Previous Lesson
    Next Chapter →