0% found this document useful (0 votes)
110 views10 pages

ALV Report

This report displays purchasing document data from tables EKKO and EKPO in an ALV grid. It allows the user to select documents by purchasing document number or material number on a selection screen. The data is filtered based on the selection, combined from the tables, and displayed fields are defined. The grid is displayed and includes functionality to call transaction MM01 when a document number is selected.

Uploaded by

Vaibhav Sambare
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views10 pages

ALV Report

This report displays purchasing document data from tables EKKO and EKPO in an ALV grid. It allows the user to select documents by purchasing document number or material number on a selection screen. The data is filtered based on the selection, combined from the tables, and displayed fields are defined. The grid is displayed and includes functionality to call transaction MM01 when a document number is selected.

Uploaded by

Vaibhav Sambare
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

*&---------------------------------------------------------------------*

*& Report ZDEMO_ALV1_PO


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT

zdemo_alv1_po.

TABLES : ekko,ekpo, TRDIR.


TYPE-POOLS: slis.
*---------------------------------------------*
*
TYPES
*
*---------------------------------------------*
TYPES : BEGIN OF gty_final,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
matnr TYPE ekpo-matnr,
werks TYPE ekpo-werks,
bukrs TYPE ekko-bukrs,
bstyp TYPE ekko-bstyp,
bsart TYPE ekko-bsart,
END OF gty_final.
TYPES : BEGIN OF gty_ekko,
ebeln TYPE ekko-ebeln,
bukrs TYPE ekko-bukrs,
bstyp TYPE ekko-bstyp,
bsart TYPE ekko-bsart,
END OF gty_ekko.
*---------------------------------------------*
*
DATA
*
*---------------------------------------------*
DATA : gt_final TYPE STANDARD TABLE OF gty_final,
gt_ekko TYPE STANDARD TABLE OF gty_ekko.
DATA : gs_final TYPE gty_final,
gs_ekko TYPE gty_ekko.
DATA : flag(2),
v_ebeln TYPE ebeln,
v_matnr TYPE matnr.

*---------------------------------------------*
*
ALV DECLARATION
*
*---------------------------------------------*
* alv Declaration
*fieldcat
DATA: gt_fcat TYPE slis_t_fieldcat_alv,
gs_fcat TYPE slis_fieldcat_alv.
*top of page
DATA: gt_top
gs_top

TYPE slis_t_listheader,
TYPE slis_listheader.

*layout.
DATA: gs_lay

TYPE slis_layout_alv.

*sort
DATA: gt_sort TYPE slis_t_sortinfo_alv ,
gs_sort TYPE slis_sortinfo_alv.

*---------------------------------------------*
*
SELECTION-SCREEN
*
*---------------------------------------------*
SELECT-OPTIONS : s_ebeln FOR ekpo-ebeln,
s_matnr FOR ekpo-matnr.
AT SELECTION-SCREEN.
IF s_ebeln IS INITIAL
AND
s_matnr IS INITIAL.
flag = 'A'.
MESSAGE 'enter atleast value in one field' TYPE 'E'.
ENDIF.
IF s_ebeln IS INITIAL .
flag = 'B'.
SELECT SINGLE matnr FROM ekpo INTO v_matnr
WHERE matnr IN s_matnr.
ENDIF.
IF s_matnr IS INITIAL.
flag = 'C'.
SELECT SINGLE ebeln FROM ekpo INTO v_ebeln
WHERE ebeln IN s_ebeln.

ENDIF.

*---------------------------------------------*
*
START-OF-SELECTION
*
*---------------------------------------------*
START-OF-SELECTION.
PERFORM data_selection.
PERFORM data_manupulation.
PERFORM data_dispaly.
*&---------------------------------------------------------------------*
*&
Form data_selection
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM data_selection .
SELECT ebeln
ebelp
matnr
werks
FROM ekpo
INTO TABLE gt_final
WHERE ebeln IN s_ebeln
AND
matnr IN s_matnr.
IF gt_final[] IS NOT INITIAL.
SELECT ebeln
bukrs
bstyp
bsart
FROM ekko INTO TABLE gt_ekko
FOR ALL ENTRIES IN gt_final
WHERE ebeln = gt_final-ebeln.
ENDIF.

ENDFORM.

" data_selection

*&---------------------------------------------------------------------*
*&
Form data_manupulation
*&---------------------------------------------------------------------*
*
text

