Vous êtes sur la page 1sur 10

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

*& Report ZSA_PROG_ALV_FUNCTII


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZSA_PROG_ALV_FUNCTII.
type-pools: slis.
tables: likp.
selection-screen begin of block b1 with frame.
select-options: so_dl
for likp-vbeln obligatory, "del
so_dl_dt for likp-lfdat, "del date
so_dl_ty for likp-lfart, "del type
so_sh_po for likp-vstel, "Shipping point
so_s_to for likp-kunnr. "Ship-to party
parameters:
p_del_c type c as checkbox, "Only deliveries completely Good
s Issued (checkbox)
p_var type disvariant-variant, "ALV Layout (parameter)
p_sort_s type c as checkbox, "Sort by shipping point
p_sort_d type c as checkbox."Sort by delivery date (checkbox)
selection-screen end of block b1.
types: begin of ty_itab,
vbeln
type
posnr
type
lfdat
type
lfart
type
vstel
type
kunnr
type
wadat_ist type
lfimg
meins
vbeln_v
posnr_v
auart

type
type
type
type
type

likp-vbeln, "delivery
lips-posnr, "delivery item
likp-lfdat, "delivery date
likp-lfart, "delivery type
likp-vstel, "shipping point
likp-kunnr, "ship-to party
likp-wadat_ist, "actual goods movement date
lips-lfimg,
lips-meins,
vbap-vbelv,
vbap-posnv,
vbak-auart,

"quantity
"UoM
"sales order
"sales order item
"? sales order type sau vbap-posar item typ

e
kwmeng
type vbap-kwmeng, "sales order quantity
wbstk
type vbuk-wbstk, "total goods movement status
end of ty_itab,
begin of ty_del,
vbeln
type
posnr
type
lfdat
type
lfart
type
vstel
type
kunnr
type
wadat_ist type
lfimg
type
meins
type
end of ty_del,

likp-vbeln, "delivery
lips-posnr, "delivery item
likp-lfdat, "delivery date
likp-lfart, "delivery type
likp-vstel, "shipping point
likp-kunnr, "ship-to party
likp-wadat_ist, "actual goods movement date
lips-lfimg, "quantity
lips-meins, "UoM

begin of ty_s_order,
vbeln_v
type vbap-vbeln, "sales order
posnr_v
type vbap-posnr, "sales order item
auart
type vbak-auart, "? sales order type sau vbap-posar item typ
e
*

kwmeng
type vbap-kwmeng, "sales order quantity
wbstk
type vbuk-wbstk, "total goods movement status
end of ty_s_order,
begin of ty_vbuk,
wbstk
type vbuk-wbstk, "total goods movement status
end of ty_vbuk.

data: gs_del
it_del
gs_s_order
it_s_order
it_vb
gs_vb
gs_delivery
gs_delivery2
it_delivery
it_delivery2
gs_delivery3
it_delivery3
gs_fieldcat
it_fieldcat
it_vbfa
gs_vbfa

type
type
type
type
type
type
type
type
type
type
type
type
type
type

ty_del,
table of ty_del,
ty_s_order,
table of ty_s_order,
table of ty_vbuk,
ty_vbuk,
ty_itab,
ty_itab,
table of ty_itab,
table of ty_itab,
ty_itab,
table of ty_itab,
slis_fieldcat_alv, "slis_fieldcat_alv,
slis_t_fieldcat_alv, "slis_t_fieldcat_alv.

type table of vbfa,


type vbfa.

data: it_sort type slis_t_sortinfo_alv,


gs_sort type slis_sortinfo_alv,
gd_layout
TYPE slis_layout_alv,
gd_repid
LIKE sy-repid,
g_save TYPE c VALUE 'X',
g_variant TYPE disvariant,
gx_variant TYPE disvariant,
g_exit TYPE c.

initialization.
gx_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save
= g_save
CHANGING
cs_variant = gx_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc = 0.
p_var = gx_variant-variant.
ENDIF.
** F4 Help for Varient
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
**-- Display all existing variants

g_variant-report = sy-repid.
* Utilizing the name of the report, this function module will search for a list
of
* variants and will fetch the selected one into the parameter field for variants
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = g_variant
i_save
= g_save
IMPORTING
e_exit
= g_exit
es_variant = gx_variant
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 g_exit = space.
p_var = gx_variant-variant.
ENDIF.
ENDIF.
start-of-selection.
perform select.
perform catalog.
perform sort.
perform variant.
perform display.
*&---------------------------------------------------------------------*
*&
Form SELECT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form SELECT .
select a~vbeln
b~posnr
a~lfdat
a~lfart
a~vstel
a~kunnr
a~wadat_ist
b~lfimg
b~meins
from likp as a inner join lips as b on a~vbeln = b~vbeln
into corresponding fields of table it_delivery
where a~vbeln in so_dl
and a~lfdat in so_dl_dt
and a~lfart in so_dl_ty
and a~vstel in so_sh_po
and a~kunnr in so_s_to.
*move-corresponding it_del to it_delivery.
*loop at it_del into gs_del.
* move-corresponding gs_del to gs_delivery.
* append gs_delivery to it_delivery.

