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

ALV Display

Former Member
0 Likes
710

Hi All,

Given below is ALV report using OO ABAP.Its not displaying th report.Plz let me know wat is wrong..

REPORT ZRAK .

data : gt_mara type table of mara.

data : gl_alv_grid type ref to cl_gui_alv_grid,

gc_custom_control_name type scrfname value 'CCALV',

gr_ccontainer type ref to cl_gui_custom_container,

gt_fieldcat type lvc_t_fcat,

gs_layout type lvc_s_layo.

DATA : wa_fieldcat type lvc_s_fcat.

start-of-selection.

select matnr from mara into table gt_mara.

wa_fieldcat-fieldname = 'MATNR'.

append wa_fieldcat to gt_fieldcat.

clear wa_fieldcat.

*wa_fieldcat-fieldname = 'EMARA'.

*append wa_fieldcat to gt_fieldcat.

*clear wa_fieldcat.

if gl_alv_grid is initial.

CREATE OBJECT GR_CCONTAINER

EXPORTING

  • PARENT =

CONTAINER_NAME = gc_custom_control_name

  • STYLE =

  • LIFETIME = lifetime_default

  • REPID =

  • DYNNR =

  • NO_AUTODEF_PROGID_DYNNR =

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_ERROR = 2

CREATE_ERROR = 3

LIFETIME_ERROR = 4

LIFETIME_DYNPRO_DYNPRO_LINK = 5

others = 6

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CREATE OBJECT gl_alv_grid

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

I_PARENT = gr_Ccontainer

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_USE_VARIANT_CLASS = SPACE

  • I_NAME =

EXCEPTIONS

ERROR_CNTL_CREATE = 1

ERROR_CNTL_INIT = 2

ERROR_CNTL_LINK = 3

ERROR_DP_CREATE = 4

others = 5

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF sy-subrc EQ 0.

gs_layout-grid_title = text-100.

gs_layout-CWIDTH_OPT = 'X'.

gs_layout-ZEBRA = 'X'.

  • galv_layout-report = sy-repid.

CALL METHOD GL_ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

IS_LAYOUT = gs_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

IT_OUTTAB = gt_mara[]

IT_FIELDCATALOG = gt_fieldcat

  • IT_SORT =

  • IT_FILTER =

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

others = 4

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDIF.

endif.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
679

Hi!

where does your alv control display?

Is there a screen?

Cheers!

6 REPLIES 6
Read only

Former Member
0 Likes
679

hi,

refer to the program BCALV_GRID_01 and BCALV_GRID_02

regards,

sreelakshmi

Read only

mvoros
Active Contributor
0 Likes
679

Hi,

maybe you should rewrite your report using modern approach described in the following link:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/eac1fa0b-0e01-0010-0990-8530de49...

You can find tons of questions and answers on this forum and please put your code into code tags (check on the right side Markup/Results ). The code will be easier to read. Hence chance that someone will help you will be higher.

Cheers

Read only

Former Member
0 Likes
680

Hi!

where does your alv control display?

Is there a screen?

Cheers!

Read only

Former Member
0 Likes
679

Hi,

from the line if gl_alv_grid is initial.....

until last endif i.e set_table_for_first_display

this shold be in the PBO module of your screen not in start-of-slection

where is your call screen stmt???

you should define a screen, on the screen drag & drop a custiom container and give it the name 'CCALV' ehat you gave in your program.

then in the PBO write the aboe logic and in PAI if you want to handle any sy-ucomm you can do it,

see my sample program

&----


*& Report ZSOW_OBJECT7

*&

&----


*&

*&

&----


REPORT ZSOW_OBJECT7.

DATA:GS_LAYOUT TYPE DISVARIANT,

ITAB TYPE TABLE OF SFLIGHT,

G_CUST TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

G_GRID TYPE REF TO CL_GUI_ALV_GRID.

START-OF-SELECTION.

SELECT * FROM SFLIGHT INTO TABLE ITAB UP TO 10 ROWS.

  • 'gs_layout' must at least contain the report-id to allow

  • saving a layout.

GS_LAYOUT-REPORT = SY-REPID.

CALL SCREEN 100.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'MAIN'.

  • SET TITLEBAR 'xxx'.

IF G_CUST IS INITIAL.

CREATE OBJECT G_CUST

EXPORTING

CONTAINER_NAME = 'CUSTOM'.

CREATE OBJECT G_GRID

EXPORTING

I_PARENT = G_CUST.

CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = 'SFLIGHT'

IS_VARIANT = GS_LAYOUT

I_SAVE = 'X'

  • I_DEFAULT = 'X'

