Вы находитесь на странице: 1из 14

*&---------------------------------------------------------------------*

*& Include
ZSDN_BILLING_LIST_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& 01.
Form FREE_TABLES
*&---------------------------------------------------------------------*
* This FORM is used to release the memory allocated like internal
* tables and variables.
*----------------------------------------------------------------------*
FORM FREE_TABLES .
FREE :
IT_VBAK,
IT_VBAP,
IT_VBFA,
IT_VBRP,
IT_VBRK,
IT_VEDA,
IT_VBPA,
IT_OUTPUT,
IT_FIELDCAT.
CLEAR :WA_VBAK,
WA_VBAP,
WA_VBFA,
WA_VBRK,
WA_VBRP,
WA_VEDA,
WA_VBPA,
WA_OUTPUT,
G_PERNR,
G_USER,
R_PARVW,
R_RFBSK.
ENDFORM.
" FREE_TABLES
*&---------------------------------------------------------------------*
*& 02. Form POPULATE_PARTNER
*&---------------------------------------------------------------------*
*
The purpose of this form is to populate the partner data based
*
* on the selection screen values.
*
*----------------------------------------------------------------------*
FORM POPULATE_PARTNER .
DATA : L_PARVW TYPE TPAR-PARVW.
CLEAR : L_PARVW.
SELECT PARVW FROM TPAR
INTO L_PARVW
WHERE NRART EQ K_NRART.
R_PARVW-SIGN = K_SIGN_I.
R_PARVW-OPTION = K_OPTION_EQ.
R_PARVW-LOW = L_PARVW.
APPEND R_PARVW.
CLEAR R_PARVW.
ENDSELECT.

"'PE'.
"'I'
"'EQ'

CLEAR : G_PERNR, G_USER.


SELECT SINGLE PERNR FROM PA0105
INTO G_PERNR
WHERE SUBTY EQ K_SUBTY

" '0001'

AND
AND
AND
AND

BEGDA
ENDDA
USRTY
USRID

LE
GE
EQ
EQ

SY-DATUM
SY-DATUM
K_USRTY
SY-UNAME.

" '0001'

G_USER = SY-UNAME.
ENDFORM.
" POPULATE_PARTNER
*&---------------------------------------------------------------------*
*& 04. Form SELECT_DATA
*&---------------------------------------------------------------------*
*
This form is used to extract Billing Document: Header Data,
*
*
Billing Document: Item Data, Sales Document Flow Data,
*
*
Sales Document: Header Data, Sales Document: Item Data.
*
*----------------------------------------------------------------------*
FORM SELECT_DATA .
SELECT VBELN FKART FKTYP VBTYP WAERK VKORG VTWEG
FKDAT KDGRP RFBSK ERNAM KUNRG KUNAG ZZ_DMR_BILLFROM ZZ_DMR_BILLTO
FROM VBRK
INTO TABLE IT_VBRK
WHERE VBELN IN S_VBELN
AND FKART IN S_FKART
AND VKORG IN S_VKORG
AND VTWEG IN S_VTWEG
AND FKDAT IN S_FKDAT
AND KDGRP IN S_KDGRP
AND RFBSK IN R_RFBSK
AND KUNRG IN S_KUNRG
AND KUNAG IN S_KUNAG.
*
AND sfakn EQ space.
" 097470
*
AND fksto NE k_x.
" 097470
IF SY-SUBRC = 0.
SORT IT_VBRK BY VBELN.
SELECT VBELN POSNR NETWR MWSBP PS_PSP_PNR VGBEL VGPOS
FROM VBRP
INTO TABLE IT_VBRP
FOR ALL ENTRIES IN IT_VBRK
WHERE VBELN = IT_VBRK-VBELN.
IF SY-SUBRC = 0.
SORT IT_VBRP BY VBELN POSNR.
SELECT VBELV POSNV VBELN POSNN STUFE VBTYP_V FPLNR FPLTR
FROM VBFA
INTO TABLE IT_VBFA
FOR ALL ENTRIES IN IT_VBRP
WHERE VBELN = IT_VBRP-VBELN
AND POSNN = IT_VBRP-POSNR
AND ( VBTYP_V = K_VBTYP_G OR
VBTYP_V = K_VBTYP_C OR
VBTYP_V = K_VBTYP_L ).
IF SY-SUBRC = 0.
SORT IT_VBFA BY VBELV POSNV.
SELECT VBELN POSNR ZZ_CONT_MFN ZZ_CONT_TRANPH ZZ_CONT_WNTY_CLS
ZZ_CONT_SUBSLA ZZ_CONT_SUBCOLA ZZ_CONT_NTE ZZ_CONT_TPENG
ZZ_CONT_TPBUS ZZ_CONT_NTEEXP ZZ_CONT_NTESER PSTYV
FROM VBAP
INTO TABLE IT_VBAP

