Currently Being Moderated

|  |

Wiki application written in Abap.

 

 

 

 

 

WIKI PAGE

https://wiki.sdn.sap.com/wiki/x/8G0

 

TUTORIAL

Create these entities in data dictionary:

 

image

 

image

 

image

 

 

Create a function group (proposed name ZWIKI ), with these functions:

 

ZWIKI_PAGE_CREATE

FUNCTION zwiki_page_create.

*"----

-


""Interfase local

*"  IMPORTING

*"     REFERENCE(IM_PAGEID) TYPE  INT4

*"     REFERENCE(IM_VERSION) TYPE  INT4

*"     REFERENCE(IM_FATHER) TYPE  INT4

*"     REFERENCE(IM_DESCRIPTION) TYPE  CHAR50

*"     REFERENCE(IM_DOC) TYPE  XSTRING

*"     REFERENCE(IM_NEWPAGE) TYPE  CHAR1

*"  EXPORTING

*"     REFERENCE(EX_PAGEID) TYPE  INT4

*"     REFERENCE(EX_VERSION) TYPE  INT4

*"----

-


 

  DATA: wa_zwiki_pages TYPE zwiki_pages,

        max_pagid      TYPE int4,

        max_version    TYPE int4.

 

  CLEAR max_pagid.

  CLEAR max_version.

  CLEAR wa_zwiki_pages.

 

  wa_zwiki_pages-father       = im_father.

  wa_zwiki_pages-description  = im_description.

  wa_zwiki_pages-usr          = sy-uname.

  GET TIME STAMP FIELD wa_zwiki_pages-timestamp.

  wa_zwiki_pages-doc          = im_doc.

 

  IF im_newpage EQ 'X'.

 

    SELECT SINGLE MAX( pageid ) FROM zwiki_pages

                                INTO max_pagid.

 

    wa_zwiki_pages-pageid = max_pagid + 1.

    wa_zwiki_pages-version = 1.

 

  ELSE.

 

    wa_zwiki_pages-pageid = im_pageid.

 

    SELECT SINGLE MAX( version ) FROM zwiki_pages

                                 INTO max_version

                                 WHERE pageid = im_pageid.

 

    wa_zwiki_pages-version = max_version + 1.

 

  ENDIF.

 

  INSERT zwiki_pages FROM wa_zwiki_pages.

 

  ex_pageid  = wa_zwiki_pages-pageid.

  ex_version = wa_zwiki_pages-version.

 

ENDFUNCTION.

 

 

ZWIKI_PAGE_DISPLAY

FUNCTION zwiki_page_display.

*"----

-


""Local Interface:

*"  IMPORTING

*"     REFERENCE(IM_PAGEID) TYPE  INT4

*"     REFERENCE(IM_VERSION) TYPE  INT4

*"     REFERENCE(IM_LASTVERSION) TYPE  CHAR1

*"  EXPORTING

*"     REFERENCE(EX_MAXVERSION) TYPE  INT4

*"     REFERENCE(EX_WIKI_PAGE) TYPE  ZWIKI_PAGES

*"     REFERENCE(T_CHILD_PAGES) TYPE  ZWIKI_CHILD_LIST_TAB

*"----

-


 

  DATA: max_version TYPE int4.

 

  IF im_lastversion EQ 'X'.

 

    SELECT SINGLE MAX( version )

                  FROM zwiki_pages

                  INTO max_version

                  WHERE pageid = im_pageid.

 

    SELECT SINGLE * FROM zwiki_pages

             INTO ex_wiki_page

             WHERE pageid  = im_pageid AND

                   version = max_version.

 

    ex_maxversion = max_version.

 

  ELSE.

 

    SELECT SINGLE * FROM zwiki_pages

             INTO ex_wiki_page

             WHERE pageid  = im_pageid AND

                   version = im_version.

 

  ENDIF.

 

  SELECT description pageid FROM zwiki_pages

                            INTO TABLE t_child_pages

                            WHERE father = im_pageid AND

                                  version = 1

                                  ORDER BY description.

 

ENDFUNCTION.

 

 

