Application Development and Automation 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: 
Read only

Alignment in OOPs ALV

Former Member
5,195

I want to align text to left and right based on some condition in same colomn in OOPs ALV(set_table_for_first_display). I can't use 'lvc_s_fcat-just' as this apply to every row for the colomn.

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
3,849

You may use a different style for each cell by defining a style column in your ALV table named YOURSTYLECOL of type LVC_T_STYL (table of combination { field name, style 1, style 2, ... }).

Transmit its name via the layout parameter IS_LAYOUT-STYLEFNAME = 'YOURSTYLECOL'.

In every row of your ALV table, fill this style table with as many rows as number of cells to apply a style. The style 1 may have values from constants ALV_STYLE* from the include <CL_ALV_CONTROL>, for instance ALV_STYLE_ALIGN_RIGHT_CENTER. Some style constants correspond only to STYLE1, others to STYLE2, etc.

9 REPLIES 9
Read only

SimoneMilesi
Active Contributor
0 Likes
3,849

I do not know if you you can rely on structure LVC_S_STYL (table type LVC_T_STYLE), you can give a try with them.

You can check the BCALV... demo reports

Read only

Sandra_Rossi
Active Contributor
3,850

You may use a different style for each cell by defining a style column in your ALV table named YOURSTYLECOL of type LVC_T_STYL (table of combination { field name, style 1, style 2, ... }).

Transmit its name via the layout parameter IS_LAYOUT-STYLEFNAME = 'YOURSTYLECOL'.

In every row of your ALV table, fill this style table with as many rows as number of cells to apply a style. The style 1 may have values from constants ALV_STYLE* from the include <CL_ALV_CONTROL>, for instance ALV_STYLE_ALIGN_RIGHT_CENTER. Some style constants correspond only to STYLE1, others to STYLE2, etc.

Read only

0 Likes
3,849

Hi Sandra,

Thanks for your response but i have used this logic and i didn't get result as per my requirement.

Read only

3,849

Probably you did something wrong. In my system, it works well:

DATA go_alv TYPE REF TO cl_gui_alv_grid.
TYPES : BEGIN OF ty_scarr2.
    INCLUDE TYPE scarr AS scarr.
TYPES: styles TYPE lvc_t_styl,
       END OF ty_scarr2,
       ty_scarr2s TYPE STANDARD TABLE OF ty_scarr2 WITH EMPTY KEY.
INCLUDE <cl_alv_control>.
DATA gt_scarr2 TYPE ty_scarr2s.

PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF go_alv IS INITIAL.
    CREATE OBJECT go_alv
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    SELECT * FROM scarr INTO TABLE @DATA(gt_scarr).
    LOOP AT gt_scarr ASSIGNING FIELD-SYMBOL(<scarr>).
      gt_scarr2 = VALUE #( BASE gt_scarr2 (
          scarr  = <scarr>
          styles = VALUE #( ( fieldname = 'CARRNAME' style = alv_style_align_right_center ) ) ) ).
    ENDLOOP.
    go_alv->set_table_for_first_display(
        EXPORTING
          i_structure_name = 'SCARR'
          is_layout        = VALUE #( stylefname = 'STYLES' )
        CHANGING
          it_outtab        = gt_scarr2 ).
  ENDIF.

AT SELECTION-SCREEN ON EXIT-COMMAND.
  go_alv->free( ).
  FREE go_alv.

Screenshot:

Read only

kumarsubhendu19
Discoverer
0 Likes
3,849

** declaration for ALV Columns

DATA : gr_columns TYPE REF TO cl_salv_columns_table,

gr_column TYPE REF TO cl_salv_column .

TRY . gr_column ?= lo_cols->get_column( 'ZREV' ).

gr_column->set_medium_text( 'Rev.Chrgs.Appl.' ).

gr_column->set_short_text( 'Rev.Chrgs' ).

gr_column->set_alignment( value = if_salv_form_c_h_align=>center ).

CATCH cx_salv_not_found. "#EC NO_HANDLER

ENDTRY.

"Here using set_alignment you can set the alignment as per your need

Read only

0 Likes
3,849

Hi Subhendu,

I am not using SALV

Read only

kumarsubhendu19
Discoverer
0 Likes
3,849

Hi Anurag,

To get it done , please refer program - BCALV_EDIT_07

Here SAP Tried dynamic representation for drop down table .

the same way you can handle it for alignment too by changing the it_outtab as per your need .

Sandra Rossi has provided the solution for this .
Read only

0 Likes
3,849

How is the ALV drop down demo program related to the question? (it doesn't even handle styles and alignments)

Read only

0 Likes
3,849

this is what SAP has done to handle the rows dynamically , by adding an additional field to it , handling it with as per the needs , i was looking for it , then i saw your comment you have also did it in similar way , that's why i have mentioned you have provided the solution .