CHANGING

IT_OUTTAB = ITAB.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

Note: My custom container name in screen 100 is 'CUSTOM'.

    • Do reward points if it helps you

Regards,

Sowjanya

Read only

anversha_s
Active Contributor
0 Likes
679

Dear Rakesh,

where is your call screen statement. Please refer the below

program.

BCALV_EDIT_01.

Regards,

Anversha

Read only

Former Member
0 Likes
679

Hi,

Have you Activate your Custome Control

gc_custom_control_name type scrfname value 'CCALV',

Check whether you given name( custom conainer ) is correct or not , build the field catalog and append the fields.

In this Decaration

gr_ccontainer type ref to cl_gui_custom_container,

CREATE OBJECT gl_alv_grid

EXPORTING

I_SHELLSTYLE = 0

I_LIFETIME =

I_PARENT = gr_Ccontainer------correct it has a small letter (case senitive)

I_APPL_EVENTS = space

I_PARENTDBG =

I_APPLOGPARENT =

I_GRAPHICSPARENT =

I_USE_VARIANT_CLASS = SPACE

I_NAME =

EXCEPTIONS

ERROR_CNTL_CREATE = 1

ERROR_CNTL_INIT = 2

ERROR_CNTL_LINK = 3

ERROR_DP_CREATE = 4

others = 5

.

Or

Refer the PRogram BCALV_EDIT_02 for the same

Or

Am sending one reference code for this , in place of

Replace my Container and custome container nmaes with your's and run the program .ok

Code is

TABLES: VBAK.

TYPE-POOLS: ICON.

*&----


*

*& Declaration Section for the Internal Tables *

*&----


*

DATA: BEGIN OF GT_OUTTAB OCCURS 0.

  • vbeln TYPE vbak-vbeln,

  • erdat TYPE vbak-erdat,

  • erzet TYPE vbak-erzet,

  • ernam TYPE vbak-ernam,

  • netwr TYPE vbak-netwr,

INCLUDE STRUCTURE ZVBAK_INTERNAL1.

DATA: CELLTAB TYPE LVC_T_STYL.

DATA: END OF GT_OUTTAB.

DATA: IT_VBAK TYPE TABLE OF ZVBAK_INTERNAL1 WITH HEADER LINE.

DATA: OK_CODE LIKE SY-UCOMM,

SAVE_OK LIKE SY-UCOMM,

G_CONTAINER TYPE SCRFNAME VALUE 'GRID_CONTROL',

GRID1 TYPE REF TO CL_GUI_ALV_GRID,

G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

GS_LAYOUT TYPE LVC_S_LAYO,

I_FCAT TYPE LVC_T_FCAT,

W_FCAT TYPE LVC_S_FCAT.

CALL SCREEN 200.

*&----


*

*& Module STATUS_0200 OUTPUT

*&----


*

  • text

*----


*

MODULE STATUS_0200 OUTPUT.

SET PF-STATUS 'MAIN100'.

SET TITLEBAR 'MAIN100'.

IF G_CUSTOM_CONTAINER IS INITIAL.

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING

CONTAINER_NAME = G_CONTAINER.

CREATE OBJECT GRID1

EXPORTING

I_PARENT = G_CUSTOM_CONTAINER.

PERFORM SELECT_DATA_AND_INIT_STYLE.

*§3.Provide the fieldname of the celltab field by using field

  • STYLEFNAME of the layout structure.

GS_LAYOUT-STYLEFNAME = 'CELLTAB'.

CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = 'ZVBAK_INTERNAL1'

IS_LAYOUT = GS_LAYOUT

  • ls_fieldcat = it_fieldcatalog

CHANGING

IT_OUTTAB = GT_OUTTAB[]

IT_FIELDCATALOG = I_FCAT.

ENDIF.

ENDMODULE. " STATUS_0200 OUTPUT

*&----


*

*& Module USER_COMMAND_0200 INPUT

*&----


*

  • text

*----


*

MODULE USER_COMMAND_0200 INPUT.

SAVE_OK = OK_CODE.

CLEAR OK_CODE.

CASE SAVE_OK.

WHEN 'EXIT'.

PERFORM EXIT_PROGRAM.

WHEN 'SWITCH'.

PERFORM SWITCH_EDIT_MODE.

WHEN OTHERS.

  • do nothing

ENDCASE.

ENDMODULE. " USER_COMMAND_0200 INPUT

*&----


*

*& Form exit_program

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM EXIT_PROGRAM .

LEAVE PROGRAM.

ENDFORM. " exit_program

*&----


