简体   繁体   English

如何在 SALV 表上调用 remove_column?

[英]How to call remove_column on SALV table?

I want to execute the method remove_column on an instance of cl_salv_column_table but because of its visibility level, I am not able to do so.我想在cl_salv_column_table的实例上执行remove_column方法,但由于其可见性级别,我无法这样做。


Plan:计划:

I already tried inheriting from cl_salv_columns_list and then perform the call inside the remove -method:我已经尝试从cl_salv_columns_list继承,然后在remove -method 中执行调用:

CLASS lcl_columns_list DEFINITION INHERITING FROM CL_SALV_COLUMNS_LIST.
    PUBLIC SECTION.
    METHODS:
        remove IMPORTING iw_colname TYPE string.
ENDCLASS.

But apparently my casting knowledge got rusty as I'm not able to figure out an appropriate solution.但显然我的铸造知识变得生疏,因为我无法找到合适的解决方案。

This is my current hierarchy - the red arrows show the way I would have to take:这是我当前的层次结构 - 红色箭头显示了我必须采取的方式:

在此处输入图片说明

My approach looks like this:我的方法是这样的:

DATA lo_column_list TYPE REF TO lcl_columns_list.
lo_column_list ?= CAST cl_salv_columns_list( lo_columns ).

But it fails with:但它失败了:

 CX_SY_MOVE_CAST_ERROR Source type: \\CLASS=CL_SALV_COLUMNS_TABLE Target type: "\\PROGRAM=XXX\\CLASS=LCL_COLUMNS_LIST"

Background:背景:

My task is to select all columns of 3 tables (which would be done like SELECT t1~*, t2~*, t3~* ... ) as long as their names don't conflict (eg field MANDT should only be displayed once).我的任务是选择 3 个表的所有列(这将像SELECT t1~*, t2~*, t3~* ... )只要它们的名称不冲突(例如字段MANDT应该只显示一次)。 This would require defining a very big structure and kick the size of the selection list to a maximum.这将需要定义一个非常大的结构并将选择列表的大小最大化。

To avoid this, I wanted to make use of the type generated by my inline-declaration.为了避免这种情况,我想利用我的内联声明生成的类型。 Hiding the individual columns via set_visible( abap_false ) would still display them in the layout manager - which looks really ugly.通过set_visible( abap_false )隐藏各个列仍会在布局管理器中显示它们 - 这看起来非常难看。

Is there any other way to accomplish my target?有没有其他方法可以实现我的目标?

Use set_technical( abap_true ) to hide the columns entirely.使用set_technical( abap_true )完全隐藏列。 As for your approach - sorry, inheritance does not work that way - in no statically typed object oriented language that I know.至于你的方法 - 抱歉,继承不能那样工作 - 在我知道的没有静态类型的面向对象语言中。 You can't 'recast' an instantiated object to a different class.您不能将实例化的对象“重铸”到不同的类。 You would need to modify the framework extensively to support that.您需要广泛修改框架以支持这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM