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

How to dynamically modify the style of a given column in my internal table

Hi, I'm trying to dynamically modify a column of an internal table.

I'm using field-symbols for that.

The column I want to modify is called tabstyle (it's also a table)

I'm trying to modify a specific line of this table.

(The aim is to have a dynamic way to disable a cell in my ALV)

- Get the correct line of the table: ok

- Get the component 'TABSTYLE' of this line : OK

- Add 'disabled' in tabstyle : OK

The remaining problem is : I cannot modify the internal table with the new TABSTYLE

I get the error "<table> has no structure and therefore no component called tabstyle"

when I try do to <table>-tabstyle = <tabstyle>

However, the instruction

ASSIGN COMPONENT 'TABSTYLE' OF STRUCTURE <table> TO <tabstyle>.

worked....

So.... If anyone could have a look at my code and help I d be really glad !

Thanks !

JC

cell to be disabled : CHAMP TYPE LVC_FNAME

line number in ALV : LIGNE TYPE I

table for ALV : P_REFERENCE TYPE STANDARD TABLE

METHOD griser.

FIELD-SYMBOLS <table_reference> TYPE STANDARD TABLE.
ASSIGN p_reference TO <table_reference>.
FIELD-SYMBOLS <tabstyle> TYPE lvc_t_styl.
FIELD-SYMBOLS <style> TYPE lvc_s_styl.
FIELD-SYMBOLS <fieldname> TYPE lvc_fname.
DATA tabstyle TYPE lvc_t_styl.

field-SYMBOLS <table_reference_fields> type any.
data gs_fldname type ref to data.
create data gs_fldname like line of <table_reference>.
assign gs_fldname->* to <table_reference_fields>.

" Get the line that I want to modify in my internal table
READ TABLE <table_reference> ASSIGNING <table_reference_fields> INDEX ligne.

" Check if the line is found at this index
CHECK <table_reference_fields> IS ASSIGNED.

" Tabstyle to be modified

ASSIGN COMPONENT 'TABSTYLE' OF STRUCTURE <table_reference_fields> TO <tabstyle>.

CHECK <tabstyle> IS ASSIGNED.

" Remove everything related to 'champ' in <tabstyle>

" delete <tabstyle> where fieldname = champ was NOT allowed

LOOP AT <tabstyle> ASSIGNING <style>.
ASSIGN COMPONENT 'FIELDNAME' OF STRUCTURE <style> TO <fieldname>.
IF <fieldname> NE champ.
APPEND <style> TO tabstyle.
ENDIF.
ENDLOOP.

" Disable the cell (that's the aim of this method)
DATA s_stylerow TYPE lvc_s_styl.
s_stylerow-fieldname = champ.
s_stylerow-style = mc_style_disabled.
INSERT s_stylerow INTO TABLE tabstyle.

" Try to alter the internal table... and doesnt really work

ASSIGN tabstyle TO <tabstyle>. "ok but not really useful
MOVE tabstyle to <tabstyle>. "ok but not really useful

<table_reference_fields>-tabstyle = tabstyle. " doesnt work....

modify <table_reference_fields>-tabstyle from tabstyle. " Doesnt work...

modify <table_reference> from <table_reference_fields> index ligne. " 'overwritten protected field'..

ENDMETHOD.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 14, 2012 at 10:20 AM

    Hi,

    Not sure I'm getting this properly but I don't really understand the use of table tabstyle here:

    Could it be done this way?...

    LOOP AT <tabstyle> ASSIGNING <style>.

    ASSIGN COMPONENT 'FIELDNAME' OF STRUCTURE <style> TO <fieldname>.

    "IF <fieldname> NE champ.

    " APPEND <style> TO tabstyle.

    "ENDIF.

    IF <fieldname> EQ champ.

    ASSIGN COMPONENT 'STYLE' OF STRUCTURE <style> TO <s>.

    <s>-style = mc_style_disabled.

    ENDIF.

    ENDLOOP.

    " Disable the cell (that's the aim of this method)
    " DATA s_stylerow TYPE lvc_s_styl.
    " s_stylerow-fieldname = champ.
    " s_stylerow-style = mc_style_disabled.
    " INSERT s_stylerow INTO TABLE tabstyle.

    Then, you don't have to alter the tabstyle table after your loop, no?

    Otherwise maybe you could try with this assignment:

    <tabstyle>[] = tabstyle[].

    Cheers,

    Manu.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 14, 2012 at 12:17 PM

    modify <table_reference> from <table_reference_fields> index ligne. " 'overwritten protected

    P_REFERENCE should be defined as CHANGING parameter, only then method can modify the content of it.

        METHODS : griser IMPORTING champ TYPE lvc_fname            "field
    ligne TYPE i "line number in alv
    CHANGING p_reference TYPE STANDARD TABLE. "table for ALV

    Now try this code

        FIELD-SYMBOLS <table_reference>  TYPE STANDARD TABLE.
    ASSIGN p_reference TO <table_reference>.

    FIELD-SYMBOLS <tabstyle> TYPE lvc_t_styl.
    FIELD-SYMBOLS <style> TYPE lvc_s_styl.
    FIELD-SYMBOLS <fieldname> TYPE lvc_fname.
    DATA tabstyle TYPE lvc_t_styl.

    FIELD-SYMBOLS <table_reference_fields> TYPE ANY.
    DATA gs_fldname TYPE REF TO data.
    CREATE DATA gs_fldname LIKE LINE OF <table_reference>.
    ASSIGN gs_fldname->* TO <table_reference_fields>.


    " Get the line that I want to modify in my internal table
    READ TABLE <table_reference> ASSIGNING <table_reference_fields> INDEX ligne.


    " Check if the line is found at this index
    CHECK <table_reference_fields> IS ASSIGNED.

    " Tabstyle to be modified

    ASSIGN COMPONENT 'TABSTYLE' OF STRUCTURE <table_reference_fields> TO <tabstyle>.

    CHECK <tabstyle> IS ASSIGNED.
    DATA ls_style TYPE lvc_s_styl .
    ls_style-fieldname = champ .

    READ TABLE <tabstyle> FROM ls_style ASSIGNING <style>.
    IF <style> IS ASSIGNED .
    ELSE.
    INSERT ls_style INTO <tabstyle> INDEX sy-tabix.
    READ TABLE <tabstyle> ASSIGNING <style> INDEX sy-tabix.
    ENDIF.

    <style>-style = cl_gui_alv_grid=>mc_style_disabled.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Pawan Kesari

      I agree with you. It SHOULD work this way. Actually, it's not.

      If I do smthg like this :

      ASSIGN COMPONENT 'TABSTYLE' OF STRUCTURE <table_reference_fields> TO <tabstyle>.

      CLEAR <tabstyle>.

      ==> <tabstyle> is cleared

      ==> <table_reference_fields>-tabstyle is NOT cleared

      ==> <table_reference_fields>-tabstyle says "<table_reference_fields> has no structure and thereforce no component called tabstyle"

      So.... no way to modify <table_reference_fields>-tabstyle ?

      Thx

      JC

  • Posted on May 14, 2012 at 07:33 PM

    Hi,

    most important is a REFRESH of the ALV display, otherwise no change to style, content or color will take effect.

    Post relevant code lines: Grid construction (ALV/SALV/FM), table modification, display refresh.

    Regards

    Clemens

    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.