*

*& Form select_data_and_init_style

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM SELECT_DATA_AND_INIT_STYLE.

DATA: LT_CELLTAB TYPE LVC_T_STYL,

L_INDEX TYPE I.

SELECT VBELN

ERDAT

ERZET

ERNAM

NETWR UP TO 100 ROWS

FROM VBAK

INTO TABLE IT_VBAK.

  • move corresponding fields from lt_sflight to gt_outtab

LOOP AT IT_VBAK.

MOVE-CORRESPONDING IT_VBAK TO GT_OUTTAB.

APPEND GT_OUTTAB.

ENDLOOP.

*§2.After selecting data, set edit status for each row in a loop

  • according to field NETWR.

LOOP AT GT_OUTTAB.

L_INDEX = SY-TABIX.

REFRESH LT_CELLTAB.

IF GT_OUTTAB-VBELN EQ '0000000080'.

PERFORM FILL_CELLTAB USING 'RW'

CHANGING LT_CELLTAB.

ELSE.

PERFORM FILL_CELLTAB USING 'RO'

CHANGING LT_CELLTAB.

ENDIF.

*§2c.Copy your celltab to the celltab of the current row of gt_outtab.

INSERT LINES OF LT_CELLTAB INTO TABLE GT_OUTTAB-CELLTAB.

MODIFY GT_OUTTAB INDEX L_INDEX.

ENDLOOP.

  • CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

  • EXPORTING

  • input = input

  • IMPORTING

  • output = output.

*

ENDFORM. " select_data_and_init_style

*END-OF-SELECTION.

*&----


*

*& Form fill_celltab

*&----


*

  • text

*----


*

  • -->P_0194 text

  • <--P_LT_CELLTAB text

*----


*

FORM FILL_CELLTAB USING VALUE(P_MODE)

CHANGING P_LT_CELLTAB TYPE LVC_T_STYL.

DATA: LS_CELLTAB TYPE LVC_S_STYL,

L_MODE TYPE RAW4.

  • This forms sets the style of column 'PRICE' editable

  • according to 'p_mode' and the rest to read only either way.

IF P_MODE EQ 'RW'.

*§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell

  • to status "editable".

L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.

ELSE. "p_mode eq 'RO'

*§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell

  • to status "non-editable".

L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

ENDIF.

LS_CELLTAB-FIELDNAME = 'VBELN'.

LS_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

LS_CELLTAB-FIELDNAME = 'ERDAT'.

LS_CELLTAB-STYLE = L_MODE.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

LS_CELLTAB-FIELDNAME = 'ERZET'.

LS_CELLTAB-STYLE = L_MODE.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

LS_CELLTAB-FIELDNAME = 'ERNAM'.

LS_CELLTAB-STYLE = L_MODE.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

LS_CELLTAB-FIELDNAME = 'NETWR'.

LS_CELLTAB-STYLE = L_MODE.

INSERT LS_CELLTAB INTO TABLE P_LT_CELLTAB.

ENDFORM. " fill_celltab

*&----


*

*& Form switch_edit_mode

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM SWITCH_EDIT_MODE.

IF GRID1->IS_READY_FOR_INPUT( ) EQ 0.

  • set edit enabled cells ready for input

CALL METHOD GRID1->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

ELSE.

  • lock edit enabled cells against input

CALL METHOD GRID1->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 0.

ENDIF.

ENDFORM. " switch_edit_mode

*&----


*

*& Form build_field_cat

*&----


*

FORM BUILD_FIELD_CAT.

CLEAR I_FCAT.

W_FCAT-COL_POS = '1'.

W_FCAT-FIELDNAME = 'VBELN'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Sales and Distribution'.

APPEND W_FCAT TO I_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = '2'.

W_FCAT-FIELDNAME = 'ERDAT'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Date'.

APPEND W_FCAT TO I_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = '3'.

W_FCAT-FIELDNAME = 'ERZET'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Entry time'.

APPEND W_FCAT TO I_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = '4'.

W_FCAT-FIELDNAME = 'ERNAM'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Name of Person'.

APPEND W_FCAT TO I_FCAT.

CLEAR W_FCAT.

W_FCAT-COL_POS = '5'.

W_FCAT-FIELDNAME = 'NETWR'.

W_FCAT-REF_TABLE = 'VBAK'.

W_FCAT-SELTEXT = 'Net Value'.

W_FCAT-CFIELDNAME = 'NETWR_AK'.

APPEND W_FCAT TO I_FCAT.

ENDFORM. " build_field_cat

Reward Points If Usefull

Regards

Fareedas