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: 

how to create ALV grid display

Former Member

If an Internal table has fields from three DDIC tables ex. EKPO ,EKPO , MSEG..How to use this Internal table to create an ALV Grid Display..what would be the IStruct name

1 ACCEPTED SOLUTION

Former Member

Hi

ABAP List Viewer

Simple ALV report

http://www.sapgenie.com/abap/controls/alvgrid.htm

http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox

ALV

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

Check the program in the following link:

http://sap-img.com/abap/display-secondary-list-using-alv-grid.htm

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

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

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

13. Top-of-page in ALV

14. ALV Group Heading

http://www.sap-img.com/fu037.htm

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

15. ALV output to PDF conversion

It has an example code for PDF Conversion.

http://www.erpgenie.com/abap/code/abap51.htm

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

The common features of report are column alignment, sorting, filtering, subtotals, totals etc. To implement these, a lot of coding and logic is to be put. To avoid that we can use a concept called ABAP List Viewer (ALV).

This helps us to implement all the features mentioned very effectively.

Using ALV, We can have three types of reports:

1. Simple Report

2. Block Report

3. Hierarchical Sequential Report

There are some function modules which will enable to produce the above reports without much effort.

All the definitions of internal tables, structures and constants are declared in a type-pool called SLIS.

1. SIMPLE REPORT.

The important function modules are

a. Reuse_alv_list_display

b. Reuse_alv_fieldcatalog_merge

c. Reuse_alv_events_get

d. Reuse_alv_commentary_write

e. Reuse_alv_grid_display

A. REUSE_ALV_LIST_DISPLAY : This is the function module which prints the data.

The important parameters are :

I. Export :

i. I_callback_program : report id

ii. I_callback_pf_status_set : routine where a user can set his own pf status or change the functionality of the existing pf status

iii. I_callback_user_command : routine where the function codes are handled

iv. I_structure name : name of the dictionary table

v. Is_layout : structure to set the layout of the report

