SAP ABAP - Custom Report Mutasi Finish Product
*&---------------------------------------------------------------------*
*& Report YRMUTASI_FG*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT yrmutasi_fg.
TYPE-POOLS: slis.
"===========================================================================
INCLUDE yrmutasi_fg_01. "Structure & Selection
INCLUDE yrmutasi_fg_02. "Get Data Laporan Mutasi
INCLUDE yrmutasi_fg_03. "Alv Grid
"===========================================================================
START-OF-SELECTION.
PERFORM getdata.
IF it_data_01[] IS INITIAL.
MESSAGE 'Data tidak ditemukan' TYPE 'I' DISPLAY LIKE 'W'.
ELSE.
PERFORM setfieldcat.
PERFORM build_alv_header.
PERFORM display_alv.
ENDIF.
INCLUDE YRMUTASI_FG_01.
*&---------------------------------------------------------------------*
*& Include YRMUTASI_FG_01
*&---------------------------------------------------------------------*
TABLES : mseg, mara.
TYPES:
BEGIN OF zprint,
icons LIKE icon-id,
colinfo TYPE lvc_t_scol,
ccell TYPE lvc_t_scol,
cstyl TYPE lvc_t_styl,
cline TYPE char4,
check TYPE flag,
box(1).
"MEREP_OUTTAB_EBAN
TYPES:
END OF zprint.
TYPES :
BEGIN OF t_mseg,
nurut TYPE i,
jndok TYPE char50,
jndok2 TYPE char50,
nopen TYPE char50,
tapen TYPE char50,
noaju TYPE char50,
tgaju TYPE char50,
mblnr TYPE mblnr,
zeile TYPE mblpo,
mjahr TYPE mjahr,
bwart TYPE bwart,
shkzg TYPE shkzg,
matnr TYPE matnr,
maktx TYPE maktx,
werks TYPE werks_d,
lgort TYPE lgort_d,
charg TYPE charg_d,
meins TYPE meins,
menge TYPE menge_d,
budat_mkpf TYPE budat,
lifnr TYPE lifnr,
kunnr TYPE kunnr,
name1 TYPE name1,
waers TYPE waers,
dmbtr TYPE dmbtr,
smbln TYPE mblnr,
smblp TYPE mblpo,
sjahr TYPE mjahr,
vbeln_im TYPE vbeln_vl,
vbelp_im TYPE posnr_vl,
menge_s TYPE menge_d,
menge_h TYPE menge_d,
END OF t_mseg,
BEGIN OF t_lips,
vbeln TYPE vbeln,
posnr TYPE posnr,
vgbel TYPE vgbel,
vgpos TYPE vgpos,
znopen TYPE char50,
ztybc TYPE char50,
zdatno TYPE char50,
znoaju TYPE char50,
zdtaju TYPE char50,
END OF t_lips ,
BEGIN OF t_data,
nurut TYPE i,
matnr TYPE matnr,
maktx TYPE maktx,
meins TYPE meins,
werks TYPE werks_d,
lgort TYPE lgort_d,
menge1 TYPE menge_d, "saldo awal
menge2 TYPE menge_d, "Pemasukan
menge3 TYPE menge_d, "Pengeluaran
menge4 TYPE menge_d, "Penyesuaian
menge5 TYPE menge_d, "Saldo Akhir
zopnm TYPE char20,
zslsh TYPE char20,
zket TYPE char20,
END OF t_data.
DATA : it_mseg TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_01 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_02 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_03 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_04 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_05 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_06 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_data_01 TYPE TABLE OF t_data WITH HEADER LINE,
it_data_02 TYPE TABLE OF t_data WITH HEADER LINE,
it_lips1 TYPE TABLE OF t_lips WITH HEADER LINE,
it_lips2 TYPE TABLE OF t_lips WITH HEADER LINE.
* it_ztsd007 TYPE TABLE OF ztsd007 WITH HEADER LINE.
DATA: ld_field TYPE vrm_id,
ld_field2 TYPE vrm_id,
it_listbox TYPE vrm_values,
wa_listbox LIKE LINE OF it_listbox,
it_listbox2 TYPE vrm_values,
wa_listbox2 LIKE LINE OF it_listbox.
DATA: alv_fldcat TYPE slis_t_fieldcat_alv,
it_fldcat TYPE lvc_t_fcat,
wa_layout TYPE lvc_s_layo,
wa_it_fldcat TYPE lvc_s_fcat,
wa_flname(20) TYPE c.
* it_list_commentary type slis_t_listheader,
* wa_list_commentary type slis_listheader,
* it_event_exit type slis_t_event_exit,
* wa_event_exit type slis_event_exit.
DATA : v_matnr TYPE matnr,
v_charg TYPE charg_d,
v_class TYPE klasse_d.
* it_charprint TYPE TABLE OF ztmme125b,
* wa_charprint TYPE ztmme125b.
DATA count TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
*SELECT-OPTIONS :
* p_budat for mseg-budat_mkpf.
PARAMETERS :
p_bukrs TYPE bukrs,
p_sdate TYPE budat DEFAULT sy-datum,
p_edate TYPE budat DEFAULT sy-datum.
SELECT-OPTIONS :
p_matnr FOR mara-matnr NO INTERVALS,
z_matnr FOR mara-matnr NO-DISPLAY.
* p_matnr type matnr.
SELECTION-SCREEN END OF BLOCK b1.
INCLUDE yx_abap_14.
AT SELECTION-SCREEN OUTPUT.
z_matnr-sign = 'I'.
z_matnr-option = 'CP'.
z_matnr-low = '01*'.
APPEND z_matnr TO z_matnr.
z_matnr-sign = 'I'.
z_matnr-option = 'CP'.
z_matnr-low = '02*'.
APPEND z_matnr TO z_matnr.
z_matnr-sign = 'I'.
z_matnr-option = 'CP'.
z_matnr-low = '03*'.
APPEND z_matnr TO z_matnr.
*& Include YRMUTASI_FG_01
*&---------------------------------------------------------------------*
TABLES : mseg, mara.
TYPES:
BEGIN OF zprint,
icons LIKE icon-id,
colinfo TYPE lvc_t_scol,
ccell TYPE lvc_t_scol,
cstyl TYPE lvc_t_styl,
cline TYPE char4,
check TYPE flag,
box(1).
"MEREP_OUTTAB_EBAN
TYPES:
END OF zprint.
TYPES :
BEGIN OF t_mseg,
nurut TYPE i,
jndok TYPE char50,
jndok2 TYPE char50,
nopen TYPE char50,
tapen TYPE char50,
noaju TYPE char50,
tgaju TYPE char50,
mblnr TYPE mblnr,
zeile TYPE mblpo,
mjahr TYPE mjahr,
bwart TYPE bwart,
shkzg TYPE shkzg,
matnr TYPE matnr,
maktx TYPE maktx,
werks TYPE werks_d,
lgort TYPE lgort_d,
charg TYPE charg_d,
meins TYPE meins,
menge TYPE menge_d,
budat_mkpf TYPE budat,
lifnr TYPE lifnr,
kunnr TYPE kunnr,
name1 TYPE name1,
waers TYPE waers,
dmbtr TYPE dmbtr,
smbln TYPE mblnr,
smblp TYPE mblpo,
sjahr TYPE mjahr,
vbeln_im TYPE vbeln_vl,
vbelp_im TYPE posnr_vl,
menge_s TYPE menge_d,
menge_h TYPE menge_d,
END OF t_mseg,
BEGIN OF t_lips,
vbeln TYPE vbeln,
posnr TYPE posnr,
vgbel TYPE vgbel,
vgpos TYPE vgpos,
znopen TYPE char50,
ztybc TYPE char50,
zdatno TYPE char50,
znoaju TYPE char50,
zdtaju TYPE char50,
END OF t_lips ,
BEGIN OF t_data,
nurut TYPE i,
matnr TYPE matnr,
maktx TYPE maktx,
meins TYPE meins,
werks TYPE werks_d,
lgort TYPE lgort_d,
menge1 TYPE menge_d, "saldo awal
menge2 TYPE menge_d, "Pemasukan
menge3 TYPE menge_d, "Pengeluaran
menge4 TYPE menge_d, "Penyesuaian
menge5 TYPE menge_d, "Saldo Akhir
zopnm TYPE char20,
zslsh TYPE char20,
zket TYPE char20,
END OF t_data.
DATA : it_mseg TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_01 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_02 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_03 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_04 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_05 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_mseg_06 TYPE TABLE OF t_mseg WITH HEADER LINE,
it_data_01 TYPE TABLE OF t_data WITH HEADER LINE,
it_data_02 TYPE TABLE OF t_data WITH HEADER LINE,
it_lips1 TYPE TABLE OF t_lips WITH HEADER LINE,
it_lips2 TYPE TABLE OF t_lips WITH HEADER LINE.
* it_ztsd007 TYPE TABLE OF ztsd007 WITH HEADER LINE.
DATA: ld_field TYPE vrm_id,
ld_field2 TYPE vrm_id,
it_listbox TYPE vrm_values,
wa_listbox LIKE LINE OF it_listbox,
it_listbox2 TYPE vrm_values,
wa_listbox2 LIKE LINE OF it_listbox.
DATA: alv_fldcat TYPE slis_t_fieldcat_alv,
it_fldcat TYPE lvc_t_fcat,
wa_layout TYPE lvc_s_layo,
wa_it_fldcat TYPE lvc_s_fcat,
wa_flname(20) TYPE c.
* it_list_commentary type slis_t_listheader,
* wa_list_commentary type slis_listheader,
* it_event_exit type slis_t_event_exit,
* wa_event_exit type slis_event_exit.
DATA : v_matnr TYPE matnr,
v_charg TYPE charg_d,
v_class TYPE klasse_d.
* it_charprint TYPE TABLE OF ztmme125b,
* wa_charprint TYPE ztmme125b.
DATA count TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
*SELECT-OPTIONS :
* p_budat for mseg-budat_mkpf.
PARAMETERS :
p_bukrs TYPE bukrs,
p_sdate TYPE budat DEFAULT sy-datum,
p_edate TYPE budat DEFAULT sy-datum.
SELECT-OPTIONS :
p_matnr FOR mara-matnr NO INTERVALS,
z_matnr FOR mara-matnr NO-DISPLAY.
* p_matnr type matnr.
SELECTION-SCREEN END OF BLOCK b1.
INCLUDE yx_abap_14.
AT SELECTION-SCREEN OUTPUT.
z_matnr-sign = 'I'.
z_matnr-option = 'CP'.
z_matnr-low = '01*'.
APPEND z_matnr TO z_matnr.
z_matnr-sign = 'I'.
z_matnr-option = 'CP'.
z_matnr-low = '02*'.
APPEND z_matnr TO z_matnr.
z_matnr-sign = 'I'.
z_matnr-option = 'CP'.
z_matnr-low = '03*'.
APPEND z_matnr TO z_matnr.
INCLUDE YRMUTASI_FG_02.
*&---------------------------------------------------------------------*
*& Include YRMUTASI_FG_02
*&---------------------------------------------------------------------*
FORM getdata.
REFRESH : it_mseg_01, it_mseg_02, it_mseg_03, it_mseg_04, it_mseg.
CLEAR : it_mseg_01, it_mseg_02, it_mseg_03, it_mseg_04, it_mseg.
DATA zmenge TYPE menge_d.
CLEAR count.
"Saldo Awal
"======================================SALDO AWAL================================================================
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_mseg_01[]
FROM matdoc INNER JOIN mara ON matdoc~matnr = mara~matnr
* WHERE matdoc~bwart <> '311'
WHERE matdoc~bwart IN ( SELECT bwart FROM ytmm120 )
AND matdoc~budat < p_sdate AND matdoc~charg <> '' AND matdoc~matnr IN p_matnr
AND mara~mtart = 'ZFGD' AND matdoc~bukrs = p_bukrs .
IF it_mseg_01[] IS INITIAL.
EXIT.
ENDIF.
SORT it_mseg_01[] BY mblnr mjahr zeile shkzg.
CLEAR : it_mseg, it_mseg_01, zmenge.
LOOP AT it_mseg_01.
IF it_mseg_01-shkzg = 'H'.
zmenge = it_mseg_01-menge * -1.
CLEAR it_mseg_01-menge.
it_mseg_01-menge = zmenge.
ELSEIF it_mseg_01-shkzg = 'S'.
ENDIF.
MODIFY it_mseg_01 FROM it_mseg_01 TRANSPORTING menge
WHERE mblnr = it_mseg_01-mblnr AND mjahr = it_mseg_01-mjahr AND zeile = it_mseg_01-zeile.
CLEAR : it_mseg, it_mseg_01, zmenge.
ENDLOOP.
SORT it_mseg_01[] BY matnr DESCENDING.
"Calculate saldo awal
CLEAR : it_mseg, it_mseg_01, it_data_01.
LOOP AT it_mseg_01.
READ TABLE it_data_01[] INTO it_data_01 WITH KEY
matnr = it_mseg_01-matnr werks = it_mseg_01-werks lgort = it_mseg_01-lgort.
IF it_data_01 IS INITIAL.
it_mseg-matnr = it_mseg_01-matnr.
it_mseg-meins = it_mseg_01-meins.
it_mseg-menge = it_mseg_01-menge.
APPEND it_mseg TO it_mseg[].
it_data_01-matnr = it_mseg_01-matnr.
it_data_01-meins = it_mseg_01-meins.
it_data_01-menge1 = it_mseg_01-menge.
it_data_01-werks = it_mseg_01-werks.
it_data_01-lgort = it_mseg_01-lgort.
* append it_mseg to it_mseg[].
APPEND it_data_01 TO it_data_01[].
ELSE.
it_data_01-menge1 = it_data_01-menge1 + it_mseg_01-menge.
MODIFY it_data_01[] FROM it_data_01 TRANSPORTING menge1
WHERE matnr = it_data_01-matnr AND werks = it_mseg_01-werks AND lgort = it_mseg_01-lgort.
it_mseg-menge = it_mseg-menge + it_mseg_01-menge.
MODIFY it_mseg[] FROM it_mseg TRANSPORTING menge
WHERE matnr = it_data_01-matnr AND werks = it_mseg_01-werks AND lgort = it_mseg_01-lgort.
ENDIF.
CLEAR : it_mseg, it_mseg_01, it_data_01.
ENDLOOP.
SORT it_mseg[] BY matnr werks lgort.
"========================================================================================================================
"======================================PEMASUKAN=========================================================================
IF p_matnr IS INITIAL.
REFRESH p_matnr.
CLEAR : it_mseg, p_matnr.
LOOP AT it_mseg.
p_matnr-sign = 'I'.
p_matnr-option = 'EQ'.
p_matnr-low = it_mseg-matnr.
APPEND p_matnr TO p_matnr.
CLEAR : it_mseg, p_matnr.
ENDLOOP.
ENDIF.
"Ambil data pemasukan
SELECT * FROM matdoc INTO CORRESPONDING FIELDS OF TABLE it_mseg_02[]
WHERE bwart IN ( SELECT bwart FROM ytmm120 WHERE descm = 'PEMASUKAN' ) AND budat BETWEEN p_sdate
AND p_edate AND charg <> '' AND matnr IN p_matnr AND matdoc~bukrs = p_bukrs .
"Ambil data pengeluaran
SELECT * FROM matdoc INTO CORRESPONDING FIELDS OF TABLE it_mseg_03[]
WHERE bwart IN ( SELECT bwart FROM ytmm120 WHERE descm = 'PENGELUARAN' ) AND budat BETWEEN p_sdate AND p_edate
AND charg <> '' AND matnr IN p_matnr AND matdoc~bukrs = p_bukrs .
"calculate total pemasukan
CLEAR : it_mseg_02, it_data_01.
LOOP AT it_mseg_02.
READ TABLE it_data_01[] INTO it_data_01 WITH KEY
matnr = it_mseg_02-matnr werks = it_mseg_02-werks lgort = it_mseg_02-lgort.
IF it_data_01 IS INITIAL.
ELSE.
it_data_01-menge2 = it_data_01-menge2 + it_mseg_02-menge.
MODIFY it_data_01[] FROM it_data_01 TRANSPORTING
menge2 WHERE matnr = it_data_01-matnr AND werks = it_data_01-werks AND lgort = it_data_01-lgort.
ENDIF.
CLEAR : it_mseg, it_mseg_01, it_data_01.
ENDLOOP.
"calculate total konsumsi
CLEAR : it_mseg_03, it_data_01.
LOOP AT it_mseg_03.
READ TABLE it_data_01[] INTO it_data_01 WITH KEY
matnr = it_mseg_03-matnr werks = it_mseg_03-werks lgort = it_mseg_03-lgort.
IF it_data_01 IS INITIAL.
ELSE.
it_data_01-menge3 = it_data_01-menge3 + it_mseg_03-menge.
MODIFY it_data_01[] FROM it_data_01 TRANSPORTING menge3
WHERE matnr = it_data_01-matnr AND werks = it_data_01-werks AND lgort = it_data_01-lgort.
ENDIF.
CLEAR : it_mseg, it_mseg_03, it_data_01.
ENDLOOP.
SORT it_data_01 BY matnr.
REFRESH : it_mseg_05, it_mseg_06.
SORT it_mseg BY matnr.
DATA zmenge4 TYPE menge_d.
CLEAR : zmenge4, it_mseg_05, it_data_01.
LOOP AT it_data_01.
count = count + 1.
it_data_01-nurut = count.
SELECT SINGLE maktx FROM makt INTO it_data_01-maktx WHERE matnr = it_data_01-matnr.
READ TABLE it_mseg_05[] INTO it_mseg_05 WITH KEY matnr = it_data_01-matnr.
it_data_01-menge4 = it_mseg_05-menge.
zmenge4 = it_data_01-menge1 + it_data_01-menge2 + it_data_01-menge4 - it_data_01-menge3.
it_data_01-menge5 = zmenge4.
MODIFY it_data_01[] FROM it_data_01 TRANSPORTING nurut maktx menge4 menge5
WHERE matnr = it_data_01-matnr AND werks = it_data_01-werks AND lgort = it_data_01-lgort.
CLEAR : it_mseg_05, it_data_01, zmenge4.
ENDLOOP.
SORT it_data_01[] BY matnr werks lgort.
ENDFORM.
*& Include YRMUTASI_FG_02
*&---------------------------------------------------------------------*
FORM getdata.
REFRESH : it_mseg_01, it_mseg_02, it_mseg_03, it_mseg_04, it_mseg.
CLEAR : it_mseg_01, it_mseg_02, it_mseg_03, it_mseg_04, it_mseg.
DATA zmenge TYPE menge_d.
CLEAR count.
"Saldo Awal
"======================================SALDO AWAL================================================================
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_mseg_01[]
FROM matdoc INNER JOIN mara ON matdoc~matnr = mara~matnr
* WHERE matdoc~bwart <> '311'
WHERE matdoc~bwart IN ( SELECT bwart FROM ytmm120 )
AND matdoc~budat < p_sdate AND matdoc~charg <> '' AND matdoc~matnr IN p_matnr
AND mara~mtart = 'ZFGD' AND matdoc~bukrs = p_bukrs .
IF it_mseg_01[] IS INITIAL.
EXIT.
ENDIF.
SORT it_mseg_01[] BY mblnr mjahr zeile shkzg.
CLEAR : it_mseg, it_mseg_01, zmenge.
LOOP AT it_mseg_01.
IF it_mseg_01-shkzg = 'H'.
zmenge = it_mseg_01-menge * -1.
CLEAR it_mseg_01-menge.
it_mseg_01-menge = zmenge.
ELSEIF it_mseg_01-shkzg = 'S'.
ENDIF.
MODIFY it_mseg_01 FROM it_mseg_01 TRANSPORTING menge
WHERE mblnr = it_mseg_01-mblnr AND mjahr = it_mseg_01-mjahr AND zeile = it_mseg_01-zeile.
CLEAR : it_mseg, it_mseg_01, zmenge.
ENDLOOP.
SORT it_mseg_01[] BY matnr DESCENDING.
"Calculate saldo awal
CLEAR : it_mseg, it_mseg_01, it_data_01.
LOOP AT it_mseg_01.
READ TABLE it_data_01[] INTO it_data_01 WITH KEY
matnr = it_mseg_01-matnr werks = it_mseg_01-werks lgort = it_mseg_01-lgort.
IF it_data_01 IS INITIAL.
it_mseg-matnr = it_mseg_01-matnr.
it_mseg-meins = it_mseg_01-meins.
it_mseg-menge = it_mseg_01-menge.
APPEND it_mseg TO it_mseg[].
it_data_01-matnr = it_mseg_01-matnr.
it_data_01-meins = it_mseg_01-meins.
it_data_01-menge1 = it_mseg_01-menge.
it_data_01-werks = it_mseg_01-werks.
it_data_01-lgort = it_mseg_01-lgort.
* append it_mseg to it_mseg[].
APPEND it_data_01 TO it_data_01[].
ELSE.
it_data_01-menge1 = it_data_01-menge1 + it_mseg_01-menge.
MODIFY it_data_01[] FROM it_data_01 TRANSPORTING menge1
WHERE matnr = it_data_01-matnr AND werks = it_mseg_01-werks AND lgort = it_mseg_01-lgort.
it_mseg-menge = it_mseg-menge + it_mseg_01-menge.
MODIFY it_mseg[] FROM it_mseg TRANSPORTING menge
WHERE matnr = it_data_01-matnr AND werks = it_mseg_01-werks AND lgort = it_mseg_01-lgort.
ENDIF.
CLEAR : it_mseg, it_mseg_01, it_data_01.
ENDLOOP.
SORT it_mseg[] BY matnr werks lgort.
"========================================================================================================================
"======================================PEMASUKAN=========================================================================
IF p_matnr IS INITIAL.
REFRESH p_matnr.
CLEAR : it_mseg, p_matnr.
LOOP AT it_mseg.
p_matnr-sign = 'I'.
p_matnr-option = 'EQ'.
p_matnr-low = it_mseg-matnr.
APPEND p_matnr TO p_matnr.
CLEAR : it_mseg, p_matnr.
ENDLOOP.
ENDIF.
"Ambil data pemasukan
SELECT * FROM matdoc INTO CORRESPONDING FIELDS OF TABLE it_mseg_02[]
WHERE bwart IN ( SELECT bwart FROM ytmm120 WHERE descm = 'PEMASUKAN' ) AND budat BETWEEN p_sdate
AND p_edate AND charg <> '' AND matnr IN p_matnr AND matdoc~bukrs = p_bukrs .
"Ambil data pengeluaran
SELECT * FROM matdoc INTO CORRESPONDING FIELDS OF TABLE it_mseg_03[]
WHERE bwart IN ( SELECT bwart FROM ytmm120 WHERE descm = 'PENGELUARAN' ) AND budat BETWEEN p_sdate AND p_edate
AND charg <> '' AND matnr IN p_matnr AND matdoc~bukrs = p_bukrs .
"calculate total pemasukan
CLEAR : it_mseg_02, it_data_01.
LOOP AT it_mseg_02.
READ TABLE it_data_01[] INTO it_data_01 WITH KEY
matnr = it_mseg_02-matnr werks = it_mseg_02-werks lgort = it_mseg_02-lgort.
IF it_data_01 IS INITIAL.
ELSE.
it_data_01-menge2 = it_data_01-menge2 + it_mseg_02-menge.
MODIFY it_data_01[] FROM it_data_01 TRANSPORTING
menge2 WHERE matnr = it_data_01-matnr AND werks = it_data_01-werks AND lgort = it_data_01-lgort.
ENDIF.
CLEAR : it_mseg, it_mseg_01, it_data_01.
ENDLOOP.
"calculate total konsumsi
CLEAR : it_mseg_03, it_data_01.
LOOP AT it_mseg_03.
READ TABLE it_data_01[] INTO it_data_01 WITH KEY
matnr = it_mseg_03-matnr werks = it_mseg_03-werks lgort = it_mseg_03-lgort.
IF it_data_01 IS INITIAL.
ELSE.
it_data_01-menge3 = it_data_01-menge3 + it_mseg_03-menge.
MODIFY it_data_01[] FROM it_data_01 TRANSPORTING menge3
WHERE matnr = it_data_01-matnr AND werks = it_data_01-werks AND lgort = it_data_01-lgort.
ENDIF.
CLEAR : it_mseg, it_mseg_03, it_data_01.
ENDLOOP.
SORT it_data_01 BY matnr.
REFRESH : it_mseg_05, it_mseg_06.
SORT it_mseg BY matnr.
DATA zmenge4 TYPE menge_d.
CLEAR : zmenge4, it_mseg_05, it_data_01.
LOOP AT it_data_01.
count = count + 1.
it_data_01-nurut = count.
SELECT SINGLE maktx FROM makt INTO it_data_01-maktx WHERE matnr = it_data_01-matnr.
READ TABLE it_mseg_05[] INTO it_mseg_05 WITH KEY matnr = it_data_01-matnr.
it_data_01-menge4 = it_mseg_05-menge.
zmenge4 = it_data_01-menge1 + it_data_01-menge2 + it_data_01-menge4 - it_data_01-menge3.
it_data_01-menge5 = zmenge4.
MODIFY it_data_01[] FROM it_data_01 TRANSPORTING nurut maktx menge4 menge5
WHERE matnr = it_data_01-matnr AND werks = it_data_01-werks AND lgort = it_data_01-lgort.
CLEAR : it_mseg_05, it_data_01, zmenge4.
ENDLOOP.
SORT it_data_01[] BY matnr werks lgort.
ENDFORM.
INCLUDE YRMUTASI_FG_03.
*&---------------------------------------------------------------------*
*& Include YRMUTASI_FG_03
*&---------------------------------------------------------------------*
FORM build_alv_header .
* Type H is used to display headers i.e. big font
CLEAR wa_list_commentary.
wa_list_commentary-typ = 'H'.
wa_list_commentary-info = 'Laporan Mutasi Barang Jadi'.
APPEND wa_list_commentary TO it_list_commentary.
CLEAR wa_list_commentary.
wa_list_commentary-typ = 'H'.
SELECT SINGLE adrc~name1 FROM adrc INNER JOIN t001 ON adrc~addrnumber = t001~adrnr
INTO wa_list_commentary-info
WHERE t001~bukrs = p_bukrs.
* wa_list_commentary-info = 'PT XBCD'.
APPEND wa_list_commentary TO it_list_commentary.
* Type S is used to display key and value pairs
CLEAR wa_list_commentary.
wa_list_commentary-typ = 'S'.
wa_list_commentary-key = 'Tanggal :' .
DATA strdate TYPE string.
CONCATENATE p_sdate+6(2) p_sdate+4(2) p_sdate(4) INTO wa_list_commentary-info SEPARATED BY '-'.
CONCATENATE p_edate+6(2) p_edate+4(2) p_edate(4) INTO strdate SEPARATED BY '-'.
CONCATENATE wa_list_commentary-info 's/d' strdate INTO wa_list_commentary-info SEPARATED BY space.
APPEND wa_list_commentary TO it_list_commentary.
* Type A is used to display italic font
CLEAR wa_list_commentary.
wa_list_commentary-typ = 'A'.
CONCATENATE 'Refresh on' sy-uzeit+0(2) INTO wa_list_commentary-info SEPARATED BY space.
CONCATENATE wa_list_commentary-info sy-uzeit+2(2) sy-uzeit+4(2) INTO wa_list_commentary-info SEPARATED BY ':'.
APPEND wa_list_commentary TO it_list_commentary.
* perform top_of_page.
ENDFORM.
FORM to_alv_slis_event_exit .
CLEAR wa_event_exit.
wa_event_exit-ucomm = '&IC1'.
wa_event_exit-after = 'X'.
APPEND wa_event_exit TO it_event_exit.
wa_event_exit-ucomm = '%_GC 121 2'.
wa_event_exit-after = 'X'.
APPEND wa_event_exit TO it_event_exit.
ENDFORM.
FORM setfieldcat.
* CLEAR wa_it_fldcat.
* wa_it_fldcat-col_pos = 1.
* wa_it_fldcat-fieldname = 'NURUT'.
* wa_it_fldcat-datatype = 'NUMC'.
* wa_it_fldcat-scrtext_l = 'No'.
* wa_it_fldcat-intlen = 4.
* wa_it_fldcat-outputlen = 4.
* APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 1.
wa_it_fldcat-fieldname = 'WERKS'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-scrtext_l = 'Plant'.
wa_it_fldcat-intlen = 6.
wa_it_fldcat-outputlen = 6.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 2.
wa_it_fldcat-fieldname = 'LGORT'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-scrtext_l = 'St. Location'.
wa_it_fldcat-intlen = 6.
wa_it_fldcat-outputlen = 6.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 3.
wa_it_fldcat-fieldname = 'MATNR'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-scrtext_l = 'Kode Barang'.
wa_it_fldcat-intlen = 40.
wa_it_fldcat-outputlen = 30.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 4.
wa_it_fldcat-fieldname = 'MAKTX'.
wa_it_fldcat-datatype = 'CHAR'. "it_ztmme125b-atfor.
wa_it_fldcat-scrtext_l = 'Nama Barang'.
wa_it_fldcat-intlen = 40.
wa_it_fldcat-outputlen = 40.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 5.
wa_it_fldcat-fieldname = 'MEINS'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-scrtext_l = 'Satuan'.
wa_it_fldcat-intlen = 6.
wa_it_fldcat-outputlen = 6.
APPEND wa_it_fldcat TO it_fldcat .
DATA vstr TYPE char100.
CLEAR vstr.
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 7.
wa_it_fldcat-fieldname = 'MENGE1'.
wa_it_fldcat-datatype = 'QUAN'.
wa_it_fldcat-qfieldname = 'MEINS'.
CONCATENATE p_sdate+6(2) p_sdate+4(2) p_sdate(4) INTO vstr SEPARATED BY '/'.
CONCATENATE 'Saldo Awal' vstr INTO wa_it_fldcat-scrtext_l SEPARATED BY space.
* wa_it_fldcat-scrtext_l = 'Saldo Awal'.
wa_it_fldcat-intlen = 20.
wa_it_fldcat-outputlen = 20.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 8.
wa_it_fldcat-fieldname = 'MENGE2'.
wa_it_fldcat-datatype = 'QUAN'.
wa_it_fldcat-qfieldname = 'MEINS'.
wa_it_fldcat-scrtext_l = 'Pemasukan'.
wa_it_fldcat-intlen = 20.
wa_it_fldcat-outputlen = 20.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 9.
wa_it_fldcat-fieldname = 'MENGE3'.
wa_it_fldcat-datatype = 'QUAN'.
wa_it_fldcat-qfieldname = 'MEINS'.
wa_it_fldcat-scrtext_l = 'Pengeluaran'.
wa_it_fldcat-intlen = 20.
wa_it_fldcat-outputlen = 20.
APPEND wa_it_fldcat TO it_fldcat .
* CLEAR wa_it_fldcat.
* wa_it_fldcat-col_pos = 10.
* wa_it_fldcat-fieldname = 'MENGE4'.
* wa_it_fldcat-datatype = 'QUAN'.
* wa_it_fldcat-qfieldname = 'MEINS'.
* wa_it_fldcat-scrtext_l = 'Penyesuaian'.
* wa_it_fldcat-intlen = 20.
* wa_it_fldcat-outputlen = 20.
* APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 11.
wa_it_fldcat-fieldname = 'MENGE5'.
wa_it_fldcat-datatype = 'QUAN'.
wa_it_fldcat-qfieldname = 'MEINS'.
CLEAR vstr.
CONCATENATE p_edate+6(2) p_edate+4(2) p_edate(4) INTO vstr SEPARATED BY '/'.
CONCATENATE 'Saldo Akhir' vstr INTO wa_it_fldcat-scrtext_l SEPARATED BY space.
* wa_it_fldcat-scrtext_l = 'Saldo Akhir'.
wa_it_fldcat-intlen = 20.
wa_it_fldcat-outputlen = 20.
wa_it_fldcat-do_sum = 'X'.
APPEND wa_it_fldcat TO it_fldcat .
ENDFORM.
FORM f_build_sort.
*&---------------------------------------------------------------------*
* ini untuk pengurutan record
*----------------------------------------------------------------------*
DATA: l_sort TYPE lvc_s_sort.
DEFINE def_sort.
CLEAR l_sort.
*Sort position
l_sort-spos = &1.
l_sort-fieldname = &2.
l_sort-subtot = &3.
* l_sort-up = &4.
*Sort by ascending
l_sort-up = yes. """"""""""""""""""""""" kalo mau merubah desc digan dengan no
*Separate Line between Group
l_sort-group = 'UL'.
APPEND l_sort TO it_sort_lvc.
END-OF-DEFINITION.
* def_sort '01' 'MATNR' yes.
def_sort '01' 'WERKS' yes.
* def_sort '03' 'LGORT' yes.
ENDFORM. "f_build_sort
FORM display_alv.
PERFORM f_build_sort.
wa_layout-stylefname = 'FIELD_STYLE'.
wa_layout-zebra = 'X'.
wa_layout-cwidth_opt = 'X'.
wa_layout-box_fname = 'WERKS'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
* i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout_lvc = wa_layout
* it_sort_lvc = it_sort_lvc
it_fieldcat_lvc = it_fldcat[]
i_save = 'X'
TABLES
t_outtab = it_data_01
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
*& Include YRMUTASI_FG_03
*&---------------------------------------------------------------------*
FORM build_alv_header .
* Type H is used to display headers i.e. big font
CLEAR wa_list_commentary.
wa_list_commentary-typ = 'H'.
wa_list_commentary-info = 'Laporan Mutasi Barang Jadi'.
APPEND wa_list_commentary TO it_list_commentary.
CLEAR wa_list_commentary.
wa_list_commentary-typ = 'H'.
SELECT SINGLE adrc~name1 FROM adrc INNER JOIN t001 ON adrc~addrnumber = t001~adrnr
INTO wa_list_commentary-info
WHERE t001~bukrs = p_bukrs.
* wa_list_commentary-info = 'PT XBCD'.
APPEND wa_list_commentary TO it_list_commentary.
* Type S is used to display key and value pairs
CLEAR wa_list_commentary.
wa_list_commentary-typ = 'S'.
wa_list_commentary-key = 'Tanggal :' .
DATA strdate TYPE string.
CONCATENATE p_sdate+6(2) p_sdate+4(2) p_sdate(4) INTO wa_list_commentary-info SEPARATED BY '-'.
CONCATENATE p_edate+6(2) p_edate+4(2) p_edate(4) INTO strdate SEPARATED BY '-'.
CONCATENATE wa_list_commentary-info 's/d' strdate INTO wa_list_commentary-info SEPARATED BY space.
APPEND wa_list_commentary TO it_list_commentary.
* Type A is used to display italic font
CLEAR wa_list_commentary.
wa_list_commentary-typ = 'A'.
CONCATENATE 'Refresh on' sy-uzeit+0(2) INTO wa_list_commentary-info SEPARATED BY space.
CONCATENATE wa_list_commentary-info sy-uzeit+2(2) sy-uzeit+4(2) INTO wa_list_commentary-info SEPARATED BY ':'.
APPEND wa_list_commentary TO it_list_commentary.
* perform top_of_page.
ENDFORM.
FORM to_alv_slis_event_exit .
CLEAR wa_event_exit.
wa_event_exit-ucomm = '&IC1'.
wa_event_exit-after = 'X'.
APPEND wa_event_exit TO it_event_exit.
wa_event_exit-ucomm = '%_GC 121 2'.
wa_event_exit-after = 'X'.
APPEND wa_event_exit TO it_event_exit.
ENDFORM.
FORM setfieldcat.
* CLEAR wa_it_fldcat.
* wa_it_fldcat-col_pos = 1.
* wa_it_fldcat-fieldname = 'NURUT'.
* wa_it_fldcat-datatype = 'NUMC'.
* wa_it_fldcat-scrtext_l = 'No'.
* wa_it_fldcat-intlen = 4.
* wa_it_fldcat-outputlen = 4.
* APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 1.
wa_it_fldcat-fieldname = 'WERKS'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-scrtext_l = 'Plant'.
wa_it_fldcat-intlen = 6.
wa_it_fldcat-outputlen = 6.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 2.
wa_it_fldcat-fieldname = 'LGORT'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-scrtext_l = 'St. Location'.
wa_it_fldcat-intlen = 6.
wa_it_fldcat-outputlen = 6.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 3.
wa_it_fldcat-fieldname = 'MATNR'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-scrtext_l = 'Kode Barang'.
wa_it_fldcat-intlen = 40.
wa_it_fldcat-outputlen = 30.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 4.
wa_it_fldcat-fieldname = 'MAKTX'.
wa_it_fldcat-datatype = 'CHAR'. "it_ztmme125b-atfor.
wa_it_fldcat-scrtext_l = 'Nama Barang'.
wa_it_fldcat-intlen = 40.
wa_it_fldcat-outputlen = 40.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 5.
wa_it_fldcat-fieldname = 'MEINS'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-scrtext_l = 'Satuan'.
wa_it_fldcat-intlen = 6.
wa_it_fldcat-outputlen = 6.
APPEND wa_it_fldcat TO it_fldcat .
DATA vstr TYPE char100.
CLEAR vstr.
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 7.
wa_it_fldcat-fieldname = 'MENGE1'.
wa_it_fldcat-datatype = 'QUAN'.
wa_it_fldcat-qfieldname = 'MEINS'.
CONCATENATE p_sdate+6(2) p_sdate+4(2) p_sdate(4) INTO vstr SEPARATED BY '/'.
CONCATENATE 'Saldo Awal' vstr INTO wa_it_fldcat-scrtext_l SEPARATED BY space.
* wa_it_fldcat-scrtext_l = 'Saldo Awal'.
wa_it_fldcat-intlen = 20.
wa_it_fldcat-outputlen = 20.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 8.
wa_it_fldcat-fieldname = 'MENGE2'.
wa_it_fldcat-datatype = 'QUAN'.
wa_it_fldcat-qfieldname = 'MEINS'.
wa_it_fldcat-scrtext_l = 'Pemasukan'.
wa_it_fldcat-intlen = 20.
wa_it_fldcat-outputlen = 20.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 9.
wa_it_fldcat-fieldname = 'MENGE3'.
wa_it_fldcat-datatype = 'QUAN'.
wa_it_fldcat-qfieldname = 'MEINS'.
wa_it_fldcat-scrtext_l = 'Pengeluaran'.
wa_it_fldcat-intlen = 20.
wa_it_fldcat-outputlen = 20.
APPEND wa_it_fldcat TO it_fldcat .
* CLEAR wa_it_fldcat.
* wa_it_fldcat-col_pos = 10.
* wa_it_fldcat-fieldname = 'MENGE4'.
* wa_it_fldcat-datatype = 'QUAN'.
* wa_it_fldcat-qfieldname = 'MEINS'.
* wa_it_fldcat-scrtext_l = 'Penyesuaian'.
* wa_it_fldcat-intlen = 20.
* wa_it_fldcat-outputlen = 20.
* APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-col_pos = 11.
wa_it_fldcat-fieldname = 'MENGE5'.
wa_it_fldcat-datatype = 'QUAN'.
wa_it_fldcat-qfieldname = 'MEINS'.
CLEAR vstr.
CONCATENATE p_edate+6(2) p_edate+4(2) p_edate(4) INTO vstr SEPARATED BY '/'.
CONCATENATE 'Saldo Akhir' vstr INTO wa_it_fldcat-scrtext_l SEPARATED BY space.
* wa_it_fldcat-scrtext_l = 'Saldo Akhir'.
wa_it_fldcat-intlen = 20.
wa_it_fldcat-outputlen = 20.
wa_it_fldcat-do_sum = 'X'.
APPEND wa_it_fldcat TO it_fldcat .
ENDFORM.
FORM f_build_sort.
*&---------------------------------------------------------------------*
* ini untuk pengurutan record
*----------------------------------------------------------------------*
DATA: l_sort TYPE lvc_s_sort.
DEFINE def_sort.
CLEAR l_sort.
*Sort position
l_sort-spos = &1.
l_sort-fieldname = &2.
l_sort-subtot = &3.
* l_sort-up = &4.
*Sort by ascending
l_sort-up = yes. """"""""""""""""""""""" kalo mau merubah desc digan dengan no
*Separate Line between Group
l_sort-group = 'UL'.
APPEND l_sort TO it_sort_lvc.
END-OF-DEFINITION.
* def_sort '01' 'MATNR' yes.
def_sort '01' 'WERKS' yes.
* def_sort '03' 'LGORT' yes.
ENDFORM. "f_build_sort
FORM display_alv.
PERFORM f_build_sort.
wa_layout-stylefname = 'FIELD_STYLE'.
wa_layout-zebra = 'X'.
wa_layout-cwidth_opt = 'X'.
wa_layout-box_fname = 'WERKS'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
* i_callback_pf_status_set = 'SET_PF_STATUS'
i_callback_top_of_page = 'TOP_OF_PAGE'
is_layout_lvc = wa_layout
* it_sort_lvc = it_sort_lvc
it_fieldcat_lvc = it_fldcat[]
i_save = 'X'
TABLES
t_outtab = it_data_01
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
Custom Table
Comments
Post a Comment