Create a bsp application (proposed name ZWIKI), with a page with flow logic (proposed name zwiki.htm) and set the status (in Properties tab ) "Stateful from now On. Lifetime : Session".

 

Set atrributes to page

image

 

Page Layout<br /><textarea cols="90" rows="20"><%@page language="abap" %>

<%@extension name="htmlb" prefix="htmlb" %>

<%@extension name="btf" prefix="btf" %>

<htmlb:content design="design2003" >

  <htmlb:page title=" " >

    <htmlb:form id           = "myFormId"

                method       = "post"

                encodingType = "multipart/form-data" >

      <%

  IF newpage EQ 'X' or zwiki-pageid GT 0.

      %>

      <htmlb:group id="document" >

        <htmlb:groupHeader>

          <htmlb:inputField id    = "description"

                            width = "25%"

                            value = "<%= zwiki-description %> ">

          <htmlb:image id      = "F_SAVE"

                       src="/sap/public/bsp/sap/public/bc/icons/s_F_SAVE.gif" mce_src="/sap/public/bsp/sap/public/bc/icons/s_F_SAVE.gif"

                       onClick = "F_SAVE"

                       tooltip = "Save">

          <htmlb:image id      = "F_BACK"

                       src="/sap/public/bsp/sap/public/bc/icons/s_F_BACK.gif" mce_src="/sap/public/bsp/sap/public/bc/icons/s_F_BACK.gif"

                       onClick = "F_BACK"

                       tooltip = "Back">

          <htmlb:image id      = "F_ENDT"

                       src="/sap/public/bsp/sap/public/bc/icons/s_F_ENDT.gif" mce_src="/sap/public/bsp/sap/public/bc/icons/s_F_ENDT.gif"

                       onClick = "F_ENDT"

                       tooltip = "Home">

        </htmlb:groupHeader>

        <htmlb:groupBody>

          <btf:editor id       = "btf1"

                      width    = "100%"

                      document = "<%= s_documentdata-btf_doc %>">

        </htmlb:groupBody>

      </htmlb:group>

      <%

  ENDIF.

  IF newpage NE 'X'.

      %>

      <htmlb:group id     = "kids"

                   height = "100%"

                   design = "SECONDARYBOXCOLOR" >

        <htmlb:groupHeader>

          <htmlb:image id      = "B_INSR"

                       src="/sap/public/bsp/sap/public/bc/icons/s_B_INSR.gif" mce_src="/sap/public/bsp/sap/public/bc/icons/s_B_INSR.gif"

                       onClick = "B_INSR"

                       tooltip = "Add Page">

          <htmlb:label text   = "Add Page"

                       design = "EMPHASIZED"

                       for    = " ">

        </htmlb:groupHeader>

        <htmlb:groupBody>

          <htmlb:tableView id                  = "table"

                           columnHeaderVisible = "false"

                           visibleRowCount     = "25"

                           fillUpEmptyRows     = "false"

                           emptyTableText      = "New Page"

                           onRowSelection      = "TABLE"

                           selectionMode       = "SINGLESELECT"

                           width               = "100%"

                           table               = "<%= t_child_pages %>"

                           iterator            = "<%= tv_iterator %>" >

            <htmlb:tableViewColumns>

              <htmlb:tableViewColumn columnName = "description"

                                     width      = "100%">

              <htmlb:tableViewColumn columnName = "pagid"

                                     width      = "0%">

            </htmlb:tableViewColumns>

          </htmlb:tableView>

        </htmlb:groupBody>

      </htmlb:group>

      <%

  ENDIF.

      %>

    </htmlb:form>

  </htmlb:page>

</htmlb:content>

</textarea><br /><br />OnInitialization event handler code

IF s_documentdata-btf_doc IS INITIAL.   DATA: btf TYPE REF TO if_btf.   DATA: document TYPE REF TO if_btf_document.   btf = cl_btf=>get_reference( ).   DATA: l_exception TYPE REF TO cx_btf_runtime_error,         lp_exception TYPE REF TO cx_btf_parameter_error.   TRY.       document = btf->create_document( sy-langu ).     CATCH cx_btf_runtime_error INTO l_exception.   ENDTRY.   s_documentdata-btf_doc = document.   zwiki-pageid = 0.   zwiki-version = 0.   zwiki-father = 0.   zwiki-description = ''.   newpage = ''.   CALL FUNCTION 'ZWIKI_PAGE_DISPLAY'     EXPORTING       im_pageid            = zwiki-pageid       im_version           = zwiki-version       im_lastversion       = ''    IMPORTING        t_child_pages        = t_child_pages.   . ENDIF.

 

 

