ALV another usage - Modified Report ZRSD0018

来源:互联网 发布:单片机的最小系统除了 编辑:程序博客网 时间:2024/05/18 14:14
*&---------------------------------------------------------------------*
*& Company ASAT Company Limited                                        *
*&                                                                     *
*& Report: ZRFI0018                                                    *
*&                                                                     *
*& Autor : Danny Yip                                                   *
*&                                                                     *
*& Date : 05.07.2004                                                  *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Description:                                                        *
*&                                                                     *
*&   This report is to list the billed sales orders grouped by         *
*& different dimensions (e.g. package, customer, device).              *
*&                                                                     *
*&---------------------------------------------------------------------*
*& Change History:                                                     *
*&                                                                     *
*& Ref Date       By        Description                               *
*& 000 05.07.2004 DANN_YIP Initial Implementation                    *
*&                           Transport Request : DEVK901784            *
*&                                                                     *
*& 001 30.07.2004 DANN_YIP Should show reversed & reversing bill.doc *
*&                           with negative values reversing bill.doc   *
*&                           Transport Request : DEVK901992            *
*&                                                                     *
*& 002 02.08.2004 DANN_YIP Should show reversed & reversing bill.doc *
*&                           with negative values reversing bill.doc   *
*&                           Transport Request : DEVK901996            *
*&                                                                     *
*& 003 02.09.2004 DANN_YIP 1. Include Nationality and Region         *
*&                           2. Add Assembly Lead-Count & Test Lead-   *
*&                              Count columns                          *
*&                           3. Negative Assm & Test LC for reversing *
*&                              billing doc                            *
*&                           Transport Request : DEVK902195            *
*&                                                                     *
*& 004 13.06.2005 DANN_YIP 1. Cater item# changed in billing doc     *
*&                           2. Breakdown sales conditions             *
*&                           Transport Request : DEVK906587            *
*&                                                                     *
*& 005 16.06.2005 DANN_YIP 1. Add criteria 'bill.doc.type'           *
*&                           2. Add markdown column                    *
*&                           Transport Request : DEVK906788            *
*&                                                                     *
*& 006 28.07.2005 DANN_YIP 1. Add sales org. field                   *
*&                           Transport Request : DEVK908485            *
*&                                                                     *
*& 007 15.08.2005 DANN_YIP 1. Add new cond.types                     *
*&                           2. Fix unit price calculation             *
*&                           3. Add unclassified column for monitoring *
*&                              new cond.types in future               *
*&                           Transport Request : DEVK909959            *
*&                                                                     *
*& 008 17.08.2005 DANN_YIP 1. Fix MKDN cond.type                     *
*&                           2. Change unit price to 3 d.p.            *
*&                           Transport Request : DEVK910173            *
*&                                                                     *
*& 009 25.08.2005 DANN_YIP 1. Get sold-to                            *
*&                           2. Add cancelled billing doc indicator    *
*&                           Transport Request : DEVK910776            *
*&                                                                     *
*& 010 03.09.2005 DANN_YIP 1. Add pro-forma invoice                  *
*&                           Transport Request : DEVK911627            *
*&                                               DEVK911631            *
*&                                                                     *
*& 011 06.09.2005 DANN_YIP Fix markdown sign for credit memo         *
*&                           Transport Request : DEVK911807            *
*&                                                                     *
*& 012 20.09.2005 DANN_YIP 1. Add assembly qty                       *
*&                           2. Change unit price to 5 d.p.            *
*&                           Transport Request : DEVK912276            *
*&                                                                     *
*& 013 27.09.2005 DANN_YIP 1. Add 2 more columns for multiple test   *
*&                              unit price                             *
*&                           Transport Request : DEVK912550            *
*&                                                                     *
*& 014 07.10.2005 CATH_WONG 1. Correct error for checking GT_LINE     *
*&                           TR: DEVK913069                            *
*& 015 07.10.2005 CATH_WONG 1. change condition type DPBG & DPUT from *
*&                           test added to Assy Adder                  *
*&                           TR: DEVK913090                            *
*& 016 21.11.2005 CATH_WONG 1. add PROB & LTRM to test adder and SAW *
*&                           to assy other                             *
*&                           TR: DEVK914274                            *
*& 017 04.07.2006 JASO_DING Add 11 colume ASSL ASSX ENGG EXTW GSAW HOTA
*&                           HOTT MINA MINB MINT QATD                  *
*&                           TR: DEVK919479                            *
*& 018 02.01.2007 Wats_yuan Task# 961:
*&                      1)the extra wire unit price with title “EXTW”,*
*&                      2)the market gold price with title “MKTG”,     *
*&                      3)the gold base price with title “GOLD”        *
*&                      4)the number of extra wires (D in Fig.2) with *
*&                        title “Number of Extra Wires”                *
*&                                                  "DEVK921611        *
*&#940 12/30/2006 Leo Lee   Add a column with header ‘Pkg Group (CO)’ to
*                       DEVK921639 show the device package group
*
* ======================================================================
* Last Modified By:    Wei_Zhu
* Last Modified Date: 2007-02-01
* Modifed Description: 1)For each record retrieved in the report,
*                        add the marketing information per the relevant
*                        device
*                       2)Display the result from item 1 under a new
*                         column titled ‘Marketing Segment’
*                        Task#1016   request#DEVK921978
*&---------------------------------------------------------------------*
report zrfi0018.
 
type-pools: slis.                            "ALV Type Pool
 
tables: mara,                                "Material Master
        kna1,                                "Customer Master
*{ Modification 003
*    Add nationality and region
        adrc,                                "Address table
*} Modification 003
        vbap,                                "Sales Order Line
        vbrk,                                "Billing Doc Header
        vbrp,                                "Billing Doc Item
       rmclm,                               "Classification
        tkchw.                                              "DEVK921598
 
 
*----------------------------------------------------------------------*
* Global Data Declaration                                             *
*----------------------------------------------------------------------*
 
* Global variables for ALV use
data: g_repid like sy-repid,                 "Report Name
      g_save(1) type c,                      "Save Variants
      gx_variant like disvariant,            "Layout Variant
      g_variant like disvariant,             "Layout Variant
      gt_fieldcat type lvc_t_fcat,           "Table Field Catalog
      gt_fieldcata type slis_t_fieldcat_alv, "ALV Field Catalog
      gt_top_of_page type slis_t_listheader. "ALV Top-of-page
 
* Line item table to be put on ALV output
data: begin of gt_line occurs 0,
*{ Modification 005
*    Add bill.doc.type
        fkart like vbrk-fkart,             "Bill.Doc.Type
*} Modification 005
*{ Modification 006
*    Add sales org.
        vkorg like vbrk-vkorg,             "Sales Org.
*} Modification 006
        fkdat like vbrk-fkdat,             "Bill.Date
        knumv like vbrk-knumv,             "Condition Doc#
        rfbsk like vbrk-rfbsk,             "BD Posting Status
*{ Modification 002
*    To identify which line is of negative value (cancel / credit memo)
        vbtyp like vbrk-vbtyp,             "BD Doc Category
*} Modification 002
*{ Modification 009
*    To add cancelled doc indicator
        fksto like vbrk-fksto,             "Cancelled doc
*} Modification 009
        vbeln like vbrp-vbeln,             "BD Doc#
        posnr like vbrp-posnr,             "BD Item#
        matnr like vbrp-matnr,             "Material#
        aubel like vbrp-aubel,             "SO Doc#
        aupos like vbrp-aupos,             "SO Item#
        fkimg like vbrp-fkimg,             "Bill.Qty
        vrkme like vbrp-vrkme,             "Bill.Qty.UOM
        pstyv like vbrp-pstyv,             "Item Category
        vgbel like vbrp-vgbel,             "Delivery Doc#
        vgpos like vbrp-vgpos,             "Delivery Doc Item#
        vgtyp like vbrp-vgtyp,             "Reference Doc.Type
        kunnr like vbpa-kunnr,             "Customer#
        kdmat like vbap-kdmat,             "Customer PO#
        kwmeng like vbap-kwmeng,            "SO.Qty
        zmeng like vbap-zmeng,             "Target Qty
        aurkm like vbap-vrkme,             "SO.Qty.UOM
*{ Modification 009
*    To cater for sales org 3100 model
        vbpap like vbpa-posnr,             "Partner item#
*} Modification 009
       zzatoat like vbap-zzatoat,
       zzattoa like vbap-zzattoa,
       parnt(30),                                           "DEVK921598
      end   of gt_line.
 
* Customer name table
data: begin of gt_kna1 occurs 0,
        kunnr like kna1-kunnr,              "Customer#
        name1 like kna1-name1,              "Customer Name
*{ Modification 003
*    Add nationality and region
        adrnr like kna1-adrnr,              "Address#
        bran1 like kna1-bran1,                              "Region 1
        bran2 like kna1-bran2,                              "Region 2
        bran3 like kna1-bran3,                              "Region 3
        regiogroup like adrc-regiogroup,    "Nationality
*} Modification 003
      end   of gt_kna1.
 
* Material description table
data: begin of gt_makt occurs 0,
        matnr like makt-matnr,              "Material#
        spras like makt-spras,              "Language
        maktx like makt-maktx,              "Material Description
* DEVK921978 BEGIN
        extwg like mara-extwg,
*   DEVK921978 END
      end   of gt_makt.
 
* Material classification table
data: begin of gt_matclass occurs 0,
        matnr like mchb-matnr,              "Material
        class like klah-class,              "Package
        atnam like cabn-atnam,              "Characteristics Name
        ausp1 like ausp-atwrt,              "Characteristics Text Value
        atflv like ausp-atflv,              "Characteristics Num Value
      end   of gt_matclass.
 
* Characteristics-ALV_fieldname relationship table
data: begin of gt_char occurs 0,
        atnam like cabn-atnam,              "Characteristics Name
        itype like lvc_s_fcat-inttype,      "ALV Field Type
        field like lvc_s_fcat-fieldname,    "ALV Field Name
      end   of gt_char.
 
* Billing condition table
data: begin of gt_konv occurs 0,
        knumv like konv-knumv,              "Condition Doc#
        kposn like konv-kposn,              "Condition Item#
        stunr like konv-stunr,              "Condition Step#
        zaehk like konv-zaehk,              "Condition Counter
        kschl like konv-kschl,              "Condition Type
*{ Modification 004
*    Add condition rate & base
        kbetr like konv-kbetr,              "Condition Rate
        kawrt like konv-kawrt,              "Condition Base
*} Modification 004
*{ Modification 007
*    Fix unit price calculation
        kpein like konv-kpein,              "Condition Price Unit
*} Modification 007
        kwert like konv-kwert,              "Condition Amount
      end   of gt_konv.
 
* Sales Order header table
data: begin of gt_vbak occurs 0,
        aubel like vbak-vbeln,              "SO Doc#
        bstnk like vbak-bstnk,              "Customer PO Number
      end   of gt_vbak.
 
* Sales Order status table
data: begin of gt_vbup occurs 0,
        aubel like vbup-vbeln,              "SO Doc#
        aupos like vbup-posnr,              "SO Item#
        gbsta like vbup-gbsta,              "Overal Status
      end   of gt_vbup.
 