FOR ALL ENTRIES IN IT_VBFA


WHERE VBELN = IT_VBFA-VBELV
AND POSNR = IT_VBFA-POSNV
AND ZZ_CONT_WNTY_CLS IN S_WNTCLS
AND ZZ_CONT_SUBSLA IN S_CONSLA.
IF SY-SUBRC = 0.
SORT IT_VBAP BY VBELN POSNR.
SELECT VBELN VPOSN VENDDAT
FROM VEDA
INTO TABLE IT_VEDA
FOR ALL ENTRIES IN IT_VBAP
WHERE VBELN = IT_VBAP-VBELN
AND ( VPOSN = IT_VBAP-POSNR OR
VPOSN = K_POSNR )
AND VENDDAT IN S_VENDAT.
IF SY-SUBRC = 0.
SORT IT_VEDA BY VBELN VPOSN.
ENDIF.
*
i
*
*
*
*
*
*
*
*

*
*

"'000000'

SELECT vbeln posnr parvw kunnr pernr " parvw , kunnr added by srihar
FROM vbpa
INTO TABLE it_vbpa
FOR ALL ENTRIES IN it_vbap
WHERE vbeln = it_vbap-vbeln
AND ( posnr = it_vbap-posnr OR
posnr = k_posnr )
AND parvw IN r_parvw
AND pernr = g_pernr.

"'000000'

SELECT VBELN POSNR PARVW KUNNR PERNR " parvw , kunnr added by srihari
FROM VBPA
INTO TABLE IT_VBPA
FOR ALL ENTRIES IN IT_VBAP
WHERE VBELN = IT_VBAP-VBELN.
AND POSNR = IT_VBAP-POSNR.
"'000000'
AND PARVW EQ 'BP'. "Srihari
IF SY-SUBRC = 0.
SORT IT_VBPA BY VBELN.
ENDIF.
SELECT VBELN AUART ERNAM KVGR1
FROM VBAK
INTO TABLE IT_VBAK
FOR ALL ENTRIES IN IT_VBAP
WHERE VBELN = IT_VBAP-VBELN
AND AUART IN S_AUART.
IF SY-SUBRC = 0.
SORT IT_VBAK BY VBELN.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.

****Begin of changes by 097470


IF IT_VBRK IS NOT INITIAL.
SELECT KUNNR NAME1 FROM KNA1 INTO TABLE IT_KNA1

FOR ALL ENTRIES IN IT_VBRK


WHERE KUNNR = IT_VBRK-KUNAG.
IF SY-SUBRC = 0.
SORT IT_KNA1 BY KUNNR.
ENDIF.
ENDIF.
IF IT_VBRP IS NOT INITIAL.
SELECT VBELN AUART FROM VBAK INTO TABLE IT_VBAK_DOCTYPE
FOR ALL ENTRIES IN IT_VBRP
WHERE VBELN = IT_VBRP-VGBEL.
IF SY-SUBRC = 0.
SORT IT_VBAK_DOCTYPE BY VBELN.
ENDIF.
SELECT PSPNR PSPHI FROM PRPS INTO TABLE IT_PRPS
FOR ALL ENTRIES IN IT_VBRP
WHERE PSPNR = IT_VBRP-PS_PSP_PNR.
IF SY-SUBRC = 0.
SORT IT_PRPS BY PSPNR.
ENDIF.
IF IT_PRPS IS NOT INITIAL.
SELECT PSPNR POST1 FROM PROJ INTO TABLE IT_PROJ
FOR ALL ENTRIES IN IT_PRPS
WHERE PSPNR = IT_PRPS-PSPHI.
IF SY-SUBRC = 0.
SORT IT_PROJ BY PSPNR.
ENDIF.
ENDIF.
SELECT VBELV POSNV VBELN POSNN STUFE VBTYP_V
FROM VBFA INTO TABLE IT_VBFA1
FOR ALL ENTRIES IN IT_VBRP
WHERE VBELV = IT_VBRP-VGBEL.
IF SY-SUBRC = 0.
SORT IT_VBFA1 BY VBELV.
ENDIF.
IF IT_VBFA1 IS NOT INITIAL.
SELECT VBELV POSNV VBELN POSNN STUFE VBTYP_V
FROM VBFA INTO TABLE IT_VBFA2
FOR ALL ENTRIES IN IT_VBFA1
WHERE VBELN = IT_VBFA1-VBELV AND
VBTYP_V = 'C'.
IF SY-SUBRC = 0.
SORT IT_VBFA2 BY VBELN VBTYP_V.
ENDIF.
IT_VBAP1[] = IT_VBAP[].
IF IT_VBFA2 IS NOT INITIAL.
SELECT VBELN POSNR ZZ_CONT_MFN ZZ_CONT_TRANPH ZZ_CONT_WNTY_CLS
ZZ_CONT_SUBSLA ZZ_CONT_SUBCOLA ZZ_CONT_NTE ZZ_CONT_TPENG
ZZ_CONT_TPBUS ZZ_CONT_NTEEXP ZZ_CONT_NTESER PSTYV
FROM VBAP APPENDING TABLE IT_VBAP1
FOR ALL ENTRIES IN IT_VBFA2
WHERE VBELN = IT_VBFA2-VBELV.
IF SY-SUBRC = 0.