*endloop.
*select vbelv posnv vbeln posnn
* from vbfa
* into corresponding fields of table it_delivery2
* for all entries in it_delivery
* where vbeln = it_delivery-vbeln and
*
posnn = it_delivery-posnr.
*
vbtyp_n = 'J'.
select *
from vbfa
into corresponding fields of table it_vbfa
for all entries in it_delivery
where vbeln = it_delivery-vbeln and
posnn = it_delivery-posnr and
vbtyp_n = 'J'.
select y~vbeln
y~posnr
x~auart
y~kwmeng
FROM vbak as x inner join vbap as y on x~vbeln = y~vbeln
into table it_s_order
for all entries in it_vbfa
where y~vbeln = it_vbfa-vbelv and
y~posnr = it_vbfa-posnv.
* and y~posnr = it_vbfa-posnr.
*loop at it_vbfa into gs_vbfa.
loop at it_s_order into gs_s_order.
move-corresponding gs_s_order to gs_delivery2.
append gs_delivery2 to it_delivery2.
endloop.
*endloop.
loop at it_delivery into gs_delivery.
*
*
*
*
*
*
*
*
*

gs_delivery2-vbeln = gs_delivery-vbeln.
gs_delivery2-posnr = gs_delivery-posnr.
gs_delivery2-lfdat = gs_delivery-lfdat.
gs_delivery2-lfart = gs_delivery-lfart.
gs_delivery2-vstel = gs_delivery-vstel.
gs_delivery2-kunnr = gs_delivery-kunnr.
gs_delivery2-wadat_ist = gs_delivery-wadat_ist.
gs_delivery2-lfimg = gs_delivery-lfimg.
gs_delivery2-meins = gs_delivery-meins.
gs_delivery-vbeln_v = gs_delivery2-vbeln_v.
gs_delivery-posnr_v = gs_delivery2-posnr_v.
gs_delivery-auart = gs_delivery2-auart.
gs_delivery-kwmeng = gs_delivery2-kwmeng.

modify it_delivery from gs_delivery index sy-tabix transporting


vbeln posnr lfdat lfart vstelkunnr wadat_ist lfimg meins
vbeln_v posnr_v auart kwmeng .
endloop.
*

select wbstk
from vbuk
into corresponding fields of table it_vb
for all entries in it_vbfa
where vbeln = it_vbfa-vbelv.
loop at it_vb into gs_vb.
move-corresponding gs_vb to gs_delivery3.
append gs_delivery3 to it_delivery3.
endloop.
loop at it_delivery into gs_delivery.
gs_delivery-wbstk = gs_delivery3-wbstk.
modify it_delivery from gs_delivery index sy-tabix transporting wbstk.
endloop.
endform.
" SELECT
*&---------------------------------------------------------------------*
*&
Form CATALOG
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form CATALOG .
gs_fieldcat-col_pos = 1.
gs_fieldcat-fieldname = 'VBELN'.
gs_fieldcat-tabname = 'IT_DELIVERY'.
gs_fieldcat-seltext_m = 'Del'.
gs_fieldcat-emphasize = 'C111'.
gs_fieldcat-fix_column = 'X'.
append gs_fieldcat to it_fieldcat.
clear gs_fieldcat.
gs_fieldcat-col_pos = 2.
gs_fieldcat-fieldname = 'POSNR'.
gs_fieldcat-tabname = 'IT_DELIVERY'.
gs_fieldcat-seltext_m = 'Del Item'.
gs_fieldcat-emphasize = 'C111'.
gs_fieldcat-fix_column = 'X'.
append gs_fieldcat to it_fieldcat.
clear gs_fieldcat.
gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

3.
= 'LFDAT'.
'IT_DELIVERY'.
= 'Del Date'.
it_fieldcat.

gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

4.
= 'LFART'.
'IT_DELIVERY'.
= 'Del type'.
it_fieldcat.

gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

5.
= 'VSTEL'.
'IT_DELIVERY'.
= 'Shi point'.
it_fieldcat.

gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

6.
= 'KUNNR'.
'IT_DELIVERY'.
= 'Shi to party'.
it_fieldcat.

gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

7.
= 'WADAT_IST'.
'IT_DELIVERY'.
= 'Actual gds mov date'.
it_fieldcat.

gs_fieldcat-col_pos = 9.
gs_fieldcat-fieldname = 'LFIMG'.
gs_fieldcat-tabname = 'IT_DELIVERY'.
gs_fieldcat-seltext_m = 'LFIMG'.
* gs_fieldcat-outputlen = 0.
* gs_fieldcat-no_output = 'X'.
gs_fieldcat-do_sum = 'X'.
append gs_fieldcat to it_fieldcat.
clear gs_fieldcat.
gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

