cancel
Showing results for 
Search instead for 
Did you mean: 

Hiding a table column for a particular condition

Sougata
Active Contributor
0 Kudos

Hello,

I have defined a table (flowed) with 7 columns. I want to hide the 6th column (type Decimal field) completely if a condition is True. This condition is passed to the Form from an ABAP program as an import parameter of the Form Interface.

I've written a FormCalc Script on that particular column cell which is:

if ( $.rawValue == null or $.rawValue == "" ) then
  $.presence = "hidden";
endif

This works fine except the column header is still displayed on the form as a result the format of the table has gone wrong and it looks weird.

Last column header "Advertised" should be shifted left to replace the 6th column header - As you can see the values of the 6th column are hidden but the column header is still displayed. I was unable to put any script on the column header as it is a type Text field.

Has anyone had a similar problem like this in the past? I know I can use Alternatives->True/False in the form context but I don't want to go there if there is something simple which I'm missing. Any ideas?

Thanks!

Sougata.

Accepted Solutions (1)

Accepted Solutions (1)

Sougata
Active Contributor
0 Kudos

This is how I solved it:

1. Declare a boolean variable in the form interface and flag it true or false depending on whether the condition was met or not in the Code Initialization of the form. Example code below:

DATA:
  ls_items TYPE zlo_s_promo_item.

LOOP AT it_promo_items INTO ls_items
  WHERE prom_sell_price IS NOT INITIAL.
  EXIT.
ENDLOOP.

lv_psell_flag = boolc( sy-subrc IS NOT INITIAL ).

2. Define the column header as Text Field then bind it to the boolean variable declared in step 1. FormCalc script for the column header should be as under:

if ( $.rawValue == "X" ) then

$.presence = "hidden";

endif

3. The FormCalc script for the column value (defined as Decimal field in my case) should be as under:

if ( $.rawValue == null or $.rawValue == "" or $.rawValue == 0.00 ) then

  $.presence = "hidden";

endif

Result is the entire column (including the column header) is displayed or hidden depending on the value of the boolean variable.

Hope this helps someone in future who might be stuck at a similar issue.

Cheers,

Sougata.

Sougata
Active Contributor
0 Kudos

Continued to have the same problem that Formcalc script did not work from page 2 onwards.

The right way to go about this is to create an Alternative in the Context of the data table then set the Alternate Condition via a variable which is set at the Code Initialization event of the form Interface. Within the Alternative we can then Deactivate the required columns within the True & False condition.

The approach to insert client side scripting on a table column header in order to hide it is incorrect and thus should be avoided.

Note that steps 2 & 3 of the above post should be avoided - Step 1 is however required to make the Alternative work.

Former Member
0 Kudos

Hello Sougata,

can you please explain more detailled how you did that? Especially how you can deactivate the columns within the True&False condition. My problem is that the headerline hasat just text an no binded data so I cannot make any conditions to them in the context. I tried to use the true path in the hierachie of the layout, this is a bad idea, the field was printet when it shouldn't be printet and whe it should be printet I got ten or more headerlines. Can anyone give me some advise?

Thanks,

Marco

Sougata
Active Contributor
0 Kudos

Marco,

In the Context open the Alternative node then open the TRUE node....keep opening till you get to the fields of the structure. Then right click on the field that you don't want to print and choose Deactivate.

Cheers,

Sougata.

Former Member
0 Kudos

In my case, this wasn't necessary. It works when I create 2 subforms one with the field one without the field, both are visible and with FormCalc I make one invisible depending on the variable. I tested it with 7 sites and it worked so far.

Thanks and a nice weekend

former_member195669
Discoverer
0 Kudos

Hello Sougata,

I have a requirement to hide all the columns who has no value in it including the column header.

For example, I would like to hide three columns Customer material, unit and Price.

Column width should be adjusted accordingly.

        Item

MaterialMaterial desc

Customer

Material

QuantityUnitPricePrice in USD
10MAT1Material12200
20MAT2Material13300
30MAT3Material14400

BR//Tirumal

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Sougata,

Can you try moving the column header which you dont want to be displayed inside a subform and write the below script in the subform.

$.presence = "hidden"

if ( Exists(Column_Name) eq 1) then

$.presence = 'visible'

endif.

Regards,

Sanjeev.

sandeep_katoch
Contributor
0 Kudos

Hi Sougata,

You can easily put a script in a text field. But yes if it is a normal text only then you cant put any script.

change it to a text field from library and put a script there.

BR,

Sandeep Katoch

Sougata
Active Contributor
0 Kudos

Hi Sandeep,

Thanks for your help. It works...I'm able to hide the header row but now the column appears with blank value from page 2 onwards. In other words the FormCalc script for the value cell does not work from subsequent page onwards. The script for the header works fine for all pages when I changed it to Text field from library as you had suggested.

Any idea how to make it work on all pages?

Sougata.

sandeep_katoch
Contributor
0 Kudos

Hi Sougata,

Write the script in form ready or layout ready or initialization event and it will do the needful for you.

Try with any one of them and I hope it will work.

BR,

Sandeep Katoch

Sougata
Active Contributor
0 Kudos

Tried all the three events but the result is the same - it doesn't work from page 2 onwards.

Sougata.

sandeep_katoch
Contributor
0 Kudos

Hi Sougata,

Are you using subform as table or simple table.

If you are using subform as table then you need to put script at both header level and at details level.

Try putting the script at details level also.

PS : For more details refer to this thread

http://scn.sap.com/thread/1694807

BR,

Sandeep Katoch

Sougata
Active Contributor
0 Kudos

Doesn't work. I read the link you had sent me - I can't see anything wrong with my script but I can't make the table as part of Master Pages. The table is perfectly fine on page 1 but the script fails from page 2 onwards. Its a simple table, its not wrapped in a Subform. Any idea what is going wrong in subsequent pages?

Sougata.

sandeep_katoch
Contributor
0 Kudos

That is why it is giving a problem.

If it is not wrapped inside a subform then you need to put a script explicitly on each page and on every table row.

Best practice is to wrap the table inside a subform and make the subform as flowed. All the properties of parent are by default applied to consequent pages.

BR,

Sandeep Katoch