*&---------------------------------------------------------------------*
*& Report ZVVF_MMRO_LAST_PO *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
*======================================================================*
* Purpose : Generate last PO(s) for combination of Plant, Material and
* Vendor.
*======================================================================*
REPORT ZVVF_MMRO_LAST_PO NO STANDARD PAGE HEADING LINE-SIZE 1023.
TABLES: ekko, ekpo, konv.
*========================= DATA DECLARATION ===========================*
* The final display table.
DATA: BEGIN OF pmvtab OCCURS 0,
werks LIKE ekpo-werks,
matnr LIKE ekpo-matnr,
lifnr LIKE ekko-lifnr,
bedat LIKE ekko-bedat,
ebeln LIKE ekpo-ebeln,
kposn LIKE konv-kposn,
kschl LIKE konv-kschl,
ebelp LIKE ekpo-ebelp,
name1 LIKE t001w-name1,
txz01 LIKE ekpo-txz01,
name2 LIKE lfa1-name1,
ernam LIKE ekko-ernam,
username LIKE cdhdr-username,
ekorg LIKE ekko-ekorg,
ekgrp LIKE ekko-ekgrp,
bsart LIKE ekko-bsart,
reswk LIKE ekko-reswk,
kwert LIKE konv-kwert,
kbetr LIKE konv-kbetr,
menge LIKE ekpo-menge,
netpr LIKE ekpo-netpr,
netpr2 TYPE ekpo-netpr,
knumv LIKE ekko-knumv,
meins LIKE ekpo-meins,
bprme LIKE ekpo-bprme,
peinh LIKE ekpo-peinh,
bpumz LIKE ekpo-bpumz,
bpumn LIKE ekpo-bpumn,
netwr LIKE ekpo-netwr,
infnr LIKE ekpo-infnr,
batxt LIKE t161t-batxt,
ekotx LIKE t024e-ekotx,
eknam LIKE t024-eknam,
matkl LIKE ekpo-matkl,
wgbez LIKE t023t-wgbez,
END OF pmvtab.
DATA final_pmv LIKE pmvtab OCCURS 0 WITH HEADER LINE.
DATA podet_pmv LIKE pmvtab OCCURS 0 WITH HEADER LINE.
DATA pmv1 LIKE LINE OF pmvtab.
DATA pmv2 LIKE LINE OF pmvtab.
*----------------------------------------------
* Gets condiions, etc from cluster table 'konv'
*----------------------------------------------
DATA: BEGIN OF temp_konv OCCURS 0,
kwert LIKE konv-kwert, knumv LIKE konv-knumv,
kbetr LIKE konv-kbetr, kschl LIKE konv-kschl,
kposn LIKE konv-kposn, lifnr LIKE konv-lifnr,
END OF temp_konv.
*----------------------------------------------
* Contains unique conditions (kschl) for matrix
*----------------------------------------------
DATA: BEGIN OF head_temp OCCURS 0, " Tables for list manipulation
kschl LIKE konv-kschl, vtext LIKE t685t-vtext,
END OF head_temp.
*----------------------
* Plant and their names
*----------------------
DATA: BEGIN OF werks1_tab OCCURS 0,
werks LIKE ekpo-werks, " 4 (5) Plant
END OF werks1_tab.
DATA: BEGIN OF werks_tab OCCURS 0,
werks LIKE ekpo-werks, " 4 (5) Plant
name1 LIKE t001w-name1, " 30 Plant Desc
END OF werks_tab.
*-----------------------
* Vendor and their names
*-----------------------
DATA: BEGIN OF lifnr1_tab OCCURS 0,
lifnr LIKE ekko-lifnr, " 10 (6) Vendor
END OF lifnr1_tab.
DATA: BEGIN OF lifnr_tab OCCURS 0,
lifnr LIKE ekko-lifnr, " 10 (6) Vendor
name1 LIKE lfa1-name1, " 35 Vendor Desc
END OF lifnr_tab.
*--------------------------
* PO Groups and their names
*--------------------------
DATA: BEGIN OF ekgrp1_tab OCCURS 0,
ekgrp LIKE ekko-ekgrp, " 4 (5) Group
END OF ekgrp1_tab.
DATA: BEGIN OF ekgrp_tab OCCURS 0,
ekgrp LIKE ekko-ekgrp, " 4 (5) Group
eknam LIKE t024-eknam, " 20 Group Desc
END OF ekgrp_tab.
*----------------
* PO Organisation
*----------------
DATA: BEGIN OF ekorg1_tab OCCURS 0,
ekorg LIKE ekko-ekorg, " 4 (5) Orgn.
END OF ekorg1_tab.
DATA: BEGIN OF ekorg_tab OCCURS 0,
ekorg LIKE ekko-ekorg, " 4 (5) Orgn.
ekotx LIKE t024e-ekotx, " 20 Orgn. Desc
END OF ekorg_tab.
*---------
* PO Types
*---------
DATA: BEGIN OF bsart1_tab OCCURS 0,
bsart LIKE ekko-bsart, " 4 (5) PO Type
END OF bsart1_tab.
DATA: BEGIN OF bsart_tab OCCURS 0,
bsart LIKE ekko-bsart, " 4 (5) PO Type
batxt LIKE t161t-batxt, " 20 Orgn. Desc
END OF bsart_tab.
*-----------------------
* Material Group details
*-----------------------
DATA mat_type LIKE t023t OCCURS 0 WITH HEADER LINE.
*-------------------------------------
* For the user who last changed the PO
*-------------------------------------
DATA: BEGIN OF cdhdr1_tab OCCURS 0,
objectid LIKE cdhdr-objectid,
END OF cdhdr1_tab.
DATA: BEGIN OF cdhdr_tab OCCURS 0,
objectid LIKE cdhdr-objectid,
udate LIKE cdhdr-udate,
utime LIKE cdhdr-utime,
username LIKE cdhdr-username,
END OF cdhdr_tab.
DATA cdhdr_line LIKE LINE OF cdhdr_tab.
*------------------
* Counter variables
*------------------
DATA: w_v TYPE c VALUE '|',
th(2) TYPE c VALUE 'th'.
*------------------
* List manipulation
*------------------
DATA:w_toggle TYPE i VALUE 0,
w_tempc TYPE i VALUE 0,
w_count TYPE i VALUE 0,
w_here TYPE i VALUE 0,
w_last TYPE i VALUE 0,
w_cols TYPE i VALUE 0,
w_spacing TYPE i VALUE 20,
w_sum_price TYPE i VALUE 20.
*----------
* New lines
*----------
DATA:matnr_newline TYPE i VALUE 0,
lifnr_newline TYPE i VALUE 0,
ebeln_newline TYPE i VALUE 0,
kposn_newline TYPE i VALUE 0,
lastpo_newline TYPE i VALUE 0.
*----------------------------
* Entries in different tables
*----------------------------
DATA:w_entries TYPE i VALUE 0,
w_entries_tk TYPE i VALUE 0,
w_entries_ht TYPE i VALUE 0,
w_entries_pmv TYPE i VALUE 0.
*--------------
* Table indices
*--------------
DATA:w_tabix TYPE i VALUE 0,
w_which TYPE i VALUE 0.
*------------------------------------
* Condition value calculation - kwert
*------------------------------------
DATA:w_netpr TYPE p DECIMALS 2 VALUE 0,
w_netpr1 TYPE p DECIMALS 2 VALUE 0,
w_menge TYPE p DECIMALS 2 VALUE 0,
grmenge TYPE p DECIMALS 2 VALUE 0.
*------------------------------------------------
* Variables for writing list in proper identation
*------------------------------------------------
DATA: BEGIN OF lr,
w_werks TYPE i VALUE 2, "5
w_name1 TYPE i VALUE 8, "30
w_matnr TYPE i VALUE 39, "8
w_txz01 TYPE i VALUE 48, "40
w_lifnr TYPE i VALUE 89, "6
w_name2 TYPE i VALUE 96, "35
w_lastpo TYPE i VALUE 132, "11
w_ebeln TYPE i VALUE 144, "10
w_bedat TYPE i VALUE 155, "10
w_knumv TYPE i VALUE 166, "10
w_ernam TYPE i VALUE 177, "12
w_username TYPE i VALUE 190, "12
w_netpr2 TYPE i VALUE 203, "12
w_meins TYPE i VALUE 216, "5
w_menge TYPE i VALUE 222, "13
grmenge TYPE i VALUE 235, "13
w_kposn TYPE i VALUE 249, "6
w_ekorg TYPE i VALUE 256, "5
w_ekotx TYPE i VALUE 262, "20
w_ekgrp TYPE i VALUE 283, "5
w_eknam TYPE i VALUE 289, "20
w_bsart TYPE i VALUE 310, "5
w_batxt TYPE i VALUE 316, "20
w_matkl TYPE i VALUE 337, "9
w_wgbez TYPE i VALUE 347, "20
w_start TYPE i VALUE 368,
* w_netpr TYPE i VALUE 1,
* w_ebelp TYPE i VALUE 1,
* w_reswk TYPE i VALUE 1,
* w_kschl TYPE i VALUE 1,
* w_kwert TYPE i VALUE 1,
* w_kbetr TYPE i VALUE 1,
* w_bprme TYPE i VALUE 1,
* w_peinh TYPE i VALUE 1,
* w_bpumz TYPE i VALUE 1,
* w_bpumn TYPE i VALUE 1,
END OF lr.
* For vertical lines.
DATA: BEGIN OF v_lines,
w_werks TYPE i VALUE 1, "5
w_name1 TYPE i VALUE 7, "30
w_matnr TYPE i VALUE 38, "8
w_txz01 TYPE i VALUE 47, "40
w_lifnr TYPE i VALUE 88, "6
w_name2 TYPE i VALUE 95, "35
w_lastpo TYPE i VALUE 131, "11
w_ebeln TYPE i VALUE 143, "10
w_bedat TYPE i VALUE 154, "10
w_knumv TYPE i VALUE 165, "10
w_ernam TYPE i VALUE 176, "12
w_username TYPE i VALUE 189, "12
w_netpr2 TYPE i VALUE 202, "12
w_meins TYPE i VALUE 215, "5
w_menge TYPE i VALUE 221, "13
grmenge TYPE i VALUE 234, "13
w_kposn TYPE i VALUE 248, "6
w_ekorg TYPE i VALUE 255, "5
w_ekotx TYPE i VALUE 261, "20
w_ekgrp TYPE i VALUE 282, "5
w_eknam TYPE i VALUE 288, "20
w_bsart TYPE i VALUE 309, "5
w_batxt TYPE i VALUE 315, "20
w_matkl TYPE i VALUE 336, "9
w_wgbez TYPE i VALUE 346, "20
w_start TYPE i VALUE 367,
* w_netpr2 TYPE i VALUE 1,
* w_ebelp TYPE i VALUE 1,
* w_reswk TYPE i VALUE 1,
* w_kschl TYPE i VALUE 1,
* w_kwert TYPE i VALUE 1,
* w_kbetr TYPE i VALUE 1,
* w_bprme TYPE i VALUE 1,
* w_peinh TYPE i VALUE 1,
* w_bpumz TYPE i VALUE 1,
* w_bpumn TYPE i VALUE 1,
END OF v_lines.
DATA counter TYPE i VALUE 0.
DATA which_last(2) TYPE c VALUE 'th'.
*========================= SELECTION SCREEN ===========================*
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_bedat FOR ekko-bedat OBLIGATORY,
s_werks FOR ekpo-werks,
s_matnr FOR ekpo-matnr,
s_lifnr FOR ekko-lifnr,
s_kschl FOR konv-kschl.
SELECTION-SCREEN SKIP 1.
SELECT-OPTIONS: s_matkl FOR ekpo-matkl.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
SELECT-OPTIONS: s_ekorg FOR ekko-ekorg,
s_ekgrp FOR ekko-ekgrp.
SELECTION-SCREEN END OF BLOCK b4.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: radio1 RADIOBUTTON GROUP rad DEFAULT 'X'.
PARAMETERS: radio2 RADIOBUTTON GROUP rad.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
PARAMETERS:s_which TYPE i DEFAULT 1.
SELECTION-SCREEN SKIP 1.
PARAMETERS:p_value AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b3.
SELECTION-SCREEN END OF BLOCK b1.
*================================ MAIN ================================*
TOP-OF-PAGE.
PERFORM header.
PERFORM po_header.
START-OF-SELECTION.
w_which = s_which.
IF radio2 = 'X'.
PERFORM init.
ENDIF.
PERFORM pop_pmv.
PERFORM pop_temp_konv.
PERFORM merge.
IF p_value = 'X'.
DELETE final_pmv WHERE kwert = 0.
ENDIF.
DESCRIBE TABLE final_pmv LINES w_entries.
PERFORM list.
PERFORM footer.
*=============================== FORMS ================================*
*============================ FORM pop_pmv ============================*
FORM pop_pmv.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE pmvtab
UP TO s_which ROWS
FROM ekpo AS a
INNER JOIN ekko AS b ON a~ebeln = b~ebeln
WHERE b~bedat IN s_bedat AND
a~werks IN s_werks AND
a~matnr IN s_matnr AND
a~bukrs EQ 'VVF' AND
b~ekorg IN s_ekorg AND
b~ekgrp IN s_ekgrp AND
a~matkl IN s_matkl AND
b~knumv <> 0 AND
( b~lifnr IN s_lifnr OR b~reswk IN s_lifnr ) and
B~LOEKZ <> 'L' AND " PO is not deleted.
( b~frgke = 'Z' OR b~frgrl <> 'X' ) " PO is released.
ORDER BY b~bedat DESCENDING.
DESCRIBE TABLE pmvtab LINES w_entries_pmv.
IF w_entries_pmv = 0.
PERFORM quit.
ENDIF.
LOOP AT pmvtab.
cdhdr1_tab-objectid = pmvtab-ebeln.
APPEND cdhdr1_tab TO cdhdr1_tab.
IF pmvtab-lifnr EQ space.
werks1_tab-werks = pmvtab-reswk.
APPEND werks1_tab TO werks1_tab.
ELSE.
lifnr1_tab-lifnr = pmvtab-lifnr.
APPEND lifnr1_tab TO lifnr1_tab.
ENDIF.
werks1_tab-werks = pmvtab-werks.
APPEND werks1_tab TO werks1_tab.
pmvtab-kposn = pmvtab-ebelp.
ekorg1_tab-ekorg = pmvtab-ekorg.
APPEND ekorg1_tab TO ekorg1_tab.
ekgrp1_tab-ekgrp = pmvtab-ekgrp.
APPEND ekgrp1_tab TO ekgrp1_tab.
bsart1_tab-bsart = pmvtab-bsart.
APPEND bsart1_tab TO bsart1_tab.
MODIFY pmvtab TRANSPORTING kposn.
CLEAR pmvtab.
ENDLOOP.
PERFORM pop_other_tabs.
IF radio1 = 'X'.
PERFORM pop_lifnr_tab.
ENDIF.
PERFORM pop_final_pmv_tab.
ENDFORM.
*=========================== FORM temp_konv ===========================*
FORM pop_temp_konv.
SELECT knumv kwert kbetr kschl kposn lifnr
INTO CORRESPONDING FIELDS OF TABLE temp_konv
FROM konv
FOR ALL ENTRIES IN pmvtab
WHERE knumv = pmvtab-knumv AND
kposn = pmvtab-kposn AND
kschl IN s_kschl.
DESCRIBE TABLE temp_konv LINES w_entries_tk.
ENDFORM.
*============================= FORM merge =============================*
FORM merge.
SORT pmvtab BY knumv kposn.
SORT temp_konv BY knumv kposn.
LOOP AT pmvtab.
LOOP AT temp_konv.
IF temp_konv-knumv = pmvtab-knumv AND
temp_konv-kposn = pmvtab-kposn.
pmvtab-kwert = temp_konv-kwert.
pmvtab-kbetr = temp_konv-kbetr.
pmvtab-kschl = temp_konv-kschl.
pmvtab-netpr2 = ( pmvtab-netpr / pmvtab-peinh ) *
( pmvtab-bpumz / pmvtab-bpumn ).
APPEND pmvtab TO final_pmv.
DELETE temp_konv.
ELSE.
IF pmvtab-knumv > temp_konv-knumv.
DELETE temp_konv.
ELSE.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM.
*============================= FORM list ==============================*
FORM list.
IF radio1 = 'X'.
SORT pmvtab BY werks matnr lifnr bedat DESCENDING
ebeln DESCENDING
kposn ASCENDING.
SORT final_pmv BY werks matnr lifnr bedat DESCENDING
ebeln DESCENDING
kposn ASCENDING
kschl ASCENDING.
ELSE.
SORT pmvtab BY werks matnr bedat DESCENDING
ebeln DESCENDING
kposn ASCENDING.
SORT final_pmv BY werks matnr bedat DESCENDING
ebeln DESCENDING
kposn ASCENDING
kschl ASCENDING.
ENDIF.
PERFORM generate_head_temp.
FORMAT COLOR COL_NORMAL.
LOOP AT final_pmv.
pmv1 = final_pmv.
AT NEW werks.
PERFORM set_format.
WRITE:/1 sy-vline,
AT lr-w_werks(5) pmv1-werks,
AT lr-w_name1(30) pmv1-name1.
matnr_newline = 1.
ENDAT.
AT NEW matnr.
IF matnr_newline = 0.
PERFORM set_format.
WRITE:/1 sy-vline.
ENDIF.
WRITE: AT lr-w_matnr(6) pmv1-matnr,
AT lr-w_txz01(40) pmv1-txz01,
AT lr-w_matkl(9) pmv1-matkl,
AT lr-w_wgbez(20) pmv1-wgbez.
lifnr_newline = 1.
IF radio2 = 'X'.
READ TABLE pmvtab WITH KEY werks = pmv1-werks
matnr = pmv1-matnr.
w_tabix = sy-tabix. " + w_which - 1.
DO w_which TIMES.
counter = counter + 1.
IF w_tabix <= w_entries_pmv.
READ TABLE pmvtab INDEX w_tabix.
READ TABLE final_pmv WITH KEY werks = pmvtab-werks
matnr = pmvtab-matnr
ebeln = pmvtab-ebeln.
IF final_pmv-werks = pmv1-werks AND
final_pmv-matnr = pmv1-matnr.
IF lastpo_newline = 1.
PERFORM set_format.
WRITE:/1 sy-vline.
ENDIF.
PERFORM write_which_lastpo.
PERFORM write_podet.
ENDIF.
ENDIF.
w_tabix = w_tabix + 1.
lastpo_newline = 1.
ENDDO.
CLEAR counter.
CLEAR lastpo_newline.
ENDIF.
ENDAT.
AT NEW lifnr.
IF radio2 <> 'X'.
IF lifnr_newline = 0.
PERFORM set_format.
WRITE:/1 sy-vline.
ENDIF.
WRITE: AT lr-w_lifnr(6) pmv1-lifnr,
AT lr-w_name2(35) pmv1-name2.
READ TABLE pmvtab WITH KEY werks = pmv1-werks
matnr = pmv1-matnr
lifnr = pmv1-lifnr.
w_tabix = sy-tabix. " + w_which - 1.
DO w_which TIMES.
counter = counter + 1.
IF w_tabix <= w_entries_pmv.
READ TABLE pmvtab INDEX w_tabix.
READ TABLE final_pmv WITH KEY werks = pmvtab-werks
matnr = pmvtab-matnr
lifnr = pmvtab-lifnr
ebeln = pmvtab-ebeln.
IF final_pmv-werks = pmv1-werks AND
final_pmv-matnr = pmv1-matnr AND
final_pmv-lifnr = pmv1-lifnr.
IF lastpo_newline = 1.
PERFORM set_format.
WRITE:/1 sy-vline.
ENDIF.
PERFORM write_which_lastpo.
PERFORM write_podet.
ENDIF.
ENDIF.
w_tabix = w_tabix + 1.
lastpo_newline = 1.
ENDDO.
CLEAR counter.
CLEAR lastpo_newline.
ENDIF.
ENDAT.
AT END OF lifnr.
w_count = v_lines-w_start.
DO w_entries_ht TIMES. "entries is number of unique kschl's
w_count = w_count + w_spacing.
WRITE AT w_count w_v.
ENDDO.
PERFORM vert_lines.
ENDAT.
matnr_newline = 0.
lifnr_newline = 0.
ENDLOOP.
w_tempc = w_last + 5.
****Begin of modification for Upgrade by Suresh(SC10082004)**********
* WRITE:/1(w_tempc) sy-uline.
uline at /(w_tempc).
******End of modification for Upgrade by Suresh(SC10082004)**********
ENDFORM. "list
*====================== FORM generate_head_temp =======================*
FORM generate_head_temp.
LOOP AT final_pmv.
head_temp-kschl = final_pmv-kschl.
APPEND head_temp.
ENDLOOP.
SORT head_temp BY kschl.
DELETE ADJACENT DUPLICATES FROM head_temp.
LOOP AT head_temp.
SELECT SINGLE vtext
INTO (head_temp-vtext)
FROM t685t
WHERE kschl = head_temp-kschl AND spras = 'E'.
MODIFY head_temp. CLEAR head_temp.
ENDLOOP.
DESCRIBE TABLE head_temp LINES w_entries_ht.
w_cols = w_entries_ht * w_spacing.
IF w_cols > 575.
w_cols = 575 / w_entries_ht.
w_spacing = floor( w_cols ).
ENDIF.
IF w_spacing < 15.
w_sum_price = 15.
ENDIF.
ENDFORM.
*====================== FORM write_which_lastpo =======================*
FORM write_which_lastpo.
IF counter = 1.
which_last = 'st'.
ELSEIF counter = 2.
which_last = 'nd'.
ELSEIF counter = 3.
which_last = 'rd'.
ELSE.
which_last = 'th'.
ENDIF.
* IF counter = 1.
* WRITE: AT lr-w_lastpo 'Last'. "no space.
* ELSE.
WRITE: AT lr-w_lastpo(2) counter, which_last, 'last'.
* ENDIF.
ENDFORM.
*========================== FORM write_podet ==========================*
FORM write_podet.
IF radio1 = 'X'.
LOOP AT final_pmv WHERE werks = pmvtab-werks AND
matnr = pmvtab-matnr AND
txz01 = pmvtab-txz01 AND
lifnr = pmvtab-lifnr AND
ebeln = pmvtab-ebeln.
podet_pmv = final_pmv.
APPEND final_pmv TO podet_pmv.
ENDLOOP.
ENDIF.
IF radio2 = 'X'.
LOOP AT final_pmv WHERE werks = pmvtab-werks AND
matnr = pmvtab-matnr AND
txz01 = pmvtab-txz01 AND
ebeln = pmvtab-ebeln.
podet_pmv = final_pmv.
APPEND final_pmv TO podet_pmv.
ENDLOOP.
ENDIF.
SORT podet_pmv BY werks matnr lifnr bedat DESCENDING
ebeln DESCENDING
kposn ASCENDING
kschl ASCENDING.
LOOP AT podet_pmv.
FORMAT COLOR COL_NORMAL.
pmv2 = podet_pmv.
AT NEW ebeln.
WRITE:
AT lr-w_batxt(20) pmv2-batxt,
AT lr-w_ekotx(20) pmv2-ekotx,
AT lr-w_eknam(20) pmv2-eknam,
AT lr-w_ebeln(10) pmv2-ebeln,
AT lr-w_ernam(12) pmv2-ernam,
AT lr-w_username(12) pmv2-username,
AT lr-w_ekorg(5) pmv2-ekorg,
AT lr-w_ekgrp(5) pmv2-ekgrp,
AT lr-w_bsart(4) pmv2-bsart,
AT lr-w_bedat(10) pmv2-bedat,
AT lr-w_knumv(10) pmv2-knumv.
kposn_newline = 1.
ENDAT.
AT NEW kposn.
SELECT SUM( menge )
FROM ekbe
INTO grmenge
WHERE ebeln = pmv2-ebeln AND ebelp = pmv2-kposn AND vgabe = 1
GROUP by ebeln ebelp.
ENDSELECT.
IF kposn_newline = 0.
PERFORM set_format.
WRITE:/1 w_v.
ENDIF.
WRITE:
AT lr-w_netpr2(12) pmv2-netpr2,
AT lr-w_meins(5) pmv2-meins,
AT lr-w_menge(13) pmv2-menge,
AT lr-grmenge(13) grmenge,
AT lr-w_kposn(6) pmv2-kposn.
CLEAR grmenge.
kposn_newline = 0.
ENDAT.
AT NEW kschl.
READ TABLE head_temp WITH KEY kschl = pmv2-kschl.
w_count = v_lines-w_start + 1 - w_spacing +
( sy-tabix * w_spacing ).
w_tempc = w_spacing - 1.
WRITE AT w_count(w_tempc) pmv2-kwert.
ENDAT.
AT END OF kposn.
kposn_newline = 1.
SUM.
w_count = v_lines-w_start.
DO w_entries_ht TIMES. "entries is number of unique kschl's
w_count = w_count + w_spacing.
WRITE AT w_count w_v.
ENDDO.
w_here = w_last - ( 2 * w_sum_price ).
FORMAT COLOR COL_TOTAL.
WRITE: AT w_here(w_sum_price) podet_pmv-kwert RIGHT-JUSTIFIED.
FORMAT COLOR COL_NORMAL.
IF podet_pmv-menge <> 0.
w_netpr = podet_pmv-kwert / pmv2-menge.
w_netpr1 = w_netpr * ( pmv2-bpumz / pmv2-bpumn ).
ENDIF.
w_here = w_last - w_sum_price.
WRITE: AT w_here(w_sum_price) w_netpr.
w_here = w_last + 1.
WRITE: AT w_here(4) pmv2-meins. "pmv2-netwr, pmv2-kbetr.
* w_here = w_last + 6.
* write: at w_here w_netpr1, 'per', pmv2-peinh, pmv2-bprme.
PERFORM vert_lines.
ENDAT.
* AT END OF ebeln.
* SUM.
* IF podet_pmv-menge <> 0.
* w_netpr = podet_pmv-kwert / podet_pmv-menge.
* ENDIF.
* w_here = w_last + w_spacing.
* WRITE: AT w_here(w_spacing) w_netpr.
* ENDAT.
kposn_newline = 0.
ENDLOOP.
CLEAR podet_pmv. REFRESH podet_pmv.
ENDFORM.
*=========================== FORM po_header ===========================*
FORM po_header.
IF w_entries = 0.
PERFORM quit.
ENDIF.
w_last = w_entries_ht * w_spacing + v_lines-w_start + 1 +
( 2 * w_sum_price ).
w_tempc = w_last + 5.
****Begin of modification for Upgrade by Suresh(SC10082004)**********
* WRITE:/1(w_tempc) sy-uline.
uline at /(w_tempc).
******End of modification for Upgrade by Suresh(SC10082004)**********
FORMAT COLOR COL_HEADING.
WRITE:/1 w_v,
AT lr-w_werks 'Plant', "werks
AT lr-w_name1 'Plant', "name1
AT lr-w_matnr 'Material', "matnr
AT lr-w_txz01 'Material', "txz01
AT lr-w_ernam 'User', "ernam
AT lr-w_username 'Changed', "username
AT lr-w_ekorg 'PO', "ekorg
AT lr-w_ekotx 'Purchasing', "ekotx
AT lr-w_ekgrp 'PO', "ekgrp
AT lr-w_eknam 'Purchasing', "eknam
AT lr-w_bsart 'PO', "bsart
AT lr-w_batxt 'Purchase', "batxt
AT lr-w_bedat 'PO', "bedat
AT lr-w_knumv 'Document', "knumv
AT lr-w_lastpo 'Which', "which last po
AT lr-w_ebeln 'PO', "ebeln
AT lr-w_kposn 'Line', "kposn
AT lr-w_netpr2 'Net', "netpr
AT lr-w_meins 'Unit', "meins
AT lr-w_menge 'PO', "menge
AT lr-grmenge 'GR', "menge (GR)
AT lr-w_matkl 'Material',
AT lr-w_wgbez 'Material Group'.
IF radio1 = 'X'.
WRITE: AT lr-w_lifnr 'Vendor', "lifnr
AT lr-w_name2 'Vendor'. "name2
ENDIF.
PERFORM vert_lines.
w_count = v_lines-w_start + 1.
LOOP AT head_temp.
w_tempc = w_spacing - 1. "In between two vertical lines.
WRITE: AT w_count(w_tempc) head_temp-kschl.
w_count = w_count + w_spacing.
w_tempc = w_count - 1.
WRITE AT w_tempc w_v.
ENDLOOP.
w_tempc = w_last - ( 2 * w_sum_price ).
WRITE: AT w_tempc 'SUM'.
w_tempc = w_tempc + w_sum_price + 1.
WRITE AT w_tempc 'LANDED COST'.
w_tempc = w_last + 1.
WRITE: AT w_tempc 'Unit'. ", 'netwr', w_v, 'kbetr'.
WRITE:/1 w_v,
AT lr-w_werks 'Code', "werks
AT lr-w_name1 'Name', "name1
AT lr-w_matnr 'Code', "matnr
AT lr-w_txz01 'Description', "txz01
AT lr-w_ernam 'Name', "ernam
AT lr-w_username 'Last By', "username
AT lr-w_ekorg 'Orgn.', "ekorg
AT lr-w_ekotx 'Organisation', "ekotx
AT lr-w_ekgrp 'Group', "ekgrp
AT lr-w_eknam 'Group', "eknam
AT lr-w_bsart 'Type', "bsart
AT lr-w_batxt 'Order Type', "batxt
AT lr-w_bedat 'Date', "bedat
AT lr-w_knumv 'Condition', "knumv
AT lr-w_lastpo 'Last PO', "which last po
AT lr-w_ebeln 'Number', "ebeln
AT lr-w_kposn 'Item', "kposn
AT lr-w_netpr2 'Price', "netpr
AT lr-w_meins 'per', "meins
AT lr-w_menge 'Quantity', "menge
AT lr-grmenge 'Quantity', "menge (GR)
AT lr-w_matkl 'Group',
AT lr-w_wgbez 'Description'.
IF radio1 = 'X'.
WRITE: AT lr-w_lifnr 'Code', "lifnr
AT lr-w_name2 'Name'. "name2
ENDIF.
w_tempc = w_last + 1.
WRITE AT w_tempc 'Per'.
PERFORM vert_lines.
w_count = v_lines-w_start + 1.
LOOP AT head_temp.
w_tempc = w_spacing - 1. "In between two vertical lines.
WRITE: AT w_count(w_tempc) head_temp-vtext.
w_count = w_count + w_spacing.
w_tempc = w_count - 1.
WRITE AT w_tempc sy-vline.
ENDLOOP.
w_tempc = w_last + 5.
****Begin of modification for Upgrade by Suresh(SC10082004)**********
* WRITE:/1(w_tempc) sy-uline.
uline at /(w_tempc).
******End of modification for Upgrade by Suresh(SC10082004)**********
FORMAT RESET.
ENDFORM.
*=========================== FORM vert_lines ==========================*
FORM vert_lines.
WRITE: AT v_lines-w_werks w_v,
AT v_lines-w_name1 w_v,
AT v_lines-w_matnr w_v,
AT v_lines-w_txz01 w_v,
AT v_lines-w_ernam w_v,
AT v_lines-w_username w_v,
AT v_lines-w_ekorg w_v,
AT v_lines-w_ekgrp w_v,
AT v_lines-w_bsart w_v,
AT v_lines-w_bedat w_v,
AT v_lines-w_knumv w_v,
AT v_lines-w_lastpo w_v,
AT v_lines-w_ebeln w_v,
AT v_lines-w_kposn w_v,
AT v_lines-w_netpr2 w_v,
AT v_lines-w_meins w_v,
AT v_lines-w_menge w_v,
AT v_lines-grmenge w_v,
AT v_lines-w_start w_v,
AT v_lines-w_batxt w_v,
AT v_lines-w_ekotx w_v,
AT v_lines-w_eknam w_v,
AT v_lines-w_matkl w_v,
AT v_lines-w_wgbez w_v.
IF radio1 = 'X'.
WRITE: AT v_lines-w_lifnr w_v,
AT v_lines-w_name2 w_v.
ENDIF.
w_tempc = w_last - w_sum_price - 1.
WRITE: AT w_tempc w_v.
WRITE: AT w_last w_v.
w_tempc = w_last + 5.
WRITE AT w_tempc w_v.
ENDFORM.
*========================= FORM pop_lifnr_tab =========================*
FORM pop_lifnr_tab.
SORT lifnr1_tab BY lifnr.
DELETE ADJACENT DUPLICATES FROM lifnr1_tab COMPARING lifnr.
SELECT lifnr name1
INTO CORRESPONDING FIELDS OF TABLE lifnr_tab
FROM lfa1
FOR ALL ENTRIES IN lifnr1_tab
WHERE lifnr = lifnr1_tab-lifnr.
ENDFORM.
*======================== FORM pop_other_tabs =========================*
FORM pop_other_tabs.
SORT werks1_tab BY werks.
DELETE ADJACENT DUPLICATES FROM werks1_tab COMPARING werks.
SELECT werks name1
INTO CORRESPONDING FIELDS OF TABLE werks_tab
FROM t001w
FOR ALL ENTRIES IN werks1_tab
WHERE werks = werks1_tab-werks.
SORT ekorg1_tab BY ekorg.
DELETE ADJACENT DUPLICATES FROM ekorg1_tab COMPARING ekorg.
SELECT ekorg ekotx
INTO CORRESPONDING FIELDS OF TABLE ekorg_tab
FROM t024e
FOR ALL ENTRIES IN ekorg1_tab
WHERE ekorg = ekorg1_tab-ekorg.
DELETE ADJACENT DUPLICATES FROM ekorg_tab COMPARING ekorg.
SORT ekgrp1_tab BY ekgrp.
DELETE ADJACENT DUPLICATES FROM ekgrp1_tab COMPARING ekgrp.
SELECT ekgrp eknam
INTO CORRESPONDING FIELDS OF TABLE ekgrp_tab
FROM t024
FOR ALL ENTRIES IN ekgrp1_tab
WHERE ekgrp = ekgrp1_tab-ekgrp.
DELETE ADJACENT DUPLICATES FROM ekgrp_tab COMPARING ekgrp.
SORT bsart1_tab BY bsart.
DELETE ADJACENT DUPLICATES FROM bsart1_tab COMPARING bsart.
SELECT bsart batxt
INTO CORRESPONDING FIELDS OF TABLE bsart_tab
FROM t161t
FOR ALL ENTRIES IN bsart1_tab
WHERE bsart = bsart1_tab-bsart AND spras = 'E'.
DELETE ADJACENT DUPLICATES FROM bsart_tab COMPARING bsart.
SORT cdhdr1_tab BY objectid.
DELETE ADJACENT DUPLICATES FROM cdhdr1_tab COMPARING objectid.
SELECT objectid udate utime username
INTO CORRESPONDING FIELDS OF TABLE cdhdr_tab
FROM cdhdr
FOR ALL ENTRIES IN cdhdr1_tab
WHERE objectid = cdhdr1_tab-objectid.
SORT cdhdr_tab BY objectid DESCENDING
udate DESCENDING
utime DESCENDING.
DELETE ADJACENT DUPLICATES FROM cdhdr_tab COMPARING objectid.
SELECT *
FROM t023t
INTO CORRESPONDING FIELDS OF TABLE mat_type.
ENDFORM.
*======================= FORM pop_final_pmv_tab =======================*
FORM pop_final_pmv_tab.
LOOP AT pmvtab.
READ TABLE werks_tab WITH KEY werks = pmvtab-werks.
IF sy-subrc = 0.
pmvtab-name1 = werks_tab-name1.
ENDIF.
IF pmvtab-lifnr EQ space.
READ TABLE werks_tab WITH KEY werks = pmvtab-reswk.
IF sy-subrc = 0.
pmvtab-lifnr = werks_tab-werks.
pmvtab-name2 = werks_tab-name1.
ENDIF.
ELSE.
READ TABLE lifnr_tab WITH KEY lifnr = pmvtab-lifnr.
IF sy-subrc = 0.
pmvtab-name2 = lifnr_tab-name1.
ENDIF.
ENDIF.
READ TABLE cdhdr_tab WITH KEY objectid = pmvtab-ebeln.
IF sy-subrc = 0.
pmvtab-username = cdhdr_tab-username.
ENDIF.
READ TABLE ekorg_tab WITH KEY ekorg = pmvtab-ekorg.
IF sy-subrc = 0.
pmvtab-ekotx = ekorg_tab-ekotx.
ENDIF.
READ TABLE ekgrp_tab WITH KEY ekgrp = pmvtab-ekgrp.
IF sy-subrc = 0.
pmvtab-eknam = ekgrp_tab-eknam.
ENDIF.
READ TABLE bsart_tab WITH KEY bsart = pmvtab-bsart.
IF sy-subrc = 0.
pmvtab-batxt = bsart_tab-batxt.
ENDIF.
READ TABLE mat_type WITH KEY matkl = pmvtab-matkl.
IF sy-subrc = 0.
pmvtab-wgbez = mat_type-wgbez.
ENDIF.
MODIFY pmvtab. CLEAR pmvtab.
ENDLOOP.
ENDFORM.
*============================= FORM init ==============================*
FORM init.
DATA offset TYPE i VALUE 43.
lr-w_ernam = lr-w_ernam - offset.
lr-w_username = lr-w_username - offset.
lr-w_ekorg = lr-w_ekorg - offset.
lr-w_ekgrp = lr-w_ekgrp - offset.
lr-w_bsart = lr-w_bsart - offset.
lr-w_bedat = lr-w_bedat - offset.
lr-w_knumv = lr-w_knumv - offset.
lr-w_ebeln = lr-w_ebeln - offset.
lr-w_kposn = lr-w_kposn - offset.
lr-w_netpr2 = lr-w_netpr2 - offset.
lr-w_meins = lr-w_meins - offset.
lr-w_menge = lr-w_menge - offset.
lr-w_start = lr-w_start - offset.
lr-w_ekotx = lr-w_ekotx - offset.
lr-w_eknam = lr-w_eknam - offset.
lr-w_batxt = lr-w_batxt - offset.
lr-grmenge = lr-grmenge - offset.
lr-w_lastpo = lr-w_lastpo - offset.
lr-w_matkl = lr-w_matkl - offset.
lr-w_wgbez = lr-w_wgbez - offset.
v_lines-w_ernam = v_lines-w_ernam - offset.
v_lines-w_username = v_lines-w_username - offset.
v_lines-w_ekorg = v_lines-w_ekorg - offset.
v_lines-w_ekgrp = v_lines-w_ekgrp - offset.
v_lines-w_bsart = v_lines-w_bsart - offset.
v_lines-w_bedat = v_lines-w_bedat - offset.
v_lines-w_knumv = v_lines-w_knumv - offset.
v_lines-w_ebeln = v_lines-w_ebeln - offset.
v_lines-w_kposn = v_lines-w_kposn - offset.
v_lines-w_netpr2 = v_lines-w_netpr2 - offset.
v_lines-w_meins = v_lines-w_meins - offset.
v_lines-w_menge = v_lines-w_menge - offset.
v_lines-w_start = v_lines-w_start - offset.
v_lines-w_ekotx = v_lines-w_ekotx - offset.
v_lines-w_eknam = v_lines-w_eknam - offset.
v_lines-w_batxt = v_lines-w_batxt - offset.
v_lines-grmenge = v_lines-grmenge - offset.
v_lines-w_lastpo = v_lines-w_lastpo - offset.
v_lines-w_matkl = v_lines-w_matkl - offset.
v_lines-w_wgbez = v_lines-w_wgbez - offset.
ENDFORM.
*============================= FORM header ============================*
FORM header.
FORMAT COLOR COL_BACKGROUND.
WRITE:/1(100) sy-uline.
WRITE:/1 sy-vline. WRITE:3 'User:'. WRITE: 10(10) sy-uname.
WRITE:21 sy-vline. WRITE:25 'Date:'. WRITE: 40(10) sy-datum.
WRITE:100 sy-vline.
WRITE:/1(100) sy-uline.
WRITE:/1 sy-vline. WRITE:21 sy-vline.
WRITE:25 'Dates :', 40 s_bedat-low, 55'TO ', 60 s_bedat-high.
WRITE:100 sy-vline, / sy-vline. WRITE:21 sy-vline.
WRITE:25 'Plants :', 40 s_werks-low, 55'TO ', 60 s_werks-high.
WRITE:100 sy-vline, / sy-vline. WRITE:21 sy-vline.
WRITE:25 'Material:', 40 s_matnr-low, 55'TO ', 60 s_matnr-high.
WRITE:100 sy-vline, / sy-vline. WRITE:21 sy-vline.
WRITE:25 'Vendors :', 40 s_lifnr-low, 55'TO ', 60 s_lifnr-high.
WRITE:100 sy-vline.
WRITE:/1(100) sy-uline.
WRITE:100 sy-vline, / sy-vline. WRITE:21 sy-vline.
IF radio1 = 'X'.
WRITE: 25 'The output is for Plant-Material-Vendor combination.'.
ELSE.
WRITE: 25 'The output is for Plant-Material combination.'.
ENDIF.
WRITE:100 sy-vline, / sy-vline. WRITE:21 sy-vline.
WRITE:25 'PO ', s_which, 'from last is shown for the combination.'.
WRITE:100 sy-vline.
WRITE:/1(100) sy-uline.
FORMAT RESET.
ENDFORM.
*============================= FORM footer ============================*
FORM footer.
WRITE:/1(21) sy-uline.
WRITE:/1 sy-vline. WRITE:5 'End of report'. WRITE:21 sy-vline.
WRITE:/1(21) sy-uline.
ENDFORM.
*============================= FORM quit ==============================*
FORM quit.
WRITE:/1(100) sy-uline.
WRITE:/1 sy-vline.
WRITE:22 'No matching records found. Please try a better criteria.'.
WRITE: AT 100 sy-vline.
WRITE:/1(100) sy-uline.
STOP.
ENDFORM.
*=========================== FORM set_format ==========================*
FORM set_format.
IF w_toggle = 0.
FORMAT INTENSIFIED ON. w_toggle = 1.
ELSE.
FORMAT INTENSIFIED OFF. w_toggle = 0.
ENDIF.
ENDFORM.
No comments:
Post a Comment