Advertisement
sinke

ZFI30290_CLASSES

Nov 10th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 38.10 KB | None | 0 0
  1.  
  2. Code listing for: ZFI30290_CLASSES
  3. Description: Klase za program ZFI30290
  4. *&---------------------------------------------------------------------*
  5. *&  Include           ZFI30290_CLASSES
  6. *&---------------------------------------------------------------------*
  7. class lcl_app definition.
  8.   public section.
  9.     types:  begin of t_out,
  10.               bukrs       type bukrs,
  11.               butxt       type butxt,
  12.               saknr_lact  type saknr,
  13.               txt50_lact  type txt50_skat,
  14.               saknr_kons  type saknr,
  15.               txt50_kons  type txt50_skat,
  16.               ktopl       type ktopl,
  17.               saknr       type saknr,
  18.               txt50       type txt50_skat,
  19.               bklas       type bklas,
  20.               bkbez       type bkbez,
  21.               mtart       type mtart,
  22.               mtbez       type mtbez,
  23.               matnr       type matnr,
  24.               maktx       type maktx,
  25.               dispo       type dispo,
  26.               dsnam       type dsnam,
  27.               zwtyp       type zwtyp,
  28.               meins       type meins,
  29.               werks       type werks_d,
  30.               name1       type t001w-name1,
  31.               lbkum       type mbew-lbkum,
  32.               lbkum_kg    type mbew-lbkum,
  33.               salk3       type salk3,
  34.               mgvbr       type mgvbr,
  35.               mgvbr_kg    type mgvbr,
  36.               wgvbr       type wgvbr,
  37.               letztbew    type letztbew,
  38.               menge       type mdbs-menge,
  39.             end of t_out,
  40.  
  41.             begin of t_material_valuation,
  42.               bukrs type bukrs,
  43.               ktopl type ktopl,
  44.               matnr type matnr,
  45.               bwkey type bwkey,
  46.               bklas type bklas,
  47.               saknr type saknr,
  48.               lfgja type lfgja,
  49.               lfmon type lfmon,
  50.               lbkum type mbew-lbkum,
  51.               salk3 type salk3,
  52.             end of t_material_valuation,
  53.  
  54.             begin of t_t030,
  55.               ktopl type ktopl,
  56.               bklas type bklas,
  57.               konts type saknr,
  58.             end of t_t030,
  59.  
  60.             begin of t_ska1,
  61.               saknr_lact type saknr,
  62.               saknr_grup type saknr,
  63.               saknr_podu type saknr,
  64.             end of t_ska1,
  65.  
  66.             begin of t_mrp,
  67.               matnr type matnr,
  68.               werks type werks_d,
  69.               dispo type dispo,
  70.               dsnam type dsnam,
  71.             end of t_mrp,
  72.  
  73.             begin of t_werks,
  74.               werks type werks_d,
  75.               name1 type t001w-name1,
  76.               bukrs type bukrs,
  77.             end of t_werks,
  78.  
  79.             begin of t_s031,
  80.               lgort type s031-lgort,
  81.               lgobe type t001l-lgobe,
  82.               mgvbr type s031-mgvbr,
  83.               basme type s031-basme,
  84.               wgvbr type s031-wgvbr,
  85.               hwaer type s031-hwaer,
  86.             end of t_s031,
  87.  
  88.  
  89.             tt_out                        type standard table of t_out,
  90.             tt_material_valuation         type standard table of t_material_valuation,
  91.             tt_t030                       type standard table of t_t030,
  92.             tt_bklas                      type range of bklas,
  93.             tt_ska1                       type hashed table of t_ska1 with unique key saknr_podu,
  94.             tt_mrp                        type hashed table of t_mrp with unique key matnr werks,
  95.             tt_werks                      type hashed table of t_werks with unique key werks.
  96.  
  97.     class-data:
  98.       app type ref to lcl_app.
  99.  
  100.     class-methods:
  101.       make_it_so,
  102.       f4_saknr_lact,
  103.       f4_saknr,
  104.       authority_check,
  105.       find_layout,
  106.       check_layout.
  107.  
  108.  
  109.     data:
  110.       mt_out                              type tt_out,
  111.       mt_fc                               type lvc_t_fcat.
  112.  
  113.     methods:
  114.       constructor,
  115.       main,
  116.       handle_pbo,
  117.       handle_pai                          importing i_ucomm     type syucomm.
  118.  
  119.  
  120.  
  121.  
  122.   private section.
  123.  
  124.     data:
  125.           mt_t001                         type hashed table of t001 with unique key bukrs,
  126.           mt_ska1                         type tt_ska1,
  127.           mt_skat                         type hashed table of skat with unique key ktopl saknr,
  128.           mt_makt                         type hashed table of makt with unique key matnr,
  129.           mt_t025t                        type hashed table of t025t with unique key bklas,
  130.           mt_mara                         type hashed table of mara with unique key matnr,
  131.           mt_mrp                          type hashed table of t_mrp with unique key matnr werks,
  132.           mt_t134t                        type hashed table of t134t with unique key mtart,
  133.           mt_werks                        type tt_werks,
  134.           mt_ztwtyp                       type hashed table of ztwtyp with unique key extwg.
  135.  
  136.     data:
  137.       m_salv                              type ref to cl_salv_table,
  138.  
  139.       m_alv                               type ref to cl_gui_alv_grid,
  140.       m_splitter                          type ref to cl_gui_splitter_container,
  141.       m_container                         type ref to cl_gui_container,
  142.       m_html_container                    type ref to cl_gui_container,
  143.       m_header_document                   type ref to cl_dd_document.
  144.  
  145.     methods:
  146.       select_material_valuation           changing  c_mbew  type tt_material_valuation,
  147.       select_mov_for_curr_stocks          importing i_mbew  type tt_material_valuation
  148.                                           changing  c_out   type tt_out,
  149.       select_last_goods_movement          importing i_mbew  type tt_material_valuation
  150.                                           changing  c_out   type tt_out,
  151.       select_order_item                   importing i_mbew  type tt_material_valuation
  152.                                           changing  c_out   type tt_out,
  153.       get_t030                            changing  c_t030  type tt_t030,
  154.       get_bklas                           importing i_t030  type tt_t030
  155.                                           changing  c_bklas type tt_bklas,
  156.       on_link_click                       for event hotspot_click of cl_gui_alv_grid importing e_row_id
  157.                                                                                                es_row_no,
  158.       display_s031_data                   importing i_row type t_out,
  159.       get_list_header                     returning value(r_header) type lvc_title,
  160.  
  161.       build_fc                            changing  c_fc    type lvc_t_fcat,
  162.       display_header.
  163.  
  164.  
  165.  
  166. endclass. "lcl_app DEFINITION
  167.  
  168.  
  169.  
  170. *----------------------------------------------------------------------*
  171. *       CLASS lcl_app IMPLEMENTATION
  172. *----------------------------------------------------------------------*
  173. *
  174. *----------------------------------------------------------------------*
  175. class lcl_app implementation.
  176.  
  177.   method make_it_so.
  178.     if lcl_app=>app is initial.
  179.       create object lcl_app=>app.
  180.     endif.
  181.  
  182.     lcl_app=>app->main( ).
  183.   endmethod.                    "make_it_so
  184.  
  185.  
  186.  
  187.   method constructor.
  188.  
  189.     if s_spmon-high is initial.
  190.       s_spmon-high = s_spmon-low.
  191.     endif.
  192.  
  193.     me->build_fc( changing  c_fc  = me->mt_fc ).
  194.  
  195. *   Daj mi sva konta na svijetu, svaèija...sve mi poveži... to mi treba... to mi radi. aaaaaaa...
  196.     select distinct
  197.       ska1_poduzeca~saknr as saknr_podu
  198.       ska1_grupe~saknr as saknr_grup
  199.       zlkon01~saknr as saknr_lact
  200.     into corresponding fields of table me->mt_ska1
  201.     from
  202.         zlkon01 inner join ska1 as ska1_grupe on
  203.           zlkon01~saknr = ska1_grupe~bilkt
  204.         inner join ska1 as ska1_poduzeca on
  205.           ska1_poduzeca~bilkt = ska1_grupe~saknr
  206.         inner join t001 on
  207.           ska1_poduzeca~ktopl = t001~ktopl
  208.     where
  209.         zlkon01~zstock <> '' and
  210.         ska1_grupe~ktopl = 'KONS' and
  211.         t001~bukrs in s_bukrs and
  212.         zlkon01~saknr in s_saknrl and
  213.         ska1_poduzeca~saknr in s_saknr.
  214.  
  215.  
  216.     select * from t001 into table me->mt_t001 where bukrs in s_bukrs.
  217.  
  218.     select * from skat into table me->mt_skat where spras = sy-langu.
  219.  
  220.     select * from mara into table me->mt_mara.
  221.  
  222.     select * from makt into table me->mt_makt where spras = sy-langu.
  223.  
  224.     select * from t025t into table me->mt_t025t where spras = sy-langu.
  225.  
  226.  
  227.     select
  228.       t001w~werks
  229.       t001w~name1
  230.       t001k~bukrs
  231.     from
  232.       t001w inner join t001k on
  233.         t001w~bwkey = t001k~bwkey
  234.     into
  235.       table me->mt_werks
  236.     where
  237.       t001k~bukrs in s_bukrs.
  238.  
  239.     select
  240.       marc~matnr
  241.       marc~werks
  242.       marc~dispo
  243.       t024d~dsnam
  244.     from
  245.        marc inner join t024d on
  246.         marc~dispo = t024d~dispo and
  247.         marc~werks = t024d~werks
  248.     into
  249.       table me->mt_mrp.
  250.  
  251.  
  252.     select * from t134t into table me->mt_t134t where spras = sy-langu.
  253.  
  254.     select * from ztwtyp into table me->mt_ztwtyp.
  255.  
  256.  
  257.   endmethod.                    "constructor
  258.  
  259.  
  260.  
  261.   method main.
  262.     data:
  263.           lt_mbew   type tt_material_valuation,
  264.           ls_mbew   type t_material_valuation,
  265.           ls_ska1   type t_ska1,
  266.           ls_skat   type skat,
  267.           ls_makt   type makt,
  268.           ls_mara   type mara,
  269.           ls_t025t  type t025t,
  270.           ls_t001   type t001,
  271.           ls_mrp    type t_mrp,
  272.           ls_werks  type t_werks,
  273.           ls_t134t  type t134t,
  274.           ls_ztwtyp type ztwtyp,
  275.           ls_out    type t_out.
  276.  
  277.     field-symbols:
  278.           <out> type t_out.
  279.  
  280.     me->select_material_valuation( changing c_mbew = lt_mbew ).
  281.  
  282.     loop at lt_mbew into ls_mbew.
  283.       move-corresponding ls_mbew to ls_out.
  284.       ls_out-werks = ls_mbew-bwkey.
  285.       append ls_out to me->mt_out.
  286.     endloop.
  287.  
  288.     me->select_mov_for_curr_stocks( exporting i_mbew = lt_mbew
  289.                                     changing c_out = me->mt_out ).
  290.  
  291.     me->select_last_goods_movement( exporting i_mbew = lt_mbew
  292.                                     changing c_out = me->mt_out ).
  293.  
  294.     me->select_order_item( exporting i_mbew = lt_mbew
  295.                            changing c_out = me->mt_out ).
  296.  
  297.  
  298.     delete me->mt_out where lbkum = 0 and salk3 = 0 and mgvbr = 0 and wgvbr = 0 and menge <= 0.
  299.  
  300.     loop at me->mt_out assigning <out>.
  301.       read table me->mt_ska1 with table key saknr_podu = <out>-saknr into ls_ska1.
  302.       if sy-subrc = 0.
  303.         <out>-saknr_lact = ls_ska1-saknr_lact.
  304.         <out>-saknr_kons = ls_ska1-saknr_grup.
  305.       endif.
  306.  
  307.       read table me->mt_skat with table key ktopl = <out>-ktopl saknr = <out>-saknr into ls_skat.
  308.       if sy-subrc = 0.
  309.         <out>-txt50 = ls_skat-txt50.
  310.       endif.
  311.  
  312.       read table me->mt_skat with table key ktopl = 'KONS' saknr = <out>-saknr_kons into ls_skat.
  313.       if sy-subrc = 0.
  314.         <out>-txt50_kons = ls_skat-txt50.
  315.       endif.
  316.  
  317.       read table me->mt_skat with table key ktopl = 'LACT' saknr = <out>-saknr_lact into ls_skat.
  318.       if sy-subrc = 0.
  319.         <out>-txt50_lact = ls_skat-txt50.
  320.       endif.
  321.  
  322.       read table me->mt_makt with table key matnr = <out>-matnr into ls_makt.
  323.       if sy-subrc = 0.
  324.         <out>-maktx = ls_makt-maktx.
  325.       endif.
  326.  
  327.       read table me->mt_t025t with table key bklas = <out>-bklas into ls_t025t.
  328.       if sy-subrc = 0.
  329.         <out>-bkbez = ls_t025t-bkbez.
  330.       endif.
  331.  
  332.       read table me->mt_t001 with table key bukrs = <out>-bukrs into ls_t001.
  333.       if sy-subrc = 0.
  334.         <out>-butxt = ls_t001-butxt.
  335.       endif.
  336.  
  337.       read table me->mt_mrp with table key matnr = <out>-matnr werks = <out>-werks into ls_mrp.
  338.       if sy-subrc = 0.
  339.         <out>-dispo = ls_mrp-dispo.
  340.         <out>-dsnam = ls_mrp-dsnam.
  341.       endif.
  342.  
  343.       read table me->mt_mara with table key matnr = <out>-matnr into ls_mara.
  344.       if sy-subrc = 0.
  345.         <out>-meins = ls_mara-meins.
  346.         <out>-mtart = ls_mara-mtart.
  347.  
  348.         read table me->mt_t134t with table key mtart = ls_mara-mtart into ls_t134t.
  349.         if sy-subrc = 0.
  350.           <out>-mtbez = ls_t134t-mtbez.
  351.         endif.
  352.  
  353.         read table me->mt_ztwtyp with table key extwg = ls_mara-extwg into ls_ztwtyp.
  354.         if sy-subrc = 0.
  355.           <out>-zwtyp = ls_ztwtyp-zwtyp.
  356.         endif.
  357.       endif.
  358.  
  359.  
  360.       read table me->mt_werks with table key werks = <out>-werks into ls_werks.
  361.       if sy-subrc = 0.
  362.         <out>-name1 = ls_werks-name1.
  363.       endif.
  364.  
  365.       call function 'MATERIAL_UNIT_CONVERSION'
  366.         exporting
  367.           input                = <out>-lbkum
  368.           matnr                = <out>-matnr
  369.           meinh                = 'KG'
  370.         importing
  371.           output               = <out>-lbkum_kg
  372.         exceptions
  373.           conversion_not_found = 1
  374.           input_invalid        = 2
  375.           material_not_found   = 3
  376.           meinh_not_found      = 4
  377.           meins_missing        = 5
  378.           no_meinh             = 6
  379.           output_invalid       = 7
  380.           overflow             = 8
  381.           others               = 9.
  382.       if sy-subrc <> 0.
  383. *        message id sy-msgid type 'I' number sy-msgno
  384. *                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  385.         clear <out>-lbkum_kg.
  386.       endif.
  387.  
  388.       call function 'MATERIAL_UNIT_CONVERSION'
  389.         exporting
  390.           input                = <out>-mgvbr
  391.           matnr                = <out>-matnr
  392.           meinh                = 'KG'
  393.         importing
  394.           output               = <out>-mgvbr_kg
  395.         exceptions
  396.           conversion_not_found = 1
  397.           input_invalid        = 2
  398.           material_not_found   = 3
  399.           meinh_not_found      = 4
  400.           meins_missing        = 5
  401.           no_meinh             = 6
  402.           output_invalid       = 7
  403.           overflow             = 8
  404.           others               = 9.
  405.       if sy-subrc <> 0.
  406. *        message id sy-msgid type 'I' number sy-msgno
  407. *                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  408.         clear <out>-mgvbr_kg.
  409.       endif.
  410.  
  411.  
  412.  
  413.     endloop.
  414.  
  415.  
  416.     call screen 100.
  417.  
  418.   endmethod.                    "main
  419.  
  420.  
  421.  
  422.   method select_material_valuation.
  423.     data: lt_mbew     type hashed table of t_material_valuation with unique key matnr bwkey,
  424.           ls_mbew     type t_material_valuation,
  425.           lt_mbewh    type standard table of t_material_valuation,
  426.           lt_mbewh_t  type standard table of t_material_valuation,
  427.           ls_mbewh    type t_material_valuation,
  428.           ls_mbewh_t  type t_material_valuation,
  429.           lt_t030     type tt_t030,
  430.           ls_t030     type t_t030,
  431.           rt_bklas    type tt_bklas,
  432.           l_check     type c,
  433.  
  434.           l_lfmon     type mbew-lfmon,
  435.           l_lfgja     type mbew-lfgja.
  436.  
  437.     me->get_t030(   changing  c_t030 = lt_t030 ).
  438.  
  439.     check lt_t030 is not initial.
  440.  
  441.     me->get_bklas(  exporting i_t030 = lt_t030
  442.                     changing  c_bklas = rt_bklas ).
  443.  
  444. *   Prethodni period od onog zadnjeg (gornjeg) na selekcijskom...
  445.     if s_spmon-high+4(2) = 1.
  446.       l_lfmon = 12.
  447.       l_lfgja = s_spmon-high(4) - 1.
  448.     else.
  449.       l_lfmon = s_spmon-high+4(2) - 1.
  450.       l_lfgja = s_spmon-high(4).
  451.     endif.
  452.  
  453. *   Prvo kupim trenutne zalihe
  454.     select
  455.         *
  456.     from
  457.         mbew inner join t001k on
  458.           mbew~bwkey = t001k~bwkey
  459.         inner join t001 on
  460.           t001k~bukrs = t001~bukrs
  461.     into corresponding fields of table lt_mbew
  462.     where
  463.         bklas in rt_bklas and
  464.         t001~bukrs in s_bukrs and
  465.         bwtar = '' and
  466.         ( lfgja < s_spmon-high(4) or
  467.         ( lfmon <= s_spmon-high+4(2) and lfgja = s_spmon-high(4) ) ) and
  468.         matnr in s_matnr.
  469.  
  470. *   Onda kupim povijesne zalihe
  471.     select
  472.       t001~bukrs
  473.       t001~ktopl
  474.       matnr
  475.       mbewh~bwkey
  476.       lbkum
  477.       salk3
  478.       bklas
  479.       lfgja
  480.       lfmon
  481.     into
  482.       corresponding fields of table lt_mbewh
  483.     from
  484.         mbewh inner join t001k on
  485.           mbewh~bwkey = t001k~bwkey
  486.         inner join t001 on
  487.           t001k~bukrs = t001~bukrs
  488.     where
  489.       bklas in rt_bklas and
  490.       t001~bukrs in s_bukrs and
  491.       ( lfgja < s_spmon-high(4) or
  492.       ( lfmon <= s_spmon-high+4(2) and lfgja = s_spmon-high(4) ) ) and
  493.       matnr in s_matnr.
  494.  
  495.     sort lt_mbewh by matnr bwkey lfgja lfmon.
  496.  
  497.     loop at lt_mbewh into ls_mbewh where ( lfgja <  l_lfgja ) or ( lfmon <= l_lfmon and lfgja = l_lfgja ).
  498.  
  499.       select
  500.         t001~bukrs
  501.         t001~ktopl
  502.         matnr
  503.         mbewh~bwkey
  504.         lbkum
  505.         salk3
  506.         bklas
  507.         lfgja
  508.         lfmon
  509.       into
  510.         corresponding fields of table lt_mbewh_t
  511.       from
  512.         mbewh inner join t001k on
  513.           mbewh~bwkey = t001k~bwkey
  514.         inner join t001 on
  515.           t001k~bukrs = t001~bukrs
  516.       where
  517.         mbewh~bklas in s_bklas and
  518.         mbewh~bwkey = ls_mbewh-bwkey and
  519.         t001~bukrs in s_bukrs and
  520.         matnr = ls_mbewh-matnr and
  521.         ( lfgja > ls_mbewh-lfgja or
  522.         ( lfmon > ls_mbewh-lfmon and lfgja = ls_mbewh-lfgja ) ) and
  523.         matnr in s_matnr.
  524.  
  525.       sort lt_mbewh_t by matnr bwkey lfgja lfmon.
  526.  
  527.       read table lt_mbewh_t into ls_mbewh_t index 1.
  528.       if sy-subrc = 0.
  529.         ls_mbewh-lbkum = ls_mbewh_t-lbkum.
  530.         ls_mbewh-salk3 = ls_mbewh_t-salk3.
  531.         modify lt_mbewh from ls_mbewh.
  532.       endif.
  533.  
  534.     endloop.
  535.  
  536. *   Pièi po povijesnim i provjeravaj nedostaje li nam slog u trenutnim zalihama i po potrebi ga upiši u izlaznu internjaèu.
  537.     loop at lt_mbewh into ls_mbewh.
  538.  
  539.       clear l_check.
  540.  
  541.       at end of bwkey.
  542.         l_check = 'X'.
  543.       endat.
  544.  
  545.       if l_check = 'X'.
  546.         read table lt_mbew with table key
  547.           matnr = ls_mbewh-matnr
  548.           bwkey = ls_mbewh-bwkey
  549.           transporting no fields.
  550.  
  551.         if sy-subrc ne 0.
  552.           read table lt_t030 with key bklas = ls_mbewh-bklas ktopl = ls_mbewh-ktopl into ls_t030.
  553.           if sy-subrc = 0.
  554.             ls_mbewh-saknr = ls_t030-konts.
  555.           endif.
  556.           collect ls_mbewh into c_mbew.
  557.         endif.
  558.       endif.
  559.  
  560.     endloop.
  561.  
  562. *   U izlaznu internjaèu nadoštukaj trnutne zalihe (nakon èega bi tranu trebale biti sve potrebne zalihe po klasi vrednovanja).
  563.     loop at lt_mbew into ls_mbew.
  564.       read table lt_t030 with key bklas = ls_mbew-bklas ktopl = ls_mbewh-ktopl into ls_t030.
  565.       if sy-subrc = 0.
  566.         ls_mbew-saknr = ls_t030-konts.
  567.       endif.
  568.  
  569.       collect ls_mbew into c_mbew.
  570.  
  571.     endloop.
  572.  
  573.   endmethod.                    "select_material_valuation
  574.  
  575.  
  576.  
  577.   method select_mov_for_curr_stocks.
  578.     data: lt_data type tt_out,
  579.           ls_data type t_out.
  580.  
  581.     field-symbols: <out> type t_out.
  582.  
  583.     select
  584.       *
  585.     from
  586.       s031
  587.     into
  588.       corresponding fields of table lt_data
  589. *    for
  590. *      all entries in i_mbew
  591.     where
  592.       spmon in s_spmon
  593. *      and matnr = i_mbew-matnr
  594.       .
  595.  
  596.     loop at lt_data into ls_data.
  597.       read table c_out with key matnr = ls_data-matnr werks = ls_data-werks assigning <out>.
  598.       if sy-subrc <> 0.
  599.         continue.
  600.       endif.
  601.  
  602.       <out>-mgvbr = <out>-mgvbr + ls_data-mgvbr.
  603.       <out>-wgvbr = <out>-wgvbr + ls_data-wgvbr.
  604.  
  605.     endloop.
  606.  
  607.   endmethod.                    "select_mov_for_curr_stocks
  608.  
  609.  
  610.  
  611.   method select_last_goods_movement.
  612.     data:
  613.           lt_s032 type standard table of s032,
  614.           ls_s032 type s032.
  615.  
  616.     field-symbols:
  617.           <out> type t_out.
  618.  
  619.     select
  620.       *
  621.     from
  622.       s032
  623.     into
  624.       table lt_s032
  625.     for
  626.       all entries in me->mt_werks
  627.     where
  628.       werks = me->mt_werks-werks.
  629.  
  630. *   Treba mi najnoviji po pogonu i materijalu, bez obzira na skl. lok.
  631.     sort lt_s032 by werks matnr ascending letztbew descending.
  632.     delete adjacent duplicates from lt_s032 comparing werks matnr.
  633.  
  634.     loop at lt_s032 into ls_s032.
  635.       read table c_out with key matnr = ls_s032-matnr werks = ls_s032-werks assigning <out>.
  636.       if sy-subrc <> 0.
  637.         continue.
  638.       endif.
  639.  
  640.       <out>-letztbew = ls_s032-letztbew.
  641.  
  642.     endloop.
  643.  
  644.  
  645.   endmethod.                    "select_last_goods_movement
  646.  
  647.  
  648.  
  649.   method select_order_item.
  650.     data:
  651.           lt_mdbs type standard table of mdbs,
  652.           ls_mdbs type mdbs,
  653.           ls_mara type mara.
  654.  
  655.     field-symbols:
  656.           <out> type t_out.
  657.  
  658.     select
  659.       *
  660.     from
  661.       mdbs
  662.     into
  663.       table lt_mdbs
  664.     for
  665.       all entries in i_mbew
  666.     where
  667.       loekz = '' and
  668.       elikz = '' and
  669.       matnr = i_mbew-matnr and
  670.       exists ( select * from ekko where ekko~ebeln = mdbs~ebeln and ekko~lifnr <> '' and ekko~memory = '' ) and
  671.       werks in ( select bwkey from t001k where bukrs in s_bukrs ).
  672.  
  673.     loop at lt_mdbs into ls_mdbs.
  674.       read table c_out with key matnr = ls_mdbs-matnr werks = ls_mdbs-werks assigning <out>.
  675.       if sy-subrc <> 0.
  676.         continue.
  677.       endif.
  678.  
  679.       read table me->mt_mara with table key matnr = ls_mdbs-matnr into ls_mara.
  680.  
  681.       call function 'MATERIAL_UNIT_CONVERSION'
  682.         exporting
  683.           input                = ls_mdbs-menge
  684.           matnr                = ls_mdbs-matnr
  685.           meinh                = ls_mdbs-meins
  686.         importing
  687.           output               = ls_mdbs-menge
  688.         exceptions
  689.           conversion_not_found = 1
  690.           input_invalid        = 2
  691.           material_not_found   = 3
  692.           meinh_not_found      = 4
  693.           meins_missing        = 5
  694.           no_meinh             = 6
  695.           output_invalid       = 7
  696.           overflow             = 8
  697.           others               = 9.
  698.       if sy-subrc <> 0.
  699.         message id sy-msgid type sy-msgty number sy-msgno
  700.                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  701.       endif.
  702.  
  703.       call function 'MATERIAL_UNIT_CONVERSION'
  704.         exporting
  705.           input                = ls_mdbs-wemng
  706.           matnr                = ls_mdbs-matnr
  707.           meinh                = ls_mdbs-meins
  708.         importing
  709.           output               = ls_mdbs-wemng
  710.         exceptions
  711.           conversion_not_found = 1
  712.           input_invalid        = 2
  713.           material_not_found   = 3
  714.           meinh_not_found      = 4
  715.           meins_missing        = 5
  716.           no_meinh             = 6
  717.           output_invalid       = 7
  718.           overflow             = 8
  719.           others               = 9.
  720.       if sy-subrc <> 0.
  721.         message id sy-msgid type sy-msgty number sy-msgno
  722.                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  723.       endif.
  724.  
  725.  
  726.       <out>-menge = <out>-menge + ls_mdbs-menge - ls_mdbs-wemng.
  727.  
  728.     endloop.
  729.   endmethod.                    "select_order_item
  730.  
  731.  
  732.  
  733.   method get_t030.
  734.  
  735.     data: rt_saknr_poduzeca type range of saknr,
  736.           rs_saknr_poduzeca like line of rt_saknr_poduzeca,
  737.           ls_ska1           type t_ska1,
  738.           lt_t001k          type standard table of t001k,
  739.           ls_t001           type t001,
  740.           rt_ktopl_poduzeca type range of ktopl,
  741.           rs_ktopl_poduzeca like line of rt_ktopl_poduzeca...
  742.  
  743.  
  744.  
  745.     rs_ktopl_poduzeca-sign = 'I'.
  746.     rs_ktopl_poduzeca-option = 'EQ'.
  747.  
  748.     loop at me->mt_t001 into ls_t001.
  749.       rs_ktopl_poduzeca-low = ls_t001-ktopl.
  750.       append rs_ktopl_poduzeca to rt_ktopl_poduzeca.
  751.     endloop.
  752.  
  753.  
  754. *   Napuni range tablicu sa kontima kontnog plana poduzeæa
  755.     loop at me->mt_ska1 into ls_ska1.
  756.       rs_saknr_poduzeca-low = ls_ska1-saknr_podu.
  757.       rs_saknr_poduzeca-sign = 'I'.
  758.       rs_saknr_poduzeca-option = 'EQ'.
  759.       append rs_saknr_poduzeca to rt_saknr_poduzeca.
  760.     endloop.
  761.  
  762.  
  763.     select * from t001k into table lt_t001k where bukrs in s_bukrs.
  764.  
  765.     check lt_t001k is not initial.
  766.  
  767. *   I napokon mi naði klase vrednovanja i pripadajuæa konta poduzeæa koje mi trebaju
  768.     select
  769.       ktopl
  770.       bklas
  771.       konts
  772.     into corresponding fields of table c_t030
  773.     from
  774.       t030
  775.     for all entries in lt_t001k
  776.     where
  777.         ktosl       = 'BSX' and
  778.         ktopl       in rt_ktopl_poduzeca and
  779.         t030~bwmod  = lt_t001k-bwmod and
  780.         konts       in rt_saknr_poduzeca and
  781.         bklas       in s_bklas.
  782.  
  783.   endmethod.                    "get_t030_data
  784.  
  785.  
  786.  
  787.   method get_bklas.
  788.     data:
  789.           ls_t030 type t_t030,
  790.           ls_bklas like line of c_bklas.
  791.  
  792.     ls_bklas-sign = 'I'.
  793.     ls_bklas-option = 'EQ'.
  794.  
  795.     loop at i_t030 into ls_t030.
  796.       ls_bklas-low = ls_t030-bklas.
  797.  
  798.       append ls_bklas to c_bklas.
  799.     endloop.
  800.  
  801.   endmethod.                    "set_bklas
  802.  
  803.  
  804.  
  805.   method on_link_click.
  806.     data: ls_out type t_out.
  807.  
  808.     read table me->mt_out index e_row_id into ls_out.
  809.  
  810.     me->display_s031_data( ls_out ).
  811.  
  812.   endmethod.                    "on_link_click
  813.  
  814.  
  815.   method display_s031_data.
  816.     data:
  817.           lt_data       type standard table of t_s031,
  818.  
  819.           lo_popup      type ref to cl_salv_table,
  820.           lo_functions  type ref to cl_salv_functions,
  821.           lo_display    type ref to cl_salv_display_settings,
  822.           lo_cols       type ref to cl_salv_columns.
  823.  
  824.  
  825.  
  826.     select  *
  827.     from    s031 left outer join t001l on
  828.               s031~werks = t001l~werks and
  829.               s031~lgort = t001l~lgort
  830.     into    corresponding fields of table lt_data
  831.     where   s031~werks = i_row-werks and
  832.             matnr = i_row-matnr and
  833.             spmon in s_spmon and
  834.             ( s031~mgvbr <> 0 or s031~wgvbr <> 0 ).
  835.  
  836.     try.
  837.         cl_salv_table=>factory( importing r_salv_table = lo_popup changing t_table = lt_data ).
  838.  
  839.         lo_functions = lo_popup->get_functions( ).
  840.         lo_functions->set_all( abap_true ).
  841.  
  842.         lo_cols = lo_popup->get_columns( ).
  843.         lo_cols->set_optimize( abap_true ).
  844.  
  845.         lo_display = lo_popup->get_display_settings( ).
  846.         lo_display->set_striped_pattern( cl_salv_display_settings=>true ).
  847. *        lo_display->set_list_header( 'Pregled zaliha po pogonima' ).
  848.  
  849.       catch cx_salv_msg.
  850.         message 'Nešto strašno se dogodilo.' type 'E'.
  851.     endtry.
  852.  
  853.  
  854.     lo_popup->set_screen_popup(  start_column = 5
  855.                                           end_column   = 80
  856.                                           start_line   = 5
  857.                                           end_line     = 20 ).
  858.  
  859.     lo_popup->display( ).
  860.  
  861.  
  862.  
  863.   endmethod.                    "display_s031_data
  864.  
  865.  
  866.  
  867.   method get_list_header.
  868.     data:
  869.           ls_t001     type t001,
  870.           l_bukrs_cnt type i.
  871.  
  872.     describe table me->mt_t001 lines l_bukrs_cnt.
  873.  
  874.     if l_bukrs_cnt = 1.
  875.       loop at me->mt_t001 into ls_t001.
  876.         r_header = ls_t001-bukrs.
  877.         concatenate 'Pregled zaliha po pogonima za poduzeæe' r_header into r_header separated by space.
  878.         exit.
  879.       endloop.
  880.     else.
  881.       loop at me->mt_t001 into ls_t001.
  882.  
  883.         if r_header is initial.
  884.           r_header = ls_t001-bukrs.
  885.         else.
  886.           concatenate r_header ',' into r_header.
  887.           concatenate r_header ls_t001-bukrs into r_header separated by space.
  888.         endif.
  889.       endloop.
  890.       concatenate 'Pregled zaliha po pogonima za poduzeæa' r_header into r_header separated by space.
  891.     endif.
  892.  
  893.     concatenate r_header 'za priod od' s_spmon-low 'do' s_spmon-high into r_header separated by space.
  894.  
  895.  
  896.  
  897.   endmethod.                    "get_list_header
  898.  
  899.  
  900.  
  901.   method handle_pbo.
  902.     data: ls_layo     type lvc_s_layo,
  903.           variant     type disvariant.
  904.  
  905.  
  906.     set pf-status 'PF100'.
  907.     set titlebar 'TB100'.
  908.  
  909.     if me->m_splitter is initial.
  910.       create object me->m_splitter
  911.         exporting
  912.           parent  = cl_gui_container=>default_screen
  913.           rows    = 2
  914.           columns = 1.
  915.  
  916.       me->m_splitter->set_row_height( exporting height = 70
  917.                                                 id     = 1 ).
  918.  
  919.       me->m_html_container = me->m_splitter->get_container( row    = 1
  920.                                                             column = 1 ).
  921.  
  922.     endif.
  923.  
  924.     me->m_splitter->set_row_mode( mode = cl_gui_splitter_container=>mode_absolute ).
  925.  
  926.     if me->m_alv is initial.
  927.  
  928.       me->m_container = me->m_splitter->get_container(  row    = 2
  929.                                                         column = 1 ).
  930.  
  931.  
  932.  
  933.       create object me->m_alv
  934.         exporting
  935.           i_parent = me->m_container.
  936.  
  937.       ls_layo-cwidth_opt  = 'X'.
  938.  
  939.       ls_layo-grid_title = ''.
  940.  
  941.  
  942.       variant-report      = sy-repid.
  943.       variant-username    = sy-uname.
  944.       variant-variant     = p_layout.
  945.  
  946.  
  947.       me->m_alv->set_table_for_first_display(  exporting  is_layout             = ls_layo
  948.                                                           i_save                = 'A'
  949.                                                           i_default             = 'X'
  950.                                                           is_variant            = variant
  951.                                                 changing  it_outtab             = me->mt_out
  952.                                                           it_fieldcatalog       = me->mt_fc ).
  953.  
  954.       set handler on_link_click for me->m_alv.
  955.       me->display_header( ).
  956.     endif.
  957.  
  958.     me->m_alv->refresh_table_display( i_soft_refresh = 'X' ).
  959.  
  960.   endmethod.                    "handle_pbo
  961.  
  962.  
  963.  
  964.   method handle_pai.
  965.     case i_ucomm.
  966.       when 'BACK' or 'CANCEL'.
  967.         set screen 0.
  968.       when 'EXIT'.
  969.         leave program.
  970.     endcase.
  971.  
  972.   endmethod.                    "handle_pai
  973.  
  974.  
  975.  
  976.   method display_header.
  977.     data:
  978.        l_text(255)  type c,
  979.        l_dummy(255) type c,
  980.  
  981.        right        type ref to cl_dd_area,
  982.  
  983.        ls_t001  type t001.
  984.  
  985.     create object me->m_header_document.
  986.  
  987.     me->m_header_document->vertical_split(
  988.           exporting split_area  = me->m_header_document
  989.                     split_width = '160'
  990.           importing
  991.                     right_area  = right ).
  992.  
  993.  
  994.  
  995.     l_text = 'Poduzeæe:'.
  996.     me->m_header_document->add_text( text = l_text sap_emphasis = 'STRONG' ).
  997.  
  998.     loop at me->mt_t001 into ls_t001.
  999.       write ls_t001-bukrs to l_text.
  1000.       right->add_text( text = l_text sap_color = cl_dd_document=>list_key ).
  1001.  
  1002.       l_text = ls_t001-butxt.
  1003.       right->add_text( text = l_text ).
  1004.     endloop.
  1005.  
  1006.     me->m_header_document->new_line( ).
  1007.     right->new_line( ).
  1008.  
  1009.     l_text = 'Period:'.
  1010.     me->m_header_document->add_text( text = l_text sap_emphasis = 'STRONG' ).
  1011.  
  1012.     write s_spmon-low to l_text.
  1013.     right->add_text( text = l_text sap_color = cl_dd_document=>list_key ).
  1014.  
  1015.     if s_spmon-low <> s_spmon-high.
  1016.       l_text = ' do '.
  1017.       right->add_text( text = l_text ).
  1018.       write s_spmon-high to l_text.
  1019.       right->add_text( text = l_text sap_color = cl_dd_document=>list_key ).
  1020.     endif.
  1021.  
  1022.  
  1023.     me->m_header_document->set_document_background( 'Z_PATTERN_PAPER' ).
  1024.  
  1025. *   Prikaži zaglavlje
  1026.     me->m_header_document->merge_document( ).
  1027.     me->m_header_document->display_document( parent = me->m_html_container ).
  1028.  
  1029.   endmethod.                    "display_header
  1030.  
  1031.  
  1032.  
  1033.   method build_fc.
  1034.     data:
  1035.           ls_fc       type lvc_s_fcat,
  1036.           l_coltext   type lvc_txtcol,
  1037.           l_fieldname type lvc_fname.
  1038.  
  1039.  
  1040.     define add_field.
  1041.       ls_fc-fieldname = &1.
  1042.       ls_fc-ref_field = &2.
  1043.       ls_fc-ref_table = &3.
  1044.       if &4 is not initial.
  1045.         ls_fc-coltext = &4.
  1046.       endif.
  1047.       ls_fc-hotspot = &5.
  1048.       append ls_fc to c_fc.
  1049.       clear ls_fc.
  1050.     end-of-definition.
  1051.  
  1052.     add_field:
  1053.        'BUKRS'      'BUKRS'     'T001'    ''                      '',
  1054.        'BUTXT'      'BUTXT'     'T001'    ''                      '',
  1055.        'SAKNR_LACT' 'SAKNR'     'ZLKON01' 'Lactalis konto'        '',
  1056.        'TXT50_LACT' 'TXT50'     'SKAT'    'Naziv Lactalis konta'  '',
  1057.        'SAKNR_KONS' 'SAKNR'     'SKA1'    'Konto KONS'            '',
  1058.        'TXT50_KONS' 'TXT50'     'SKAT'    'Naziv konta KONS'      '',
  1059.        'SAKNR'      'SAKNR'     'SKA1'    ''                      '',
  1060.        'TXT50'      'TXT50'     'SKAT'    ''                      '',
  1061.        'BKLAS'      'BKLAS'     'MBEW'    ''                      '',
  1062.        'BKBEZ'      'BKBEZ'     'T025T'   ''                      '',
  1063.        'MTART'      'MTART'     'MARA'    ''                      '',
  1064.        'MTBEZ'      'MTBEZ'     'T134T'   ''                      '',
  1065.        'MATNR'      'MATNR'     'MARA'    ''                      '',
  1066.        'MAKTX'      'MAKTX'     'MAKT'    ''                      '',
  1067.        'DISPO'      'DISPO'     'MARC'    ''                      '',
  1068.        'DSNAM'      'DSNAM'     'T024D'   ''                      '',
  1069.        'ZWTYP'      'ZWTYP'     'ZTWTYP'  ''                      '',
  1070.        'MEINS'      'MEINS'     'MARA'    ''                      '',
  1071.        'WERKS'      'WERKS'     'T001W'   ''                      '',
  1072.        'NAME1'      'NAME1'     'T001W'   ''                      '',
  1073.        'LBKUM'      'LBKUM'     'MBEW'    ''                      '',
  1074.        'LBKUM_KG'   'LBKUM'     'MBEW'    'Ukupna zaliha KG'      '',
  1075.        'SALK3'      'SALK3'     'MBEW'    ''                      '',
  1076.        'MGVBR'      'MGVBR'     'S031'    ''                      'X',
  1077.        'MGVBR_KG'   'MGVBR'     'S031'    'Potrošnja KG'          'X',
  1078.        'WGVBR'      'WGVBR'     'S031'    ''                      'X',
  1079.        'LETZTBEW'   'LETZTBEW'  'S032'    ''                      '',
  1080.        'MENGE'      'MENGE'     'MDBS'    'Naruèeno/neisporuèeno' ''
  1081.        .
  1082.  
  1083.   endmethod.                    "build_fc
  1084.  
  1085.  
  1086.  
  1087.   method f4_saknr_lact.
  1088.     types: begin of t_lact_saknr,
  1089.               saknr type ska1-saknr,
  1090.               txt50 type skat-txt50,
  1091.             end of t_lact_saknr.
  1092.  
  1093.     data: lt_lact_saknr type standard table of t_lact_saknr,
  1094.           lt_return     type standard table of ddshretval.
  1095.  
  1096.     select distinct
  1097.       zlkon01~saknr
  1098.       skat~txt50
  1099.     into corresponding fields of table lt_lact_saknr
  1100.     from
  1101.         zlkon01 inner join ska1 as ska1_grupe on
  1102.           zlkon01~saknr = ska1_grupe~bilkt
  1103.         inner join ska1 as ska1_poduzeca on
  1104.           ska1_poduzeca~bilkt = ska1_grupe~saknr
  1105.         left outer join skat on
  1106.           zlkon01~saknr = skat~saknr and
  1107.           skat~ktopl = 'LACT' and
  1108.           skat~spras = sy-langu
  1109.     where
  1110.         zlkon01~zstock <> '' and
  1111.         ska1_grupe~ktopl = 'KONS'.
  1112.  
  1113.  
  1114.     call function 'F4IF_INT_TABLE_VALUE_REQUEST'
  1115.       exporting
  1116.         retfield        = 'SAKNR'
  1117.         dynpprog        = sy-repid
  1118.         dynpnr          = sy-dynnr
  1119.         dynprofield     = 'S_SAKNRL'
  1120.         window_title    = 'Lactalis konto'
  1121.         value_org       = 'S'
  1122.       tables
  1123.         value_tab       = lt_lact_saknr
  1124.         return_tab      = lt_return
  1125.       exceptions
  1126.         parameter_error = 1
  1127.         no_values_found = 2
  1128.         others          = 3.
  1129.     if sy-subrc <> 0.
  1130.       message id sy-msgid type sy-msgty number sy-msgno
  1131.               with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  1132.     endif.
  1133.  
  1134.  
  1135.   endmethod.                    "f4_saknr_lact
  1136.  
  1137.  
  1138.  
  1139.   method f4_saknr.
  1140.     types: begin of t_saknr,
  1141.               saknr type ska1-saknr,
  1142.               txt50 type skat-txt50,
  1143.             end of t_saknr.
  1144.  
  1145.     data: lt_saknr  type standard table of t_saknr,
  1146.           lt_return type standard table of ddshretval.
  1147.  
  1148.     select distinct
  1149.       ska1_poduzeca~saknr
  1150.       skat~txt50
  1151.     into corresponding fields of table lt_saknr
  1152.     from
  1153.         zlkon01 inner join ska1 as ska1_grupe on
  1154.           zlkon01~saknr = ska1_grupe~bilkt
  1155.         inner join ska1 as ska1_poduzeca on
  1156.           ska1_poduzeca~bilkt = ska1_grupe~saknr
  1157.         inner join t001 on
  1158.           ska1_poduzeca~ktopl = t001~ktopl
  1159.         left outer join skat on
  1160.           skat~saknr = ska1_poduzeca~saknr and
  1161.           skat~ktopl = ska1_poduzeca~ktopl and
  1162.           skat~spras = sy-langu
  1163.     where
  1164.         zlkon01~zstock <> '' and
  1165.         ska1_grupe~ktopl = 'KONS' and
  1166.         t001~bukrs in s_bukrs and
  1167.         zlkon01~saknr in s_saknrl.
  1168.  
  1169.     call function 'F4IF_INT_TABLE_VALUE_REQUEST'
  1170.       exporting
  1171.         retfield        = 'SAKNR'
  1172.         dynpprog        = sy-repid
  1173.         dynpnr          = sy-dynnr
  1174.         dynprofield     = 'S_SAKNR'
  1175.         value_org       = 'S'
  1176.       tables
  1177.         value_tab       = lt_saknr
  1178.         return_tab      = lt_return
  1179.       exceptions
  1180.         parameter_error = 1
  1181.         no_values_found = 2
  1182.         others          = 3.
  1183.     if sy-subrc <> 0.
  1184.       message id sy-msgid type sy-msgty number sy-msgno
  1185.               with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  1186.     endif.
  1187.  
  1188.   endmethod.                    "f4_saknr
  1189.  
  1190.  
  1191.   method authority_check.
  1192.     data:
  1193.           l_message type string,
  1194.           lt_t001   type standard table of t001,
  1195.           ls_t001   type t001.
  1196.  
  1197.     select * from t001 into table lt_t001 where bukrs in s_bukrs.
  1198.  
  1199.     loop at lt_t001 into ls_t001.
  1200.  
  1201.       authority-check object 'F_BKPF_BUK'
  1202.              id 'BUKRS' field ls_t001-bukrs
  1203.              id 'ACTVT' field '03'.
  1204.       if sy-subrc ne 0.
  1205.         concatenate 'Nemate autorizaciju za poduzeæe' ls_t001-bukrs into l_message separated by space.
  1206.         message l_message type 'E'.
  1207.       endif.
  1208.  
  1209.     endloop.
  1210.   endmethod.                    "authority_check
  1211.  
  1212.  
  1213.   method find_layout.
  1214.  
  1215.     data:
  1216.           l_exit,
  1217.           ls_variant type disvariant.
  1218.  
  1219.     ls_variant-report = sy-repid.
  1220.  
  1221.     call function 'LVC_VARIANT_F4'
  1222.       exporting
  1223.         is_variant = ls_variant
  1224.         i_save     = 'X'
  1225.       importing
  1226.         e_exit     = l_exit
  1227.         es_variant = ls_variant
  1228.       exceptions
  1229.         not_found  = 1
  1230.         others     = 2.
  1231.  
  1232.     if sy-subrc ne 0.
  1233.       message id sy-msgid type sy-msgty number sy-msgno
  1234.       with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  1235.     elseif l_exit ne 'X'.
  1236.       p_layout    = ls_variant-variant.
  1237.     endif.
  1238.  
  1239.   endmethod.                    "find_variant
  1240.  
  1241.  
  1242.   method check_layout.
  1243.  
  1244.     data: ls_variant type disvariant.
  1245.  
  1246.     if not p_layout is initial.
  1247.       move p_layout to ls_variant-variant.
  1248.       move sy-repid to ls_variant-report.
  1249.  
  1250.       call function 'LVC_VARIANT_EXISTENCE_CHECK'
  1251.         exporting
  1252.           i_save        = 'X'
  1253.         changing
  1254.           cs_variant    = ls_variant
  1255.         exceptions
  1256.           wrong_input   = 1
  1257.           not_found     = 2
  1258.           program_error = 3
  1259.           others        = 4.
  1260.       if sy-subrc <> 0.
  1261.         message id sy-msgid type sy-msgty number sy-msgno
  1262.         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  1263.       else.
  1264.  
  1265.       endif.
  1266.     endif.
  1267.   endmethod.                    "check_layout
  1268.  
  1269. endclass. "lcl_app IMPLEMENTATION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement