Você está na página 1de 11

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

* PROGRAM NAME
: Authorized Contracts
*
* APPLICATION NAME : SD
*
* SUBSYSTEM
:
*
* AUTHOR
: Ashwini Nerurkar
*
* TRANSACTION
:
*
* TABLES UPDATED
: None
*
* REPORTS
: Authorized Contracts
*
* INPUT FILES
: None
*
* OUTPUT FILES
: None
*
* SAP RELEASE
: 4.0B
*
* PROGRAM ID
:
*
* PROGRAM DESCRIPTION : This program determines the contracts that
*
*
have been Authorized
*
*----------------------------------------------------------------------*
* LOG #
| DATE | AUTHOR
| DESCRIPTION
*
*----------------------------------------------------------------------*
*DEVK916359 |07/16/99 | anerurka | Started coding
*
*DEVK916740 |08/09/99 | anerurka | Changes made to selection criteria
*
| selection screen
*
*{ INSERT
NDVK903723
1
* AMOK 05/29/2001 - PE to ZE Conversion
*} INSERT
*{ INSERT
NDVK904324
2
* AMOK 06/18/2001 - Delete blank distributor
*} INSERT
*
* 10/23/2001 - DROSEN - added call Z_CHECK_REP_AUTH - very rep
* authorization - dtr10232001
*
* AMOK 03/26/2002 - Added resale price
* CLAY 07/03/02 - erdat (Creation Date) added back; Req: K.Vosburg
* CLAY 07/29/02 - valid fr/to date added to report output: J.Davenpo
* CLAY 07/29/02 - sales territory - required removed: J.Davenpo
* CLAY 07/29/02 - add "open-quantity" to the report output: J.Davenpo
* ClAY 10/30/03 - add "description" to the report output: K.Vosburg
* 05/22/2006 - KC Ong - Display 3 decimals for book cost,AMM,unit price
*
resale price
KC060522
* 10/08/07 - DROSEN - add to selection criteria and output AZ contract
* and item number.
*
*----------------------------------------------------------------------*
REPORT zv_authorized_contracts LINE-SIZE 275
LINE-COUNT 65.
TABLES : vbak,
" Sales Document: Header Data
vbap,
" Sales Document: Item Data
knvv,
" Customer Master Sales Data
jest,
" Object status
kna1,
" General Data in Customer Master
vbpa,
" Sales Document: Partner
jcds, " Change Documents for System/User Statuses (Table JEST)
vbkd,
" Sales Document: Business Data
konv,
konp.
SELECT-OPTIONS : s_guebg FOR vbak-guebg NO-EXTENSION NO INTERVALS,
s_gueen FOR vbak-gueen NO-EXTENSION NO INTERVALS,
*
s_erdat for vbak-erdat obligatory,"contract creation dt
*
s_erdat for vbak-erdat, "contract creation dt
*erdat added back 7/3/02, Requestor: K.Vosburg
s_matkl FOR vbap-matkl, " material group
*matnr added 5/27 for idt material, requestor: K.Vosburg
s_matnr FOR vbap-matnr, "IDT material number
s_ernam FOR vbak-ernam, " contract created by

s_kunnr FOR vbak-kunnr,


" customer
s_pernr FOR vbpa-pernr obligatory, " territory code
s_pernr FOR vbpa-pernr, " non-oblig. terr. code.
*vbak-ktext added 10/30/03 for description, requestor: K.Vosburg
s_ktext FOR vbak-ktext, "description
s_vkbur FOR vbak-vkbur, " sales office
s_bzirk FOR knvv-bzirk, " sales district "DEVK920169 in
s_erdat FOR vbak-erdat, "contract creation dt
s_vkorg FOR vbak-vkorg,
" sales org
s_azrcon FOR vbak-zazr_contract.
*

PARAMETER : chk_auth AS CHECKBOX. " to display only authorized conts.


*--int. table to store SO # that have changed in the specified dt. range
DATA : BEGIN OF tab0 OCCURS 10,
vbeln LIKE vbak-vbeln,
" contracts
posnr LIKE vbap-posnr.
" item
DATA : END OF tab0.
*--int. table to store the final data that has to be displayed
DATA : BEGIN OF itab OCCURS 10,
kunnr LIKE vbak-kunnr,
" customer
pernr LIKE vbpa-pernr,
" Sales terrotory
vbeln LIKE vbak-vbeln,
" contract
posnr LIKE vbap-posnr,
" contract item
vkorg LIKE vbak-vkorg,
" sales org
vtweg LIKE vbak-vtweg,
" Distribution channel
spart LIKE vbak-spart,
" Division
bzirk LIKE knvv-bzirk,
" sales district "DEVK920169 in
matnr LIKE vbap-matnr,
" material #
knumv LIKE vbak-knumv,
bstkd LIKE vbkd-bstkd,
" Customer purchase order number
ktext LIKE vbak-ktext,
" Description
guebg LIKE vbak-guebg,
" valid from
gueen LIKE vbak-gueen,
" valid to
zmeng TYPE p DECIMALS 0,
" target qty
netpr LIKE vbap-netpr,
" net price
zz_unit_price LIKE vbap-zz_unit_price,
"KC060522
kzwi5 LIKE vbap-kzwi5,
" Resale total Price
udate LIKE jcds-udate,
" change dt
*
book_price LIKE konv-kbetr, "Book price
"KC060522
book_price LIKE vbap-zz_unit_price,
"KC060522
*
amm_price LIKE konv-kbetr, "Approved Price
"KC060522
amm_price LIKE vbap-zz_unit_price,
"KC060522
open_qty TYPE p DECIMALS 0, "PGIed Qty
zrsl_price LIKE vbap-zz_unit_price,
"KC060522
zazr_contract LIKE vbap-zazr_contract,
zazr_item LIKE vbap-zazr_item,
text(14).
DATA : END OF itab.
DATA: BEGIN OF terr_c10 OCCURS 0,
sign(1),
options(2),
low(10),
high(10).
DATA: END OF terr_c10.
DATA : fname(20),
fvalue LIKE vbak-vbeln,
true TYPE i VALUE 1,
false TYPE i VALUE 0,
err_rc TYPE i,

terr_i TYPE i VALUE 0,


terr_char(10),
initialization.
START-OF-SELECTION.
PERFORM initialize.

""DEVK920169 in

* insert - dtr10232001
* check rep authorization to perform query/report
err_rc = false.
* convert field types (I know - its odd...)
* strip the 0's off the territory number ...
LOOP AT s_pernr.
terr_c10 = s_pernr.
terr_i = s_pernr-low.
terr_char = terr_i.
CONDENSE terr_char NO-GAPS.
terr_c10-low = terr_char.
terr_i = s_pernr-low.
terr_char = terr_i.
CONDENSE terr_char NO-GAPS.
terr_c10-high = terr_char.
APPEND terr_c10.
ENDLOOP.
CALL FUNCTION 'Z_CHECK_REP_AUTH'
TABLES
s_pernr = terr_c10
CHANGING
err_rc = err_rc.
IF err_rc = true.
EXIT.
ENDIF.
* end isnert - dtr10232001

PERFORM data_select.

" data selection from tables

END-OF-SELECTION.
PERFORM write_output.

" write the o/p

*top-of-page.
* perform write_header. " header that repeats for every page
AT LINE-SELECTION.
GET CURSOR FIELD fname VALUE fvalue.
PERFORM call_va43.

