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 grid display

Former Member
0 Likes
1,108

hi i am new to ABAP...

i have two data base tables mara,makt....

i want dislpa matnr meins maktx using alv grid display....

any one can help me in this issue.....

hi i am new to ABAP...

i have two data base tables mara,makt....

i want dislpa matnr meins maktx using alv grid display....

any one can help me in this issue.....

7 REPLIES 7
Read only

amit_khare
Active Contributor
0 Likes
1,074

Check this link -

http://www.sap-img.com/abap/sample-programs-on-alv-grid.htm

Regards,

Amit

Reward all helpful replies.

Read only

SantoshKallem
Active Contributor
0 Likes
1,074
Read only

Former Member
0 Likes
1,074

hi

follow the link below which will generate tyhe automatic code at end and u can copy that code to ur ABAP program.

click on this link and proceed as follows

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

Welcome!

• Home

• Start generating ALV -


choose this

• What is this about

• Personalized templates

Step1: give name, author, title and descri.(any chars for all)

Step2: fill with ur tables choose inner join

And follow the remaining steps as similarly

reward points if helpful

regards

sreeni

Read only

Former Member
0 Likes
1,074

Refer the following program and add the fields according your requirements:

REPORT  z_82235_test4                           .

TABLES: mara, makt.

TYPE-POOLS: slis.

TYPES: BEGIN OF tab,
          matnr TYPE matnr,
          matkl TYPE matkl,
          maktx TYPE maktx,
       END OF tab.

DATA: itab TYPE TABLE OF tab,
      wa LIKE LINE OF itab.



*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
      gd_tab_group type slis_t_sp_group_alv,
      gd_layout    type slis_layout_alv,
      gd_repid     like sy-repid.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.

* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you  more control of the final product.

* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
*               I.e. Field type may be required in-order for
*                    the 'TOTAL' function to work.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material No'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATKL'.
  fieldcatalog-seltext_m   = 'Group'.
  fieldcatalog-col_pos     = 2.
   fieldcatalog-outputlen   = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MAKTX'.
  fieldcatalog-seltext_m   = 'Description'.
  fieldcatalog-col_pos     = 1.
  fieldcatalog-outputlen   = 8.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.


endform.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
endform.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
  gd_repid = sy-repid.
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = gd_repid
*            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
*            i_callback_user_command = 'USER_COMMAND'
*            i_grid_title           = outtext
            is_layout               = gd_layout
            it_fieldcat             = fieldcatalog[]
*            it_special_groups       = gd_tabgroup
*            IT_EVENTS                = GT_XEVENTS
            i_save                  = 'X'
*            is_variant              = z_template

       tables
            t_outtab                = itab
       exceptions
            program_error           = 1
            others                  = 2.
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
endform.                    " DISPLAY_ALV_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.

SELECT F~matnr F~matkl P~maktx
    INTO table itab
    FROM mara AS F INNER JOIN makt AS P
           ON F~matnr = P~matnr.

endform.                    " DATA_RETRIEVAL

Read only

Former Member
0 Likes
1,074

declare fieldcatalog variable in dat.

data : d_fieldcat type slis_ t_fieldcat_alv,

d_fieldcat_wa type slis_fieldcat_alv.

d_fielcat_wa-matnr = 'MATNR'.

d_fieldcat_wa-seltext_i = 'material no'.

d_fieldcat_wa-col_pos = 1.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

d_fielcat_wa-matnr = 'MAKTX'.

d_fieldcat_wa-seltext_i = 'material description'.

d_fieldcat_wa-col_pos = 2.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

d_fielcat_wa-matnr = 'MEINS'.

d_fieldcat_wa-seltext_i = 'unit'.

d_fieldcat_wa-col_pos = 3.

append d_fieldcat_wa to d_fieldcat.

clear d_fieldcat_wa.

call function REUSE_ALV_GRID_DISPLAY.

exporting

programname = gd_repid.

fieldcat = d_fieldcat.

importing.

t_outtab = itab.

exceptions.

reward with points. if u find this as helpful

Message was edited by:

Vinutha YV

Read only

Former Member
0 Likes
1,074

Hi hari prasad,

go through this urlls:

1. Please give me general info on ALV.

http://www.sapfans.com/forums/viewtopic.php?t=58286

http://www.sapfans.com/forums/viewtopic.php?t=76490

http://www.sapfans.com/forums/viewtopic.php?t=20591

http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.

2. How do I program double click in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=11601

