Skip to Content
  • Create pointer to model<br>

  model ?= get_model( ‘mf’ ).

clear lt_data.

clear lt_table_cat.

clear lt_table_subject.

lt_data = model->GET_FAQ_DATA( ).

lt_table_cat = model->GET_FAQ_CAT( ).

lt_table_subject = model->GET_FAQ_SUBJECT( ).

if selectedRowIndex IS INITIAL.

selectedRowIndex = -1.

endif.

  • Data definitions<br>

  data: default_view type ref to if_bsp_page.

  • Create view<br>

  default_view = create_view( view_name = ‘obj/index.htm’ ).

default_view->set_attribute( name = ‘lv_data’

value = lt_data ).

default_view->set_attribute( name = ‘lv_table_cat’

value = lt_table_cat ).

default_view->set_attribute( name = ‘lv_table_subject’

value = lt_table_subject ).

default_view->set_attribute( name = ‘iterator’

value = me ).

default_view->set_attribute( name = ‘sri’

value = selectedRowIndex ).

default_view->set_attribute( name = ‘lv_id’

value = lt_id ).

default_view->set_attribute( name = ‘lv_edit’

value = lt_edit ).

default_view->set_attribute( name = ‘lv_visible’

value = lt_visible ).

default_view->set_attribute( name = ‘lv_short_desc’

value = lt_short_desc ).

default_view->set_attribute( name = ‘lv_long_desc’

value = lt_long_desc ).

default_view->set_attribute( name = ‘lv_author’

value = lt_author ).

default_view->set_attribute( name = ‘lv_cat’

value = lt_cat ).

default_view->set_attribute( name = ‘lv_cat_id’

value = lt_cat_id ).

default_view->set_attribute( name = ‘lv_rating’

value = lt_rating ).

default_view->set_attribute( name = ‘lv_rating_image’

value = lt_rating_image ).

default_view->set_attribute( name = ‘lv_subject’

value = lt_subject ).

default_view->set_attribute( name = ‘lv_subject_id’

value = lt_subject_id ).

default_view->set_attribute( name = ‘lv_title’

value = lt_title ).

default_view->set_attribute( name = ‘lv_url’

value = lt_url ).

  • Call view<br>

  call_view( default_view ).

endmethod.

 

DO_HANDLE_EVENT

>
method DO_HANDLE_EVENT .

  • Table Types<br>

  data: wa TYPE ZFAQ_DATA.

data: witab TYPE ZFAQ_DATA.

  • Object definitions<br>

  data: lt_event TYPE REF TO if_htmlb_data.

data: table TYPE REF TO CL_HTMLB_TABLEVIEW.

data: table_event TYPE REF TO cl_htmlb_event_tableview.

data: ddlb TYPE REF TO CL_HTMLB_DROPDOWNLISTBOX.

data: listbox TYPE REF TO CL_HTMLB_LISTBOX.

  • Data definitions<br>

  DATA: myCDate TYPE STRING.

