Home > Default > Help - Error in PR BAPI :  Purchasing across company codes is not allowed..

Help - Error in PR BAPI :  Purchasing across company codes is not allowed..

October 11Hits:2
Advertisement
I have written a program to create Purchase Requisition.I am using two BAPIs.In the file i specify the old PR No, New Plant,Purch Group and Purch Org.It is actually a program to create a new PR in a new plant which is a copy of an Old PR in older plant.
Program is below:
I am getting the error Purchasing across company codes is not allowed..
Please Help
*& Report  ZMMB_BDC_ME51N_WO
REPORT  ZMMB_BDC_ME51N_WO.
INITIALIZATION.
D A T A   D E C L A R A T I O N                                     *
  TYPES: BEGIN OF TY_TABDATA,
          BANFN TYPE EBAN-BANFN, " Purchase Requistion No
          WERKS TYPE MEREQ3211GRID-WERKS, "Plant
          EKGRP TYPE MEREQ3211GRID-EKGRP, "Purchasing Group
          EKORG TYPE MEREQ3211GRID-EKORG, "Purchasing Organization
         END OF TY_TABDATA.
  TYPES: BEGIN OF TY_CHECK,
            BANFN TYPE EBAN-BANFN, " Purchase Requistion No
            BNFPO TYPE EBAN-BNFPO, " Purchase Requistion Item No
            EBAKZ TYPE EBAN-EBAKZ, " PR Closed
         END OF TY_CHECK.
Declaration of the Internal Table & Work Area.
  DATA:
         IT_TABDATA         TYPE  STANDARD  TABLE  OF   TY_TABDATA, " Internal Table for file
         WA_TABDATA         TYPE                       TY_TABDATA.
  DATA: IT_ITEM TYPE STANDARD TABLE OF BAPIEBAN ,
        WA_ITEM LIKE LINE OF IT_ITEM,
        IT_ITEM1 TYPE STANDARD TABLE OF BAPIEBANC,
        WA_ITEM1 LIKE LINE OF IT_ITEM1,
        IT_ACCOUNT TYPE STANDARD TABLE OF BAPIEBKN,
        WA_ACCOUNT LIKE LINE OF IT_ACCOUNT,
        IT_PRITEMTEXT TYPE STANDARD TABLE OF BAPIEBANTX,
        WA_PRITEMTEXT LIKE LINE OF IT_PRITEMTEXT,
        IT_SERVICES TYPE STANDARD TABLE OF BAPIESLL ,
        WA_SERVICES LIKE LINE OF IT_SERVICES,
        IT_SERVICES1 TYPE STANDARD TABLE OF BAPIESLLC ,
        WA_SERVICES1 LIKE LINE OF IT_SERVICES1,
        IT_SERVICETEXT TYPE STANDARD TABLE OF BAPIESLLTX,
        WA_SERVICETEXT LIKE LINE OF IT_SERVICETEXT,
        IT_CHECK TYPE STANDARD TABLE OF TY_CHECK,
        WA_CHECK LIKE LINE OF IT_CHECK.
   Global data Declaration
  DATA:   GV_YEAR(4)         TYPE C,
          GV_MNTH(2)         TYPE C,
          GV_DATE(2)         TYPE C,
          GV_DATUM(8)       TYPE C,
          GV_ANS TYPE C,
          W_FILENAME      TYPE  STRING.
Declaration of the Internal Table with Header Line comprising of the uploaded data.
  DATA:  BEGIN  OF  IT_FILE_UPLOAD  OCCURS  0.
  INCLUDE  STRUCTURE  ALSMEX_TABLINE.  "  Rows for Table with Excel Data
  DATA:  END  OF  IT_FILE_UPLOAD.
Batch Input Data for a single Transaction.
Message of Call Transaction.
  DATA:  BDCDATA  LIKE  BDCDATA     OCCURS  0  WITH  HEADER  LINE,
         MSGTAB   LIKE  BDCMSGCOLL  OCCURS  0  WITH  HEADER  LINE.
