*&---------------------------------------------------------------------*
*& Report Z_COPA_ROYALTY
*& Description : Royalty development
*&---------------------------------------------------------------------*
*&* Program Basis for royalty calculation
*&* Royalty = Loading group % in ztable for material * (Revenue from revenue gl account - Raw material cost from raw materials gl account- Imported material cost froom imp materials gl acct as in ztables) / 100
*&
*&---------------------------------------------------------------------*
REPORT z_copa_royalty.
TABLES: bsis,ckis.
*Data declarations
TYPES: BEGIN OF ty_final,
bukrs TYPE bukrs, "Company code
gjahr TYPE gjahr, "Fiscal year
monat TYPE monat, "Fiscal period
werks TYPE werks_d, "Plant
vbeln TYPE vbeln, "Billing doc
fkdat TYPE vbrk-fkdat, "billing date
matnr TYPE matnr, "Material no
maktx TYPE maktx,
mtart TYPE mtart, "Material type
hkont TYPE hkont, "GL account
revenue TYPE wrbtr, "cost of fin good
"wrbtr TYPE wrbtr, "Amount
menge TYPE menge_d, "Quantity of fin good
comp_qty TYPE menge_d, "Computed quantity
imported TYPE wrbtr, "Imported cost
rm TYPE wrbtr, "raw material cost
shkzg TYPE shkzg, "Debit/Credit indicator
kunnr TYPE kunnr, "Customer number
belnr TYPE belnr_d, "Accounting doc no
fkart TYPE fkart, "Billing type
gross TYPE wrbtr, " gross = revenue - imported - gross
field1 TYPE zladgr, "Loading group
field2 TYPE zabprc, "Loading Percentage
royalty TYPE wrbtr, "royalty = load % * grosss /100
END OF ty_final.
TYPES : BEGIN OF ty_imp,
rbukrs TYPE faglflext-rbukrs,
ryear TYPE faglflext-ryear,
monat TYPE monat,
cost_elem TYPE faglflext-cost_elem,
cost TYPE wrbtr,
END OF ty_imp.
DATA: gt_imp_cost TYPE TABLE OF ty_imp,
gs_imp_cost TYPE ty_imp.
TYPES: BEGIN OF ty_bsis,
bukrs TYPE bukrs, "Company code
belnr TYPE belnr_d,"Accounting doc no
gjahr TYPE gjahr, "Fiscal year
buzei TYPE buzei, "Line item
monat TYPE monat, "Fiscal period
hkont TYPE hkont, "GL account
END OF ty_bsis.
TYPES: BEGIN OF ty_revenue,
belnr TYPE belnr_d, "Accounting doc no
buzei TYPE buzei, "Line item
bukrs TYPE bukrs, "Company code
gjahr TYPE gjahr, "Fiscal year
wrbtr TYPE wrbtr, "Amount
shkzg TYPE shkzg, "Debit/Credit indicator
matnr TYPE matnr, "Material no
werks TYPE werks_d, "Plant
menge TYPE menge_d, "Quantity
kunnr TYPE kunnr, "Customer number
mtart TYPE mtart, "Material type
fktyp TYPE fktyp, "Billing category
awkey TYPE awkey, "Reference key
koart TYPE koart,
END OF ty_revenue.
TYPES: BEGIN OF ty_vbrk,
fkart TYPE fkart, "Billing Type
fktyp TYPE fktyp, "Billing category
END OF ty_vbrk.
TYPES: BEGIN OF ty_tab2,
matnr TYPE matnr, "Material no
werks TYPE werks_d, "Plant
kalnr TYPE ck_kalnr1, "Cost Estimate no
saknr TYPE zsaknr, "GL account
losgr TYPE ck_losgr, "Costing lot size
menge LIKE ckis-menge, "Quantity
wrtfw_kpf LIKE ckis-wrtfw_kpf, "Value in Object Currency
END OF ty_tab2.
TYPES: BEGIN OF ty_marc,
matnr TYPE matnr, "Material no
werks TYPE werks_d, "Plant
losgr TYPE ck_losgr,"Costing lot size
END OF ty_marc.
TYPES: BEGIN OF ty_comp,
matnr TYPE matnr, "Material no
werks TYPE werks_d, "Plant
kalnr TYPE ck_kalnr1, "Cost Estimate no
menge LIKE ckis-menge, "Qty
wrtfw_kpf LIKE ckis-wrtfw_kpf, "Value in object
END OF ty_comp.
TYPES: BEGIN OF ty_ledg,
drcrk TYPE shkzg, "Debit/Credit indicator
cost_elem TYPE kstar, "Cost element
rbukrs TYPE bukrs, "Company code
ryear TYPE gjahr, "Fiscal year
hsl01 TYPE hslxx12, "Total of transactions of the period
hsl02 TYPE hslxx12, "Total of transactions of the period
hsl03 TYPE hslxx12, "Total of transactions of the period
hsl04 TYPE hslxx12, "Total of transactions of the period
hsl05 TYPE hslxx12, "Total of transactions of the period
hsl06 TYPE hslxx12, "Total of transactions of the period
hsl07 TYPE hslxx12, "Total of transactions of the period
hsl08 TYPE hslxx12, "Total of transactions of the period
hsl09 TYPE hslxx12, "Total of transactions of the period
hsl10 TYPE hslxx12, "Total of transactions of the period
hsl11 TYPE hslxx12, "Total of transactions of the period
hsl12 TYPE hslxx12, "Total of transactions of the period
hsl13 TYPE hslxx12, "Total of transactions of the period
hsl14 TYPE hslxx12, "Total of transactions of the period
hsl15 TYPE hslxx12, "Total of transactions of the period
hsl16 TYPE hslxx12, "Total of transactions of the period
END OF ty_ledg.
TYPES: BEGIN OF ty_ledg1,
drcrk TYPE shkzg, "Debit/Credit indicator
cost_elem TYPE kstar, "Cost element
rbukrs TYPE bukrs, "Company code
ryear TYPE gjahr, "Fiscal year
tot_imp_cst TYPE hslxx12,"Total imported cost
END OF ty_ledg1.
TYPES:BEGIN OF ty_LDGRP,
MATNR TYPE ZFI002-MATNR,
MAKTX TYPE ZFI002-MAKTX,
LADGR TYPE ZFI001-LADGR,
ABPRC TYPE ZFI001-ABPRC,
END OF ty_LDGRP.
DATA: IT_LDGRP TYPE TABLE OF ty_ldgrp,
wa_ldgrp LIKE LINE OF it_ldgrp.
TYPES: BEGIN OF TY_MTART,
MATNR TYPE MARA-MATNR,
MTART TYPE MTART,
END OF ty_mtart.
TYPES: BEGIN OF ty_mva_price,
MATNR TYPE MARA-MATNR,
BWKEY TYPE MBEWH-BWKEY,
LFGJA TYPE MBEWH-LFGJA,
LFMON TYPE MBEWH-LFMON,
VERPR TYPE MBEWH-VERPR,
END OF ty_mva_price.
DATA: IT_RM_PRICE TYPE TABLE OF ty_mva_price,
WA_RM_PRICE TYPE ty_mva_price.
DATA lv_rm_cost TYPE BSEG-WRBTR.
DATA: IT_MTART TYPE TABLE OF TY_MTART,
WA_MTART TYPE TY_MTART.
DATA: gt_ledg TYPE STANDARD TABLE OF ty_ledg,
gs_ledg LIKE LINE OF gt_ledg,
gt_ledg1 TYPE STANDARD TABLE OF ty_ledg,
gs_ledg1 LIKE LINE OF gt_ledg1,
lv_field TYPE char200,
gt_ledg2 TYPE STANDARD TABLE OF ty_ledg,
gs_ledg2 LIKE LINE OF gt_ledg2,
gt_ledg3 TYPE STANDARD TABLE OF ty_ledg1,
gs_ledg3 LIKE LINE OF gt_ledg3,
gt_tab TYPE STANDARD TABLE OF ty_ledg,
gs_tab LIKE LINE OF gt_tab,
lv_tot_qty TYPE menge_d,
lv_tot_imp TYPE hslxx12.
*DATA: IT_FINAL TYPE STANDARD TABLE OF ty_final,
* wa_final LIKE LINE OF IT_FINAL,
DATA: IT_FINAL TYPE STANDARD TABLE OF ZFI005,
wa_final LIKE LINE OF IT_FINAL,
lv_mtart TYPE mtart.
DATA: gt_bsis TYPE STANDARD TABLE OF ty_bsis,
gs_bsis LIKE LINE OF gt_bsis,
gt_bsas TYPE STANDARD TABLE OF ty_bsis,
gs_bsas LIKE LINE OF gt_bsas,
IT_REVENUE TYPE STANDARD TABLE OF ty_revenue,
IT_KUNNR TYPE TABLE OF ty_revenue,
wa_revenue LIKE LINE OF IT_REVENUE,
gt_vbrk TYPE STANDARD TABLE OF ty_vbrk,
gs_vbrk LIKE LINE OF gt_vbrk.
DATA: gt_tab3 TYPE STANDARD TABLE OF zfi003,
gs_tab3 LIKE LINE OF gt_tab3,
gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_fieldcat LIKE LINE OF gt_fieldcat,
gt_layout TYPE slis_layout_alv,
lv_typ TYPE VBTYP.
DATA: gt_saknr TYPE RANGE OF zfi003-saknr,
gs_saknr LIKE LINE OF gt_saknr,
gt_matnr TYPE RANGE OF zfi004-matnr,
gs_matnr LIKE LINE OF gt_matnr,
gt_comp TYPE STANDARD TABLE OF stpox,
gs_comp LIKE LINE OF gt_comp.
DATA: lv_date TYPE dats,
lv_menge LIKE ckis-menge,
lv_val LIKE ckis-wrtfw_kpf,
gt_tab2 TYPE STANDARD TABLE OF ty_tab2,
gs_tab2 LIKE LINE OF gt_tab2,
gt_tab4 TYPE STANDARD TABLE OF zfi004,
gs_tab4 LIKE LINE OF gt_tab4,
it_marc TYPE STANDARD TABLE OF ty_marc,
wa_marc LIKE LINE OF it_marc,
lt_comp1 TYPE STANDARD TABLE OF stpox,
ls_comp1 LIKE LINE OF gt_comp,
lt_comp2 TYPE STANDARD TABLE OF stpox,
ls_comp2 LIKE LINE OF gt_comp.
DATA P_period type monat .
*Selection screen to enter company code, fiscal year, period.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: bukrs TYPE bukrs OBLIGATORY MATCHCODE OBJECT zbukrs,
gjahr LIKE bsis-gjahr OBLIGATORY.
PARAMETERS : monat TYPE bsis-monat.
*SELECT-OPTIONS: monat FOR bsis-monat.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
*Part I
* Computation for Revenue
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_tab3
FROM zfi003
WHERE fldgp = 'R'.
*Get Materials from fidoc/ qty billing doc as per above GL accounts
SELECT bukrs
belnr
gjahr
buzei
monat
hkont
FROM bsis
INTO TABLE gt_bsis
FOR ALL ENTRIES IN gt_tab3
WHERE hkont = gt_tab3-saknr
AND bukrs = bukrs
AND gjahr = gjahr
AND monat = monat.
SELECT bukrs
belnr
gjahr
buzei
monat
hkont
FROM bsas
APPENDING TABLE gt_bsis
FOR ALL ENTRIES IN gt_tab3
WHERE hkont = gt_tab3-saknr
AND bukrs = bukrs
AND gjahr = gjahr
AND monat = monat.
* get revenue cost and other data
SELECT belnr
buzei
bukrs
gjahr
* wrbtr
shkzg
matnr
werks
INTO CORRESPONDING FIELDS OF TABLE IT_REVENUE
FROM bseg
FOR ALL ENTRIES IN gt_bsis
WHERE belnr = gt_bsis-belnr
AND bukrs = gt_bsis-bukrs
AND gjahr = gt_bsis-gjahr
AND buzei = gt_bsis-buzei
.
DELETE ADJACENT DUPLICATES FROM gt_bsis COMPARING ALL FIELDS.
SORT IT_REVENUE ASCENDING.
SELECT MATNR
MTART
FROM MARA
INTO TABLE IT_MTART
FOR ALL ENTRIES IN IT_REVENUE
WHERE MATNR = IT_REVENUE-matnr.
** Get lot size for revenue materials
* SELECT matnr werks losgr
* FROM marc
* INTO TABLE it_marc
* FOR ALL ENTRIES IN IT_revenue
* WHERE matnr = IT_revenue-matnr
* AND werks = IT_revenue-werks.
LOOP AT gt_bsis INTO gs_bsis.
READ TABLE IT_REVENUE INTO wa_revenue WITH KEY belnr = gs_bsis-belnr
gjahr = gs_bsis-gjahr
buzei = gs_bsis-buzei
bukrs = gs_bsis-bukrs.
* Get material type
READ TABLE IT_MTART INTO WA_MTART WITH KEY matnr = wa_revenue-matnr.
wa_final-mtart = WA_MTART-mtart.
SELECT SINGLE kunnr INTO wa_final-kunnr FROM bseg WHERE belnr = gs_bsis-belnr
AND bukrs = gs_bsis-bukrs
AND gjahr = gs_bsis-gjahr
AND Koart = 'D'.
* READ TABLE IT_MARC INTO WA_MARC WITH KEY MATNR = wa_revenue-matnr
* werks = wa_revenue-werks .
* WA_FINAL-LOSGR = WA_MARC-LOSGR.
* Get billing doc
SELECT SINGLE awkey FROM bkpf INTO wa_revenue-awkey WHERE belnr = wa_revenue-belnr
AND gjahr = wa_revenue-gjahr
AND bukrs = wa_revenue-bukrs.
SELECT SINGLE fkimg FROM vbrp INTO wa_final-menge WHERE vbeln = wa_revenue-awkey+0(10).
* Get blling type
SELECT SINGLE netwr fkart fkdat FROM vbrk INTO (wa_final-revenue,gs_vbrk-fkart,wa_final-fkdat) WHERE vbeln = wa_revenue-awkey+0(10)."billing type
SELECT SINGLE vbtyp FROM tvfk INTO lv_typ WHERE fkart = gs_vbrk-fkart. " if invoice
IF lv_typ <> 'M' .
wa_final-comp_qty = 0.
ELSE.
wa_final-comp_qty = wa_final-menge.
ENDIF.
IF wa_final-mtart <> 'FERT'.
wa_final-comp_qty = 0.
ELSE.
wa_final-comp_qty = wa_final-menge.
ENDIF.
wa_final-bukrs = gs_bsis-bukrs.
wa_final-belnr = gs_bsis-belnr.
wa_final-gjahr = gs_bsis-gjahr.
* wa_final-buzei = gs_bsis-buzei.
wa_final-monat = gs_bsis-monat.
wa_final-hkont = gs_bsis-hkont.
wa_final-shkzg = wa_revenue-shkzg.
wa_final-matnr = wa_revenue-matnr.
wa_final-werks = wa_revenue-werks.
wa_final-vbeln = wa_revenue-awkey+0(10).
** IF wa_revenue-shkzg = 'H'.
* wa_final-revenue = wa_final-revenue * -1.
**
** ENDIF.
wa_final-fkart = gs_vbrk-fkart.
lv_tot_qty = lv_tot_qty + wa_final-comp_qty.
APPEND wa_final TO IT_FINAL.
CLEAR: wa_final,wa_revenue.
ENDLOOP.
* End of Part I
*Part II - Computation of zinc and Aluminium cost
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_tab3
FROM zfi003
WHERE fldgp = 'M'.
LOOP AT gt_tab3 INTO gs_tab3.
gs_saknr-sign = 'I'.
gs_saknr-option = 'EQ'.
gs_saknr-low = gs_tab3-saknr.
APPEND gs_saknr TO gt_saknr.
ENDLOOP.
SELECT *
FROM zfi004
INTO TABLE gt_tab4.
LOOP AT gt_tab4 INTO gs_tab4.
gs_matnr-sign = 'I'.
gs_matnr-option = 'EQ'.
gs_matnr-low = gs_tab4-matnr.
APPEND gs_matnr TO gt_matnr.
ENDLOOP.
* Calculate raw material cost for each finished material as per period
* Get components for all materials
LOOP AT IT_FINAL INTO wa_final.
REFRESH : GT_COMP[] , IT_RM_PRICE.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01'
DATUV = sy-datum
EMENG = wa_final-comp_qty
MKTLS = 'X'
MTNRV = wa_final-matnr
STPST = 0
SVWVO = 'X'
WERKS = wa_final-werks
VRSVO = 'X'
MEHRS = 'X'
TABLES
stb = gt_comp
EXCEPTIONS
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
CONVERSION_ERROR = 8
OTHERS = 9
.
IF sy-subrc EQ 0.
* Calculate total of qty & value of components
* APPEND LINES OF lt_comp1 to gt_comp.
DELETE gt_comp WHERE idnrk not in gt_matnr.
if gt_comp is NOT INITIAL.
* select moving average price for fetched components
SELECT MATNR
BWKEY
LFGJA
LFMON
VERPR
FROM MBEWH
INTO TABLE IT_RM_PRICE
FOR ALL ENTRIES IN GT_COMP
WHERE MATNR = gt_comp-idnrk
AND BWKEY = gt_comp-werks
AND LFGJA = gjahr
AND LFMON = monat .
SORT IT_RM_PRICE BY MATNR BWKEY LFGJA LFMON.
* Raw Material Cost
LOOP AT gt_comp INTO gs_comp .
READ TABLE IT_RM_PRICE INTO WA_RM_PRICE WITH KEY MATNR = gs_comp-idnrk
BWKEY = gs_comp-werks
LFGJA = wa_final-gjahr
LFMON = wa_final-monat BINARY SEARCH.
lv_rm_cost = lv_rm_cost + ( ( gs_comp-mnglg * WA_RM_PRICE-VERPR ) )."/ wa_final-losgr ).
wa_final-maktx = gs_comp-OJTXB.
ENDLOOP.
wa_final-rm = lv_rm_cost.
MODIFY IT_FINAL FROM WA_FINAL.
clear : lv_rm_cost, wa_final.
endif.
ENDIF.
ENDLOOP.
*rev --> Fin Mat qty from billing doc & Value
* RM cost --> comp cost * Fin Mat qty --> Component qty* mbewh price = comp cost
* im cost ->
* End of part II
* Computation of imported material cost
SELECT *
FROM zfi003
INTO TABLE gt_tab3
WHERE fldgp = 'IM'.
SELECT COST_ELEM
RBUKRS
RYEAR
DRCRK
HSL01
HSL02
HSL03
HSL04
HSL05
HSL06
HSL07
HSL08
HSL09
HSL10
HSL11
HSL12
HSL13
HSL14
HSL15
HSL16
FROM faglflext
INTO CORRESPONDING FIELDS OF TABLE gt_ledg
FOR ALL ENTRIES IN gt_tab3
WHERE cost_elem = gt_tab3-saknr
AND rbukrs = bukrs
AND ryear = gjahr.
P_period = monat.
*WHILE p_period IN monat .
LOOP AT gt_ledg INTO gs_ledg .
* if gs_ledg-drcrk = 'H'.
* gs_ledg-hsl01 = gs_ledg-hsl01 * -1.
* gs_ledg-hsl02 = gs_ledg-hsl02 * -1.
* gs_ledg-hsl03 = gs_ledg-hsl03 * -1.
* gs_ledg-hsl04 = gs_ledg-hsl04 * -1.
* gs_ledg-hsl05 = gs_ledg-hsl05 * -1.
* gs_ledg-hsl06 = gs_ledg-hsl06 * -1.
* gs_ledg-hsl07 = gs_ledg-hsl07 * -1.
* gs_ledg-hsl08 = gs_ledg-hsl08 * -1.
* gs_ledg-hsl09 = gs_ledg-hsl09 * -1.
* gs_ledg-hsl10 = gs_ledg-hsl10 * -1.
* gs_ledg-hsl11 = gs_ledg-hsl11 * -1.
* gs_ledg-hsl12 = gs_ledg-hsl12 * -1.
* gs_ledg-hsl13 = gs_ledg-hsl13 * -1.
* gs_ledg-hsl14 = gs_ledg-hsl14 * -1.
* gs_ledg-hsl15 = gs_ledg-hsl15 * -1.
* gs_ledg-hsl16 = gs_ledg-hsl16 * -1.
*
* endif.
gs_imp_cost-ryear = gs_ledg-ryear.
gs_imp_cost-rbukrs = gs_ledg-rbukrs.
* gs_imp_cost-cost_elem = gs_ledg-cost_elem.
gs_imp_cost-monat = p_period.
CASE p_period.
WHEN '01'.
gs_imp_cost-cost = gs_ledg-hsl01 .
WHEN '02'.
gs_imp_cost-cost = gs_ledg-hsl02 .
WHEN '03'.
gs_imp_cost-cost = gs_ledg-hsl03 .
WHEN '04'.
gs_imp_cost-cost = gs_ledg-hsl04 .
WHEN '05'.
gs_imp_cost-cost = gs_ledg-hsl05 .
WHEN '06'.
gs_imp_cost-cost = gs_ledg-hsl06 .
WHEN '07'.
gs_imp_cost-cost = gs_ledg-hsl07 .
WHEN '08'.
gs_imp_cost-cost = gs_ledg-hsl08.
WHEN '09'.
gs_imp_cost-cost = gs_ledg-hsl09.
WHEN '10'.
gs_imp_cost-cost = gs_ledg-hsl10 .
WHEN '11'.
gs_imp_cost-cost = gs_ledg-hsl11 .
WHEN '12'.
gs_imp_cost-cost = gs_ledg-hsl12 + gs_ledg-hsl13 + gs_ledg-hsl14 + gs_ledg-hsl15 + gs_ledg-hsl16 .
ENDCASE.
COLLECT gs_imp_cost INTO gt_imp_cost.
CLEAR gs_imp_cost.
ENDLOOP.
* ADD 1 to p_period.
*ENDWHILE.
SELECT
ZFI002~MATNR
ZFI002~MAKTX
ZFI001~LADGR
ZFI001~ABPRC
INTO TABLE IT_LDGRP
FROM ZFI001
INNER JOIN ZFI002 on zfi001~LADGR = zfi002~ladgr
FOR ALL ENTRIES IN IT_FINAL
WHERE zfi002~matnr = it_final-matnr.
LOOP AT IT_FINAL INTO wa_final.
READ TABLE GT_IMP_COST INTO GS_IMP_COST WITH KEY RBUKRs = WA_FINAL-BUKRS
RYEAR = WA_FINAL-GJAHR
monat = WA_FINAL-monat.
if lv_tot_qty NE 0.
wa_final-imported = ( GS_IMP_COST-COST * wa_final-comp_qty ) / lv_tot_qty.
endif.
wa_final-gross = wa_final-revenue - wa_final-rm - wa_final-imported.
READ TABLE IT_LDGRP INTO WA_LDGRP WITH KEY MATNR = WA_FINAL-MATNR.
* wa_final-maktx = WA_LDGRP-MAKTX.
wa_final-royalty = wa_final-gross * WA_LDGRP-abprc / 100.
wa_final-field1 = WA_LDGRP-abprc.
wa_final-field2 = WA_LDGRP-ladgr.
MODIFY IT_FINAL FROM wa_final.
CLEAR: WA_LDGRP ,GS_IMP_COST.
ENDLOOP.
IF IT_FINAL IS NOT INITIAL.
MODIFY ZFI005 FROM TABLE IT_FINAL.
endif.
PERFORM field_cat.
PERFORM field_layout.
PERFORM build_alv.
*&---------------------------------------------------------------------*
*& Form FIELD_CAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM field_cat .
gs_fieldcat-fieldname = 'BUKRS'.
gs_fieldcat-seltext_m = 'Company Code'.
gs_fieldcat-col_pos = 1.
* gs_fieldcat-outputlen = 12.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'GJAHR'.
gs_fieldcat-seltext_m = 'Fiscal year'.
gs_fieldcat-col_pos = 2.
* gs_fieldcat-outputlen = 6.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'MONAT'.
gs_fieldcat-seltext_m = 'Period'.
gs_fieldcat-col_pos = 3.
* gs_fieldcat-outputlen = 6.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'VBELN'.
gs_fieldcat-seltext_m = 'Billing Doc No'.
gs_fieldcat-col_pos = 4.
* gs_fieldcat-outputlen = 18.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'FKDAT'.
gs_fieldcat-seltext_m = 'Billing Date'.
gs_fieldcat-col_pos = 5.
* gs_fieldcat-outputlen = 18.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
* gs_fieldcat-fieldname = 'WRBTR'.
* gs_fieldcat-seltext_m = 'Value'.
* gs_fieldcat-col_pos = 6.
* gs_fieldcat-outputlen = 17.
* APPEND gs_fieldcat TO gt_fieldcat.
* CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'MATNR'.
gs_fieldcat-seltext_m = 'Material no'.
gs_fieldcat-col_pos = 7.
* gs_fieldcat-outputlen = 18.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'MAKTX'.
gs_fieldcat-seltext_m = 'Material'.
gs_fieldcat-col_pos = 8.
* gs_fieldcat-outputlen = 18.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'WERKS'.
gs_fieldcat-seltext_m = 'Plant'.
gs_fieldcat-col_pos = 9.
* gs_fieldcat-outputlen = 5.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'MENGE'.
gs_fieldcat-seltext_m = 'Qty'.
gs_fieldcat-col_pos = 10.
* gs_fieldcat-outputlen = 5.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'KUNNR'.
gs_fieldcat-seltext_m = 'Customer'.
gs_fieldcat-col_pos = 11.
* gs_fieldcat-outputlen = 10.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'MTART'.
gs_fieldcat-seltext_m = 'Mat type'.
gs_fieldcat-col_pos = 12.
* gs_fieldcat-outputlen = 10.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'FKART'.
gs_fieldcat-seltext_m = 'Bill typ'.
gs_fieldcat-col_pos = 13.
* gs_fieldcat-outputlen = 8.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'COMP_QTY'.
gs_fieldcat-seltext_m = 'Computed quantity '.
gs_fieldcat-col_pos = 14.
* gs_fieldcat-outputlen = 5.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'REVENUE'.
gs_fieldcat-seltext_m = 'REVENUE'.
gs_fieldcat-col_pos = 15.
* gs_fieldcat-outputlen = 17.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'IMPORTED'.
gs_fieldcat-seltext_m = 'Import cost'.
gs_fieldcat-col_pos = 16.
* gs_fieldcat-outputlen = 17.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'RM'.
gs_fieldcat-seltext_m = 'Raw Material Cost'.
gs_fieldcat-col_pos = 17.
* gs_fieldcat-outputlen = 17.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'FIELD1'.
gs_fieldcat-seltext_m = 'Load%'.
gs_fieldcat-col_pos = 18.
* gs_fieldcat-outputlen = 5.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'FIELD2'.
gs_fieldcat-seltext_m = 'Load grp'.
gs_fieldcat-col_pos = 19.
* gs_fieldcat-outputlen = 8.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'GROSS'.
gs_fieldcat-seltext_m = 'GROSS'.
gs_fieldcat-col_pos = 20.
* gs_fieldcat-outputlen = 17.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = 'ROYALTY'.
gs_fieldcat-seltext_m = 'ROYALTY'.
gs_fieldcat-col_pos = 21.
* gs_fieldcat-outputlen = 17.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
ENDFORM. " FIELD_CAT
*&---------------------------------------------------------------------*
*& Form FIELD_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM field_layout .
gt_layout-no_input = 'X'.
gt_layout-colwidth_optimize = 'X'.
ENDFORM. " FIELD_LAYOUT
*&---------------------------------------------------------------------*
*& Form BUILD_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_alv .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = gt_layout
it_fieldcat = gt_fieldcat
TABLES
t_outtab = IT_FINAL
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " BUILD_ALV