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: 

can anyone send me an object [ alv report ] with explanation

Former Member
0 Kudos
194

Hi all,

I am new to this group and in ABAP also ..

Kindly help me out by sending one ALV Report and the related data .. I would be greatful to you all..

I am asking you the object to explain in the interview so help me out guys

Thanks and Regards

Santosh

5 REPLIES 5

Former Member
0 Kudos
61

Hi,

Check this thread for ALV related questions..

Please make sure to reward points for helpful answers..

Thanks,

Naren

gastn_jareo
Active Participant
0 Kudos
61

You can check this thread too. It has a lot of links to examples, specialy for interactive ALV reports:

/thread/178055 [original link is broken]

Former Member
0 Kudos
61

Check the lonk for more examples in ALV ;

http://www.sapdevelopment.co.uk/reporting/alv/alvscr.htm

Former Member
0 Kudos
61

Hello Santosh,

For <b>OOALV</b>,we <b>define a container</b>.Generally we use a custom container.The class used is <b>cl_gui_custom_container</b>.In the <b>layout</b> of your screen,make a custom container (icon with C written) and name it <b>CONTAINER</b> (in caps).Now create the container by going to the PATTERN button->ABAP objects.

We can now <b>attach a control to the container</b>.ALV,text editor,picture control are different types of controls.For ALV,we use the class <b>cl_gui_alv_grid</b>.Again you can create an instance by using the pattern button.The container name is given as the parent of the ALV in the constructor method.

We can use several methods of the ALV class to display data and for various functionalities.To display the data first time,we use <b>SET_TABLE_FOR_FIRST_DISPLAY</b> method.You can go to se24,type CL_GUI_ALV_GRID and click DISPLAY button.There you can see all the methods and attributes of the ALV class which you can use.

Here is a sample program:

REPORT SAMPLE.

<b>**alv and cont are references to the respective classes.However,the objects are not created yet.</b>

DATA: alv type ref to cl_gui_alv_GRID,

cont type ref to cl_gui_custom_container,

itab_spfli type table of spfli,

ok_code type sy-ucomm.

START-OF-SELECTION.

<b>**I fill my internal table itab_spfli with the data that i want in my ALV display</b>

select * from spfli into table itab_spfli.

<b>**I call the screen.In the screen layout,i have made a container named</b> <b>CONTAINER</b>

call screen 100.

END-OF-SELECTION.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

seT PF-STATUS 'GUI'.

  • SET TITLEBAR 'xxx'.

<b>**If the container is being made for the first time,i create a container object.I m passing the name CONTAINER that i used in the screen layout here</b>

if cont is initial.

CREATE OBJECT cont

EXPORTING

CONTAINER_NAME = 'CONTAINER'.

<b>**The ALV object is created here and the parent name is the container object ie cont</b>

CREATE OBJECT ALV

EXPORTING

I_PARENT = CONT.

<b>**SET_TABLE_FOR_FIRST_DISPLAY method is called to display the data.I give the structure name SPFLI and the internal table which conatins the actual data ie itab_spfli</b>

CALL METHOD ALV->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

I_STRUCTURE_NAME = 'SPFLI'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT =

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

CHANGING

IT_OUTTAB = itab_spfli

  • IT_FIELDCATALOG =

  • 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.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

case ok_code.

when 'BACK'.

leave to screen 0.

when 'EXIT'.

leave to screen 0.

when 'SAVE'.

MODIFY spfli from table itab_spfli.

ENDCASE.

-


<b>Also try the transaction ABAPDOCU for simple ALV programs.</b>

<b>For ALV:</b>

http://help.sap.com/saphelp_erp2005/helpdata/en/99/49b844d61911d2b469006094192fe3/frameset.htm

<b>For OO concepts:</b>

http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm

<b>-->download the PDF from following link.</b>

www.abap4.it/download/ALV.pdf

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf

Regards,

Beejal

<b>**Reward if this helps</b>

Former Member
0 Kudos
61

hi santosh,

just watch the following code which can help u to develop alv reports on ur own,

following is the complete code for data excration,manipulation and display the output in ALV including interacation with transaction code MM02,MM03.

