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

Object Oriented ALV

Former Member
0 Likes
970

Hi all,

I am looking for step by step method to create an ALV in Object Oriented methodology.

Will anybody please help me to get it, if any.

Thanks in advance.

Anirban Bhattacharjee

1 ACCEPTED SOLUTION
7 REPLIES 7
Read only

former_member69765
Contributor
0 Likes
907

Hi,

Check this link for example code ... This describes the step by step procedure to create a OO ALV and then gives the complete code also.

It has many other OO examples.

http://www.abaplearning.com/index.php?option=com_content&view=section&id=2&Itemid=14

PS: you will have to log in.. other wise it does not display the article .. This section is only for registered members... and Registration is free...

Read only

Former Member
0 Likes
907

Hello,

Please see this: [An easy reference for ALV grid control|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907].

Regards.

Read only

Subhankar
Active Contributor
0 Likes
907

Please fallow this way

  • Create ALV instance with class-method cl_salv_table=>factory

TRY.

CALL METHOD cl_salv_table=>factory

EXPORTING

list_display = if_salv_c_bool_sap=>false

IMPORTING

r_salv_table = v_oref_table

CHANGING

t_table = i_final.

CATCH cx_salv_msg INTO l_except1.

l_text1 = l_except1->get_text( ).

MESSAGE i000 WITH l_text1.

LEAVE LIST-PROCESSING.

ENDTRY.

  • Make header of the report

PERFORM sub_header_report USING v_oref_table.

  • Get the toolbar

v_oref_functions = v_oref_table->get_functions( ).

  • For activating application toolbar

v_oref_functions->set_all( abap_true ).

v_oref_columns = v_oref_table->get_columns( ).

  • It populate the key fields which are always displayed

PERFORM sub_fill_fields_of_fcatalog USING:

'SUM_COMM' l_lead_col ' ',

'RACCT' 'Account Number'(035) ' ',

'FOBAC' 'FOB Acrual'(023) 'X',

'EXCESS' 'Excess'(024) 'X',

'OBSOLE' 'Obsolescence'(025) 'X',

'PPV' 'Puchachse Price Var'(026) 'X',

'FR_VAR' 'Freight Variance'(027) 'X',

'PROD_OR_VAR' 'Produc Ord Var'(028) 'X',

'DEP_VAR' 'Dept. Variance'(029) 'X',

'OTH_PROD_VAR' 'Other Prod Var'(030) 'X',

'PR_OR_SCRP_VAR' 'Scrap Variance'(031) 'X',

'COST_OF_ACC' 'Cost of Sales Accnt'(032) 'X',

'INV_ACC' 'Inventory Account'(033) 'X'.

  • Optimize the columns

v_oref_columns->set_optimize( value = 'X' ).

  • Setting the layout

  • get the LAYOUT object

l_oref_layout = v_oref_table->get_layout( ).

  • set the layout key

l_progname = sy-repid.

l_wa_key-report = l_progname.

l_oref_layout->set_key( value = l_wa_key ).

  • set save restriction:

  • none / only user-dependent / only user-independent

l_oref_layout->set_save_restriction(

value = if_salv_c_layout=>restrict_none ).

  • set: setting of default layout is allowed / isnu2019t allowed

l_oref_layout->set_default( value = 'X' ).

  • Dispaly the output

v_oref_table->display( ).

&----


*& Form sub_header_report

&----


  • Create the header of the report

----


  • -->P_v_oref_TABLE table name

----


FORM sub_header_report USING p_v_oref_table TYPE REF TO

cl_salv_table .

DATA : l_oref_grid TYPE REF TO cl_salv_form_layout_grid.

CREATE OBJECT l_oref_grid.

  • Add text items for top of page

l_oref_grid->create_text( row = 1 column = 1 text = 'Program'(022)

).

l_oref_grid->create_text( row = 1 column = 2 text = sy-repid ).

l_oref_grid->create_text( row = 2 column = 1

text = 'User Name'(021) ).

l_oref_grid->create_text( row = 2 column = 2 text = sy-uname ).

l_oref_grid->create_text( row = 3 column = 1 text = 'Date'(020) ).

l_oref_grid->create_text( row = 3 column = 2 text = sy-datum ).

l_oref_grid->create_text( row = 3 column = 3 text = 'Time'(019) ).

l_oref_grid->create_text( row = 3 column = 4 text = sy-uzeit ).

l_oref_grid->create_text( row = 4 column = 1 text = 'System'(018) ).

l_oref_grid->create_text( row = 4 column = 2 text = sy-sysid ).

l_oref_grid->create_text( row = 4 column = 3 text = 'Client'(017) ).

l_oref_grid->create_text( row = 4 column = 4 text = sy-mandt ).

  • Declare grid as header of list

p_v_oref_table->set_top_of_list( value = l_oref_grid ).

ENDFORM. " sub_header_report

&----


*& Form sub_fill_fields_of_fcatalog

&----


  • This subroutine populates the field catalog excluding

  • period fields

----


  • -->P_FIELDNAME Table field name

  • -->P_NAME Field description

  • -->P_DEC Decimal value flag

----


FORM sub_fill_fields_of_fcatalog USING p_fieldname TYPE lvc_fname

p_name TYPE c

p_dec TYPE c.

DATA: l_char_l TYPE scrtext_l, "For short text

l_char_m TYPE scrtext_m, "For medium text

l_char_s TYPE scrtext_s, "For long text

l_except1 TYPE REF TO cx_salv_not_found,"Exception

l_text1 TYPE string, "Exception msg

l_orf_aggregs TYPE REF TO cl_salv_aggregations.

  • Getting the text long/short/medium into variables

l_char_l = p_name.

l_char_m = p_name.

l_char_s = p_name.

  • Setting the long/short/medium text and fix the key fileds

TRY.

CALL METHOD v_oref_columns->get_column

EXPORTING

columnname = p_fieldname

RECEIVING

value = v_oref_column1.

CATCH cx_salv_not_found INTO l_except1.

l_text1 = l_except1->get_text( ).

MESSAGE i000 WITH l_text1.

LEAVE LIST-PROCESSING.

ENDTRY.

v_oref_column ?= v_oref_column1.

v_oref_column->set_long_text( l_char_l ).

v_oref_column->set_medium_text( l_char_m ).

v_oref_column->set_short_text( l_char_s ).

v_oref_column->set_key( value = 'X' ).

v_oref_columns->set_key_fixation( value = 'X' ).

  • Set the decimal length

IF p_dec = 'X'.

v_oref_column->set_decimals( value = '2' ).

ENDIF.

IF p_fieldname = 'RACCT' AND p_gl <> c_check.

v_oref_column->set_visible( value = space ).

ENDIF.

IF p_gl = c_check.

v_oref_columns->set_column_position( columnname = 'RACCT'

position = 2 ).

ENDIF.

IF p_fieldname NE 'RACCT' AND p_fieldname NE 'SUM_COMM'.

l_orf_aggregs = v_oref_table->get_aggregations( ).

l_orf_aggregs->add_aggregation( columnname = p_fieldname

aggregation = if_salv_c_aggregation=>total ).

ENDIF.

ENDFORM. " sub_fill_fields_of_fcatalog

Read only

Former Member
0 Likes
907

Thaks all.

anirban