vi. It_fieldcat : internal table with the list of all fields and their attributes which are to be printed (this table can be populated automatically by the function module REUSE_ALV_FIELDCATALOG_MERGE

vii. It_events : internal table with a list of all possible events of ALV and their corresponding form names.

II. Tables :

i. t_outtab : internal table with the data to be output

B. REUSE_ALV_FIELDCATALOG_MERGE : This function module is used to populate a fieldcatalog which is essential to display the data in ALV. If the output data is from a single dictionary table and all the columns are selected, then we need not exclusively create the field catalog. Its enough to mention the table name as a parameter(I_structure name) in the REUSE_ALV_LIST_DISPLAY. But in other cases we need to create it.

The Important Parameters are :

I. Export :

i. I_program_name : report id

ii. I_internal_tabname : the internal output table

iii. I_inclname : include or the report name where all the dynamic forms are handled.

II Changing

ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV which is

declared in the type pool SLIS.

C. REUSE_ALV_EVENTS_GET : Returns table of possible events for a list type

Parameters :

I. Import :

Et_Events : The event table is returned with all possible CALLBACK events

for the specified list type (column 'NAME'). For events to be processed by Callback, their 'FORM' field must be filled. If the field is initialized, the event is ignored. The entry can be read from the event table, the field 'FORM' filled and the entry modified using constants from the type pool SALV.

II. Export :

I_List_type :

0 = simple list REUSE_ALV_LIST_DISPLAY

1 = hierarchcal-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY

2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND

3 = hierarchical-sequential block list

REUSE_ALV_BLOCK_LIST_HS_APPEND

D. REUSE_ALV_COMMENTARY_WRITE : This is used in the Top-of-page event to print the headings and other comments for the list.

Parameters :

I. it_list_commentary : internal table with the headings of the type slis_t_listheader.

This internal table has three fields :

Typ : ‘H’ – header, ‘S’ – selection , ‘A’ - action

Key : only when typ is ‘S’.

Info : the text to be printed

E. REUSE_ALV_GRID_DISPLAY : A new function in 4.6 version, to display the results in grid rather than as a preview.

Parameters : same as reuse_alv_list_display

This is an example for simple list.

2. BLOCK REPORT

This is used to have multiple lists continuously.

The important functions used in this report are:

A. REUSE_ALV_BLOCK_LIST_INIT

B. REUSE_ALV_BLOCK_LIST_APPEND

C. REUSE_ALV_BLOCK_LIST_HS_APPEND

D. REUSE_ALV_BLOCK_LIST_DISPLAY

A. REUSE_ALV_BLOCK_LIST_INIT

Parameters:

I. I_CALLBACK_PROGRAM

II. I_CALLBACK_PF_STATUS_SET

III. I_CALLBACK_USER_COMMAND

This function module is used to set the default gui status etc.

B. REUSE_ALV_BLOCK_LIST_APPEND

Parameters :

Export :

I. is_layout : layout settings for block

II. it_fieldcat : field catalog

III. i_tabname : internal table name with output data

IV. it_events : internal table with all possible events

Tables :

i. t_outtab : internal table with output data.

This function module adds the data to the block.

Repeat this function for all the different blocks to be displayed one after the other.

C. REUSE_ALV_BLOCK_LIST_HS_APPEND

This function module is used for hierarchical sequential blocks.

D. REUSE_ALV_BLOCK_LIST_DISPLAY

Parameters : All the parameters are optional.

This function module display the list with data appended by the above function.

Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used.

3. Hierarchical reports :

Hierarchical sequential list output.

The function module is

A. REUSE_ALV_HIERSEQ_LIST_DISPLAY

Parameters:

I. Export:

i. I_CALLBACK_PROGRAM

ii. I_CALLBACK_PF_STATUS_SET

iii. I_CALLBACK_USER_COMMAND

iv. IS_LAYOUT

v. IT_FIELDCAT

vi. IT_EVENTS

vii. i_tabname_header : Name of the internal table in the program containing the

output data of the highest hierarchy level.

viii. i_tabname_item : Name of the internal table in the program containing the

output data of the lowest hierarchy level.

ix. is_keyinfo : This structure contains the header and item table field

names which link the two tables (shared key).

II. Tables

i. t_outtab_header : Header table with data to be output

ii. t_outtab_item : Name of the internal table in the program containing the

output data of the lowest hierarchy level.

slis_t_fieldcat_alv : This internal table contains the field attributes. This internal table can be populated automatically by using ‘REUSE_ALV_FIELDCATALOG_MERGE’.

Important Attributes :

A. col_pos : position of the column

B. fieldname : internal fieldname

C. tabname : internal table name

D. ref_fieldname : fieldname (dictionary)

E. ref_tabname : table (dictionary)

F. key(1) : column with key-color

G. icon(1) : icon

H. symbol(1) : symbol

I. checkbox(1) : checkbox

J. just(1) : (R)ight (L)eft (C)ent.

K. do_sum(1) : sum up

L. no_out(1) : (O)blig.(X)no out

M. outputlen : output length

N. seltext_l : long key word

O. seltext_m : middle key word

P. seltext_s : short key word

Q. reptext_ddic : heading (ddic)

R. ddictxt(1) : (S)hort (M)iddle (L)ong

S. datatype : datatype

11 REPLIES 11

Former Member

Hi

ABAP List Viewer

Simple ALV report

http://www.sapgenie.com/abap/controls/alvgrid.htm

http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox

ALV

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

Check the program in the following link:

http://sap-img.com/abap/display-secondary-list-using-alv-grid.htm

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

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

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

13. Top-of-page in ALV

14. ALV Group Heading

http://www.sap-img.com/fu037.htm

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

15. ALV output to PDF conversion

It has an example code for PDF Conversion.

http://www.erpgenie.com/abap/code/abap51.htm

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

The common features of report are column alignment, sorting, filtering, subtotals, totals etc. To implement these, a lot of coding and logic is to be put. To avoid that we can use a concept called ABAP List Viewer (ALV).

This helps us to implement all the features mentioned very effectively.

Using ALV, We can have three types of reports:

1. Simple Report

2. Block Report

3. Hierarchical Sequential Report

There are some function modules which will enable to produce the above reports without much effort.

All the definitions of internal tables, structures and constants are declared in a type-pool called SLIS.

1. SIMPLE REPORT.

The important function modules are

a. Reuse_alv_list_display

b. Reuse_alv_fieldcatalog_merge

c. Reuse_alv_events_get

d. Reuse_alv_commentary_write

e. Reuse_alv_grid_display

A. REUSE_ALV_LIST_DISPLAY : This is the function module which prints the data.

The important parameters are :

I. Export :

i. I_callback_program : report id

ii. I_callback_pf_status_set : routine where a user can set his own pf status or change the functionality of the existing pf status

iii. I_callback_user_command : routine where the function codes are handled

iv. I_structure name : name of the dictionary table

v. Is_layout : structure to set the layout of the report

vi. It_fieldcat : internal table with the list of all fields and their attributes which are to be printed (this table can be populated automatically by the function module REUSE_ALV_FIELDCATALOG_MERGE

vii. It_events : internal table with a list of all possible events of ALV and their corresponding form names.

II. Tables :

i. t_outtab : internal table with the data to be output

B. REUSE_ALV_FIELDCATALOG_MERGE : This function module is used to populate a fieldcatalog which is essential to display the data in ALV. If the output data is from a single dictionary table and all the columns are selected, then we need not exclusively create the field catalog. Its enough to mention the table name as a parameter(I_structure name) in the REUSE_ALV_LIST_DISPLAY. But in other cases we need to create it.

The Important Parameters are :

I. Export :

i. I_program_name : report id

ii. I_internal_tabname : the internal output table

iii. I_inclname : include or the report name where all the dynamic forms are handled.

II Changing

ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV which is

declared in the type pool SLIS.

C. REUSE_ALV_EVENTS_GET : Returns table of possible events for a list type

Parameters :

I. Import :

Et_Events : The event table is returned with all possible CALLBACK events

for the specified list type (column 'NAME'). For events to be processed by Callback, their 'FORM' field must be filled. If the field is initialized, the event is ignored. The entry can be read from the event table, the field 'FORM' filled and the entry modified using constants from the type pool SALV.

II. Export :

I_List_type :

0 = simple list REUSE_ALV_LIST_DISPLAY

1 = hierarchcal-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY

2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND

3 = hierarchical-sequential block list

REUSE_ALV_BLOCK_LIST_HS_APPEND

D. REUSE_ALV_COMMENTARY_WRITE : This is used in the Top-of-page event to print the headings and other comments for the list.

Parameters :

I. it_list_commentary : internal table with the headings of the type slis_t_listheader.

This internal table has three fields :

Typ : ‘H’ – header, ‘S’ – selection , ‘A’ - action

Key : only when typ is ‘S’.

Info : the text to be printed

E. REUSE_ALV_GRID_DISPLAY : A new function in 4.6 version, to display the results in grid rather than as a preview.

Parameters : same as reuse_alv_list_display

This is an example for simple list.

2. BLOCK REPORT

This is used to have multiple lists continuously.

The important functions used in this report are:

A. REUSE_ALV_BLOCK_LIST_INIT

B. REUSE_ALV_BLOCK_LIST_APPEND

C. REUSE_ALV_BLOCK_LIST_HS_APPEND

D. REUSE_ALV_BLOCK_LIST_DISPLAY

A. REUSE_ALV_BLOCK_LIST_INIT

Parameters:

I. I_CALLBACK_PROGRAM

II. I_CALLBACK_PF_STATUS_SET

III. I_CALLBACK_USER_COMMAND

This function module is used to set the default gui status etc.

B. REUSE_ALV_BLOCK_LIST_APPEND

Parameters :

Export :

I. is_layout : layout settings for block

II. it_fieldcat : field catalog

III. i_tabname : internal table name with output data

IV. it_events : internal table with all possible events

Tables :

i. t_outtab : internal table with output data.

This function module adds the data to the block.

Repeat this function for all the different blocks to be displayed one after the other.

C. REUSE_ALV_BLOCK_LIST_HS_APPEND

This function module is used for hierarchical sequential blocks.

D. REUSE_ALV_BLOCK_LIST_DISPLAY

Parameters : All the parameters are optional.

This function module display the list with data appended by the above function.

Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used.

3. Hierarchical reports :

Hierarchical sequential list output.

The function module is

A. REUSE_ALV_HIERSEQ_LIST_DISPLAY

Parameters:

I. Export:

i. I_CALLBACK_PROGRAM

ii. I_CALLBACK_PF_STATUS_SET

iii. I_CALLBACK_USER_COMMAND

iv. IS_LAYOUT

v. IT_FIELDCAT

vi. IT_EVENTS

vii. i_tabname_header : Name of the internal table in the program containing the

output data of the highest hierarchy level.

viii. i_tabname_item : Name of the internal table in the program containing the

output data of the lowest hierarchy level.

ix. is_keyinfo : This structure contains the header and item table field

names which link the two tables (shared key).

II. Tables

i. t_outtab_header : Header table with data to be output

ii. t_outtab_item : Name of the internal table in the program containing the

output data of the lowest hierarchy level.

slis_t_fieldcat_alv : This internal table contains the field attributes. This internal table can be populated automatically by using ‘REUSE_ALV_FIELDCATALOG_MERGE’.

Important Attributes :

A. col_pos : position of the column

B. fieldname : internal fieldname

C. tabname : internal table name

D. ref_fieldname : fieldname (dictionary)

E. ref_tabname : table (dictionary)

F. key(1) : column with key-color

G. icon(1) : icon

H. symbol(1) : symbol

I. checkbox(1) : checkbox

J. just(1) : (R)ight (L)eft (C)ent.

K. do_sum(1) : sum up

L. no_out(1) : (O)blig.(X)no out

M. outputlen : output length

N. seltext_l : long key word

O. seltext_m : middle key word

P. seltext_s : short key word

Q. reptext_ddic : heading (ddic)

R. ddictxt(1) : (S)hort (M)iddle (L)ong

S. datatype : datatype

Former Member
0 Kudos

Hi,

Here are examples for ALV Grid -

Hope this helps.

ashish

Former Member
0 Kudos

Hi,

If you have a DDIC structure that matches your output columns...Then you can pass the DDIC structure to get the field catalog and then pass it to the alv

Otherwise..You have to build the field catalog internal table in the program..

Thanks

naren

Former Member
0 Kudos

hI,

Pass the internal table name instead of structure in caps and in quotes.

Thank you.

Former Member
0 Kudos

HI,

TABLES:MARA.

DATA:BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

ERSDA LIKE MARA-ERSDA,

ERNAM LIKE MARA-ERNAM,

MBRSH LIKE MARA-MBRSH,

END OF ITAB.

TYPE-POOLS:SLIS.

DATA:FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = SY-REPID

I_INTERNAL_TABNAME = 'ITAB' "<b>ur internal table</b>

I_INCLNAME = SY-REPID

CHANGING

CT_FIELDCAT = FIELDCAT1.

<b>*fill ur internal table</b>

SELECT * FROM MARA INTO CORRESPONDING FIELDS OF

TABLE ITAB UP TO 20 ROWS.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = FIELDCAT1

TABLES

T_OUTTAB = ITAB.

rgds,

bharat.

Former Member
0 Kudos

Hi Balram,

you can create your own internal table , might be type of a structure with all the fields you require.

eg : Types : begin of ty_itab,

fld1 type tab1-fld,

fld2 type tab2-fld,

fld3 type tab3-fld,

end of ty_itab.

data : itab type standard table of ty_itab.

Reward If Useful,

Regards,

Chitra

Former Member
0 Kudos

hi balram,

using that internal table build the field catelog for the fields which you want to display the fields in grid output.

structure for field ctelog is <b>slis_fieldcat_alv</b>.

ex:

DATA : ls_fieldcat TYPE slis_fieldcat_alv.

and pass that field catelog to REUSE_ALV_GRID_DISPLAY fm.

Reward points if useful

Chandra

Former Member
0 Kudos

Hi,

Use this code, i hope it will help you

TYPE-POOLS: SLIS.

TABLES: MARA.

DATA: I_REPID LIKE SY-REPID.

DATA: I_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.

I_REPID = SY-REPID.

SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.

PERFORM GET_DATA.

PERFORM DISPLAY.

FORM GET_DATA.

SELECT MATNR PSTAT LVORM FROM MARA INTO CORRESPONDING FIELDS OF TABLE I_MARA WHERE MATNR IN S_MATNR.

ENDFORM.

FORM DISPLAY.

call function 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = I_REPID

I_STRUCTURE_NAME = 'MARA'

tables

t_outtab = I_MARA

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.

IF USEFULL REWARD

harimanjesh_an
Active Participant
0 Kudos

hi balram,

Use FM 'REUSE_ALV_GRID_DISPLAY' to display ALV grid. Before this u have to populate ur field catalog and layout of grid.

<b>

DATA : gt_fieldcat TYPE slis_t_fieldcat_alv, "Field Catalog

gs_layout TYPE slis_layout_alv. "Layout Structure</b>

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = gs_layout " Layout of ur GRID

it_fieldcat = gt_fieldcat[] " Field Catalog of GRID

TABLES

t_outtab = t_emp[] " Data to be displayed

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.

Reward me if useful..........

Harimanjesh AN

Former Member
0 Kudos

Hi balram,

just try this code by using se38.nothing can change.


TABLES VBAK,VBAP.
TYPE-POOLS SLIS.
* Data Declaration
TYPES: BEGIN OF T_VBAK,
      VBELN TYPE VBAK-VBELN,
      ERDAT TYPE VBAK-ERDAT,
      ERNAM TYPE VBAK-ERNAM,
      AUDAT TYPE VBAK-AUDAT,
      POSNR TYPE VBAP-POSNR,
      MATNR TYPE VBAP-MATNR,
      LINE_COLOR(4) TYPE C,
      END OF T_VBAK.

DATA: IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0,
      WA_VBAK TYPE T_VBAK.

* ALV Data Declaration
DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
      GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
      GD_REPID TYPE SY-REPID,
*      I_EVENTS TYPE SLIS_T_EVENT,
*      W_EVENTS LIKE LINE OF I_EVENTS.

START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BLD_FLDCAT.
PERFORM BLD_LAYOUT.
PERFORM DISPLAY_ALV_REPORT.


* Build Field Catalog for ALV Report
FORM BLD_FLDCAT.

FLDCAT-FIELDNAME = 'VBELN'.
FLDCAT-SELTEXT_M = 'Sales Document'.
FLDCAT-COL_POS = 0.
*FLDCAT-EMPHASIZE = 'C411'.
FLDCAT-OUTPUTLEN = 20.
FLDCAT-KEY = 'X'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'ERDAT'.
FLDCAT-SELTEXT_L = 'Record Date created'.
FLDCAT-COL_POS = 1.
FLDCAT-KEY = 'X'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'ERNAM'.
FLDCAT-SELTEXT_L = 'Cteated Object Person Name'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'AUDAT'.
FLDCAT-SELTEXT_M = 'Document Date'.
FLDCAT-COL_POS = 3.
FLDCAT-EMPHASIZE = 'C110'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'POSNR'.
FLDCAT-SELTEXT_L = 'Sales Document item'.
FLDCAT-COL_POS = 4.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'MATNR'.
FLDCAT-SELTEXT_L = 'Material Number’.
FLDCAT-COL_POS = 5.
FLDCAT-OUTPUTLEN = 60.
FLDCAT-DO_SUM = 'X'.
FLDCAT-DATATYPE = 'CURR'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

ENDFORM.


* Build Layout for ALV Grid Report

FORM BLD_LAYOUT.

GD_LAYOUT-NO_INPUT = 'X'.
GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.

ENDFORM.


* Display report using ALV grid

FORM DISPLAY_ALV_REPORT.

DATA T_EVENT TYPE SLIS_T_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
 EXPORTING
   I_LIST_TYPE           = 0
 IMPORTING
   ET_EVENTS             = T_EVENT.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

GD_REPID = SY-REPID.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM                = GD_REPID
   IS_LAYOUT                         = GD_LAYOUT
   I_CALLBACK_HTML_TOP_OF_PAGE       = 'TOP_OF_PAGE_SPLIT'
   IT_FIELDCAT                       = FLDCAT[]
   I_SAVE                            = 'X'
  TABLES
    T_OUTTAB                          = IT_VBAK
 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.


* Retrieve data from VBAK table and populate itab IT_VBAK

FORM DATA_RETRIEVAL.

DATA LD_COLOR(1) TYPE C.

SELECT K~VBELN K~ERDAT K~ERNAM K~AUDAT P~POSNR P~MATNR FROM VBAK AS K INNER JOIN VBAP AS P 
ON K~VBELN = P~VBELN
INTO TABLE IT_VBAK.

LOOP AT IT_VBAK INTO WA_VBAK.
LD_COLOR = LD_COLOR + 1.
IF LD_COLOR = 8.
  LD_COLOR = 1.
ENDIF.
CONCATENATE 'C' LD_COLOR '10' INTO WA_VBAK-LINE_COLOR.
MODIFY IT_VBAK FROM WA_VBAK.
ENDLOOP.

ENDFORM.

FORM TOP_OF_PAGE.
DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
      W_HEADER TYPE SLIS_LISTHEADER.

W_HEADER-TYP = 'H'.
W_HEADER-INFO = 'WELCOME HEADER LIST'.
APPEND W_HEADER TO T_HEADER.

W_HEADER-TYP = 'S'.
W_HEADER-KEY = 'REPORT:'.
W_HEADER-INFO = SY-REPID.
APPEND W_HEADER TO T_HEADER.

W_HEADER-TYP = 'S'.
W_HEADER-KEY = 'DATE:'.
CONCATENATE SY-DATUM+4(2) ' / ' SY-DATUM+6(2) ' / ' SY-DATUM(4) INTO W_HEADER-INFO.
APPEND W_HEADER TO T_HEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
  EXPORTING
    IT_LIST_COMMENTARY       = T_HEADER.

ENDFORM.

FORM TOP_OF_PAGE_SPLIT USING R_TOP TYPE REF TO CL_DD_DOCUMENT.

DATA: S_TAB TYPE SDYDO_TEXT_TABLE,
      C_AREA TYPE REF TO CL_DD_AREA,
      TEXT TYPE SDYDO_TEXT_ELEMENT.

DATA: BEGIN OF TAB_TEXT OCCURS 0,
      TEXT TYPE SDYDO_TEXT_ELEMENT,
      END OF TAB_TEXT.

CALL METHOD R_TOP->INITIALIZE_DOCUMENT.

CALL METHOD R_TOP->VERTICAL_SPLIT
    EXPORTING
      SPLIT_AREA = R_TOP
      SPLIT_WIDTH = '70%'
    IMPORTING
      RIGHT_AREA = C_AREA.
IF SY-SUBRC <> 0.
*    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


TAB_TEXT-TEXT = 'GEMS TECHNO SOLUTIONS PVT LIMITED'.
APPEND TAB_TEXT.
TAB_TEXT-TEXT = 'PLOT NO.100,SECTOR 1'.
APPEND TAB_TEXT.
TAB_TEXT-TEXT = 'MVP DOUBLE ROAD'.
APPEND TAB_TEXT.
TAB_TEXT-TEXT = 'MVP COLONY,VIZAG'.
APPEND TAB_TEXT.

S_TAB[] = TAB_TEXT[].

CALL METHOD C_AREA->ADD_TEXT
    EXPORTING
      TEXT_TABLE    = S_TAB
      FIX_LINES     = 'X'
     SAP_FONTSIZE  = CL_DD_DOCUMENT=>MEDIUM
     SAP_EMPHASIS  = CL_DD_DOCUMENT=>STRONG.

TEXT = 'REPORT:'.
CALL METHOD R_TOP->ADD_TEXT
    EXPORTING
      TEXT         = TEXT
      SAP_EMPHASIS = 'STRONG'.

CALL METHOD R_TOP->ADD_GAP
    EXPORTING
      WIDTH = 2.

TEXT = SY-REPID.
CALL METHOD R_TOP->ADD_TEXT
    EXPORTING
      TEXT         = TEXT
      SAP_STYLE    = 'KEY'.

CALL METHOD R_TOP->NEW_LINE.

TEXT = 'DATE:'.
CALL METHOD R_TOP->ADD_TEXT
    EXPORTING
      TEXT        = TEXT
      SAP_EMPHASIS = 'STRONG'.

CALL METHOD R_TOP->ADD_GAP
    EXPORTING
      WIDTH    = 8.

TEXT = SY-DATUM.
CALL METHOD R_TOP->ADD_TEXT
    EXPORTING
      TEXT      = TEXT
      SAP_STYLE = 'KEY'.

CALL METHOD R_TOP->NEW_LINE.

ENDFORM.

reward,if it is usefull

regards

chandu

Former Member
0 Kudos

Hi balram,

just try this code by using se38.nothing can change.


TABLES VBAK,VBAP.
TYPE-POOLS SLIS.
* Data Declaration
TYPES: BEGIN OF T_VBAK,
      VBELN TYPE VBAK-VBELN,
      ERDAT TYPE VBAK-ERDAT,
      ERNAM TYPE VBAK-ERNAM,
      AUDAT TYPE VBAK-AUDAT,
      POSNR TYPE VBAP-POSNR,
      MATNR TYPE VBAP-MATNR,
      LINE_COLOR(4) TYPE C,
      END OF T_VBAK.

DATA: IT_VBAK TYPE STANDARD TABLE OF T_VBAK INITIAL SIZE 0,
      WA_VBAK TYPE T_VBAK.

* ALV Data Declaration
DATA: FLDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
      GD_LAYOUT TYPE SLIS_LAYOUT_ALV,
      GD_REPID TYPE SY-REPID,
*      I_EVENTS TYPE SLIS_T_EVENT,
*      W_EVENTS LIKE LINE OF I_EVENTS.

START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BLD_FLDCAT.
PERFORM BLD_LAYOUT.
PERFORM DISPLAY_ALV_REPORT.


* Build Field Catalog for ALV Report
FORM BLD_FLDCAT.

FLDCAT-FIELDNAME = 'VBELN'.
FLDCAT-SELTEXT_M = 'Sales Document'.
FLDCAT-COL_POS = 0.
*FLDCAT-EMPHASIZE = 'C411'.
FLDCAT-OUTPUTLEN = 20.
FLDCAT-KEY = 'X'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'ERDAT'.
FLDCAT-SELTEXT_L = 'Record Date created'.
FLDCAT-COL_POS = 1.
FLDCAT-KEY = 'X'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'ERNAM'.
FLDCAT-SELTEXT_L = 'Cteated Object Person Name'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'AUDAT'.
FLDCAT-SELTEXT_M = 'Document Date'.
FLDCAT-COL_POS = 3.
FLDCAT-EMPHASIZE = 'C110'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'POSNR'.
FLDCAT-SELTEXT_L = 'Sales Document item'.
FLDCAT-COL_POS = 4.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

FLDCAT-FIELDNAME = 'MATNR'.
FLDCAT-SELTEXT_L = 'Material Number’.
FLDCAT-COL_POS = 5.
FLDCAT-OUTPUTLEN = 60.
FLDCAT-DO_SUM = 'X'.
FLDCAT-DATATYPE = 'CURR'.
APPEND FLDCAT TO FLDCAT.
CLEAR FLDCAT.

ENDFORM.


* Build Layout for ALV Grid Report

FORM BLD_LAYOUT.

GD_LAYOUT-NO_INPUT = 'X'.
GD_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.

ENDFORM.


* Display report using ALV grid

FORM DISPLAY_ALV_REPORT.

DATA T_EVENT TYPE SLIS_T_EVENT.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
 EXPORTING
   I_LIST_TYPE           = 0
 IMPORTING
   ET_EVENTS             = T_EVENT.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

GD_REPID = SY-REPID.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
   I_CALLBACK_PROGRAM                = GD_REPID
   IS_LAYOUT                         = GD_LAYOUT
   I_CALLBACK_HTML_TOP_OF_PAGE       = 'TOP_OF_PAGE_SPLIT'
   IT_FIELDCAT                       = FLDCAT[]
   I_SAVE                            = 'X'
  TABLES
    T_OUTTAB                          = IT_VBAK
 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.


* Retrieve data from VBAK table and populate itab IT_VBAK

FORM DATA_RETRIEVAL.

DATA LD_COLOR(1) TYPE C.

SELECT K~VBELN K~ERDAT K~ERNAM K~AUDAT P~POSNR P~MATNR FROM VBAK AS K INNER JOIN VBAP AS P 
ON K~VBELN = P~VBELN
INTO TABLE IT_VBAK.

LOOP AT IT_VBAK INTO WA_VBAK.
LD_COLOR = LD_COLOR + 1.
IF LD_COLOR = 8.
  LD_COLOR = 1.
ENDIF.
CONCATENATE 'C' LD_COLOR '10' INTO WA_VBAK-LINE_COLOR.
MODIFY IT_VBAK FROM WA_VBAK.
ENDLOOP.

ENDFORM.

FORM TOP_OF_PAGE.
DATA: T_HEADER TYPE SLIS_T_LISTHEADER,
      W_HEADER TYPE SLIS_LISTHEADER.

W_HEADER-TYP = 'H'.
W_HEADER-INFO = 'WELCOME HEADER LIST'.
APPEND W_HEADER TO T_HEADER.

W_HEADER-TYP = 'S'.
W_HEADER-KEY = 'REPORT:'.
W_HEADER-INFO = SY-REPID.
APPEND W_HEADER TO T_HEADER.

W_HEADER-TYP = 'S'.
W_HEADER-KEY = 'DATE:'.
CONCATENATE SY-DATUM+4(2) ' / ' SY-DATUM+6(2) ' / ' SY-DATUM(4) INTO W_HEADER-INFO.
APPEND W_HEADER TO T_HEADER.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
  EXPORTING
    IT_LIST_COMMENTARY       = T_HEADER.

ENDFORM.

FORM TOP_OF_PAGE_SPLIT USING R_TOP TYPE REF TO CL_DD_DOCUMENT.

DATA: S_TAB TYPE SDYDO_TEXT_TABLE,
      C_AREA TYPE REF TO CL_DD_AREA,
      TEXT TYPE SDYDO_TEXT_ELEMENT.

DATA: BEGIN OF TAB_TEXT OCCURS 0,
      TEXT TYPE SDYDO_TEXT_ELEMENT,
      END OF TAB_TEXT.

CALL METHOD R_TOP->INITIALIZE_DOCUMENT.

CALL METHOD R_TOP->VERTICAL_SPLIT
    EXPORTING
      SPLIT_AREA = R_TOP
      SPLIT_WIDTH = '70%'
    IMPORTING
      RIGHT_AREA = C_AREA.
IF SY-SUBRC <> 0.
*    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


TAB_TEXT-TEXT = 'GEMS TECHNO SOLUTIONS PVT LIMITED'.
APPEND TAB_TEXT.
TAB_TEXT-TEXT = 'PLOT NO.100,SECTOR 1'.
APPEND TAB_TEXT.
TAB_TEXT-TEXT = 'MVP DOUBLE ROAD'.
APPEND TAB_TEXT.
TAB_TEXT-TEXT = 'MVP COLONY,VIZAG'.
APPEND TAB_TEXT.

S_TAB[] = TAB_TEXT[].

CALL METHOD C_AREA->ADD_TEXT
    EXPORTING
      TEXT_TABLE    = S_TAB
      FIX_LINES     = 'X'
     SAP_FONTSIZE  = CL_DD_DOCUMENT=>MEDIUM
     SAP_EMPHASIS  = CL_DD_DOCUMENT=>STRONG.

TEXT = 'REPORT:'.
CALL METHOD R_TOP->ADD_TEXT
    EXPORTING
      TEXT         = TEXT
      SAP_EMPHASIS = 'STRONG'.

CALL METHOD R_TOP->ADD_GAP
    EXPORTING
      WIDTH = 2.

TEXT = SY-REPID.
CALL METHOD R_TOP->ADD_TEXT
    EXPORTING
      TEXT         = TEXT
      SAP_STYLE    = 'KEY'.

CALL METHOD R_TOP->NEW_LINE.

TEXT = 'DATE:'.
CALL METHOD R_TOP->ADD_TEXT
    EXPORTING
      TEXT        = TEXT
      SAP_EMPHASIS = 'STRONG'.

CALL METHOD R_TOP->ADD_GAP
    EXPORTING
      WIDTH    = 8.

TEXT = SY-DATUM.
CALL METHOD R_TOP->ADD_TEXT
    EXPORTING
      TEXT      = TEXT
      SAP_STYLE = 'KEY'.

CALL METHOD R_TOP->NEW_LINE.

ENDFORM.

reward,if it is usefull

regards

chandu