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: 

INTERACTIVE ALV

Former Member
0 Kudos

hi,

can any one provide me simple Interactive ALV

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Check out the below program in the link

http://www.sap-img.com/abap/an-interactive-alv-report.htm

Regards,

Santosh

6 REPLIES 6

Former Member
0 Kudos

Check out the below program in the link

http://www.sap-img.com/abap/an-interactive-alv-report.htm

Regards,

Santosh

Former Member
0 Kudos

Reward if useful

&----


*& Report ZCHECKALV_EXAMPLE *

*& *

&----


*& *

*& *

&----


REPORT zcheckalv_example

NO STANDARD PAGE HEADING.

  • Tables

************************************************************************

TABLES sflight.

************************************************************************

  • Includes

INCLUDE <icon>.

INCLUDE <symbol>.

************************************************************************

  • Type-Pools

TYPE-POOLS: slis.

************************************************************************

  • Constants

************************************************************************

CONSTANTS: c_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'

.

************************************************************************

  • Intenal Table for ALV

************************************************************************

DATA: i_fieldcat TYPE slis_t_fieldcat_alv,

i_layout TYPE slis_layout_alv,

i_sp_group TYPE slis_t_sp_group_alv,

i_events TYPE slis_t_event,

i_print TYPE slis_print_alv,

i_sort TYPE slis_t_sortinfo_alv.

DATA: i_list_top_of_page TYPE slis_t_listheader.

************************************************************************

*Internal Table for data to be displayed

************************************************************************

DATA: BEGIN OF i_sflight OCCURS 0.

INCLUDE STRUCTURE sflight.

DATA: box,

lights.

DATA: END OF i_sflight.

************************************************************************

  • Variable

DATA: w_repid LIKE sy-repid,

w_boxnam TYPE slis_fieldname VALUE 'BOX',

w_f2code LIKE sy-ucomm VALUE '&ETA',

w_lignam TYPE slis_fieldname VALUE 'LIGHTS',

w_save(1) TYPE c,

w_default(1) TYPE c,

w_exit(1) TYPE c,

i_variant LIKE disvariant,

i_variant1 LIKE disvariant.

  • Selection Screen

************************************************************************

SELECT-OPTIONS s_carrid FOR sflight-carrid.

SELECT-OPTIONS s_connid FOR sflight-connid.

SELECT-OPTIONS s_fldate FOR sflight-fldate.

*SELECTION-SCREEN SKIP 1.

PARAMETERS: p_maxrow TYPE i DEFAULT 30."to limit the selection

SELECTION-SCREEN SKIP 1.

  • Variant for ALV display

SELECTION-SCREEN BEGIN OF BLOCK 0 WITH FRAME TITLE text-000.

PARAMETERS: p_varnt LIKE disvariant-variant.

SELECTION-SCREEN END OF BLOCK 0.

  • Layout of the report display

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

PARAMETERS: p_zebra AS CHECKBOX DEFAULT ' ', "Striped pattern

p_nocolh AS CHECKBOX DEFAULT ' ', "No column heading

p_novlin AS CHECKBOX DEFAULT ' ', "No vertical lines

p_colopt AS CHECKBOX DEFAULT ' ', "Optimizes col. wd

p_keyhot AS CHECKBOX DEFAULT ' ', "Key fields hot

p_noinpt AS CHECKBOX DEFAULT ' '. "No field for input

SELECTION-SCREEN END OF BLOCK a.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-002.

PARAMETERS: p_lights AS CHECKBOX DEFAULT 'X',

p_lightc AS CHECKBOX DEFAULT 'X'.

SELECTION-SCREEN END OF BLOCK b.

SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-003.

PARAMETERS: p_totonl AS CHECKBOX DEFAULT ' ',

p_totext(60),

p_sttext(60).

SELECTION-SCREEN END OF BLOCK c.

SELECTION-SCREEN BEGIN OF BLOCK d WITH FRAME TITLE text-004.

PARAMETERS: p_chkbox AS CHECKBOX DEFAULT 'X',

p_detpop AS CHECKBOX DEFAULT 'X',

p_groupb AS CHECKBOX DEFAULT ' ',

p_groups AS CHECKBOX DEFAULT ' '.

SELECTION-SCREEN END OF BLOCK d.

SELECTION-SCREEN BEGIN OF BLOCK e WITH FRAME TITLE text-005.

PARAMETERS: p_print AS CHECKBOX DEFAULT ' ',

p_nosinf AS CHECKBOX DEFAULT ' ',

p_nocove AS CHECKBOX DEFAULT ' ',

p_nonewp AS CHECKBOX DEFAULT ' ',

p_nolinf AS CHECKBOX DEFAULT ' ',

p_reserv TYPE i.

SELECTION-SCREEN END OF BLOCK e.

************************************************************************

  • AT SELECTION-SCREEN.

************************************************************************

  • Process on value request (list of possible variants)

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_varnt.

PERFORM f4_for_variant.

  • PAI

AT SELECTION-SCREEN.

PERFORM pai_of_selection_screen.

************************************************************************

*INITIALIZATION.

INITIALIZATION.

w_repid = sy-repid.

  • Set Options: save variant userspecific or general

  • 'A or 'U' are for user-specific variants list

  • 'X' or 'space' for general

w_save = 'A'.

PERFORM variant_init.

*----- Get default variant

i_variant1 = i_variant.

CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'

EXPORTING

i_save = w_save

CHANGING

cs_variant = i_variant1

EXCEPTIONS

not_found = 2.

IF sy-subrc = 0.

p_varnt = i_variant1-variant.

ENDIF.

*----- Getting Events

PERFORM eventtab_build USING i_events.

*----- Even Top of Page

PERFORM comment_build USING i_list_top_of_page.

*----- Creating Special Group

PERFORM sp_group_build USING i_sp_group.

*----- Mentioning Sort Details

PERFORM t_sort_build USING i_sort.

*----- Filling Fieldcatalog

PERFORM fieldcat_init USING i_fieldcat.

************************************************************************

*START-OF-SELECTION

START-OF-SELECTION.

PERFORM selection.

************************************************************************

*END-OF-SELECTION

END-OF-SELECTION.

*----- Creating Layout for Report

PERFORM layout_build USING i_layout. "wg. Parameters

*----- Mentioning Print Parameters

PERFORM print_build USING i_print. "wg. Parameters

*----- Display Report

PERFORM disply_report.

************************************************************************

----


  • FORM F4_FOR_VARIANT *

----


FORM f4_for_variant.

*

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

EXPORTING

is_variant = i_variant

i_save = w_save

  • it_default_fieldcat =

IMPORTING

e_exit = w_exit

es_variant = i_variant1

EXCEPTIONS

not_found = 2.

IF sy-subrc = 2.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

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

ELSE.

IF w_exit = space.

p_varnt = i_variant1-variant.

ENDIF.

ENDIF.

ENDFORM. "f4_for_variant

&----


*& Form PAI_OF_SELECTION_SCREEN

&----


  • to check whether right variant is entered on the selection scr

----


FORM pai_of_selection_screen.

*

IF NOT p_varnt IS INITIAL.

MOVE i_variant TO i_variant1.

MOVE p_varnt TO i_variant1-variant.

CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'

EXPORTING

i_save = w_save

CHANGING

cs_variant = i_variant1.

i_variant = i_variant1.

ELSE.

PERFORM variant_init.

ENDIF.

ENDFORM. " PAI_OF_SELECTION_SCREEN

&----


*& Form VARIANT_INIT

----


FORM variant_init.

CLEAR i_variant.

i_variant-report = w_repid.

ENDFORM. " VARIANT_INIT

----


  • FORM EVENTTAB_BUILD *

----


  • --> l_EVENTS *

----


FORM eventtab_build USING l_events TYPE slis_t_event.

DATA: ls_event TYPE slis_alv_event.

*

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = l_events.

READ TABLE l_events WITH KEY name = slis_ev_top_of_page INTO ls_event.

IF sy-subrc = 0.

MOVE c_formname_top_of_page TO ls_event-form.

APPEND ls_event TO l_events.

ENDIF.

ENDFORM. "eventtab_build

----


  • FORM TOP_OF_PAGE *

----


  • ........ *

----


FORM top_of_page.

*

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

i_logo = 'ENJOYSAP_LOGO'

it_list_commentary = i_list_top_of_page.

ENDFORM. "top_of_page

----


  • FORM COMMENT_BUILD *

----


  • --> L_TOP_OF_PAGE *

----


FORM comment_build USING l_top_of_page TYPE slis_t_listheader.

DATA: ls_line TYPE slis_listheader.

***Header

CLEAR ls_line.

ls_line-typ = 'H'.

  • LS_LINE-KEY: not used for this type

ls_line-info = 'Heading list'.

APPEND ls_line TO l_top_of_page.

***Selection

CLEAR ls_line.

ls_line-typ = 'S'.

ls_line-key = 'Key 1'.

ls_line-info = 'Information'.

APPEND ls_line TO l_top_of_page.

ls_line-key = 'Key 2'.

APPEND ls_line TO l_top_of_page.

***Action

CLEAR ls_line.

ls_line-typ = 'A'.

  • LS_LINE-KEY: not used for this type

ls_line-info = 'Status list'.

APPEND ls_line TO l_top_of_page.

ENDFORM. "comment_build

----


  • FORM SP_GROUP_BUILD *

----


  • --> L_SP_GROUP *

----


FORM sp_group_build USING l_sp_group TYPE slis_t_sp_group_alv.

DATA: ls_sp_group TYPE slis_sp_group_alv.

*Fields are assigned to the special group

CLEAR ls_sp_group.

ls_sp_group-sp_group = 'A'.

ls_sp_group-text = 'Reservation status'.

APPEND ls_sp_group TO l_sp_group.

CLEAR ls_sp_group.

ls_sp_group-sp_group = 'B'.

ls_sp_group-text = 'Flight charges'.

APPEND ls_sp_group TO l_sp_group.

ENDFORM. "sp_group_build

----


  • FORM T_SORT_BUILD *

----


FORM t_sort_build USING l_sort TYPE slis_t_sortinfo_alv.

DATA: ls_sort TYPE slis_sortinfo_alv.

ls_sort-fieldname = 'CARRID'.

ls_sort-spos = 1.

ls_sort-up = 'X'.

ls_sort-subtot = 'X'.

APPEND ls_sort TO l_sort.

ENDFORM. "t_sort_build

----


  • FORM FIELDCAT_INIT *

----


  • --> L_FIELDCAT *

----


FORM fieldcat_init USING l_fieldcat TYPE slis_t_fieldcat_alv.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

*

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'SEATSOCC'.

*The field is not displayed in the initial output, can be interactively

  • chosen for display

ls_fieldcat-no_out = 'X'.

*This field is assigned to a special group with tech. key 'A' and can be

*displayed using the special group buttons

ls_fieldcat-sp_group = 'A'.

*The field cannot be summed irrespective of its data type

ls_fieldcat-no_sum = 'X'.

APPEND ls_fieldcat TO l_fieldcat.

*

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'SEATSMAX'.

ls_fieldcat-no_out = 'X'.

ls_fieldcat-sp_group = 'A'.