http://www.sapfans.com/forums/viewtopic.php?t=23010

3. How do I add subtotals (I have problem to add them)...

http://www.sapfans.com/forums/viewtopic.php?t=20386

http://www.sapfans.com/forums/viewtopic.php?t=85191

http://www.sapfans.com/forums/viewtopic.php?t=88401

http://www.sapfans.com/forums/viewtopic.php?t=17335

4. How to add list heading like top-of-page in ABAP lists?

http://www.sapfans.com/forums/viewtopic.php?t=58775

http://www.sapfans.com/forums/viewtopic.php?t=60550

http://www.sapfans.com/forums/viewtopic.php?t=16629

5. How to print page number / total number of pages X/XX in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)

6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.

http://www.sapfans.com/forums/viewtopic.php?t=64320

http://www.sapfans.com/forums/viewtopic.php?t=44477

7. How can I set the cell color in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=52107

8. How do I print a logo/graphics in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=81149

http://www.sapfans.com/forums/viewtopic.php?t=35498

http://www.sapfans.com/forums/viewtopic.php?t=5013

9. How do I create and use input-enabled fields in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=84933

http://www.sapfans.com/forums/viewtopic.php?t=69878

10. How can I use ALV for reports that are going to be run in background?

http://www.sapfans.com/forums/viewtopic.php?t=83243

http://www.sapfans.com/forums/viewtopic.php?t=19224

11. How can I display an icon in ALV? (Common requirement is traffic light icon).

http://www.sapfans.com/forums/viewtopic.php?t=79424

http://www.sapfans.com/forums/viewtopic.php?t=24512

12. How can I display a checkbox in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=88376

http://www.sapfans.com/forums/viewtopic.php?t=40968

http://www.sapfans.com/forums/viewtopic.php?t=6919

Go thru these programs they may help u to try on some hands on

ALV Demo program

BCALV_DEMO_HTML

BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode

BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode

BCALV_GRID_DEMO Simple ALV Control Call Demo Program

BCALV_TREE_DEMO Demo for ALV tree control

BCALV_TREE_SIMPLE_DEMO

BC_ALV_DEMO_HTML_D0100

Go through this program/.

REPORT zbt_rep NO STANDARD PAGE HEADING

MESSAGE-ID zbt_msg.

TABLES:mara.

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

SELECT-OPTIONS:s_matnr FOR mara-matnr OBLIGATORY.

PARAMETERS:p_mtart TYPE mara-mtart.

SELECTION-SCREEN:END OF BLOCK b1.

TYPES:BEGIN OF ty_mat,

matnr TYPE mara-matnr,

mtart TYPE mara-mtart,

meins TYPE mara-meins,

END OF ty_mat,

BEGIN OF ty_uom_text,

msehi TYPE t006a-msehi,

msehl TYPE t006a-msehl,

END OF ty_uom_text,

BEGIN OF ty_output,

matnr TYPE mara-matnr,

mtart TYPE mara-mtart,

meins TYPE mara-meins,

msehl TYPE t006a-msehl,

END OF ty_output.

DATA: it_mat TYPE STANDARD TABLE OF ty_mat WITH HEADER LINE,

it_uom_text TYPE STANDARD TABLE OF ty_uom_text WITH HEADER LINE,

it_output TYPE STANDARD TABLE OF ty_output WITH HEADER LINE.

INITIALIZATION.

s_matnr-sign = 'I'.

s_matnr-option = 'BT'.

s_matnr-low = '1'.

s_matnr-high = '1000'.

APPEND s_matnr.

AT SELECTION-SCREEN.

IF s_matnr-high IS INITIAL.

  • Make an entry in all required fields

MESSAGE e001(zbt_msg).

ENDIF.

START-OF-SELECTION.

SELECT matnr mtart meins FROM mara INTO TABLE it_mat

WHERE matnr IN s_matnr AND

mtart = p_mtart.

SELECT msehi msehl FROM t006a INTO TABLE it_uom_text

WHERE spras = sy-langu.

END-OF-SELECTION.

LOOP AT it_mat.

it_output-matnr = it_mat-matnr.

it_output-mtart = it_mat-mtart.

it_output-meins = it_mat-meins.

READ TABLE it_uom_text WITH KEY msehi = it_mat-meins.

IF sy-subrc = 0.

it_output-msehl = it_uom_text-msehl.

ENDIF.

APPEND it_output.

CLEAR it_output.

ENDLOOP.

IF NOT it_output[] IS INITIAL.

