SAP:Get Inactive BOM Data

data: begin of itab occurs 0,
            matnr_pre like mast-matnr,
            matnr    like mara-matnr,
            idnrk    like mara-matnr,
            maktx    like makt-maktx,
            meins    like mara-meins,
            menge    like stpo-menge,
            alprf   like stpo-alprf,
            ewahr   like stpo-ewahr,
            item_text1 type length 40,
            item_text2 type length 40,
            text(255type c,
            ltxsp  like stpo-ltxsp ,
            stlnr  like stpo-stlnr ,
            stlkn  like stpo-stlkn ,
            stpoz  like stpo-stpoz ,
       end of itab.
  data: itab_tmp like table of itab with header line.

  data: begin of it_matnr occurs 0,
        matnr    like mara-matnr,
        matnr_pre like mast-matnr,
        end of it_matnr.
  data: it_matnr_tmp  like table of it_matnr with header line.
  data: it_matnr1  like table of it_matnr with header line.
  data:lv_datuv like csap_mbom-datuv.

selection-screen begin of block b1 with frame title text-001.
parameters:     p_werks like mast-werks obligatory.
select-options: p_matnr for mast-matnr.
parameters:     p_stlan like mast-stlan default '1',
                p_bmeng like stko-bmeng default '1' ,
                p_datuv like stko-datuv default sy-datum.

selection-screen end of block b1.

 form get_data .
      data:lv_tabix like sy-tabix.

      select distinct m~matnr m~matnr as matnr_pre
          into  table it_matnr1
        from  stko as k
             inner join mast as on m~stlnr k~stlnr and m~stlal k~stlal
        where m~matnr in p_matnr
          and m~werks p_werks
          and m~stlan p_stlan
          and k~stlst '01'
          and k~loekz space.
      perform change_date_format using p_datuv  'X' changing  lv_datuv.
      sort it_matnr1  by matnr.
      loop at it_matnr1.
        move-corresponding it_matnr1 to it_matnr.
        append it_matnr.
        perform get_mutl_bom.
        clear:it_matnr,it_matnr[].
      endloop.
      loop at itab.
        lv_tabix sy-tabix.
        clear :itab-text.
        concatenate itab-item_text1 itab-item_text2  into itab-text separated by space.
        perform get_material_desc using  itab-idnrk changing  itab-maktx.
        modify itab index lv_tabix transporting text  maktx.
      endloop.
    endform.                    " GET_DATA

form get_mutl_bom .
      data: it_stpo like table of stpo_api02 with header line.
      refresh it_matnr_tmp.
      if it_matnr[] is not initial.
        it_matnr_tmp[] it_matnr[].
        refresh:it_matnr.
        loop at it_matnr_tmp.
          call function 'CSAP_MAT_BOM_READ'
            exporting
              material   it_matnr_tmp-matnr
              plant      p_werks
              bom_usage  p_stlan
              valid_from lv_datuv
              valid_to   lv_datuv
            tables
              t_stpo     it_stpo
            exceptions
              error      1
              others     2.
          if sy-subrc eq 0.
            loop at it_stpo.
              check it_stpo-item_categ 'L'.
              move-corresponding  it_stpo  to  itab.
              itab-matnr_pre it_matnr_tmp-matnr_pre.
              itab-matnr it_matnr_tmp-matnr.
              itab-idnrk it_stpo-component.
              perform tranfer_material  using itab-idnrk ''  changing itab-idnrk.
              itab-meins it_stpo-comp_unit.
              itab-menge it_stpo-comp_qty.
              itab-alprf it_stpo-ai_prio.
              itab-ewahr it_stpo-usage_prob.
              itab-item_text1 it_stpo-item_text1.
              itab-item_text2 it_stpo-item_text2.
              itab-stlnr it_stpo-bom_no.
              itab-stlkn it_stpo-item_node.
              itab-stpoz it_stpo-item_count.
              it_matnr-matnr itab-idnrk .
              it_matnr-matnr_pre itab-matnr_pre.
              collect it_matnr.
              append itab.
              clear:itab.
            endloop.
          endif.
        endloop.
      endif.
      if it_matnr[] is not initial.
        perform get_mutl_bom.
      endif.
    endform.                    " GET_MUTL_BOM

 form change_date_format  using p_old_date
                                  p_external
                            changing p_new_date.
      constants:c_chk_date like pa0001-ename value '0123456789/'.

      if p_external 'X'.
        call function 'CONVERT_DATE_TO_EXTERNAL'
          exporting
            date_internal            p_old_date
          importing
            date_external            p_new_date
          exceptions
            date_internal_is_invalid 1
            others                   2.
        if sy-subrc <> 0.
          clear:p_new_date.
        endif.
      else.
        check p_old_date is not initial.
        if p_old_date cn c_chk_date.
          p_new_date '00000000'.
        else.
          call function 'CONVERT_DATE_TO_INTERNAL'
            exporting
              date_external            p_old_date
            importing
              date_internal            p_new_date
            exceptions
              date_external_is_invalid 1
              others                   2.
          if sy-subrc ne 0.
            p_new_date '00000000'.
          endif.
        endif.
      endif.

    endform.                    " CHANGE_DATE_FORMAT
*&---------------------------------------------------------------------*
*&      Form  tranfer_material
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_OLD      text
*      -->P_OUTPUT   text
*      -->P_NEW      text
*----------------------------------------------------------------------*
    form  tranfer_material using    p_old
                                    p_output
                           changing p_new  .
      if p_output 'X'.
        call function 'CONVERSION_EXIT_MATN1_OUTPUT'
          exporting
            input  p_old
          importing
            output p_new.
      else.
        data:lv_input type length 50.
        lv_input p_old.
        translate   lv_input to upper case.
        call function 'CONVERSION_EXIT_MATN1_INPUT'
          exporting
            input        lv_input
          importing
            output       p_new
          exceptions
            length_error 1
            others       2.
        if sy-subrc <> 0.
        endif.
      endif.
    endform.                    "tranfer_material
*&---------------------------------------------------------------------*
*&      Form  get_material_desc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_MATNR    text
*      -->P_MAKTX    text
*----------------------------------------------------------------------*
    form get_material_desc using p_matnr
                            changing p_maktx.
      select single maktx
        into p_maktx
        from makt
        where matnr eq p_matnr and
              spras eq sy-langu.
    endform.                    "get_material_desc

form display_data .
      data:  l_fieldcat like line of t_fieldcat.
      refresh: t_fieldcat.
      define alv_field.
        clear:l_fieldcat.
        l_fieldcat-fieldname &1.
        l_fieldcat-seltext_m &2.
        l_fieldcat-seltext_l &3.
        l_fieldcat-outputlen &4.
        l_fieldcat-just &5.
        l_fieldcat-do_sum &6.
        l_fieldcat-ref_tabname &7 .
        l_fieldcat-ref_fieldname &8 .
        append l_fieldcat to  t_fieldcat.
      end-of-definition.

      alv_field 'MATNR_PRE' '' 'High Material' '' '' '' 'MARA' 'MATNR'.
      alv_field 'MATNR' '' 'Material' '' '' '' 'MARA' 'MATNR'.
      alv_field 'IDNRK' '' 'Component' '' '' '' 'MARA' 'MATNR'.
      alv_field 'MAKTX' '' 'Comp.Desc' '' '' '' '' ''.
      alv_field 'MEINS' 'UOM' '' '' '' '' '' ''.
      alv_field 'MENGE' 'Qty' '' '' '' '' '' ''.
      alv_field 'ALPRF' '' 'Priority' '' '' '' '' ''.
      alv_field 'EWAHR' 'Prob' '' '' '' '' '' ''.
      alv_field 'TEXT' 'Text' '' '' '' '' '' ''.

      t_layout-zebra 'X'.
      t_layout-f2code '&ETA'.
      t_layout-colwidth_optimize 'X'.
     " sort itab by matnr_pre matnr idnrk.
      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program          sy-cprog
          is_layout                   t_layout
*         I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
*         I_callback_pf_status_set    = 'STANDARD1'
          i_default                   'X'
          i_save                      'X'
*         I_CALLBACK_USER_COMMAND     = 'PROCESS_USER_COMMAND'
          it_fieldcat                 t_fieldcat[]
          it_events                   t_events
        tables
          t_outtab                    itab
        exceptions
          program_error               1
          others                      2.
    endform.                    " DISPLAY_DATA
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值