* Sales Order item related invoice table
data: begin of gt_vbfa occurs 0,
        aubel   like vbfa-vbelv,            "SO Doc#
        aupos   like vbfa-posnv,            "SO Item#
        vbeln   like vbfa-vbeln,            "Follow-up Doc#
        posnn   like vbfa-posnn,            "Follow-up Item#
        vbtyp_n like vbfa-vbtyp_n,          "Invoice Type
        rfmng   like vbfa-rfmng,            "Billed Quantity
        meins   like vbfa-meins,            "Billed Quantity UOM
      end   of gt_vbfa.
 
*{ Modification 010
*    Get pro-forma invoice
* Delivery item related pro-forma invoice table
data: begin of gt_pfiv occurs 0,
        vgbel like vbrp-vgbel,              "Delivery Doc#
        vgpos like vbrp-vgpos,              "Delivery Item#
        vbeln like vbrp-vbeln,              "Pro-forma Inv#
      end   of gt_pfiv.
*} Modification 010
 
 
* Hierarchy table              "DEVK921598
data: begin of gt_tkchw occurs 0,
        nodid like tkchw-nodid,              "Node ID
        parnt like tkchw-parnt,              "Parent Node ID
        wert1 like tkchw-wert1,              "Description
      end of gt_tkchw.
 
 
* ALV output data table
field-symbols: <gt_out> type standard table. "ALV Data Table
 
 
*----------------------------------------------------------------------*
* Constants                                                           *
*----------------------------------------------------------------------*
constants: c_matcltype like klah-klart     value '001', "Package ClType
*{ Modification 009
*    Sales Org 3100 model
           c_asat      like kna1-kunnr     value '0000010000', "CustASAT
*} Modification 009
*{ Modification 003
*    To give negative values on lead-count
           c_lead      like cabn-atnam     value 'LEAD', "Char:LeadCount
*} Modification 003
           c_soitmobj like thead-tdobject value 'VBBK', "Txt ObjCode
           c_id_mawb   like thead-tdid     value 'Z002', "MAWB Text ID
           c_id_hawb   like thead-tdid     value 'Z003', "HAWB Text ID
           c_id_flight like thead-tdid     value 'Z004'. "Flight Text ID
 
 
*----------------------------------------------------------------------*
* Selection Screen                                                    *
*----------------------------------------------------------------------*
selection-screen begin of block a with frame title text-s10.
* Selection Criteria
*{ Modification 005
select-options: so_fkart for vbrk-fkart.
*} Modification 005
select-options: so_kunnr for kna1-kunnr.
*{ Modification 006
*    Add sales org.
*PARAMETERS:     P_BUKRS LIKE VBAK-BUKRS_VF OBLIGATORY.
select-options: so_vkorg for vbrk-vkorg.
*} Modification 006
select-options: so_fkdat for vbrk-fkdat no-extension,
                so_aubel for vbrp-aubel,
                so_vbeln for vbrp-vbeln,
                so_matnr for mara-matnr,
                so_kdmat for vbap-kdmat,
*{ Modification 003
*    Add nationality and region
*                SO_CLASS FOR RMCLM-CLASS.
                so_class for rmclm-class,
                so_natio for adrc-regiogroup,
                so_regio for kna1-bran1.
*} Modification 003
selection-screen end of block a.
* Variant
selection-screen begin of block b with frame title text-s20.
parameters: p_vari like disvariant-variant.
selection-screen end of block b.
 
* Process on value request
at selection-screen on value-request for p_vari.
 perform f4_for_variant.
 
* PAI
at selection-screen on p_vari.
 perform validate_variant.
 
 
*----------------------------------------------------------------------*
* Initialization                                                      *
*----------------------------------------------------------------------*
initialization.
 
* Set report program name
 g_repid = sy-repid.
* Set Options: Save variants user-specific or general
 g_save = 'A'.
* Initialize variant
 perform variant_init.
* Get default values
 perform get_default.
 
 
*----------------------------------------------------------------------*
* Start of Selection                                                  *
*----------------------------------------------------------------------*
start-of-selection.
 
* Select records from DB
 perform select_records.
 
*----------------------------------------------------------------------*
* End of Selection                                                    *
*----------------------------------------------------------------------*
end-of-selection.
 
* Construct field catalog for ALV display and ALV data table
 perform build_fieldcat.
* Generate ALV data table
 perform generate_out_table.
* Fill ALV data table
 perform fill_out_table.
**016
 perform sum_gtout.
* Set top-of-page content
 perform set_top_of_page.
* Display report
 perform alv_output.
 
 
*----------------------------------------------------------------------*
* Subroutines                                                         *
*----------------------------------------------------------------------*
 
 
*&---------------------------------------------------------------------*
*&      Form F4_FOR_VARIANT
*&---------------------------------------------------------------------*
*       Value request for variant
*----------------------------------------------------------------------*
form f4_for_variant.
 
 data: l_exit(1) type c.               "Exit Code
 
 call function 'REUSE_ALV_VARIANT_F4'
    exporting
      is_variant = g_variant
      i_save     = g_save
    importing
      e_exit     = l_exit
      es_variant = gx_variant
    exceptions
      not_found = 2.
 if sy-subrc = 2.
    message id sy-msgid type 'S' number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
 else.
    if l_exit = space.
      p_vari = gx_variant-variant.
    endif.
 endif.
 
endform.                    " F4_FOR_VARIANT
 
*&---------------------------------------------------------------------*
*&      Form VALIDATE_VARIANT
*&---------------------------------------------------------------------*
*       Validate the existence of input variant
*----------------------------------------------------------------------*
form validate_variant.
 
 if not p_vari is initial.
    move g_variant to gx_variant.
    move p_vari to gx_variant-variant.
    call function 'REUSE_ALV_VARIANT_EXISTENCE'
      exporting
        i_save     = g_save
      changing
        cs_variant = gx_variant.
    g_variant = gx_variant.
 else.
    perform variant_init.
 endif.
 
endform.                    " VALIDATE_VARIANT
 
*&---------------------------------------------------------------------*
*&      Form VARIANT_INIT
*&---------------------------------------------------------------------*
*       Variant Initialization
*----------------------------------------------------------------------*
form variant_init.
 
 clear g_variant.
 g_variant-report = g_repid.
 
endform.                    " VARIANT_INIT
 
*&---------------------------------------------------------------------*
*&      Form GET_DEFAULT
*&---------------------------------------------------------------------*
*       Assign default values on selection screen
*----------------------------------------------------------------------*
form get_default.
 
* Get default variant
 gx_variant = g_variant.
 call function 'REUSE_ALV_VARIANT_DEFAULT_GET'
    exporting
      i_save     = g_save
    changing
      cs_variant = gx_variant
    exceptions
      not_found = 2.
 if sy-subrc = 0.
    p_vari = gx_variant-variant.
 endif.
 
endform.                    " GET_DEFAULT
 
*&---------------------------------------------------------------------*
*&      Form SET_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       Set Top-of-page Content
*----------------------------------------------------------------------*
form set_top_of_page .
 
 data: ls_line type slis_listheader,
        l_lines type i,
        l_text1(30) type c,
        l_text2(30) type c.
 
* Macro: _APPEND_SELECT_OPTIONS
*          &1 - Selection Criteria Text
*          &2 - Select-Option Variable
 define _append_select_options.
    ls_line-key = &1.
    read table &2 index 1.
    if &2-high is initial.
      write &2-low to l_text1.
      ls_line-info = l_text1.
    else.
      write: &2-low to l_text1,
             &2-high to l_text2.
      concatenate l_text1 '-' l_text2 into ls_line-info
                  separated by space.
    endif.
    describe table &2 lines l_lines.
    if l_lines > 1.
      concatenate ls_line-info ', ...' into ls_line-info.
    endif.
    append ls_line to gt_top_of_page.
 end-of-definition.
 
* Header
 clear ls_line.
 ls_line-typ = 'H'.
 ls_line-info = sy-title.
 append ls_line to gt_top_of_page.
 
* Selection Criteria List
 clear ls_line.
 ls_line-typ = 'S'.
 
* Customer Number
 if not ( so_kunnr is initial ).
    _append_select_options text-101 so_kunnr.
 endif.
*{ Modification 006
*    Add sales org.
** Company Code
* LS_LINE-KEY = TEXT-102.
* LS_LINE-INFO = P_BUKRS.
* APPEND LS_LINE TO GT_TOP_OF_PAGE.
* Sales Org.
 if not ( so_vkorg is initial ).
    _append_select_options text-102 so_vkorg.
 endif.
*} Modification 006
* Billing Date Range
 if not ( so_fkdat is initial ).
    _append_select_options text-103 so_fkdat.
 endif.
* Sales Order
 if not ( so_aubel is initial ).
    _append_select_options text-104 so_aubel.
 endif.
* Billing Document
 if not ( so_vbeln is initial ).
    _append_select_options text-105 so_vbeln.
 endif.
* Material Number
 if not ( so_matnr is initial ).
    _append_select_options text-106 so_matnr.
 endif.
* Material Number
 if not ( so_kdmat is initial ).
    _append_select_options text-107 so_kdmat.
 endif.
* Package
 if not ( so_class is initial ).
    _append_select_options text-108 so_class.
 endif.
 
endform.                    " SET_TOP_OF_PAGE
 
*&---------------------------------------------------------------------*
*&      Form SELECT_RECORDS
*&---------------------------------------------------------------------*
*       Select records from DB
*----------------------------------------------------------------------*
form select_records.
 
 data: l_subrc like sy-subrc.
 