LOOP AT it_output.

WRITE:/ it_output-matnr,it_output-mtart,

it_output-meins,it_output-msehl.

CLEAR it_output.

ENDLOOP.

ELSE.

MESSAGE s002(zbt_msg).

LEAVE LIST-PROCESSING.

ENDIF.

TOP-OF-PAGE.

WRITE:/ 'MATREIAL INFORMATION'.

*********Rewards some points.

Rgds,

P.Naganjana Reddy

Read only

Former Member
0 Likes
1,074

Hi,

Check this sample prg.

I think i would be useful for you.

SIMPLE ALV PROGRAM

USING TWO TABLES

REPORT ZEASALV_04 .

TABLES : zeastable_02,zeastable_04.

TYPE-POOLS : slis.

TYPES : BEGIN OF fieldst,

name LIKE zeastable_02-name,

znum LIKE zeastable_02-znum,

empno LIKE zeastable_04-empno,

zempsalary LIKE zeastable_04-zempsalary,

END OF fieldst.

DATA itab TYPE TABLE OF fieldst WITH HEADER LINE.

DATA: w_report_id LIKE sy-repid. "Program name

DATA: w_title TYPE lvc_title VALUE 'Assignment 1 in ALV'.

DATA: w_layout TYPE slis_layout_alv. "Layout setup

DATA: w_fieldcat TYPE slis_t_fieldcat_alv. "Field Catlog

START-OF-SELECTION.

SELECT-OPTIONS employee FOR zeastable_04-empno.

SELECT zeastable_02name zeastable_02znum

zeastable_04empno zeastable_04zempsalary

INTO CORRESPONDING FIELDS OF TABLE itab FROM

zeastable_02 INNER JOIN zeastable_04 ON

zeastable_02name = zeastable_04name

WHERE zeastable_04~empno IN employee.

*----


  • LOOP AT itab.

  • WRITE 😕 itab-name,itab-znum, itab-empno,itab-zempsalary.

  • ENDLOOP.

  • ENDSELECT.

  • WRITE 😕 itab.

*----


w_report_id = sy-repid.

PERFORM i_layout CHANGING w_layout.

PERFORM i_fieldcat CHANGING w_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = 'ZEASALV_04'

i_grid_title = w_title

is_layout = w_layout

it_fieldcat = w_fieldcat

i_save = 'A'

TABLES

t_outtab = itab

EXCEPTIONS

program_error = 1

OTHERS = 2

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

PERFORM i_layout CHANGING w_layout.

PERFORM i_fieldcat CHANGING w_fieldcat.

PERFROM i_layout.

&----


*& Form i_layout

&----


  • text

----


  • <--P_W_LAYOUT text

----


form i_layout changing p_w_layout.

clear w_layout.

w_layout-colwidth_optimize = 'X'.

w_layout-edit = ' '.

endform. " i_layout

PERFORM i_fieldcat

&----


*& Form i_fieldcat

&----


  • text

----


  • <--P_W_FEILDCAT text

----


form i_fieldcat changing p_w_feildcat.

data: l_line_fieldcat type slis_fieldcat_alv.

clear l_line_fieldcat.

l_line_fieldcat-fieldname = 'NAME'.

l_line_fieldcat-ref_tabname = 'itab'.

l_line_fieldcat-seltext_m = 'NAME'.

  • l_line_fieldcat-key = 'X'.

append l_line_fieldcat to w_fieldcat.

clear l_line_fieldcat.

l_line_fieldcat-fieldname = 'ZNUM'.

l_line_fieldcat-ref_tabname = 'itab'.

l_line_fieldcat-seltext_m = 'NUMBER'.

  • l_line_fieldcat-key = 'X'.

append l_line_fieldcat to w_fieldcat.

clear l_line_fieldcat.

l_line_fieldcat-fieldname = 'EMPNO'.

l_line_fieldcat-ref_tabname = 'itab'.

l_line_fieldcat-seltext_m = 'EMPLNUM'.

*l_line_fieldcat-key = 'X'.

append l_line_fieldcat to w_fieldcat.

clear l_line_fieldcat.

l_line_fieldcat-fieldname = 'ZEMPSALARY'.

l_line_fieldcat-ref_tabname = 'itab'.

l_line_fieldcat-seltext_m = 'SALARY'.

*l_line_fieldcat-key = 'X'.

append l_line_fieldcat to w_fieldcat.

endform. " i_fieldcat

Reward Points if it is useful to you.