Skip to Content
0
Former Member
Nov 17, 2008 at 12:23 PM

Insert data from more than one table in ALV Grid

231 Views

Hello everybody!!!

I am an absolute beginner in SAP/ABAP development.

I ve seen various examples of displaying data from only one table in ALV Grid ( mostly they use sflight 😊 ).

What i want to do is to take data from three tables and do the same thing.

I have a screen with a custom container named "CC_ALV" and a button with fc "EXIT".

My code is the following :

First in the report:

&----


*& Report ZALVDEMO

*&

&----


*&

*&

&----


REPORT ZALVDEMO.

*data decleration

+tables : mkpf,mseg,makt.+

+data: begin of zAVLTest occurs 0,+

+mblnr like mkpf-mblnr,+

+mjahr like mkpf-mjahr,+

+matnr like mseg-matnr,+

+maktx like makt-maktx,+

+erfmg like mseg-erfmg,+

+erfme like mseg-erfme,+

+werks like mseg-werks,+

+lgort like mseg-lgort,+

+end of zAVLTest.+

+data ok_code TYPE sy-ucomm.+

+data GRID TYPE REF TO CL_GUI_ALV_GRID.+

+data G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.+

+* SELECTION SCREEN+

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

select-options: s_mblnr for mkpf-mblnr.

parameters: s_mjahr like mkpf-mjahr obligatory default sy-datum(4).

selection-screen skip.

select-options: s_matnr for mseg-matnr,

s_werks for mseg-werks,

s_lgort for mseg-lgort.

selection-screen end of block b1.

*database selection

start-of-selection.

*SET PF-STATUS 'MENU'.

perform select_mat_doc.

end-of-selection.

*display data

call screen 0001.

INCLUDE ZALVDEMO_SELECT_MAT_DOCF01.

Then the include file:

----


***INCLUDE ZALVDEMO_SELECT_MAT_DOCF01 .

----


&----


*& Form select_mat_doc

&----


+* text+

----


+* --> p1 text+

+* <-- p2 text+

----


+FORM select_mat_doc .+

+select * from mkpf INNER JOIN mseg on mkpfmblnr = msegmblnr and mkpfmjahr = msegmjahr+

inner join makt on maktmatnr = msegmatnr

into corresponding fields of table zAvlTest

where mseg~matnr in s_matnr and

mseg~werks in s_werks and

mseg~lgort in s_lgort and

mkpf~mblnr in s_mblnr and

mkpf~mjahr eq s_mjahr.

ENDFORM. " select_mat_doc

&----


*& Module pbo_stock OUTPUT

&----


* text

----


MODULE pbo_stock OUTPUT.

SET PF-STATUS 'MENU'.

IF G_CUSTOM_CONTAINER IS INITIAL.

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = 'CC_ALV'.

CREATE OBJECT GRID

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING I_STRUCTURE_NAME ='zalvtEST'

CHANGING IT_OUTTAB = gt_outtab[].

ENDIF.

ENDMODULE. " pbo_stock OUTPUT

&----


*& Module pai_stock INPUT

&----


* text

----


MODULE pai_stock INPUT.

* to react on oi_custom_events:

call method cl_gui_cfw=>dispatch.

CASE OK_CODE.

WHEN 'EXIT'.

write: ' Exit Push Button'.

WHEN OTHERS.

* do nothing

ENDCASE.

CLEAR OK_CODE.

ENDMODULE. " pai_stock INPUT

Thanks in advance anyone who reads that and hope to get a response soon!!! 😊

P.S : i didn't have time to go htrough every thread so if smth like this was asked before, plz forgive me for consuming your time.