S E L E C T I O N - S C R E E N                                     *
  SELECTION-SCREEN:  BEGIN  OF  BLOCK  B1  WITH  FRAME TITLE TEXT-001,
                         BEGIN  OF  BLOCK  B2  WITH  FRAME TITLE TEXT-004.
  PARAMETERS: P_FNAME  LIKE  RLGRAP-FILENAME  OBLIGATORY.
  SELECTION-SCREEN:      END  OF  BLOCK  B2,
                     END  OF  BLOCK  B1.
E V E N T : AT    S E L E C T I O N - S C R E E N                   *
AT  SELECTION-SCREEN  ON  VALUE-REQUEST  FOR  P_FNAME.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      STATIC    = 'X'
    CHANGING
      FILE_NAME = P_FNAME.
E V E N T : S T A R T - O F - S E L E C T I O N                     *
START-OF-SELECTION.
Upload Excel file into Internal Table.
  PERFORM  UPLOAD_EXCEL_FILE.
  IF  NOT  IT_FILE_UPLOAD  IS  INITIAL.
  Confirm whether you want to proceed with the Upload.
    PERFORM  CONFIRM_UPLOAD.
    IF  GV_ANS  EQ  '1'.
  Organize the uploaded data into another Internal Table.
      PERFORM  ORGANIZE_UPLOADED_DATA.
      PERFORM BAPI_CALL.
    ENDIF.
  ELSE.
    LEAVE PROGRAM.
  ENDIF.
*&      Form  UPLOAD_EXCEL_FILE
      text
-->  p1        text
<--  p2        text
FORM UPLOAD_EXCEL_FILE .
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      FILENAME                = P_FNAME
      I_BEGIN_COL             = 1
      I_BEGIN_ROW             = 4
      I_END_COL               = 4
      I_END_ROW               = 9999
    TABLES
      INTERN                  = IT_FILE_UPLOAD
    EXCEPTIONS
      INCONSISTENT_PARAMETERS = 1
      UPLOAD_OLE              = 2
      OTHERS                  = 3.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                    " UPLOAD_EXCEL_FILE
*&      Form  CONFIRM_UPLOAD
      text
-->  p1        text
<--  p2        text
FORM CONFIRM_UPLOAD .
  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
      TITLEBAR       = TEXT-002
      TEXT_QUESTION  = TEXT-003
    IMPORTING
      ANSWER         = GV_ANS
    EXCEPTIONS
      TEXT_NOT_FOUND = 1
      OTHERS         = 2.
ENDFORM.                    " CONFIRM_UPLOAD
*&      Form  ORGANIZE_UPLOADED_DATA
      text
-->  p1        text
<--  p2        text
FORM ORGANIZE_UPLOADED_DATA .
  DATA : GV_TOTROW TYPE I, "No of records
          GV_ROW TYPE I,
          LC_CNT(3) TYPE N.
  GV_TOTROW = 1.
  SORT  IT_FILE_UPLOAD  BY  ROW
                          COL.
  LOOP AT IT_FILE_UPLOAD.
    GV_TOTROW = IT_FILE_UPLOAD-ROW.
  ENDLOOP.
  GV_ROW = 1.
  WHILE GV_ROW <= GV_TOTROW.
    LOOP  AT  IT_FILE_UPLOAD WHERE ROW = GV_ROW.
      CASE  IT_FILE_UPLOAD-COL.
        WHEN '0001'.
          WA_TABDATA-BANFN = IT_FILE_UPLOAD-VALUE.
        WHEN '0002'.
          WA_TABDATA-WERKS = IT_FILE_UPLOAD-VALUE.
        WHEN '0003'.
          WA_TABDATA-EKGRP = IT_FILE_UPLOAD-VALUE.
        WHEN '0004'.
          WA_TABDATA-EKORG = IT_FILE_UPLOAD-VALUE.
      ENDCASE.
    ENDLOOP.
    GV_ROW = GV_ROW + 1.
    APPEND WA_TABDATA TO   IT_TABDATA .
    CLEAR :WA_TABDATA.
  ENDWHILE.
