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

New PO creation from existing open PO with new organ. struct



 
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: 1636

PostPosted: Sat Mar 27, 2010 12:47 am    Post subject: New PO creation from existing open PO with new organ. struct Reply with quote

New PO creation from existing open PO with new organizational structure

Author: Qamar Javed

Code:
*&---------------------------------------------------------------------*
*& Report  YMPUR_OPENPO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  YMPUR_OPENPO.

TYPES : BEGIN OF TP_EKPO,
          EBELN TYPE EBELN,
          EBELP TYPE EBELP,
          MATNR TYPE MATNR,
          MENGE TYPE BSTMG,
          MEINS TYPE BSTME,
          KNTTP TYPE KNTTP,
          PSTYP TYPE PSTYP,
          LGORT TYPE LGORT_D,
          NETPR TYPE BPREI,
          ELIKZ TYPE ELIKZ,
          LOEKZ TYPE ELOEK,
          WERKS TYPE EWERK,
        END OF TP_EKPO.

DATA :  T_EKPO TYPE STANDARD TABLE OF TP_EKPO,
        WA_EKPO TYPE TP_EKPO.

TYPES : BEGIN OF TP_EKKO,
          EBELN TYPE EBELN,
          BSART TYPE ESART,
          LIFNR TYPE ELIFN,
          BUKRS TYPE BUKRS,
          EKORG TYPE EKORG,
          EKGRP TYPE BKGRP,
          INCO1 TYPE INCO1,
          INCO2 TYPE INCO2,
          ZTERM TYPE DZTERM,
          AEDAT TYPE ERDAT,
          KNUMV TYPE KNUMV,
          WAERS TYPE WAERS,
        END OF TP_EKKO.

DATA :  T_EKKO TYPE STANDARD TABLE OF TP_EKKO,
        WA_EKKO TYPE TP_EKKO.

DATA : W_EBELN TYPE EKKO-EBELN.

CONSTANTS: C_X TYPE C VALUE 'X'.

SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_EBELN FOR W_EBELN OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK B1.


START-OF-SELECTION.

  PERFORM FETCH_DATA.
  PERFORM GRDONE_CHECK.

END-OF-SELECTION.

  PERFORM CREATE_PO.

*&---------------------------------------------------------------------*
*&      Form  FETCH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FETCH_DATA .

  SELECT EBELN EBELP MATNR MENGE KNTTP PSTYP
         LGORT NETPR ELIKZ LOEKZ WERKS
    FROM EKPO
    INTO CORRESPONDING FIELDS OF TABLE T_EKPO
    WHERE EBELN IN S_EBELN AND ELIKZ NE 'X' AND LOEKZ EQ ' '.

  IF T_EKPO  IS INITIAL.
    " PERFORM error log
  ENDIF.

  SELECT EBELN BSART LIFNR BUKRS EKORG EKGRP INCO1
         INCO2 ZTERM AEDAT KNUMV WAERS
    FROM EKKO
    INTO TABLE T_EKKO
    FOR ALL ENTRIES IN T_EKPO
    WHERE EBELN EQ T_EKPO-EBELN.

  IF T_EKKO  IS INITIAL.
    " PERFORM error log
  ENDIF.


ENDFORM.                    " FETCH_DATA
*&---------------------------------------------------------------------*
*&      Form  GRDONE_CHECK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GRDONE_CHECK .

  DATA : TL_XEKBES TYPE STANDARD TABLE OF EKBES WITH HEADER LINE.
  DATA : L_IDX TYPE SY-TABIX.

  LOOP AT T_EKPO INTO WA_EKPO.

    L_IDX = SY-TABIX.

    CALL FUNCTION 'ME_READ_HISTORY'
      EXPORTING
        EBELN                    = WA_EKPO-EBELN
        EBELP                    = WA_EKPO-EBELP
        WEBRE                    = ''
*   I_BYPASSING_BUFFER       =
*   I_REFRESH_BUFFER         =
*   I_EKBEH                  =
*   LFGJA                    =
*   LFBNR                    =
*   LFPOS                    =
 TABLES
*   XEKBE                    =
  XEKBES                   = TL_XEKBES
*   XEKBEZ                   =
*   XEKBNK                   =
*   XEKBZ                    =
*   XRSEG                    =
.
    WA_EKPO-MENGE = WA_EKPO-MENGE - TL_XEKBES-WEMNG.
    MODIFY T_EKPO INDEX L_IDX FROM WA_EKPO TRANSPORTING MENGE.

  ENDLOOP.

ENDFORM.                    " GRDONE_CHECK

