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: 

ALV crashes in background

Former Member
0 Kudos

I've made a dynamic table for my alv data using 'cl_alv_table_create=>create_dynamic_table'.

CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = lt_alv_data
    IMPORTING
      ep_table        = gt_alv_data.

* assign data table to <fs_alv>
  ASSIGN gt_alv_data->* TO <fs_alv>.

I then display the container using set_table_for_first_display. In foreground I'm using a customer container and in background a docking container.

*   Display the ALV Container
  CALL METHOD lo_grid->set_table_for_first_display
    EXPORTING
      it_toolbar_excluding          = lt_fun
      is_layout                     = gs_layout
      is_variant                    = ls_variant
      i_save                        = 'A'
    CHANGING
      it_outtab                     = <fs_alv>
      it_fieldcatalog               = gt_fcat
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS

This works perfectly in foreground but not in background. The it_outtab used to be a static tabletype. It would then work in background. Only thing I added is the first snippet of code and changed the parameter it_outtab to the fieldsymbol. In the error logs I see a dump getwa_not_assigned. I went into debugger and the <fs_alv> was assigned in background so the error is comming from a different field-symbol. It turns out to be a field symbol used in SAP program SAPLKKBL.

I need this way of working cause I add some columns to the fieldcatalog dynamically and the it_outtab data table needs those columns as well.

Thank you

1 ACCEPTED SOLUTION

former_member226225
Contributor
0 Kudos

Hi,

Let us use the OFFLINE method of CL_GUI_ALV_GRID class and it will return the E_OFFLINE parameter if it will return zero then should be in foreground execution and if it return non-zero value then it should be executed in BACKGROUND .

See the following code related to it and execute it in background

REPORT ZDYNAMICBACKGROUND. .

*Type pools declaration for ALV

TYPE-POOLS: SLIS. " ALV Global Types

*data declaration for dynamic internal table and alv

DATA: L_STRUCTURE TYPE REF TO DATA,

L_TABLE TYPE REF TO DATA,

STRUC_DESC TYPE REF TO CL_ABAP_STRUCTDESCR,

LT_LAYOUT TYPE SLIS_LAYOUT_ALV,

LS_LVC_FIELDCATALOGUE TYPE LVC_S_FCAT,

LT_LVC_FIELDCATALOGUE TYPE LVC_T_FCAT,

LS_FIELDCATALOGUE TYPE lvc_s_fcat,

LT_FIELDCATALOGUE TYPE lvc_t_fcat.

data : o_cont type ref TO cl_gui_custom_container,

o_dock type REF TO cl_gui_docking_container,

o_grid type ref to cl_gui_alv_grid.

*field symbols declaration

FIELD-SYMBOLS : <IT_TABLE> TYPE STANDARD TABLE,

<DYN_STR> TYPE ANY,

<STR_COMP> TYPE ABAP_COMPDESCR.

*declarations for grid title

DATA : T1(30),

T2(10),

T3(50).

*selection screen declaration for table input

PARAMETERS : P_TABLE LIKE DD02L-TABNAME.

*initialization event

INITIALIZATION.

*start of selection event

START-OF-SELECTION.

call screen 100.

*texts for grid title

T1 = 'Dynamic ALV display for table'.

T2 = P_TABLE.

CONCATENATE T1 T2 INTO T3 SEPARATED BY SPACE.

module STATUS_0100 output.

  • Dynamic creation of a structure

CREATE DATA L_STRUCTURE TYPE (P_TABLE).

ASSIGN L_STRUCTURE->* TO <DYN_STR>.

  • Fields Structure

STRUC_DESC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <DYN_STR> ).

LOOP AT STRUC_DESC->COMPONENTS ASSIGNING <STR_COMP>.

  • Build Fieldcatalog

LS_LVC_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.

LS_LVC_FIELDCATALOGUE-REF_TABLE = P_TABLE.

APPEND LS_LVC_FIELDCATALOGUE TO LT_LVC_FIELDCATALOGUE.

  • Build Fieldcatalog

LS_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.

LS_FIELDCATALOGUE-REF_TABLE = P_TABLE.

APPEND LS_FIELDCATALOGUE TO LT_FIELDCATALOGUE.

ENDLOOP.

  • Create internal table dynamic

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_LVC_FIELDCATALOGUE

IMPORTING

EP_TABLE = L_TABLE.

ASSIGN L_TABLE->* TO <IT_TABLE>.

  • Read data from the table selected.

SELECT * FROM (P_TABLE)

INTO CORRESPONDING FIELDS OF TABLE <IT_TABLE>.

  • ALV Layout

LT_LAYOUT-ZEBRA = 'X'.

LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

LT_LAYOUT-WINDOW_TITLEBAR = T3.

SET PF-STATUS 'ABC'.

data mode type i.

CALL METHOD cl_gui_alv_grid=>offline

receiving

e_offline = mode.

if mode eq 0.

CREATE OBJECT o_cont

EXPORTING

container_name = 'CST'.

CREATE OBJECT o_grid

EXPORTING

i_parent = o_cont.

CALL METHOD o_grid->set_table_for_first_display

CHANGING

it_outtab = <it_table>

it_fieldcatalog = LT_FIELDCATALOGUE.

else.

CREATE OBJECT o_grid

EXPORTING

i_parent = o_dock.

CALL METHOD o_grid->set_table_for_first_display

CHANGING

it_outtab = <it_table>

it_fieldcatalog = LT_FIELDCATALOGUE.