SORT IT_VBAP1 BY VBELN.


ENDIF.
ENDIF.
IF IT_VBAP1 IS NOT INITIAL.
SELECT * FROM TVAPT INTO TABLE IT_TVAPT
FOR ALL ENTRIES IN IT_VBAP1
WHERE SPRAS = 'E' AND
PSTYV = IT_VBAP1-PSTYV.
IF SY-SUBRC = 0.
SORT IT_TVAPT BY SPRAS PSTYV.
ENDIF.
ENDIF.
SELECT FPLNR FPLTR AFDAT FROM FPLT INTO TABLE IT_FPLT
FOR ALL ENTRIES IN IT_VBFA
WHERE FPLNR = IT_VBFA-FPLNR AND
FPLTR = IT_VBFA-FPLTR.
IF SY-SUBRC = 0.
SORT IT_FPLT BY FPLNR FPLTR.
ENDIF.
ENDIF.
SELECT VBELN FKDAT FROM VBKD INTO TABLE IT_VBKD
FOR ALL ENTRIES IN IT_VBRP
WHERE VBELN = IT_VBRP-VGBEL.
IF SY-SUBRC = 0.
SORT IT_VBKD BY VBELN.
ENDIF.
ENDIF.
SELECT * FROM TVV1T INTO TABLE IT_TVV1T WHERE SPRAS = 'E'.
IF SY-SUBRC = 0.
SORT IT_TVV1T BY SPRAS KVGR1.
ENDIF.
****End of changes by 097470
ENDFORM.
" SELECT_DATA
*&---------------------------------------------------------------------*
*& 05. Form PROCESS_DATA
*&---------------------------------------------------------------------*
* This form is used to process through the selected data and populate *
* output internal table which is used for ALV display.
*----------------------------------------------------------------------*
FORM PROCESS_DATA .
DATA : L_UPDATE TYPE XFELD,
LW_KNA1 TYPE KNA1. "srihari
IF IT_VBFA[] IS NOT INITIAL.
SORT IT_VBFA BY VBELN POSNN STUFE.
ENDIF.
CLEAR LV_NETWR.
" 097470
LOOP AT IT_VBRP INTO WA_VBRP.
CLEAR : L_UPDATE, WA_VBAP, WA_VBAK, WA_VBRK, WA_VBPA, WA_VEDA,
WA_VBFA, WA_OUTPUT.
CLEAR : WA_KNA1, WA_VBAK_DOCTYPE, WA_TVV1T, WA_VBFA1, WA_VBFA2,
WA_VBAP1, WA_TVAPT, WA_FPLT, WA_PRPS,WA_PROJ, WA_VBKD. " 097470

READ TABLE IT_VBFA INTO WA_VBFA