*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM data_manupulation .
LOOP AT gt_final INTO gs_final.
READ TABLE gt_ekko INTO gs_ekko WITH KEY ebeln = gs_final-ebeln.
IF sy-subrc EQ 0.
gs_final-bukrs = gs_ekko-bukrs.
gs_final-bstyp = gs_ekko-bstyp.
gs_final-bsart = gs_ekko-bsart.
MODIFY gt_final FROM gs_final.

HIDE: gs_final-matnr,
gs_final-ebeln.
ENDIF.
ENDLOOP.
ENDFORM.

" data_manupulation

*&---------------------------------------------------------------------*
*&
Form data_dispaly
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM data_dispaly .
CLEAR: gt_fcat,
gs_fcat.
gs_fcat-row_pos
= 1.
gs_fcat-tabname
= 'gt_final'.
gs_fcat-fieldname
= 'EBELN'.
gs_fcat-outputlen
= '12'.
gs_fcat-seltext_l
= 'Purchasing Document Number'.
APPEND gs_fcat TO gt_fcat.
gs_fcat-row_pos
gs_fcat-tabname
gs_fcat-fieldname
gs_fcat-outputlen

=
=
=
=

2.
'gt_final'.
'MATNR'.
'20'.

gs_fcat-seltext_l
= 'Material Number'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-row_pos
= 3.
gs_fcat-tabname
= 'gt_final'.
gs_fcat-fieldname
= 'EBELP'.
gs_fcat-seltext_l
= 'Item Number of Purchasing Document'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-row_pos
= 4.
gs_fcat-tabname
= 'gt_final'.
gs_fcat-fieldname
= 'WERKS'.
gs_fcat-outputlen
= '10'.
gs_fcat-seltext_l
= 'Plant'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
gs_fcat-row_pos
= 5.
gs_fcat-tabname
= 'gt_final'.
gs_fcat-fieldname
= 'BUKRS'.
gs_fcat-outputlen
= '13'.
gs_fcat-seltext_l
= 'Company Code'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.

gs_fcat-row_pos
= 6.
gs_fcat-tabname
= 'gt_final'.
gs_fcat-fieldname
= 'BSTYP'.
gs_fcat-outputlen
= '16'.
gs_fcat-seltext_l
= 'Purchasing Document Category'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
*
gs_fcat-row_pos
= 7.
gs_fcat-tabname
= 'gt_final'.
gs_fcat-fieldname
= 'BSART'.
gs_fcat-outputlen
= '16'.
gs_fcat-seltext_l
= 'Purchasing Document Type'.
APPEND gs_fcat TO gt_fcat.
CLEAR gs_fcat.
*layout.
CLEAR gs_lay.
gs_lay-colwidth_optimize = 'X'.
gs_lay-zebra
= 'X'.

gs_lay-no_colhead

= ''.

CLEAR : gt_sort ,
gs_sort .
IF flag = 'B'.
gs_sort-spos = '2'.
gs_sort-fieldname = 'MATNR'.
APPEND gs_sort
TO gt_sort .
ELSE.
gs_sort-spos = '1'.
gs_sort-fieldname = 'EBELN'.
APPEND gs_sort
TO gt_sort .
ENDIF.

*
*
*
*

*
*
*
*
*

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

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_INTERFACE_CHECK
= ' '
I_BYPASSING_BUFFER
= ' '
I_BUFFER_ACTIVE
= ' '
i_callback_program
= sy-repid
I_CALLBACK_PF_STATUS_SET
= ' '
i_callback_user_command
= '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
= 'Grid Display'
I_GRID_SETTINGS
=
is_layout
= gs_lay
it_fieldcat
= gt_fcat[]
IT_EXCLUDING
=
IT_SPECIAL_GROUPS
=
it_sort
= gt_sort
IT_FILTER
=
IS_SEL_HIDE
=
I_DEFAULT
= 'X'
i_save
= 'A'
IS_VARIANT
=
IT_EVENTS
=
IT_EVENT_EXIT
=
IS_PRINT
=
IS_REPREP_ID
=
I_SCREEN_START_COLUMN
= 0
I_SCREEN_START_LINE
= 0
I_SCREEN_END_COLUMN
= 0
I_SCREEN_END_LINE
= 0

