Skip to Content

*&———————————————————————*

*& Report  Z_COPA_PROD_VARIANCE

*&

*&———————————————————————*

*& Description : Product variance report

*& Date : 29.01.2013

*& Developer : Fariha kazi

*&———————————————————————*

REPORT  z_copa_prod_variance.

TABLES: cobk,coep,aufk.

TYPE-POOLS : slis.

TYPES: BEGIN OF ty_mara,

  matnr TYPE matnr_d,

  matkl TYPE mara-matkl,

  wrkst TYPE mara-wrkst,

  END OF ty_mara.

DATA: gt_mara TYPE TABLE OF ty_mara,

      gs_mara TYPE ty_mara.

TYPES: BEGIN OF ty_marc,

  matnr TYPE matnr_d,

  werks TYPE marc-werks,

  prctr TYPE marc-prctr,

  END OF ty_marc.

DATA: gt_marc TYPE TABLE OF ty_marc,

      gs_marc TYPE ty_marc.

TYPES : BEGIN OF ty_afpo,

    aufnr TYPE afpo-aufnr,

    matnr TYPE afpo-matnr,

    pwerk TYPE afpo-pwerk,

    lgort TYPE afpo-lgort,

    dauat TYPE afpo-dauat,

END OF ty_afpo.

DATA: gt_afpo TYPE TABLE OF ty_afpo,

      gs_afpo TYPE ty_afpo.

TYPES : BEGIN OF ty_keko,

        matnr TYPE keko-matnr,

            werks TYPE keko-werks,

            kalnr TYPE keko-kalnr,

            losgr TYPE keko-losgr,

END OF ty_keko.

DATA : gt_keko TYPE TABLE OF ty_keko,

      gs_keko TYPE ty_keko.

TYPES : BEGIN OF ty_ckis,

  kalnr TYPE ckis-kalnr,

  werks TYPE ckis-werks,

  matnr TYPE ckis-matnr,

  menge TYPE ckis-menge,

  opreis TYPE ckis-opreis,

  END OF ty_ckis.

DATA: gt_ckis TYPE TABLE OF ty_ckis,

      gt_ckis_temp TYPE TABLE OF ty_ckis,

      gs_ckis TYPE ty_ckis.

DATA: gt_fcat     TYPE slis_t_fieldcat_alv,

      gv_gjahr    TYPE gjahr,

*added by Dipesh

      gv_gjahr_prv TYPE gjahr.

TYPES : BEGIN OF ty_coep,

      objnr     LIKE coep-objnr,

      werks     LIKE aufk-werks,”*plant

      matnr     TYPE matnr,”*Co-product

      budat     LIKE cobk-budat,”*posting Date

      megbtr    LIKE coep-mbgbtr,”Co-product quantity

      wogbtr    LIKE coep-wogbtr,”Co-product Value in Object Currency

      belnr     LIKE cobk-belnr,

      buzei     LIKE coep-buzei,

      gjahr     LIKE cobk-gjahr,

      objnr1     LIKE coep-objnr,

      kstar     LIKE coep-kstar,

      kokrs     LIKE cobk-kokrs,

      perio     TYPE monat,

      aufnr TYPE aufnr,

      END OF ty_coep.

TYPES: BEGIN OF ty_cobk,

        kokrs TYPE coep-kokrs,

        belnr TYPE coep-belnr,

        budat TYPE cobk-budat,

*          gjahr type coep-gjahr,

  END OF ty_cobk.

TYPES : BEGIN OF ty_final,

        werks     LIKE aufk-werks,”*plant

        aufnr     LIKE aufk-aufnr,”*Process Order

        budat     LIKE cobk-budat,”*posting Date

        dauat     LIKE afpo-dauat,

        kstar     LIKE coep-kstar,

        prctr     LIKE marc-prctr,

        wrkst     LIKE mara-wrkst,

        matkl     LIKE mara-matkl,

