Skip to Content
author's profile photo Former Member
Former Member

If statement within a view is not working correctly ?

Hi all,

maybe i am wrong but i think the if statement within a view is not working correctly. See code down below.

I would like to use the Hallo World depending on the page attribute isFrame with or without all the neccessary html tags. Therefore i have embedded the htmlb tags in an if statement. But for any reason if isframe is initial it isn't working. It would be great if anybody could help me.

<%@page language="abap"%>

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

<% if not isframe is initial. %>

<htmlb:content design="design2003">

<htmlb:page title = "Top Level Navigation view">

<% endif. %>

hallo world

<% if not isframe is initial. %>

</htmlb:page>

</htmlb:content>

<% endif. %>

thanks in advance and best regards

Matthias Hlubek

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    Posted on Jan 23, 2005 at 04:48 PM

    Matthias,

    The short answer: your example is <b>NOT</b> going to work. The long answer will probably 5 pages to describe. So first let me rewrite the example so that it could work, and then give a short version of the long answer. Do not be disappointed if it is not totally clear. It is rather complicated. (See the nice form of IF statements that are possible since 620.)

    <%@page language="abap"%>
    <%@extension name="htmlb" prefix="htmlb"%>
    <% if isframe is <b>NOT</b> initial. %>
    <htmlb:content design="design2003">
      <htmlb:page title = "Top Level Navigation view">
        hallo world
      </htmlb:page>
    </htmlb:content>
    <% else. %>
      hallo world
    <% endif. %>
    

    So why does your example not work? Let us start with a simple tag:

      <htmlb:page title = "Top Level Navigation view">
        ...
      </htmlb:page>
    

    Now, for each tag, we have effectively the opening part (<htmlb:page>), an optional body, and then the closing part (</htmlb:page>). We are now at the level of the BSP runtime processing one tag. What the runtime does not know, is whether the tag wants to process its body or not. Each tag can decide dynamically at runtime whether the body should be processed. So the BSP compiler generates the following code:

      DATA: tag TYPE REF TO cl_htmlb_page.
      CREATE OBJECT tag.
      tag->title = 'Top Level Navigation view'.
      IF tag->DO_AT_BEGINNING( ) = CONTINUE.
        ...
      ENDIF.
      tag->DO_AT_END( ).
    

    You should actually just debug your BSP code at ABAP level, and then you will immediately see all of this. Now, let us mix in your example with our code generation. First you simplified example:

    <% if isframe is NOT initial. %>
      <htmlb:page title = "Top Level Navigation view">
    <% endif. %>
      ...
    <% if isframe is NOT initial. %>
      </htmlb:page>
    <% endif. %>
    

    And then with our generated code. Look specifically at how the IF/ENDIF blocks suddenly match!

    if isframe is NOT initial.
      DATA: tag TYPE REF TO cl_htmlb_page.
      CREATE OBJECT tag.
      tag->title = 'Top Level Navigation view'.
      IF tag->DO_AT_BEGINNING( ) = CONTINUE.
    endif.
      ...
    if isframe is NOT initial.
      ENDIF.
      tag->DO_AT_END( ).
    endif.
    

    You can see that your ENDIF statements are closing IF blocks generated by the BSP compiler. Such a nesting will not work. This is a very short form of the problem, there are a number of variations, and different types of the same problem.

    The only way to solve this problem, is probably to put the body into a page fragment and include it like I did above with the duplicate HelloWorld strings. But this duplicates source code. Better is to put body onto a view, that can be processed as required.

    brian

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 07, 2005 at 04:17 PM

    Hi Matthias,

    you've made a typing error. You wrote "if not isframe is initial" twice.

    Nevertheless the HTML style is not really correct (but HTML is indulgent in your case).

    A better form would be:

    <%@page language="abap"%>
    <%@extension name="htmlb" prefix="htmlb"%>
    
    <htmlb:content design="design2003">
    
    <% if not isframe is initial. %>
    <htmlb:page title = "Top Level Navigation view">
    hallo world
    </htmlb:page>
    <% endif. %>
    
    </htmlb:content>
    

    This also takes care of the end-tags.

    Regards,

    Rainer

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 10, 2005 at 07:58 AM

    Hi Sebastian,

    I know that my code is different, but you can't write "Hello World" without any HTML tags. You need at least

    <html>
    <head>
    <title>Text des Titels</title>
    </head>
    <body>
    Hello World!
    </body>
    </html>
    

    Regards,

    Rainer

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Rainer,

      you are right. But my intention is to use that view depending on a flag differently.

      Either as a normal html page as you have describted it or as part of a html page (as a fragment).

      regards,

      Matthias

  • Posted on Jan 10, 2005 at 08:30 AM

    Hi Matthias,

    in this case you have to use page fragments. You can find an example in the application it00 with the name basic_include.htm.

    If you work with views the main view needs the content and page tags. There you can call other views depending on your if-statement.

    Regards,

    Rainer

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.