* Get billing documents under sales criteria
*{ Modification 006
*    Add sales org.
*{ Modification 005
*    Add billing doc. type to selection
**{ Modification 001 & 002
**    To identify which line is of negative value (return / cancelling)
**    and to retrieve cancelling and cancelled billing docs also
** SELECT A~FKDAT A~KNUMV A~RFBSK B~VBELN B~POSNR B~MATNR B~AUBEL
**         B~AUPOS B~FKIMG B~VRKME B~PSTYV B~VGBEL B~VGTYP C~KUNNR
**         D~KDMAT D~KWMENG D~ZMENG D~VRKME AS AURKM
**    INTO CORRESPONDING FIELDS OF TABLE GT_LINE
**    FROM VBRK AS A
**      INNER JOIN VBRP AS B ON A~VBELN = B~VBELN
**      INNER JOIN VBPA AS C ON B~AUBEL = C~VBELN
**      INNER JOIN VBAP AS D ON B~AUBEL = D~VBELN AND B~AUPOS = D~POSNR
**    WHERE A~BUKRS = P_BUKRS    "Company Code
**      AND A~FKDAT IN SO_FKDAT "Billing Date
**      AND B~VBELN IN SO_VBELN "Billing Doc#
**      AND B~AUBEL IN SO_AUBEL "Sales Order#
**      AND B~MATNR IN SO_MATNR "Material#
**      AND C~PARVW = 'RE'       "Party Type = Bill-to
**      AND C~KUNNR IN SO_KUNNR "Customer#
**      AND D~KDMAT IN SO_KDMAT "Customer Material#
**    ORDER BY B~VBELN B~POSNR.
* SELECT A~FKDAT A~KNUMV A~RFBSK A~VBTYP B~VBELN B~POSNR B~MATNR
*         B~AUBEL B~AUPOS B~FKIMG B~VRKME B~PSTYV B~VGBEL B~VGTYP
*         C~KUNNR D~KDMAT D~KWMENG D~ZMENG D~VRKME AS AURKM
*    INTO CORRESPONDING FIELDS OF TABLE GT_LINE
*    FROM VBRK AS A
*      INNER JOIN VBRP AS B ON A~VBELN = B~VBELN
*      INNER JOIN VBPA AS C ON B~AUBEL = C~VBELN
*      INNER JOIN VBAP AS D ON B~AUBEL = D~VBELN AND B~AUPOS = D~POSNR
*    WHERE A~BUKRS = P_BUKRS    "Company Code
*      AND A~BUKRS = P_BUKRS    "Company Code
*      AND A~FKDAT IN SO_FKDAT "Billing Date
*      AND B~VBELN IN SO_VBELN "Billing Doc#
*      AND B~AUBEL IN SO_AUBEL "Sales Order#
*      AND B~MATNR IN SO_MATNR "Material#
*      AND C~PARVW = 'RE'       "Party Type = Bill-to
*      AND C~KUNNR IN SO_KUNNR "Customer#
*      AND D~KDMAT IN SO_KDMAT "Customer Material#
*    ORDER BY B~VBELN B~POSNR.
**} Modification 001 & 002
* SELECT A~FKART A~FKDAT A~KNUMV A~RFBSK A~VBTYP B~VBELN B~POSNR
*         B~MATNR B~AUBEL B~AUPOS B~FKIMG B~VRKME B~PSTYV B~VGBEL
*         B~VGTYP C~KUNNR D~KDMAT D~KWMENG D~ZMENG D~VRKME AS AURKM
*    INTO CORRESPONDING FIELDS OF TABLE GT_LINE
*    FROM VBRK AS A
*      INNER JOIN VBRP AS B ON A~VBELN = B~VBELN
*      INNER JOIN VBPA AS C ON B~AUBEL = C~VBELN
*      INNER JOIN VBAP AS D ON B~AUBEL = D~VBELN AND B~AUPOS = D~POSNR
*    WHERE A~FKART IN SO_FKART "Bill.Doc.Type
*      AND A~BUKRS = P_BUKRS    "Company Code
*      AND A~FKDAT IN SO_FKDAT "Billing Date
*      AND B~VBELN IN SO_VBELN "Billing Doc#
*      AND B~AUBEL IN SO_AUBEL "Sales Order#
*      AND B~MATNR IN SO_MATNR "Material#
*      AND C~PARVW = 'RE'       "Party Type = Bill-to
*      AND C~KUNNR IN SO_KUNNR "Customer#
*      AND D~KDMAT IN SO_KDMAT "Customer Material#
*    ORDER BY B~VBELN B~POSNR.
**} Modification 005
 
*{ Modification 010
*    Get pro-forma invoice
*{ Modification 009
*    Get sold-to and cater for sales org 3100 model
 select a~fkart a~vkorg a~fkdat a~knumv a~rfbsk a~vbtyp a~fksto b~vbeln
        b~posnr b~matnr b~aubel b~aupos b~fkimg b~vrkme b~pstyv b~vgbel
        b~vgpos b~vgtyp c~kunnr d~kdmat d~kwmeng d~zmeng
        d~vrkme as aurkm c~posnr as vbpap d~zzatoat d~zzattoa
   into corresponding fields of table gt_line
   from vbrk as a
     inner join vbrp as b on b~vbeln = a~vbeln
     inner join vbpa as c on c~vbeln = b~aubel
     inner join vbap as d on d~vbeln = b~aubel and d~posnr = b~aupos
   where a~fkart in so_fkart "Bill.Doc.Type
     and a~vkorg in so_vkorg "Sales Org.
     and a~fkdat in so_fkdat "Billing Date
     and a~kunag eq c_asat    "Customer# = 10000
     and b~vbeln in so_vbeln "Billing Doc#
     and b~aubel in so_aubel "Sales Order#
     and b~matnr in so_matnr "Material#
     and c~parvw eq 'RE'      "Party Type = Bill-to
     and d~kdmat in so_kdmat. "Customer Material#
*} Modification 006
 
 sort gt_line by vbeln posnr vbpap descending.
 delete adjacent duplicates from gt_line comparing vbeln posnr.
 delete gt_line where not kunnr in so_kunnr.
 
 select a~fkart a~vkorg a~fkdat a~knumv a~rfbsk a~vbtyp a~fksto b~vbeln
        b~posnr b~matnr b~aubel b~aupos b~fkimg b~vrkme b~pstyv b~vgbel
        b~vgpos b~vgtyp a~kunag as kunnr c~kdmat c~kwmeng c~zmeng
        c~vrkme as aurkm
   appending corresponding fields of table gt_line
   from vbrk as a
     inner join vbrp as b on b~vbeln = a~vbeln
     inner join vbap as c on c~vbeln = b~aubel and c~posnr = b~aupos
   where a~fkart in so_fkart "Bill.Doc.Type
     and a~vkorg in so_vkorg "Sales Org.
     and a~fkdat in so_fkdat "Billing Date
     and a~kunag in so_kunnr "Customer#
     and a~kunag ne c_asat    "Not historical DG
     and b~vbeln in so_vbeln "Billing Doc#
     and b~aubel in so_aubel "Sales Order#
     and b~matnr in so_matnr "Material#
     and c~kdmat in so_kdmat. "Customer Material#
 
 sort gt_line by vbeln posnr.
*} Modification 009
*} Modification 010
 
* No record found
**start 014
* CHECK SY-SUBRC = 0.
 if not gt_line[] is initial.
**end 014
    delete adjacent duplicates from gt_line comparing vbeln posnr.
* Check material class
    if not ( so_class[] is initial ). "If package(s) is input
      sort gt_line by matnr.
      loop at gt_line.
* Get material's package for every new material in the line item list
        on change of gt_line-matnr.
          perform check_package using    gt_line-matnr
                                changing l_subrc.
        endon.
* Delete all line items with material whose package not in input list
        if l_subrc ne 0.
          delete gt_line.
        endif.
      endloop.
    endif.
 
*{ Modification 003
*    Add nationality and region
* Get customer information
    select a~kunnr a~name1 a~adrnr a~bran1 a~bran2 a~bran3 b~regiogroup
      into corresponding fields of table gt_kna1
      from kna1 as a
        inner join adrc as b on a~adrnr = b~addrnumber
      for all entries in gt_line
      where a~kunnr = gt_line-kunnr
        and b~date_from <= sy-datum
        and b~date_to   >= sy-datum
        and b~nation = space.
 
    sort gt_kna1 by kunnr.
 
* Check nationality & region
    if not ( so_natio[] is initial and so_regio[] is initial ).
      sort gt_line by kunnr.
      loop at gt_line.
* Get customer's address for every new customer in the line item list
        on change of gt_line-kunnr.
          l_subrc = 0.
        read table gt_kna1 with key kunnr = gt_line-kunnr binary search.
          if sy-subrc = 0.
            if not ( so_natio[] is initial ).
* Check whether the nationality is in the input list
              if not ( gt_kna1-regiogroup in so_natio ).
                l_subrc = 1.
              endif.
            endif.
            if not ( so_regio[] is initial ).
* Check whether the region is in the input list
              if not ( gt_kna1-bran1 in so_regio[] or
                       gt_kna1-bran2 in so_regio[] or
                       gt_kna1-bran3 in so_regio[] ).
                l_subrc = 1.
              endif.
            endif.
          endif.
        endon.
* Delete all line items with customers not in list
        if l_subrc ne 0.
          delete gt_line.
        endif.
      endloop.
    endif.
*} Modification 003
 
* Get material description
* DEVK921978 BEGIN
 
*    SELECT MATNR SPRAS MAKTX INTO CORRESPONDING FIELDS OF TABLE GT_MAKT
*      FROM MAKT
*      FOR ALL ENTRIES IN GT_LINE
*      WHERE MATNR = GT_LINE-MATNR.
 
    select makt~matnr makt~spras makt~maktx mara~extwg
      into corresponding fields of table gt_makt
      from makt
      inner join mara
      on makt~matnr = mara~matnr
      for all entries in gt_line
      where makt~matnr = gt_line-matnr.
* DEVK921978 END
 
* Get material classification
    loop at gt_makt.
      perform get_classification using gt_makt-matnr.
    endloop.
 
*{ Modification 003
*    Move upwards
** Get customer information
* SELECT KUNNR NAME1 INTO CORRESPONDING FIELDS OF TABLE GT_KNA1
*    FROM KNA1
*    FOR ALL ENTRIES IN GT_LINE
*    WHERE KNA1~KUNNR = GT_LINE-KUNNR.
*} Modification 003
 
* Get sales breakdown from billing documents
*{ Modification 004
*    To ignore statistical lines and use bill.doc.item#
* SELECT KNUMV KPOSN STUNR ZAEHK KSCHL KWERT
*    INTO CORRESPONDING FIELDS OF TABLE GT_KONV
*    FROM KONV
*    FOR ALL ENTRIES IN GT_LINE
*   WHERE KNUMV = GT_LINE-KNUMV
*      AND KPOSN = GT_LINE-AUPOS.
    select knumv kposn stunr zaehk kschl kbetr kawrt kpein kwert
      into corresponding fields of table gt_konv
      from konv
      for all entries in gt_line
      where knumv = gt_line-knumv
        and kposn = gt_line-posnr
*start of 018 "DEVK921611
*        AND KSTAT = SPACE.
         and ( kstat = space
              or kschl = 'MKTG' ).
*end of 018 "DEVK921611
*} Modification 004
 
* Get sales order header status
    select vbeln as aubel bstnk
      into corresponding fields of table gt_vbak
      from vbak
      for all entries in gt_line
      where vbeln = gt_line-aubel.
 
* Get sales order line status
    select vbeln as aubel posnr as aupos gbsta
      into corresponding fields of table gt_vbup
      from vbup
      for all entries in gt_line
      where vbeln = gt_line-aubel
        and posnr = gt_line-aupos.
 
* Get sales order related invoice quantity information
    select vbelv as aubel
           posnv as aupos
           vbtyp_n vbeln posnn rfmng meins
      into corresponding fields of table gt_vbfa
      from vbfa
      for all entries in gt_line
      where vbelv = gt_line-aubel
        and posnv = gt_line-aupos
        and vbtyp_n in ('M', 'N', 'O', 'P', 'S') "Invoice doc type
        and vbtyp_v = 'C'.                        "Sales order type
 
*{ Modification 010
*    Get pro-forma invoice
    select a~vbelv as vgbel a~posnv as vgpos a~vbeln
      into corresponding fields of table gt_pfiv
      from vbfa as a
        inner join vbrk as b on b~vbeln = a~vbeln
      for all entries in gt_line
      where a~vbelv = gt_line-vgbel
        and a~posnv = gt_line-vgpos
       and a~vbtyp_n = 'U'                       "Pro-forma inv doc type
        and a~vbtyp_v = 'J'                       "Delivery doc type
        and b~rfbsk ne 'E'.
*} Modification 010
**start 014
 endif.
**end 014
endform.                    " SELECT_RECORDS
 