*        posnr     LIKE afpo-posnr,

        matnr     LIKE afpo-matnr,”*Co-product

        objnr     LIKE coep-objnr,”*Objnr

        megbtr    LIKE coep-mbgbtr,”o/p qty

        wogbtr    LIKE coep-wogbtr,”o/p val

        totqty     LIKE coep-mbgbtr,”tot qty

        totval LIKE coep-wogbtr,”totval

        objnr1    LIKE coep-objnr,”*Component Objnr

        matnr2    LIKE afpo-matnr,”*Component

        tarqty      LIKE coep-megbtr, “Total Target Qty

        tarval      LIKE coep-wogbtr, “Total Target Value in Object Currency

        compqty   LIKE coep-mbgbtr,”totComponent quantity

        compval   LIKE coep-wogbtr,”totComponent Value in Object Currency

        perunit    LIKE coep-wogbtr, “per unit value

        varqty      LIKE coep-megbtr, “Variance Qty

        varval      LIKE coep-wogbtr, “Variance Value in Object Currency

        lgort(6),”Storage Location

*        charg(10),”Batch Number

        belnr     LIKE cobk-belnr,

        buzei     LIKE coep-buzei,

*        gjahr     LIKE cobk-gjahr,

        kalnr TYPE keko-kalnr,

        losgr     LIKE keko-losgr, “Lot Size for Product Costing

        type      TYPE char30,

       END OF ty_final.

DATA : itab1      TYPE TABLE OF ty_final WITH HEADER LINE.

DATA : gt_coep_temp    TYPE STANDARD TABLE OF ty_coep,

       gs_itab    LIKE LINE OF gt_coep_temp,

       gt_total_comp   TYPE STANDARD TABLE OF ty_coep,

       wa_total_comp TYPE ty_coep,

       gt_total_comp_temp TYPE STANDARD TABLE OF ty_coep.

DATA : gt_cobk    TYPE TABLE OF ty_cobk,

       gs_cobk    LIKE LINE OF gt_cobk,

       gt_coep    TYPE TABLE OF ty_coep,

       gs_coep    LIKE LINE OF gt_coep,

       bukrs      LIKE t001-bukrs VALUE ‘1001’,

       gv_perio   LIKE bapi0002_4-fiscal_period,

       gv_day     TYPE char10.

DATA : gv_matnr   TYPE coep-matnr,

        lv_objnr  TYPE coep-objnr.

RANGES : matnr1 FOR coep-matnr.

RANGES : matnr2 FOR coep-matnr.

SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.

PARAMETERS : kokrs LIKE cobk-kokrs OBLIGATORY DEFAULT ‘1001’.

SELECT-OPTIONS : budat FOR cobk-budat ,” OBLIGATORY,

                 matnr FOR coep-matnr,

                 werks FOR coep-werks NO INTERVALS.

“objnr FOR coep-objnr.”Remove after Testing

SELECT-OPTIONS ip_auart FOR aufk-auart NO INTERVALS.

SELECTION-SCREEN END OF BLOCK a1.

REFRESH : matnr1[],matnr2[].

CLEAR : matnr,matnr1,matnr2.

LOOP AT matnr.

  gv_matnr = matnr-low.

  CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’

    EXPORTING

      input  = gv_matnr

    IMPORTING

      output = gv_matnr.

  matnr1 = matnr.

  matnr1-low = gv_matnr.

  matnr2 = matnr.

  SHIFT gv_matnr LEFT DELETING LEADING space.

  matnr2-low = gv_matnr.

  APPEND matnr1.

  APPEND matnr2.

  CLEAR : matnr,matnr1,matnr2.

ENDLOOP.

REFRESH matnr.

APPEND LINES OF matnr2 TO matnr.

APPEND LINES OF matnr1 TO matnr.

TYPES:BEGIN OF ty_total_qty,

  kokrs TYPE kokrs,

  belnr TYPE coep-belnr,

  buzei TYPE coep-buzei,

  objnr TYPE objnr,

  werks TYPE werks_d,

  matnr TYPE matnr,

  wogbtr TYPE coep-wogbtr,

  megbtr TYPE coep-megbtr,

  gjahr TYPE gjahr,

  perio TYPE monat,

  aufnr TYPE afpo-aufnr,

  END OF ty_total_qty.