WITH KEY VBELN = WA_VBRP-VBELN
POSNN = WA_VBRP-POSNR BINARY SEARCH.
IF SY-SUBRC = 0.
READ TABLE IT_VBAP INTO WA_VBAP
WITH KEY VBELN = WA_VBFA-VBELV
POSNR = WA_VBFA-POSNV BINARY SEARCH.
IF SY-SUBRC = 0.
READ TABLE IT_VBAK INTO WA_VBAK
WITH KEY VBELN = WA_VBAP-VBELN BINARY SEARCH.
ENDIF.
" 097470
ENDIF.
" 097470
*
IF sy-subrc = 0.
**
IF wa_vbak-ernam = g_user.
"sy-uname.
**
l_update = k_x.
"'X'
**
ELSE.
**
READ TABLE it_vbpa INTO wa_vbpa
**
WITH KEY vbeln = wa_vbap-vbeln BINARY SEARCH.
**
IF sy-subrc = 0.
**
l_update = k_x.
"'X'.
**
wa_output-KUNNR = wa_vbpa-KUNNR. " start of change srihari
**
ENDIF.
**
ENDIF.
**
IF l_update IS INITIAL.
**
READ TABLE it_vbrk INTO wa_vbrk
**
WITH KEY vbeln = wa_vbfa-vbeln
**
ernam = sy-uname.
**
IF sy-subrc = 0.
**
l_update = k_x.
"'X'.
**
ENDIF.
**
ENDIF.
**************************************************************Start of change by
srihari 27/06/2016
SORT IT_VBPA BY VBELN PARVW.
READ TABLE IT_VBPA INTO WA_VBPA
WITH KEY VBELN = WA_VBAP-VBELN
PARVW = 'RE'.
*
PARVW = 'RE' BINARY SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-KUNNR = WA_VBPA-KUNNR. " start of change srihari
CLEAR LW_KNA1.
CALL FUNCTION 'KNA1_SINGLE_READ'
EXPORTING
*
KZRFB
= ' '
KNA1_KUNNR
= WA_OUTPUT-KUNNR
*
CVP_BEHAVIOR =
IMPORTING
WKNA1
= LW_KNA1
EXCEPTIONS
NOT_FOUND
= 1
KUNNR_BLOCKED = 2
OTHERS
= 3.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ELSE.
WA_OUTPUT-KNAME1 = LW_KNA1-NAME1.
ENDIF.
ENDIF.
*

READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_OUTPUT-KUNNR BINARY SE

ARCH.
*
IF SY-SUBRC = 0.
*
WA_OUTPUT-KNAME1 = WA_KNA1-NAME1. "srihari
*
ENDIF.
**************************************************************End of change by s
rihari 27/06/2016
*

l_update = 'X'.
" temp added by 097470
L_UPDATE = K_X. "srihari
IF L_UPDATE = K_X.
WA_OUTPUT-VBELN = WA_VBRP-VBELN.
WA_OUTPUT-MWSBP = WA_VBRP-MWSBP.
READ TABLE IT_VBRK INTO WA_VBRK
WITH KEY VBELN = WA_VBRP-VBELN BINARY SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-FKART = WA_VBRK-FKART.
WA_OUTPUT-KUNAG = WA_VBRK-KUNAG.
WA_OUTPUT-KUNRG = WA_VBRK-KUNRG.
WA_OUTPUT-FKDAT = WA_VBRK-FKDAT.
WA_OUTPUT-VKORG = WA_VBRK-VKORG.
WA_OUTPUT-VTWEG = WA_VBRK-VTWEG.
WA_OUTPUT-FKTYP = WA_VBRK-FKTYP.
WA_OUTPUT-VBTYP = WA_VBRK-VBTYP.
WA_OUTPUT-RFBSK = WA_VBRK-RFBSK.
WA_OUTPUT-WAERK = WA_VBRK-WAERK.
WA_OUTPUT-ERNAM = WA_VBRK-ERNAM.
ENDIF.

*********** Begin of changes by 097470


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

READ TABLE it_veda INTO wa_veda


WITH KEY vbeln = wa_vbap-vbeln
vposn = wa_vbap-posnr BINARY SEARCH.
IF sy-subrc = 0.
wa_output-venddat = wa_veda-venddat.
ELSE.
READ TABLE it_veda INTO wa_veda
WITH KEY vbeln = wa_vbap-vbeln
vposn = k_posnr BINARY SEARCH.
IF sy-subrc = 0.
wa_output-venddat = wa_veda-venddat.
ELSE.
CONTINUE.
ENDIF.
ENDIF.

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