*&---------------------------------------------------------------------*
*&      Form CHECK_PACKAGE
*&---------------------------------------------------------------------*
*       Check whether the package is within selected list
*----------------------------------------------------------------------*
*      -->P_MATNR Material#
*      <--P_SUBRC Return Code (0-Pass, Otherwise-Failed)
*----------------------------------------------------------------------*
form check_package using    p_matnr like mara-matnr
                    changing p_subrc like sy-subrc.
 
 data: lt_class like sclass occurs 0 with header line,
        lt_clobjdat like clobjdat occurs 0 with header line,
        l_objek like ausp-objek.
 
 p_subrc = 1.
 l_objek = p_matnr.
 call function 'CLAF_CLASSIFICATION_OF_OBJECTS'
    exporting
      classtext    = ''            "No class text
      classtype    = c_matcltype   "Material Classification
      features     = ''            "No characteristic values
      object       = l_objek       "Material#
    tables
      t_class      = lt_class
      t_objectdata = lt_clobjdat
    exceptions
      others       = 4.
 if sy-subrc = 0.
    loop at lt_class where class in so_class.
      p_subrc = 0.
      exit.
    endloop.
 endif.
 
endform.                    " CHECK_PACKAGE
 
*&---------------------------------------------------------------------*
*&      Form GET_CLASSIFICATION
*&---------------------------------------------------------------------*
*       Get the features in the material classification by material#
*----------------------------------------------------------------------*
*      -->P_MATNR Material#
*----------------------------------------------------------------------*
form get_classification using    p_matnr like mara-matnr.
 
 data: lt_class like sclass occurs 0 with header line,
        lt_clobjdat like clobjdat occurs 0 with header line,
        l_objek like ausp-objek.
 
 l_objek = p_matnr.
* Get the features of characteristics of the material
 call function 'CLAF_CLASSIFICATION_OF_OBJECTS'
    exporting
      classtext       = ''          "No class text
      classtype       = c_matcltype "Material classification
      object          = l_objek     "Material#
      initial_charact = ''          "No initial characteristic
    tables
      t_class         = lt_class
      t_objectdata    = lt_clobjdat
    exceptions
      others          = 4.
 if sy-subrc = 0.
    read table lt_class index 1.
    move lt_class-class to gt_matclass-class.
    move p_matnr to gt_matclass-matnr.
    loop at lt_clobjdat.
      move-corresponding lt_clobjdat to gt_matclass.
      append gt_matclass.
    endloop.
    if sy-subrc = 0.
      append gt_matclass.
    endif.
 endif.
 
endform.                    " GET_CLASSIFICATION
 
*&---------------------------------------------------------------------*
*&      Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       Build ALV Field Catalog
*----------------------------------------------------------------------*
form build_fieldcat.
 
 data: ls_fieldcat type lvc_s_fcat,        "ALV Data Field Catalog
        ls_fieldcata type slis_fieldcat_alv. "ALV Display Field Catalog
 
* Macro: _APPEND_FIELDCAT
*          &1 - Field Name
*          &2 - Reference Table
*          &3 - Reference Table Field (when Field Name is different)
*          &4 - Short Field Label
*          &5 - Medium Field Label
*          &6 - Long Field Label
*          &7 - Text Field Name
*          &8 - Reference Field with Quantity Unit
*          &9 - Hotspot
 define _append_fieldcat.
    clear: ls_fieldcat, ls_fieldcata.
    ls_fieldcat-fieldname       = &1.
    ls_fieldcat-ref_table       = &2.
    ls_fieldcat-ref_field      = &3.
    ls_fieldcata-fieldname      = &1.
    ls_fieldcata-ref_tabname    = &2.
    ls_fieldcata-ref_fieldname = &3.
    ls_fieldcata-seltext_s      = &4.
    ls_fieldcata-seltext_m      = &5.
    ls_fieldcata-seltext_l      = &6.
    ls_fieldcata-reptext_ddic   = &6.
    ls_fieldcata-text_fieldname = &7.
    ls_fieldcata-qfieldname     = &8.
    ls_fieldcata-hotspot        = &9.
    append ls_fieldcat to gt_fieldcat.
    append ls_fieldcata to gt_fieldcata.
 end-of-definition.
 
* DEVK921978 Begin
 _append_fieldcat 'EXTWG' 'MARA' '' 'Marketing Segment'
                   'Marketing Segment' 'Marketing Segment' '' '' ''.
* DEVK921978 End
 
 _append_fieldcat 'KUNNR' 'VBPA' '' '' '' '' 'NAME1' '' 'X'. "Bill-to
 _append_fieldcat 'NAME1' 'KNA1' '' '' '' '' '' '' ''.       "Cust.Name
*{ Modification 003
*    Add nationality and region
 _append_fieldcat 'REGIOGROUP' 'ADRC' '' 'Nation.' 'Nationality'
                   'Nationality' '' '' ''.
 _append_fieldcat 'BRAN1' 'KNA1' '' 'Region1' 'Region1' 'Region1'
                   '' '' ''.
 _append_fieldcat 'BRAN2' 'KNA1' '' 'Region2' 'Region2' 'Region2'
                   '' '' ''.
 _append_fieldcat 'BRAN3' 'KNA1' '' 'Region3' 'Region3' 'Region3'
                   '' '' ''.
*} Modification 003
 _append_fieldcat 'BSTNK' 'VBAK' '' '' '' '' '' '' ''.       "Cust.PO#
 _append_fieldcat 'AUBEL' 'VBAP' 'VBELN' '' '' '' '' '' 'X'. "SO Doc#
 _append_fieldcat 'AUPOS' 'VBAP' 'POSNR' '' '' '' '' '' ''. "SO Item
 _append_fieldcat 'GBSTA' 'VBUP' '' '' '' '' '' '' ''.       "Status
*{ Modification 005
*    Add bill doc.type
 _append_fieldcat 'FKART' 'VBRK' '' '' '' '' '' '' ''.       "Bill Type
*} Modification 005
*{ Modification 006
*    Add sales org.
 _append_fieldcat 'VKORG' 'VBRK' '' '' '' '' '' '' ''.       "Sales Org
*} Modification 006
*{ Modification 010
*    Add pro-forma invoice#
 _append_fieldcat 'VBEL2' 'VBRP' 'VBELN' 'Pro-forma#' 'Pro-forma Inv#'
                   'Pro-forma Invoice#' '' '' 'X'.            "Proforma#
*} Modification 010
 _append_fieldcat 'VBELN' 'VBRP' '' '' '' '' '' '' 'X'.      "Bill Doc#
 _append_fieldcat 'POSNR' 'VBRP' '' '' '' '' '' '' ''.       "BD Item
 _append_fieldcat 'FKDAT' 'VBRK' '' '' '' '' '' '' ''.       "Bill Date
 _append_fieldcat 'RFBSK' 'VBRK' '' '' '' '' '' '' ''.       "BD Postg
*{ Modification 009
*    Add cancelled doc indicator
 _append_fieldcat 'FKSTO' 'VBRK' '' '' '' '' '' '' ''.       "Cancelled
*} Modification 009
 _append_fieldcat 'PSTYV' 'VBRP' '' '' '' '' '' '' ''.       "Item Cat.
 _append_fieldcat 'MAWBT' 'AUSP' 'ATWRT' 'MAWB' 'MAWB' 'MAWB' '' '' ''.
 _append_fieldcat 'HAWBT' 'AUSP' 'ATWRT' 'HAWB' 'HAWB' 'HAWB' '' '' ''.
 _append_fieldcat 'FLIGH' 'AUSP' 'ATWRT' 'Flight' 'Flight'
                   'Carrier/Flight' '' '' ''.
 _append_fieldcat 'VGBEL' 'LIKP' 'VBELN' '' '' '' '' '' 'X'. "Del.Doc
 _append_fieldcat 'MATNR' 'VBAP' '' '' '' '' 'MAKTX' '' 'X'. "Device
 _append_fieldcat 'MAKTX' 'MAKT' '' '' '' '' '' '' ''.       "Dev.Desc
 _append_fieldcat 'KDMAT' 'VBAP' '' '' '' '' '' '' ''.       "Cust.Mat#
 _append_fieldcat 'CLASS' 'KLAH' '' 'Pack.' 'Package'
                   'Package' '' '' ''.
 
 perform append_all_charact.               "Append All Characteristics
 
 _append_fieldcat 'FKIMG' 'VBRP' '' '' '' '' '' 'VRKME' ''. "Bill Qty
 _append_fieldcat 'VRKME' 'VBRP' '' '' '' '' '' '' ''.    "Bill Qty UOM