10.
= 'MEINS'.
'IT_DELIVERY'.
= 'UoM'.
it_fieldcat.

gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

11.
= 'VBELN_V'.
'IT_DELIVERY'.
= 'Sal order'.
it_fieldcat.

gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

12.
= 'POSNR_V'.
'IT_DELIVERY'.
= 'Sal ord item'.
it_fieldcat.

gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

13.
= 'AUART'.
'IT_DELIVERY'.
= 'Sal ord type'.
it_fieldcat.

gs_fieldcat-col_pos = 14.
gs_fieldcat-fieldname = 'KWMENG'.
gs_fieldcat-tabname = 'IT_DELIVERY'.
gs_fieldcat-seltext_m = 'Sal ord quantity'.
gs_fieldcat-do_sum = 'X'.
append gs_fieldcat to it_fieldcat.
clear gs_fieldcat.
gs_fieldcat-col_pos =
gs_fieldcat-fieldname
gs_fieldcat-tabname =
gs_fieldcat-seltext_m
append gs_fieldcat to
clear gs_fieldcat.

8.
= 'WBSTK'.
'IT_DELIVERY'.
= 'Tot gds mov'.
it_fieldcat.

endform.
" CATALOG
*&---------------------------------------------------------------------*
*&
Form DISPLAY
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form DISPLAY .
gd_repid = sy-repid.
g_variant-variant = p_var.

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

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_INTERFACE_CHECK
= ' '
I_BYPASSING_BUFFER
= ' '
I_BUFFER_ACTIVE
= ' '
I_CALLBACK_PROGRAM
= gd_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
=
I_GRID_SETTINGS
=
IS_LAYOUT
=
IT_FIELDCAT
= it_fieldcat
IT_EXCLUDING
=
IT_SPECIAL_GROUPS
=
IT_SORT
= it_sort
IT_FILTER
=
IS_SEL_HIDE
=
I_DEFAULT
= 'X'
I_SAVE
= 'X'
IS_VARIANT
= g_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
= it_delivery
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 SORT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form SORT .
clear gs_sort.
if p_sort_s = 'X'.
gs_sort-fieldname = 'VSTEL'.
gs_sort-spos = '1'.
gs_sort-up = 'X'.
append gs_sort to it_sort.
endif.
if p_sort_d = 'X'.
gs_sort-fieldname = 'LFDAT'.
gs_sort-spos = '2'.
gs_sort-up = 'X'.
append gs_sort to it_sort.
endif.
endform.
" SORT
*&---------------------------------------------------------------------*
*&
Form VARIANT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
form VARIANT .
g_variant-variant = p_var.
g_variant-report = sy-repid.

CALL FUNCTION 'LVC_VARIANT_EXISTENCE_CHECK' "Check for display variant


EXPORTING
i_save
= space
"Variants Can be Saved
CHANGING
cs_variant
= g_variant
"Variant information
EXCEPTIONS
wrong_input
= 1
"Inconsistent input parameters
not_found
= 2
"Variant not found
program_error
= 3
"Program Errors
.
" LVC_VARIANT_EXISTENCE_CHECK
IF sy-subrc = 2.
MESSAGE 'Display Variant Not Found, Displaying Default Variant'
TYPE 'S'.
ENDIF.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save
= g_save
CHANGING
cs_variant = gx_variant
EXCEPTIONS
not_found = 2.
IF sy-subrc = 0.
p_var = gx_variant-variant.
ENDIF.
endform.
" VARIANT
form top_of_page.
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 = 'ALV cu functii'.
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.
APPEND wa_header TO t_header.
CLEAR: wa_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.

"Today's date

"total no. of records selected


describe table it_delivery 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.
.
CLEAR t_header.
* suma pe quantity
*
DATA: l_q1 TYPE p VALUE 0,
*
l_q2 TYPE p VALUE 0,
*
l_q1_c type c,
*
l_q2_c type c.
*
LOOP AT it_delivery INTO gs_delivery.
*
l_q1 = l_q1 + gs_delivery-lfimg.
*
l_q2 = l_q2 + gs_delivery-kwmeng.
* ENDLOOP.
* l_q1 = l_q1_c.
* concatenate 'Total quantity delivery: ' l_q1_c 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.
*
* l_q2 = l_q2_c.
* concatenate 'Total quantity sales order: ' l_q2_c into t_line separated by sp
ace.
* wa_header-typ = 'A'.
* wa_header-info = t_line.
* APPEND wa_header TO t_header.
* CLEAR: wa_header, t_line.
*
* CLEAR t_header.
endform.

Vous aimerez peut-être aussi