DATA: gt_total_matnr TYPE TABLE OF ty_total_qty.

DATA: gt_total_matnr_temp TYPE TABLE OF ty_total_qty,

      wa_total_matnr TYPE ty_total_qty.

START-OF-SELECTION.

  CALL FUNCTION ‘BAPI_COMPANYCODE_GET_PERIOD’

    EXPORTING

      companycodeid = bukrs

      posting_date  = budat-low

    IMPORTING

      fiscal_period = gv_perio

      fiscal_year   = gv_gjahr.

  gv_gjahr_prv = gv_gjahr – 1.

*  Get orders for confirmation with this period

*  Out of the above orders consider those within COBK

*  Get total qty confirmed previously if any for these orders

*  Get materials used.

* Get all orders confirmed in this period range.

  SELECT  belnr

          gjahr

          kokrs

          buzei

          wogbtr

          megbtr

          matnr

          objnr

          werks

          kstar

          perio

    INTO CORRESPONDING FIELDS OF TABLE gt_coep

    FROM coep

    WHERE

    kokrs = kokrs

      AND gjahr = gv_gjahr

      AND perio = gv_perio

      AND werks IN werks

      AND matnr IN matnr

      AND beknz = ‘L’

      AND megbtr < 0

      AND vrgng = ‘COIN’

      AND wrttp = ’04’.

  IF sy-subrc EQ 0.

    SORT gt_coep ASCENDING.

    SELECT kokrs belnr budat FROM cobk

      INTO TABLE gt_cobk

      FOR ALL ENTRIES IN gt_coep

     WHERE kokrs = gt_coep-kokrs

      AND belnr = gt_coep-belnr

      AND gjahr = gv_gjahr

      AND vrgng = ‘COIN’.

    “AND budat in budat.

    gt_coep_temp[] =  gt_coep[].

*         Get dates & other data.

    LOOP AT gt_coep_temp INTO gs_coep.

      gs_coep-objnr1 = gs_coep-objnr.

      IF gs_coep-objnr1+0(2) <> ‘OR’.

        REPLACE FIRST OCCURRENCE OF ‘OP’ IN gs_coep-objnr1 WITH ‘OR’.

      ENDIF.

      lv_objnr = gs_coep-objnr.

      REPLACE FIRST OCCURRENCE OF ‘OR’ IN lv_objnr WITH space .

      CONDENSE   lv_objnr.

      gs_coep-aufnr = lv_objnr.

      READ TABLE gt_cobk INTO gs_cobk WITH KEY kokrs = gs_coep-kokrs belnr = gs_coep-belnr.

      gs_coep-budat = gs_cobk-budat.

      MODIFY gt_coep_temp FROM gs_coep.

    ENDLOOP.

    SORT gt_coep_temp  BY budat.

    DELETE gt_coep_temp WHERE budat NOT IN budat.

    DELETE ADJACENT DUPLICATES FROM gt_coep_temp COMPARING objnr werks matnr.

    IF gt_coep_temp[] IS NOT INITIAL.

*          Get total qty confirmed for above orders  for  every material with their confirmation period & year

*           This will also get

      SELECT kokrs

             belnr

             buzei

             objnr

             werks

             matnr

             wogbtr

             megbtr

            gjahr

            perio

        FROM coep

        INTO TABLE gt_total_matnr

        FOR ALL ENTRIES IN gt_coep_temp

        WHERE

        kokrs = gt_coep_temp-kokrs

        AND

        objnr =   gt_coep_temp-objnr

        AND

        werks = gt_coep_temp-werks

        AND gjahr IN (gv_gjahr,gv_gjahr_prv)

        AND   matnr = gt_coep_temp-matnr

        AND vrgng = ‘COIN’

        AND wrttp = ’04’.

      .