*{ Modification 003
*    Add assembly lead-count and test lead-count
 _append_fieldcat 'ASMLC' 'VBRP' 'FKIMG' 'Assm.LC' 'Assm.LeadCount'
                   'Assembly LeadCount' '' 'VRKME' ''.
 _append_fieldcat 'TSTLC' 'VBRP' 'FKIMG' 'Test LC' 'Test LeadCount'
                   'Test LeadCount' '' 'VRKME' ''.
 
*} Modification 003
*{ Modification 004
*    Sales breakdown
* _APPEND_FIELDCAT 'S_BEFO' 'KONV' 'KWERT' 'Before MD'
*                   'Price Before MD' 'Price Before Markdown' '' '' ''.
* _APPEND_FIELDCAT 'S_MKDN' 'KONV' 'KWERT' 'MKDN' 'Markdown'
*                   'Markdown' '' '' ''.
*{ Modification 008
*    Change unit price to 3 d.p.
* _APPEND_FIELDCAT 'S_ASUP' 'KONV' 'KWERT' 'ASP' 'Assm.Unit Price'
*                   'Assembly Unit Price' '' '' ''.
 _append_fieldcat 'S_AQTY' 'VBRP' 'FKIMG' 'Assm.Qty' 'Assmembly Qty'
                   'Assembly Quantity' '' '' ''.
* Extended the length of unit price data type
 _append_fieldcat 'S_ASUP' 'VBAP' 'KLMENG' 'ASP' 'Assm.Unit Price'
                   'Assembly Unit Price' '' '' ''.
 
*** begin, larry, change to 5 digits after decimal point
 data idx type i.
 
 read table gt_fieldcat with key fieldname = 'S_ASUP' into ls_fieldcat.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcat-ref_table = ''.
    ls_fieldcat-ref_field = ''.
    ls_fieldcat-inttype = 'P'.
    ls_fieldcat-decimals = 5.
    modify gt_fieldcat index idx from ls_fieldcat.
 endif.
 
 read table gt_fieldcata with key fieldname = 'S_ASUP' into
 ls_fieldcata.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcata-decimals_out = 5.
    ls_fieldcata-ref_tabname = ''.
    ls_fieldcata-ref_fieldname = ''.
    modify gt_fieldcata index idx from ls_fieldcata .
 endif.
*** end, larry
 
*{ Modification 017
 
_append_fieldcat 'S_ASSX' 'VBAP' 'KLMENG' 'AOP' 'Assm.Other Unit Price'
                  'Assembly Other Unit Price' '' '' ''.
 
 read table gt_fieldcat with key fieldname = 'S_ASSX' into ls_fieldcat.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcat-ref_table = ''.
    ls_fieldcat-ref_field = ''.
    ls_fieldcat-inttype = 'P'.
    ls_fieldcat-decimals = 5.
    modify gt_fieldcat index idx from ls_fieldcat.
 endif.
 
 read table gt_fieldcata with key fieldname = 'S_ASSX' into
 ls_fieldcata.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcata-decimals_out = 5.
    ls_fieldcata-ref_tabname = ''.
    ls_fieldcata-ref_fieldname = ''.
    modify gt_fieldcata index idx from ls_fieldcata .
 endif.
 
 
 _append_fieldcat 'S_GSAW' 'VBAP' 'KLMENG' 'GSP'
 'GaAs Sawing Unit Price' 'GaAs Sawing Unit Price' '' '' ''.
 
 read table gt_fieldcat with key fieldname = 'S_GSAW' into ls_fieldcat.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcat-ref_table = ''.
    ls_fieldcat-ref_field = ''.
    ls_fieldcat-inttype = 'P'.
    ls_fieldcat-decimals = 5.
    modify gt_fieldcat index idx from ls_fieldcat.
 endif.
 
 read table gt_fieldcata with key fieldname = 'S_GSAW' into
 ls_fieldcata.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcata-decimals_out = 5.
    ls_fieldcata-ref_tabname = ''.
    ls_fieldcata-ref_fieldname = ''.
    modify gt_fieldcata index idx from ls_fieldcata .
 endif.
 
 _append_fieldcat 'S_QATD' 'VBAP' 'KLMENG' 'QTP'
 'QA Test Unit Price' 'QA Test by Device Unit Price' '' '' ''.
 
 read table gt_fieldcat with key fieldname = 'S_QATD' into ls_fieldcat.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcat-ref_table = ''.
    ls_fieldcat-ref_field = ''.
    ls_fieldcat-inttype = 'P'.
    ls_fieldcat-decimals = 5.
    modify gt_fieldcat index idx from ls_fieldcat.
 endif.
 
 read table gt_fieldcata with key fieldname = 'S_QATD' into
 ls_fieldcata.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcata-decimals_out = 5.
    ls_fieldcata-ref_tabname = ''.
    ls_fieldcata-ref_fieldname = ''.
    modify gt_fieldcata index idx from ls_fieldcata .
 endif.
 
* _APPEND_FIELDCAT 'S_HAAM' 'KONV' 'KBETR' 'Pre.Asm' 'Fast Premium-Asm'
*                   'Fast Premium-Assembly' '' '' ''.
* _APPEND_FIELDCAT 'S_HTAM' 'KONV' 'KBETR' 'Pre.Tst' 'Fast
*                   Premium-Test'
*                   'Fast Premium-Test' '' '' ''.
 _append_fieldcat 'S_QAAM' 'KONV' 'KBETR' 'QA.Tst' 'QA Test Amt'
                   'QA Test Charge' '' '' ''.
 
 _append_fieldcat 'S_EXTW' 'KONV' 'KBETR' 'Extra Wire'
 'Extra Wires Amt' 'Extra Wires Amount' '' '' ''.
 
 read table gt_fieldcat with key fieldname = 'S_EXTW' into ls_fieldcat.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcat-ref_table = ''.
    ls_fieldcat-ref_field = ''.
    ls_fieldcat-inttype = 'P'.
    ls_fieldcat-decimals = 4.
    modify gt_fieldcat index idx from ls_fieldcat.
 endif.
 
 read table gt_fieldcata with key fieldname = 'S_EXTW' into
 ls_fieldcata.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcata-decimals_out = 4.
    ls_fieldcata-ref_tabname = ''.
    ls_fieldcata-ref_fieldname = ''.
    modify gt_fieldcata index idx from ls_fieldcata .
 endif.
 
 _append_fieldcat 'S_ASSL' 'KONV' 'KBETR' 'Othr.Lot' 'Assm.Other Lot'
                   'Assembly Others(Lot)' '' '' ''.
 _append_fieldcat 'S_ENGG' 'KONV' 'KBETR' 'Eng.Chrg' 'Eng.Lot Chrg'
                   'Engineering Lot Chrg' '' '' ''.
 _append_fieldcat 'S_MINA' 'KONV' 'KBETR' 'Min.Assy'
                   'Min Lot Charge-Assy'
                   'Min Lot Charge-Assembly' '' '' ''.
 _append_fieldcat 'S_MINB' 'KONV' 'KBETR' 'Min.BckGr'
                   'Min Lot Charge-BckGr'
                   'Min Lot Charge-Backgrind' '' '' ''.
 _append_fieldcat 'S_MINT' 'KONV' 'KBETR' 'Min.Tst'
                   'Min Lot Charge-Test'
                   'Min Lot Charge-Test' '' '' ''.
 
*} Modification 017
 
*} Modification 008
 _append_fieldcat 'S_ASSM' 'KONV' 'KWERT' 'AS' 'Assm.Sales'
                   'Assembly Sales' '' '' ''.
 _append_fieldcat 'S_DISA' 'KONV' 'KWERT' 'Assm.Disc' 'Assm.Discount'
                   'Assembly Discount' '' '' ''.
 _append_fieldcat 'S_ASOT' 'KONV' 'KWERT' 'Assm.Other' 'Assm.Others'
                   'Assembly Others' '' '' ''.
 _append_fieldcat 'S_ASAD' 'KONV' 'KWERT' 'Assm.Adder' 'Assm.Adders'
                   'Assembly Adders' '' '' ''.
 _append_fieldcat 'S_GOLD' 'KONV' 'KWERT' 'Gold' 'Gold Adder'
                   'Gold Adder' '' '' ''.
 _append_fieldcat 'S_WAFE' 'KONV' 'KWERT' 'Wafer' 'Wafer'
                   'Wafer' '' '' ''.
 _append_fieldcat 'S_BACK' 'KONV' 'KWERT' 'Backgrind' 'Backgrind'
                   'Backgrind' '' '' ''.
 _append_fieldcat 'S_HOTA' 'KONV' 'KWERT' 'FRP' 'Assm.FRP'
                   'Assembly FRP' '' '' ''.
 _append_fieldcat 'S_HOTT' 'KONV' 'KWERT' 'FRPT' 'Test FRP'
                   'Test FRP' '' '' ''.
 _append_fieldcat 'S_TQTY' 'VBRP' 'FKIMG' 'Test Qty' 'Test Qty'
                   'Test Quantity' '' '' ''.
* Extended the length of unit price data type
 _append_fieldcat 'S_TUP1' 'VBAP' 'KLMENG' 'TUP1' '1st Test Unit Price'
                  '1st Test Unit Price' '' '' ''.
 
*** begin, larry, change to 5 digits after decimal point
 read table gt_fieldcat with key fieldname = 'S_TUP1' into ls_fieldcat.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcat-ref_table = ''.
    ls_fieldcat-ref_field = ''.
    ls_fieldcat-inttype = 'P'.
    ls_fieldcat-decimals = 5.
    modify gt_fieldcat index idx from ls_fieldcat.
 endif.
 
 read table gt_fieldcata with key fieldname = 'S_TUP1' into
 ls_fieldcata.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcata-decimals_out = 5.
    ls_fieldcata-ref_tabname = ''.
    ls_fieldcata-ref_fieldname = ''.
    modify gt_fieldcata index idx from ls_fieldcata .
 endif.
 
*** end, larry
 
 
 _append_fieldcat 'S_TUP2' 'VBAP' 'KLMENG' 'TUP2' '2nd Test Unit Price'
                  '2nd Test Unit Price' '' '' ''.
 
*** begin, larry, change to 5 digits after decimal point
* data idx type i.
 read table gt_fieldcat with key fieldname = 'S_TUP2' into ls_fieldcat.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcat-ref_table = ''.
    ls_fieldcat-ref_field = ''.
    ls_fieldcat-inttype = 'P'.
    ls_fieldcat-decimals = 5.
    modify gt_fieldcat index idx from ls_fieldcat.
 endif.
 
 read table gt_fieldcata with key fieldname = 'S_TUP2' into
 ls_fieldcata.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcata-decimals_out = 5.
    ls_fieldcata-ref_tabname = ''.
    ls_fieldcata-ref_fieldname = ''.
    modify gt_fieldcata index idx from ls_fieldcata .
 endif.
 
*** end, larry
 
 _append_fieldcat 'S_TUP3' 'VBAP' 'KLMENG' 'TUP3' '2nd Test Unit Price'
                  '3rd Test Unit Price' '' '' ''.
 
*** begin, larry, change to 5 digits after decimal point
* data idx type i.
 
 read table gt_fieldcat with key fieldname = 'S_TUP3' into ls_fieldcat.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcat-ref_table = ''.
    ls_fieldcat-ref_field = ''.
    ls_fieldcat-inttype = 'P'.
    ls_fieldcat-decimals = 5.
    modify gt_fieldcat index idx from ls_fieldcat.
 endif.
 
 
 read table gt_fieldcata with key fieldname = 'S_TUP3' into
 ls_fieldcata.
 if sy-subrc = 0.
    idx = sy-tabix.
    ls_fieldcata-decimals_out = 5.
    ls_fieldcata-ref_tabname = ''.
    ls_fieldcata-ref_fieldname = ''.
    modify gt_fieldcata index idx from ls_fieldcata .
 endif.
 
*** end, larry
 
 
 _append_fieldcat 'S_TSTA' 'KONV' 'KWERT' 'Test Sales' 'Test Sales'
                   'Test Sales' '' '' ''.
 _append_fieldcat 'S_DIST' 'KONV' 'KWERT' 'Test Disc' 'Test Discount'
                   'Test Discount' '' '' ''.
 _append_fieldcat 'S_TTOT' 'KONV' 'KWERT' 'Test Other' 'Test Others'
                   'Test Others' '' '' ''.
 _append_fieldcat 'S_TTAD' 'KONV' 'KWERT' 'Test Adder' 'Test Adders'
                   'Test Adders' '' '' ''.
**016
 _append_fieldcat 'S_TOT' 'KONV' 'KWERT' 'Test Total' 'Test Total'
                   'Test Total' '' '' ''.
**016
 _append_fieldcat 'S_PACK' 'KONV' 'KWERT' 'Pack' 'Packing'
                   'Packing' '' '' ''.
 _append_fieldcat 'S_TOOL' 'KONV' 'KWERT' 'Tool' 'Tooling'
                   'Tooling' '' '' ''.
*} Modification 004
*{ Modification 007
*    Add unclassified column
 _append_fieldcat 'S_UNCL' 'KONV' 'KWERT' 'Unclass' 'Unclassified'
                   'Unclassified' '' '' ''.
*} Modification 007
 _append_fieldcat 'S_GRSS' 'KONV' 'KWERT' 'Gross' 'Gross Sales'
                   'Gross Sales' '' '' ''.
*{ Modification 005
*    Sales breakdown
 _append_fieldcat 'S_MKDN' 'KONV' 'KWERT' 'MKDN' 'Markdown'
                   'Markdown' '' '' ''.
 _append_fieldcat 'S_ICAM' 'KONV' 'KWERT' 'Inter-Co.' 'Inter-Co. Amt.'
                   'Inter-Company Amount' '' '' ''.
*} Modification 005
 _append_fieldcat 'KWMENG' 'VBAP' '' '' '' '' '' 'AURKM' ''. "SO Qty
 _append_fieldcat 'AURKM' 'VBAP' 'VRKME' '' '' '' '' '' ''. "SO Qty UOM
 _append_fieldcat 'RFMNG' 'VBFA' '' 'Unbill.Qty' 'Unbilled Qty'
                   'Unbilled Quantity' '' 'MEINS' ''.     "SO Unbill.Qty
 _append_fieldcat 'MEINS' 'VBFA' '' '' '' '' '' '' ''. "SO Unb.Qty UOM
 _append_fieldcat 'ZZATOAT' 'VBAP' '' 'A to A+T' 'A to A+T' 'A to A+T'
 '' '' 'X'.
 _append_fieldcat 'ZZATTOA' 'VBAP' '' 'A+T to A ' 'A+T to A' 'A+T to A'
 '' '' 'X'.
 
 _append_fieldcat 'PARNT' '' '' 'Pakg Group (CO)' 'Pakg Group (CO)'
                   'Pakg Group (CO)' '' '' ''.
