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: 

Help on ALV grid needed...

Former Member
0 Kudos

HI, I am a new comer to SAP and I have some material on ALV grid but not enough to write code to display from an internal table to the grid. I have written the code using 2 methods:

1. set_table_for_first_display and

2. reuse_alv_grid_display

The code with reuse_alv_grid_disply works fine but am not able to add more functionality to the code as I dont have any material explaining the methods to be used with it. The code with set_table_for_first_display has some problem in it. The code for it is:

tables kna1.

data: BEGIN OF itkna1 OCCURS 0,

ktokd like kna1-ktokd,

kunnr like kna1-kunnr,

name1 like kna1-name1,

name2 like kna1-name2,

end of itkna1.

*creating an instance of grid

data it_custom_control_name type scrfname value 'CC_ALV'.

data it_container type ref to cl_gui_custom_container.

data it_alvgrid type ref to cl_gui_alv_grid.

data it_lyo type lvc_s_layo.

Selection-screen begin of block Enter_data with frame title text-001.

PARAMETERS pktokd like KNA1-ktokd OBLIGATORY.

SELECT-OPTIONS skunnr FOR KNA1-kunnr.

Selection-screen end of block Enter_data.

SELECT ktokd kunnr name1 name2

FROM kna1 into CORRESPONDING FIELDS OF TABLE itkna1

WHERE ktokd = pktokd AND kunnr IN skunnr.

*loop at itkna1.

  • write:/ itkna1-ktokd, itkna1-kunnr, itkna1-name1, itkna1-name2.

*ENDLOOP.

*prepare field catalog

data it_fcat type lvc_t_fcat.

data tmp_fcat like LINE OF it_fcat.

clear: it_fcat, tmp_fcat.

tmp_fcat-fieldname = 'KTOKD'.

tmp_fcat-ref_table = 'KNA1'.

tmp_fcat-ref_field = 'KTOKD'.

tmp_fcat-col_pos = '1'.

*tmp_fcat-inttype = 'C'.

*tmp_fcat-coltext = 'Customer Group'.

*tmp_fcat-seltext = 'Customer Group'.

*tmp_fcat-outputlen = '4'.

append tmp_fcat to it_fcat.

tmp_fcat-fieldname = 'KUNNR'.

tmp_fcat-ref_table = 'KNA1'.

tmp_fcat-ref_field = 'KUNNR'.

tmp_fcat-col_pos = '2'.

*tmp_fcat-inttype = 'N'.

*tmp_fcat-coltext = 'Customer Number'.

*tmp_fcat-seltext = 'Customer Number'.

*tmp_fcat-outputlen = '10'.

append tmp_fcat to it_fcat.

tmp_fcat-fieldname = 'NAME1'.

tmp_fcat-ref_table = 'KNA1'.

tmp_fcat-ref_field = 'NAME1'.

tmp_fcat-col_pos = '3'.

*tmp_fcat-inttype = 'C'.

*tmp_fcat-coltext = 'name'.

*tmp_fcat-seltext = 'name'.

*tmp_fcat-outputlen = '12'.

append tmp_fcat to it_fcat.

tmp_fcat-fieldname = 'NAME2'.

tmp_fcat-ref_table = 'KNA1'.

tmp_fcat-ref_field = 'NAME2'.

tmp_fcat-col_pos = '4'.

*tmp_fcat-inttype = 'C'.

*tmp_fcat-coltext = 'name2'.

*tmp_fcat-seltext = 'name2'.

*tmp_fcat-outputlen = '12'.

append tmp_fcat to it_fcat.

*prepare layout

it_lyo-grid_title = 'Custormer details'.

*creating an instance of container class

create OBJECT it_container

EXPORTING

container_name = it_custom_control_name

EXCEPTIONS

cntl_error = 1

create_error = 2

OTHERS = 3.

*creating an instance of the grid

create OBJECT it_alvgrid

EXPORTING

i_parent = it_container

EXCEPTIONS

error_dp_create = 1

OTHERS = 2.

*displaying the grid

call METHOD it_alvgrid->set_table_for_first_display

EXPORTING

is_layout = it_lyo

i_structure_name = 'KNA1'

CHANGING

it_outtab = itkna1[]

it_fieldcatalog = it_fcat

EXCEPTIONS

invalid_parameter_combination = 1

others = 2.

It would be really helpful if some one could tell me what is wrong with this code and tell me where to get the material for extending code using type-pools-slis.

Thanks in advance!!!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

check BCALV_* programs for reuse_alv_grid_display.

bcalv_edit_* programs for set_table_for_first_display.

regards,

bharat.

8 REPLIES 8

Former Member
0 Kudos

Pushpa,

Below link is the best site for material.

http://esnips.com/_t_/ALV+DOcs

Don't forget to reward if useful....

Former Member
0 Kudos

i cant see any call screen in your prog... if you have to display an alv first you have to create a screen and in that screen you have to create a custom control which will contain the grid... pls go thrugh the prog

here i have changed your code and it is working in my system just try this..


tables kna1.
data: BEGIN OF itkna1 OCCURS 0,
ktokd like kna1-ktokd,
kunnr like kna1-kunnr,
name1 like kna1-name1,
name2 like kna1-name2,
end of itkna1.
*creating an instance of grid
data it_custom_control_name type scrfname value 'CC_ALV'.
data it_container type ref to cl_gui_custom_container.
data it_alvgrid type ref to cl_gui_alv_grid.
data it_lyo type lvc_s_layo.
DATA : OKCODE LIKE SY-UCOMM.