*           Sum total costs/qty for material irrespective of perio & year also get first order confirmation period for cost estimate

      SORT gt_total_matnr BY objnr gjahr perio werks matnr.

      gt_total_matnr_temp[] = gt_total_matnr[].

      REFRESH: gt_total_matnr[].

      LOOP AT gt_total_matnr_temp INTO wa_total_matnr.

        CLEAR:wa_total_matnr-gjahr,wa_total_matnr-perio,wa_total_matnr-belnr,wa_total_matnr-buzei.

        lv_objnr = wa_total_matnr-objnr.

        REPLACE FIRST OCCURRENCE OF ‘OP’ IN lv_objnr WITH space .

        REPLACE FIRST OCCURRENCE OF ‘OR’ IN lv_objnr WITH space .

        CONDENSE   lv_objnr.

        wa_total_matnr-aufnr = lv_objnr.

*                MULTIPLY WA_TOTAL_MATNR-MEGBTR BY -1.

*                MULTIPLY  WA_TOTAL_MATNR-WOGBTR BY -1.

        COLLECT wa_total_matnr INTO gt_total_matnr.

        CLEAR: wa_total_matnr.

      ENDLOOP.

      CLEAR : gs_coep.

*           Get Components/Materials used for producing materials above from COEP

      SELECT belnr

              gjahr

              kokrs

              buzei

              wogbtr

              megbtr

              matnr

              objnr

              werks

              kstar

              perio

        FROM coep

        INTO CORRESPONDING FIELDS OF TABLE gt_total_comp

        “APPENDING CORRESPONDING FIELDS OF TABLE gt_ckis

        FOR ALL ENTRIES IN gt_coep_temp

        WHERE kokrs  =  gt_coep_temp-kokrs

        AND   objnr  =  gt_coep_temp-objnr1

        AND   vrgng =  ‘COIN’

        AND gjahr IN (gv_gjahr,gv_gjahr_prv)

       “AND matnr  <> space ” performance delete later

         AND megbtr GT 0.

      DELETE gt_total_comp WHERE matnr IS INITIAL.

*           Total Actual cost/qty for components irrespective of perio & year i.e for previous confirmations also

      SORT gt_coep_temp ASCENDING BY objnr matnr.

      SORT gt_total_comp ASCENDING BY objnr matnr.

      SORT gt_total_comp.

      gt_total_comp_temp[] = gt_total_comp[].

      REFRESH: gt_total_comp[].

      LOOP AT gt_total_comp_temp INTO wa_total_comp.

        CLEAR:wa_total_comp-gjahr ,wa_total_comp-perio,wa_total_comp-belnr,wa_total_comp-buzei.

        COLLECT wa_total_comp INTO gt_total_comp.

        CLEAR: wa_total_comp.

      ENDLOOP.

*           material type

      SELECT  matnr

              matkl

              wrkst

        FROM mara

        INTO TABLE gt_mara

        FOR ALL ENTRIES IN gt_total_matnr

        WHERE matnr = gt_total_matnr-matnr.

*           profit centre

      SELECT matnr

             werks

             prctr

        FROM marc

        INTO  TABLE gt_marc

        FOR ALL ENTRIES IN gt_total_matnr

        WHERE matnr = gt_total_matnr-matnr

        AND werks = gt_total_matnr-werks.

*          Order details like order type storage location

      SELECT  aufnr

              matnr

              pwerk

              lgort

              dauat

            FROM afpo

            INTO TABLE gt_afpo

            FOR ALL ENTRIES IN gt_total_matnr

            WHERE aufnr = gt_total_matnr-aufnr

            AND matnr = gt_total_matnr-matnr.

      DELETE ADJACENT DUPLICATES FROM gt_afpo COMPARING aufnr matnr pwerk.

*          Cost estimate for components