ENDFORM.                    " ORGANIZE_UPLOADED_DATA
*&      Form  BAPI_CALL
      text
-->  p1        text
<--  p2        text
FORM BAPI_CALL .
  DATA:ITM_NO(4) TYPE N,LV_PERCENTAGE(3) TYPE N,
       LV_MSG(60),
       IT_RETURN TYPE STANDARD TABLE OF BAPIRETURN,
       WA_RETURN LIKE LINE OF IT_RETURN.
  DATA: BEGIN OF WA_RETURN1,
        BANFN TYPE EBAN-BANFN.
  INCLUDE  TYPE BAPIRETURN.
  DATA END OF WA_RETURN1.
  DATA:IT_RETURN1 LIKE STANDARD TABLE OF WA_RETURN1.
  DESCRIBE TABLE IT_TABDATA LINES ITM_NO.
  LOOP AT IT_TABDATA INTO WA_TABDATA.
    CALL FUNCTION 'BAPI_REQUISITION_GETDETAIL'
      EXPORTING
        NUMBER                               = WA_TABDATA-BANFN
       ACCOUNT_ASSIGNMENT                   = 'X'
       ITEM_TEXTS                           = 'X'
       SERVICES                             = 'X'
       SERVICE_TEXTS                        = 'X'
      TABLES
        REQUISITION_ITEMS                    = IT_ITEM
       REQUISITION_ACCOUNT_ASSIGNMENT       = IT_ACCOUNT
       REQUISITION_TEXT                     = IT_PRITEMTEXT
  REQUISITION_LIMITS                   =
  REQUISITION_CONTRACT_LIMITS          =
   REQUISITION_SERVICES                 = IT_SERVICES
   REQUISITION_SERVICES_TEXTS           = IT_SERVICETEXT
  REQUISITION_SRV_ACCASS_VALUES        =
  RETURN                               =
    COMPUTE LV_PERCENTAGE = ( ITM_NO / SY-TABIX ) * 100.
    CONCATENATE 'PROCESSING PURCHASING REQUISITION FOR OLD PR NUMBER ' WA_TABDATA-BANFN INTO LV_MSG.
    CALL FUNCTION 'RM_SAPGUI_PROGRESS_INDICATOR'
      EXPORTING
        PERCENTAGE = LV_PERCENTAGE
        TEXT       = LV_MSG.
    CLEAR:LV_PERCENTAGE ,LV_MSG.
    IF IT_TABDATA[] IS NOT INITIAL.
      SELECT BANFN BNFPO EBAKZ FROM EBAN INTO TABLE IT_CHECK FOR ALL ENTRIES IN IT_TABDATA
          WHERE BANFN = IT_TABDATA-BANFN AND EBAKZ = 'X'.
    ENDIF.
    LOOP AT IT_CHECK INTO WA_CHECK.
      LOOP AT IT_ITEM INTO WA_ITEM WHERE PREQ_NO = WA_CHECK-BANFN AND PREQ_ITEM = WA_CHECK-BNFPO.
        DELETE IT_ITEM WHERE PREQ_NO = WA_CHECK-BANFN AND PREQ_ITEM = WA_CHECK-BNFPO.
      ENDLOOP.
      LOOP AT IT_ACCOUNT INTO WA_ACCOUNT WHERE PREQ_NO = WA_CHECK-BANFN AND PREQ_ITEM = WA_CHECK-BNFPO.
        DELETE IT_ACCOUNT WHERE PREQ_NO = WA_CHECK-BANFN AND PREQ_ITEM = WA_CHECK-BNFPO.
      ENDLOOP.
    ENDLOOP.
    LOOP AT IT_ITEM INTO WA_ITEM.
      WA_ITEM-PLANT = WA_TABDATA-WERKS.
      WA_ITEM-PUR_GROUP = WA_TABDATA-EKGRP.
      WA_ITEM-PURCH_ORG = WA_TABDATA-EKORG.
      MODIFY IT_ITEM FROM WA_ITEM TRANSPORTING PLANT PUR_GROUP PURCH_ORG.
      MOVE-CORRESPONDING WA_ITEM TO WA_ITEM1.
      WA_ITEM1-PREQ_NO = ''.
      WA_ITEM1-STORE_LOC = ''.
      APPEND WA_ITEM1 TO IT_ITEM1.
      CLEAR WA_ITEM1.
    ENDLOOP.
    LOOP AT IT_ACCOUNT INTO WA_ACCOUNT.
      WA_ACCOUNT-PREQ_NO = ''.
      MODIFY IT_ACCOUNT FROM WA_ACCOUNT TRANSPORTING PREQ_NO.
    ENDLOOP.
    LOOP AT IT_SERVICES INTO WA_SERVICES.
      MOVE-CORRESPONDING WA_SERVICES TO WA_SERVICES1.
      APPEND WA_SERVICES1 TO IT_SERVICES1.
      CLEAR WA_SERVICES1.
    ENDLOOP.
    CALL FUNCTION 'BAPI_REQUISITION_CREATE'
   EXPORTING
     SKIP_ITEMS_WITH_ERROR                =
     AUTOMATIC_SOURCE                     = 'X'
   IMPORTING
     NUMBER                               =
      TABLES
        REQUISITION_ITEMS                    = IT_ITEM1
       REQUISITION_ACCOUNT_ASSIGNMENT       = IT_ACCOUNT
       REQUISITION_ITEM_TEXT                = IT_PRITEMTEXT
     REQUISITION_LIMITS                   =
     REQUISITION_CONTRACT_LIMITS          =
      REQUISITION_SERVICES                 = IT_SERVICES1
     REQUISITION_SRV_ACCASS_VALUES        =
       RETURN                               = IT_RETURN
      REQUISITION_SERVICES_TEXT            = IT_SERVICETEXT
     REQUISITION_ADDRDELIVERY             =
     EXTENSIONIN                          =
    READ TABLE IT_RETURN INTO WA_RETURN INDEX 1.
    IF WA_RETURN-TYPE = 'E'.
      CLEAR WA_RETURN.
      LOOP AT IT_RETURN INTO WA_RETURN WHERE TYPE EQ 'E'.
        WA_RETURN1-BANFN = WA_TABDATA-BANFN.
        MOVE-CORRESPONDING WA_RETURN TO  WA_RETURN1.
        APPEND WA_RETURN1 TO IT_RETURN1.
        CLEAR WA_RETURN1.
      ENDLOOP.
    ELSE.
      WA_RETURN1-BANFN = WA_TABDATA-BANFN.
      MOVE-CORRESPONDING WA_RETURN TO  WA_RETURN1.
      APPEND WA_RETURN1 TO IT_RETURN1.
      CLEAR WA_RETURN1.
    ENDIF.
    IF SY-SUBRC <> 0.
    ENDIF.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING
         WAIT          =
       IMPORTING
         RETURN        =
    REFRESH: IT_RETURN[],IT_ITEM[],IT_ACCOUNT[],IT_PRITEMTEXT[],IT_ITEM1[],IT_SERVICES[],IT_SERVICES1[],
             IT_SERVICETEXT[].
  ENDLOOP.
  WRITE :10 'OLD PR NUMBER' COLOR COL_KEY, 25 'MESSAGE' COLOR COL_KEY.
  LOOP AT IT_RETURN1 INTO WA_RETURN1.
    WRITE:/10 WA_RETURN1-BANFN,25 WA_RETURN1-MESSAGE.
  ENDLOOP.
  CLEAR:IT_TABDATA[],WA_TABDATA.
ENDFORM   .                 "BAPI_CALL

Answers

Solved on Own

Read other 2 answers

Tags:

Related Articles

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.692 s.