cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Table Creation in BSP for phtmlb dropdown list boxes

Former Member
0 Kudos

Hi All,

I am developing a survey BSP application that pulls in question data from Z tables R/3. One type of question is a dropdown list. For this you must populate a table with the possible answers (below it is t_dd_answers). This is all fine if the dropdown boxes are static as you just define you static number of tables required for the possible and the application will hold all of the values for you when you want to retreive them for further processing.

My issue is that depending on how the questions are configured in R/3 my BSP app does not know how many dropdown boxes there will be on the .htm

Is there a way to dynamically create n different internal tables to hold the possible answers, show them when the .htm is loaded and also be able to retreive the data when the user has made a choice and hit 'save' (or similar).

Code outline is:

<%

loop at t_dropdown into ....

wa_dd_answers-name = wa_dropdown-zansnum.

wa_dd_answers-value = wa_dropdown-zanswer.

append wa_dd_answers to t_dd_answers.

%>

<phtmlb:formLayoutDropDownListBox id = "<%=w_dd_name%>"

label = "<%=wa_questions-zquestxt%>"

table = "<%=t_dd_answers%>"

nameOfKeyColumn = "NAME"

nameOfValueColumn = "VALUE"/>

<%endloop.%>

Ideally I would like to dynamically create t_dd_answers, t_dd_answers1, t_dd_answers2, t_dd_answers3 etc as needed.

Many thanks!

Niall

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Thomas/All,

The use of a deep structure is an interesting one... but how do I fill the deep structure?! I have not worked much OO ABAP and cannot seem to get this to work through the use of work areas.

When I try to loop through the internal structure (as below) I get an error saying: '"wa_main_table-inner_table" is neither specified under "tables" or defined as an internal table'

loop at main_table into wa_main_table.

loop at wa_main_table-inner_table into wa_inner_table.

endloop.

endloop.

I know I am probably doing something silly here. I just cant see what! Any help is much appeciated.

Thanks,

Niall

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Actually deep structures have been around for a while. I remember using them for the first time back in 3.0D (1996).

But enough nistalga - let's get to the problem.

I'm interested to see how you declared your main_table defintion. That is probably where the problem lies. Your coding looks generally correct.

Here is a quick little example all done in-line in ABAP code. For your complex nest table, I would really suggest creating a table type in the data dictionary.


TYPES: t_sbook TYPE STANDARD TABLE OF sbook WITH NON-UNIQUE DEFAULT KEY.

TYPES BEGIN OF t_sflight.
INCLUDE TYPE sflight.
TYPES i_sbook TYPE t_sbook.
TYPES END OF t_sflight.

DATA: isflight TYPE TABLE OF t_sflight.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE isflight.

FIELD-SYMBOLS: <wa_sflight> LIKE LINE OF isflight.
FIELD-SYMBOLS: <wa_sbook> TYPE sbook.

LOOP AT isflight ASSIGNING <wa_sflight>.
  SELECT * FROM sbook INTO TABLE <wa_sflight>-i_sbook
   WHERE carrid = <wa_sflight>-carrid
     AND connid = <wa_sflight>-connid
     AND fldate = <wa_sflight>-fldate.
ENDLOOP.

LOOP AT isflight ASSIGNING <wa_sflight>.
  WRITE: / <wa_sflight>-carrid,
           <wa_sflight>-connid,
           <wa_sflight>-fldate.
  LOOP AT <wa_sflight>-i_sbook ASSIGNING <wa_sbook>.
    WRITE: /5 <wa_sbook>-bookid,
              <wa_sbook>-passname.
  ENDLOOP.
ENDLOOP.

Former Member
0 Kudos

Hi Thomas,

Solved!

I have it working. Thanks for all your input. I could get the deep structure working for regular ABAP ok (and have used them before) but not in the OO context.

You are totally correct - it was all down to my main_table definition. I had been staring at the issue for so long that I thought I had tried everything!

Your code above is a little more elegant than I have written but I will certainly try out your example in the future.

Thanks again,

Niall

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks to you all for the replies... I will try out some suggestions and let you know how I get on.

Cheers,

Niall

Former Member
0 Kudos

Hi Niall,

What u can do is u can dynamically supply some html drop-downs with ids listed in an internal table and later on u can retrieve the value selected.

In this way u can skip the use of dynamic internal tables.

If u want to know more about dynamic rendering of html elements check out the following link:

/people/brian.mckellar/blog/2003/10/30/bsp-programming-bsp-element-expressions-bees

Hope it'll help u.

Regards,

Ankur

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

On possibility would be to use a deep structure for your question internal table. For every record in your questions table, imbed another internal table with your dropdown values.

That way you would have the following:

table="<%= wa_questions-dd_answers %>"

That way you aren't try to dynamically create anything.

Former Member
0 Kudos

Hi Niall,

I think it's more appropriate for this thread to belong to the BSP forum. I'm moving it there, where you can expect to find more answers.

Regards,

Anand Mandalika.