SAP ABAP - Custom Report Stock on Posting Date
Main Program
*&------------------------------------------------------------------*
*& Report ZRMM008
*&------------------------------------------------------------------*
*&
*&------------------------------------------------------------------*
REPORT zrmm008.
INCLUDE zrmm008_01.
INCLUDE zrmm008_02.
INCLUDE zrmm008_03.
INCLUDE zrmm008_04.
INCLUDE zrmm008_05.
START-OF-SELECTION.
"Check Company Code Authorization
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD p_bukrs
ID 'ACTVT' FIELD '03'.
IF sy-subrc = 0.
IF grp1 = 'X'.
* PERFORM get_data.
PERFORM get_inv_sloc_level.
ELSE.
* PERFORM get_data_plant_level.
PERFORM get_inv_plant_level.
ENDIF.
PERFORM set_fieldcat.
PERFORM display_alv.
ELSE.
CLEAR str_msg.
str_msg = |NO Authorization FOR company CODE { p_bukrs }|.
MESSAGE str_msg TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
TOP-OF-PAGE.
PERFORM top_of_page.
END-OF-SELECTION.
Include Program
Include ZRMM008_01.
*&---------------------------------------------------------------------*
*& Include ZRMM008_01
*&---------------------------------------------------------------------*
TABLES: acdoca, bkpf, matdoc, t001.
TYPES:
BEGIN OF ty_sumdata,
mandt TYPE mandt,
matnr TYPE matnr,
bukrs TYPE bukrs,
werks TYPE werks_d,
lgort TYPE lgort_d,
menge TYPE menge_d,
cost2 TYPE zcost2,
END OF ty_sumdata,
BEGIN OF ty_sumdata_cls,
mandt TYPE mandt,
matnr TYPE matnr,
bukrs TYPE bukrs,
werks TYPE werks_d,
menge TYPE menge_d,
cost2 TYPE zcost2,
END OF ty_sumdata_cls.
TYPES: BEGIN OF t_data.
INCLUDE TYPE zsrmm008.
TYPES: linecolor(4),
cputm TYPE cputm,
END OF t_data.
DATA:
lt_data TYPE TABLE OF t_data,
lt_datax TYPE TABLE OF t_data,
lt_datat TYPE TABLE OF t_data,
ls_data TYPE t_data,
ls_data_end TYPE t_data,
lt_audit_data TYPE TABLE OF zcds_inv_audit_report,
lt_audit_data301 TYPE TABLE OF zcds_inv_audit_report,
lt_audit_datax TYPE TABLE OF zcds_inv_audit_report,
lt_audit_clse TYPE TABLE OF zcds_inv_audit_report_closing,
ls_audit_clse TYPE zcds_inv_audit_report_closing,
ls_audit_data TYPE zcds_inv_audit_report,
ls_audit_datax TYPE zcds_inv_audit_report,
lt_sumdata TYPE STANDARD TABLE OF ty_sumdata,
lt_sumdata_cls TYPE STANDARD TABLE OF ty_sumdata_cls,
ls_sumdata TYPE ty_sumdata,
ls_sumdata_cls TYPE ty_sumdata_cls,
zcum_qty TYPE menge_d,
zcum_val TYPE zcost1,
str_budat TYPE budat,
str_msg TYPE string,
ccwaers TYPE waers,
prperiod TYPE lfmon,
pryear TYPE gjahr,
zzmblnr TYPE mblnr,
zzawitem TYPE acdoca-awitem.
DATA:
lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
is_layout TYPE slis_layout_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
wa_top TYPE slis_listheader,
it_top TYPE slis_t_listheader,
month2(3) TYPE c.
RANGES:
ex_mblnr FOR zzmblnr,
ex_zeile FOR matdoc-zeile,
ex_matnr FOR matdoc-matnr,
ex_werks FOR matdoc-werks,
ex_lgort FOR matdoc-lgort,
ex_bukrs FOR matdoc-bukrs.
Include ZRMM008_02.
*&---------------------------------------------------------------------*
*& Include ZRMM008_02
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS:
p_bukrs TYPE t001-bukrs OBLIGATORY.
* p_gjahr TYPE gjahr DEFAULT sy-datum(4) OBLIGATORY.
SELECT-OPTIONS:
* s_gjahr FOR acdoca-gjahr DEFAULT sy-datum(4),
s_budat FOR matdoc-budat,
s_werks FOR matdoc-werks,
s_matnr FOR matdoc-matnr.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (31) TEXT-909. "1
PARAMETERS : p_cpudt AS CHECKBOX USER-COMMAND eck.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (31) TEXT-908. "1
PARAMETERS : p_ckb AS CHECKBOX USER-COMMAND eck.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (31) TEXT-907. "1
PARAMETERS : p_nkb AS CHECKBOX USER-COMMAND eck.
SELECTION-SCREEN END OF LINE.
* PARAMETERS:
* p_cpudt AS CHECKBOX DEFAULT ''.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
PARAMETERS:
grp1 RADIOBUTTON GROUP grp USER-COMMAND erad DEFAULT 'X',
grp2 RADIOBUTTON GROUP grp.
SELECTION-SCREEN END OF BLOCK b2.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF grp2 = 'X' AND ( screen-name CS 'CKB' OR screen-name CS 'NKB' OR screen-name = '%C908010_1000' OR screen-name = '%C907014_1000' ).
screen-invisible = 1.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
Include ZRMM008_03.
*&---------------------------------------------------------------------*
*& Include ZRMM008_03
*&---------------------------------------------------------------------*
FORM get_data.
REFRESH : ex_matnr, ex_werks, ex_lgort, ex_bukrs.
CLEAR : prperiod, ccwaers, str_budat, pryear.
IF s_budat-low IS INITIAL.
* str_budat = '00000000'.
ELSE.
str_budat = s_budat-low.
prperiod = s_budat-low+4(2).
IF s_budat-low+4(2) = '01'.
pryear = s_budat-low(4).
pryear = pryear - 1.
prperiod = '12'.
ELSE.
prperiod = prperiod - 1.
pryear = s_budat-low(4).
ENDIF.
ENDIF.
SELECT SINGLE waers FROM t001 INTO ccwaers WHERE bukrs = p_bukrs.
REFRESH : lt_audit_data, lt_audit_datax, lt_audit_clse, lt_audit_data301.
SELECT DISTINCT * FROM zcds_inv_audit_report INTO TABLE @lt_audit_data
WHERE bukrs = @p_bukrs "AND gjahr IN @s_gjahr
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr AND lgort <> ''.
SELECT DISTINCT * FROM zcds_inv_audit_report_tf301_v2 INTO TABLE @lt_audit_data301
WHERE bukrs = @p_bukrs "AND gjahr IN @s_gjahr
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr AND lgort <> ''.
IF lt_audit_data301 IS NOT INITIAL.
APPEND LINES OF lt_audit_data301 TO lt_audit_data.
ENDIF.
CHECK lt_audit_data IS NOT INITIAL.
SORT lt_audit_data BY mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks lgort menge1 awref awitem awitgrp.
DELETE ADJACENT DUPLICATES FROM lt_audit_data
COMPARING mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks lgort menge1 awref awitem awitgrp.
REFRESH : ex_mblnr, ex_zeile.
LOOP AT lt_audit_data ASSIGNING FIELD-SYMBOL(<fs_extf301>).
CLEAR ex_mblnr.
ex_mblnr-sign = 'I'.
ex_mblnr-option = 'EQ'.
ex_mblnr-low = <fs_extf301>-mblnr.
APPEND ex_mblnr TO ex_mblnr[].
CLEAR ex_zeile.
ex_zeile-sign = 'I'.
ex_zeile-option = 'EQ'.
ex_zeile-low = <fs_extf301>-awitem.
APPEND ex_zeile TO ex_zeile[].
ENDLOOP.
SORT ex_mblnr[] BY low.
SORT ex_zeile[] BY low.
DELETE ADJACENT DUPLICATES FROM ex_mblnr[] COMPARING low.
DELETE ADJACENT DUPLICATES FROM ex_zeile[] COMPARING low.
"Sudah zcds_inv_audit_report_tf301 sudah di union ke cdz zcds_inv_audit_report
* REFRESH lt_invtf301.
* SORT ex_mblnr[] BY low.
* DELETE ADJACENT DUPLICATES FROM ex_mblnr[] COMPARING low.
SELECT DISTINCT * FROM zcds_inv_audit_report_tf301
INTO TABLE @DATA(lt_invtf301)
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr AND lgort <> ''. "AND mblnr IN @ex_mblnr. "AND zeile NOT IN @ex_zeile.
IF lt_invtf301 IS NOT INITIAL.
SORT lt_invtf301 BY mblnr mjahr zeile.
LOOP AT lt_invtf301 ASSIGNING FIELD-SYMBOL(<fs_inv301>).
CLEAR zzawitem.
zzawitem = <fs_inv301>-zeile.
READ TABLE lt_audit_data WITH KEY mblnr = <fs_inv301>-mblnr awitem = zzawitem TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
CLEAR ls_audit_data.
MOVE-CORRESPONDING <fs_inv301> TO ls_audit_data.
APPEND ls_audit_data TO lt_audit_data.
ENDIF.
ENDLOOP.
* APPEND LINES OF lt_invtf301 TO lt_audit_data.
ENDIF.
SELECT DISTINCT * FROM zcds_inv_audit_report INTO TABLE @DATA(lt_audit_data_change_price)
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr AND lgort = '' AND ( awtyp = 'PRCHG' OR awtyp = '' ).
IF lt_audit_data_change_price IS NOT INITIAL.
APPEND LINES OF lt_audit_data_change_price TO lt_audit_data.
ENDIF.
SELECT DISTINCT * FROM zcds_inv_audit_report_closing INTO TABLE @lt_audit_clse
WHERE bukrs = @p_bukrs "AND gjahr IN @s_gjahr
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND matnr IN @s_matnr.
IF lt_audit_data IS NOT INITIAL.
lt_audit_datax = lt_audit_data.
ENDIF.
SELECT * FROM zcds_matdesc5
INTO TABLE @DATA(lt_matdesc)
FOR ALL ENTRIES IN @lt_audit_data
WHERE matnr = @lt_audit_data-matnr.
SORT lt_matdesc BY matnr.
IF lt_audit_datax IS INITIAL.
CLEAR ls_audit_clse.
LOOP AT lt_audit_clse INTO ls_audit_clse.
CLEAR ls_audit_datax.
MOVE-CORRESPONDING ls_audit_clse TO ls_audit_datax.
APPEND ls_audit_datax TO lt_audit_datax.
CLEAR ls_audit_clse.
ENDLOOP.
ENDIF.
SORT lt_audit_datax BY matnr bukrs werks lgort.
DELETE ADJACENT DUPLICATES FROM lt_audit_datax COMPARING matnr bukrs werks lgort.
IF p_cpudt = ''.
SORT lt_audit_datax BY matnr bukrs werks lgort budat cpudt cputm mblnr ASCENDING.
SORT lt_audit_data BY matnr bukrs werks lgort budat cpudt cputm mblnr ASCENDING.
SORT lt_audit_clse BY matnr bukrs werks lgort budat cpudt cputm belnr ASCENDING.
ELSE.
SORT lt_audit_datax BY matnr bukrs werks lgort cpudt cputm budat mblnr ASCENDING.
SORT lt_audit_data BY matnr bukrs werks lgort cpudt cputm budat mblnr ASCENDING.
SORT lt_audit_clse BY matnr bukrs werks lgort cpudt cputm budat belnr ASCENDING.
ENDIF.
"Ambil document BC by doc MIGO
SELECT * FROM zmmdt_kb_trans
INTO TABLE @DATA(lt_kbdoc)
FOR ALL ENTRIES IN @lt_audit_data
WHERE mblnr = @lt_audit_data-mblnr AND mjahr = @lt_audit_data-mjahr.
SORT lt_kbdoc BY mblnr mjahr.
IF lt_audit_datax IS NOT INITIAL.
CLEAR : ex_matnr, ex_werks, ex_lgort, ex_bukrs.
* SELECT * FROM mbewh INTO TABLE @DATA(lt_mbewh)
* FOR ALL ENTRIES IN @lt_audit_datax
* WHERE matnr = @lt_audit_datax-matnr AND
* bwkey = @lt_audit_datax-werks AND
* lfgja = @pryear AND lfmon = @prperiod.
LOOP AT lt_audit_datax ASSIGNING FIELD-SYMBOL(<fs_filter>).
CLEAR : ex_matnr, ex_werks, ex_lgort, ex_bukrs.
ex_matnr-option = 'EQ'.
ex_matnr-sign = 'I'.
ex_matnr-low = <fs_filter>-matnr.
APPEND ex_matnr TO ex_matnr[].
ex_werks-option = 'EQ'.
ex_werks-sign = 'I'.
ex_werks-low = <fs_filter>-werks.
APPEND ex_werks TO ex_werks[].
ex_lgort-option = 'EQ'.
ex_lgort-sign = 'I'.
ex_lgort-low = <fs_filter>-lgort.
APPEND ex_lgort TO ex_lgort[].
ex_bukrs-option = 'EQ'.
ex_bukrs-sign = 'I'.
ex_bukrs-low = <fs_filter>-bukrs.
APPEND ex_bukrs TO ex_bukrs[].
ENDLOOP.
SORT ex_matnr[] BY low.
SORT ex_werks[] BY low.
SORT ex_lgort[] BY low.
DELETE ADJACENT DUPLICATES FROM ex_matnr[] COMPARING low.
DELETE ADJACENT DUPLICATES FROM ex_werks[] COMPARING low.
DELETE ADJACENT DUPLICATES FROM ex_lgort[] COMPARING low.
* SELECT *
* FROM zcds_inv_audit_report AS a
* WHERE
* a~bukrs = @p_bukrs AND
* a~matnr IN @ex_matnr AND
* a~werks IN @ex_werks AND
* a~lgort IN @ex_lgort AND
* CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
* INTO TABLE @DATA(lt_base_sumdata).
*
* SELECT *
* FROM zcds_inv_audit_report_tf301 AS a
* WHERE
* a~bukrs = @p_bukrs AND
* a~matnr IN @ex_matnr AND
* a~werks IN @ex_werks AND
* a~lgort IN @ex_lgort AND
* CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
* INTO TABLE @DATA(lt_base_sumdata_tf).
*
* SORT lt_base_sumdata BY mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks lgort awref awitem awitgrp.
* DELETE ADJACENT DUPLICATES FROM lt_base_sumdata
* COMPARING mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks lgort awref awitem awitgrp.
SELECT a~matnr, a~bukrs, a~werks, a~lgort, SUM( menge ) AS menge
FROM zcds_inv_matdoc AS a
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @ex_matnr AND
a~werks IN @ex_werks AND
a~lgort IN @ex_lgort AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
GROUP BY a~matnr, a~bukrs, a~werks, a~lgort INTO TABLE @DATA(lt_sum_matdoc).
SELECT a~matnr, a~bukrs, a~werks, a~lgort, SUM( hsl ) AS cost2
FROM zcds_inv_matdoc AS a INNER JOIN acdoca AS b
ON a~bukrs = b~rbukrs AND a~mblnr = b~awref AND a~mjahr = b~gjahr AND a~zeile = right( b~awitem, 4 )
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @ex_matnr AND
a~werks IN @ex_werks AND
a~lgort IN @ex_lgort AND
b~rldnr = '0L' AND
b~koart = 'M' AND
b~ktosl = 'BSX' AND
a~bwart NOT IN ('311','312') AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
GROUP BY a~matnr, a~bukrs, a~werks, a~lgort INTO TABLE @DATA(lt_op_balance).
SELECT a~matnr, a~bukrs, a~werks, a~lgort, SUM( hsl ) AS cost2
FROM zcds_inv_matdoc AS a INNER JOIN acdoca AS b
ON a~bukrs = b~rbukrs AND a~mblnr = b~awref AND a~mjahr = b~gjahr AND a~zeile = right( b~awitem, 4 )
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @ex_matnr AND
a~werks IN @ex_werks AND
a~umlgo IN @ex_lgort AND
b~rldnr = '0L' AND
b~koart = 'M' AND
b~ktosl = 'BSX' AND
a~bwart NOT IN ('311','312') AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
GROUP BY a~matnr, a~bukrs, a~werks, a~lgort INTO TABLE @DATA(lt_op_balance_tf).
SELECT a~matnr, a~bukrs, a~werks, a~lgort, SUM( hsl ) AS cost2
FROM zcds_inv_matdoc AS a INNER JOIN acdoca AS b
ON a~bukrs = b~rbukrs AND a~ebeln = b~ebeln AND a~ebelp = b~ebelp
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @ex_matnr AND
a~werks IN @ex_werks AND
a~lgort IN @ex_lgort AND
b~rldnr = '0L' AND
b~koart = 'M' AND
b~ktosl = 'BSX' AND
b~blart = 'RE' AND
a~bwart IN ('101','102') AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
GROUP BY a~matnr, a~bukrs, a~werks, a~lgort INTO TABLE @DATA(lt_op_balance_re).
SORT lt_op_balance BY matnr bukrs werks lgort ASCENDING.
SORT lt_op_balance_tf BY matnr bukrs werks lgort ASCENDING.
SORT lt_op_balance_re BY matnr bukrs werks lgort ASCENDING.
SORT lt_sum_matdoc BY matnr bukrs werks lgort ASCENDING.
ENDIF.
CLEAR ls_audit_datax.
LOOP AT lt_audit_datax INTO ls_audit_datax.
CLEAR ls_data.
READ TABLE lt_matdesc ASSIGNING FIELD-SYMBOL(<fs_matdesc>) WITH KEY matnr = ls_audit_datax-matnr BINARY SEARCH.
IF sy-subrc = 0.
ls_data-zmatspec = <fs_matdesc>-matspec.
ENDIF.
REFRESH : lt_sumdata_cls, lt_sumdata.
IF ls_audit_datax-lgort IS INITIAL.
zcl_mm_saldo_awal_audit_report=>get_opening_balance_closing(
EXPORTING
ip_client = sy-mandt
ip_matnr = ls_audit_datax-matnr
ip_bukrs = ls_audit_datax-bukrs
ip_werks = ls_audit_datax-werks
* ip_lgort = ls_audit_datax-lgort
ip_budat = str_budat
ip_cpudt = p_cpudt
IMPORTING
ex_sumdata = lt_sumdata_cls "Get opening balance per material, plant, sloc
).
CLEAR ls_sumdata_cls.
READ TABLE lt_sumdata_cls INTO ls_sumdata_cls INDEX 1.
ls_data-menge2 = 0.
ls_data-cost3 = ls_sumdata-cost2.
ELSE.
CLEAR ls_sumdata.
READ TABLE lt_op_balance ASSIGNING FIELD-SYMBOL(<fs_sumdata>)
WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
werks = ls_audit_datax-werks lgort = ls_audit_datax-lgort BINARY SEARCH.
IF sy-subrc = 0.
* ls_data-menge2 = <fs_sumdata>-menge.
ls_data-cost3 = <fs_sumdata>-cost2.
ENDIF.
*
READ TABLE lt_op_balance_tf ASSIGNING FIELD-SYMBOL(<fs_sumtfdata>)
WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
werks = ls_audit_datax-werks lgort = ls_audit_datax-lgort BINARY SEARCH.
IF sy-subrc = 0.
* ls_data-menge2 = ls_data-menge2 + <fs_sumtfdata>-menge.
ls_data-cost3 = ls_data-cost3 + <fs_sumtfdata>-cost2.
ENDIF.
READ TABLE lt_op_balance_re ASSIGNING FIELD-SYMBOL(<fs_sumtfdatare>)
WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
werks = ls_audit_datax-werks lgort = ls_audit_datax-lgort BINARY SEARCH.
IF sy-subrc = 0.
* ls_data-menge2 = ls_data-menge2 + <fs_sumtfdata>-menge.
ls_data-cost3 = ls_data-cost3 + <fs_sumtfdatare>-cost2.
ENDIF.
READ TABLE lt_sum_matdoc ASSIGNING FIELD-SYMBOL(<fs_matdoc>)
WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
werks = ls_audit_datax-werks lgort = ls_audit_datax-lgort BINARY SEARCH.
IF sy-subrc = 0.
ls_data-menge2 = <fs_matdoc>-menge.
ENDIF.
ENDIF.
ls_data-matnr = ls_audit_datax-matnr.
ls_data-maktx = ls_audit_datax-maktx.
ls_data-bukrs = ls_audit_datax-bukrs.
ls_data-werks = ls_audit_datax-werks.
ls_data-lgort = ls_audit_datax-lgort.
ls_data-mblnr = 'OP Balance'.
ls_data-waers = ccwaers.
* SELECT SINGLE meins FROM mara INTO ls_audit_datax-meins WHERE matnr = ls_audit_datax-matnr.
ls_data-meins = ls_audit_datax-meins.
ls_data-linecolor = 'C511'.
* ls_data-linecolor = 'C311'.
APPEND ls_data TO lt_data.
CLEAR : zcum_qty, zcum_val, ls_audit_data.
zcum_qty = ls_data-menge2.
zcum_val = ls_data-cost3.
READ TABLE lt_audit_data WITH KEY matnr = ls_audit_datax-matnr werks = ls_audit_datax-werks lgort = ls_audit_datax-lgort TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT lt_audit_data INTO ls_audit_data WHERE matnr = ls_audit_datax-matnr AND
werks = ls_audit_datax-werks AND
lgort = ls_audit_datax-lgort.
CLEAR ls_data.
MOVE-CORRESPONDING ls_audit_data TO ls_data.
IF ls_data-cost2 IS NOT INITIAL AND ls_data-menge1 IS NOT INITIAL.
ls_data-cost1 = ls_data-cost2 / ls_data-menge1.
IF ls_data-cost2 < 0 AND ls_data-menge1 < 0.
ls_data-cost1 = ls_data-cost1 * -1.
ENDIF.
ENDIF.
zcum_qty = zcum_qty + ls_data-menge1.
zcum_val = zcum_val + ls_data-cost2.
ls_data-menge2 = zcum_qty.
ls_data-cost3 = zcum_val.
ls_data-waers = ccwaers.
ls_data-linecolor = 'C2'.
READ TABLE lt_kbdoc ASSIGNING FIELD-SYMBOL(<fs_kbdoc>)
WITH KEY mblnr = ls_audit_data-mblnr mjahr = ls_audit_data-mjahr.
IF sy-subrc = 0.
ls_data-kbtype = <fs_kbdoc>-kbtype.
ls_data-kbnum = <fs_kbdoc>-kbnum.
ls_data-kbdate = <fs_kbdoc>-kbdate.
ENDIF.
APPEND ls_data TO lt_data.
CLEAR ls_audit_data.
ENDLOOP.
ENDIF.
IF ls_data IS NOT INITIAL.
CLEAR : ls_data-mblnr, ls_data-budat, ls_data-cpudt, ls_data-xabln, ls_data-cost1, ls_data-grref,
ls_data-cost2, ls_data-menge1, ls_data-mjahr, ls_data-bwart, ls_data-racct, ls_data-gkont,
ls_data-belnr, ls_data-gjahr, ls_data-kbtype, ls_data-kbnum, ls_data-kbdate.
ls_data-mblnr = 'EndBalance'.
ls_data-linecolor = 'C311'.
CLEAR ls_data_end.
MOVE-CORRESPONDING ls_data TO ls_data_end.
APPEND ls_data TO lt_data.
ENDIF.
* BREAK-POINT.
"Ambil Data Dari Hasil Closing
CLEAR ls_audit_clse.
READ TABLE lt_audit_clse WITH KEY matnr = ls_audit_datax-matnr werks = ls_audit_datax-werks TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT lt_audit_clse INTO ls_audit_clse
WHERE matnr = ls_audit_datax-matnr AND
werks = ls_audit_datax-werks.
CLEAR ls_data.
MOVE-CORRESPONDING ls_audit_clse TO ls_data.
ls_data-maktx = ls_audit_datax-maktx.
IF ls_data-cost2 IS NOT INITIAL AND ls_data-menge1 IS NOT INITIAL.
ls_data-cost1 = ls_data-cost2 / ls_data-menge1.
IF ls_data-cost2 < 0 AND ls_data-menge1 < 0.
ls_data-cost1 = ls_data-cost1 * -1.
ENDIF.
ENDIF.
zcum_qty = zcum_qty + ls_data-menge1.
zcum_val = zcum_val + ls_data-cost2.
ls_data-meins = ls_audit_datax-meins.
ls_data-menge2 = 0.
ls_data-cost3 = zcum_val.
ls_data-waers = ccwaers.
ls_data-linecolor = 'C2'.
APPEND ls_data TO lt_data.
CLEAR ls_audit_clse.
ENDLOOP.
ENDIF.
* IF ls_data_end IS NOT INITIAL.
* CLEAR : ls_data-mblnr, ls_data-budat, ls_data-cpudt, ls_data-xabln, ls_data-cost1,
* ls_data-cost2, ls_data-menge1, ls_data-mjahr, ls_data-bwart, ls_data-racct, ls_data-belnr, ls_data-gjahr.
* ls_data-mblnr = 'EndBalance'.
* ls_data-linecolor = 'C311'.
* APPEND ls_data_end TO lt_data.
* ENDIF.
CLEAR ls_audit_datax.
ENDLOOP.
* BREAK-POINT.
* SORT lt_data BY matnr bukrs werks lgort ASCENDING.
ENDFORM.
FORM get_inv_sloc_level.
CLEAR ccwaers.
DATA(splant) = |WERKS LIKE '{ p_bukrs }%'|.
SELECT * FROM zcds_sloc_kb_indicator
INTO TABLE @DATA(lt_zvtwlad)
WHERE (splant).
IF grp1 = 'X'.
IF p_ckb = 'X' AND p_nkb = 'X'.
ELSEIF p_ckb = 'X'.
DELETE lt_zvtwlad WHERE kbindicator <> 'KB'.
IF lt_zvtwlad IS INITIAL.
MESSAGE 'Data not found' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ELSEIF p_nkb = 'X' .
DELETE lt_zvtwlad WHERE kbindicator = 'KB'.
IF lt_zvtwlad IS INITIAL.
MESSAGE 'Data not found' TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
ENDIF.
ENDIF.
CLEAR : prperiod, ccwaers, str_budat, pryear, splant.
IF s_budat-low IS INITIAL.
* str_budat = '00000000'.
ELSE.
str_budat = s_budat-low.
prperiod = s_budat-low+4(2).
IF s_budat-low+4(2) = '01'.
pryear = s_budat-low(4).
pryear = pryear - 1.
prperiod = '12'.
ELSE.
prperiod = prperiod - 1.
pryear = s_budat-low(4).
ENDIF.
ENDIF.
SELECT SINGLE waers FROM t001 INTO ccwaers WHERE bukrs = p_bukrs.
REFRESH : lt_datat, lt_data, lt_datax.
"Ambil data Goods Movement Yg ada document FI
SELECT * FROM zcds_inv_audit_report_v3
INTO TABLE @DATA(lt_movement)
FOR ALL ENTRIES IN @lt_zvtwlad
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr
AND lgort = @lt_zvtwlad-lgort.
SELECT * FROM zcds_inv_audit_report_umb
INTO TABLE @DATA(lt_umb)
FOR ALL ENTRIES IN @lt_zvtwlad
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr
AND lgort = @lt_zvtwlad-lgort.
LOOP AT lt_movement ASSIGNING FIELD-SYMBOL(<fs_movement>).
CLEAR ls_data.
MOVE-CORRESPONDING <fs_movement> TO ls_data.
READ TABLE lt_umb ASSIGNING FIELD-SYMBOL(<fs_umb>)
WITH KEY mblnr = <fs_movement>-mblnr mjahr = <fs_movement>-mjahr
zeile = <fs_movement>-zeile menge1 = <fs_movement>-menge1.
IF sy-subrc = 0.
CLEAR ls_data-lgort.
ENDIF.
APPEND ls_data TO lt_datat.
ENDLOOP.
SORT lt_movement BY mblnr mjahr zeile.
"Ambil data goods movement transfer
SELECT * FROM zcds_inv_matdoc
INTO TABLE @DATA(lt_transfer)
FOR ALL ENTRIES IN @lt_zvtwlad
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr
AND bwart IN ('301','302','311','312')
AND lgort = @lt_zvtwlad-lgort.
* SORT lt_movement by mblnr mjahr
LOOP AT lt_transfer ASSIGNING FIELD-SYMBOL(<fs_transfer>).
CLEAR ls_data.
READ TABLE lt_movement
WITH KEY mblnr = <fs_transfer>-mblnr mjahr = <fs_transfer>-mjahr zeile = <fs_transfer>-zeile
TRANSPORTING NO FIELDS BINARY SEARCH.
IF sy-subrc <> 0.
MOVE-CORRESPONDING <fs_transfer> TO ls_data.
ls_data-menge1 = <fs_transfer>-menge.
APPEND ls_data TO lt_datat.
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.
"Ambil data RE dan Price Change
SELECT * FROM zcds_inv_audit_report_re
INTO TABLE @DATA(lt_prchg_re)
FOR ALL ENTRIES IN @lt_zvtwlad
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr
AND lgort = @lt_zvtwlad-lgort.
LOOP AT lt_prchg_re ASSIGNING FIELD-SYMBOL(<fs_prchg_re>).
CLEAR ls_data.
MOVE-CORRESPONDING <fs_prchg_re> TO ls_data.
CLEAR ls_data-lgort.
APPEND ls_data TO lt_datat.
ENDLOOP.
"Opening Balance Qty
IF p_ckb = 'X' AND grp1 = 'X'.
SELECT
a~matnr, a~bukrs, a~werks, a~lgort,
SUM( menge1 ) AS menge, SUM( a~cost2 ) AS cost2
FROM zcds_inv_audit_report_v3 AS a
INNER JOIN zcds_sloc_kb_indicator AS b
ON a~werks = b~werks AND a~lgort = b~lgort
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @s_matnr AND
a~werks IN @s_werks AND
b~kbindicator = 'KB' AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
GROUP BY a~matnr, a~bukrs, a~werks, a~lgort
INTO TABLE @DATA(lt_sum_matdoc).
ELSE.
SELECT
a~matnr, a~bukrs, a~werks, a~lgort,
SUM( menge1 ) AS menge, SUM( a~cost2 ) AS cost2
FROM zcds_inv_audit_report_v3 AS a
* FOR ALL ENTRIES IN @lt_zvtwlad
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @s_matnr AND
a~werks IN @s_werks AND
* a~lgort = @lt_zvtwlad-lgort AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
GROUP BY a~matnr, a~bukrs, a~werks, a~lgort
INTO TABLE @lt_sum_matdoc.
ENDIF.
"Opening Balance Value
* SELECT a~matnr, b~bukrs, a~werks, SUM( a~hsl ) AS cost2
* FROM acdoca AS a INNER JOIN bkpf AS b
* ON a~rbukrs = b~bukrs AND a~belnr = b~belnr AND a~gjahr = b~gjahr
* WHERE
* a~rbukrs = @p_bukrs AND
* a~matnr IN @s_matnr AND
* a~werks IN @s_werks AND
* a~koart = 'M' AND
* a~ktosl = 'BSX' AND
* a~rldnr = '0L' AND
* CASE WHEN @p_cpudt = 'X' THEN b~cpudt ELSE b~budat END < @str_budat
* GROUP BY a~matnr, b~bukrs, a~werks INTO TABLE @DATA(lt_op_balance).
REFRESH lt_datax.
IF lt_sum_matdoc IS NOT INITIAL.
LOOP AT lt_sum_matdoc ASSIGNING FIELD-SYMBOL(<fs_sum1>).
CLEAR ls_data.
MOVE-CORRESPONDING <fs_sum1> TO ls_data.
APPEND ls_data TO lt_datax.
ENDLOOP.
ENDIF.
IF lt_datat IS NOT INITIAL.
APPEND LINES OF lt_datat TO lt_datax.
ENDIF.
IF lt_datax IS NOT INITIAL.
IF lt_datat IS NOT INITIAL.
"Ambil document BC by doc MIGO
SELECT * FROM zmmdt_kb_trans
INTO TABLE @DATA(lt_kbdoc)
FOR ALL ENTRIES IN @lt_datat
WHERE mblnr = @lt_datat-mblnr AND mjahr = @lt_datat-mjahr.
ENDIF.
SORT lt_datax BY matnr bukrs werks lgort.
DELETE ADJACENT DUPLICATES FROM lt_datax COMPARING matnr bukrs werks lgort.
"Ambil Material Desc & Spec
SELECT * FROM zcds_matdesc5
INTO TABLE @DATA(lt_material)
FOR ALL ENTRIES IN @lt_datax
WHERE matnr = @lt_datax-matnr.
* SORT lt_op_balance BY matnr bukrs werks ASCENDING.
SORT lt_sum_matdoc BY matnr bukrs werks lgort ASCENDING.
IF p_cpudt = ''.
SORT lt_datax BY matnr bukrs werks lgort budat cpudt cputm mblnr ASCENDING.
SORT lt_datat BY matnr bukrs werks lgort budat cpudt cputm mblnr ASCENDING.
ELSE.
SORT lt_datax BY matnr bukrs werks lgort cpudt cputm budat mblnr ASCENDING.
SORT lt_datat BY matnr bukrs werks lgort cpudt cputm budat mblnr ASCENDING.
ENDIF.
LOOP AT lt_datax ASSIGNING FIELD-SYMBOL(<fs_datax>).
CLEAR : ls_data, ls_sumdata.
ls_data-matnr = <fs_datax>-matnr.
READ TABLE lt_material ASSIGNING FIELD-SYMBOL(<fs_material1>) WITH KEY matnr = <fs_datax>-matnr.
IF sy-subrc = 0.
ls_data-maktx = <fs_material1>-maktx.
ls_data-zmatspec = <fs_material1>-matspec.
ENDIF.
READ TABLE lt_sum_matdoc ASSIGNING FIELD-SYMBOL(<fs_matdoc>)
WITH KEY matnr = <fs_datax>-matnr bukrs = <fs_datax>-bukrs
werks = <fs_datax>-werks lgort = <fs_datax>-lgort BINARY SEARCH.
IF sy-subrc = 0.
ls_data-menge2 = <fs_matdoc>-menge.
ls_data-cost3 = <fs_matdoc>-cost2.
ENDIF.
ls_data-bukrs = <fs_datax>-bukrs.
ls_data-werks = <fs_datax>-werks.
ls_data-lgort = <fs_datax>-lgort.
ls_data-mblnr = 'OP Balance'.
ls_data-waers = ccwaers.
ls_data-meins = <fs_datax>-meins.
ls_data-linecolor = 'C511'.
APPEND ls_data TO lt_data.
CLEAR : zcum_qty, zcum_val, ls_audit_data.
zcum_qty = ls_data-menge2.
zcum_val = ls_data-cost3.
* CLEAR ls_data.
LOOP AT lt_datat ASSIGNING FIELD-SYMBOL(<fs_data>)
WHERE matnr = <fs_datax>-matnr AND bukrs = <fs_datax>-bukrs AND werks = <fs_datax>-werks AND lgort = <fs_datax>-lgort.
CLEAR ls_data.
MOVE-CORRESPONDING <fs_data> TO ls_data.
READ TABLE lt_material ASSIGNING FIELD-SYMBOL(<fs_material>) WITH KEY matnr = <fs_data>-matnr.
IF sy-subrc = 0.
ls_data-maktx = <fs_material>-maktx.
ls_data-zmatspec = <fs_material>-matspec.
ENDIF.
READ TABLE lt_kbdoc ASSIGNING FIELD-SYMBOL(<fs_kbdoc>)
WITH KEY mblnr = <fs_data>-mblnr mjahr = <fs_data>-mjahr.
IF sy-subrc = 0.
ls_data-kbtype = <fs_kbdoc>-kbtype.
ls_data-kbnum = <fs_kbdoc>-kbnum.
ls_data-kbdate = <fs_kbdoc>-kbdate.
ENDIF.
IF ls_data-cost2 IS NOT INITIAL AND ls_data-menge1 IS NOT INITIAL.
ls_data-cost1 = ls_data-cost2 / ls_data-menge1.
IF ls_data-cost2 < 0 AND ls_data-menge1 < 0.
ls_data-cost1 = ls_data-cost1 * -1.
ENDIF.
ENDIF.
zcum_qty = zcum_qty + ls_data-menge1.
zcum_val = zcum_val + ls_data-cost2.
ls_data-menge2 = zcum_qty.
ls_data-cost3 = zcum_val.
ls_data-waers = ccwaers.
ls_data-linecolor = 'C2'.
APPEND ls_data TO lt_data.
CLEAR <fs_data>.
ENDLOOP.
IF ls_data IS NOT INITIAL.
CLEAR : ls_data-mblnr, ls_data-budat, ls_data-cpudt, ls_data-xabln, ls_data-cost1, ls_data-grref,
ls_data-cost2, ls_data-menge1, ls_data-mjahr, ls_data-bwart, ls_data-racct, ls_data-gkont,
ls_data-belnr, ls_data-gjahr, ls_data-kbtype, ls_data-kbnum, ls_data-kbdate, ls_data-blart.
ls_data-mblnr = 'EndBalance'.
ls_data-linecolor = 'C311'.
CLEAR ls_data_end.
MOVE-CORRESPONDING ls_data TO ls_data_end.
APPEND ls_data TO lt_data.
ENDIF.
ENDLOOP.
ELSE.
ENDIF.
ENDFORM.
Include ZRMM008_04.
*&---------------------------------------------------------------------*
*& Include ZRMM008_04
*&---------------------------------------------------------------------*
FORM get_data_plant_level.
REFRESH : ex_matnr, ex_werks, ex_lgort, ex_bukrs.
CLEAR : prperiod, ccwaers, str_budat, pryear.
IF s_budat-low IS INITIAL.
* str_budat = '00000000'.
ELSE.
str_budat = s_budat-low.
prperiod = s_budat-low+4(2).
IF s_budat-low+4(2) = '01'.
pryear = s_budat-low(4).
pryear = pryear - 1.
prperiod = '12'.
ELSE.
prperiod = prperiod - 1.
pryear = s_budat-low(4).
ENDIF.
ENDIF.
SELECT SINGLE waers FROM t001 INTO ccwaers WHERE bukrs = p_bukrs.
REFRESH : lt_audit_data, lt_audit_datax, lt_audit_clse, lt_audit_data301.
SELECT DISTINCT * FROM zcds_inv_audit_report INTO TABLE @lt_audit_data
WHERE bukrs = @p_bukrs "AND gjahr IN @s_gjahr
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr.
SELECT DISTINCT * FROM zcds_inv_audit_report_tf301_v2 INTO TABLE @lt_audit_data301
WHERE bukrs = @p_bukrs "AND gjahr IN @s_gjahr
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr.
IF lt_audit_data301 IS NOT INITIAL.
APPEND LINES OF lt_audit_data301 TO lt_audit_data.
ENDIF.
CHECK lt_audit_data IS NOT INITIAL.
SORT lt_audit_data BY mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks lgort menge1 hsl awref awitem awitgrp.
* DELETE ADJACENT DUPLICATES FROM lt_audit_data
* COMPARING mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks lgort menge1 hsl awref awitem awitgrp.
REFRESH : ex_mblnr, ex_zeile.
LOOP AT lt_audit_data ASSIGNING FIELD-SYMBOL(<fs_extf301>).
CLEAR ex_mblnr.
ex_mblnr-sign = 'I'.
ex_mblnr-option = 'EQ'.
ex_mblnr-low = <fs_extf301>-mblnr.
APPEND ex_mblnr TO ex_mblnr[].
CLEAR ex_zeile.
ex_zeile-sign = 'I'.
ex_zeile-option = 'EQ'.
ex_zeile-low = <fs_extf301>-awitem.
APPEND ex_zeile TO ex_zeile[].
ENDLOOP.
SORT ex_mblnr[] BY low.
SORT ex_zeile[] BY low.
DELETE ADJACENT DUPLICATES FROM ex_mblnr[] COMPARING low.
DELETE ADJACENT DUPLICATES FROM ex_zeile[] COMPARING low.
SELECT DISTINCT * FROM zcds_inv_audit_report_tf301
INTO TABLE @DATA(lt_invtf301)
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr. "AND mblnr IN @ex_mblnr. "AND zeile NOT IN @ex_zeile.
IF lt_invtf301 IS NOT INITIAL.
SORT lt_invtf301 BY mblnr mjahr zeile.
LOOP AT lt_invtf301 ASSIGNING FIELD-SYMBOL(<fs_inv301>).
CLEAR zzawitem.
zzawitem = <fs_inv301>-zeile.
READ TABLE lt_audit_data WITH KEY mblnr = <fs_inv301>-mblnr awitem = zzawitem TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
CLEAR ls_audit_data.
MOVE-CORRESPONDING <fs_inv301> TO ls_audit_data.
APPEND ls_audit_data TO lt_audit_data.
ENDIF.
ENDLOOP.
* APPEND LINES OF lt_invtf301 TO lt_audit_data.
ENDIF.
SELECT DISTINCT * FROM zcds_inv_audit_report INTO TABLE @DATA(lt_audit_data_change_price)
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr AND ( awtyp = 'PRCHG' OR awtyp = '' ).
IF lt_audit_data_change_price IS NOT INITIAL.
APPEND LINES OF lt_audit_data_change_price TO lt_audit_data.
ENDIF.
SELECT DISTINCT * FROM zcds_inv_audit_report_closing INTO TABLE @lt_audit_clse
WHERE bukrs = @p_bukrs "AND gjahr IN @s_gjahr and
AND werks IN @s_werks
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND matnr IN @s_matnr.
IF lt_audit_data IS NOT INITIAL.
lt_audit_datax = lt_audit_data.
ENDIF.
SORT lt_audit_data BY mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks lgort menge1 hsl awref awitem awitgrp.
* DELETE ADJACENT DUPLICATES FROM lt_audit_data
* COMPARING mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks lgort menge1 hsl awref awitem awitgrp.
SELECT * FROM zcds_matdesc5
INTO TABLE @DATA(lt_matdesc)
FOR ALL ENTRIES IN @lt_audit_data
WHERE matnr = @lt_audit_data-matnr.
SORT lt_matdesc BY matnr.
IF lt_audit_clse IS NOT INITIAL.
CLEAR ls_audit_clse.
LOOP AT lt_audit_clse INTO ls_audit_clse.
CLEAR ls_audit_datax.
MOVE-CORRESPONDING ls_audit_clse TO ls_audit_datax.
APPEND ls_audit_datax TO lt_audit_datax.
APPEND ls_audit_datax TO lt_audit_data.
CLEAR ls_audit_clse.
ENDLOOP.
ENDIF.
SORT lt_audit_datax BY matnr bukrs werks.
DELETE ADJACENT DUPLICATES FROM lt_audit_datax COMPARING matnr bukrs werks.
IF p_cpudt = ''.
SORT lt_audit_datax BY matnr bukrs werks budat cpudt cputm mblnr ASCENDING.
SORT lt_audit_data BY matnr bukrs werks budat cpudt cputm mblnr ASCENDING.
SORT lt_audit_clse BY matnr bukrs werks budat cpudt cputm belnr ASCENDING.
ELSE.
SORT lt_audit_datax BY matnr bukrs werks cpudt cputm budat mblnr ASCENDING.
SORT lt_audit_data BY matnr bukrs werks cpudt cputm budat mblnr ASCENDING.
SORT lt_audit_clse BY matnr bukrs werks cpudt cputm budat belnr ASCENDING.
ENDIF.
"Ambil document BC by doc MIGO
SELECT * FROM zmmdt_kb_trans
INTO TABLE @DATA(lt_kbdoc)
FOR ALL ENTRIES IN @lt_audit_data
WHERE mblnr = @lt_audit_data-mblnr AND mjahr = @lt_audit_data-mjahr.
SORT lt_kbdoc BY mblnr mjahr.
IF lt_audit_datax IS NOT INITIAL.
CLEAR : ex_matnr, ex_werks, ex_lgort, ex_bukrs.
LOOP AT lt_audit_datax ASSIGNING FIELD-SYMBOL(<fs_filter>).
CLEAR : ex_matnr, ex_werks, ex_lgort, ex_bukrs.
ex_matnr-option = 'EQ'.
ex_matnr-sign = 'I'.
ex_matnr-low = <fs_filter>-matnr.
APPEND ex_matnr TO ex_matnr[].
ex_werks-option = 'EQ'.
ex_werks-sign = 'I'.
ex_werks-low = <fs_filter>-werks.
APPEND ex_werks TO ex_werks[].
ex_lgort-option = 'EQ'.
ex_lgort-sign = 'I'.
ex_lgort-low = <fs_filter>-lgort.
APPEND ex_lgort TO ex_lgort[].
ex_bukrs-option = 'EQ'.
ex_bukrs-sign = 'I'.
ex_bukrs-low = <fs_filter>-bukrs.
APPEND ex_bukrs TO ex_bukrs[].
ENDLOOP.
SORT ex_matnr[] BY low.
SORT ex_werks[] BY low.
SORT ex_lgort[] BY low.
DELETE ADJACENT DUPLICATES FROM ex_matnr[] COMPARING low.
DELETE ADJACENT DUPLICATES FROM ex_werks[] COMPARING low.
DELETE ADJACENT DUPLICATES FROM ex_lgort[] COMPARING low.
SELECT *
FROM zcds_inv_audit_report AS a
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @ex_matnr AND
a~werks IN @ex_werks AND
* a~lgort IN @ex_lgort AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
INTO TABLE @DATA(lt_base_sumdata).
SELECT *
FROM zcds_inv_audit_report_tf301 AS a
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @ex_matnr AND
a~werks IN @ex_werks AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
INTO TABLE @DATA(lt_base_sumdata_tf).
SORT lt_base_sumdata BY mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks awref awitem awitgrp.
SORT lt_base_sumdata_tf BY mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks awref awitem awitgrp.
DELETE ADJACENT DUPLICATES FROM lt_base_sumdata
COMPARING mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks awref awitem awitgrp.
DELETE ADJACENT DUPLICATES FROM lt_base_sumdata_tf
COMPARING mblnr mjahr xabln belnr gjahr bukrs bukrs poper periv matnr werks awref awitem awitgrp.
SELECT a~matnr, a~bukrs, a~werks, SUM( menge ) AS menge
FROM zcds_inv_matdoc AS a
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @ex_matnr AND
a~werks IN @ex_werks AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
GROUP BY a~matnr, a~bukrs, a~werks INTO TABLE @DATA(lt_sum_matdoc).
SELECT a~matnr, b~bukrs, a~werks, SUM( a~hsl ) AS cost2
FROM acdoca AS a INNER JOIN bkpf AS b
ON a~rbukrs = b~bukrs AND a~belnr = b~belnr AND a~gjahr = b~gjahr
WHERE
a~rbukrs = @p_bukrs AND
a~matnr IN @ex_matnr AND
a~werks IN @ex_werks AND
a~koart = 'M' AND
a~ktosl = 'BSX' AND
a~rldnr = '0L' AND
CASE WHEN @p_cpudt = 'X' THEN b~cpudt ELSE b~budat END < @str_budat
GROUP BY a~matnr, b~bukrs, a~werks INTO TABLE @DATA(lt_op_balance).
* SELECT
* a~matnr,
* a~bukrs,
* a~werks,
** a~lgort,
* SUM( a~menge1 ) AS menge,
* SUM( a~cost2 ) AS cost2
* FROM @lt_base_sumdata AS a
* WHERE
* a~bukrs = @p_bukrs AND
* a~matnr IN @ex_matnr AND
* a~werks IN @ex_werks AND
** a~lgort IN @ex_lgort AND
* CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
* GROUP BY a~matnr, a~bukrs, a~werks INTO TABLE @DATA(lt_op_balance).
*
* SELECT
* a~matnr,
* a~bukrs,
* a~werks,
** a~lgort,
* SUM( a~menge1 ) AS menge,
* SUM( a~cost2 ) AS cost2
* FROM @lt_base_sumdata_tf AS a
* WHERE
* a~bukrs = @p_bukrs AND
* a~matnr IN @ex_matnr AND
* a~werks IN @ex_werks AND
** a~lgort IN @ex_lgort AND
* CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
* GROUP BY a~matnr, a~bukrs, a~werks INTO TABLE @DATA(lt_op_balance_tf).
*
* SELECT
* a~matnr,
* a~bukrs,
* a~werks,
* SUM( a~menge1 ) AS menge,
* SUM( a~cost2 ) AS cost2 FROM
* zcds_inv_audit_report_closing AS a
* WHERE
* a~bukrs = @p_bukrs AND
* a~matnr IN @ex_matnr AND
* a~werks IN @ex_werks AND
* CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
* GROUP BY a~matnr, a~bukrs, a~werks INTO TABLE @DATA(lt_op_balance_clsd).
ENDIF.
SORT lt_op_balance BY matnr bukrs werks ASCENDING.
* SORT lt_op_balance_tf BY matnr bukrs werks ASCENDING.
* SORT lt_op_balance_clsd BY matnr bukrs werks ASCENDING.
SORT lt_sum_matdoc BY matnr bukrs werks ASCENDING.
CLEAR ls_audit_datax.
LOOP AT lt_audit_datax INTO ls_audit_datax.
CLEAR ls_data.
READ TABLE lt_matdesc ASSIGNING FIELD-SYMBOL(<fs_matdesc>) WITH KEY matnr = ls_audit_datax-matnr BINARY SEARCH.
IF sy-subrc = 0.
ls_data-zmatspec = <fs_matdesc>-matspec.
ENDIF.
REFRESH : lt_sumdata_cls, lt_sumdata.
* IF ls_audit_datax-lgort IS INITIAL.
* zcl_mm_saldo_awal_audit_report=>get_opening_balance_closing(
* EXPORTING
* ip_client = sy-mandt
* ip_matnr = ls_audit_datax-matnr
* ip_bukrs = ls_audit_datax-bukrs
* ip_werks = ls_audit_datax-werks
** ip_lgort = ls_audit_datax-lgort
* ip_budat = str_budat
* ip_cpudt = p_cpudt
* IMPORTING
* ex_sumdata = lt_sumdata_cls "Get opening balance per material, plant, sloc
* ).
*
* CLEAR ls_sumdata_cls.
* READ TABLE lt_sumdata_cls INTO ls_sumdata_cls INDEX 1.
*
* ls_data-menge2 = 0.
* ls_data-cost3 = ls_sumdata-cost2.
* ELSE.
* CLEAR ls_sumdata.
* READ TABLE lt_op_balance ASSIGNING FIELD-SYMBOL(<fs_sumdata>)
* WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
* werks = ls_audit_datax-werks lgort = ls_audit_datax-lgort BINARY SEARCH.
*
* IF sy-subrc = 0.
* ls_data-menge2 = <fs_sumdata>-menge.
* ls_data-cost3 = <fs_sumdata>-cost2.
* ENDIF.
* ENDIF.
CLEAR ls_sumdata.
READ TABLE lt_op_balance ASSIGNING FIELD-SYMBOL(<fs_sumdata>)
WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
werks = ls_audit_datax-werks BINARY SEARCH.
IF sy-subrc = 0.
* ls_data-menge2 = <fs_sumdata>-menge.
ls_data-cost3 = <fs_sumdata>-cost2.
ENDIF.
* READ TABLE lt_op_balance_tf ASSIGNING FIELD-SYMBOL(<fs_sumtfdata>)
* WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
* werks = ls_audit_datax-werks BINARY SEARCH.
* IF sy-subrc = 0.
** ls_data-menge2 = ls_data-menge2 + <fs_sumtfdata>-menge.
* ls_data-cost3 = ls_data-cost3 + <fs_sumtfdata>-cost2.
* ENDIF.
*
* READ TABLE lt_op_balance_clsd ASSIGNING FIELD-SYMBOL(<fs_sumdatacls>)
* WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
* werks = ls_audit_datax-werks BINARY SEARCH.
*
* IF sy-subrc = 0.
** ls_data-menge2 = ls_data-menge2 + <fs_sumdatacls>-menge.
* ls_data-cost3 = ls_data-cost3 + <fs_sumdatacls>-cost2.
* ENDIF.
READ TABLE lt_sum_matdoc ASSIGNING FIELD-SYMBOL(<fs_matdoc>)
WITH KEY matnr = ls_audit_datax-matnr bukrs = ls_audit_datax-bukrs
werks = ls_audit_datax-werks BINARY SEARCH.
IF sy-subrc = 0.
ls_data-menge2 = <fs_matdoc>-menge.
ENDIF.
ls_data-matnr = ls_audit_datax-matnr.
ls_data-maktx = ls_audit_datax-maktx.
ls_data-bukrs = ls_audit_datax-bukrs.
ls_data-werks = ls_audit_datax-werks.
ls_data-lgort = ls_audit_datax-lgort.
ls_data-mblnr = 'OP Balance'.
ls_data-waers = ccwaers.
* SELECT SINGLE meins FROM mara INTO ls_audit_datax-meins WHERE matnr = ls_audit_datax-matnr.
ls_data-meins = ls_audit_datax-meins.
ls_data-linecolor = 'C511'.
* ls_data-linecolor = 'C311'.
APPEND ls_data TO lt_data.
CLEAR : zcum_qty, zcum_val, ls_audit_data.
zcum_qty = ls_data-menge2.
zcum_val = ls_data-cost3.
READ TABLE lt_audit_data WITH KEY matnr = ls_audit_datax-matnr werks = ls_audit_datax-werks TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
LOOP AT lt_audit_data INTO ls_audit_data WHERE matnr = ls_audit_datax-matnr AND
werks = ls_audit_datax-werks. "AND
* lgort = ls_audit_datax-lgort.
CLEAR ls_data.
MOVE-CORRESPONDING ls_audit_data TO ls_data.
IF ls_data-cost2 IS NOT INITIAL AND ls_data-menge1 IS NOT INITIAL.
ls_data-cost1 = ls_data-cost2 / ls_data-menge1.
IF ls_data-cost2 < 0 AND ls_data-menge1 < 0.
ls_data-cost1 = ls_data-cost1 * -1.
ENDIF.
ENDIF.
zcum_qty = zcum_qty + ls_data-menge1.
zcum_val = zcum_val + ls_data-cost2.
ls_data-menge2 = zcum_qty.
ls_data-cost3 = zcum_val.
ls_data-waers = ccwaers.
ls_data-linecolor = 'C2'.
READ TABLE lt_kbdoc ASSIGNING FIELD-SYMBOL(<fs_kbdoc>)
WITH KEY mblnr = ls_audit_data-mblnr mjahr = ls_audit_data-mjahr.
IF sy-subrc = 0.
ls_data-kbtype = <fs_kbdoc>-kbtype.
ls_data-kbnum = <fs_kbdoc>-kbnum.
ls_data-kbdate = <fs_kbdoc>-kbdate.
ENDIF.
APPEND ls_data TO lt_data.
CLEAR ls_audit_data.
ENDLOOP.
ENDIF.
IF ls_data IS NOT INITIAL.
CLEAR : ls_data-mblnr, ls_data-budat, ls_data-cpudt, ls_data-xabln, ls_data-cost1, ls_data-grref,
ls_data-cost2, ls_data-menge1, ls_data-mjahr, ls_data-bwart, ls_data-racct, ls_data-gkont,
ls_data-belnr, ls_data-gjahr, ls_data-kbtype, ls_data-kbnum, ls_data-kbdate.
ls_data-mblnr = 'EndBalance'.
ls_data-linecolor = 'C311'.
CLEAR ls_data_end.
MOVE-CORRESPONDING ls_data TO ls_data_end.
APPEND ls_data TO lt_data.
ENDIF.
CLEAR ls_audit_datax.
ENDLOOP.
ENDFORM.
FORM get_inv_plant_level.
CLEAR ccwaers.
CLEAR : prperiod, ccwaers, str_budat, pryear.
IF s_budat-low IS INITIAL.
* str_budat = '00000000'.
ELSE.
str_budat = s_budat-low.
prperiod = s_budat-low+4(2).
IF s_budat-low+4(2) = '01'.
pryear = s_budat-low(4).
pryear = pryear - 1.
prperiod = '12'.
ELSE.
prperiod = prperiod - 1.
pryear = s_budat-low(4).
ENDIF.
ENDIF.
SELECT SINGLE waers FROM t001 INTO ccwaers WHERE bukrs = p_bukrs.
REFRESH : lt_datat, lt_data, lt_datax.
"Ambil data Goods Movement Yg ada document FI
SELECT * FROM zcds_inv_audit_report_v3
INTO TABLE @DATA(lt_movement)
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr.
LOOP AT lt_movement ASSIGNING FIELD-SYMBOL(<fs_movement>).
CLEAR ls_data.
MOVE-CORRESPONDING <fs_movement> TO ls_data.
APPEND ls_data TO lt_datat.
ENDLOOP.
SORT lt_movement BY mblnr mjahr zeile.
"Ambil data goods movement transfer
SELECT * FROM zcds_inv_matdoc
INTO TABLE @DATA(lt_transfer)
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr
AND bwart IN ('301','302','311','312').
* SORT lt_movement by mblnr mjahr
LOOP AT lt_transfer ASSIGNING FIELD-SYMBOL(<fs_transfer>).
CLEAR ls_data.
READ TABLE lt_movement
WITH KEY mblnr = <fs_transfer>-mblnr mjahr = <fs_transfer>-mjahr zeile = <fs_transfer>-zeile
TRANSPORTING NO FIELDS BINARY SEARCH.
IF sy-subrc <> 0.
MOVE-CORRESPONDING <fs_transfer> TO ls_data.
ls_data-menge1 = <fs_transfer>-menge.
APPEND ls_data TO lt_datat.
ELSE.
CONTINUE.
ENDIF.
ENDLOOP.
"Ambil data RE dan Price Change
SELECT * FROM zcds_inv_audit_report_re
INTO TABLE @DATA(lt_prchg_re)
WHERE bukrs = @p_bukrs
AND CASE WHEN @p_cpudt = 'X' THEN cpudt ELSE budat END IN @s_budat
AND werks IN @s_werks
AND matnr IN @s_matnr.
LOOP AT lt_prchg_re ASSIGNING FIELD-SYMBOL(<fs_prchg_re>).
CLEAR ls_data.
MOVE-CORRESPONDING <fs_prchg_re> TO ls_data.
APPEND ls_data TO lt_datat.
ENDLOOP.
"Opening Balance Qty
SELECT a~matnr, a~bukrs, a~werks, SUM( menge ) AS menge
FROM zcds_inv_matdoc AS a
WHERE
a~bukrs = @p_bukrs AND
a~matnr IN @s_matnr AND
a~werks IN @s_werks AND
CASE WHEN @p_cpudt = 'X' THEN a~cpudt ELSE a~budat END < @str_budat
GROUP BY a~matnr, a~bukrs, a~werks INTO TABLE @DATA(lt_sum_matdoc).
"Opening Balance Value
SELECT a~matnr, b~bukrs, a~werks, SUM( a~hsl ) AS cost2
FROM acdoca AS a INNER JOIN bkpf AS b
ON a~rbukrs = b~bukrs AND a~belnr = b~belnr AND a~gjahr = b~gjahr
WHERE
a~rbukrs = @p_bukrs AND
a~matnr IN @s_matnr AND
a~werks IN @s_werks AND
a~koart = 'M' AND
a~ktosl = 'BSX' AND
a~rldnr = '0L' AND
CASE WHEN @p_cpudt = 'X' THEN b~cpudt ELSE b~budat END < @str_budat
GROUP BY a~matnr, b~bukrs, a~werks INTO TABLE @DATA(lt_op_balance).
REFRESH lt_datax.
IF lt_sum_matdoc IS NOT INITIAL.
LOOP AT lt_sum_matdoc ASSIGNING FIELD-SYMBOL(<fs_sum1>).
CLEAR ls_data.
MOVE-CORRESPONDING <fs_sum1> TO ls_data.
APPEND ls_data TO lt_datax.
ENDLOOP.
ELSE.
LOOP AT lt_op_balance ASSIGNING FIELD-SYMBOL(<fs_sum2>).
CLEAR ls_data.
MOVE-CORRESPONDING <fs_sum2> TO ls_data.
APPEND ls_data TO lt_datax.
ENDLOOP.
ENDIF.
IF lt_datat IS NOT INITIAL.
APPEND LINES OF lt_datat TO lt_datax.
ENDIF.
IF lt_datax IS NOT INITIAL.
IF lt_datat IS NOT INITIAL.
"Ambil document BC by doc MIGO
SELECT * FROM zmmdt_kb_trans
INTO TABLE @DATA(lt_kbdoc)
FOR ALL ENTRIES IN @lt_datat
WHERE mblnr = @lt_datat-mblnr AND mjahr = @lt_datat-mjahr.
ENDIF.
SORT lt_datax BY matnr bukrs werks.
DELETE ADJACENT DUPLICATES FROM lt_datax COMPARING matnr bukrs werks.
"Ambil Material Desc & Spec
SELECT * FROM zcds_matdesc5
INTO TABLE @DATA(lt_material)
FOR ALL ENTRIES IN @lt_datax
WHERE matnr = @lt_datax-matnr.
SORT lt_op_balance BY matnr bukrs werks ASCENDING.
SORT lt_sum_matdoc BY matnr bukrs werks ASCENDING.
IF p_cpudt = ''.
SORT lt_datax BY matnr bukrs werks budat cpudt cputm mblnr ASCENDING.
SORT lt_datat BY matnr bukrs werks budat cpudt cputm mblnr ASCENDING.
ELSE.
SORT lt_datax BY matnr bukrs werks cpudt cputm budat mblnr ASCENDING.
SORT lt_datat BY matnr bukrs werks cpudt cputm budat mblnr ASCENDING.
ENDIF.
LOOP AT lt_datax ASSIGNING FIELD-SYMBOL(<fs_datax>).
CLEAR : ls_data, ls_sumdata.
ls_data-matnr = <fs_datax>-matnr.
READ TABLE lt_material ASSIGNING FIELD-SYMBOL(<fs_material1>) WITH KEY matnr = <fs_datax>-matnr.
IF sy-subrc = 0.
ls_data-maktx = <fs_material1>-maktx.
ls_data-zmatspec = <fs_material1>-matspec.
ENDIF.
READ TABLE lt_op_balance ASSIGNING FIELD-SYMBOL(<fs_sumdata>)
WITH KEY matnr = <fs_datax>-matnr bukrs = <fs_datax>-bukrs
werks = <fs_datax>-werks BINARY SEARCH.
IF sy-subrc = 0.
ls_data-cost3 = <fs_sumdata>-cost2.
ENDIF.
READ TABLE lt_sum_matdoc ASSIGNING FIELD-SYMBOL(<fs_matdoc>)
WITH KEY matnr = <fs_datax>-matnr bukrs = <fs_datax>-bukrs
werks = <fs_datax>-werks BINARY SEARCH.
IF sy-subrc = 0.
ls_data-menge2 = <fs_matdoc>-menge.
ENDIF.
ls_data-bukrs = <fs_datax>-bukrs.
ls_data-werks = <fs_datax>-werks.
ls_data-lgort = ''.
ls_data-mblnr = 'OP Balance'.
ls_data-waers = ccwaers.
ls_data-meins = <fs_datax>-meins.
ls_data-linecolor = 'C511'.
APPEND ls_data TO lt_data.
CLEAR : zcum_qty, zcum_val, ls_audit_data.
zcum_qty = ls_data-menge2.
zcum_val = ls_data-cost3.
* CLEAR ls_data.
LOOP AT lt_datat ASSIGNING FIELD-SYMBOL(<fs_data>)
WHERE matnr = <fs_datax>-matnr AND bukrs = <fs_datax>-bukrs AND werks = <fs_datax>-werks.
CLEAR ls_data.
MOVE-CORRESPONDING <fs_data> TO ls_data.
READ TABLE lt_material ASSIGNING FIELD-SYMBOL(<fs_material>) WITH KEY matnr = <fs_data>-matnr.
IF sy-subrc = 0.
ls_data-maktx = <fs_material>-maktx.
ls_data-zmatspec = <fs_material>-matspec.
ENDIF.
READ TABLE lt_kbdoc ASSIGNING FIELD-SYMBOL(<fs_kbdoc>)
WITH KEY mblnr = <fs_data>-mblnr mjahr = <fs_data>-mjahr.
IF sy-subrc = 0.
ls_data-kbtype = <fs_kbdoc>-kbtype.
ls_data-kbnum = <fs_kbdoc>-kbnum.
ls_data-kbdate = <fs_kbdoc>-kbdate.
ENDIF.
IF ls_data-cost2 IS NOT INITIAL AND ls_data-menge1 IS NOT INITIAL.
ls_data-cost1 = ls_data-cost2 / ls_data-menge1.
IF ls_data-cost2 < 0 AND ls_data-menge1 < 0.
ls_data-cost1 = ls_data-cost1 * -1.
ENDIF.
ENDIF.
zcum_qty = zcum_qty + ls_data-menge1.
zcum_val = zcum_val + ls_data-cost2.
ls_data-menge2 = zcum_qty.
ls_data-cost3 = zcum_val.
ls_data-waers = ccwaers.
ls_data-linecolor = 'C2'.
APPEND ls_data TO lt_data.
CLEAR <fs_data>.
ENDLOOP.
IF ls_data IS NOT INITIAL.
CLEAR : ls_data-mblnr, ls_data-budat, ls_data-cpudt, ls_data-xabln, ls_data-cost1, ls_data-grref,
ls_data-cost2, ls_data-menge1, ls_data-mjahr, ls_data-bwart, ls_data-racct, ls_data-gkont,
ls_data-belnr, ls_data-gjahr, ls_data-kbtype, ls_data-kbnum, ls_data-kbdate, ls_data-blart.
ls_data-mblnr = 'EndBalance'.
ls_data-linecolor = 'C311'.
CLEAR ls_data_end.
MOVE-CORRESPONDING ls_data TO ls_data_end.
APPEND ls_data TO lt_data.
ENDIF.
ENDLOOP.
ELSE.
ENDIF.
ENDFORM.
Include ZRMM008_05.
*&---------------------------------------------------------------------*
*& Include ZRMM008_05
*&---------------------------------------------------------------------*
FORM set_fieldcat.
REFRESH lt_fieldcat.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = sy-repid
i_structure_name = 'ZSRMM008'
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
CLEAR ls_fieldcat.
LOOP AT lt_fieldcat INTO ls_fieldcat.
IF ls_fieldcat-fieldname = 'MENGE1' OR ls_fieldcat-fieldname = 'MENGE2' OR ls_fieldcat-fieldname = 'COST1' OR ls_fieldcat-fieldname = 'COST2'
OR ls_fieldcat-fieldname = 'COST3'.
ELSEIF ( ls_fieldcat-fieldname = 'MATNR' OR ls_fieldcat-fieldname = 'MAKTX' OR ls_fieldcat-fieldname = 'BUKRS'
OR ls_fieldcat-fieldname = 'WERKS' OR ls_fieldcat-fieldname = 'LGORT' ) AND grp1 = 'X'.
ls_fieldcat-key = 'X'.
ls_fieldcat-sp_group = 'X'.
IF ls_fieldcat-fieldname = 'BUKRS'.
ls_fieldcat-no_out = 'X'.
ENDIF.
MODIFY lt_fieldcat FROM ls_fieldcat
TRANSPORTING key emphasize no_out WHERE fieldname = ls_fieldcat-fieldname.
ELSEIF ( ls_fieldcat-fieldname = 'MATNR' OR ls_fieldcat-fieldname = 'MAKTX' OR ls_fieldcat-fieldname = 'BUKRS'
OR ls_fieldcat-fieldname = 'WERKS') AND grp2 = 'X'.
ls_fieldcat-key = 'X'.
ls_fieldcat-sp_group = 'X'.
IF ls_fieldcat-fieldname = 'BUKRS'.
ls_fieldcat-no_out = 'X'.
ENDIF.
MODIFY lt_fieldcat FROM ls_fieldcat
TRANSPORTING key emphasize no_out WHERE fieldname = ls_fieldcat-fieldname.
ELSEIF ls_fieldcat-fieldname = 'MBLNR'.
ls_fieldcat-seltext_s = ls_fieldcat-seltext_m = ls_fieldcat-seltext_l = 'Document'.
MODIFY lt_fieldcat FROM ls_fieldcat
TRANSPORTING seltext_l seltext_m seltext_s outputlen WHERE fieldname = ls_fieldcat-fieldname.
ELSEIF ls_fieldcat-fieldname = 'MEINS' OR ls_fieldcat-fieldname = 'WAERS'.
ls_fieldcat-no_out = 'X'.
MODIFY lt_fieldcat FROM ls_fieldcat
TRANSPORTING no_out WHERE fieldname = ls_fieldcat-fieldname.
ELSEIF ls_fieldcat-fieldname = 'GRREF'.
ls_fieldcat-seltext_s = ls_fieldcat-seltext_m = ls_fieldcat-seltext_l = 'Trans. Ref'.
ls_fieldcat-outputlen = 20.
MODIFY lt_fieldcat FROM ls_fieldcat
TRANSPORTING seltext_l seltext_m seltext_s outputlen WHERE fieldname = ls_fieldcat-fieldname.
ENDIF.
IF grp2 = 'X' AND ls_fieldcat-fieldname = 'LGORT'.
ls_fieldcat-no_out = 'X'.
MODIFY lt_fieldcat FROM ls_fieldcat
TRANSPORTING key emphasize no_out WHERE fieldname = ls_fieldcat-fieldname.
ENDIF.
CLEAR ls_fieldcat.
ENDLOOP.
ENDFORM.
FORM display_alv.
is_layout-colwidth_optimize = 'X'.
is_layout-info_fieldname = 'LINECOLOR'.
REFRESH lt_sort.
CLEAR ls_sort.
ls_sort-spos = 1.
ls_sort-fieldname = 'MATNR'.
ls_sort-up = 'X'.
ls_sort-subtot = 'X'.
APPEND ls_sort TO lt_sort.
CLEAR ls_sort.
ls_sort-spos = 2.
ls_sort-fieldname = 'MAKTX'.
APPEND ls_sort TO lt_sort.
CLEAR ls_sort.
ls_sort-spos = 4.
ls_sort-fieldname = 'WERKS'.
ls_sort-up = 'X'.
APPEND ls_sort TO lt_sort.
IF grp1 = 'X'.
CLEAR ls_sort.
ls_sort-spos = 5.
ls_sort-fieldname = 'LGORT'.
ls_sort-up = 'X'.
APPEND ls_sort TO lt_sort.
ENDIF.
DATA: it_menu TYPE slis_t_extab.
APPEND '&ODN' TO it_menu. "Ascending sort
APPEND '&OUP' TO it_menu. "Decending Sot
APPEND '&RNT' TO it_menu. "Print menu from list menu bar
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* i_structure_name = 'ZSRMM008'
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout = is_layout
it_fieldcat = lt_fieldcat
it_excluding = it_menu
it_sort = lt_sort
TABLES
t_outtab = lt_data.
ENDFORM.
FORM top_of_page.
DATA: date TYPE char11,
date2 TYPE char11,
ld_lines TYPE i,
ld_bulanx(3) TYPE c,
ld_bulan(3) TYPE c,
v_judul TYPE string,
ld_linesc(10) TYPE c,
vtitle TYPE char100,
vbukrs TYPE char100,
vname1 TYPE ad_name1,
vname2 TYPE ad_name1,
vname3 TYPE ad_name1,
vname4 TYPE ad_name1.
CLEAR ld_bulan.
CLEAR it_top.
ld_bulan = s_budat-low+4(2).
IF ld_bulan IS NOT INITIAL.
PERFORM conv_date USING ld_bulan CHANGING ld_bulanx.
CONCATENATE s_budat-low+6(2) ld_bulanx s_budat-low+0(4) INTO date SEPARATED BY '-'.
ENDIF.
CLEAR ld_bulan.
ld_bulan = s_budat-high+4(2).
IF ld_bulan IS NOT INITIAL.
PERFORM conv_date USING ld_bulan CHANGING ld_bulanx.
CONCATENATE s_budat-high+6(2) ld_bulanx s_budat-high+0(4) INTO date2 SEPARATED BY '-'.
ENDIF.
CLEAR : vname1, vname2, vname3, vname4, vbukrs.
SELECT SINGLE adrc~name1 adrc~name2 adrc~name3 adrc~name4
FROM adrc
INNER JOIN t001 ON adrc~addrnumber EQ t001~adrnr
INTO (vname1, vname2, vname3, vname4)
WHERE t001~bukrs = p_bukrs.
CLEAR vtitle.
CONCATENATE vname1 vname2 vname3 vname4 INTO vtitle SEPARATED BY space.
CONCATENATE p_bukrs '-' vtitle INTO vbukrs SEPARATED BY ' '.
CLEAR wa_top.
wa_top-typ = 'H'.
wa_top-info = vtitle.
APPEND wa_top TO it_top.
* CLEAR wa_top.
* wa_top-typ = 'A'.
* wa_top-info = 'Goods Receipt Purchase Order Detail Report'.
* APPEND wa_top TO it_top.
CLEAR wa_top.
IF s_budat-high IS INITIAL.
date2 = date.
ENDIF.
wa_top-typ = 'S'.
wa_top-info = 'Periode : '.
CONCATENATE wa_top-info date 's/d' date2
INTO wa_top-info
SEPARATED BY space.
APPEND wa_top TO it_top.
CLEAR ld_lines.
DESCRIBE TABLE lt_data LINES ld_lines.
CLEAR wa_top.
wa_top-typ = 'S'.
wa_top-info = |NUMBER OF LINE DATA { ld_lines } ROWS|.
* CONCATENATE wa_top-info DATE 's/d' date2
* INTO wa_top-info
* separated by space.
APPEND wa_top TO it_top.
CLEAR wa_top.
wa_top-typ = 'S'.
APPEND wa_top TO it_top.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_top.
ENDFORM.
FORM conv_date USING bln TYPE char3 CHANGING ld_bulanx.
CASE bln.
WHEN '01'.
month2 = 'Jan'.
WHEN '02'.
month2 = 'Feb'.
WHEN '03'.
month2 = 'Mar'.
WHEN '04'.
month2 = 'Apr'.
WHEN '05'.
month2 = 'May'.
WHEN '06'.
month2 = 'Jun'.
WHEN '07'.
month2 = 'Jul'.
WHEN '08'.
month2 = 'Aug'.
WHEN '09'.
month2 = 'Sep'.
WHEN '10'.
month2 = 'Oct'.
WHEN '11'.
month2 = 'Nov'.
WHEN '12'.
month2 = 'Dec'.
ENDCASE.
ld_bulanx = month2.
ENDFORM.
CDS View
@AbapCatalog.sqlViewName: 'ZVMM003'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS View Inventory Ledger Audit Report'
define view ZCDS_INV_AUDIT_REPORT as select from
matdoc as a inner join bkpf as b on a.mblnr = left(b.awkey, 10) and a.mjahr = right(b.awkey, 4)
and a.bukrs = b.bukrs
inner join acdoca as c on b.bukrs = c.rbukrs and b.belnr = c.belnr and c.gjahr = b.gjahr
and c.matnr = a.matnr and c.koart = 'M' and c.werks = a.werks and c.ktosl = 'BSX'
and a.mblnr = c.awref and a.zeile = right(c.awitem, 4)
inner join makt as d on a.matnr = d.matnr and d.spras = $session.system_language
and a.bukrs = b.bukrs {
key a.mblnr,
key a.mjahr,
key a.xabln,
key b.belnr,
key b.gjahr,
key b.bukrs,
key a.bwart,
key c.poper,
key c.periv,
key c.fiscyearper,
key a.matnr,
key a.werks,
key a.lgort,
d.maktx,
a.meins,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'RHCUR' c.hsl,
@Semantics.amount.currencyCode: 'RHCUR' c.hsl as cost2,
//@Semantics.amount.currencyCode: 'RHCUR' cast(c.hsl as abap.fltp) / cast(a.menge as abap.fltp ) as cost1,
c.rhcur,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'ROCUR' c.osl,
c.rocur,
@Semantics.quantity.unitOfMeasure: 'RUNIT' c.msl as menge1,
c.runit,
c.racct,
c.gkont,
a.budat,
a.cpudt,
a.cputm,
c.ktosl,
c.awtyp,
c.awsys,
c.aworg,
c.awref,
c.awitem,
c.awitgrp,
cast(
case
when ( a.bwart = '101' or a.bwart = '102' ) and a.ebeln <> '' then
'GRPO'
when ( a.bwart = '101' or a.bwart = '102' ) and a.aufnr <> '' then
'GRPROD'
end as char10 ) as grref
} where a.xauto = '' and c.rldnr = '0L' and c.koart = 'M' and
(a.bwart <> '301' and a.bwart <> '302' and a.bwart <> '311' and a.bwart <> '312')
union
select distinct from
matdoc as a
inner join makt as d on a.matnr = d.matnr and d.spras = $session.system_language
{
key a.mblnr,
key a.mjahr,
key a.xabln,
key a.mblnr as belnr,
key a.gjahr as gjahr,
key a.bukrs,
key a.bwart,
key cast(concat('0',substring(a.budat, 4, 2)) as num03 ) as poper,
key cast('00' as char2) as periv,
key cast('0000000' as numc7) as fiscyearper,
key a.matnr,
key a.werks,
key a.lgort,
d.maktx,
a.meins,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'RHCUR' 0 as hsl,
@Semantics.amount.currencyCode: 'RHCUR' 0 as cost2,
//@Semantics.amount.currencyCode: 'RHCUR' cast(c.hsl as abap.fltp) / cast(a.menge as abap.fltp ) as cost1,
cast('' as abap.cuky( 5 )) as rhcur,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'ROCUR' 0 as osl,
cast('' as abap.cuky( 5 )) as rocur,
@Semantics.quantity.unitOfMeasure: 'RUNIT'
case when a.shkzg = 'H' then
a.menge * -1 else a.menge end as menge1,
a.meins as runit,
'' as racct,
'' as gkont,
a.budat,
a.cpudt,
a.cputm,
'' as ktosl,
'' as awtyp,
'' as awsys,
'' as aworg,
'' as awref,
cast('000000' as num06) as awitem,
cast('000000' as num06) as awitgrp,
cast('' as char10) as grref
} where (a.bwart = '311' or a.bwart = '312')
union
select from acdoca as a
inner join bkpf as b on a.belnr = b.belnr and a.rbukrs = b.bukrs and a.gjahr = b.gjahr
inner join makt as c on a.matnr = c.matnr and c.spras = $session.system_language
//inner join mara as d on a.matnr = d.matnr
left outer join ekpo as d on a.ebeln = d.ebeln and a.ebelp = d.ebelp
{
key '' as mblnr,
key a.gjahr as mjahr,
key '' as xabln,
key a.belnr,
key a.gjahr,
key a.rbukrs as bukrs,
key '' as bwart,
key cast(concat('0',substring(a.budat, 4, 2)) as num03 ) as poper,
key cast( '00' as char2 ) as periv,
key cast( '0000000' as numc7 ) as fiscyearper,
key a.matnr,
key a.werks,
key d.lgort,
c.maktx,
d.meins,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'RHCUR' a.hsl,
@Semantics.amount.currencyCode: 'RHCUR' a.hsl as cost2,
//@Semantics.amount.currencyCode: 'RHCUR' cast(c.hsl as abap.fltp) / cast(a.menge as abap.fltp ) as cost1,
a.rhcur,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'ROCUR' a.osl,
a.rocur,
@Semantics.quantity.unitOfMeasure: 'RUNIT'
0 as menge1,
d.meins as runit,
a.racct,
a.gkont,
a.budat,
b.cpudt,
b.cputm,
'' as ktosl,
cast('' as char5 ) as awtyp,
a.awsys,
a.aworg,
a.awref,
cast('000000' as num06) as awitem,
cast('000000' as num06) as awitgrp,
cast('' as char10) as grref
} where a.rldnr = '0L' and a.koart = 'M' and ( a.awtyp = 'RMRP' or a.awtyp = 'PRCHG' )
@AbapCatalog.sqlViewName: 'ZVMM003_V2'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Inventory Audit Report'
define view ZCDS_INV_AUDIT_REPORT_V3 as select from ZCDS_INV_MATDOC as a
inner join acdoca as b on a.mblnr = b.awref and a.mjahr = b.gjahr and
a.zeile = right( b.awitem, 4 ) and b.rldnr = '0L' and b.koart = 'M' and
b.ktosl = 'BSX'
{
key a.bukrs,
key a.mblnr,
key a.mjahr,
key a.zeile,
key b.belnr,
key b.gjahr,
b.budat,
a.cpudt,
a.cputm,
b.werks,
a.lgort,
a.charg,
a.matnr,
a.menge,
a.meins,
@Semantics.quantity.unitOfMeasure: 'RUNIT'
b.msl as menge1,
b.runit,
@Semantics.amount.currencyCode: 'RHCUR'
b.hsl as cost2,
b.rhcur,
b.racct,
b.gkont,
a.xabln,
a.bwart,
cast(
case
when ( a.bwart = '101' or a.bwart = '102' ) and a.ebeln <> '' then
'GRPO'
when ( a.bwart = '101' or a.bwart = '102' ) and a.aufnr <> '' then
'GRPROD'
end as char10 ) as grref,
b.blart,
a.ebeln,
a.ebelp
}
@AbapCatalog.sqlViewName: 'ZVMM012'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS Matdoc'
define view ZCDS_INV_MATDOC as select from matdoc as a
{
key a.mblnr,
key a.mjahr,
key a.zeile,
key a.bukrs,
a.budat,
a.bldat,
a.cpudt,
a.cputm,
a.werks,
a.lgort,
a.charg,
a.matnr,
@Semantics.quantity.unitOfMeasure: 'MEINS'
case
when a.shkzg = 'H' then
a.menge * -1
else a.menge end as menge,
a.meins,
a.erfme,
@Semantics.quantity.unitOfMeasure: 'ERFME'
case
when a.shkzg = 'H' then
a.erfmg * -1
else a.erfmg end as erfmg,
a.bwart,
a.sgtxt,
a.ebeln,
a.ebelp,
a.shkzg,
@Semantics.amount.currencyCode: 'WAERS'
case
when a.shkzg = 'H' then
a.dmbtr * -1
else a.dmbtr end as dmbtr,
a.waers,
a.xauto,
a.umwrk,
a.umlgo,
a.xabln,
a.aufnr,
a.blart,
a.cancelled,
cast(lpad(substring( a.budat, 5, 2 ), 3, '0' ) as abap.numc( 3 ) ) as poper
}
@AbapCatalog.sqlViewName: 'ZVMM003_RE'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Inventory Audit Report RE'
define view ZCDS_INV_AUDIT_REPORT_RE as select from acdoca as a
inner join bkpf as b on a.rbukrs = b.bukrs and a.belnr = b.belnr and a.gjahr = b.gjahr
inner join ekpo as c on a.ebeln = c.ebeln and a.ebelp = c.ebelp
{
key b.bukrs,
key a.belnr,
key a.gjahr,
a.awref,
a.awitem,
a.werks,
c.lgort,
a.matnr,
a.msl,
a.runit,
@Semantics.amount.currencyCode: 'RHCUR'
a.hsl as cost2,
a.rhcur,
a.osl,
a.rocur,
a.koart,
a.ktosl,
a.racct,
a.gkont,
a.ebeln,
a.ebelp,
a.blart,
a.awtyp,
a.budat,
b.cpudt,
b.cputm
} where a.rldnr = '0L' and a.koart = 'M' and a.blart = 'RE' and a.ktosl = 'BSX'
union
select from acdoca as a
inner join bkpf as b on a.rbukrs = b.bukrs and a.belnr = b.belnr and a.gjahr = b.gjahr
{
key b.bukrs,
key a.belnr,
key a.gjahr,
a.awref,
a.awitem,
a.werks,
cast( '' as char4 ) as lgort,
a.matnr,
a.msl,
a.runit,
@Semantics.amount.currencyCode: 'RHCUR'
a.hsl as cost2,
a.rhcur,
a.osl,
a.rocur,
a.koart,
a.ktosl,
a.racct,
a.gkont,
a.ebeln,
a.ebelp,
a.blart,
a.awtyp,
a.budat,
b.cpudt,
b.cputm
} where a.rldnr = '0L' and a.koart = 'M' and a.blart = 'RE' and a.ktosl = 'BSX' and a.ebeln = ''
union
select from acdoca as a
inner join bkpf as b on a.rbukrs = b.bukrs and a.belnr = b.belnr and a.gjahr = b.gjahr
{
key b.bukrs,
key a.belnr,
key a.gjahr,
a.awref,
a.awitem,
a.werks,
cast( '' as char4 ) as lgort,
a.matnr,
a.msl,
a.runit,
@Semantics.amount.currencyCode: 'RHCUR'
a.hsl as cost2,
a.rhcur,
a.osl,
a.rocur,
a.koart,
a.ktosl,
a.racct,
a.gkont,
a.ebeln,
a.ebelp,
a.blart,
a.awtyp,
a.budat,
b.cpudt,
b.cputm
} where a.rldnr = '0L' and a.koart = 'M' and a.awtyp = 'PRCHG' and a.ktosl = 'BSX'
union
select from acdoca as a
inner join bkpf as b on a.rbukrs = b.bukrs and a.belnr = b.belnr and a.gjahr = b.gjahr
{
key b.bukrs,
key a.belnr,
key a.gjahr,
a.awref,
a.awitem,
a.werks,
cast( '' as char4 ) as lgort,
a.matnr,
a.msl,
a.runit,
@Semantics.amount.currencyCode: 'RHCUR'
a.hsl as cost2,
a.rhcur,
a.osl,
a.rocur,
a.koart,
a.ktosl,
a.racct,
a.gkont,
a.ebeln,
a.ebelp,
a.blart,
a.awtyp,
a.budat,
b.cpudt,
b.cputm
} where a.rldnr = '0L' and a.koart = 'M' and a.blart = 'ML' and a.ktosl = 'BSX'
@AbapCatalog.sqlViewName: 'ZVMM004'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS Inventory Audit Report Closing'
define view ZCDS_INV_AUDIT_REPORT_CLOSING as select from acdoca as a
inner join bkpf as b on a.belnr = b.belnr and a.rbukrs = b.bukrs and a.gjahr = b.gjahr
inner join makt as c on a.matnr = c.matnr and c.spras = $session.system_language{
key a.rldnr,
key a.belnr,
key a.gjahr,
key a.rbukrs as bukrs,
key a.poper,
key a.periv,
key a.fiscyearper,
key a.werks,
cast( '' as char4 ) as lgort,
a.budat,
a.bldat,
b.cpudt,
b.cputm,
a.matnr,
c.maktx,
@Semantics.amount.currencyCode: 'RHCUR' a.hsl,
@Semantics.amount.currencyCode: 'RHCUR' a.hsl as cost2,
a.rhcur,
@DefaultAggregation: #SUM
@Semantics.amount.currencyCode: 'ROCUR' a.osl,
a.rocur,
@Semantics.quantity.unitOfMeasure: 'RUNIT' 0 as menge1,
a.runit,
a.racct,
a.gkont,
a.ktosl,
a.koart,
a.drcrk
} where a.rldnr = '0L' and a.koart = 'M' and ( a.awtyp = 'MLHD' or a.awtyp = 'PRCHG' )
Comments
Post a Comment