wa_output-vbeln_c = wa_vbap-vbeln.
wa_output-posnr_c = wa_vbap-posnr.
wa_output-zzssla = wa_vbap-zz_cont_subsla.
wa_output-zztpeng = wa_vbap-zz_cont_tpeng.
wa_output-zzwnty = wa_vbap-zz_cont_wnty_cls.
wa_output-zzscola = wa_vbap-zz_cont_subcola.
wa_output-zzmfn = wa_vbap-zz_cont_mfn.
wa_output-zzntes = wa_vbap-zz_cont_nteser.
wa_output-zzntee = wa_vbap-zz_cont_nteexp.
wa_output-zznte = wa_vbap-zz_cont_nte.
wa_output-zztranp = wa_vbap-zz_cont_tranph.
wa_output-zztpbus = wa_vbap-zz_cont_tpbus.
wa_output-auart = wa_vbak-auart.

*
*

wa_output-posnr = wa_vbrp-posnr.
wa_output-netwr = wa_vbrp-netwr.
" sold to party name
READ TABLE IT_KNA1 INTO WA_KNA1 WITH KEY KUNNR = WA_VBRK-KUNAG BINARY SEAR

CH.
IF SY-SUBRC = 0.
WA_OUTPUT-NAME1 = WA_KNA1-NAME1.
ENDIF.

***Start if change by srihari 22 nd July


*
READ TABLE it_kna1 INTO wa_kna1 WITH KEY kunnr = wa_vbpa-kunnr BINARY SEA
RCH.
*
IF sy-subrc = 0.
*
wa_output-KNAME1 = wa_kna1-name1. "srihari
*
ENDIF.
***End of change by srihari
" sales document
WA_OUTPUT-VBELN_C = WA_VBRP-VGBEL.
" sales document type
READ TABLE IT_VBAK_DOCTYPE INTO WA_VBAK_DOCTYPE WITH KEY VBELN = WA_VBRP-V
GBEL BINARY SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-AUART = WA_VBAK_DOCTYPE-AUART.
ENDIF.
" Customer invoice communication
READ TABLE IT_TVV1T INTO WA_TVV1T WITH KEY SPRAS = K_SPRAS
KVGR1 = WA_VBAK-KVGR1 BINARY SE
ARCH.
IF SY-SUBRC = 0.
CONCATENATE WA_VBAK-KVGR1 WA_TVV1T-BEZEI INTO WA_OUTPUT-KVGR1 SEPARATED
BY ' '.
ENDIF.
" Item category
READ TABLE IT_VBFA1 INTO WA_VBFA1 WITH KEY VBELV = WA_VBRP-VGBEL BINARY SE
ARCH.
IF SY-SUBRC = 0.
IF WA_VBRK-VTWEG = K_VTWEG_IC.
READ TABLE IT_VBAP1 INTO WA_VBAP1 WITH KEY VBELN = WA_VBFA1-VBELV BINA
RY SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-PSTYV = WA_VBAP1-PSTYV.
ENDIF.
ELSEIF WA_VBFA1-VBTYP_V NE K_VBTYP_C.
READ TABLE IT_VBFA2 INTO WA_VBFA2 WITH KEY VBELN = WA_VBFA1-VBELV
VBTYP_V = K_VBTYP_C BINARY
SEARCH.
IF SY-SUBRC = 0.
READ TABLE IT_VBAP1 INTO WA_VBAP1 WITH KEY VBELN = WA_VBFA2-VBELV BI
NARY SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-PSTYV = WA_VBAP1-PSTYV.