*
I_HTML_HEIGHT_TOP
= 0
*
I_HTML_HEIGHT_END
= 0
*
IT_ALV_GRAPHICS
=
*
IT_HYPERLINK
=
*
IT_ADD_FIELDCAT
=
*
IT_EXCEPT_QINFO
=
*
IR_SALV_FULLSCREEN_ADAPTER
=
* IMPORTING
*
E_EXIT_CAUSED_BY_CALLER
=
*
ES_EXIT_CAUSED_BY_USER
=
TABLES
t_outtab
= gt_final[]
* 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.
" data_dispaly

"data_dispaly

*&---------------------------------------------------------------------*
*&
Form top_of_page
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM top_of_page .
CLEAR: gs_top,
gt_top.
DATA: v_datl(10),
v_dath(10).

gs_top-typ = 'H'.
gs_top-key = 'Report:'.
gs_top-info = 'Purchasing Data header Report'.
APPEND gs_top TO gt_top.
CLEAR gs_top.
IF flag = 'C'.
IF s_ebeln-high IS INITIAL.

CLEAR gs_top.
gs_top-typ =
gs_top-key =
gs_top-info =
APPEND gs_top
CLEAR gs_top.
ENDIF.

'S'.
'Customer:'.
s_ebeln-low.
TO gt_top.

ELSEIF s_ebeln-low IS INITIAL.


CLEAR gs_top.
gs_top-typ = 'S'.
gs_top-key = 'Customer:'.
CONCATENATE 'Up to Purchasing Document Number ' s_ebelnhigh INTO gs_top-info.
APPEND gs_top TO gt_top.
CLEAR gs_top.
ELSE.
gs_top-typ = 'S'.
gs_top-key = 'Customer: '.
CONCATENATE s_ebeln-low 'To' s_ebeln-high INTO gs_topinfo SEPARATED BY space.
APPEND gs_top TO gt_top.
CLEAR gs_top.
ENDIF.
ELSEIF flag = 'B'.

IF s_matnr-high
CLEAR gs_top.
gs_top-typ =
gs_top-key =
gs_top-info =
APPEND gs_top
CLEAR gs_top.
ENDIF.

IS INITIAL.
'S'.
'Matrial:'.
s_matnr-low.
TO gt_top.

ELSEIF s_matnr-low IS INITIAL.


CLEAR gs_top.
gs_top-typ = 'S'.
gs_top-key = 'Material:'.
CONCATENATE 'Up to Material Number'
gs_top-info = s_ebeln-high.
APPEND gs_top TO gt_top.
CLEAR gs_top.
ELSE.
gs_top-typ

= 'S'.

s_matnr-high INTO gs_top-info.

gs_top-key = 'Material: '.


CONCATENATE s_matnr-low 'To' s_matnr-high INTO gs_topinfo SEPARATED BY space.
APPEND gs_top TO gt_top.
CLEAR gs_top.
ENDIF.
ELSE.
gs_top-typ = 'S'.
gs_top-key = 'Customer: '.
CONCATENATE s_ebeln-low 'To' s_ebeln-high INTO gs_topinfo SEPARATED BY space.
APPEND gs_top TO gt_top.
CLEAR gs_top.
gs_top-typ
gs_top-key

= 'S'.
= 'Material

:'.

CONCATENATE s_matnr-low '


info SEPARATED BY space.
APPEND gs_top TO gt_top.
CLEAR gs_top.
ENDIF.

To' s_matnr-high INTO gs_top-

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'


EXPORTING
it_list_commentary
= gt_top
I_LOGO
= 'LOGO_COGNIZANT'
*
I_END_OF_LIST_GRID
=
*
I_ALV_FORM
=
.
ENDFORM.

" top_of_page

FORM user_command USING r_ucomm TYPE sy-ucomm


rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
READ TABLE gt_final INTO gs_final INDEX rs_selfield-tabindex.
IF rs_selfield-sel_tab_field = '1-ebeln'.
IF sy-subrc = 0.
CALL TRANSACTION 'MM01'.
ENDIF.

CALL TRANSACTION 'MM01'.


ENDIF.
endcase.
endform.
*AT LINE-SELECTION.
*
* DATA: val(20),
*
lin TYPE i.
*
* CLEAR : val.
*
*
* GET CURSOR FIELD val.
*
* CONDENSE val.
*
* CASE val.
*
*
WHEN 'gt_FINAL-MATNR'.
*
call TRANSACTION 'MM01'.
* ENDCASE.

You might also like