Reverse query of z_bom_rev BOM

Source: Internet
Author: User
*&---------------------------------------------------------------------*
* & Report z_bom_rev *
*&*
*&---------------------------------------------------------------------*
*&*
*&*
*&---------------------------------------------------------------------*

Report z_bom_rev line-size 200.

Types: Begin of ty_mat,
Matnr_s type matnr,
Maktx_s type maktx,
Matnr type matnr,
Andat type andat,
Maktx type maktx,
Vwalt type stalt,
End of ty_mat.

Types: Begin of ty_matnr,
Matnr type matnr,
End of ty_matnr.

Data MS type table of ty_matnr with header line.
Data it_mat type table of ty_mat with header line.
Data: itab type table of stpov with header line,
Equi type table of cscequi,
Knd type table of cscknd,
Mat type table of cscmat,
STD type table of cscstd,
TPL type table of csctpl.

Selection-screen begin of block BL1 with frame title T1.
Parameters:
P_werks type werks obligatory,
P_stlan type stlan obligatory.

Select-options s_matnr for it_mat-matnr no intervals. "obligatory.

Selection-screen end of block BL1.

Initialization.

T1 = 'query '.

At selection-screen.

If s_matnr is initial.
Message 'material number is mandatory! 'Type '.
Endif.

Start-of-selection.
Select matnr from Marc into Table MS where matnr in s_matnr and werks = p_werks.
Write:/'source material number', 'source material description', 'top-level material number', 'top-level material description', 'creation date', 'optional BOM number '.

Loop at ms.
Call function 'conversion _ exit_matn1_input'
Exporting
Input = MS-matnr
Importing
Output = MS-matnr.
Modify Ms.
Perform gettops using MS-matnr ''''.
Perform Disp.
Write /.
Endloop.

*&---------------------------------------------------------------------*
* & Form gettops
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> Matnr text
* --> Andat text
* --> Vwalt text
*----------------------------------------------------------------------*
Form gettops using matnr andat vwalt.

Data intab type table of stpov with header line.
Data Count type I.

Intab [] = itab [].
Local itab.
Call function 'cs _ where_used_mat'
Exporting
Datub = sy-Datum
Datuv = sy-Datum
Matnr = matnr
Stlan =''
Werks = p_werks
Mclmt = '000000'
Mnstl =''
Mxstl =''
Stltp =''
Newsi =''
Tables
Wultb = intab
Equicat = equi
Kndcat = knd
Matcat = mat
Stdcat = std
Tplcat = TPL
Exceptions
Call_invalid = 1
Material_not_found = 2
No_where_used_rec_found = 3
No_where_used_rec_selected = 4
No_where_used_rec_valid = 5
Cx_sy_dyn_call_illegal_type = 6
Others.

If sy-subrc = 0.
Loop at intab where matnr <> matnr and stlan = p_stlan.
Count = count + 1.
Endloop.
* If intab-matnr <> matnr.
* Perform gettops using intab-matnr intab-andat intab-vwalt.
*
* Endif.
* Endloop.
If Count = 0.
It_mat-matnr = matnr.
It_mat-andat = andat.
It_mat-vwalt = vwalt.
It_mat-matnr_s = MS-matnr.
Append it_mat.

Else.
Loop at intab where matnr <> matnr and stlan = p_stlan.
Perform gettops using intab-matnr intab-andat intab-vwalt.
Endloop.
Endif.
Else.
It_mat-matnr = matnr.
It_mat-andat = andat.
It_mat-vwalt = vwalt.
It_mat-matnr_s = MS-matnr.
Append it_mat.

Endif.
Endform. "gettops

*&---------------------------------------------------------------------*
* & Form disp
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
Form Disp.

* Write:/matnr, andat, vwalt.
Sort it_mat by matnr andat vwalt.
Delete adjacent duplicates from it_mat.
Loop at it_mat.
Select single maktx into it_mat-maktx
From Makt
Where matnr = it_mat-matnr and spras = '1 '.
Select single maktx into it_mat-maktx_s
From Makt
Where matnr = it_mat-matnr_s and spras = '1 '.
* Write:/it_mat-matnr under 'item number', it_mat-maktx under 'item description', IT_MAT-ANDAT under 'creation date', IT_MAT-VWALT under' optional BOM number '.
* Write:/'source item No. ', 'source item description', 'top-level item No.', 'top-level item description', 'creation date', and 'optional BOM No '.

Write:/it_mat-matnr_s, it_mat-maktx_s under 'source material description', it_mat-matnr under 'top material number', it_mat-maktx under 'top material description', it_mat-andat under 'create date', it_mat-vwalt under
'Optional BOM number '.
Endloop.
Clear it_mat.
Refresh it_mat.
Endform. "disp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.