SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Post PI_CONS messages for raw material consumption booking



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sun Oct 14, 2007 9:11 pm    Post subject: Post PI_CONS messages for raw material consumption booking Reply with quote

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 = 4.
     COUNTER = 8.
     DO 10 TIMES.
        COUNTER1 = COUNTER + 1.
        COUNTER2 = COUNTER + 2.
        COUNTER3 = COUNTER + 3.
        COUNTER4 = COUNTER + 4.

        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
                                     .

        TEMP_ITAB-PLANT  = .
        TEMP_ITAB-STORE  = .

        TEMP_ITAB-MTL_VAL    = .
        TEMP_ITAB-BATCH_VAL  = .
        TEMP_ITAB-PO_VAL     = ZPLC_MATERIAL-PON.
        TEMP_ITAB-WEIGHT_VAL = .

        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.

LOOP AT TEMP_ITAB. "INTO TEMP_ITAB_WA.

AT NEW PO_VAL.

SUM.

  APPEND TEMP_ITAB TO TEMP_ITAB_SUM  .
ENDAT.

ENDLOOP.


ASSIGN TEMP_ITAB_SUM TO .
LOOP AT TEMP_ITAB_SUM.
   MESSDTL_ITAB-PROC_MESS_ID_TMP = MESSDTL_ITAB-PROC_MESS_ID_TMP + 1.
   MESSHDR_ITAB-PROC_MESS_ID_TMP = MESSDTL_ITAB-PROC_MESS_ID_TMP.
   MESSHDR_ITAB-PLANT = TEMP_ITAB_SUM-PLANT.
   MESSHDR_ITAB-PROC_MESS_CATEGORY = 'PI_CONS'.
   MESSHDR_ITAB-SENDER_NAME = SY-UNAME.
   APPEND MESSHDR_ITAB.

   DO 9 TIMES.
      IF SY-INDEX = 2.
         MESSDTL_ITAB-NAME_CHAR = 'PPPI_STORAGE_LOCATION'.
         MESSDTL_ITAB-DATA_TYPE = 'CHAR'.
      ELSEIF SY-INDEX = 3.
         MESSDTL_ITAB-NAME_CHAR = 'PPPI_MATERIAL'.
         MESSDTL_ITAB-DATA_TYPE = 'CHAR'.
      ELSEIF SY-INDEX = 4.
         MESSDTL_ITAB-NAME_CHAR = 'PPPI_BATCH'.
         MESSDTL_ITAB-DATA_TYPE = 'CHAR'.
      ELSEIF SY-INDEX = 5.
         MESSDTL_ITAB-NAME_CHAR = 'PPPI_PROCESS_ORDER'.
         MESSDTL_ITAB-DATA_TYPE = 'CHAR'.
      ELSEIF SY-INDEX = 6.
         MESSDTL_ITAB-NAME_CHAR = 'PPPI_MATERIAL_CONSUMED'.
         MESSDTL_ITAB-DATA_TYPE = 'NUM'.
      ELSEIF SY-INDEX = 7.
         MESSDTL_ITAB-NAME_CHAR = 'PPPI_UNIT_OF_MEASURE'.
         MESSDTL_ITAB-DATA_TYPE = 'CHAR'.
      ELSEIF SY-INDEX = 8.
         MESSDTL_ITAB-NAME_CHAR = 'PPPI_EVENT_DATE'.
         MESSDTL_ITAB-DATA_TYPE = 'DATE'.
      ELSEIF SY-INDEX = 9.
         MESSDTL_ITAB-NAME_CHAR = 'PPPI_EVENT_TIME'.
         MESSDTL_ITAB-DATA_TYPE = 'TIME'.
      ENDIF.
      IF SY-INDEX > 1 AND SY-INDEX <= 6.
         ASSIGN COMPONENT SY-INDEX OF STRUCTURE  TO
                                                .
         MESSDTL_ITAB-CHAR_VALUE = .
      ELSEIF SY-INDEX = 7.
         MESSDTL_ITAB-CHAR_VALUE = 'TO'.
      ELSEIF SY-INDEX = 8.
         MESSDTL_ITAB-CHAR_VALUE = SY-DATUM.
      ELSEIF SY-INDEX = 9.
         MESSDTL_ITAB-CHAR_VALUE = SY-UZEIT.

      ENDIF.
      IF SY-INDEX <> 1.
         APPEND MESSDTL_ITAB.
      ENDIF.
   ENDDO.