APPEND ls_fieldcat TO l_fieldcat.

*

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'PRICE'.

ls_fieldcat-no_out = 'X'.

ls_fieldcat-sp_group = 'B'.

APPEND ls_fieldcat TO l_fieldcat.

*

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = 'CARRID'.

ls_fieldcat-outputlen = 7.

APPEND ls_fieldcat TO l_fieldcat.

ENDFORM. "fieldcat_init

----


  • FORM SELECTION *

----


FORM selection.

SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE i_sflight

UP TO p_maxrow ROWS WHERE carrid IN s_carrid

AND connid IN s_connid AND fldate IN s_fldate.

PERFORM data_add TABLES i_sflight.

ENDFORM. "selection

----


  • FORM DATA_ADD *

----


  • --> L_SFLIGHT

----


FORM data_add TABLES l_sflight STRUCTURE i_sflight.

LOOP AT l_sflight.

IF sy-tabix > 10.

l_sflight-box = 'X'.

l_sflight-lights = '3'.

ELSE.

IF sy-tabix = 1.

l_sflight-lights = '2'.

ELSE.

l_sflight-lights = '1'.

ENDIF.

ENDIF.

MODIFY l_sflight.

ENDLOOP.

ENDFORM. "data_add

----


  • FORM LAYOUT_BUILD *

----


  • <-> LS_LAYOUT *

----


FORM layout_build USING ls_layout TYPE slis_layout_alv.

ls_layout-f2code = w_f2code.

ls_layout-zebra = p_zebra.

ls_layout-colwidth_optimize = p_colopt.

IF p_chkbox = 'X'.

*Fieldname for check box on the report output

ls_layout-box_fieldname = w_boxnam.

ELSE.

ls_layout-box_fieldname = space.

ENDIF.

ls_layout-no_input = p_noinpt.

ls_layout-no_vline = p_novlin.

ls_layout-no_colhead = p_nocolh.

IF p_lights = 'X' OR p_lightc = 'X'.

**Fieldname for lights on the report output

ls_layout-lights_fieldname = w_lignam.

ELSE.

CLEAR ls_layout-lights_fieldname.

ENDIF.

ls_layout-lights_condense = p_lightc.

ls_layout-totals_text = p_totext.

ls_layout-subtotals_text = p_sttext.

ls_layout-totals_only = p_totonl.

ls_layout-key_hotspot = p_keyhot.

ls_layout-detail_popup = p_detpop.

ls_layout-group_change_edit = p_groups.

  • E05_LS_LAYOUT-GROUP_BUTTONS = P_GROUPB.

  • ls_layout-group_buttons = 'X'.

ENDFORM. "layout_build

----


  • FORM PRINT_BUILD *

----


  • ........ *

----


FORM print_build USING l_print TYPE slis_print_alv.

*

l_print-print = p_print.

l_print-no_print_selinfos = p_nosinf.

l_print-no_coverpage = p_nocove.

l_print-no_new_page = p_nonewp.

l_print-no_print_listinfos = p_nolinf.

l_print-reserve_lines = p_reserv.

l_print-print = p_print.

ENDFORM. "print_build

&----


*& Form disply_report

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM disply_report .

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = w_repid

  • i_internal_tabname = 'I_SFLIGHT'

i_structure_name = 'SFLIGHT'

i_client_never_display = 'X'

i_inclname = w_repid

CHANGING

ct_fieldcat = i_fieldcat[]

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno

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

ENDIF.

  • Call ABAP/4 List Viewer

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

i_callback_program = w_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

i_structure_name = 'SFLIGHT'

i_background_id = 'ALV_BACKGROUND'

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

is_layout = i_layout

it_fieldcat = i_fieldcat[]

  • IT_EXCLUDING =

it_special_groups = i_sp_group[]