&----


*& Report ZMM_MATERIAL_INVENTORY_R

*&

&----


*&

*&

&----


REPORT zmm_material_inventory_r NO STANDARD PAGE HEADING.

&----


*&Purpose:

*& material inventory rport

&----


*define database tables...

TABLES: mara,

makt,

marc,

mbew,

mvke,

t023t.

*define types...

TYPES: BEGIN OF t_tab_mara,

matnr TYPE matnr,

matkl TYPE matkl,

mtart TYPE mtart,

prdha TYPE prodh_d,

bismt TYPE bismt,

meins TYPE meins.

TYPES: END OF t_tab_mara.

TYPES: BEGIN OF t_tab_mbew,

matnr TYPE matnr,

bwkey TYPE bwkey,

stprs TYPE stprs,

verpr TYPE verpr,

bwprh TYPE bwprh,

bwph1 TYPE bwph1,

vjbwh TYPE vjbwh.

TYPES: END OF t_tab_mbew.

TYPES: BEGIN OF t_tab_mvke,

matnr TYPE matnr,

vkorg TYPE vkorg,

vtweg TYPE vtweg.

TYPES: END OF t_tab_mvke.

TYPES: BEGIN OF t_tab_makt,

matnr TYPE matnr,

maktx TYPE maktx.

TYPES: END OF t_tab_makt.

TYPES: BEGIN OF t_tab_marc,

werks TYPE werks_d,

matnr TYPE matnr.

TYPES: END OF t_tab_marc.

TYPES: BEGIN OF t_tab_t023t,

matkl TYPE matkl,

wgbez TYPE wgbez.

TYPES: END OF t_tab_t023t.

TYPES: BEGIN OF t_tab_t134t,

mtart TYPE mtart,

mtbez TYPE mtbez.

TYPES: END OF t_tab_t134t.

TYPES: BEGIN OF t_tab_inner,

matnr TYPE matnr,

matkl TYPE matkl,

mtart TYPE mtart,

prdha TYPE prodh_d,

bismt TYPE bismt,

meins TYPE meins,

maktx TYPE maktx,

bwkey TYPE bwkey,

stprs TYPE stprs,

verpr TYPE verpr,

bwprh TYPE bwprh,

bwph1 TYPE bwph1,

vjbwh TYPE vjbwh,

vkorg TYPE vkorg,

vtweg TYPE vtweg.

TYPES: END OF t_tab_inner.

TYPES: BEGIN OF t_tab_globe,

matnr TYPE matnr,

matkl TYPE matkl,

mtart TYPE mtart,

prdha TYPE prodh_d,

bismt TYPE bismt,

meins TYPE meins,

stprs TYPE stprs,

verpr TYPE verpr,

bwprh TYPE bwprh,

bwph1 TYPE bwph1,

vjbwh TYPE vjbwh,

vkorg TYPE vkorg,

vtweg TYPE vtweg,

l_tex(70) TYPE c,

maktx TYPE maktx,

werks TYPE werks_d,

wgbez TYPE wgbez,

mtbez TYPE mtbez.

TYPES: END OF t_tab_globe.

TYPE-POOLS: slis.

*define internal tables...

DATA: g_tab_mara TYPE STANDARD TABLE OF t_tab_mara, "structure of mara

g_wa_mara LIKE LINE OF g_tab_mara.

DATA: g_tab_mbew TYPE STANDARD TABLE OF t_tab_mbew, "stucture of mbew

g_wa_mbew LIKE LINE OF g_tab_mbew.

DATA: g_tab_mvke TYPE STANDARD TABLE OF t_tab_mvke, "stucture of mvke

g_wa_mvke LIKE LINE OF g_tab_mvke.

DATA: g_tab_makt TYPE STANDARD TABLE OF t_tab_makt, "stucture of makt

g_wa_makt LIKE LINE OF g_tab_makt.

DATA: g_tab_marc TYPE STANDARD TABLE OF t_tab_marc, "stucture of marc

g_wa_marc LIKE LINE OF g_tab_marc.

DATA: g_tab_t023t TYPE STANDARD TABLE OF t_tab_t023t, "stucture of t023t