ENDIF.
ENDIF.
ELSEIF WA_VBFA1-VBTYP_V EQ K_VBTYP_C.
READ TABLE IT_VBAP1 INTO WA_VBAP1 WITH KEY VBELN = WA_VBFA1-VBELV BINA
RY SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-PSTYV = WA_VBAP1-PSTYV.
ENDIF.
ENDIF.
ENDIF.
" Item category desc
IF WA_OUTPUT-PSTYV IS NOT INITIAL.
READ TABLE IT_TVAPT INTO WA_TVAPT WITH KEY SPRAS = K_SPRAS
PSTYV = WA_VBAP1-PSTYV BINARY
SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-PSTYV_TEXT = WA_TVAPT-VTEXT.
ENDIF.
ENDIF.
"/* For intercomany docs, billing from/to and billing event is balnk
"/* From ZTNM docs, billing from/to is from VBRK and billing event is blan
k
"/* For ZAMB docs, billing from/to is balnk and billing event is from VBKD
"/* For remaining docs, billing from/to is balnk and billing event is from
FPLT
IF WA_VBRK-VTWEG NE K_VTWEG_IC.
IF WA_OUTPUT-PSTYV = K_PSTYV_TNM.
" Billing from/to
WA_OUTPUT-ZZ_DMR_BILLFROM = WA_VBRK-ZZ_DMR_BILLFROM.
WA_OUTPUT-ZZ_DMR_BILLTO = WA_VBRK-ZZ_DMR_BILLTO.
" Billing event
ELSEIF WA_OUTPUT-PSTYV = K_PSTYV_AMB.
READ TABLE IT_VBKD INTO WA_VBKD WITH KEY VBELN = WA_VBRP-VGBEL BINARY
SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-AFDAT = WA_VBKD-FKDAT.
ENDIF.
ELSE.
READ TABLE IT_FPLT INTO WA_FPLT WITH KEY FPLNR = WA_VBFA-FPLNR
FPLTR = WA_VBFA-FPLTR BINARY
SEARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-AFDAT = WA_FPLT-AFDAT.
ENDIF.
ENDIF.
ENDIF.
" Project desc
READ TABLE IT_PRPS INTO WA_PRPS WITH KEY PSPNR = WA_VBRP-PS_PSP_PNR BINARY
SEARCH.
IF SY-SUBRC = 0.
READ TABLE IT_PROJ INTO WA_PROJ WITH KEY PSPNR = WA_PRPS-PSPHI BINARY SE
ARCH.
IF SY-SUBRC = 0.
WA_OUTPUT-POST1 = WA_PROJ-POST1.
ENDIF.
ENDIF.

" Contract number


CLEAR: WA_VBFA1, WA_VBFA2.
READ TABLE IT_VBFA INTO WA_VBFA1 WITH KEY VBELN = WA_OUTPUT-VBELN
VBTYP_V = K_VBTYP_G.
IF SY-SUBRC = 0.
WA_OUTPUT-CONT_NUM = WA_VBFA1-VBELV.
ELSE.
READ TABLE IT_VBFA INTO WA_VBFA2 WITH KEY VBELN = WA_OUTPUT-VBELN_C
VBTYP_V = K_VBTYP_G.
IF SY-SUBRC = 0.
WA_OUTPUT-CONT_NUM = WA_VBFA2-VBELV.
ENDIF.
ENDIF.
" Net value
LV_NETWR = LV_NETWR + WA_VBRP-NETWR.
WA_OUTPUT-NETWR = LV_NETWR.
IF WA_VBRK-VBTYP = K_VBTYP_O.
WA_OUTPUT-NETWR = -1 * WA_OUTPUT-NETWR.
ENDIF.
******Start of change by srihari 21st July 2016
*data : val(13) type c.
*data : val1(13) type c.
*
**data : val1 like vbap-netpr.
*wa_vbrp-netwr = wa_vbrp-netwr * -1.
*wa_vbrp-mwsbp = wa_vbrp-mwsbp * -1.
* val = wa_vbrp-netwr.
* val1 = wa_vbrp-mwsbp.
IF WA_VBRK-FKART = 'ZS1' OR WA_VBRK-FKART = 'ZIVS' .
*CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
* CHANGING
*
VALUE
= val .
*
*CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
* CHANGING
*
VALUE
= val1 .
*wa_output-netwr = val .
*wa_output-mwsbp = val1 .
WA_OUTPUT-NETWR = -1 * WA_OUTPUT-NETWR .
WA_OUTPUT-MWSBP = -1 * WA_OUTPUT-MWSBP .
ENDIF.
***End of change by srihari 21st July 2016
************end of changes by 097470

*
*
*

AT END OF VBELN.
APPEND WA_OUTPUT TO IT_OUTPUT.
CLEAR LV_NETWR.
ENDAT.
ENDIF.
ENDIF.
ENDIF.
ENDIF.

" 097470

CLEAR WA_VBRP.
ENDLOOP.
ENDFORM.
" PROCESS_DATA
*&---------------------------------------------------------------------*
*& 03. Form DOCUMENT_STATUS
*&---------------------------------------------------------------------*
* The purpose of this form is to select the appropriate billing
*
* documents based on the selction screen inputs.
*
*----------------------------------------------------------------------*
FORM DOCUMENT_STATUS .
* Selection: Open billing documents
IF NOT CHK_OPEN IS INITIAL AND
CHK_BFI IS INITIAL.
R_RFBSK-SIGN = K_SIGN_E.
R_RFBSK-OPTION = K_OPTION_EQ.
R_RFBSK-LOW = K_RFBSK_C.
APPEND R_RFBSK.
CLEAR R_RFBSK.

