*&---------------------------------------------------------------------*
*& Report ZMM_OUTPAC
*&
*&---------------------------------------------------------------------*
*& This report is for view outstanding PO qty
*& with material PO type = ZPAC using a Very Simple ALV method
*& (MONITORING OUTSTANDING ORDER PACKAGING REPORT)
*& and a sample how to get converted MEINS (unit of measure) from a select statement
*&---------------------------------------------------------------------*
REPORT zmm_outpac LINE-SIZE 273 LINE-COUNT 35 NO STANDARD PAGE HEADING.
*&---------------------------------------------------------------------*
*& Table description
TABLES : ekko, ekpo, eket, eban, mara, makt, lfa1, mseg, t006a.
*&---------------------------------------------------------------------*
*& Data description
DATA : BEGIN OF itab OCCURS 0,
no(3),
matnr LIKE mara-matnr,
txz01 LIKE ekpo-txz01,
MSEH3 LIKE T006A-MSEH3,
badat LIKE eban-badat,
banfn LIKE ekpo-banfn,
bnfpo LIKE ekpo-bnfpo,
bedat LIKE ekko-bedat,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebeln,
menge LIKE ekpo-menge,
eindt LIKE eket-eindt,
lifnr LIKE ekko-lifnr,
name1 LIKE lfa1-NAME1,
ketpo LIKE tline-tdline,
leado(5),
leadr(5),
kethead LIKE tline-tdline,
END OF itab.
DATA : BEGIN OF vendor_data OCCURS 0,
lifnr LIKE lfa1-lifnr,
name1 LIKE lfa1-name1,
END OF vendor_data.
DATA : BEGIN OF history OCCURS 0,
ebeln LIKE mseg-ebeln,
ebelp LIKE mseg-ebelp,
bwart LIKE mseg-bwart,
menge LIKE mseg-menge,
END OF history.
DATA : v_index LIKE sy-tabix,
v_value1 LIKE mseg-menge,
v_nettof LIKE ekpo-menge.
DATA : BEGIN OF tbl_hdr OCCURS 0,
judul(80),
field(80),
panjang(3).
DATA END OF tbl_hdr.
* for ALV
TYPE-POOLS: slis.
CONSTANTS: c_formname_top_of_page TYPE slis_formname
VALUE 'TOP_OF_PAGE'.
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
t_layout TYPE slis_layout_alv,
t_print TYPE slis_print_alv,
t_sort TYPE slis_t_sortinfo_alv,
t_sp_group TYPE slis_t_sp_group_alv,
t_grid_title TYPE lvc_title,
t_events TYPE slis_t_event,
t_list_top_of_page TYPE slis_t_listheader,
v_progid LIKE sy-repid,
v_save VALUE 'A',
t_variant LIKE disvariant,
v_variant LIKE disvariant.
*&---------------------------------------------------------------------*
*& Selection Screen
PARAMETERS: p_mtart LIKE mara-mtart DEFAULT 'ZPAC' .
PARAMETERS: p_werks LIKE t001w-werks obligatory.
select-options : s_bedat for ekko-bedat.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'P_MTART'.
screen-input = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
INITIALIZATION.
s_bedat-low = sy-datlo - 30.
s_bedat-high = sy-datlo.
append s_bedat.
START-OF-SELECTION.
* PERFORM cek_otorisasi.
PERFORM getdata.
IF itab[] IS INITIAL.
MESSAGE i208(00) WITH 'Data not found'.
ELSE.
PERFORM display.
ENDIF.
*&---------------------------------------------------------------------*
*& Form GETDATA
*&---------------------------------------------------------------------*
FORM getdata .
DATA : v_name LIKE thead-tdname.
DATA: lt_tline LIKE tline OCCURS 0 WITH HEADER LINE.
SELECT
a~bedat a~lifnr
b~matnr C~MSEH3 b~menge b~banfn b~bnfpo b~ebeln b~ebelp b~txz01
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ekko AS a
INNER JOIN ekpo AS b ON b~mandt = a~mandt
AND a~ebeln = b~ebeln
INNER JOIN t006a AS C ON C~MSEHI = B~MEINS
and c~spras = sy-langu
WHERE b~mtart = p_mtart AND
b~werks = p_werks and
a~bedat in s_bedat.
CALL FUNCTION 'FI_PROGRESS_INDICATOR'
EXPORTING
percentage = 0
text = 'Collecting data... '.
* GET QTY
SELECT ebeln ebelp bwart menge
INTO CORRESPONDING FIELDS OF TABLE history
FROM mseg
FOR ALL ENTRIES IN itab
WHERE ebeln = itab-ebeln
AND bwart IN ('101', '102').
* vendor name
SELECT lifnr name1
FROM lfa1
INTO CORRESPONDING FIELDS OF TABLE vendor_data
FOR ALL ENTRIES IN itab
WHERE lifnr = itab-lifnr.
* NETTING OFF
LOOP AT itab.
v_index = sy-tabix.
CLEAR : v_value1, v_nettof.
LOOP AT history WHERE ebeln = itab-ebeln AND ebelp = itab-ebelp.
IF history-bwart = '101'.
v_value1 = v_value1 + history-menge.
ELSEIF history-bwart = '102'.
v_value1 = v_value1 - history-menge.
ENDIF.
ENDLOOP.
v_nettof = itab-menge - v_value1.
IF v_nettof <= 0.
DELETE itab.
ELSE.
itab-menge = v_nettof.
MODIFY itab INDEX v_index.
ENDIF.
ENDLOOP.
SORT itab BY ebeln ebelp.
LOOP AT itab.
v_index = sy-tabix.
itab-no = v_index.
SELECT SINGLE badat
FROM eban
INTO itab-badat
WHERE banfn = itab-banfn.
SELECT SINGLE eindt
FROM eket
INTO itab-eindt
WHERE ebeln = itab-ebeln
AND ebelp = itab-ebelp.
READ TABLE vendor_data WITH KEY lifnr = itab-lifnr.
itab-name1 = vendor_data-name1.
* get keterangan PO
"Item PO text
CONCATENATE itab-ebeln itab-ebelp INTO v_name.
PERFORM read_text TABLES lt_tline
USING sy-mandt 'F01' 'EKPO' v_name 132.
READ TABLE lt_tline INDEX 1.
IF sy-subrc = 0.
itab-ketpo = lt_tline-tdline.
ELSE.
itab-ketpo = ''.
ENDIF.
* LEAD PO
itab-leado = sy-datlo - itab-bedat.
* LEAD PR
if itab-badat = '00000000'.
itab-leadr = '-'.
else.
itab-leadr = sy-datlo - itab-badat.
endif.
CLEAR : lt_tline.
REFRESH : lt_tline.
* get keterangan PO HEADER
v_name = itab-ebeln.
PERFORM read_text TABLES lt_tline
USING sy-mandt 'F01' 'EKKO' v_name 132.
READ TABLE lt_tline INDEX 1.
IF sy-subrc = 0.
itab-kethead = lt_tline-tdline.
ELSE.
itab-kethead = ''.
ENDIF.
CLEAR : v_name, lt_tline.
REFRESH : lt_tline.
MODIFY itab INDEX v_index.
* add to ALV
ENDLOOP.
ENDFORM. " GETDATA
*&---------------------------------------------------------------------*
*& Form read_text
*&---------------------------------------------------------------------*
FORM read_text TABLES ft_lines STRUCTURE tline
USING fu_mandt
fu_tdid
fu_tdobject
fu_tdname
fu_length.
DATA: lv_mandt LIKE sy-mandt,
lv_tdid LIKE thead-tdid,
lv_tdobject LIKE thead-tdobject,
lv_tdname LIKE thead-tdname,
lv_length LIKE sy-index.
REFRESH ft_lines.
lv_mandt = fu_mandt.
lv_tdid = fu_tdid.
lv_tdobject = fu_tdobject.
lv_tdname = fu_tdname.
lv_length = fu_length.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = lv_mandt
id = lv_tdid
language = sy-langu
name = lv_tdname
object = lv_tdobject
TABLES
lines = ft_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc = 0.
CALL FUNCTION 'FORMAT_TEXTLINES'
EXPORTING
formatwidth = lv_length
TABLES
lines = ft_lines
EXCEPTIONS
bound_error = 1
OTHERS = 2.
ENDIF.
ENDFORM. " READ_TEXT
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
FORM display .
PERFORM header.
PERFORM createalv.
ENDFORM. " DISPLAY
*&---------------------------------------------------------------------*
*& Form HEADER
*&---------------------------------------------------------------------*
FORM header.
DATA : hdr(1000),
pjg TYPE i,
pstr TYPE i,
tp TYPE i,
k1(50),
k2(50),
k3(50),
k4(50).
PERFORM getjudul CHANGING hdr.
SPLIT hdr AT ',' INTO TABLE tbl_hdr.
LOOP AT tbl_hdr.
CONDENSE tbl_hdr-judul.
pstr = STRLEN( tbl_hdr-judul ).
SPLIT tbl_hdr-judul AT '(' INTO k1 k2.
SPLIT k2 AT ')' INTO k3 k4.
pstr = pstr - STRLEN( k4 ).
pjg = STRLEN( k1 ) + 1.
tp = pjg + 2.
IF tp < pstr.
tbl_hdr-panjang = tbl_hdr-judul+pjg(2).
ELSE.
tbl_hdr-panjang = tbl_hdr-judul+pjg(1).
ENDIF.
tbl_hdr-judul = k1.
tbl_hdr-field = k4.
MODIFY tbl_hdr INDEX sy-tabix.
ENDLOOP.
ENDFORM. " Header
*&---------------------------------------------------------------------*
*& Form CREATEALV
*&---------------------------------------------------------------------*
FORM createalv .
CLEAR v_variant.
v_save = 'A'.
v_variant-report = sy-repid.
t_variant = v_variant.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = v_save
CHANGING
cs_variant = t_variant
EXCEPTIONS
not_found = 2.
PERFORM f_create_field USING t_fieldcat[].
PERFORM setting_attr.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = t_layout
i_callback_top_of_page = 'TOP-OF-PAGE'
it_fieldcat = t_fieldcat[]
it_special_groups = t_sp_group[]
i_save = v_save
is_variant = v_variant
it_events = t_events[]
TABLES
t_outtab = itab.
ENDFORM. " CREATEALV
*&---------------------------------------------------------------------*
*& Form f_create_field
*&---------------------------------------------------------------------*
FORM f_create_field USING fu_t_fieldcat TYPE slis_t_fieldcat_alv.
DATA: lv_fieldcat TYPE slis_fieldcat_alv.
REFRESH fu_t_fieldcat.
LOOP AT tbl_hdr.
CLEAR lv_fieldcat.
lv_fieldcat-col_pos = sy-tabix.
lv_fieldcat-fieldname = tbl_hdr-field.
lv_fieldcat-outputlen = tbl_hdr-panjang.
lv_fieldcat-reptext_ddic = tbl_hdr-judul.
APPEND lv_fieldcat TO fu_t_fieldcat.
ENDLOOP.
ENDFORM. " f_create_field
*&----------------------------------------------------------
*& Form top-of-page
*&----------------------------------------------------------
FORM top-of-page.
*ALV Header declarations
DATA: t_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
tpmatnr LIKE marc-matnr,
temp(20).
* Title
wa_header-typ = 'H'.
wa_header-info = 'MONITORING OUTSTANDING ORDER PACKAGING REPORT'.
APPEND wa_header TO t_header.
wa_header-typ = 'A'.
IF tpmatnr IS INITIAL.
tpmatnr = 'ALL'.
ENDIF.
CONCATENATE 'Plant : ' p_werks INTO wa_header-info SEPARATED BY space.
append wa_header to t_header.
wa_header-typ = 'A'.
CONCATENATE 'Printed By : ' sy-uname INTO wa_header-info SEPARATED BY space.
APPEND wa_header TO t_header.
wa_header-typ = 'A'.
CONCATENATE sy-datlo+6(2) '.' sy-datlo+4(2) '.' sy-datlo(4) INTO temp.
CONCATENATE 'Printed Date : ' temp INTO wa_header-info SEPARATED BY space.
APPEND wa_header TO t_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = t_header.
* i_logo = ''.
ENDFORM. " top-of-page
*&---------------------------------------------------------------------*
*& Form SETTING_ATTR
*&---------------------------------------------------------------------*
FORM setting_attr.
* setting variant
* V_VARIANT-VARIANT = P_VAR.
* V_VARIANT-REPORT = SY-REPID.
* V_VARIANT-USERNAME = SY-UNAME.
ENDFORM. "SETTING_ATTR
*&---------------------------------------------------------------------*
*& Form GETJUDUL
*&---------------------------------------------------------------------*
FORM getjudul CHANGING p_hdr.
CONCATENATE 'NO(3)NO,'
'MATERIAL(11)MATNR,'
'MATERIAL DESCRIPTION(40)TXZ01,'
'SATUAN(6)MSEH3,'
'TGL PR(10)BADAT,'
'NO PR(10)BANFN,'
'ITEM PR(8)BNFPO,'
'TGL PO(10)BEDAT,'
'NO PO(10)EBELN,'
'ITEM PO(8)EBELP,'
'SISA(7)MENGE,'
'TGL PERMINTAAN(14)EINDT,'
'SUPPLIER(40)NAME1,'
'KETERANGAN PO(132)KETPO,'
'LEAD PO(7)LEADO,'
'LEAD PR(7)LEADR,'
'KETERANGAN(132)KETHEAD'
INTO p_hdr.
ENDFORM. " GETJUDUL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment