0% found this document useful (0 votes)
56 views2 pages

SAP ABAP Material Code

This document contains SAP code that is querying and processing data from various tables to calculate material conversion rates and quantities for production orders. It is: 1) Querying material conversion rates from one table and material data from another table. 2) Querying valid production orders that meet certain criteria from a third table. 3) Looping through the results, performing calculations to derive equivalent pineapple cases and standard cases, and removing invalid rows.

Uploaded by

Paw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views2 pages

SAP ABAP Material Code

This document contains SAP code that is querying and processing data from various tables to calculate material conversion rates and quantities for production orders. It is: 1) Querying material conversion rates from one table and material data from another table. 2) Querying valid production orders that meet certain criteria from a third table. 3) Looping through the results, performing calculations to derive equivalent pineapple cases and standard cases, and removing invalid rows.

Uploaded by

Paw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

DATA: lv_index TYPE i.

"Get Material Conversion from CA to SC


SELECT a~material, a~denomintr, a~numerator
FROM /bi0/pmat_unit AS a
INNER JOIN @result_package AS b ON a~material = b~material AND b~erfme = 'CS'
WHERE a~objvers = 'A'
AND a~mat_unit = 'SC' "Standard Case
INTO TABLE @DATA(lt_marm).

IF sy-subrc NE 0.
"Do nothing
ENDIF.

"Get Material data


SELECT a~material, a~/bic/zdpinecof, a~matl_type, a~/bic/zdmatcls
FROM /bi0/pmaterial AS a
INNER JOIN @result_package AS b ON a~material = b~material AND b~erfme = 'CS'
WHERE a~objvers = 'A'
AND ( a~matl_type = 'ZHAL' or a~matl_type = 'ZFER' ) "Semi-finished goods or
Finished Goods only
INTO TABLE @DATA(lt_mat).

IF sy-subrc NE 0.
"Do nothing
ENDIF.

"Get Valid Production Order


SELECT a~prodorder
FROM /bi0/pprodorder AS a
INNER JOIN @result_package as b on a~PRODORDER = b~PRODORDER
WHERE a~objvers = 'A'
AND ( a~coord_type = 'ZP01' OR a~coord_type = 'ZP02' )
AND a~plant IN ( '1220','1221','1800' ) "only certain plantations
INTO TABLE @DATA(lt_pord).

IF sy-subrc NE 0.
"Do nothing
ENDIF.

LOOP AT result_package ASSIGNING <result_fields>.


lv_index = sy-tabix.

IF <result_fields>-erfme NE 'CS'.
DELETE result_package INDEX lv_index.
CONTINUE.
ELSE. "Case
"Check if valid production order
READ TABLE lt_pord TRANSPORTING NO FIELDS WITH KEY table_line =
<result_fields>-prodorder.
IF sy-subrc NE 0.
DELETE result_package INDEX lv_index.
CONTINUE.
ENDIF.

"Reversals - set quantity to negative


IF <result_fields>-bwart = '102' OR <result_fields>-bwart = '262'.
MULTIPLY <result_fields>-erfmg BY -1.
ENDIF.
"Calculate Equivalent Pineapple Case
READ TABLE lt_mat ASSIGNING FIELD-SYMBOL(<lfs_mat>) WITH KEY material =
<result_fields>-material.
IF sy-subrc EQ 0.
IF <lfs_mat>-matl_type = 'ZHAL'. "Semi-finished goods
IF NOT <lfs_mat>-/bic/zdmatcls = 'B0' OR <lfs_mat>-/bic/zdmatcls =
'B1'. "Exclude non-Brites
DELETE result_package INDEX lv_index.
CONTINUE.
ENDIF.
ENDIF.
<result_fields>-pcase = <result_fields>-erfmg * <lfs_mat>-/bic/zdpinecof.
<result_fields>-pmein = 'ZPC'.
ELSE.
DELETE result_package INDEX lv_index.
CONTINUE.
ENDIF.

"Calculate Equivalent Standard Case


READ TABLE lt_marm ASSIGNING FIELD-SYMBOL(<lfs_marm>) WITH KEY material =
<result_fields>-material.
IF sy-subrc EQ 0.
IF <lfs_marm>-numerator > 0.
<result_fields>-scase = <result_fields>-erfmg * ( <lfs_marm>-
denomintr / <lfs_marm>-numerator ).
<result_fields>-smein = 'SC'.
ENDIF.
ENDIF.

ENDIF.

* <result_fields>-fiscvarnt = 'VD'.
*
* "Derive Fiscal Year / Period
* CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
* EXPORTING
* i_date = <result_fields>-budat
* i_periv = <result_fields>-fiscvarnt
* IMPORTING
* e_buper = <result_fields>-fiscper3
* e_gjahr = <result_fields>-fiscyear
* EXCEPTIONS
* input_false = 1
* t009_notfound = 2
* t009b_notfound = 3
* OTHERS = 4.
*
* IF sy-subrc NE 0.
* "Do nothing
* ENDIF.

ENDLOOP.

You might also like