it_sort = i_sort[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

i_save = w_save

is_variant = i_variant

it_events = i_events[]

  • IT_EVENT_EXIT =

is_print = i_print

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

t_outtab = i_sflight

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.

  • CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

  • EXPORTING

  • i_callback_program = w_repid

  • i_structure_name = 'SFLIGHT'

  • is_layout = i_layout

  • it_fieldcat = i_fieldcat[]

    • IT_EXCLUDING =

  • it_special_groups = i_sp_group[]

  • it_sort = i_sort[]

    • IT_FILTER =

    • IS_SEL_HIDE =

    • i_default = W_DEFAULT

  • i_save = w_save

  • is_variant = i_variant

  • it_events = i_events[]

    • IT_EVENT_EXIT =

  • is_print = i_print

    • I_SCREEN_START_COLUMN = 0

    • I_SCREEN_START_LINE = 0

    • I_SCREEN_END_COLUMN = 0

    • I_SCREEN_END_LINE = 0

    • IMPORTING

    • E_EXIT_CAUSED_BY_CALLER =

  • TABLES

  • t_outtab = i_sflight.

ENDFORM. " disply_report

Former Member
0 Kudos

hi,

look at these links

ALV

http://www.geocities.com/mpioud/Abap_programs.html

http://www.sapdevelopment.co.uk/reporting/reportinghome.htm

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

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

OR SEE THIS SAMPLE CODE

check the example.

*-----tables declaration

TABLES:EKKO.

TYPE-POOLS:SLIS.

*-----data declaration

TYPES:BEGIN OF X_EKKO,

EBELN type EKKO-EBELN, "PO Number

BUKRS type EKKO-BUKRS, "Company code

BSART type EKKO-BSART, "Purchasing Document type

LIFNR type EKKO-LIFNR, "Vendor

SPRAS type EKKO-SPRAS, "Language Key

ZTERM type EKKO-ZTERM, "Terms of payment key

END OF X_EKKO,

BEGIN OF X_EKPO,

EBELN type EKPO-EBELN,

EBELP type EKPO-EBELP, "Item number

WERKS type EKPO-WERKS, "Plant

MATNR type EKPO-MATNR, "Material Number

MATKL type EKPO-MATKL, "Material Group

END OF X_EKPO.

DATA:IT_EKKO TYPE STANDARD TABLE OF X_EKKO,

IT_EKPO TYPE STANDARD TABLE OF X_EKPO,

WA_EKKO TYPE X_EKKO,

WA_EKPO TYPE X_EKPO, "#EC *

IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV,

WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,

WA_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV.

*-----Selection-screen design

SELECTION-SCREEN BEGIN OF BLOCK B1.

SELECT-OPTIONS:S_EBELN FOR EKKO-EBELN.

SELECTION-SCREEN END OF BLOCK B1.

*-----SELECTION-SCREEN VALIDATION

AT SELECTION-SCREEN.

SELECT EBELN

FROM EKKO

INTO TABLE IT_EKKO

WHERE EBELN IN S_EBELN.

*-----if there are no values display an error

IF SY-SUBRC NE 0.

MESSAGE E009.

ENDIF.

*-----Data retrieval

START-OF-SELECTION.

*-----retrieving data from the PO header

SELECT EBELN BUKRS BSART LIFNR SPRAS ZTERM

FROM EKKO

INTO TABLE IT_EKKO

WHERE EBELN IN S_EBELN.

*-----if there are no records display an error

IF SY-SUBRC NE 0.

MESSAGE E003.

ENDIF.

*-----Field catalog for the PO Header

REFRESH IT_FIELDCAT[].

WA_FIELDCAT-COL_POS = '1'.

WA_FIELDCAT-FIELDNAME = 'EBELN'.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-KEY = 'X'.

WA_FIELDCAT-HOTSPOT = 'X'.

WA_FIELDCAT-REF_FIELDNAME = 'EBELN'.

WA_FIELDCAT-REF_TABNAME = 'EKKO'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = '2'.

WA_FIELDCAT-FIELDNAME = 'BUKRS'.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-REF_FIELDNAME = 'BUKRS'.

WA_FIELDCAT-REF_TABNAME = 'EKKO'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = '3'.

WA_FIELDCAT-FIELDNAME = 'BSART'.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-REF_FIELDNAME = 'BSART'.

WA_FIELDCAT-REF_TABNAME = 'EKKO'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = '4'.

WA_FIELDCAT-FIELDNAME = 'LIFNR'.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-REF_FIELDNAME = 'LIFNR'.

WA_FIELDCAT-REF_TABNAME = 'EKKO'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = '5'.

WA_FIELDCAT-FIELDNAME = 'SPRAS'.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-REF_FIELDNAME = 'SPRAS'.

WA_FIELDCAT-REF_TABNAME = 'EKKO'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-COL_POS = '6'.

WA_FIELDCAT-FIELDNAME = 'ZTERM'.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-REF_FIELDNAME = 'ZTERM'.

WA_FIELDCAT-REF_TABNAME = 'EKKO'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

*-----to display the header details

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

IT_FIELDCAT = IT_FIELDCAT[]

TABLES

T_OUTTAB = IT_EKKO[].

&----


*& Form USER_COMMAND

&----


text

-


-->UCOMM text

-->FIELD1 text

-


FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM FIELD1 TYPE "#EC CALLED

SLIS_SELFIELD. "#EC *

READ TABLE IT_EKKO INTO WA_EKKO INDEX FIELD1-TABINDEX.

*-----retrieving item details from the PO Item table

SELECT EBELN EBELP WERKS MATNR MATKL

FROM EKPO

INTO TABLE IT_EKPO

WHERE EBELN = WA_EKKO-EBELN.

*-----to display an error if other than PO Number is clicked

IF SY-SUBRC NE 0.

MESSAGE E001.

ENDIF.

*-----Fieldcatalog for the PO item details

REFRESH IT_FIELDCAT1[].

WA_FIELDCAT1-COL_POS = '1'.

WA_FIELDCAT1-FIELDNAME = 'EBELN'.

WA_FIELDCAT1-TABNAME = 'IT_EKPO'.

WA_FIELDCAT1-REF_FIELDNAME = 'EBELN'.

WA_FIELDCAT1-REF_TABNAME = 'EKPO'.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

WA_FIELDCAT1-COL_POS = '2'.

WA_FIELDCAT1-FIELDNAME = 'EBELP'.

WA_FIELDCAT1-TABNAME = 'IT_EKPO'.

WA_FIELDCAT1-REF_FIELDNAME = 'EBELP'.

WA_FIELDCAT1-REF_TABNAME = 'EKPO'.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

WA_FIELDCAT1-COL_POS = '3'.

WA_FIELDCAT1-FIELDNAME = 'WERKS'.

WA_FIELDCAT1-TABNAME = 'IT_EKPO'.

WA_FIELDCAT1-REF_FIELDNAME = 'WERKS'.

WA_FIELDCAT1-REF_TABNAME = 'EKPO'.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

WA_FIELDCAT1-COL_POS = '4'.

WA_FIELDCAT1-FIELDNAME = 'MATNR'.

WA_FIELDCAT1-TABNAME = 'IT_EKPO'.

WA_FIELDCAT1-REF_FIELDNAME = 'MATNR'.

WA_FIELDCAT1-REF_TABNAME = 'EKPO'.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

WA_FIELDCAT1-COL_POS = '5'.

WA_FIELDCAT1-FIELDNAME = 'MATKL'.

WA_FIELDCAT1-TABNAME = 'IT_EKPO'.

WA_FIELDCAT1-REF_FIELDNAME = 'MATKL'.

WA_FIELDCAT1-REF_TABNAME = 'EKPO'.

APPEND WA_FIELDCAT1 TO IT_FIELDCAT1.

CLEAR WA_FIELDCAT1.

*-----to display the item details

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = IT_FIELDCAT1[]

TABLES

T_OUTTAB = IT_EKPO[].

ENDFORM. "user_command_form

Reward points if useful

Rohan

Former Member
0 Kudos

Hi

TYPE-POOLS : slis.

----


  • STRUCTURE DECLARATION

----


TYPES: BEGIN OF st_ekko,

ebeln TYPE ekko-ebeln,

aedat TYPE ekko-aedat,

bukrs TYPE ekko-bukrs,

bsart TYPE ekko-bsart,

lifnr TYPE ekko-lifnr,

END OF st_ekko.

TYPES: BEGIN OF st_ekpo,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

matnr TYPE ekpo-matnr,

menge TYPE ekpo-menge,

meins TYPE ekpo-meins,

netpr TYPE ekpo-netpr,

END OF st_ekpo.

----


  • INTERNAL TABLE DECLARATION

----


DATA : it_ekko TYPE STANDARD TABLE OF st_ekko,

wa_ekko TYPE st_ekko,

it_ekpo TYPE STANDARD TABLE OF st_ekpo ,

it_fieldcat TYPE slis_t_fieldcat_alv,

wa_fieldcat TYPE slis_fieldcat_alv,

it_events TYPE slis_t_event,

wa_events TYPE slis_alv_event,

it_listheader TYPE slis_t_listheader,

wa_listheader LIKE LINE OF it_listheader.

----


  • GLOBAL DECLARATION

----


DATA: v_repid TYPE sy-repid,

v_ebeln TYPE ekko-ebeln.

----


  • INITIALIZATION

----


INITIALIZATION.

v_repid = sy-repid.

SELECT-OPTIONS so_ebeln FOR v_ebeln OBLIGATORY.

PERFORM fill_feildcat.

PERFORM eventcall.

PERFORM fill_events.

----


  • START-OF-SELECTION

----


START-OF-SELECTION.

PERFORM get_data.

PERFORM display.

&----


*& Form FILL_FEILDCAT

&----


FORM fill_feildcat .

wa_fieldcat-tabname = 'IT_EKKO'.

wa_fieldcat-fieldname = 'EBELN'.

wa_fieldcat-seltext_l = 'PURCHASE ORDER NUMBER'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKKO'.

wa_fieldcat-fieldname = 'AEDAT'.

wa_fieldcat-seltext_l = 'DATE.'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKKO'.

wa_fieldcat-fieldname = 'BUKRS'.

wa_fieldcat-seltext_l = 'COMPANY CODE'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKKO'.

wa_fieldcat-fieldname = 'BUKRS'.

wa_fieldcat-seltext_l = 'DOCMENT TYPE'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKKO'.

wa_fieldcat-fieldname = 'LIFNR'.

wa_fieldcat-no_out = 'X'.

wa_fieldcat-seltext_l = 'VENDOR NUMBER'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " FILL_FEILDCAT

&----


*& Form get_data

&----


FORM get_data .

SELECT ebeln aedat bukrs bsart lifnr

FROM ekko

INTO TABLE it_ekko

WHERE ebeln IN so_ebeln.

ENDFORM. " get_data

&----


*& Form DISPLAY

&----


FORM display .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

i_callback_pf_status_set = 'SET_PF_STATUS1'

i_callback_user_command = 'AT_USER_COMMAND'

it_fieldcat = it_fieldcat

it_events = it_events

TABLES

t_outtab = it_ekko

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

&----


*& Form EVENTCALL

&----


FORM eventcall .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = it_events[]

EXCEPTIONS

list_type_wrong = 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. " EVENTCALL

&----


*& Form FILL_EVENTS

&----


FORM fill_events .

READ TABLE it_events WITH KEY name = slis_ev_top_of_page INTO wa_events.

IF sy-subrc = 0.

wa_events-form = 'TOP_OF_PAGE'.

APPEND wa_events TO it_events.

CLEAR wa_events.

ENDIF.

READ TABLE it_events WITH KEY name = slis_ev_pf_status_set INTO wa_events.

IF sy-subrc EQ 0.

wa_events-form = 'SET_PF_STATUS1'.

APPEND wa_events TO it_events.

CLEAR wa_events.

ENDIF.

ENDFORM. " FILL_EVENTS

&----


*& Form TOP_OF_PAGE

&----


FORM top_of_page.

REFRESH it_listheader.

wa_listheader-typ = 'H'.

wa_listheader-info = text-001.

APPEND wa_listheader TO it_listheader.

CLEAR wa_listheader.

wa_listheader-typ = 'A'.

wa_listheader-info = text-002.

APPEND wa_listheader TO it_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = it_listheader[]

i_logo = 'FITP_CORP_LOGO'.

  • I_END_OF_LIST_GRID = I_END_OF_LIST_GRID

  • I_ALV_FORM = I_ALV_FORM

ENDFORM. "TOP_OF_PAGE

&----


*& Form SET_PF_STATUS

&----


FORM set_pf_status1 USING rt_extab TYPE slis_t_extab.

SET PF-STATUS 'STANDARD1' .

ENDFORM. "SET_PF_STATUS

&----


*& Form AT USER-COMMAND

&----


FORM at_user_command USING r_ucomm TYPE sy-ucomm

rs_selfield TYPE slis_selfield.

CASE r_ucomm.

WHEN '&IC1'.

IF rs_selfield-fieldname EQ 'EBELN'.

READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.

PERFORM data_retrieval_ekpo.

PERFORM build_fieldcatlog_ekpo.

PERFORM event_call_ekpo.

PERFORM populate_events_ekpo.

PERFORM display1.

ELSE.

MESSAGE text-004 TYPE 'I'.

ENDIF.

ENDCASE.

ENDFORM. "at_user_command

&----


*& Form BUILD_FIELDCATLOG_EKPO

&----


FORM build_fieldcatlog_ekpo .

REFRESH it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKPO'.

wa_fieldcat-fieldname = 'EBELN'.

wa_fieldcat-seltext_m = 'PO NO.'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKPO'.

wa_fieldcat-fieldname = 'EBELP'.

wa_fieldcat-seltext_m = 'LINE NO'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKPO'.

wa_fieldcat-fieldname = 'MATNR'.

wa_fieldcat-seltext_m = 'MATERIAL NO.'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKPO'.

wa_fieldcat-fieldname = 'MENGE'.

wa_fieldcat-seltext_m = 'QUANTITY'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKPO'.

wa_fieldcat-fieldname = 'MEINS'.

wa_fieldcat-seltext_m = 'UOM'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-tabname = 'IT_EKPO'.

wa_fieldcat-fieldname = 'NETPR'.

wa_fieldcat-seltext_m = 'PRICE'.

APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.

ENDFORM. " BUILD_FIELDCATLOG_EKPO

&----


*& Form EVENT_CALL_EKPO

&----


FORM event_call_ekpo .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = it_events

EXCEPTIONS

list_type_wrong = 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. " EVENT_CALL_EKPO

&----


*& Form POPULATE_EVENTS_EKPO

&----


FORM populate_events_ekpo .

READ TABLE it_events WITH KEY name = slis_ev_top_of_page INTO wa_events.

IF sy-subrc = 0.

wa_events-form = 'TOP_OF_PAGE1'.

APPEND wa_events TO it_events.

CLEAR wa_events.

ENDIF.

ENDFORM. " POPULATE_EVENTS_EKPO

&----


*& Form TOP_OF_PAGE1

&----


FORM top_of_page1.

REFRESH it_listheader.

wa_listheader-typ = 'H'.

wa_listheader-info = text-001.

APPEND wa_listheader TO it_listheader.

CLEAR wa_listheader.

wa_listheader-typ = 'S'.

wa_listheader-info = text-003.

APPEND wa_listheader TO it_listheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = it_listheader

i_logo = 'FITP_CORP_LOGO'.

ENDFORM. "TOP_OF_PAGE1

&----


*& Form DATA_RETRIEVAL_EKPO

&----


FORM data_retrieval_ekpo .

SELECT ebeln ebelp matnr menge meins netpr

FROM ekpo

INTO TABLE it_ekpo

WHERE ebeln = wa_ekko-ebeln.

ENDFORM. " DATA_RETRIEVAL_EKPO

&----


*& Form DISPLAY1

&----


FORM display1 .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

i_callback_pf_status_set = 'SET_PF_STATUS1'

it_fieldcat = it_fieldcat

it_events = it_events

TABLES

t_outtab = it_ekpo

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.

to get the standard tool bar in second screen.....goto se80...in function group...give SALV -


GUI STATUS------right click copy and give u r program name there and continue...now the standard tool bar will be copied....goto se41 and there give the name which u gave in se80 ....and save and activate ..then u wil get the standard tool bar in other screens also.

Former Member
0 Kudos

Hi,

C this Report. Simple example

REPORT ZZ123_REPT NO STANDARD PAGE HEADING LINE-SIZE 650

MESSAGE-ID ZZ_9838 .

TYPE-POOLS: SLIS.

*type declaration for values from ekko

TYPES: BEGIN OF I_EKKO,

EBELN LIKE EKKO-EBELN,

AEDAT LIKE EKKO-AEDAT,

BUKRS LIKE EKKO-BUKRS,

BSART LIKE EKKO-BSART,

LIFNR LIKE EKKO-LIFNR,

END OF I_EKKO.

DATA: IT_EKKO TYPE STANDARD TABLE OF I_EKKO INITIAL SIZE 0,

WA_EKKO TYPE I_EKKO.

*type declaration for values from ekpo

TYPES: BEGIN OF I_EKPO,

EBELN LIKE EKPO-EBELN,

EBELP LIKE EKPO-EBELP,

MATNR LIKE EKPO-MATNR,

MENGE LIKE EKPO-MENGE,

MEINS LIKE EKPO-MEINS,

NETPR LIKE EKPO-NETPR,

END OF I_EKPO.

DATA: IT_EKPO TYPE STANDARD TABLE OF I_EKPO INITIAL SIZE 0,

WA_EKPO TYPE I_EKPO .

*variable for Report ID

DATA: V_REPID LIKE SY-REPID .

*declaration for fieldcatalog

DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER.

  • declaration for events table where user comand or set PF status will

  • be defined

DATA: V_EVENTS TYPE SLIS_T_EVENT,

WA_EVENT TYPE SLIS_ALV_EVENT.

  • declartion for layout

DATA: ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.

  • declaration for variant(type of display we want)

DATA: I_VARIANT TYPE DISVARIANT,

I_VARIANT1 TYPE DISVARIANT,

I_SAVE(1) TYPE C.

*PARAMETERS : p_var TYPE disvariant-variant.

*Title displayed when the alv list is displayed

DATA: I_TITLE_EKKO TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED'.

DATA: I_TITLE_EKPO TYPE LVC_TITLE VALUE 'SECONDRY LIST DISPLAYED'.

INITIALIZATION.

V_REPID = SY-REPID.

PERFORM BUILD_FIELDCATLOG.

PERFORM EVENT_CALL.

PERFORM POPULATE_EVENT.

START-OF-SELECTION.

PERFORM DATA_RETRIEVAL.

PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.

PERFORM DISPLAY_ALV_REPORT.

&----


*& Form BUILD_FIELDCATLOG

&----


  • Fieldcatalog has all the field details from ekko

----


FORM BUILD_FIELDCATLOG.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-FIELDNAME = 'EBELN'.

WA_FIELDCAT-SELTEXT_M = 'PO NO.'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-FIELDNAME = 'AEDAT'.

WA_FIELDCAT-SELTEXT_M = 'DATE.'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-FIELDNAME = 'BUKRS'.

WA_FIELDCAT-SELTEXT_M = 'COMPANY CODE'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-FIELDNAME = 'BUKRS'.

WA_FIELDCAT-SELTEXT_M = 'DOCMENT TYPE'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_EKKO'.

WA_FIELDCAT-FIELDNAME = 'LIFNR'.

WA_FIELDCAT-NO_OUT = 'X'.

WA_FIELDCAT-SELTEXT_M = 'VENDOR CODE'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

ENDFORM. "BUILD_FIELDCATLOG

&----


*& Form EVENT_CALL

&----


  • we get all events - TOP OF PAGE or USER COMMAND in table v_events

----


FORM EVENT_CALL.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = V_EVENTS

  • EXCEPTIONS

  • LIST_TYPE_WRONG = 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. "EVENT_CALL

&----


*& Form POPULATE_EVENT

&----


  • Events populated for TOP OF PAGE & USER COMAND

----


FORM POPULATE_EVENT.

READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.

IF SY-SUBRC EQ 0.

WA_EVENT-FORM = 'TOP_OF_PAGE'.

MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =

WA_EVENT-FORM.

ENDIF.

READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.

IF SY-SUBRC EQ 0.

WA_EVENT-FORM = 'USER_COMMAND'.

MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =

WA_EVENT-NAME.

ENDIF.

ENDFORM. "POPULATE_EVENT

&----


*& Form data_retrieval

&----


  • retreiving values from the database table ekko

----


FORM DATA_RETRIEVAL.

SELECT EBELN AEDAT BUKRS BSART LIFNR FROM EKKO INTO TABLE IT_EKKO.

ENDFORM. "data_retrieval

&----


*& Form bUild_listheader

&----


  • text

----


  • -->I_LISTHEADEtext

----


FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.

DATA HLINE TYPE SLIS_LISTHEADER.

HLINE-INFO = 'this is my first alv pgm'.

HLINE-TYP = 'H'.

ENDFORM. "build_listheader

&----


*& Form display_alv_report

&----


  • text

----


FORM DISPLAY_ALV_REPORT.

V_REPID = SY-REPID.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

I_GRID_TITLE = I_TITLE_EKKO

  • I_GRID_SETTINGS =

  • IS_LAYOUT = ALV_LAYOUT

IT_FIELDCAT = I_FIELDCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • i_default = 'ZLAY1'

I_SAVE = 'A'

  • is_variant = i_variant

IT_EVENTS = V_EVENTS

TABLES

T_OUTTAB = IT_EKKO

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

&----


  • text

----


FORM TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = IT_LISTHEADER

  • i_logo =

  • I_END_OF_LIST_GRID =

.

ENDFORM. "TOP_OF_PAGE

&----


*& Form USER_COMMAND

&----


  • text

----


  • -->R_UCOMM text

  • -->, text

  • -->RS_SLEFIELDtext

----


FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

CASE R_UCOMM.

WHEN '&IC1'.

READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.

PERFORM BUILD_FIELDCATLOG_EKPO.

PERFORM EVENT_CALL_EKPO.

PERFORM POPULATE_EVENT_EKPO.

PERFORM DATA_RETRIEVAL_EKPO.

PERFORM BUILD_LISTHEADER_EKPO USING IT_LISTHEADER.

PERFORM DISPLAY_ALV_EKPO.

ENDCASE.

ENDFORM. "user_command

&----


*& Form BUILD_FIELDCATLOG_EKPO

&----


  • text

----


FORM BUILD_FIELDCATLOG_EKPO.

WA_FIELDCAT-TABNAME = 'IT_EKPO'.

WA_FIELDCAT-FIELDNAME = 'EBELN'.

WA_FIELDCAT-SELTEXT_M = 'PO NO.'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_EKPO'.

WA_FIELDCAT-FIELDNAME = 'EBELP'.

WA_FIELDCAT-SELTEXT_M = 'LINE NO'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'I_EKPO'.

WA_FIELDCAT-FIELDNAME = 'MATNR'.

WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO.'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'I_EKPO'.

WA_FIELDCAT-FIELDNAME = 'MENGE'.

WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'I_EKPO'.

WA_FIELDCAT-FIELDNAME = 'MEINS'.

WA_FIELDCAT-SELTEXT_M = 'UOM'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'I_EKPO'.

WA_FIELDCAT-FIELDNAME = 'NETPR'.

WA_FIELDCAT-SELTEXT_M = 'PRICE'.

APPEND WA_FIELDCAT TO I_FIELDCAT.

CLEAR WA_FIELDCAT.

ENDFORM. "BUILD_FIELDCATLOG_EKPO

&----


*& Form event_call_ekpo

&----


  • we get all events - TOP OF PAGE or USER COMMAND in table v_events

----


FORM EVENT_CALL_EKPO.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

I_LIST_TYPE = 0

IMPORTING

ET_EVENTS = V_EVENTS

  • EXCEPTIONS

  • LIST_TYPE_WRONG = 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. "event_call_ekpo

&----


*& Form POPULATE_EVENT

&----


  • Events populated for TOP OF PAGE & USER COMAND

----


FORM POPULATE_EVENT_EKPO.

READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.

IF SY-SUBRC EQ 0.

WA_EVENT-FORM = 'TOP_OF_PAGE'.

MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =

WA_EVENT-FORM.

ENDIF.

ENDFORM. "POPULATE_EVENT

&----


*& Form TOP_OF_PAGE

&----


  • text

----


FORM F_TOP_OF_PAGE.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = IT_LISTHEADER

  • i_logo =

  • I_END_OF_LIST_GRID =

.

ENDFORM. "TOP_OF_PAGE

&----


*& Form USER_COMMAND

&----


  • text

----


  • -->R_UCOMM text

  • -->, text

  • -->RS_SLEFIELDtext

----


*retreiving values from the database table ekko

FORM DATA_RETRIEVAL_EKPO.

SELECT EBELN EBELP MATNR MENGE MEINS NETPR FROM EKPO INTO TABLE IT_EKPO.

ENDFORM.

FORM BUILD_LISTHEADER_EKPO USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.

DATA: HLINE1 TYPE SLIS_LISTHEADER.

HLINE1-TYP = 'H'.

HLINE1-INFO = 'CHECKING PGM'.

ENDFORM.

FORM DISPLAY_ALV_EKPO.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = 'F_USER_COMMAND'

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

I_GRID_TITLE = I_TITLE_EKPO

  • I_GRID_SETTINGS =

  • IS_LAYOUT =

IT_FIELDCAT = I_FIELDCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT =

I_SAVE = 'A'

  • IS_VARIANT =

IT_EVENTS = V_EVENTS

TABLES

T_OUTTAB = IT_EKPO

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.

Regards.

Former Member
0 Kudos

Hi,

Please refer to the below code:



*&---------------------------------------------------------------------*
*& Report  ZDEMO_ALVGRID                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*& Example of a simple ALV Grid Report                                 *
*& ...................................                                 *
*&                                                                     *
*& The basic requirement for this demo is to display a number of       *
*& fields from the EKKO table.                                         *
*&---------------------------------------------------------------------*
REPORT  zdemo_alvgrid                 .

TABLES:     ekko.

type-pools: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
 END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.

*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,
      gt_events     type slis_t_event,
      gd_prntparams type slis_print_alv.


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

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
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   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  fieldcatalog-key         = 'X'.
*  fieldcatalog-do_sum      = 'X'.
*  fieldcatalog-no_zero     = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-do_sum      = 'X'.
  fieldcatalog-datatype     = 'CURR'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 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'.
  gd_layout-totals_text       = 'Totals'(201).
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
*  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
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_events
            is_print                = gd_prntparams
            i_save                  = 'X'
*            is_variant              = z_template
       tables
            t_outtab                = it_ekko
       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 ebeln ebelp statu aedat matnr menge meins netpr peinh
 up to 10 rows
  from ekpo
  into table it_ekko.
endform.                    " DATA_RETRIEVAL


*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
      wa_header type slis_listheader,
      t_line like wa_header-info,
      ld_lines type i,
      ld_linesc(10) type c.

* Title
  wa_header-typ  = 'H'.
  wa_header-info = 'EKKO Table Report'.
  append wa_header to t_header.
  clear wa_header.

* Date
  wa_header-typ  = 'S'.
  wa_header-key = 'Date: '.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "todays date
  append wa_header to t_header.
  clear: wa_header.

* Total No. of Records Selected
  describe table it_ekko lines ld_lines.
  ld_linesc = ld_lines.
  concatenate 'Total No. of Records Selected: ' ld_linesc
                    into t_line separated by space.
  wa_header-typ  = 'A'.
  wa_header-info = t_line.
  append wa_header to t_header.
  clear: wa_header, t_line.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.
endform.


*------------------------------------------------------------------*
*       FORM USER_COMMAND                                          *
*------------------------------------------------------------------*
*       --> R_UCOMM                                                *
*       --> RS_SELFIELD                                            *
*------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.

* Check function code
  CASE r_ucomm.
    WHEN '&IC1'.
*   Check field clicked on within ALVgrid report
    IF rs_selfield-fieldname = 'EBELN'.
*     Read data table, using index of row user clicked on
      READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
*     Set parameter ID for transaction screen field
      SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
*     Sxecute transaction ME23N, and skip initial data entry screen
      CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDCASE.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTS
*&---------------------------------------------------------------------*
*       Build events table
*----------------------------------------------------------------------*
form build_events.
  data: ls_event type slis_alv_event.

  call function 'REUSE_ALV_EVENTS_GET'
       exporting
            i_list_type = 0
       importing
            et_events   = gt_events[].
  read table gt_events with key name =  slis_ev_end_of_page
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_PAGE' to ls_event-form.
    append ls_event to gt_events.
  endif.

    read table gt_events with key name =  slis_ev_end_of_list
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_LIST' to ls_event-form.
    append ls_event to gt_events.
  endif.
endform.                    " BUILD_EVENTS


*&---------------------------------------------------------------------*
*&      Form  BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*       Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
  gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
  gd_prntparams-no_coverpage = 'X'.
endform.                    " BUILD_PRINT_PARAMS


*&---------------------------------------------------------------------*
*&      Form  END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  write: sy-uline(50).
  skip.
  write:/40 'Page:', sy-pagno .
endform.


*&---------------------------------------------------------------------*
*&      Form  END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  skip.
  write:/40 'Page:', sy-pagno .
endform.


Thanks,

Sriram Ponna.