g_wa_t023t LIKE LINE OF g_tab_t023t.

DATA: g_tab_t134t TYPE STANDARD TABLE OF t_tab_t134t, "stucture of t134t

g_wa_t134t LIKE LINE OF g_tab_t134t.

DATA: g_tab_inner TYPE STANDARD TABLE OF t_tab_inner, "stucture for inner

g_wa_inner LIKE LINE OF g_tab_inner.

DATA: g_tab_globe TYPE STANDARD TABLE OF t_tab_globe, "stucture for global

g_wa_globe LIKE LINE OF g_tab_globe.

DATA: repid LIKE sy-repid,

l_tab_fieldcat TYPE slis_t_fieldcat_alv,

l_pos TYPE i.

DATA: fnam(10), fval(10).

*selection screen design...

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_pla LIKE marc-werks OBLIGATORY VALUE CHECK.

SELECT-OPTIONS: s_mgr FOR mara-matkl,

s_mty FOR mara-mtart,

s_mat FOR mara-matnr.

SELECTION-SCREEN SKIP.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-019.

PARAMETERS: p_dis RADIOBUTTON GROUP gr,

p_cha RADIOBUTTON GROUP gr.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.

repid = sy-repid.

*select the data from dbtales...

START-OF-SELECTION.

PERFORM get_data.

END-OF-SELECTION.

*to display the data in alv list...

PERFORM display_alv.

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data .

*select the fields from marc...

SELECT werks

matnr

FROM marc

INTO TABLE g_tab_marc

WHERE

werks = p_pla

AND

matnr IN s_mat.

IF NOT g_tab_marc[] IS INITIAL.

*select the fields from mara...

SELECT matnr

matkl

mtart

prdha

bismt

meins

FROM mara

INTO TABLE g_tab_mara

FOR ALL ENTRIES IN g_tab_marc

WHERE

matnr EQ g_tab_marc-matnr

AND

matkl IN s_mgr

AND

mtart IN s_mty.

**select the fields from mbew...

  • SELECT matnr

  • bwkey

  • stprs

  • verpr

  • bwprh

  • bwph1

  • vjbwh

  • FROM mbew

  • INTO TABLE g_tab_mbew

  • FOR ALL ENTRIES IN g_tab_marc

  • WHERE

  • matnr EQ g_tab_marc-matnr

  • AND

  • bwkey EQ g_tab_marc-werks.

*

*

ENDIF.

IF NOT g_tab_mara IS INITIAL.

SELECT matnr

bwkey

stprs

verpr

bwprh

bwph1

vjbwh

FROM mbew

INTO TABLE g_tab_mbew

FOR ALL ENTRIES IN g_tab_mara

WHERE

matnr EQ g_tab_mara-matnr.

  • AND

  • bwkey EQ g_tab_marc-werks.

*select the fields from mvke...

SELECT matnr

vkorg

vtweg

FROM mvke

INTO TABLE g_tab_mvke

FOR ALL ENTRIES IN g_tab_mara

WHERE

matnr EQ g_tab_mara-matnr.

*select the fields from makt...

SELECT matnr

maktx

FROM makt

INTO TABLE g_tab_makt

FOR ALL ENTRIES IN g_tab_mara

WHERE

matnr EQ g_tab_mara-matnr

AND

spras EQ sy-langu.

*select the fields from t023t...

SELECT matkl

wgbez

FROM

t023t

INTO TABLE g_tab_t023t

FOR ALL ENTRIES IN

g_tab_mara

WHERE

matkl = g_tab_mara-matkl

AND

spras EQ sy-langu.

*select the fields from t134t...

SELECT mtart

mtbez

FROM

t134t

INTO TABLE g_tab_t134t

FOR ALL ENTRIES IN

g_tab_mara

WHERE

mtart = g_tab_mara-mtart

AND

spras EQ sy-langu.

  • ENDIF.

LOOP AT g_tab_marc INTO g_wa_marc.

MOVE-CORRESPONDING g_wa_marc TO g_wa_globe.

READ TABLE g_tab_mara INTO g_wa_mara WITH KEY matnr = g_wa_marc-matnr.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING g_wa_mara TO g_wa_globe.