"'E'.
"'EQ'.
"'C'.

R_RFBSK-SIGN = K_SIGN_E.
R_RFBSK-OPTION = K_OPTION_EQ.
R_RFBSK-LOW = K_RFBSK_D.
APPEND R_RFBSK.
CLEAR R_RFBSK.

"'E'.
"'EQ'.
"'D'.

R_RFBSK-SIGN = K_SIGN_E.
R_RFBSK-OPTION = K_OPTION_EQ.
R_RFBSK-LOW = K_RFBSK_E.
APPEND R_RFBSK.
CLEAR R_RFBSK.

"'E'.
"'EQ'.
"'E'.

ENDIF.
* Selection: Billing documents in FI
IF CHK_OPEN
IS INITIAL AND
NOT CHK_BFI IS INITIAL.
R_RFBSK-SIGN = K_SIGN_I.
R_RFBSK-OPTION = K_OPTION_EQ.
R_RFBSK-LOW = K_RFBSK_C.
APPEND R_RFBSK.
CLEAR R_RFBSK.
ENDIF.
* Selection: Both together
IF NOT CHK_OPEN IS INITIAL AND
NOT CHK_BFI IS INITIAL.
R_RFBSK-SIGN = K_SIGN_E.
R_RFBSK-OPTION = K_OPTION_EQ.
R_RFBSK-LOW = K_RFBSK_D.
APPEND R_RFBSK.
CLEAR R_RFBSK.
R_RFBSK-SIGN = K_SIGN_E.
R_RFBSK-OPTION = K_OPTION_EQ.
R_RFBSK-LOW = K_RFBSK_E.
APPEND R_RFBSK.
CLEAR R_RFBSK.

"'I'.
"'EQ'.
"'C'.

"'E'.
"'EQ'.
"'D'.

"'E'.
"'EQ'.
"'E'.

ENDIF.
ENDFORM.
" DOCUMENT_STATUS
*&---------------------------------------------------------------------*
*& 06. Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*
This form is used to buid a fieldcatalog for ALV output.
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT .
DATA: WA_FIELDCAT LIKE LINE OF IT_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME
= 'ZSD_ZVF05N_OUTPUT'
CHANGING
CT_FIELDCAT
= IT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR
= 2
OTHERS
= 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
DISPLAY LIKE 'S'
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
LEAVE LIST-PROCESSING.
****Begin of changes by 097470.
ELSE.
LOOP AT IT_FIELDCAT INTO WA_FIELDCAT.
CASE WA_FIELDCAT-FIELDNAME.
WHEN 'NAME1'.
WA_FIELDCAT-DDICTXT = 'M'.
WA_FIELDCAT-SELTEXT_S = 'Sold-to pt name'.
WA_FIELDCAT-SELTEXT_M = 'Sold-to pt name'.
WA_FIELDCAT-SELTEXT_L = 'Sold-to party name'.
WHEN 'ZZ_DMR_BILLFROM'.
WA_FIELDCAT-DDICTXT =
WA_FIELDCAT-SELTEXT_S
WA_FIELDCAT-SELTEXT_M
WA_FIELDCAT-SELTEXT_L

'M'.
= 'Billing From'.
= 'Billing From'.
= 'Billing From'.

WHEN 'ZZ_DMR_BILLTO'.
WA_FIELDCAT-DDICTXT =
WA_FIELDCAT-SELTEXT_S
WA_FIELDCAT-SELTEXT_M
WA_FIELDCAT-SELTEXT_L

'M'.
= 'Billing to'.
= 'Billing to'.
= 'Billing to'.

WHEN 'POST1'.
WA_FIELDCAT-DDICTXT =
WA_FIELDCAT-SELTEXT_S
WA_FIELDCAT-SELTEXT_M
WA_FIELDCAT-SELTEXT_L

'M'.
= 'Prjct desc'.
= 'Project desc'.
= 'Project description'.

WHEN 'AFDAT'.
WA_FIELDCAT-DDICTXT =
WA_FIELDCAT-SELTEXT_S
WA_FIELDCAT-SELTEXT_M
WA_FIELDCAT-SELTEXT_L

'M'.
= 'Billing Evt'.
= 'Billing Event'.
= 'Billing Event'.