Selection-screen begin of block Enter_data with frame title text-001.
PARAMETERS pktokd like KNA1-ktokd OBLIGATORY.
SELECT-OPTIONS skunnr FOR KNA1-kunnr.
Selection-screen end of block Enter_data.

SELECT ktokd kunnr name1 name2
FROM kna1 into CORRESPONDING FIELDS OF TABLE itkna1
WHERE ktokd = pktokd AND kunnr IN skunnr.

*loop at itkna1.
* write:/ itkna1-ktokd, itkna1-kunnr, itkna1-name1, itkna1-name2.
*ENDLOOP.

*prepare field catalog
data it_fcat type lvc_t_fcat.
data tmp_fcat like LINE OF it_fcat.

clear: it_fcat, tmp_fcat.
tmp_fcat-fieldname = 'KTOKD'.
tmp_fcat-ref_table = 'KNA1'.
tmp_fcat-ref_field = 'KTOKD'.
tmp_fcat-col_pos = '1'.
*tmp_fcat-inttype = 'C'.
*tmp_fcat-coltext = 'Customer Group'.
*tmp_fcat-seltext = 'Customer Group'.
*tmp_fcat-outputlen = '4'.
append tmp_fcat to it_fcat.

tmp_fcat-fieldname = 'KUNNR'.
tmp_fcat-ref_table = 'KNA1'.
tmp_fcat-ref_field = 'KUNNR'.
tmp_fcat-col_pos = '2'.
*tmp_fcat-inttype = 'N'.
*tmp_fcat-coltext = 'Customer Number'.
*tmp_fcat-seltext = 'Customer Number'.
*tmp_fcat-outputlen = '10'.
append tmp_fcat to it_fcat.

tmp_fcat-fieldname = 'NAME1'.
tmp_fcat-ref_table = 'KNA1'.
tmp_fcat-ref_field = 'NAME1'.
tmp_fcat-col_pos = '3'.
*tmp_fcat-inttype = 'C'.
*tmp_fcat-coltext = 'name'.
*tmp_fcat-seltext = 'name'.
*tmp_fcat-outputlen = '12'.
append tmp_fcat to it_fcat.

tmp_fcat-fieldname = 'NAME2'.
tmp_fcat-ref_table = 'KNA1'.
tmp_fcat-ref_field = 'NAME2'.
tmp_fcat-col_pos = '4'.
*tmp_fcat-inttype = 'C'.
*tmp_fcat-coltext = 'name2'.
*tmp_fcat-seltext = 'name2'.
*tmp_fcat-outputlen = '12'.
append tmp_fcat to it_fcat.

*prepare layout

it_lyo-grid_title = 'Custormer details'.

call screen 100.
*creating an instance of container class
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'ZSPD'.
*  SET TITLEBAR 'xxx'.
create OBJECT it_container
EXPORTING
container_name = it_custom_control_name
EXCEPTIONS
cntl_error = 1
create_error = 2
OTHERS = 3.
*creating an instance of the grid
create OBJECT it_alvgrid
EXPORTING
i_parent = it_container
EXCEPTIONS
error_dp_create = 1
OTHERS = 2.

*displaying the grid
call METHOD it_alvgrid->set_table_for_first_display
EXPORTING
is_layout = it_lyo

*i_structure_name = 'KNA1'
CHANGING
it_outtab = itkna1[]
it_fieldcatalog = it_fcat
EXCEPTIONS
invalid_parameter_combination = 1
others = 2.

ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
call method cl_gui_cfw=>dispatch.

CASE OKCODE.
WHEN 'EXIT' OR 'BACK'.
LEAVE PROGRAM.
ENDCASE.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

regards

shiba dutta

0 Kudos

Hi Shiba,

Thanks for the help..but when I am doing the modification you have shown it is giving me an error saying 'DYNPRO doesnot exist'. When I comment the call screen 100 statement that error is not coming. If you can tell me how to create that screen and how to attach the container to that screen it would be helpful.

Thank you!!

Pushpa

0 Kudos

Hi Shiba,

I have now solved my problem and have somehow worked out how to create a screen and call it from the program. Thanks for the help!!

Former Member
0 Kudos

Hi,

There is a tool (ALVrobot) developed by a person called "Gabriel Jenik" of Argentina. This tool generates ABAP code for ALV reports, by following a few simple steps.

Here's the link for that :

http://www.alvrobot.com.ar/home.php

Regards,

Ramya.R

0 Kudos

Hi Ramya,

Thanks for the reply. The tool ALVRobot you are saying simply generates a simple report and I want to add other functionalities to the report generated by it. I have searched for material related to the methods used by the ALVRobot but could not find any.

Thanks once again,

Regards,

Pushpa

Former Member
0 Kudos

Hi,

First Create a screen and add a custom control to the screen and name it 'CC_ALV'. Activate.and then in your the code call the screen.

thanks,

Ahasan

Former Member
0 Kudos

Hi,

check BCALV_* programs for reuse_alv_grid_display.

bcalv_edit_* programs for set_table_for_first_display.

regards,

bharat.