ENDIF.

READ TABLE g_tab_mbew INTO g_wa_mbew WITH KEY matnr = g_wa_marc-matnr

bwkey = g_wa_marc-werks.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING g_wa_mbew TO g_wa_globe.

ENDIF.

READ TABLE g_tab_makt INTO g_wa_makt WITH KEY matnr = g_wa_marc-matnr.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING g_wa_makt TO g_wa_globe.

ENDIF.

IF sy-subrc EQ 0.

READ TABLE g_tab_t023t INTO g_wa_t023t WITH KEY matkl = g_wa_mara-matkl.

MOVE-CORRESPONDING g_wa_t023t TO g_wa_globe.

ENDIF.

READ TABLE g_tab_t134t INTO g_wa_t134t WITH KEY mtart = g_wa_mara-mtart.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING g_wa_t134t TO g_wa_globe.

ENDIF.

LOOP AT g_tab_mvke INTO g_wa_mvke WHERE matnr = g_wa_marc-matnr.

MOVE-CORRESPONDING g_wa_mvke TO g_wa_globe.

CLEAR g_wa_mvke.

PERFORM sale_text.

APPEND g_wa_globe TO g_tab_globe.

ENDLOOP.

APPEND g_wa_globe TO g_tab_globe.

CLEAR g_wa_globe.

ENDLOOP.

SORT g_tab_globe.

DELETE ADJACENT DUPLICATES FROM g_tab_globe.

ENDIF.

*calling the FM read_text to get the sales text

ENDFORM. " get_data

&----


*& Form display_alv

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_alv .

PERFORM build_catalog.

PERFORM call_alv.

ENDFORM. " display_alv

&----


*& Form build_catalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_catalog .

PERFORM field_catalog USING l_pos 'MATNR' 'G_TAB_GLOBE' '18' text-003.

PERFORM field_catalog USING l_pos 'MAKTX' 'G_TAB_GLOBE' '40' text-004.

PERFORM field_catalog USING l_pos 'MATKL' 'G_TAB_GLOBE' '09' text-005.

PERFORM field_catalog USING l_pos 'WGBEZ' 'G_TAB_GLOBE' '20' text-006.

PERFORM field_catalog USING l_pos 'MTART' 'G_TAB_GLOBE' '08' text-007.

PERFORM field_catalog USING l_pos 'MTBEZ' 'G_TAB_GLOBE' '25' text-008.

PERFORM field_catalog USING l_pos 'PRDHA' 'G_TAB_GLOBE' '18' text-009.

PERFORM field_catalog USING l_pos 'BISMT' 'G_TAB_GLOBE' '18' text-010.

PERFORM field_catalog USING l_pos 'MEINS' 'G_TAB_GLOBE' '03' text-011.

PERFORM field_catalog USING l_pos 'STPRS' 'G_TAB_GLOBE' '11' text-012.

PERFORM field_catalog USING l_pos 'VERPR' 'G_TAB_GLOBE' '11' text-013.

PERFORM field_catalog USING l_pos 'BWPRH' 'G_TAB_GLOBE' '11' text-014.

PERFORM field_catalog USING l_pos 'BWPH1' 'G_TAB_GLOBE' '11' text-015.

PERFORM field_catalog USING l_pos 'VJBWH' 'G_TAB_GLOBE' '11' text-016.

PERFORM field_catalog USING l_pos 'VKORG' 'G_TAB_GLOBE' '04' text-020.

PERFORM field_catalog USING l_pos 'VTWEG' 'G_TAB_GLOBE' '06' text-018.

PERFORM field_catalog USING l_pos 'L_TEX' 'G_TAB_GLOBE' '70' text-017.

ENDFORM. " build_catalog

&----


*& Form field_catalog

&----


  • text

----


  • -->P_L_POS text

  • -->P_0759 text

  • -->P_0760 text

  • -->P_0761 text

  • -->P_TEXT_011 text

----


FORM field_catalog USING u_pos TYPE any

value(u_0759) TYPE any

value(u_0760) TYPE any

value(u_0761) TYPE any