*&---------------------------------------------------------------------*
*&      Form  CREATE_PO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CREATE_PO .

  DATA: WL_HEADER TYPE BAPIMEPOHEADER,
        WL_HEADERX TYPE BAPIMEPOHEADERX,
        TL_ITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,
        TL_ITEMX TYPE STANDARD TABLE OF BAPIMEPOITEMX,
        TL_RETURN TYPE STANDARD TABLE OF BAPIRET2,
        WL_RETURN TYPE BAPIRET2,
        WL_ITEM LIKE BAPIMEPOITEM,
        WL_ITEMX LIKE BAPIMEPOITEMX,
        L_BUKRS TYPE BUKRS,
        L_PONO TYPE EBELN,
        L_INT TYPE I.

  DATA: BEGIN OF TL_BAPIRETURN OCCURS 0.
          INCLUDE STRUCTURE BAPIRET2.
  DATA: END OF TL_BAPIRETURN.

  LOOP AT T_EKKO INTO WA_EKKO.

    WL_HEADER-COMP_CODE = 'CG01'.
    WL_HEADER-DOC_TYPE = WA_EKKO-BSART.
    WL_HEADER-CREAT_DATE = WA_EKKO-AEDAT.
    WL_HEADER-ITEM_INTVL = '10'.
    WL_HEADER-VENDOR = WA_EKKO-LIFNR.
    WL_HEADER-LANGU = SY-LANGU.
    WL_HEADER-PMNTTRMS = WA_EKKO-ZTERM.
    WL_HEADER-PURCH_ORG = WA_EKKO-EKORG.
    WL_HEADER-PUR_GROUP = WA_EKKO-EKGRP.
    WL_HEADER-CURRENCY = WA_EKKO-WAERS.
    WL_HEADER-REF_1 = WA_EKKO-EBELN.

    WL_HEADERX-COMP_CODE = C_X.
    WL_HEADERX-DOC_TYPE = C_X.
    WL_HEADERX-CREAT_DATE = C_X.
    WL_HEADERX-ITEM_INTVL = C_X .
    WL_HEADERX-VENDOR = C_X.
    WL_HEADERX-LANGU = C_X.
    WL_HEADERX-PMNTTRMS = C_X .
    WL_HEADERX-PURCH_ORG = C_X.
    WL_HEADERX-PUR_GROUP = C_X.
    WL_HEADERX-CURRENCY = C_X.
    WL_HEADERX-REF_1 = C_X.

    LOOP AT T_EKPO INTO WA_EKPO WHERE EBELN = WA_EKKO-EBELN.

      L_INT = L_INT + 10.
      WL_ITEM-PO_ITEM = L_INT.
      WL_ITEM-MATERIAL = WA_EKPO-MATNR.
      WL_ITEM-PLANT = 'CGP1'.
      WL_ITEM-QUANTITY = WA_EKPO-MENGE.
      WL_ITEM-PO_UNIT = WA_EKPO-MEINS.
      WL_ITEM-STGE_LOC = WA_EKPO-LGORT.
      WL_ITEM-ITEM_CAT = WA_EKPO-PSTYP.
      WL_ITEM-NET_PRICE = WA_EKPO-NETPR.
      WL_ITEM-ACCTASSCAT = WA_EKPO-KNTTP.
      APPEND WL_ITEM TO TL_ITEM.

      WL_ITEMX-PO_ITEM = L_INT.
      WL_ITEMX-PO_ITEMX = C_X.
      WL_ITEMX-MATERIAL = C_X.
      WL_ITEMX-PLANT = C_X .
      WL_ITEMX-QUANTITY = C_X .
      WL_ITEMX-STGE_LOC = C_X .
      WL_ITEMX-ITEM_CAT = C_X .
      WL_ITEMX-NET_PRICE = C_X .
      WL_ITEMX-ACCTASSCAT = C_X.
      APPEND WL_ITEMX TO TL_ITEMX.

    ENDLOOP.

    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        POHEADER         = WL_HEADER
        POHEADERX        = WL_HEADERX
      IMPORTING
        EXPPURCHASEORDER = L_PONO
      TABLES
        RETURN           = TL_RETURN
        POITEM           = TL_ITEM
        POITEMX          = TL_ITEMX.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT   = 'X'
      IMPORTING
        RETURN = TL_BAPIRETURN.

    WRITE: / 'Puchase Doc: ', WA_EKKO-EBELN.
    SKIP.
    CLEAR: WL_HEADER, WL_ITEMX, WL_HEADERX, TL_ITEM, TL_ITEMX,WL_ITEM.

    IF L_PONO IS INITIAL.
      LOOP AT TL_RETURN INTO WL_RETURN.
        WRITE / WL_RETURN-MESSAGE.
        CLEAR WL_RETURN.
      ENDLOOP.
      ULINE.
      SKIP.
    ELSE.
      WRITE : / 'New  PO Created Under the number :',
              L_PONO HOTSPOT ON.
      ULINE.
      SKIP.
    ENDIF.

  ENDLOOP.

ENDFORM.                    " CREATE_PO
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.