Skip to Content

|  |

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>

To report this post you need to login first.

17 Comments

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

  1. Eddy De Clercq
    Hi,

    A suggestion from my side would be using a more X platform editor like TinyMCE (see also Eazy az 1-2-3) which is already used for the SDN wiki. I’m still hoping that this editor will also be used for creating SDN web logs.

    Eddy

    (0) 
    1. Thomas Jung
      If you want an open alternative to the BTF editor you might take Eddy’s advice and look at TinyMCE.  I have also played around with FCKeditor.  I have an implementation that is wrapped inside a BSP Extension if you are interested.

      Thanks for sharing you sample, but you might also want to consider delivering it in SAPLink format.

      (0) 
      1. Ignacio Hernández Post author
        Thomas, thanks for your comment. I appreciate a lot the quality of your work. I am beginning to use SAPLink, of course, we can expect a Saplink version of ZWIKI, thanks again, Ignacio.
        (0) 
    2. Ignacio Hernández Post author
      Thanks Eddy, my first approach was to use standard tools that I found in Abap stack, I appreciate your recomendation, I’m going to go inside it.
      (0) 
  2. Daniel McWeeney
    Can’t see it from your screen shots as there is no URL bar, but normally wikis are addressable just by the URL, looks like you are using a INT4 for the page ID it would be great if you could do:
    http://appserver/zwiki/Name_Of_Page

    If you are already doing that cool, if not someone from the community could easily add it.  Set up a Google Code project and let’s help out.
    -d

    (0) 
  3. James Kidd
    Nice blog. 
    Question:  Is there a quick fix to prevent a short dump when using the text editor file upload function?

    Thanks

    (0) 
      1. Durairaj Athavan Raja
        to avoid dump do the following

        in the oninputprocessing of the bsp do a find and replce with the following

        find string: if event

        replace string : if not event is initial and event

        However there is some bug which doesnt show the uploaded file in the editor will fix that and post the code in the wiki page

        (0) 
  4. Rashid Javed
    It is really a very nice and detailed blog and the idea is cool to develop a tool inside SAP to communicate data with Wiki.
    However I do suggest to just describe a little bit more about the application at the start of your blog. Currently we just have “Open source wiki application written in Abap.” and right after that there is a series of screen shot and steps that keep the reader guessing what actually will it turn out to be. So just a little bit description at the start(about what the application is) will help build interest. Just a suggestion 🙂
    (0) 

Leave a Reply