u_text TYPE any.

DATA: l_wa_fieldcat TYPE slis_fieldcat_alv.

IF u_0759 EQ 'MATNR'.

l_wa_fieldcat-hotspot = 'X' .

l_wa_fieldcat-key = 'X'.

ENDIF.

ADD 1 TO u_pos.

l_wa_fieldcat-col_pos = u_pos.

l_wa_fieldcat-fieldname = u_0759.

l_wa_fieldcat-tabname = u_0760.

l_wa_fieldcat-outputlen = u_0761.

l_wa_fieldcat-reptext_ddic = u_text.

APPEND l_wa_fieldcat TO l_tab_fieldcat.

ENDFORM. " field_catalog

&----


*& Form call_alv

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM call_alv .

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = repid

i_callback_user_command = 'USER_COMMAND'

it_fieldcat = l_tab_fieldcat

TABLES

t_outtab = g_tab_globe.

ENDFORM. " call_alv

&----


*& Form CALL_TRANS

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM call_trans .

GET CURSOR FIELD fnam VALUE fval.

SET PARAMETER ID 'MAT' FIELD fval.

CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

ENDFORM. " CALL_TRANS

&----


*& Form call_trans1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM call_trans1 .

GET CURSOR FIELD fnam VALUE fval.

SET PARAMETER ID 'MAT' FIELD fval.

CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.

ENDFORM. " call_trans1

&----


*& Form USER_COMMAND

&----


  • text

----


  • -->UCOMM text

  • -->SELFIELD text

----


FORM user_command USING ucomm LIKE sy-ucomm

selfield TYPE slis_selfield.

  • DATA: p_prreg TYPE t158-prreg,

  • lv_matnr TYPE matnr.

  • p_prreg = 'ZN'.

READ TABLE g_tab_globe INTO g_wa_globe INDEX selfield-tabindex.

HIDE g_wa_globe-matnr.

CHECK sy-subrc = 0.

CASE ucomm.

WHEN '&IC1'.

IF p_dis = 'X'.

IF selfield-fieldname = 'MATNR'.

SET PARAMETER ID 'MAT' FIELD g_wa_globe-matnr.

CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

ENDIF.

ELSE.

IF selfield-fieldname = 'MATNR'.

SET PARAMETER ID 'MAT' FIELD g_wa_globe-matnr.

CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.

ENDIF.

ENDIF.

ENDCASE.

ENDFORM. "USER_COMMAND

&----


*& Form SALE_TEXT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sale_text .

DATA: l_id LIKE thead-tdid VALUE '0001',

l_lan LIKE thead-tdspras,

l_text LIKE thead-tdname,

l_obj LIKE thead-tdobject.

DATA: BEGIN OF l_text_str,

matnr TYPE matnr,

vkorg TYPE vkorg,

vtweg TYPE vtweg,

END OF l_text_str.

DATA: l_lines TYPE tline OCCURS 0 WITH HEADER LINE,

l_lines_wa LIKE LINE OF l_lines.

l_lan = 'EN'.

l_obj = 'MVKE'.

CLEAR l_lines[].

CLEAR l_text_str.

l_text_str-matnr = g_wa_globe-matnr.

l_text_str-vkorg = g_wa_globe-vkorg.

l_text_str-vtweg = g_wa_globe-vtweg.

l_text = l_text_str.

CLEAR g_wa_globe-l_tex.

CALL FUNCTION 'READ_TEXT'

EXPORTING

client = sy-mandt

id = l_id

language = l_lan

name = l_text

object = l_obj

TABLES

lines = l_lines

EXCEPTIONS

id = 1

language = 2

name = 3

not_found = 4

object = 5

reference_check = 6

wrong_access_to_archive = 7

OTHERS = 8.

IF sy-subrc = 0.

LOOP AT l_lines INTO l_lines_wa WHERE tdformat EQ '*'.

MOVE l_lines_wa-tdline TO g_wa_globe-l_tex.

CLEAR l_lines-tdline.

ENDLOOP.

ENDIF.

ENDFORM. " SALE_TEXT

regards..

seshu.

Message was edited by:

maddipatla Seshu chowdary