ENDLOOP.

     CALL FUNCTION 'BAPI_PROCESS_MESSAGE_CREATEMLT'
     TABLES
          PROCMESSHEADER       = MESSHDR_ITAB
          PROCMESSCHARAC       = MESSDTL_ITAB
          PROCMESSHEADERRETURN = RETURN_ITABH
          PROCMESSCHARACRETURN = RETURN_ITABD
          RETURN               = RETURN_ITAB
          .

   IF SY-SUBRC = 0.
      COMMIT WORK.
      WRITE : / 'Message has been created for '.

      LOOP AT MESSDTL_ITAB.
      READ TABLE RETURN_ITABH WITH KEY PROC_MESS_ID_TMP =
                                 MESSDTL_ITAB-PROC_MESS_ID_TMP.

      WRITE : / 'MSG ID',RETURN_ITABH-PROC_MESS_ID_TMP,
                'NAME :', MESSDTL_ITAB-NAME_CHAR ,
                ' VALUE : ',MESSDTL_ITAB-CHAR_VALUE.
      ENDLOOP.
      WRITE :/ ' '.

   ELSE.

      WRITE : / 'Problem in Message creation'.
      LOOP AT RETURN_ITABH.
           WRITE : / RETURN_ITABH.
      ENDLOOP.
      LOOP AT RETURN_ITABD.
           WRITE : / RETURN_ITABD.
      ENDLOOP.

      ROLLBACK WORK.
   ENDIF.
   WRITE : / RETURN_ITAB-MESSAGE.


Tables
*----------------------------------------------------------------------*
* Written By: Ram Manohar Tiwari
*----------------------------------------------------------------------*
* Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*

Material information is updated through screens in table ZPLC_MATERIAL table:

1 CHARGE_NO
2 CHARGE_DATE
3 BIN1_MATL
4 BIN1_BATCH
5 BIN1_MATL_PROCESS_ORDER_NO
6 BIN2_MATL
7 BIN2_BATCH
8 BIN2_MATL_PROCESS_ORDER_NO
9 BIN3_MATL
10 BIN3_BATCH
11 BIN3_MATL_PROCESS_ORDER_NO
12 BIN4_MATL
13 BIN4_BATCH
14 BIN4_MATL_PROCESS_ORDER_NO
15 BIN5_MATL
16 BIN5_BATCH
17 BIN5_MATL_PROCESS_ORDER_NO
18 BIN6_MATL
19 BIN6_BATCH
20 BIN6_MATL_PROCESS_ORDER_NO
21 VT1_MATL
22 VT1_BATCH
23 VT1_MATL_PROCESS_ORDER_NO
24 VT2_MATL
25 VT2_BATCH
26 VT2_MATL_PROCESS_ORDER_NO

Table ZPLC_WEIGHT is updated by the ABAP program that is sceduled in background to run after the end of the shift.

Srl. Field Name type Size Remarks

1 MANDT CLNT
2 CHARGE_NO_FROM Number 3
3 CHARGE_NO_TO Number 3
4 CHARGE_DATE Date
5 CHARGE_TIME Time
6 BIN1_MATL_WEIGHT Char 6
7 BIN2_MATL_WEIGHT Char 6
8 BIN3_MATL_WEIGHT Char 6
9 BIN4_MATL_WEIGHT Char 6
10 BIN5_MATL_WEIGHT Char 6
11 BIN6_MATL_WEIGHT Char 6
12 VT1_MATL_WEIGHT Char 6
13 VT2_MATL_WEIGHT Char 6
14 VT3_MATL_WEIGHT Char 6
15 VT4_MATL_WEIGHT Char 6
16 ENTRY_DT Date 8
17 STATUS_IND Char 1
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.