Posted: Sun Oct 14, 2007 9:11 pm Post subject: Post PI_CONS messages for raw material consumption booking
Requirement:
In a process Industry company, PLC m/c is used to measure the raw material weight before feeding it into the bins of Furnace. The software being used for handling the PLC m/c creates a data file after the end of every shift .The data file contains charge and bin wise weight of the consumed raw material in a matrix format. But this file does not conatin the reaw material information. The requirement was to post PI_CONS messages with material, batch and weight of the material. Further, it should post good movement documents automatically.
Processing:
An application developed using ABAP provides an Screen to feed the corresponding material / Bin details with validation checks incorporated in it. An ABAP program transfers the data file that contains weight details,after the end of shift,from the remote NT m/c to the SAP application server. Further, the material information data and the corresponding weight data is combined together to create PI_CONS messages in SAP system. The messages gets posted automatically after creation, resulting in creation of consumption booking and material document posting. Before the creation of messages in SAP system the same application does a goods transfer posting (309) between the raw materials in order to create stock for pearl coke. This done as one of the raw materials (Pearl Coke ) is made after processing the other two type of cokes.
BAPI 'BAPI_PROCESS_MESSAGE_CREATEMLT' is used to create PP-PI messages in SAP.
Code:
REPORT Z_PI_CONS_MESSAGE_CREATE LINE-SIZE 200.
*----------------------------------------------------------------------*
* Written By: Ram Manohar Tiwari / Rahul Aurangabadkar
*----------------------------------------------------------------------*
* Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*
* program which creates messages for PLC interface.
* It picks up data from Z tables
TABLES : ZPLC_MATERIAL,ZPLC_WEIGHT.
DATA : BEGIN OF MESSHDR_ITAB OCCURS 0.
INCLUDE STRUCTURE BAPI_RCOMHAPI.
DATA : END OF MESSHDR_ITAB.
DATA : BEGIN OF MESSDTL_ITAB OCCURS 0.
INCLUDE STRUCTURE BAPI_RCOMEAPI.
DATA : END OF MESSDTL_ITAB.
DATA : BEGIN OF RETURN_ITAB OCCURS 0.
INCLUDE STRUCTURE BAPIRET2.
DATA : END OF RETURN_ITAB.
DATA : BEGIN OF RETURN_ITABH OCCURS 0.
INCLUDE STRUCTURE BAPI_RCOMHRTC.
DATA : END OF RETURN_ITABH.
DATA : BEGIN OF RETURN_ITABD OCCURS 0.
INCLUDE STRUCTURE BAPI_RCOMERTC.
DATA : END OF RETURN_ITABD.
DATA VAR1(35) TYPE C.
DATA VAR2 TYPE N.
FIELD-SYMBOLS : ,,,,
.
FIELD-SYMBOLS : ,,,
,.
DATA VAR_INDX TYPE I.
DATA BIN_NO TYPE I.
DATA COUNTER TYPE I.
DATA COUNTER1 TYPE I.
DATA COUNTER2 TYPE I.
DATA COUNTER3 TYPE I.
DATA COUNTER4 TYPE I.
DATA COUNTER_FOR_WEIGHT TYPE I.
DATA : BEGIN OF TEMP_ITAB OCCURS 1,
PLANT LIKE ZPLC_MATERIAL-BIN1_MATL_PLANT,
STORE LIKE ZPLC_MATERIAL-BIN1_STR_LOC,
MTL_VAL LIKE ZPLC_MATERIAL-BIN1_MATL,
BATCH_VAL LIKE ZPLC_MATERIAL-BIN1_BATCH,
PO_VAL LIKE ZPLC_MATERIAL-PON,
WEIGHT_VAL LIKE ZPLC_WEIGHT-BIN1_MATL_WEIGHT,
END OF TEMP_ITAB.
DATA STATUS_FLAG(10) TYPE C.
DATA : BEGIN OF TEMP_ITAB_SUM OCCURS 1,
PLANT LIKE ZPLC_MATERIAL-BIN1_MATL_PLANT,
STORE LIKE ZPLC_MATERIAL-BIN1_STR_LOC,
MTL_VAL LIKE ZPLC_MATERIAL-BIN1_MATL,
BATCH_VAL LIKE ZPLC_MATERIAL-BIN1_BATCH,
PO_VAL LIKE ZPLC_MATERIAL-PON,
WEIGHT_VAL LIKE ZPLC_WEIGHT-BIN1_MATL_WEIGHT,
END OF TEMP_ITAB_SUM.
DATA : ERROR_TAB LIKE TEMP_ITAB OCCURS 0.
MESSDTL_ITAB-PROC_MESS_ID_TMP = 0.
SELECT * FROM ZPLC_MATERIAL WHERE STATUS = ' '.
SELECT * FROM ZPLC_WEIGHT
WHERE CHARGE_NO BETWEEN ZPLC_MATERIAL-CHARGE_NO_FROM AND
ZPLC_MATERIAL-CHARGE_NO_TO
AND CHARGE_DATE = ZPLC_MATERIAL-CHARGE_DATE
AND SHIFT = ZPLC_MATERIAL-SHIFT.
ASSIGN ZPLC_MATERIAL TO .
ASSIGN ZPLC_WEIGHT TO .
MESSDTL_ITAB-PROC_MESS_ID_TMP = 0.
COUNTER_FOR_WEIGHT = COUNTER_FOR_WEIGHT + 1.
ASSIGN COMPONENT COUNTER OF STRUCTURE TO
.
ASSIGN COMPONENT COUNTER1 OF STRUCTURE TO
.
ASSIGN COMPONENT COUNTER2 OF STRUCTURE TO
.
ASSIGN COMPONENT COUNTER3 OF STRUCTURE TO
.
ASSIGN COMPONENT COUNTER_FOR_WEIGHT OF STRUCTURE TO
.
COUNTER = COUNTER + 4.
IF ( ( TEMP_ITAB-MTL_VAL = ' ' AND TEMP_ITAB-BATCH_VAL = ' ' AND
TEMP_ITAB-PO_VAL = ' ' AND TEMP_ITAB-WEIGHT_VAL = ' ' ) OR
( NOT TEMP_ITAB-MTL_VAL = ' ' AND NOT TEMP_ITAB-BATCH_VAL = ' '
AND NOT TEMP_ITAB-PO_VAL = ' ' AND NOT TEMP_ITAB-WEIGHT_VAL = ' '
) ).
APPEND TEMP_ITAB.
ELSE.
STATUS_FLAG = 'INCOMPLETE'.
APPEND TEMP_ITAB TO ERROR_TAB.
ENDIF.
ENDDO.
ENDSELECT.
UPDATE ZPLC_MATERIAL SET STATUS = ' ' "'C'
WHERE CHARGE_NO_FROM = ZPLC_MATERIAL-CHARGE_NO_FROM
AND CHARGE_DATE = ZPLC_MATERIAL-CHARGE_DATE
AND STATUS = ' '.
STATUS_FLAG = 'COMPLETE'. "Initializing for next run
ENDSELECT.
SORT TEMP_ITAB BY PLANT STORE MTL_VAL BATCH_VAL PO_VAL.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.