*&---------------------------------------------------------------------*
*&
Form DATA_SELECT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM data_select.
DATA : lines(3),
" used for DESCRIBE TABLE LINES
p_objnr LIKE jest-objnr, " temp storage of data to select from
" JEST
x_objnr LIKE p_objnr. " temp storage for the obj. # from JCDS
*--get the contracts that have been changed in the specified dt range -*
*Above erdat selection added back in 7/3/02: Requestor:K.Vosburg
*--the OBJNR field in JCDS stores the Contract Info in the form of ----*
*--VB(Contract#)(Item #) ----------------------------------------------*
* select objnr into x_objnr
"DEVK920169 out
*
from jcds
"DEVK920169 out
*
where
"DEVK920169 out
*
udate in s_erdat and
"DEVK920169 out
*
objnr like 'VB%'.
*--first 2 chars of JCDS-OBJNR = 'VB'
*--next 10 chars
= Sales order #
*--next 6 chars
= Item #
* tab0-vbeln = x_objnr+2(10).
"DEVK920169 out
* tab0-posnr = x_objnr+13(6).
"DEVK920169 out
* append tab0. clear tab0.
"DEVK920169 out
* endselect.
"DEVK920169 out
* sort tab0 by vbeln posnr.
"DEVK920169 out
* delete adjacent duplicates from tab0 comparing all fields."DEVK920169
*---get the contracts details for the contracts selected above --------*
*---depending on the selection criteria entered on the screen ---------*
* loop at tab0.
"DEVK920169 out
SELECT f~vbeln f~vtweg f~spart f~kunnr f~guebg f~gueen f~erdat f~vkorg
f~knumv f~ktext p~posnr p~matnr p~zmeng p~netpr p~zz_unit_price
p~kzwi5 p~zazr_contract p~zazr_item
INTO CORRESPONDING FIELDS OF itab
FROM vbak AS f INNER JOIN vbap AS p
ON f~vbeln = p~vbeln
WHERE f~auart = 'ZDQT'
AND f~zazr_contract IN s_azrcon
AND f~ernam IN s_ernam
AND f~erdat IN s_erdat
AND f~vkbur IN s_vkbur
AND f~vkorg IN s_vkorg
AND f~kunnr IN s_kunnr
AND f~guebg IN s_guebg
AND f~gueen IN s_gueen
AND f~ktext IN s_ktext
AND p~matnr IN s_matnr
*NDVK912210
*--Requestor: K.Vosburg, add matnr as selection criteria.
AND p~matkl IN s_matkl.
*
and f~vbeln = tab0-vbeln
"DEVK920169 out
*
and p~posnr = tab0-posnr.
"DEVK920169 out
*--to get the data entered on the Contracts creation screen for
*--'Customer purchase order number'
SELECT SINGLE bstkd bzirk INTO (itab-bstkd,itab-bzirk) FROM vbkd
WHERE vbeln = itab-vbeln
AND posnr = itab-posnr.

IF sy-subrc <> 0.
SELECT SINGLE bstkd bzirk INTO (itab-bstkd,itab-bzirk) FROM vbkd
WHERE vbeln = itab-vbeln
AND posnr = '000000'.
ENDIF.
IF NOT s_bzirk IS INITIAL.
CHECK itab-bzirk IN s_bzirk..
ENDIF.
PERFORM get_pernr.
* Below line routine added to supply open-qty to the report.
PERFORM get_open_qty.
APPEND itab. CLEAR itab.
endif.
ENDSELECT.
* endloop.
*

"DEVK920169 out

*---check if the contracts selected are in the territory code range, if*
*---entered on the selection screen -----------------------------------*
CLEAR lines.
* describe table s_pernr lines lines.
* if lines <> 0.
* loop at itab.
*
select single * from vbpa where vbeln = itab-vbeln
*
and posnr = itab-posnr
*
and parvw = 'VE'.
*
if sy-subrc <> 0.
*
select single * from vbpa where vbeln = itab-vbeln
*
and posnr = '000000'
*
and parvw = 'VE'.
*
endif.
*
if vbpa-pernr in s_pernr.
*
else.
*
delete itab.
* endif.
* endloop.
** endif.
LOOP AT itab.
CLEAR p_objnr.
CONCATENATE 'VB' itab-vbeln itab-posnr INTO p_objnr.
*---Check the status of the Contract----------------------------------*
*---E0001 - Authorized, E0002 - Not Authorized ------------------------*
*---A status is active when the field INACT is space ------------------*
SELECT * FROM jest WHERE objnr = p_objnr
AND stat IN ('E0001', 'E0002')
AND inact = space.
IF jest-stat = 'E0002'.
MOVE 'Y' TO itab-text.
SELECT MAX( udate ) INTO itab-udate
FROM jcds
WHERE objnr = p_objnr
AND stat = jest-stat.
ELSE.
MOVE 'N' TO itab-text.
ENDIF.
PERFORM get_values.
MODIFY itab.
ENDSELECT.
IF sy-subrc <> 0.
MOVE 'N' TO itab-text.
PERFORM get_values.
MODIFY itab.
ENDIF.
CLEAR itab.

ENDLOOP.
ENDFORM.

" DATA_SELECT

*&---------------------------------------------------------------------*
*&
Form WRITE_HEADER
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM write_header.
WRITE :/ 'DI Quote #',
12 'Item',
19 'Customer Name',
40 'Material',
60 'PE',
68 'Quantity',
87 'Book Cost',
104 'AMM',
121 'Unit price',
138 'Extended Price',
155 'Resale Price',
*
*
*
*
*
*

172 'Auth Date'.


187 'Authorized'
201 'Valid',
212 'Valid',
223 'OPEN'.
234 'AZ Contract',
240 'AZ item'.

WRITE:/ 'To' UNDER 'Valid'.


* WRITE: / 'Y/N' UNDER 'Authorized'.

ULINE.
ENDFORM.

" WRITE_HEADER

*&---------------------------------------------------------------------*
*&
Form WRITE_OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM write_output.
DATA : p_netval LIKE vbap-netpr,
p_resale LIKE vbap-netpr,
guebg LIKE itab-guebg,
gueen LIKE itab-gueen.
SORT itab BY kunnr udate vbeln posnr.
DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.
*--if only Authorized Contracts are to displayed, delete the ones which
*--are not Authorized
IF chk_auth = 'X'.
LOOP AT itab WHERE text = 'N'.

DELETE itab.
ENDLOOP.
ENDIF.
*{ INSERT
NDVK904324
* AMOK 06/18/2001 - Delete blank distributor
LOOP AT itab WHERE kunnr = ' '.
DELETE itab.
ENDLOOP.
*} INSERT

FORMAT INTENSIFIED OFF.


LOOP AT itab.
AT NEW kunnr.
NEW-PAGE.
CLEAR kna1.
SELECT SINGLE * FROM kna1 WHERE kunnr = itab-kunnr.
FORMAT COLOR 7 ON.
WRITE :/ 'Distributor :', kna1-name1, '(', itab-kunnr, ')',
50 'Valid From:', 62 s_guebg-low,
74 'Valid To: ', 84 s_gueen-low,
96 '
'.
FORMAT COLOR 2 ON.
ULINE.
ENDAT.
CLEAR p_netval.
* p_netval = itab-zmeng * itab-netpr.
"KC060522
p_netval = itab-zmeng * itab-zz_unit_price.
"KC060522
CLEAR p_resale.
CONDENSE itab-zazr_contract NO-GAPS.
p_resale = itab-kzwi5 / itab-zmeng.
WRITE :/ itab-vbeln ,
12 itab-posnr ,
20 itab-bstkd+0(18),
40 itab-matnr ,
60 itab-pernr+2(6),
70 itab-zmeng,
87 itab-book_price ,
104 itab-amm_price ,
*
121 itab-netpr,
"KC060522
121 itab-zz_unit_price,
"KC060522
138 p_netval ,
*
155 p_resale,
"KC060522
155 itab-zrsl_price,
"KC060522
172 itab-udate ,
187 itab-text,
201 itab-guebg,
212 itab-gueen,
224 itab-open_qty LEFT-JUSTIFIED,
236 itab-zazr_contract LEFT-JUSTIFIED,
*
240 itab-zazr_item,
247 itab-ktext.
ENDLOOP.
IF sy-subrc <> 0.
MESSAGE i009(zrep).
ENDIF.
ENDFORM.
" WRITE_OUTPUT
*&---------------------------------------------------------------------*
*&
Form CALL_VA43
*&---------------------------------------------------------------------*

*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM call_va43.
SET PARAMETER ID 'KTN' FIELD fvalue.
CALL TRANSACTION 'VA43' AND SKIP FIRST SCREEN.
ENDFORM.
" CALL_VA43
*&---------------------------------------------------------------------*
*&
Form GET_VALUES
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM get_values.
SELECT SINGLE kbetr waers FROM konv
INTO (konv-kbetr , konv-waers)
"KC060522
WHERE knumv = itab-knumv
"KC060522
AND kposn = itab-posnr
"KC060522
AND kschl = 'ZRSL'.
"KC060522
IF sy-subrc = 0.
"KC060522
IF konv-waers = 'US$'.
"KC060522
itab-zrsl_price = konv-kbetr / 10.
"KC060522
ELSE.
"KC060522
itab-zrsl_price = konv-kbetr.
"KC060522
ENDIF.
"KC060522
ENDIF.
"KC060522
CLEAR konv.
SELECT * FROM konv WHERE knumv = itab-knumv
AND kposn = itab-posnr
AND kschl IN ('ZPR1').
",'ZB00').
PERFORM get_book_value USING konv-kposn konv-stunr
konv-zaehk konv-kschl itab-vbeln.
IF itab-book_price IS INITIAL.
*
SELECT kbetr INTO itab-book_price
"KC060522
*
FROM konp WHERE knumh = konv-knumh.
"KC060522
*
ENDSELECT.
"KC060522
SELECT kbetr konwa
"KC060522
INTO CORRESPONDING FIELDS OF konp
"KC060522
FROM konp WHERE knumh = konv-knumh.
"KC060522
IF konp-konwa = 'US$'.
"KC060522
itab-book_price = konp-kbetr / 10.
"KC060522
ELSE.
"KC060522
itab-book_price = konp-kbetr.
"KC060522
ENDIF.
"KC060522
CLEAR konp.
"KC060522
ENDSELECT.
"KC060522
ENDIF.
* SELECT mxwrt INTO itab-amm_price
"KC060522
*
FROM konp WHERE knumh = konv-knumh.
"KC060522
* ENDSELECT.
"KC060522
SELECT mxwrt konwa
"KC060522
INTO CORRESPONDING FIELDS OF konp
"KC060522
FROM konp WHERE knumh = konv-knumh.
"KC060522
IF konp-konwa = 'US$'.
"KC060522
itab-amm_price = konp-mxwrt / 10.
"KC060522

ELSE.
itab-amm_price = konp-mxwrt.
ENDIF.
ENDSELECT.
ENDSELECT.
ENDFORM.

"KC060522
"KC060522
"KC060522
"KC060522

" GET_VALUES

*&---------------------------------------------------------------------*
*&
Form GET_BOOK_VALUE
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_P_KPOSN text
*
*
-->P_P_STUNR text
*
*
-->P_P_ZAEHK text
*
*
-->P_P_KSCHL text
*
*
-->P_P_VBELN text
*
*----------------------------------------------------------------------*
FORM get_book_value USING p_kposn p_stunr p_zaehk p_kschl p_vbeln.
DATA : key LIKE cdpos-tabkey,
objectid LIKE cdhdr-objectid.
DATA:BEGIN OF line OCCURS 5.
INCLUDE STRUCTURE cdred.
DATA:END OF line.
CLEAR key.
CONCATENATE p_kposn p_stunr p_zaehk p_kschl INTO key.
MOVE p_vbeln TO objectid.
CALL FUNCTION 'CHANGEDOCUMENT_READ'
EXPORTING
*
archive_handle
=0
*
changenumber
= ''
objectclass
= 'VERKBELEG'
objectid
= objectid
tablekey
= key
tablename
= 'KONVC'
TABLES
editpos
= line
EXCEPTIONS
no_position_found
=1
wrong_access_to_archive = 2
time_zone_conversion_error = 3
OTHERS
= 4.
READ TABLE line INDEX 1.
IF sy-subrc = 0.
itab-book_price = line-f_old+1(15).
ENDIF.
ENDFORM.
" GET_BOOK_VALUE
*&---------------------------------------------------------------------*
*&
Form INITIALIZE
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM initialize.
DATA:date1 LIKE sy-datum,

date2 LIKE sy-datum.


IF NOT s_guebg IS INITIAL.
date1 = s_guebg-low.
REFRESH s_guebg.CLEAR s_guebg.
s_guebg-sign = 'I'.
s_guebg-option = 'GE'.
s_guebg-low = date1.
APPEND s_guebg .
ENDIF.
IF NOT s_gueen IS INITIAL.
date2 = s_gueen-low.
REFRESH s_gueen.CLEAR s_gueen.
s_gueen-sign = 'I'.
s_gueen-option = 'LE'.
s_gueen-low = date2.
APPEND s_gueen.
ENDIF.
ENDFORM.
" INITIALIZE
*&---------------------------------------------------------------------*
*&
Form GET_PERNR
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM get_pernr.
*{ INSERT
NDVK903723
1
* AMOK 05/29/2001 - PE to ZE Conversion
SELECT SINGLE * FROM vbpa WHERE vbeln = itab-vbeln
AND posnr = itab-posnr
AND parvw = 'ZE'.
IF sy-subrc <> 0.
SELECT SINGLE * FROM vbpa WHERE vbeln = itab-vbeln
AND posnr = '000000'
AND parvw = 'ZE'.
ENDIF.
itab-pernr = vbpa-kunnr.
IF itab-pernr IN s_pernr.
" ztericode is in the selected range
ELSE.
CLEAR itab.
ENDIF.
*} INSERT
*{ DELETE
NDVK903723
2
*\
SELECT SINGLE * FROM VBPA WHERE VBELN = ITAB-VBELN
*\
AND POSNR = ITAB-POSNR
*\
AND PARVW = 'VE'.
*\
IF SY-SUBRC <> 0.
*\
SELECT SINGLE * FROM VBPA WHERE VBELN = ITAB-VBELN
*\
AND POSNR = '000000'
*\
AND PARVW = 'VE'.
*\
ENDIF.
*\
IF VBPA-PERNR IN S_PERNR.
*\
ITAB-PERNR = VBPA-PERNR.
*\
ELSE.
*\
CLEAR ITAB.
*\
ENDIF.
*} DELETE
ENDFORM.
" GET_PERNR
*&---------------------------------------------------------------------*
*&
Form GET_PGI_QTY
*&---------------------------------------------------------------------*
*
text

*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM get_open_qty.
DATA:v_rfmng LIKE vbfa-rfmng,
pgi TYPE p DECIMALS 0.
SELECT SUM( rfmng ) INTO v_rfmng FROM vbfa WHERE
vbelv = itab-vbeln AND
posnv = itab-posnr AND
vbtyp_n = 'K'.
pgi = v_rfmng.
itab-open_qty = itab-zmeng - pgi.
CLEAR:v_rfmng,pgi.
ENDFORM.
" GET_PGI_QTY