*current period only

      CONCATENATE budat-low+0(4) budat-low+4(2) ’01’ INTO gv_day.

      SELECT  matnr

              werks

              kalnr

              losgr

         INTO TABLE gt_keko

        FROM keko

        FOR ALL ENTRIES IN gt_coep_temp

        WHERE matnr = gt_coep_temp-matnr

        AND werks = gt_coep_temp-werks

        AND kadky = gv_day.

      DELETE ADJACENT DUPLICATES FROM gt_keko  COMPARING matnr werks.

      SELECT  kalnr

              werks

              matnr

              menge

              opreis

        FROM ckis

        INTO TABLE gt_ckis

        FOR ALL ENTRIES IN gt_keko

        WHERE kalnr = gt_keko-kalnr

        AND typps = ‘M’

        AND kadky = gv_day

        AND bwvar = ‘KF1’.                              “#EC CI_NOFIRST

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

      RANGES: r_matnr FOR mara-matnr.

      r_matnr-sign = ‘I’.

      r_matnr-option = ‘EQ’.

*           Calculate Target Costs for Material & components from cost estimate

      LOOP AT gt_total_matnr INTO wa_total_matnr.

        CLEAR : itab1 ,gs_itab,gs_afpo,gs_mara,gs_marc,gs_keko.

        READ TABLE gt_mara INTO gs_mara WITH KEY matnr = wa_total_matnr-matnr.

        itab1-matkl = gs_mara-matkl.

        itab1-wrkst = gs_mara-wrkst.

        READ TABLE gt_marc INTO gs_marc WITH KEY matnr = wa_total_matnr-matnr

                                           werks = wa_total_matnr-werks.

        itab1-prctr = gs_marc-prctr.

        READ TABLE gt_coep_temp INTO gs_itab WITH KEY objnr = wa_total_matnr-objnr werks = wa_total_matnr-werks matnr = wa_total_matnr-matnr.

        READ TABLE gt_afpo INTO gs_afpo WITH KEY aufnr = wa_total_matnr-aufnr  matnr = wa_total_matnr-matnr.

        itab1-matnr  = gs_itab-matnr.

        itab1-werks  = gs_afpo-pwerk.

        itab1-lgort  = gs_afpo-lgort.

        itab1-aufnr  = gs_afpo-aufnr.

        itab1-dauat  = gs_afpo-dauat.

        itab1-budat  = gs_itab-budat.

        itab1-objnr  = gs_itab-objnr.

        itab1-kstar  = gs_itab-kstar.

        “Total Qty for material

        itab1-totqty = wa_total_matnr-megbtr .

        itab1-totval = wa_total_matnr-wogbtr .

        itab1-megbtr = itab1-totqty * -1.

        itab1-wogbtr = wa_total_matnr-wogbtr * -1 .

        READ TABLE gt_keko INTO gs_keko WITH KEY  matnr = itab1-matnr

                                                      werks = itab1-werks.

        itab1-losgr = gs_keko-losgr.

* From Cost estimate calculate components Target Qty & Value with Variance.

* it can be that there may be some components whose estimate is present but entry is not there in COEP i.e. not used whose total used qty will be zero then

        LOOP AT gt_ckis INTO gs_ckis WHERE kalnr  = gs_keko-kalnr .”use this for adding components even if they were not issued

          CLEAR : wa_total_comp.

          READ TABLE gt_total_comp INTO wa_total_comp WITH KEY objnr =  wa_total_matnr-objnr  werks = gs_keko-werks matnr = gs_ckis-matnr.

          r_matnr-low = wa_total_comp-matnr.

          APPEND r_matnr.

          IF  wa_total_matnr-matnr  <> wa_total_comp-matnr. ” remove same component & matnr

            IF itab1-losgr NE 0.

              itab1-tarqty = ( gs_ckis-menge  * itab1-megbtr ) / itab1-losgr.

              itab1-tarval = ( gs_ckis-opreis * itab1-tarqty ).

            ENDIF.

            itab1-compqty  = wa_total_comp-megbtr.

            itab1-compval  = wa_total_comp-wogbtr.

            itab1-varqty     =  itab1-compqty – itab1-tarqty .

            itab1-varval     = itab1-compval – itab1-tarval  .

            itab1-matnr2   =  gs_ckis-matnr.

            itab1-perunit   = wa_total_comp-wogbtr / wa_total_comp-megbtr.

            APPEND itab1.

          ENDIF.

        ENDLOOP.

        gt_total_comp_temp[] = gt_total_comp[].

        DELETE gt_total_comp_temp WHERE objnr NE wa_total_matnr-objnr.

        DELETE gt_total_comp_temp WHERE matnr IN r_matnr.

        LOOP AT gt_total_comp_temp INTO wa_total_comp.

          IF  wa_total_matnr-matnr  <> wa_total_comp-matnr. ” remove same component & matnr

            IF itab1-losgr NE 0.

              itab1-tarqty = 0.

              itab1-tarval = 0.

            ENDIF.

            itab1-compqty  = wa_total_comp-megbtr.

            itab1-compval  = wa_total_comp-wogbtr.

            itab1-varqty     =  itab1-compqty – itab1-tarqty .

            itab1-varval     = itab1-compval – itab1-tarval  .

            itab1-matnr2   = wa_total_comp-matnr.

            itab1-perunit   = wa_total_comp-wogbtr / wa_total_comp-megbtr.

            APPEND itab1.

          ENDIF.

        ENDLOOP.

        CLEAR wa_total_comp.

*

      ENDLOOP.

      SORT itab1 ASCENDING BY objnr.

      PERFORM fieldcat USING gt_fcat.

      PERFORM write_output.

    ELSE.

      MESSAGE ‘No data in selected date range.’ TYPE ‘S’.

    ENDIF.

  ELSE.

    MESSAGE ‘No data exists.’ TYPE ‘S’.

  ENDIF.

*&———————————————————————*

*&      Form  fieldcat

*&———————————————————————*

*       text

*———————————————————————-*

*      –>LT_FCAT    text

*———————————————————————-*

FORM fieldcat USING lt_fcat TYPE slis_t_fieldcat_alv.

  DATA: ls_fcat   TYPE slis_fieldcat_alv,

        lv_count  TYPE i.

  REFRESH lt_fcat.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘WERKS’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Plant’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘AUFNR’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Production Order’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘BUDAT’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Posting Date’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘DAUAT’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Order Type’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘PRCTR’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Profit Center’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘MATKL’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Material Group’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘MATNR’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Produced Material’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘MEGBTR’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Output Quantity’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘WOGBTR’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Output Value’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘TOTQTY’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Total Quantity’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘TOTVAL’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Total Value’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘MATNR2’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Component’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘TARQTY’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Target Qty’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘TARVAL’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Target Value’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘COMPQTY’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Component Quantity’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘COMPVAL’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Component Value’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘PERUNIT’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Per Unit Value’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘VARQTY’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Variance Qty’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘VARVAL’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Variance Value’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

  ls_fcat-fieldname = ‘LGORT’.

  ls_fcat-tabname   = ‘ITAB1’.

  ls_fcat-seltext_m = ‘Storge Location’.

  ls_fcat-col_pos      = lv_count.

  APPEND ls_fcat TO lt_fcat.

  lv_count = lv_count + 1.

  CLEAR ls_fcat.

ENDFORM.                    “FIELDCAT

*&———————————————————————*

*&      Form  WRITE_OUTPUT

*&———————————————————————*

*       text

*———————————————————————-*

FORM write_output.

  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’

    EXPORTING

      it_fieldcat = gt_fcat[]

    TABLES

      t_outtab    = itab1.

ENDFORM.                    “WRITE_OUTPUT

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Joe Cravero

    Depending on your indexing, you may want to add LEDNR = 0 to the COEP selects.  You should probably have the KEKO deletion of adjacent duplicates based on KALNR (rather than matnr + werks) and depending on your data, you may want to add LEDNR = 0 and BZOBJ = 0 on the CKIS select.

    (1) 

Leave a Reply