WHEN 'CONT_NUM'.
WA_FIELDCAT-DDICTXT =
WA_FIELDCAT-SELTEXT_S
WA_FIELDCAT-SELTEXT_M
WA_FIELDCAT-SELTEXT_L

'M'.
= 'Cont Num'.
= 'Contract Number'.
= 'Contract Number'.

WHEN 'PSTYV_TEXT'.
WA_FIELDCAT-DDICTXT =
WA_FIELDCAT-SELTEXT_S
WA_FIELDCAT-SELTEXT_M
WA_FIELDCAT-SELTEXT_L

'M'.
= 'Item cat desc'.
= 'Item cat desc'.
= 'Item category description'.

WHEN 'KVGR1'.
WA_FIELDCAT-DDICTXT =
WA_FIELDCAT-SELTEXT_S
WA_FIELDCAT-SELTEXT_M
WA_FIELDCAT-SELTEXT_L

'M'.
= 'Cust inv comm'.
= 'Cust inv comm'.
= 'Customer invoice communication'.

****Start of change by srihari 21/7/2016


WHEN 'KUNNR'.
WA_FIELDCAT-DDICTXT =
WA_FIELDCAT-SELTEXT_S
WA_FIELDCAT-SELTEXT_M
WA_FIELDCAT-SELTEXT_L

'M'.
= 'Bill to Party ID '.
= 'Bill to Party ID '.
= 'Bill to Party ID '.

WHEN 'KNAME1'.
WA_FIELDCAT-DDICTXT = 'M'.
WA_FIELDCAT-SELTEXT_S = 'Name'.
WA_FIELDCAT-SELTEXT_M = 'Name'.
WA_FIELDCAT-SELTEXT_L = 'Name'.
***End of change by srihari
ENDCASE.
MODIFY IT_FIELDCAT FROM WA_FIELDCAT INDEX SY-TABIX.
ENDLOOP.
****End of changes by 097470.
ENDIF.
ENDFORM.
" BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& 07. Form OUTPUT_DISPLAY
*&---------------------------------------------------------------------*
* This form is used to display the records fetched from different
*
* tables using the function module REUSE_ALV_GRID_DISPLAY.
*
*----------------------------------------------------------------------*
FORM OUTPUT_DISPLAY .
DATA : L_REPID LIKE SY-REPID VALUE SY-REPID,
LS_LAYOUT TYPE SLIS_LAYOUT_ALV.
LS_LAYOUT-COLWIDTH_OPTIMIZE = K_X.
LS_LAYOUT-DETAIL_INITIAL_LINES = K_X.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM
= L_REPID
I_CALLBACK_PF_STATUS_SET = K_STATUS
I_CALLBACK_USER_COMMAND = K_USER_COMMAND

"'X'.
"'X'.

IS_LAYOUT
= LS_LAYOUT
IT_FIELDCAT
= IT_FIELDCAT
I_SAVE
= K_SAVELAYOUT
"'A'
TABLES
T_OUTTAB
= IT_OUTPUT
EXCEPTIONS
PROGRAM_ERROR
= 1
OTHERS
= 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
DISPLAY LIKE 'S'
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
" OUTPUT_DISPLAY
*&--------------------------------------------------------------------*
*& 08. Form set_status
*&--------------------------------------------------------------------*
*
The purpose of this form is to SET PF-STATUS for
*
*
ALV List Application Tool Bar.
*
*---------------------------------------------------------------------*
FORM SET_STATUS USING EXTAB TYPE SLIS_T_EXTAB.
DELETE EXTAB WHERE FCODE = K_SAVE.
DELETE EXTAB WHERE FCODE = K_LOAD.
DELETE EXTAB WHERE FCODE = K_ERW.
SET PF-STATUS 'ZSDR_BILLING_LIST_1' EXCLUDING EXTAB.
ENDFORM.

"'&AVE'.
"'&OAD'.
"'&ERW'.

"set_status

*&--------------------------------------------------------------------*
*& 09. Form user_command
*&--------------------------------------------------------------------*
*
The purpose of this form is to
*
*
Handle the user action at ALV List output.
*
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'DISPLAY'.
CHECK RS_SELFIELD-TABINDEX > 0.
READ TABLE IT_OUTPUT INTO WA_OUTPUT INDEX RS_SELFIELD-TABINDEX.
CALL FUNCTION 'RV_CALL_DISPLAY_TRANSACTION'
EXPORTING
VBELN = WA_OUTPUT-VBELN.
ENDCASE.
ENDFORM.

"set_status