method DO_REQUEST .

  • Create pointer to model

  model ?= get_model( ‘mf’ ).

  clear lt_data.

  clear lt_table_cat.

  clear lt_table_subject.

  lt_data = model->GET_FAQ_DATA( ).

  lt_table_cat = model->GET_FAQ_CAT( ).

  lt_table_subject = model->GET_FAQ_SUBJECT( ).

  if selectedRowIndex IS INITIAL.

    selectedRowIndex = -1.

  endif.

  • Data definitions

  data: default_view type ref to if_bsp_page.

  • Create view

  default_view = create_view( view_name = ‘obj/index.htm’ ).

  default_view->set_attribute( name = ‘lv_data’

                               value = lt_data ).

  default_view->set_attribute( name = ‘lv_table_cat’

                               value = lt_table_cat ).

  default_view->set_attribute( name = ‘lv_table_subject’

                               value = lt_table_subject ).

  default_view->set_attribute( name = ‘iterator’

                               value = me ).

  default_view->set_attribute( name = ‘sri’

                               value = selectedRowIndex ).

  default_view->set_attribute( name = ‘lv_id’

                               value = lt_id ).

  default_view->set_attribute( name = ‘lv_edit’

                               value = lt_edit ).

  default_view->set_attribute( name = ‘lv_visible’

                               value = lt_visible ).

  default_view->set_attribute( name = ‘lv_short_desc’

                               value = lt_short_desc ).

  default_view->set_attribute( name = ‘lv_long_desc’

                               value = lt_long_desc ).

  default_view->set_attribute( name = ‘lv_author’

                               value = lt_author ).

  default_view->set_attribute( name = ‘lv_cat’

                               value = lt_cat ).

  default_view->set_attribute( name = ‘lv_cat_id’

                               value = lt_cat_id ).

  default_view->set_attribute( name = ‘lv_rating’

                               value = lt_rating ).

  default_view->set_attribute( name = ‘lv_rating_image’

                               value = lt_rating_image ).

  default_view->set_attribute( name = ‘lv_subject’

                               value = lt_subject ).

  default_view->set_attribute( name = ‘lv_subject_id’

                               value = lt_subject_id ).

  default_view->set_attribute( name = ‘lv_title’

                               value = lt_title ).

  default_view->set_attribute( name = ‘lv_url’

                               value = lt_url ).

  • Call view

  call_view( default_view ).

endmethod.

