Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

 

12 REPLIES 12

Former Member
0 Kudos

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.

 

0 Kudos

Hi.

I dont always have a line with FIELDNAME = CHAMP in my tabstyle

I want to :

1) Remove every line with fieldname = champ in tabstyle (in case it exists)

2) Add the correct line with fieldname = champ

But I CANNOT write : DELETE .... from <...>

The following code just do this "delete".

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

After that, <tabstyle> is modified, but not <table_reference_fields>-tabstyle

why, and how can I achieve this ?

Hope it is clearer.

Thx

JC

0 Kudos

I see your point now... But Did you tried what I suggested?

Instead of doing ASSIGN tabstyle TO <tabstyle> after your loop, just do:

<tabstyle>[] = tabstyle[].

Manu.

0 Kudos

Hi.

Thanks, it works.

You were right,

<tabstyle>[] = tabstyle[].

and

ASSIGN tabstyle TO <tabstyle>

do not behave the same way....

JC

Pawan_Kesari
Active Contributor
0 Kudos

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.

0 Kudos

Hi

==> Will <tabstyle>-style at "index sy-tabix" be modified ?

==> Will <table_reference>-tabstyle at "index ligne" be modified ?

Hope you can help me with that.

0 Kudos

There is no line after that.

Code uses fieldsymbols and this will directly modify the memory area. No need for MODIFY to transfer workarea into internal table, because there is no workarea.

Would suggest to debug and see it yourself.

Regards,

Pawan.

0 Kudos

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

Clemenss
Active Contributor
0 Kudos

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

Former Member
0 Kudos

well, I have made a refresh of course !

My problem is that when I do smtg like

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

CLEAR <tabstyle>.

Then <tabstyle> is cleared BUT <table>-tabstyle is not.

I tried to write : <table>-tabstyle but it says "<table> has no structure and thereforce no component called tabstyle"

If you can have a look at my code and maybe find what is wrong, you d be really helpful

Thanks again !

Jc

Former Member
0 Kudos

So clear <tabstyle>[] does not work either?

Please give it a try...

edit: just looked at one of my code where I actually did the same kind of thing (to handle individual color) and definitely this should work... if your <tabstyle> is updated, the related row tabstyle field must be cleared as well... It looks like your <table> field is write protected (??).

Can you paste your full routine source? the issue probably relies somewhere else...

Kr,

Manu.

Former Member
0 Kudos

Yes, it worked ! Thx again  !