creating a reusable questionnaire component in ... - sap q&a...sap community network sdn -...

35
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 1 Creating a Reusable Questionnaire Component in WD ABAP for PPM Applies to: Web Dynpro for ABAP and SAP PPM 4.5. For more information, visit the Web Dynpro ABAP homepage . Summary This article explains the steps to create a reusable component for providing questionnaire in any custom PPM screen. Author: Sumit Oberoi Company: Infosys Technologies Limited Created on: 20 December 2010 Author Bio Sumit Oberoi is a Technology Analyst with Infosys Technologies Limited. His areas of expertise include Web Dynpro for JAVA , Web Dynpro ABAP, Enterprise Portal, SAP PI , CAF and portal administration.

Upload: others

Post on 01-Feb-2021

23 views

Category:

Documents


0 download

TRANSCRIPT

  • SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 1

    Creating a Reusable Questionnaire

    Component in WD ABAP for PPM

    Applies to:

    Web Dynpro for ABAP and SAP PPM 4.5. For more information, visit the Web Dynpro ABAP homepage.

    Summary

    This article explains the steps to create a reusable component for providing questionnaire in any custom PPM screen.

    Author: Sumit Oberoi

    Company: Infosys Technologies Limited

    Created on: 20 December 2010

    Author Bio

    Sumit Oberoi is a Technology Analyst with Infosys Technologies Limited. His areas of expertise include Web Dynpro for JAVA , Web Dynpro ABAP, Enterprise Portal, SAP PI , CAF and portal administration.

    https://www.sdn.sap.com/irj/sdn/nw-wdabap

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 2

    Table of Contents

    Table of Contents ............................................................................................................................................... 2

    Introduction ......................................................................................................................................................... 3

    Solution Approach .............................................................................................................................................. 3

    Detailed Solution ................................................................................................................................................. 5

    Creating the Context ....................................................................................................................................... 5 ZCNR9_QNNR_HEADER............................................................................................................................................ 7

    ZCNR9_ATTRIBUTE_STRC ....................................................................................................................................... 8

    ZCNR9_NODES_INFO .............................................................................................................................................. 10

    Creating Questionnaire View ........................................................................................................................ 11

    Create Question Nodes................................................................................................................................. 12

    Create Questionnaire UI ............................................................................................................................... 18

    Updating Questionnaire Data ........................................................................................................................ 25

    Other functions .............................................................................................................................................. 28

    Result ............................................................................................................................................................ 30

    Disclaimer ......................................................................................................................................................... 33

    Related Content ................................................................................................................................................ 34

    Disclaimer and Liability Notice .......................................................................................................................... 35

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 3

    Introduction

    While working with PPM 4.5 we faced multiple requirements where custom screens required the Questionnaires as provided by PPM with the standard Item.

    We have created this WD ABAP component which uses the Standard Item’s Questionnaire data ( /rpm/TS_QNNR_API and /rpm/TS_QNNR_HDR) at runtime.

    Solution Approach

    We have used the structure /rpm/ts_qnnr_api for our questionnaire.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 4

    This structure stores the item’s questionnaire data at runtime. Below steps explain the solution approach:

    1) Using Component gets the questionnaire data from FM /RPM/QNNR_RESULT_DISPLAY

    2) Create a node ZCNR9_QNNR_API to store the data coming from /rpm/ts_qnnr_api. Make this node as Interface node.

    3) Iterate through the data in this node and create separate nodes for each question dynamically.

    4) Create a node for storing the names of all the dynamic question nodes along with the unique attribute id for each question.

    5) Loop through the node created in previous step and get elements of each question in an internal table.

    6) On the basis of the value in field ‘Display_as’ create the UI element and bind the question node to it.

    7) Create a Label and bind to the UI element created in previous step.

    8) Add the Label and Question’s UI element to the UI element container of the screen.

    9) When user answers the question we update the node ZCNR9_QNNR_API.

    10) At the end we send the updated data from ZCNR9_QNNR_API node to the FM /rpm/qnnr_result_modify.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 5

    Detailed Solution

    Creating the Context

    Create a web Dynpro ABAP component ZWCR9_QNNR_REUSE in SE80.

    In the component controller’s context create a Node ZCNR9_QNNR_API as shown below:

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 6

    The node should look like this

    We need three more nodes. There strucuture and details are shown below:

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 7

    ZCNR9_QNNR_HEADER

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 8

    ZCNR9_ATTRIBUTE_STRC

    This node is used to contain the attribute names and types for the question nodes.We have a supply method for this node as shown in the screen below:

    Supply method FILL_ATTRIB_STRUC looks like this:

    method FILL_ATTRIB_struc .

    * data declaration

    DATA it_zcnr9_attribute_strc TYPE wd_this->Elements_zcnr9_attribute_strc.

    DATA lwa_zcnr9_attribute_strc LIKE LINE OF it_zcnr9_attribute_strc.

    * @TODO compute zcar9lues

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'ATTRIBUTE_ID'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = 'FIELDNAME'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'QNNR_ID'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_QNNR_ID'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'QNNR_DESC'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_QNNR_DESCRIPTION'.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 9

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'QTYPE'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_QTYPE'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'QUESTION_ID'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_QUESTION_ID'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'QUESTION_DESC'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_TEXT'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'DISPLAY_AS'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_DISPLAY_AS'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'WEIGHTING'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_WEIGHTING'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'MANDATORY'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_MANDATORY'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'OPTION_ID'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_OPTION_ID'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'OPTION_DESC'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_TEXT'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'VALUATION'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_VALUATION'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'ANSWERED'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_ANSWERED'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'OPTION_SCORE'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_SCORE'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    lwa_zcnr9_attribute_strc-zcar9_attribute_name = 'QNNR_SCORE'.

    lwa_zcnr9_attribute_strc-zcar9_attribute_type = '/RPM/TV_SCORE'.

    APPEND lwa_zcnr9_attribute_strc TO it_zcnr9_attribute_strc.

    * bind all the elements

    node->bind_table(

    new_items = it_zcnr9_attribute_strc

    set_initial_elements = abap_true ).

    endmethod.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 10

    ZCNR9_NODES_INFO

    This node stores the name and unique Attribute id for each question node created dynamically.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 11

    Creating Questionnaire View

    Go to the View in the ZWCR9_QNNR_REUSE component and rename it to ZWVR9_QNNR.

    Add a Group to the ROOTUIELEMENTCONTAINER as shown below:

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 12

    Create Question Nodes

    To create the Question nodes we need to iterate through the ZCNR9_QNNR_API node. We use below methods to achieve that:

    1) Prepare_Context – This method iterates through the ZCNR_QNNR_API node and creates question nodes.

    method PREPARE_CONTEXT .

    TYPES :

    BEGIN OF ty_question,

    ATTRIBUTE_ID TYPE FIELDNAME,

    QNNR_ID TYPE /RPM/TV_QNNR_ID,

    QNNR_DESC TYPE /RPM/TV_QNNR_DESCRIPTION,

    QTYPE TYPE /RPM/TV_QTYPE,

    QUESTION_ID TYPE /RPM/TV_QUESTION_ID,

    QUESTION_DESC TYPE /RPM/TV_TEXT,

    DISPLAY_AS TYPE /RPM/TV_DISPLAY_AS,

    WEIGHTING TYPE /RPM/TV_WEIGHTING,

    MANDATORY TYPE /RPM/TV_MANDATORY,

    OPTION_ID TYPE /RPM/TV_OPTION_ID,

    OPTION_DESC TYPE /RPM/TV_TEXT,

    VALUATION TYPE /RPM/TV_VALUATION,

    ANSWERED TYPE /RPM/TV_ANSWERED,

    OPTION_SCORE TYPE /RPM/TV_SCORE,

    QNNR_SCORE TYPE /RPM/TV_SCORE,

    END OF ty_question,

    BEGIN OF ty_node_name,

    name TYPE string,

    END OF ty_node_name.

    DATA : it_qnnr_api TYPE STANDARD TABLE OF ig_componentcontroller=>element_zcnr9_qnn

    r_api,

    it_qnnr_temp TYPE STANDARD TABLE OF ig_componentcontroller=>element_zcnr9_qn

    nr_api,

    lwa_qnnr_api LIKE LINE OF it_qnnr_api,

    it_qnnr_hdr TYPE STANDARD TABLE OF ig_componentcontroller=>element_zcnr9_qnn

    r_header,

    lwa_qnnr_hdr LIKE LINE OF it_qnnr_hdr,

    it_node_names TYPE ig_componentcontroller=>elements_zcnr9_nodes_info,

    lwa_node_name TYPE ig_componentcontroller=>element_zcnr9_nodes_info,

    lt_api_tmp TYPE ig_componentcontroller=>element_zcnr9_qnnr_api,

    lwa_api_tmp TYPE ig_componentcontroller=>element_zcnr9_qnnr_api,

    lv_qnnr_id TYPE /RPM/TV_QNNR_ID,

    lv_display_as TYPE numc4,

    lv_flag TYPE i,

    lv_idx TYPE i,

    it_question TYPE STANDARD TABLE OF ty_question,

    lwa_question TYPE ty_question,

    lv_id TYPE string.

    DATA : lr_node_info TYPE REF TO if_wd_context_node_info,

    lr_new_node_info TYPE REF TO if_wd_context_node_info,

    lv_name TYPE string.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 13

    DATA : lo_nd_zcnr9_qnnr_api TYPE REF TO if_wd_context_node,

    lo_nd_question TYPE REF TO if_wd_context_node,

    lo_nd_node_info TYPE REF TO if_wd_context_node.

    * navigate from to via lead selection

    lo_nd_zcnr9_qnnr_api = wd_context->get_child_node( name = wd_this-

    >wdctx_zcnr9_qnnr_api ).

    * get all the values of the node in a table

    lo_nd_zcnr9_qnnr_api->get_static_attributes_table( IMPORTING

    table = it_qnnr_api ).

    * read the first question id.

    READ TABLE it_qnnr_api INTO lwa_qnnr_api INDEX 1.

    IF sy-subrc ne 0.

    * get message manager

    data lo_api_controller type ref to if_wd_controller.

    data lo_message_manager type ref to if_wd_message_manager.

    data lv_msg_id TYPE string.

    lo_api_controller ?= wd_This->Wd_Get_Api( ).

    CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER

    RECEIVING

    MESSAGE_MANAGER = lo_message_manager

    .

    * report message

    CALL METHOD lo_message_manager->REPORT_WARNING

    EXPORTING

    MESSAGE_TEXT = 'No Questionnaire Data present'

    RECEIVING

    MESSAGE_ID = lv_msg_id

    .

    EXIT.

    ELSE.

    lv_name = lwa_qnnr_api-question_id.

    * get the context root info

    CALL METHOD wd_context->get_node_info

    RECEIVING

    node_info = lr_node_info.

    * create the first question node

    CALL METHOD lr_node_info->add_new_child_node

    EXPORTING

    name = lv_name

    is_singleton = 'X'

    is_initialize_lead_selection = 'X'

    RECEIVING

    child_node_info = lr_new_node_info.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 14

    * Add the node name to node name table

    lwa_node_name-zcar9_node_name = lv_name.

    lwa_node_name-zcar9_attribute_id = lwa_qnnr_api-attribute_id.

    APPEND lwa_node_name TO it_node_names.

    * create the attributes of the node

    CALL METHOD wd_this->prepare_node EXPORTING

    im_node_ref = lr_new_node_info.

    ** copying the it_qnnr_api table to a temporary table

    it_qnnr_temp[] = it_qnnr_api[].

    LOOP AT it_qnnr_api INTO lwa_qnnr_api.

    lv_idx = sy-tabix + 1.

    READ TABLE it_qnnr_temp INTO lwa_api_tmp INDEX lv_idx.

    IF lwa_qnnr_api-question_id ne lwa_api_tmp-question_id or

    lwa_qnnr_api-attribute_id ne lwa_api_tmp-attribute_id.

    lwa_question-attribute_id = lwa_qnnr_api-attribute_id.

    lwa_question-qnnr_id = lwa_qnnr_api-qnnr_id.

    lwa_question-qnnr_desc = lwa_qnnr_api-qnnr_desc.

    lwa_question-qtype = lwa_qnnr_api-qtype.

    lwa_question-question_id = lwa_qnnr_api-question_id.

    lwa_question-question_desc = lwa_qnnr_api-question_desc.

    lwa_question-display_as = lwa_qnnr_api-display_as.

    lwa_question-weighting = lwa_qnnr_api-weighting.

    lwa_question-mandatory = lwa_qnnr_api-mandatory.

    lwa_question-option_id = lwa_qnnr_api-option_id.

    lwa_question-option_desc = lwa_qnnr_api-option_desc.

    lwa_question-valuation = lwa_qnnr_api-valuation.

    lwa_question-answered = lwa_qnnr_api-answered.

    lwa_question-option_score = lwa_qnnr_api-option_score.

    lwa_question-qnnr_score = lwa_qnnr_api-qnnr_score.

    APPEND lwa_question TO it_question.

    * adding the question values to the Question Node

    lo_nd_question = wd_context->get_child_node( name = lv_name ).

    CALL METHOD lo_nd_question->bind_table EXPORTING

    new_items = it_question

    set_initial_elements = abap_true.

    ** Setting the selected answeres in Questionnaire

    LOOP AT it_question INTO lwa_question WHERE

    answered = 'X'.

    if lwa_qnnr_api-DISPLAY_AS EQ '0004'.

    CALL METHOD LO_ND_QUESTION->SET_SELECTED

    EXPORTING

    FLAG = ABAP_TRUE

    INDEX = sy-tabix.

    else.

    CALL METHOD LO_ND_QUESTION->SET_LEAD_SELECTION_INDEX

    EXPORTING

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 15

    INDEX = sy-tabix.

    endif.

    ENDLOOP.

    * checking for the question with no 'answered value'

    IF sy-subrc ne 0.

    CALL METHOD LO_ND_QUESTION->SET_LEAD_SELECTION_INDEX

    EXPORTING

    INDEX = -1.

    ENDIF.

    * clearing the work area and the question internal table

    CLEAR lwa_question.

    CLEAR it_question.

    * create the next node and populate it

    lv_name = lwa_api_tmp-question_id.

    " lv_name = lwa_qnnr_api-question_id.

    * checking for already existing node

    READ TABLE it_node_names INTO lwa_node_name WITH KEY ZCAR9_NODE_NAME = lv_name.

    IF sy-subrc eq 0.

    * prefix the attribute id to the Question node name

    CONCATENATE lwa_api_tmp-attribute_id lv_name INTO lv_name.

    ”CONCATENATE lwa_qnnr_api-attribute_id lv_name INTO lv_name.

    ENDIF.

    CALL METHOD lr_node_info->add_new_child_node

    EXPORTING

    name = lv_name

    is_singleton = 'X'

    is_initialize_lead_selection = 'X'

    is_static = ' '

    RECEIVING

    child_node_info = lr_new_node_info.

    * Add the node name to node name table

    lwa_node_name-zcar9_node_name = lv_name. lwa_node_name-

    zcar9_attribute_id = lwa_api_tmp-

    attribute_id. APPEND lwa_node_name TO it_node_names.

    * create the attributes of the node

    CALL METHOD wd_this->prepare_node

    EXPORTING

    im_node_ref = lr_new_node_info.

    ELSE.

    lwa_question-attribute_id = lwa_qnnr_api-attribute_id.

    lwa_question-qnnr_id = lwa_qnnr_api-qnnr_id.

    lwa_question-qnnr_desc = lwa_qnnr_api-qnnr_desc.

    lwa_question-qtype = lwa_qnnr_api-qtype.

    lwa_question-question_id = lwa_qnnr_api-question_id.

    lwa_question-question_desc = lwa_qnnr_api-question_desc.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 16

    lwa_question-display_as = lwa_qnnr_api-display_as.

    lwa_question-weighting = lwa_qnnr_api-weighting.

    lwa_question-mandatory = lwa_qnnr_api-mandatory.

    lwa_question-option_id = lwa_qnnr_api-option_id.

    lwa_question-option_desc = lwa_qnnr_api-option_desc.

    lwa_question-valuation = lwa_qnnr_api-valuation.

    lwa_question-answered = lwa_qnnr_api-answered.

    lwa_question-option_score = lwa_qnnr_api-option_score.

    lwa_question-qnnr_score = lwa_qnnr_api-qnnr_score.

    APPEND lwa_question TO it_question.

    CLEAR lwa_question.

    ENDIF.

    ENDLOOP.

    * adding the question values to the last Question Node

    lo_nd_question = wd_context->get_child_node( name = lv_name ).

    CALL METHOD lo_nd_question->bind_table EXPORTING

    new_items = it_question

    set_initial_elements = abap_true.

    ** checking for the last Question's answered value

    READ TABLE it_question INTO lwa_question WITH KEY answered = 'X'.

    if sy-subrc ne 0.

    CALL METHOD LO_ND_QUESTION->SET_LEAD_SELECTION_INDEX

    EXPORTING

    INDEX = -1.

    else.

    if lwa_question-DISPLAY_AS EQ '0004'.

    CALL METHOD LO_ND_QUESTION->SET_SELECTED

    EXPORTING

    FLAG = ABAP_TRUE

    INDEX = sy-tabix.

    else.

    CALL METHOD LO_ND_QUESTION->SET_LEAD_SELECTION_INDEX

    EXPORTING

    INDEX = sy-tabix.

    endif.

    endif.

    * clearing the work area and the question internal table

    CLEAR lwa_question.

    CLEAR it_question.

    * Binding the it_node_names to zcnr9_node_info node

    lo_nd_node_info = wd_context->get_child_node( name = 'ZCNR9_NODES_INFO' ).

    CALL METHOD lo_nd_node_info->bind_table EXPORTING

    new_items = it_node_names

    set_initial_elements = abap_true.

    ENDIF. "end of Questionnaire Data check IF

    endmethod.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 17

    2) Prepare_Node – This method adds the attribute to the newly created node.

    method PREPARE_NODE .

    DATA lo_nd_zcnr9_attribute_strc TYPE REF TO if_wd_context_node.

    DATA lo_el_zcnr9_attribute_strc TYPE REF TO if_wd_context_element.

    DATA it_zcnr9_attribute_strc TYPE wd_this->Elements_zcnr9_attribute_strc.

    DATA lwa_zcnr9_attribute_strc TYPE wd_this->Element_zcnr9_attribute_strc.

    DATA lv_attrib_info TYPE wdr_context_attribute_info.

    DATA : lr_node_info TYPE REF TO if_wd_context_node_info,

    lr_new_node_info TYPE REF TO if_wd_context_node_info,

    lv_name TYPE string.

    * navigate from to via lead selection

    lo_nd_zcnr9_attribute_strc = wd_context->get_child_node( name = wd_this-

    >wdctx_zcnr9_attribute_strc ).

    * get all elements in a table

    lo_nd_zcnr9_attribute_strc->get_static_attributes_table(

    IMPORTING

    table = it_zcnr9_attribute_strc ).

    lr_node_info = im_node_ref.

    * iterate through the list of attributes

    LOOP AT it_zcnr9_attribute_strc INTO lwa_zcnr9_attribute_strc.

    * populate the attribute info structure

    lv_attrib_info-name = lwa_zcnr9_attribute_strc-zcar9_attribute_name.

    lv_attrib_info-type_name = lwa_zcnr9_attribute_strc-zcar9_attribute_type.

    * add attribute to the node

    CALL METHOD lr_node_info->add_attribute EXPORTING

    attribute_info = lv_attrib_info.

    ENDLOOP.

    endmethod.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 18

    Create Questionnaire UI

    Now we need to iterate through the list of question nodes and then create their respective UI. In PPM structure /rpm/TS_QNNR_API there is a field ‘Display_As’ this field’s value decides the UI as shown below:

    0001 - Intput/Output Field

    0002 - RadioButton

    0003 -- Dropdown List Box

    0004 – checkbox

    We initiate this process in the WDDOMODIFY method. Below is the code for WDDOMODIFYVIEW:

    method WDDOMODIFYVIEW .

    DATA lr_qnnr_grp TYPE REF TO cl_wd_uielement_container.

    DATA :lo_nd_zcnr9_nodes_info TYPE REF TO if_wd_context_node,

    lo_node_info TYPE REF TO if_wd_context_node_info.

    DATA : it_zcnr9_nodes_info TYPE wd_this->Elements_zcnr9_nodes_info,

    wa_zcnr9_nodes_info LIKE LINE OF it_zcnr9_nodes_info. CONSTANTS lc_qnnr_grp

    TYPE string VALUE 'GRP_QNNR'.

    IF wd_comp_controller->m_changed = 'X'.

    * get the info of Wd_context

    wd_context->get_node_info( RECEIVING node_info = lo_node_info ).

    *remove all the UI elements

    lr_qnnr_grp ?= view->get_element( id = lc_qnnr_grp ).

    lr_qnnr_grp->remove_all_children( ).

    * navigate from to via lead selection

    lo_nd_zcnr9_nodes_info = wd_context->get_child_node( name = wd_this-

    >wdctx_zcnr9_nodes_info ).

    lo_nd_zcnr9_nodes_info->get_static_attributes_table

    ( importing table = it_zcnr9_nodes_info ).

    * Remove the existing question nodes.

    LOOP AT it_zcnr9_nodes_info INTO wa_zcnr9_nodes_info.

    lo_node_info->remove_child_node( name = wa_zcnr9_nodes_info-zcar9_node_name ).

    ENDLOOP.

    * clear all elements from zcnr9_nodes_info node

    lo_nd_zcnr9_nodes_info->invalidate( ). CALL METHOD wd_this-

    >create_qnnr( EXPORTING

    im_view = view ).

    wd_comp_controller->m_changed = ' '.

    ENDIF.

    endmethod.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 19

    We have a method Create_Qnnr which:

    Creates the UI of Questionnaire

    Sets the answer values for already answered questions

    Set the required flag for mandatory questions.

    method CREATE_QNNR .

    DATA : lr_container TYPE REF TO cl_wd_uielement_container,

    lr_input TYPE REF TO cl_wd_input_field,

    lr_radiobtn TYPE REF TO cl_wd_radiobutton,

    lr_radiobtn_grp_idx TYPE REF TO cl_wd_radiobutton_group_by_idx,

    lr_drpdown_by_idx TYPE REF TO cl_wd_dropdown_by_idx,

    lr_chkbx_grp TYPE REF TO cl_wd_checkbox_group,

    lr_matrix_data TYPE REF TO cl_wd_matrix_data,

    lr_qnnr_grp TYPE REF TO cl_wd_uielement_container,

    lr_qnnr_txvw TYPE REF TO cl_wd_text_view,

    lr_score_lbl TYPE REF TO cl_wd_label,

    lr_hor_gutter TYPE REF TO cl_wd_horizontal_gutter,

    lr_score_inp TYPE REF TO cl_wd_input_field,

    lr_ques_lbl TYPE REF TO cl_wd_label,

    lv_mandatory TYPE /RPM/TV_MANDATORY,

    lr_matrix_head_data TYPE REF TO cl_wd_matrix_head_data.

    DATA : lo_nd_zcnr9_qnnr_api TYPE REF TO if_wd_context_node,

    lo_nd_node_info TYPE REF TO if_wd_context_node,

    lo_nd_question TYPE REF TO if_wd_context_node,

    lo_nd_qnnr_header TYPE REF TO if_wd_context_node,

    lo_el_question TYPE REF TO if_wd_context_element,

    lv_display_as TYPE /rpm/TV_DISPLAY_AS,

    lv_id TYPE string,

    lv_bind_zcar9lue TYPE string,

    lv_bind_qdesc TYPE string,

    lv_ui_elem_ref TYPE REF TO wdy_md_ui_element_reference,

    lv_qnnr_desc TYPE string,

    lv_att_id TYPE fieldname,

    lv_tmp_att TYPE fieldname,

    lv_desc_tmp TYPE string,

    lv_bind_value TYPE string,

    lv_cnt TYPE i VALUE 1,

    lv_st_cnt TYPE string,

    lv_index TYPE i.

    DATA : it_node_info TYPE STANDARD TABLE OF ig_componentcontroller=>element_zcnr9_no

    des_info,

    lwa_node_info TYPE ig_componentcontroller=>element_zcnr9_nodes_info,

    it_qnnr_hdr TYPE STANDARD TABLE OF ig_componentcontroller=>element_zcnr9_qnn

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 20

    r_header,

    lwa_qnnr_hdr LIKE LINE OF it_qnnr_hdr.

    CONSTANTS : c_inputfield TYPE numc4 VALUE 0001,

    c_radiobtn TYPE numc4 VALUE 0002,

    c_drpdwn TYPE numc4 VALUE 0003,

    c_chkbx TYPE numc4 VALUE 0004,

    c_root TYPE string VALUE 'ROOTUIELEMENTCONTAINER',

    c_ques_desc TYPE string VALUE 'QUESTION_DESC',

    c_opt_desc TYPE string VALUE 'OPTION_DESC',

    c_required TYPE wdui_state VALUE 01,

    c_label TYPE string VALUE 'LBL_',

    c_drpdn TYPE string VALUE 'DDW_',

    c_chk TYPE string VALUE 'CHK_',

    c_radio TYPE string VALUE 'RBN_',

    c_inp TYPE string VALUE 'INP_',

    c_questionnaire TYPE string VALUE 'Questionnaire :',

    c_action TYPE string VALUE 'UPDATE_QNNR',

    c_qnr_scr TYPE string VALUE 'Total Score',

    c_qnnr_score TYPE string VALUE 'QNNR_SCORE',

    c_qnnr_desc TYPE string VALUE 'Next Questionnaire',

    c_qnnr_grp TYPE string VALUE 'GRP_QNNR'.

    * get the context nodes for Questions created

    wd_this->prepare_context( ).

    * get the zcnr9_node_info into table it_node_info

    lo_nd_node_info = wd_context->get_child_node( name = 'ZCNR9_NODES_INFO' ).

    CALL METHOD lo_nd_node_info->get_static_attributes_table

    IMPORTING

    table = it_node_info.

    * get the ROOTUIELEMENT reference

    lr_container ?= im_view->get_element( 'ROOTUIELEMENTCONTAINER' ).

    * get the questionnaire group

    lr_qnnr_grp ?= im_view->get_element( id = c_qnnr_grp ).

    * get the Questionnaire Header table

    lo_nd_qnnr_header = wd_context->get_child_node( name = 'ZCNR9_QNNR_HEADER' ).

    CALL METHOD lo_nd_qnnr_header->get_static_attributes_table

    IMPORTING

    table = it_qnnr_hdr.

    **Set the default value to avoid blank value issue

    lv_desc_tmp = 'tmp'.

    LOOP AT it_node_info INTO lwa_node_info.

    * get the question node

    lo_nd_question = wd_context->get_child_node( name = lwa_node_info-

    zcar9_node_name ).

    CALL METHOD lo_nd_question->get_element

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 21

    EXPORTING

    index = 1

    RECEIVING

    node_element = lo_el_question.

    * get the UI element option for the question

    CALL METHOD lo_el_question->get_attribute

    EXPORTING

    name = 'DISPLAY_AS'

    IMPORTING

    value = lv_display_as.

    * get the mandatory value for the question

    CALL METHOD lo_el_question->get_attribute

    EXPORTING

    name = 'MANDATORY'

    IMPORTING

    value = lv_mandatory.

    * get the Attribute ID value for the question

    CALL METHOD lo_el_question->get_attribute

    EXPORTING

    name = 'ATTRIBUTE_ID'

    IMPORTING

    value = lv_att_id.

    * get the Question description value for the question

    CALL METHOD lo_el_question->get_attribute

    EXPORTING

    name = 'QUESTION_DESC'

    IMPORTING

    value = lv_bind_qdesc.

    READ TABLE it_qnnr_hdr INTO lwa_qnnr_hdr WITH KEY attribute_id = lv_att_id.

    lv_qnnr_desc = lwa_qnnr_hdr-attribute_desc.

    IF lv_qnnr_desc ne lv_desc_tmp AND lv_att_id ne lv_tmp_att.

    **Checking for Questionnaire blank description

    IF lv_qnnr_desc IS INITIAL.

    lv_qnnr_desc = c_qnnr_desc.

    ENDIF.

    lv_desc_tmp = lv_qnnr_desc.

    lv_tmp_att = lv_att_id.

    lv_cnt = 1.

    ** Check to avoid placing gutter before first questionnaire

    IF sy-tabix gt 1.

    * Create a Horizontal Gutter

    CALL METHOD cl_wd_horizontal_gutter=>new_horizontal_gutter

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 22

    EXPORTING

    height = cl_wd_horizontal_gutter=>e_height-large

    rule_type = cl_wd_horizontal_gutter=>e_rule_type-none

    RECEIVING

    control = lr_hor_gutter.

    * add the horizontal gutter to the layout

    lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( element = l

    r_hor_gutter ).

    lr_hor_gutter->set_layout_data( lr_matrix_head_data ).

    CALL METHOD lr_qnnr_grp->add_child

    EXPORTING

    the_child = lr_hor_gutter.

    ENDIF.

    CONCATENATE c_questionnaire lv_qnnr_desc INTO lv_qnnr_desc.

    * create the textview for new questionnaire

    CALL METHOD cl_wd_text_view=>new_text_view

    EXPORTING

    text = lv_qnnr_desc

    design = 00

    RECEIVING

    control = lr_qnnr_txvw.

    * add the textview for new questionnaire

    lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( element = l

    r_qnnr_txvw ).

    lr_qnnr_txvw->set_layout_data( lr_matrix_head_data ).

    CALL METHOD lr_qnnr_grp->add_child

    EXPORTING

    the_child = lr_qnnr_txvw.

    ENDIF.

    lv_st_cnt = lv_cnt.

    CONDENSE lv_st_cnt.

    CONCATENATE lv_st_cnt '.' lv_bind_qdesc INTO lv_bind_qdesc SEPARATED BY space.

    lv_cnt = lv_cnt + 1.

    CONCATENATE c_label lwa_node_info-zcar9_node_name INTO lv_id.

    * Add the question description

    CALL METHOD cl_wd_label=>new_label

    EXPORTING

    id = lv_id

    RECEIVING

    control = lr_ques_lbl.

    *set the question description with question number

    lr_ques_lbl->set_text( lv_bind_qdesc ).

    lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_

    ques_lbl ).

    lr_ques_lbl->set_layout_data( lr_matrix_head_data ).

    CALL METHOD lr_qnnr_grp->add_child

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 23

    EXPORTING

    the_child = lr_ques_lbl.

    * check the UI elecment type and create the corresponding on view

    CASE lv_display_as.

    WHEN c_inputfield.

    CONCATENATE c_inp lwa_node_info-zcar9_node_name INTO lv_id.

    CONCATENATE lwa_node_info-zcar9_node_name '.' c_opt_desc INTO lv_bind_value.

    * creating the Input field

    CALL METHOD cl_wd_input_field=>new_input_field

    EXPORTING

    bind_value = lv_bind_value

    id = lv_id

    context_menu_id = lv_id

    RECEIVING

    control = lr_input.

    * adding the matrix head data with the radio button group

    lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( element =

    lr_input ).

    lr_input->set_layout_data( lr_matrix_head_data ).

    * checking for mandatory question

    IF lv_mandatory eq 'X'.

    lr_input->set_state( value = c_required ).

    ENDIF.

    * setting the LABEL_For value of the label

    lr_ques_lbl->set_label_for( value = lv_id ).

    CALL METHOD lr_qnnr_grp->add_child

    EXPORTING

    the_child = lr_input.

    WHEN c_radiobtn.

    CONCATENATE c_radio lwa_node_info-zcar9_node_name INTO lv_id.

    CONCATENATE lwa_node_info-zcar9_node_name '.' c_opt_desc INTO lv_bind_value.

    * creating the Radio Button Group

    CALL METHOD cl_wd_radiobutton_group_by_idx=>new_radiobutton_group_by_idx( EXP

    ORTING

    bind_texts = lv_bind_value

    id = lv_id

    context_menu_id = lv_id

    on_select = c_action

    RECEIVING

    control = lr_radiobtn_grp_idx ).

    * adding the matrix head data with the radio button group

    lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( element =

    lr_radiobtn_grp_idx ).

    lr_radiobtn_grp_idx->set_layout_data( lr_matrix_head_data ).

    * checking for mandatory question

    IF lv_mandatory eq 'X'.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 24

    lr_radiobtn_grp_idx->set_state( value = c_required ).

    ENDIF.

    * setting the LABEL_For value of the label

    lr_ques_lbl->set_label_for( value = lv_id ).

    CALL METHOD lr_qnnr_grp->add_child

    EXPORTING

    the_child = lr_radiobtn_grp_idx.

    WHEN c_drpdwn.

    CONCATENATE c_drpdn lwa_node_info-zcar9_node_name INTO lv_id.

    CONCATENATE lwa_node_info-zcar9_node_name '.' c_opt_desc INTO lv_bind_value.

    * creating the Radio Button Group

    CALL METHOD cl_wd_dropdown_by_idx=>new_dropdown_by_idx( EXPORTING

    bind_texts = lv_bind_value

    id = lv_id

    context_menu_id = lv_id

    on_select = c_action

    RECEIVING

    control = lr_drpdown_by_idx ).

    * adding the matrix head data with the radio button group

    lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( element =

    lr_drpdown_by_idx ).

    lr_drpdown_by_idx->set_layout_data( lr_matrix_head_data ).

    * setting the LABEL_For value of the label

    lr_ques_lbl->set_label_for( value = lv_id ).

    * checking for mandatory question

    IF lv_mandatory eq 'X'.

    lr_drpdown_by_idx->set_state( value = c_required ).

    ENDIF.

    CALL METHOD lr_qnnr_grp->add_child

    EXPORTING

    the_child = lr_drpdown_by_idx.

    WHEN c_chkbx.

    CONCATENATE c_chk lwa_node_info-zcar9_node_name INTO lv_id.

    CONCATENATE lwa_node_info-zcar9_node_name '.' c_opt_desc INTO lv_bind_value.

    * creating the Radio Button Group

    CALL METHOD cl_wd_checkbox_group=>new_checkbox_group( EXPORTING

    bind_texts = lv_bind_value

    id = lv_id

    context_menu_id = lv_id

    ON_toggle = c_action

    RECEIVING

    control = lr_chkbx_grp ).

    * adding the matrix head data with the radio button group

    lr_matrix_head_data = cl_wd_matrix_head_data=>new_matrix_head_data( element =

    lr_chkbx_grp ).

    lr_chkbx_grp->set_layout_data( lr_matrix_head_data ).

    * checking for mandatory question

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 25

    IF lv_mandatory eq 'X'.

    lr_chkbx_grp->set_state( value = c_required ).

    ENDIF.

    * setting the LABEL_For value of the label

    lr_ques_lbl->set_label_for( value = lv_id ).

    CALL METHOD lr_qnnr_grp->add_child

    EXPORTING

    the_child = lr_chkbx_grp.

    ENDCASE.

    ENDLOOP.

    endmethod.

    Updating Questionnaire Data

    We have set the action handler for each UI element as ONACTIONUPDATE_QNNR. In this method we set the answered option of the current question in the ZCNR9_QNNR_API node.

    method ONACTIONUPDATE_QNNR .

    DATA : lo_nd_zcnr9_qnnr_api TYPE REF TO if_wd_context_node,

    it_qnnr_api TYPE wd_this->Elements_zcnr9_qnnr_api,

    it_selected_elems TYPE wdr_context_element_set,

    lwa_qnnr_api TYPE wd_this->Element_zcnr9_qnnr_api,

    lo_node TYPE REF TO if_wd_context_node,

    lo_elem TYPE REF TO if_wd_context_element,

    str_pfx TYPE string,

    str_msg_id TYPE string,

    str_node_name TYPE string.

    DATA : lv_opt_id TYPE /RPM/TV_OPTION_ID,

    lv_attr_id TYPE fieldname,

    lv_ques_id TYPE /RPM/TV_QUESTION_ID,

    lv_answered TYPE /RPM/TV_ANSWERED,

    lv_checked TYPE string,

    lv_s_index TYPE string,

    lv_index TYPE i,

    lv_display_as TYPE /RPM/TV_DISPLAY_AS.

    CONSTANTS : c_sep TYPE string VALUE '_',

    c_chkbx TYPE /RPM/TV_DISPLAY_AS VALUE '0004'.

    * get the node name

    SPLIT id AT c_sep INTO str_pfx str_node_name.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 26

    * get the node

    lo_node = wd_context->get_child_node( name = str_node_name ).

    ** get the index and change of the changed checkbox option

    lv_s_index = wdevent->get_string('INDEX').

    lv_index = lv_s_index.

    * get the lead selection element

    lo_elem = lo_node->get_element( index = lv_index ).

    * get the question id

    CALL METHOD lo_elem->get_attribute

    EXPORTING

    name = 'QUESTION_ID'

    IMPORTING

    value = lv_ques_id.

    * check for already answered option

    * Get the attribute id to use as the filter criteria

    CALL METHOD lo_elem->get_attribute

    EXPORTING

    name = 'ATTRIBUTE_ID'

    IMPORTING

    value = lv_attr_id.

    * Get the display as to set the selected option for ChkBox.

    CALL METHOD lo_elem->get_attribute

    EXPORTING

    name = 'DISPLAY_AS'

    IMPORTING

    value = lv_display_as.

    * get the questionnaire table

    lo_nd_zcnr9_qnnr_api = wd_context->get_child_node( name = wd_this-

    >wdctx_zcnr9_qnnr_api ).

    CALL METHOD lo_nd_zcnr9_qnnr_api->get_static_attributes_table

    IMPORTING

    table = it_qnnr_api.

    ** Added logic to get the checked/unchecked option and update the Qnnr node

    IF lv_display_as eq c_chkbx.

    * Getting the current checked value

    lv_checked = wdevent->get_string('CHECKED').

    lo_elem = lo_node->get_element( index = lv_index ).

    * get the option id

    CALL METHOD lo_elem->get_attribute

    EXPORTING

    name = 'OPTION_ID'

    IMPORTING

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 27

    value = lv_opt_id.

    * get the answered value for this option

    CALL METHOD lo_elem->set_attribute

    EXPORTING

    name = 'ANSWERED'

    value = lv_answered.

    READ TABLE it_qnnr_api INTO lwa_qnnr_api

    WITH KEY attribute_id = lv_attr_id

    question_id = lv_ques_id

    option_id = lv_opt_id.

    IF sy-subrc eq 0.

    * "IF lv_answered IS INITIAL.

    lwa_qnnr_api-answered = lv_checked.

    * ELSE.

    * lwa_qnnr_api-answered = ' '.

    * ENDIF.

    MODIFY it_qnnr_api from lwa_qnnr_api INDEX sy-tabix TRANSPORTING answered.

    ENDIF.

    ELSE.

    * Changed to mark only for the current answered question.

    *READ TABLE it_qnnr_api INTO lwa_qnnr_api WITH KEY answered = 'X'.

    READ TABLE it_qnnr_api INTO lwa_qnnr_api

    WITH KEY attribute_id = lv_attr_id

    question_id = lv_ques_id

    answered = 'X'.

    IF sy-subrc eq 0.

    * clear the asnwered flag

    lwa_qnnr_api-answered = ' '.

    MODIFY it_qnnr_api from lwa_qnnr_api INDEX sy-tabix TRANSPORTING answered.

    ENDIF.

    ** set the single element as 'answered' for the UI element

    * get the option id

    CALL METHOD lo_elem->get_attribute

    EXPORTING

    name = 'OPTION_ID'

    IMPORTING

    value = lv_opt_id.

    READ TABLE it_qnnr_api INTO lwa_qnnr_api

    WITH KEY attribute_id = lv_attr_id

    question_id = lv_ques_id

    option_id = lv_opt_id.

    IF sy-subrc eq 0.

    * set the selected option as answered

    lwa_qnnr_api-answered = 'X'.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 28

    MODIFY it_qnnr_api from lwa_qnnr_api INDEX sy-tabix TRANSPORTING answered.

    ENDIF.

    ENDIF.

    * binding updated values to the node

    lo_nd_zcnr9_qnnr_api->bind_table( new_items = it_qnnr_api ).

    endmethod.

    Other functions

    Check_mandatory - If some questions are marked as mandatory we need to make sure that they are answered. This method can be called from using component to check for mandatory questions. Below is the code for this:

    method CHECK_MANDATORY .

    DATA : lo_nd_zcnr9_nodes_info TYPE REF TO if_wd_context_node,

    it_zcnr9_nodes_info TYPE wd_this->Elements_zcnr9_nodes_info,

    wa_zcnr9_nodes_info LIKE LINE OF it_zcnr9_nodes_info.

    DATA : lo_nd_zcnr9_qnnr_api TYPE REF TO if_wd_context_node,

    it_zcnr9_qnnr_api TYPE wd_this->Elements_zcnr9_qnnr_api,

    wa_zcnr9_qnnr_api LIKE LINE OF it_zcnr9_qnnr_api.

    DATA : lv_length_name TYPE i,

    lv_length_attr TYPE i,

    lv_diff TYPE i,

    lv_ques_name TYPE /rpm/ts_qnnr_api-QUESTION_ID,

    lv_str_attr TYPE string.

    * navigate from to via lead selection

    lo_nd_zcnr9_qnnr_api = wd_context->get_child_node( name = wd_this-

    >wdctx_zcnr9_qnnr_api ).

    lo_nd_zcnr9_qnnr_api-

    >get_static_attributes_table( importing table = it_zcnr9_qnnr_api ).

    * navigate from to via lead selection

    lo_nd_zcnr9_nodes_info = wd_context->get_child_node( name = wd_this-

    >wdctx_zcnr9_nodes_info ).

    lo_nd_zcnr9_nodes_info-

    >get_static_attributes_table( importing table = it_zcnr9_nodes_info ).

    LOOP AT it_zcnr9_nodes_info INTO wa_zcnr9_nodes_info.

    * check whether the Attribute ID prefixed in the Question Node name

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 29

    IF wa_zcnr9_nodes_info-zcar9_node_name CS wa_zcnr9_nodes_info-zcar9_attribute_id.

    lv_length_name = strlen( wa_zcnr9_nodes_info-zcar9_node_name ).

    lv_length_attr = strlen( wa_zcnr9_nodes_info-zcar9_attribute_id ).

    lv_diff = lv_length_name - lv_length_attr.

    lv_ques_name = wa_zcnr9_nodes_info-zcar9_node_name+lv_length_attr(lv_diff).

    else.

    lv_ques_name = wa_zcnr9_nodes_info-zcar9_node_name.

    ENDIF.

    ** check whether the question is mandatory

    READ TABLE it_zcnr9_qnnr_api INTO wa_zcnr9_qnnr_api WITH KEY question_id = wa_zcn

    r9_nodes_info-zcar9_node_name

    mandatory = abap_tr

    ue

    attribute_id = wa_z

    cnr9_nodes_info-zcar9_attribute_id.

    " Change to avoid mandatory check issue in Questionnaire

    IF sy-subrc eq 0.

    ** check whether the mandatory question is answered or not

    READ TABLE it_zcnr9_qnnr_api INTO wa_zcnr9_qnnr_api WITH KEY question_id = wa_z

    cnr9_nodes_info-zcar9_node_name- answered = abap_true

    attribute_id = wa_zcnr9_nodes_info-

    zcar9_attribute_id.

    IF sy-subrc ne 0.

    * get message manager

    DATA lo_api_controller type ref to if_wd_controller.

    DATA lo_message_manager type ref to if_wd_message_manager.

    DATA : lv_msg TYPE string,

    lv_msg_id TYPE string.

    lo_api_controller ?= wd_This->Wd_Get_Api( ).

    CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER

    RECEIVING

    MESSAGE_MANAGER = lo_message_manager.

    CONCATENATE 'Question' wa_zcnr9_qnnr_api-

    question_desc 'is mandatory' INTO lv_msg SEPARATED BY space.

    * report message

    CALL METHOD lo_message_manager->REPORT_ERROR_MESSAGE

    EXPORTING

    MESSAGE_TEXT = lv_msg

    RECEIVING

    MESSAGE_ID = lv_msg_id.

    ** set the flag

    rt_mandatory_ok = ' '.

    RETURN.

    ENDIF.

    ENDIF.

    ENDLOOP.

    rt_mandatory_ok = 'X'.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 30

    RETURN.

    endmethod.

    Set_changed – Questionnaire data depends on various factors. If any of these factors change we need to reload the questionnaire data on the screen. This method is used to notify such a change. Here goes the code:

    method SET_CHANGED .

    **set the changed indicator

    wd_this->m_changed = 'X'.

    endmethod.

    Here m_changed is the attribute in Component controller

    Result

    Create a Web Dynpro component ZTEST_REUSE and declare a usage for ZWCR9_QNNR_REUSE component.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 31

    Add a View Container element in its view MAIN.

    Add the ZWNR9_Window in the viewcontainer.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 32

    Create a node of Type /rpm/TS_QNNR_API in the component controller and bind it to the reusable component’s node.

    Get the questionnaire data and bind it to the VN_QNNR_API node.

    Login to PPM and go to any item’s overview. We need to do this to bring the item data in server context. As the FM /rpm/item_result_display reas the current item’s questionnaire data.

    Execute your test component’s application and the result should look like this:

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 33

    Disclaimer

    I would mention a few points about this article:

    1) It is one-way of creating questionnaire UI dynamically based on some data provided at run-time.

    2) This article explains the solution based on PPM 4.5 environment. You can tweak it to use it for your own purpose.

    3) The output UI color is different as it inherits my PPM portal theme.

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 34

    Related Content

    Dynamic Programming in Web Dynpro ABAP

    Supply Function Method Usage in WD ABAP

    Creating Dynamic UI elements and context Step by Step

    For more information, visit the Web Dynpro ABAP homepage

    http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2915http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2915http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/2915http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4468http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4468https://www.sdn.sap.com/irj/sdn/nw-wdabap

  • Creating a Reusable Questionnaire Component in WD ABAP for PPM

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    © 2010 SAP AG 35

    Disclaimer and Liability Notice

    This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.

    SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.

    SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.