method DO_HANDLE_EVENT .

  • Table Types

  data: wa TYPE ZFAQ_DATA.

  data: witab TYPE ZFAQ_DATA.

  • Object definitions

  data: lt_event TYPE REF TO if_htmlb_data.

  data: table TYPE REF TO CL_HTMLB_TABLEVIEW.

  data: table_event TYPE REF TO cl_htmlb_event_tableview.

  data: ddlb TYPE REF TO CL_HTMLB_DROPDOWNLISTBOX.

  data: listbox TYPE REF TO CL_HTMLB_LISTBOX.

  • Data definitions

  DATA: myCDate TYPE STRING.

  data: tmpID TYPE STRING.

  DATA: myCategory TYPE STRING.

  DATA: myRating TYPE STRING.

  DATA: tmpSubject TYPE i,

        mySubject TYPE STRING,

        mySubjects TYPE STRING.

  lt_event = cl_htmlb_manager=>get_event_ex( request ).

  if lt_event IS NOT INITIAL.

    table ?= CL_HTMLB_MANAGER=>GET_DATA( request = request

                                  name    = ‘tableView’

                                  id      = ‘index_faqdata’ ).

    if table IS NOT INITIAL.

      table_event = table->data.

      selectedRowIndex = table_event->SELECTEDROWINDEX.

      READ TABLE lt_data INTO witab INDEX selectedRowIndex.

      lt_cat = model->GET_CAT_NAME( id = witab-cat_id ).

      lt_rating_image = model->SHOW_RATING_IMAGE(

                                 value = witab-rating ).

      lt_ID = witab-id.

      myCDate = witab-cdate.

      lt_CAT_ID = witab-cat_id.

      lt_SUBJECT = witab-subject.

      lt_RATING =  witab-rating.

      lt_AUTHOR = witab-author.

      lt_TITLE = witab-title.

      lt_URL =  witab-url.

      lt_SHORT_DESC = witab-short_desc.

      lt_LONG_DESC = witab-long_desc.

    endif.

    CASE event.

      WHEN ‘addfaqform’.

        lt_visible = ‘addfaq’.

        lt_edit = ‘X’.

      WHEN ‘viewfaq’.

        lt_visible = ‘viewfaq’.

        lt_edit = ”.

      WHEN ‘canaddfaq’.

        lt_visible = ”.

        lt_edit = ”.

      WHEN ‘editfaq’.

        IF selectedRowIndex NE 0.

          lt_edit = ‘X’.

          lt_visible = ‘addfaq’.

        ENDIF.

      WHEN ‘addfaq’.

        CLEAR wa.

        ddlb ?= CL_HTMLB_MANAGER=>GET_DATA(

                          request = request

                          id = ‘index_faq_category’

                          name = ‘dropdownListBox’ ).

        myCategory = ddlb->selection.

        myRating = request->GET_FORM_FIELD( name = ‘index_faq_rating’ ).

        myRating = myRating+6(1).

        IF request->GET_FORM_FIELD( name = ‘index_id’ ) IS NOT INITIAL.

          tmpID = request->GET_FORM_FIELD( name = ‘index_id’ ).

        ENDIF.

        IF tmpID NE 0.

          wa-ID = request->GET_FORM_FIELD( name = ‘index_id’ ).

          wa-CDATE = myCDate.

          wa-CAT_ID = myCategory.

          wa-SUBJECT = request->GET_FORM_FIELD(

                            name = ‘index_faq_subject’ ).

          “* Get from radio group

          wa-RATING =  myRating.

          “* Get from form data

          wa-AUTHOR = request->GET_FORM_FIELD(

                            name = ‘index_faq_author’ ).

          wa-TITLE =  request->GET_FORM_FIELD(

                            name = ‘index_faq_title’ ).

          wa-URL =  request->GET_FORM_FIELD( name = ‘index_faq_url’ ).

          wa-SHORT_DESC =  request->GET_FORM_FIELD(

                            name = ‘index_faq_short_desc’ ).

          wa-LONG_DESC =  request->GET_FORM_FIELD(

                            name = ‘index_faq_long_desc’ ).

          UPDATE ZFAQ_DATA FROM wa.

        ELSE.

          listbox ?= CL_HTMLB_MANAGER=>GET_DATA(

                            request = request

                            id = ‘index_faq_subject’

                            name = ‘listBox’ ).

          CLEAR mySubjects.

          LOOP AT listbox->selections INTO mySubject.

            tmpSubject = mySubject.

            mySubject = model->GET_SUBJECT_NAME( id = tmpSubject ).

            CONCATENATE

              mySubject

              mySubjects

            INTO mySubjects SEPARATED BY ‘,’.

          ENDLOOP.

          wa-ID = model->GET_NEXT_DATA_ID( table = ‘ZFAQ_DATA’ ).

          wa-CDATE =  SY-DATUM.

          “* Get from select list

          wa-CAT_ID = myCategory.

          wa-SUBJECT = mySubjects.

          “* Get from radio group

          wa-RATING =  myRating.

          “* Get from form data

          wa-AUTHOR = request->GET_FORM_FIELD(

                                name = ‘index_faq_author’ ).

          wa-TITLE =  request->GET_FORM_FIELD(

                                name = ‘index_faq_title’ ).

          wa-URL =  request->GET_FORM_FIELD( name = ‘index_faq_url’ ).

          wa-SHORT_DESC =  request->GET_FORM_FIELD(

                                name = ‘index_faq_short_desc’ ).

          wa-LONG_DESC =  request->GET_FORM_FIELD(

                                name = ‘index_faq_long_desc’ ).

          INSERT INTO ZFAQ_DATA VALUES wa.

        ENDIF.

        lt_data = model->GET_FAQ_DATA( ).

        lt_edit = ”.

        lt_visible = ”.

      WHEN ‘delfaq’.

        IF selectedRowIndex NE 0.

          READ TABLE lt_data INTO witab index selectedRowIndex.

          DELETE FROM ZFAQ_DATA WHERE ID = witab-id.

          selectedRowIndex = 0.

          lt_data = model->GET_FAQ_DATA( ).

          lt_edit = ”.

          lt_visible = ”.

        ENDIF.

    ENDCASE.

  endif.

endmethod.

Now you might have noticed that in the Iterator methods I have a reference to “obj”, this was the class we used in the first series, those of you who do not have the class anymore or who do not participate in the first series you will need to change it to read the

Model

method instead. The reason for this is to show that you are able to use multiple different classes and call them in multiple different ways.

So with that all said and done I am happy to announce that your fingers can take a short break as we are now done with the majority of the programming and logic. The rest is mainly layout and understanding.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply