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 grids

Former Member
0 Kudos

hi i have mad a alv grid but my data is not being trnasfered to the o/p report can anyone suggest why??

regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Please post details (code snippets, how you populated the alv grid, did you use the class method or the FM, etc) for the forum to help you better.

Sudha

14 REPLIES 14

Former Member
0 Kudos

Code Please.

Prakash.

0 Kudos

REPORT Ztst_chin_alv3.

----


  • ALV Tempalte Copy before using *

  • Created By Gavin Chaney 29/11/2005 *

----


tables : lfb1.

----


  • Declarations *

----


selection-screen begin of block a with frame title text-001.

parameters : bukrs like lfb1-bukrs.

parameters : lifnr like lfb1-lifnr.

selection-screen end of block a.

DATA: r_container TYPE REF TO cl_gui_custom_container.

DATA: r_grid TYPE REF TO cl_gui_alv_grid.

DATA: g_fieldcat TYPE lvc_t_fcat.

DATA: w_fieldcat LIKE LINE OF g_fieldcat.

DATA: g_layout TYPE lvc_s_layo.

DATA: ok_code LIKE sy-ucomm.

DATA: gs_variant TYPE disvariant.

DATA: t_selected TYPE lvc_t_row.

DATA wa_selected LIKE LINE OF t_selected.

DATA: it_items LIKE EBAN OCCURS 0.

data : it_lfb1 like lfb1 occurs 0 with header line.

----


  • Initialization *

----


INITIALIZATION.

AT SELECTION-SCREEN.

ok_code = sy-ucomm.

CASE ok_code.

WHEN 'BACK'.

LEAVE PROGRAM.

WHEN 'CANCEL'.

LEAVE PROGRAM.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN 'ONLI' OR 'CRET'.

call screen 100.

WHEN OTHERS.

ENDCASE.

----


  • GetData *

----


MODULE getdata OUTPUT.

IF sy-ucomm <> 'STOP'.

select lifnr bukrs akont fdgrv zwels

into corresponding fields of table it_lfb1

from lfb1

where

bukrs eq bukrs

and lifnr eq lifnr.

ENDIF.

ENDMODULE.

----


  • Create ALV *

----


MODULE create_alv OUTPUT.

gs_variant-report = sy-repid.

IF r_container IS INITIAL.

CREATE OBJECT r_container

EXPORTING container_name = 'CONTAINER_1'.

CREATE OBJECT r_grid

EXPORTING i_parent = r_container.

*modify the headings in the field catalogue

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'ZCATSDBALVM'

CHANGING

ct_fieldcat = g_fieldcat[].

LOOP AT g_fieldcat INTO w_fieldcat.

CASE w_fieldcat-fieldname.

WHEN 'ZCURSTAT'.

w_fieldcat-scrtext_l = 'Prev.RelCode'.

w_fieldcat-scrtext_m = 'Prev.RelCode'.

w_fieldcat-scrtext_s = 'Prev.RelCode'.

w_fieldcat-reptext = 'Prev.RelCode'.

ENDCASE.

MODIFY g_fieldcat FROM w_fieldcat.

Former Member
0 Kudos

Please post details (code snippets, how you populated the alv grid, did you use the class method or the FM, etc) for the forum to help you better.

Sudha

0 Kudos

REPORT Ztst_chin_alv3.

----


  • ALV Tempalte Copy before using *

  • Created By Gavin Chaney 29/11/2005 *

----


tables : lfb1.

----


  • Declarations *

----


selection-screen begin of block a with frame title text-001.

parameters : bukrs like lfb1-bukrs.

parameters : lifnr like lfb1-lifnr.

selection-screen end of block a.

DATA: r_container TYPE REF TO cl_gui_custom_container.

DATA: r_grid TYPE REF TO cl_gui_alv_grid.

DATA: g_fieldcat TYPE lvc_t_fcat.

DATA: w_fieldcat LIKE LINE OF g_fieldcat.

DATA: g_layout TYPE lvc_s_layo.

DATA: ok_code LIKE sy-ucomm.

DATA: gs_variant TYPE disvariant.

DATA: t_selected TYPE lvc_t_row.

DATA wa_selected LIKE LINE OF t_selected.

DATA: it_items LIKE EBAN OCCURS 0.

data : it_lfb1 like lfb1 occurs 0 with header line.

----


  • Initialization *

----


INITIALIZATION.

AT SELECTION-SCREEN.

ok_code = sy-ucomm.

CASE ok_code.

WHEN 'BACK'.

LEAVE PROGRAM.

WHEN 'CANCEL'.

LEAVE PROGRAM.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN 'ONLI' OR 'CRET'.

call screen 100.

WHEN OTHERS.

ENDCASE.

----


  • GetData *

----


MODULE getdata OUTPUT.

IF sy-ucomm <> 'STOP'.

select lifnr bukrs akont fdgrv zwels

into corresponding fields of table it_lfb1

from lfb1

where

bukrs eq bukrs

and lifnr eq lifnr.

ENDIF.

ENDMODULE.

----


  • Create ALV *

----


MODULE create_alv OUTPUT.

gs_variant-report = sy-repid.

IF r_container IS INITIAL.

CREATE OBJECT r_container

EXPORTING container_name = 'CONTAINER_1'.

CREATE OBJECT r_grid

EXPORTING i_parent = r_container.

*modify the headings in the field catalogue

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'ZCATSDBALVM'

CHANGING

ct_fieldcat = g_fieldcat[].

LOOP AT g_fieldcat INTO w_fieldcat.

CASE w_fieldcat-fieldname.

WHEN 'ZCURSTAT'.

w_fieldcat-scrtext_l = 'Prev.RelCode'.

w_fieldcat-scrtext_m = 'Prev.RelCode'.

w_fieldcat-scrtext_s = 'Prev.RelCode'.

w_fieldcat-reptext = 'Prev.RelCode'.

ENDCASE.

MODIFY g_fieldcat FROM w_fieldcat.

0 Kudos

Hi Chinmaya,

add following code in "create_alv" module to get the output:

CALL METHOD r_grid->set_table_for_first_display

CHANGING

it_outtab = it_lfb1[]

it_fieldcatalog = g_fieldcat[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

0 Kudos

Hi,

Call the method - set_table_for_first_display

CALL METHOD grid->set_table_for_first_display

EXPORTING

i_structure_name = 'ZCATSDBALVM'

is_layout = gs_layout

i_save = 'A'

  • it_toolbar_excluding = it_toolbar

CHANGING

it_outtab = gt_zcatsdbalvm

it_fieldcatalog = g_fieldcat[].

Regards

Former Member
0 Kudos

Please make sure that the name of the fields in the output internal table are same as the ones defined in your field catalog.

Former Member
0 Kudos

check in Debugging your ITAB is having any records or not.

(the table name you passed to the GRID function module)

Regards

Srikanth

Former Member
0 Kudos

Hi

Try this-

write body [] with ur fieldcatalog table.

this is how u can write-

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = repid

i_callback_pf_status_set = 'ZSC2'

is_layout = l_layout

it_fieldcat = field_cat_tab[]

TABLES

t_outtab = t_itab

More after viewing ur code.

Hope this helps u.

Regds,

Seema.

Former Member
0 Kudos

Hi,

You have the data in ITAB and passing it to the Function moduel, here the Internal table fields and the Fieldcatalog field names shoub be same .... make sure these both names are same

mark all the helpful answers

Regards

Sudheer

Former Member
0 Kudos

REPORT Ztst_chin_alv3.

----


----


tables : lfb1.

----


  • Declarations *

----


selection-screen begin of block a with frame title text-001.

parameters : bukrs like lfb1-bukrs.

parameters : lifnr like lfb1-lifnr.

selection-screen end of block a.

DATA: r_container TYPE REF TO cl_gui_custom_container.

DATA: r_grid TYPE REF TO cl_gui_alv_grid.

DATA: g_fieldcat TYPE lvc_t_fcat.

DATA: w_fieldcat LIKE LINE OF g_fieldcat.

DATA: g_layout TYPE lvc_s_layo.

DATA: ok_code LIKE sy-ucomm.

DATA: gs_variant TYPE disvariant.

DATA: t_selected TYPE lvc_t_row.

DATA wa_selected LIKE LINE OF t_selected.

DATA: it_items LIKE EBAN OCCURS 0.

data : it_lfb1 like lfb1 occurs 0 with header line.

----


  • Initialization *

----


INITIALIZATION.

AT SELECTION-SCREEN.

ok_code = sy-ucomm.

CASE ok_code.

WHEN 'BACK'.

LEAVE PROGRAM.

WHEN 'CANCEL'.

LEAVE PROGRAM.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN 'ONLI' OR 'CRET'.

call screen 100.

WHEN OTHERS.

ENDCASE.

----


  • GetData *

----


MODULE getdata OUTPUT.

IF sy-ucomm <> 'STOP'.

select lifnr bukrs akont fdgrv zwels

into corresponding fields of table it_lfb1

from lfb1

where

bukrs eq bukrs

and lifnr eq lifnr.

ENDIF.

ENDMODULE.

----


  • Create ALV *

----


MODULE create_alv OUTPUT.

gs_variant-report = sy-repid.

IF r_container IS INITIAL.

CREATE OBJECT r_container

EXPORTING container_name = 'CONTAINER_1'.

CREATE OBJECT r_grid

EXPORTING i_parent = r_container.

*modify the headings in the field catalogue

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

i_structure_name = 'ZCATSDBALVM'

CHANGING

ct_fieldcat = g_fieldcat[].

LOOP AT g_fieldcat INTO w_fieldcat.

CASE w_fieldcat-fieldname.

WHEN 'ZCURSTAT'.

w_fieldcat-scrtext_l = 'Prev.RelCode'.

w_fieldcat-scrtext_m = 'Prev.RelCode'.

w_fieldcat-scrtext_s = 'Prev.RelCode'.

w_fieldcat-reptext = 'Prev.RelCode'.

ENDCASE.

MODIFY g_fieldcat FROM w_fieldcat.

0 Kudos

Layout is not given.

wa_layout-cwidth_opt = c_x.

Method <b>set_table_for_first_display</b> is not yet called.

*-- Display Report

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

i_save = 'A'

is_layout = p_layout

CHANGING

it_outtab = p_output[]

it_fieldcatalog = p_fieldcat[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE s001(zesspa) WITH text-029. " Error in Displaying

LEAVE LIST-PROCESSING.

Endif.

Check the Sample program:

BCALV_EDIT_01

BCALV_EDIT_02

BCALV_EDIT_03

BCALV_EDIT_04

BCALV_EDIT_05

BCALV_EDIT_06

BCALV_EDIT_07

BCALV_EDIT_08

Regards,

Prakash.

Former Member
0 Kudos

Former Member
0 Kudos

Hi Chinmaya,

See the full sample code for you requirment.

if it suits your need, pls award points

&----


*& Report ZCL_CLASS1 *

*& *

&----


*& *

*& *

&----


REPORT ZCL_CLASS1.

TYPES: BEGIN OF T_MARA,

MATNR TYPE MARA-MATNR,

MAKTX TYPE MAKT-MAKTX,

WERKS TYPE MARD-WERKS,

LGORT TYPE MARD-LGORT,

LABST TYPE MARD-LABST,

END OF T_MARA.

*DATA: IT_MARA TYPE STANDARD TABLE OF T_MARA.

DATA: IT_MARA TYPE T_MARA OCCURS 0.

DATA: O_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

O_GRID TYPE REF TO CL_GUI_ALV_GRID.

DATA: X_FLDCAT TYPE LVC_S_FCAT.

DATA: IT_FLDCAT TYPE LVC_T_FCAT.

DATA: I_LAYOUT TYPE LVC_S_LAYO.

DATA: X_SORT TYPE LVC_S_SORT.

DATA: I_SORT TYPE LVC_T_SORT.

TABLES: MARA.

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.

PARAMETERS: P_CHK AS CHECKBOX.

START-OF-SELECTION.

PERFORM GET_DATA.

PERFORM GENERATE_FLDCAT.

PERFORM GENERATE_LAYOUT.

PERFORM DO_SORT.

SET SCREEN 100.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN'.

  • SET TITLEBAR 'xxx'.

PERFORM BUILD_ALV.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form BUILD_ALV

&----


  • text

----


FORM BUILD_ALV .

CREATE OBJECT O_CONT

EXPORTING

CONTAINER_NAME = 'MAT_CONTAINER'

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_ERROR = 2

CREATE_ERROR = 3

LIFETIME_ERROR = 4

LIFETIME_DYNPRO_DYNPRO_LINK = 5

others = 6.

CREATE OBJECT O_GRID

EXPORTING

I_PARENT = O_CONT

EXCEPTIONS

ERROR_CNTL_CREATE = 1

ERROR_CNTL_INIT = 2

ERROR_CNTL_LINK = 3

ERROR_DP_CREATE = 4

others = 5.

CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = ' '

IS_LAYOUT = I_LAYOUT

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

IT_OUTTAB = IT_MARA

IT_FIELDCATALOG = IT_FLDCAT[]

IT_SORT = I_SORT

  • IT_FILTER =

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

others = 4.

ENDFORM. " BUILD_ALV

&----


*& Form GET_DATA

&----


  • text

----


FORM GET_DATA .

SELECT A~MATNR

B~MAKTX

C~WERKS

C~LGORT

C~LABST

INTO TABLE IT_MARA

FROM MARA AS A

INNER JOIN MAKT AS B

ON BMATNR = AMATNR

INNER JOIN MARD AS C

ON CMATNR = AMATNR

WHERE A~MATNR IN S_MATNR

AND B~SPRAS = SY-LANGU.

ENDFORM. " GET_DATA

&----


*& Form GENERATE_FLDCAT

&----


  • text

----


FORM GENERATE_FLDCAT .

*CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

  • EXPORTING

    • I_BUFFER_ACTIVE =

  • I_STRUCTURE_NAME = 'ZSMARA'

    • I_CLIENT_NEVER_DISPLAY = 'X'

    • I_BYPASSING_BUFFER =

    • I_INTERNAL_TABNAME = ' '

  • CHANGING

  • CT_FIELDCAT = IT_FLDCAT

  • EXCEPTIONS

  • INCONSISTENT_INTERFACE = 1

  • PROGRAM_ERROR = 2

  • OTHERS = 3.

X_FLDCAT-COL_POS = 1.

X_FLDCAT-FIELDNAME = 'MATNR'.

X_FLDCAT-OUTPUTLEN = '18'.

X_FLDCAT-REPTEXT = 'Material No'.

APPEND X_FLDCAT TO IT_FLDCAT.

X_FLDCAT-COL_POS = 2.

X_FLDCAT-FIELDNAME = 'MAKTX'.

X_FLDCAT-OUTPUTLEN = '48'.

X_FLDCAT-REPTEXT = 'Material Desc'.

X_FLDCAT-TOOLTIP = 'Material Desc'.

APPEND X_FLDCAT TO IT_FLDCAT.

X_FLDCAT-COL_POS = 3.

X_FLDCAT-FIELDNAME = 'WERKS'.

X_FLDCAT-OUTPUTLEN = '5'.

X_FLDCAT-REPTEXT = 'Plant'.

X_FLDCAT-TOOLTIP = 'Plant'.

APPEND X_FLDCAT TO IT_FLDCAT.

X_FLDCAT-COL_POS = 4.

X_FLDCAT-FIELDNAME = 'LGORT'.

X_FLDCAT-OUTPUTLEN = '5'.

X_FLDCAT-REPTEXT = 'S.Loc'.

X_FLDCAT-TOOLTIP = 'S.Loc'.

APPEND X_FLDCAT TO IT_FLDCAT.

X_FLDCAT-COL_POS = 5.

X_FLDCAT-FIELDNAME = 'LABST'.

X_FLDCAT-OUTPUTLEN = '20'.

X_FLDCAT-REPTEXT = 'Quantity'.

X_FLDCAT-TOOLTIP = 'Quantity'.

X_FLDCAT-DO_SUM = 'X'.

APPEND X_FLDCAT TO IT_FLDCAT.

ENDFORM. " GENERATE_FLDCAT

&----


*& Form GENERATE_LAYOUT

&----


  • text

----


FORM GENERATE_LAYOUT .

I_LAYOUT-ZEBRA = 'X'.

I_LAYOUT-FRONTEND = 'X'.

I_LAYOUT-GRID_TITLE = 'ALV GRID USING OOPS'.

I_LAYOUT-NUMC_TOTAL = 'X'.

ENDFORM. " GENERATE_LAYOUT

&----


*& Form DO_SORT

&----


  • text

----


FORM DO_SORT .

X_SORT-FIELDNAME = 'MATNR'.

X_SORT-UP = 'X'.

X_SORT-SUBTOT = 'X'.

IF P_CHK = 'X'.

X_SORT-EXPA = SPACE.

ELSE.

X_SORT-EXPA = 'X'.

ENDIF.

APPEND X_SORT TO I_SORT.

ENDFORM. " DO_SORT