endif.

endmodule. " STATUS_0100 OUTPUT

module USER_COMMAND_0100 input.

case sy-ucomm.

when 'BACK'.

leave program.

endcase.

endmodule. " USER_COMMAND_0100 INPUT

3 REPLIES 3

former_member226225
Contributor
0 Kudos

Hi,

Let us use the OFFLINE method of CL_GUI_ALV_GRID class and it will return the E_OFFLINE parameter if it will return zero then should be in foreground execution and if it return non-zero value then it should be executed in BACKGROUND .

See the following code related to it and execute it in background

REPORT ZDYNAMICBACKGROUND. .

*Type pools declaration for ALV

TYPE-POOLS: SLIS. " ALV Global Types

*data declaration for dynamic internal table and alv

DATA: L_STRUCTURE TYPE REF TO DATA,

L_TABLE TYPE REF TO DATA,

STRUC_DESC TYPE REF TO CL_ABAP_STRUCTDESCR,

LT_LAYOUT TYPE SLIS_LAYOUT_ALV,

LS_LVC_FIELDCATALOGUE TYPE LVC_S_FCAT,

LT_LVC_FIELDCATALOGUE TYPE LVC_T_FCAT,

LS_FIELDCATALOGUE TYPE lvc_s_fcat,

LT_FIELDCATALOGUE TYPE lvc_t_fcat.

data : o_cont type ref TO cl_gui_custom_container,

o_dock type REF TO cl_gui_docking_container,

o_grid type ref to cl_gui_alv_grid.

*field symbols declaration

FIELD-SYMBOLS : <IT_TABLE> TYPE STANDARD TABLE,

<DYN_STR> TYPE ANY,

<STR_COMP> TYPE ABAP_COMPDESCR.

*declarations for grid title

DATA : T1(30),

T2(10),

T3(50).

*selection screen declaration for table input

PARAMETERS : P_TABLE LIKE DD02L-TABNAME.

*initialization event

INITIALIZATION.

*start of selection event

START-OF-SELECTION.

call screen 100.

*texts for grid title

T1 = 'Dynamic ALV display for table'.

T2 = P_TABLE.

CONCATENATE T1 T2 INTO T3 SEPARATED BY SPACE.

module STATUS_0100 output.

  • Dynamic creation of a structure

CREATE DATA L_STRUCTURE TYPE (P_TABLE).

ASSIGN L_STRUCTURE->* TO <DYN_STR>.

  • Fields Structure

STRUC_DESC ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <DYN_STR> ).

LOOP AT STRUC_DESC->COMPONENTS ASSIGNING <STR_COMP>.

  • Build Fieldcatalog

LS_LVC_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.

LS_LVC_FIELDCATALOGUE-REF_TABLE = P_TABLE.

APPEND LS_LVC_FIELDCATALOGUE TO LT_LVC_FIELDCATALOGUE.

  • Build Fieldcatalog

LS_FIELDCATALOGUE-FIELDNAME = <STR_COMP>-NAME.

LS_FIELDCATALOGUE-REF_TABLE = P_TABLE.

APPEND LS_FIELDCATALOGUE TO LT_FIELDCATALOGUE.

ENDLOOP.

  • Create internal table dynamic

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_LVC_FIELDCATALOGUE

IMPORTING

EP_TABLE = L_TABLE.

ASSIGN L_TABLE->* TO <IT_TABLE>.

  • Read data from the table selected.

SELECT * FROM (P_TABLE)

INTO CORRESPONDING FIELDS OF TABLE <IT_TABLE>.

  • ALV Layout

LT_LAYOUT-ZEBRA = 'X'.

LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

LT_LAYOUT-WINDOW_TITLEBAR = T3.

SET PF-STATUS 'ABC'.

data mode type i.

CALL METHOD cl_gui_alv_grid=>offline

receiving

e_offline = mode.

if mode eq 0.

CREATE OBJECT o_cont

EXPORTING

container_name = 'CST'.

CREATE OBJECT o_grid

EXPORTING

i_parent = o_cont.

CALL METHOD o_grid->set_table_for_first_display

CHANGING

it_outtab = <it_table>

it_fieldcatalog = LT_FIELDCATALOGUE.

else.

CREATE OBJECT o_grid

EXPORTING

i_parent = o_dock.

CALL METHOD o_grid->set_table_for_first_display

CHANGING

it_outtab = <it_table>

it_fieldcatalog = LT_FIELDCATALOGUE.

endif.

endmodule. " STATUS_0100 OUTPUT

module USER_COMMAND_0100 input.

case sy-ucomm.

when 'BACK'.

leave program.

endcase.

endmodule. " USER_COMMAND_0100 INPUT

Former Member
0 Kudos

raghunadh,

I already use the offline method to create either an istance of docking container or an instance of custom container. So that part is the same for me. Only thing I do differently is I build the fieldcatalog starting from an existing structure. I call LVC_FIELDCATALOG_MERGE and add some extra rows to the output. This then becomes the parameter i pass to cl_alv_table_create=>create_dynamic_table. You on the other hand use RTTC to create the fieldcatalog. Does it work for you in background?

Edited by: Philippe Haesaert on Feb 3, 2012 1:30 PM

0 Kudos

Solved the issue. Turned out I still had a color fieldname bound to my layout. I removed all the coding for colors earlier except this line:

gs_layout-ctab_fname = 'CELLCOLOR'.

Causing the crash...