*start of 018 "DEVK921611
 ls_fieldcata-datatype = 'CURR'.
 ls_fieldcata-outputlen = 13.
 _append_fieldcat 'P_EXTW' '' '' 'EXTW' 'EXTW'
                    'EXTW' '' '' ''.
 _append_fieldcat 'P_MKTG' 'KONV' 'KBETR' 'MKTG' 'MKTG'
                    'MKTG' '' '' ''.
 _append_fieldcat 'P_GOLD' 'KONV' 'KBETR' 'GOLD' 'GOLD'
                    'GOLD' '' '' ''.
 _append_fieldcat 'V_EXTW' 'KONV' 'KAWRT' 'NO.Wires' 'NO. Ex.Wires'
                    'Number of Extra Wires' '' '' ''.
 
*end of 018 "DEVK921611
 
endform.                    " BUILD_FIELDCAT
 
*&---------------------------------------------------------------------*
*&      Form APPEND_ALL_CHARACT
*&---------------------------------------------------------------------*
*       Append all retrieved characteristics to columns
*----------------------------------------------------------------------*
form append_all_charact.
 
 data: ls_fieldcat type lvc_s_fcat,        "ALV Data Field Catalog
        ls_fieldcata type slis_fieldcat_alv. "ALV Display Field Catalog
 
 data: lt_cabn like cabn          occurs 0 with header line,
        lt_cabnt like cabnt         occurs 0 with header line,
        lr_atinn like clsel_r_atinn occurs 0 with header line.
 
 data: l_idx(3) type n.
 
 sort gt_matclass by atnam.
 
 clear l_idx.
 loop at gt_matclass.
* Get characteristics attributes for every new characteristics
    on change of gt_matclass-atnam.
      call function 'CLSE_SELECT_CABN_VIA_NAME'
        exporting
          characteristic = gt_matclass-atnam
        tables
          t_cabn         = lt_cabn
        exceptions
          others         = 2.
      check sy-subrc = 0.
      read table lt_cabn index 1.
      clear: ls_fieldcat, ls_fieldcata, gt_char.
* Construct ALV display attributes
      add 1 to l_idx.
      concatenate 'MATCL' l_idx into ls_fieldcat-fieldname.
      if lt_cabn-atfor = 'NUM'.
        ls_fieldcat-inttype    = 'P'.
        ls_fieldcat-edit_mask = lt_cabn-atsch.
        ls_fieldcat-decimals   = lt_cabn-anzdz.
        ls_fieldcat-quantity   = lt_cabn-msehi.
        ls_fieldcat-decmlfield = ls_fieldcat-fieldname.
      else.
        ls_fieldcat-inttype    = 'C'.
        ls_fieldcat-intlen     = 30.
      endif.
      clear lr_atinn.
      refresh: lr_atinn, lt_cabnt.
      lr_atinn-option = 'EQ'.
      lr_atinn-sign   = 'I'.
      lr_atinn-low    = lt_cabn-atinn.
      append lr_atinn.
      call function 'CLSE_SELECT_CABNT'
        exporting
          language = sy-langu
        tables
          in_cabn = lr_atinn
          t_cabnt = lt_cabnt
        exceptions
          others   = 2.
      if sy-subrc = 0.
        read table lt_cabnt index 1.
        ls_fieldcat-seltext = lt_cabnt-atbez.
      else.
        ls_fieldcat-seltext = gt_matclass-atnam.
      endif.
 
      append ls_fieldcat to gt_fieldcat.
      ls_fieldcata-fieldname = ls_fieldcat-fieldname.
      ls_fieldcata-seltext_l = ls_fieldcat-seltext.
      append ls_fieldcata to gt_fieldcata.
* Maintain characteristics-ALV_fieldname relationship table
      gt_char-atnam = gt_matclass-atnam.
      gt_char-itype = ls_fieldcat-inttype.
      gt_char-field = ls_fieldcat-fieldname.
     append gt_char.
    endon.
 
 endloop.
 
endform.                    " APPEND_ALL_CHARACT
 
*&---------------------------------------------------------------------*
*&      Form GENERATE_OUT_TABLE
*&---------------------------------------------------------------------*
*       Generate ALV data table
*----------------------------------------------------------------------*
form generate_out_table.
 
 data: lx_table type ref to data.
 
* Generate ALV data table
 call method cl_alv_table_create=>create_dynamic_table
    exporting
      it_fieldcatalog = gt_fieldcat
    importing
      ep_table        = lx_table.
 assign lx_table->* to <gt_out>.
 
endform.                    " GENERATE_OUT_TABLE
 
 
*&--------------------------------------------------------------------*
*&      Form FILL_OUT_TABLE
*&--------------------------------------------------------------------*
*       Fill data into ALV data table
*---------------------------------------------------------------------*
form fill_out_table.
 
 field-symbols: <ls_out>.
 field-symbols: <l_f1>, <l_f2>, <l_f3>, <l_f4>, <l_ft>.
 
 data: l_tabix     like sy-tabix,
        l_rfmng     like vbfa-rfmng,
        l_aflag(1) type c,
        l_tflag(1) type c,
        l_tcount(1) type n,
        l_field(10) type c.
 
 sort gt_kna1 by kunnr.
 sort gt_makt by matnr spras.
 sort gt_konv by knumv kposn stunr zaehk.
 sort gt_matclass by matnr.
 sort gt_char by atnam.
 sort gt_vbak by aubel.
 sort gt_vbup by aubel aupos.
 sort gt_vbfa by aubel aupos.
 sort gt_pfiv by vgbel vgpos.
 
 assign local copy of initial line of <gt_out> to <ls_out>.
 
 select nodid parnt wert1
 into corresponding fields of table gt_tkchw
    from tkchw
    where applc    = 'KE'           "Application class for DD objects
      and id1      = 'RKEG_WWCLS'   "Hierarchy key: Component 1
      and id2      = 'ZCO'.     "Hierarchy key: Component 2 "DEVK921639
 
 loop at gt_line.
* Add begin of "DEVK921598
    perform get_package_group.
* Add end of "DEVK921598
 
    clear <ls_out>.
    clear: l_aflag, l_tflag, l_tcount.
* If ordered quantity is zero, use target quantity
    if gt_line-kwmeng is initial.
      gt_line-kwmeng = gt_line-zmeng.
    endif.
*{ Modification 010
*    Get pro-forma invoice#
    if gt_line-vgtyp = 'J'.
* If reference document type is delivery, get pro-forma invoice
      read table gt_pfiv with key vgbel = gt_line-vgbel
                                  vgpos = gt_line-vgpos
                         binary search.
      if sy-subrc = 0.
        assign component 'VBEL2' of structure <ls_out> to <l_f1>.
        <l_f1> = gt_pfiv-vbeln.
      endif.
    else.
* If reference document type is not delivery, empty delivery doc#
      clear gt_line-vgbel.
    endif.
*} Modification 010
* Get core information from retrieved line items
    move-corresponding gt_line to <ls_out>.
* Get customer name
    read table gt_kna1 with key kunnr = gt_line-kunnr binary search.
    if sy-subrc = 0.
      move-corresponding gt_kna1 to <ls_out>.
    endif.
* Get material description
    read table gt_makt with key matnr = gt_line-matnr
                                spras = sy-langu      binary search.
    if sy-subrc = 0.
      move-corresponding gt_makt to <ls_out>.
    else.
      read table gt_makt with key matnr = gt_line-matnr binary search.
      if sy-subrc = 0.
        move-corresponding gt_makt to <ls_out>.
      endif.
    endif.
* Get material classification
    read table gt_matclass with key matnr = gt_line-matnr binary search.
    if sy-subrc = 0.
* Get package information
      move-corresponding gt_matclass to <ls_out>.
      l_tabix = sy-tabix.
      loop at gt_matclass from l_tabix.
        if gt_matclass-matnr ne gt_line-matnr. exit. endif.
        read table gt_char with key atnam = gt_matclass-atnam
                           binary search.
        check sy-subrc = 0.
        assign component gt_char-field of structure <ls_out> to <l_f1>.
        if gt_char-itype = 'C'.
          <l_f1> = gt_matclass-ausp1.
        else.
          <l_f1> = gt_matclass-atflv.
        endif.
      endloop.
    endif.
* Get sales breakdown
*{ Modification 004
*    To use bill.doc.item#
*    READ TABLE GT_KONV WITH KEY KNUMV = GT_LINE-KNUMV
*                                KPOSN = GT_LINE-AUPOS
*                       BINARY SEARCH TRANSPORTING NO FIELDS.
    read table gt_konv with key knumv = gt_line-knumv
                                kposn = gt_line-posnr
                       binary search transporting no fields.
*} Modification 004
    if sy-subrc = 0.
      l_tabix = sy-tabix.
      assign component 'S_GRSS' of structure <ls_out> to <l_ft>.
      loop at gt_konv from l_tabix.
*{ Modification 004
*    To use bill.doc.item#
*        IF ( GT_KONV-KNUMV NE GT_LINE-KNUMV OR
*             GT_KONV-KPOSN NE GT_LINE-AUPOS ).
        if ( gt_konv-knumv ne gt_line-knumv or
             gt_konv-kposn ne gt_line-posnr ).
*} Modification 004
          exit.
        endif.
        case gt_konv-kschl.