and OnInputProcessing event handler code

DATA: event TYPE REF TO cl_htmlb_event.  event = cl_htmlb_manager=>get_event( runtime->server->request ).  IF event->id = 'B_INSR'.    zwiki-version = 0.    zwiki-father = zwiki-pageid.    zwiki-pageid = 0.    zwiki-description = ''.    zwiki-doc = ''.    newpage = 'X'.  ELSE.    IF event->id = 'F_SAVE'.      DATA text TYPE xstring.      DATA encoding TYPE string.      DATA language TYPE tdspras.      DATA: cl_description TYPE REF TO cl_htmlb_inputfield.      cl_description ?= cl_htmlb_manager=>get_data(                      request = runtime->server->request                      name    = 'inputField'                      id    = 'description').      DATA: editor TYPE REF TO cl_btf_bsp_editor.      editor ?= cl_btf_bsp_manager=>get_data( request = request                                              name     = 'editor'                                              id       = 'btf1' ).      editor->document->get_content(        IMPORTING text = text        encoding = encoding        language = language ).      zwiki-description = cl_description->value.      CALL FUNCTION 'ZWIKI_PAGE_CREATE'        EXPORTING          im_pageid      = zwiki-pageid          im_version     = zwiki-version          im_father      = zwiki-father          im_description = zwiki-description          im_doc         = text          im_newpage     = newpage        IMPORTING          ex_pageid      = zwiki-pageid          ex_version     = zwiki-version.      newpage = ''.    ENDIF.    IF event->id = 'F_BACK'.      zwiki-pageid = zwiki-father.      zwiki-version = 0.      newpage = ''.    ENDIF.    IF event->id = 'F_ENDT'.      zwiki-pageid = 0.      zwiki-version = 0.      zwiki-father = 0.      zwiki-description = ''.      newpage = ''.    ENDIF.    IF event->id = 'table'.      DATA: tv TYPE REF TO cl_htmlb_tableview.      DATA value TYPE string.      zwiki-pageid = 0.      tv ?= cl_htmlb_manager=>get_data(                              request      = runtime->server->request                              name         = 'tableView'                              id           = 'table' ).      IF tv IS NOT INITIAL.        DATA: tv_data TYPE REF TO cl_htmlb_event_tableview.        tv_data = tv->data.        IF tv_data->selectedrowindex IS NOT INITIAL.          DATA: wat_child_pages LIKE LINE OF t_child_pages.          READ TABLE t_child_pages INDEX tv_data->

selectedrowindex INTO

wat_child_pages.

          zwiki-pageid = wat_child_pages-pageid.

 

        ENDIF.

      ENDIF.

 

 

      zwiki-version = 0.

      zwiki-father = 0.

      zwiki-description = ''.

      newpage = ''.

    ENDIF.

 

    CALL FUNCTION 'ZWIKI_PAGE_DISPLAY'

    EXPORTING

      im_pageid            = zwiki-pageid

      im_version           = zwiki-version

      im_lastversion       = 'X'

     IMPORTING

  •       EX_MAXVERSION        = zwiki

     ex_wiki_page         = zwiki

     t_child_pages        = t_child_pages.

  ENDIF.

 

  s_documentdata-btf_doc->set_content(

EXPORTING text = zwiki-doc

encoding = encoding

clean = 1 ).

 

 

 

THAT'S ALL !!!

 

Running the application you can add a new page or edit an existing one.

 

image

 

inside the page you can use the text editor, or add a new nested page inside...not levels restrictions!

 

!https://weblogs.sdn.sap.com/weblogs/images/251678771/06-img03.JPG|height=384|alt=image|width=512|src=https://weblogs.sdn.sap.com/weblogs/images/251678771/06-img03.JPG|border=0!</body>

Comments