*{ Modification 004
*    Sales breakdown
*          WHEN 'MKDN'.
*            ASSIGN COMPONENT 'S_MKDN' OF STRUCTURE <LS_OUT> TO <L_F1>.
*          WHEN OTHERS.
*            ASSIGN COMPONENT 'S_BEFO' OF STRUCTURE <LS_OUT> TO <L_F1>.
*        ENDCASE.
*        ADD GT_KONV-KWERT TO <L_F1>.
*      ENDLOOP.
*      ASSIGN COMPONENT 'S_BEFO' OF STRUCTURE <LS_OUT> TO <L_F1>.
*      ASSIGN COMPONENT 'S_MKDN' OF STRUCTURE <LS_OUT> TO <L_F2>.
*      ASSIGN COMPONENT 'S_GRSS' OF STRUCTURE <LS_OUT> TO <L_FT>.
*      <L_FT> = <L_F1> + <L_F2>.
 
          when 'ASSM'.
            assign component 'S_AQTY' of structure <ls_out> to <l_f1>.
            <l_f1> = gt_konv-kawrt / 10.
            assign component 'S_ASUP' of structure <ls_out> to <l_f1>.
*{ Modification 007
*    Fix unit price calculation
            if gt_konv-kpein = 0.
              <l_f1> = gt_konv-kbetr.
            else.
              <l_f1> = gt_konv-kbetr / gt_konv-kpein.
            endif.
*} Modification 007
            assign component 'S_ASSM' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
            l_aflag = 'X'.
 
          when 'DISA'.
            assign component 'S_DISA' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
*{ Modification 007
*    Add cond.types
*          WHEN 'ENGG' OR 'MINA' OR 'TSTR'.
**start 016
*           WHEN 'ENGG' OR 'MINA' OR 'TSTR' OR 'ASSX'.
          when 'ENGG' or 'MINA' or 'TSTR' or 'ASSX' or 'SAW' or 'ASSL'.
*} Modification 007
**end 016
*{ Modification 017
            if gt_konv-kschl = 'ENGG' or gt_konv-kschl = 'MINA' or
               gt_konv-kschl = 'TSTR' or gt_konv-kschl = 'ASSX' or
               gt_konv-kschl = 'SAW'.
 
              assign component 'S_ASOT' of structure <ls_out> to <l_f1>.
              if gt_konv-kwert ne 0 .
                add gt_konv-kwert to <l_f1>.
              endif.
              if gt_konv-kschl = 'ENGG'.
              assign component 'S_ENGG' of structure <ls_out> to <l_f3>.
                if gt_konv-kbetr ne 0.
                  add gt_konv-kbetr to <l_f3>.
                endif.
              elseif gt_konv-kschl = 'MINA'.
              assign component 'S_MINA' of structure <ls_out> to <l_f3>.
                if gt_konv-kbetr ne 0.
                  add gt_konv-kbetr to <l_f3>.
                endif.
              elseif gt_konv-kschl = 'ASSX'.
              assign component 'S_ASSX' of structure <ls_out> to <l_f4>.
                if gt_konv-kpein = 0.
                  <l_f4> = gt_konv-kbetr.
                else.
                  <l_f4> = gt_konv-kbetr / gt_konv-kpein.
                endif.
              endif.
            else.
              assign component 'S_ASSL' of structure <ls_out> to <l_f3>.
              if gt_konv-kbetr ne 0.
                add gt_konv-kbetr to <l_f3>.
              endif.
            endif.
 
*} Modification 017
          when '2OPT' or 'COAT' or 'DBBG' or 'DBUT' or 'DCST' or
               'EXTW' or 'MINB' or 'RWRK' or 'TSTM' or 'RWUP' or
**start 015
               'TSTO' or 'DPBG' or 'DPUT'.
**end 015
*{ Modification 017
            if gt_konv-kschl = 'EXTW'.
             assign component 'S_EXTW' of structure <ls_out> to <l_f1>.
              if gt_konv-kpein = 0.
                <l_f1> = gt_konv-kbetr * gt_konv-kawrt / 10.
              else.
            <l_f1> = gt_konv-kbetr / gt_konv-kpein * gt_konv-kawrt / 10.
              endif.
*start of 018 "DEVK921611
              data wa type p decimals 4.
              assign component 'P_EXTW' of structure <ls_out> to <l_f1>.
              if gt_konv-kpein = 0.
                wa = gt_konv-kbetr.
              else.
                wa = gt_konv-kbetr / gt_konv-kpein.
              endif.
                <l_f1> = wa.
 
              assign component 'V_EXTW' of structure <ls_out> to <l_f1>.
              <l_f1> = gt_konv-kawrt / 10.
*end of 018 "DEVK921611
            endif.
 
            assign component 'S_ASAD' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
 
            if gt_konv-kschl = 'MINB'.
              assign component 'S_MINB' of structure <ls_out> to <l_f3>.
              if gt_konv-kbetr ne 0 .
                add gt_konv-kbetr to <l_f3>.
              endif.
            endif.
 
*} Modification 017
          when 'GOLD'.
            assign component 'S_GOLD' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
*start of 018 "DEVK921611
            assign component 'P_GOLD' of structure <ls_out> to <l_f1>.
            if gt_konv-kpein = 0.
              <l_f1> = gt_konv-kbetr.
            else.
              <l_f1> = gt_konv-kbetr / gt_konv-kpein.
            endif.
*end of 018 "DEVK921611
          when 'GSAW'.
*{ Modification 017
            assign component 'S_GSAW' of structure <ls_out> to <l_f1>.
            if gt_konv-kpein = 0.
              <l_f1> = gt_konv-kbetr.
            else.
              <l_f1> = gt_konv-kbetr / gt_konv-kpein.
            endif.
*} Modification 017
           assign component 'S_WAFE' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
*{ Modification 007
*    Add cond.types
*          WHEN 'BACK'.
          when 'BACK' or 'BG03' or 'BG04' or 'BG05' or 'BG06' or
               'BG08' or 'BG12' .
*} Modification 007
            assign component 'S_BACK' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
          when 'HOTA'.
            assign component 'S_HOTA' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
 
          when 'TSTA'.
            assign component 'S_TQTY' of structure <ls_out> to <l_f1>.
            add 1 to l_tcount.
            <l_f1> = gt_konv-kawrt / 10.
            concatenate 'S_TUP' l_tcount into l_field.
            assign component l_field of structure <ls_out> to <l_f1>.
*{ Modification 007
*    Fix unit price calculation
            if gt_konv-kpein = 0.
              <l_f1> = gt_konv-kbetr.
            else.
              <l_f1> = gt_konv-kbetr / gt_konv-kpein.
            endif.
*} Modification 007
*          L_TOTAL = L_TOAL + ( GT_KONV-KBETR / GT_KONV-KPEIN ).    "016
            assign component 'S_TSTA' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
            l_tflag = 'X'.
          when 'DIST'.
            assign component 'S_DIST' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
*{ Modification 007
*    Add cond.types
*          WHEN 'TSTP' OR 'TSTT' OR 'MINT'.
          when 'TSTP' or 'TSTT' or 'MINT' or 'TSTX' or 'BURN' or 'QATD'
               or 'QATP' or 'SCAN' or 'TRBB' or 'TRBU' or 'TSTI'
               or 'HOTT'.
 
            if gt_konv-kschl = 'BURN' or gt_konv-kschl = 'QATD' or
                gt_konv-kschl = 'QATP' or gt_konv-kschl = 'SCAN' or
                gt_konv-kschl = 'TRBB' or gt_konv-kschl = 'TRBU' or
                gt_konv-kschl = 'TSTI'.
*{ Modification 017
              if gt_konv-kschl = 'QATD'.
 
              assign component 'S_QATD' of structure <ls_out> to <l_f1>.
                if gt_konv-kpein = 0.
                  <l_f1> = gt_konv-kbetr.
                else.
                  <l_f1> = gt_konv-kbetr / gt_konv-kpein.
                endif.
 
              assign component 'S_QAAM' of structure <ls_out> to <l_f1>.
                if gt_konv-kwert ne 0 .
                  add gt_konv-kwert to <l_f1>.
                endif.
              endif.
*} Modification 017
              assign component 'S_TTAD' of structure <ls_out> to <l_f1>.
              if gt_konv-kwert ne 0 .
                add gt_konv-kwert to <l_f1>.
              endif.
 
            else.
*            IF GT_KONV-KSCHL = 'TSTP' OR GT_KONV-KSCHL = 'TSTT' OR
*               GT_KONV-KSCHL = 'MINT' OR GT_KONV-KSCHL = 'TSTX' OR
**              GT_KONV-KSCHL = 'QATD' OR GT_KONV-KSCHL = 'QATP'
*               GT_KONV-KSCHL = 'HOTT'.
 
              if gt_konv-kschl = 'TSTP' or gt_konv-kschl = 'TSTT'.
*{ Modification 007
              assign component 'S_TQTY' of structure <ls_out> to <l_f1>.
                if <l_f1> = 0.
                  <l_f1> = gt_konv-kawrt / 10.
                endif.
              elseif gt_konv-kschl = 'MINT'.
              assign component 'S_MINT' of structure <ls_out> to <l_f3>.
                if gt_konv-kbetr ne 0 .
                  add gt_konv-kbetr to <l_f3>.
                endif.
              elseif gt_konv-kschl = 'HOTT'.
              assign component 'S_HOTT' of structure <ls_out> to <l_f1>.
                if gt_konv-kwert ne 0 .
                  add gt_konv-kwert to <l_f1>.
                endif.
              endif.
 
              assign component 'S_TTOT' of structure <ls_out> to <l_f1>.
              if gt_konv-kwert ne 0 .
                add gt_konv-kwert to <l_f1>.
              endif.
              l_tflag = 'X'.
            endif.
*} Modification 017
**start 0016
*          WHEN 'WFRU' OR 'WFRW'.
          when 'WFRU' or 'WFRW' or 'PROB' or 'LTRM'.
**end 0016
            assign component 'S_TTAD' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
 
          when 'TUBE' or 'TUBU' or 'TRAY' or 'TRYU' or 'CANI'.
            assign component 'S_PACK' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
          when 'DSGN' or 'TOOL'.
            assign component 'S_TOOL' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
*{ Modification 008
*    Fix 'MKDN' column
*          WHEN 'MSDN'.
          when 'MKDN'.
*} Modification 008
            assign component 'S_MKDN' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
          when 'PI02'.
            assign component 'S_ICAM' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
          when others.
*{ Modification 007
*    Add unclassified column
*            GT_KONV-KWERT = 0.
            assign component 'S_UNCL' of structure <ls_out> to <l_f1>.
            if gt_konv-kwert ne 0 .
              add gt_konv-kwert to <l_f1>.
            endif.
*} Modification 007
*start of 018 "DEVK921611
            if gt_konv-kschl = 'MKTG'.
              assign component 'P_MKTG' of structure <ls_out> to <l_f1>.
              if gt_konv-kpein = 0.
                <l_f1> = gt_konv-kbetr.
              else.
                <l_f1> = gt_konv-kbetr / gt_konv-kpein.
              endif.
            endif.
*end of 018 "DEVK921611
        endcase.
        if gt_konv-kwert ne 0 .
          if gt_konv-kschl ne 'MKDN' and gt_konv-kschl ne 'PI02'.
            add gt_konv-kwert to <l_ft>.
          endif.
        endif.
*{ Modification 017
*        IF GT_KONV-KBETR NE 0 AND ( GT_KONV-KSCHL = 'ASSL'
**         GT_KONV-KSCHL = 'HOTA' OR GT_KONV-KSCHL = 'HOTT'
*           OR GT_KONV-KSCHL = 'ENGG' OR GT_KONV-KSCHL = 'MINA'
*           OR GT_KONV-KSCHL = 'MINB' OR GT_KONV-KSCHL = 'MINT' ).
*          ADD GT_KONV-KBETR TO <L_F3>.
*        ENDIF.
*{ Modification 017
      endloop.
*} Modification 004
    endif.
 
*{ Modification 001
*    To give negative values on billed amount & qty
    if gt_line-vbtyp = 'N' or gt_line-vbtyp = 'O'.
      assign component 'FKIMG' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
*{ Modification 004
*    Sales breakdown
      assign component 'S_AQTY' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_ASSM' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_DISA' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_ASOT' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_ASAD' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_GOLD' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_WAFE' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_BACK' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_HOTA' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_HOTT' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_TQTY' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_TSTA' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_DIST' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_TTOT' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_TTAD' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_PACK' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_TOOL' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
*} Modification 004
*{ Modification 007
*    Add unclassified column
      assign component 'S_UNCL' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
*} Modification 007
      assign component 'S_GRSS' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
      assign component 'S_MKDN' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
*{ Modification 011
*   Fix bug for markdown sign
      assign component 'S_ICAM' of structure <ls_out> to <l_f1>.
*} Modification 011
      <l_f1> = <l_f1> * -1.
*{ Modification 017
      assign component 'S_QAAM' of structure <ls_out> to <l_f1>.
      <l_f1> = <l_f1> * -1.
     assign component 'S_ASSL' of structure <ls_out> to <l_f3>.
      <l_f3> = <l_f3> * -1.
      assign component 'S_ENGG' of structure <ls_out> to <l_f3>.
      <l_f3> = <l_f3> * -1.
      assign component 'S_MINA' of structure <ls_out> to <l_f3>.
      <l_f3> = <l_f3> * -1.
      assign component 'S_MINB' of structure <ls_out> to <l_f3>.
      <l_f3> = <l_f3> * -1.
      assign component 'S_MINT' of structure <ls_out> to <l_f3>.
      <l_f3> = <l_f3> * -1.
*} Modification 017
    endif.
*} Modification 001
 
*{ Modification 003
*    Get lead count information (negative when reversing & credit-memo)
    read table gt_char with key atnam = c_lead binary search.
    if sy-subrc = 0.
      assign component gt_char-field of structure <ls_out> to <l_f1>.
*{ Modification 004
*    Change to checking condition type
*      ASSIGN COMPONENT 'FKIMG' OF STRUCTURE <LS_OUT> TO <L_F2>.
*      IF GT_LINE-PSTYV CS 'A'. "Item category related to Assembly
      if l_aflag = 'X'. "Assembly Price exists
        assign component 'S_AQTY' of structure <ls_out> to <l_f2>.
        assign component 'ASMLC' of structure <ls_out> to <l_ft>.
        <l_ft> = <l_f1> * <l_f2>.
      endif.
*      IF GT_LINE-PSTYV CS 'T'. "Item category related to Testing
      if l_tflag = 'X'. "Test Price exists
        assign component 'S_TQTY' of structure <ls_out> to <l_f2>.
        assign component 'TSTLC' of structure <ls_out> to <l_ft>.
        <l_ft> = <l_f1> * <l_f2>.
      endif.
*} Modification 004
    endif.
*} Modification 003
 
* Get sales order customer PO number
    read table gt_vbak with key aubel = gt_line-aubel binary search.
    if sy-subrc = 0.
      move-corresponding gt_vbak to <ls_out>.
    endif.
* Get sales order item status
    read table gt_vbup with key aubel = gt_line-aubel
                                aupos = gt_line-aupos
                       binary search.
    if sy-subrc = 0.
      move-corresponding gt_vbup to <ls_out>.
    endif.
* Get sales order item unbilled quantity
    read table gt_vbfa with key aubel = gt_line-aubel
                                aupos = gt_line-aupos
                       binary search.
    if sy-subrc = 0.
      l_tabix = sy-tabix.
      assign component 'MEINS' of structure <ls_out> to <l_f1>.
      <l_f1> = gt_vbfa-meins.
     assign component 'RFMNG' of structure <ls_out> to <l_f1>.
      clear l_rfmng.
      loop at gt_vbfa from l_tabix.
        if ( gt_vbfa-aubel ne gt_line-aubel or
             gt_vbfa-aupos ne gt_line-aupos ).
          exit.
        endif.
        case gt_vbfa-vbtyp_n.
          when 'M' or 'O'.
            add gt_vbfa-rfmng to l_rfmng.
          when 'N' or 'P' or 'S'.
            subtract gt_vbfa-rfmng from l_rfmng.
        endcase.
      endloop.
      <l_f1> = gt_line-kwmeng - abs( l_rfmng ).
    endif.
* Get MAWB text
    assign component 'MAWBT' of structure <ls_out> to <l_f1>.
    perform get_header_text using    c_id_mawb gt_line-vbeln
                            changing <l_f1>.
* Get HAWB text
    assign component 'HAWBT' of structure <ls_out> to <l_f1>.
    perform get_header_text using    c_id_hawb gt_line-vbeln
                            changing <l_f1>.
* Get Flight/Carrier text
    assign component 'FLIGH' of structure <ls_out> to <l_f1>.
    perform get_header_text using    c_id_flight gt_line-vbeln
                            changing <l_f1>.
    append <ls_out> to <gt_out>.
 endloop.
 
endform.                    " FILL_OUT_TABLE
 
*&---------------------------------------------------------------------*
*&      Form GET_HEADER_TEXT
*&---------------------------------------------------------------------*
*       Get Header Text
*----------------------------------------------------------------------*
*      -->P_TDID       Text ID
*      -->P_VBELN      Billing Doc#
*      <--P_TEXT       Return text
*----------------------------------------------------------------------*
form get_header_text using    p_tdid like thead-tdid
                               p_vbeln like vbrk-vbeln
                      changing p_text type c.
 
 data: l_tdname like thead-tdname,
        l_tdline like tline-tdline.
 
 data: lt_tline like tline occurs 0 with header line.
 
 l_tdname = p_vbeln.
 
 call function 'READ_TEXT'
    exporting
      id       = p_tdid
      language = sy-langu
      name     = l_tdname
      object   = c_soitmobj
    tables
      lines    = lt_tline
    exceptions
      others   = 8.
 if sy-subrc = 0.
    loop at lt_tline to 4.              "Maximum included 4 lines
      if l_tdline is initial.
        l_tdline = lt_tline-tdline.
      else.
        concatenate l_tdline lt_tline-tdline into l_tdline
          separated by '/'.
      endif.
    endloop.
    p_text = l_tdline.
 endif.
 
endform.                    " GET_HEADER_TEXT
 
*&---------------------------------------------------------------------*
*&      Form ALV_OUTPUT
*&---------------------------------------------------------------------*
*       Generate ALV report
*----------------------------------------------------------------------*
form alv_output.
 
 data: ls_layout type slis_layout_alv,
        lt_sort   type slis_t_sortinfo_alv,
        ls_sort   type slis_sortinfo_alv.
 
 ls_layout-colwidth_optimize = 'X'.
 
* Sorting Options
 ls_sort-spos = 1.
 ls_sort-fieldname = 'KUNNR'.
 ls_sort-up = 'X'.            " Ascending
 ls_sort-subtot = 'X'.        " Calc subtotals
 append ls_sort to lt_sort.
 
* Display ALV
 call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat             = gt_fieldcata[] "Field Catalog
      is_layout               = ls_layout       "Layout
      i_save                  = g_save          "'A'
      is_variant              = g_variant       "Variant
      it_sort                 = lt_sort[]       "Sorting
      i_callback_program      = g_repid         "Callback this program
      i_callback_user_command = 'USER_COMMAND' "User-command handling
      i_callback_top_of_page = 'TOP_OF_PAGE'   "Top-of-page display
    tables
      t_outtab                = <gt_out>
    exceptions
      program_error           = 1
      others                  = 2.
 
endform.                    " ALV_OUTPUT
 
*&---------------------------------------------------------------------*
*&      Form USER_COMMAND
*&---------------------------------------------------------------------*
*       ALV User-command Callback Subroutine
*----------------------------------------------------------------------*
form user_command using p_ucomm     like sy-ucomm
                        ps_selfield type slis_selfield.
 
 data: l_kunnr like kna1-kunnr, "Customer#
        l_vbeln like vbrk-vbeln, "Billing Doc#
        l_aubel like vbak-vbeln, "Sales Order#
        l_vgbel like likp-vbeln, "Delivery Doc#
        l_matnr like mara-matnr. "Material#
 
 if p_ucomm = '&IC1'        "SAP standard code for double-clicking
     and not ( ps_selfield-value is initial ).
 
    case ps_selfield-fieldname.
* Customer# is selected
      when 'KUNNR'.
        l_kunnr = ps_selfield-value.
        set parameter id 'KUN' field l_kunnr.
        call transaction 'XD03' and skip first screen.
* Billing Doc# is selected
      when 'VBELN'.
        l_vbeln = ps_selfield-value.
        set parameter id 'VF' field l_vbeln.
        call transaction 'VF03' and skip first screen.
* SO Doc# is selected
      when 'AUBEL'.
        l_aubel = ps_selfield-value.
        set parameter id 'AUN' field l_aubel.
        call transaction 'VA03' and skip first screen.
* Delivery Doc# is selected
      when 'VGBEL'.
        l_vgbel = ps_selfield-value.
        set parameter id 'VL' field l_vgbel.
        call transaction 'VL03' and skip first screen.
* Material# is selected
      when 'MATNR'.
        l_matnr = ps_selfield-value.
        set parameter id 'MAT' field l_matnr.
        set parameter id 'MXX' field 'K'.         "Basic View
        set parameter id 'KAR' field c_matcltype. "Material Class
        call transaction 'MM03' and skip first screen.
    endcase.
 
 endif.
 
endform.                    " USER_COMMAND
 
 
*&---------------------------------------------------------------------*
*&      Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       ALV Top-of-page Callback Subroutine
*----------------------------------------------------------------------*
form top_of_page.
 
 call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
      it_list_commentary = gt_top_of_page.
 
endform.                    " TOP_OF_PAGE
*&---------------------------------------------------------------------*
*&      Form SUM_GTOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
* --> p1        text
* <-- p2        text
*----------------------------------------------------------------------*
form sum_gtout .
 field-symbols: <ls_out>.
 field-symbols: <l_f1>, <l_f2>, <l_f3>, <l_f4>, <l_ft>.
 
* ASSIGN LOCAL COPY OF INITIAL LINE OF <GT_OUT> TO <LS_OUT>.
 loop at <gt_out> assigning <ls_out>.
*    <LS_OUT>-S_TOT = <LS_OUT>-S_TSTA + <LS_OUT>-S_DIST +
*                     <LS_OUT>-S_TTOT + <LS_OUT>-S_TTAD.
*     <LS_OUT>-S_TOT = <LS_OUT>-S_TSTA.
    assign component 'S_TOT' of structure <ls_out> to <l_ft>.
    assign component 'S_TSTA' of structure <ls_out> to <l_f1>.
    assign component 'S_DIST' of structure <ls_out> to <l_f2>.
    assign component 'S_TTOT' of structure <ls_out> to <l_f3>.
    assign component 'S_TTAD' of structure <ls_out> to <l_f4>.
    <l_ft> = <l_f1> + <l_f2> + <l_f3> + <l_f4>.
    modify <gt_out> from <ls_out>.
 endloop.
endform.                    " SUM_GTOUT
*&---------------------------------------------------------------------*
*&      Form GET_PACKAGE_GROUP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
* --> p1        text
* <-- p2        text
*----------------------------------------------------------------------*
form get_package_group .
 data: l_clint like kssk-objek.
 data: l_package_name like klah-class.
 data: l_parnt like tkchw-parnt.
 
 select single clint
 into   l_clint
 from   kssk
 where objek = gt_line-matnr and
         mafid = 'O'     and
         klart = '001'.
 
 select single class
 into   l_package_name
 from   klah
 where clint = l_clint.
 
* Get Hierarchy data
 read table gt_tkchw with key wert1 = l_package_name.
 if sy-subrc = 0.
    l_parnt = gt_tkchw-parnt.
    read table gt_tkchw with key nodid = l_parnt.
    if sy-subrc = 0.
*      READ TABLE GT_TKCHNT WITH KEY KEYID = GT_TKCHW-WERT1.
*       IF SY-SUBRC = 0.
      gt_line-parnt = gt_tkchw-wert1.
*       ENDIF.
 
    endif.
 endif.
 
 
 
endform.                    " GET_PACKAGE_GROUP
 

 

原创粉丝点击