You are on page 1of 8

*&---------------------------------------------------------------------* *& Report ZSLE_BAPI_PO *& *&---------------------------------------------------------------------* REPORT ZSLE_BAPI_PO.

*** Structure BAPI GET_LIST ( Ne fonctionne Pas ) DATA : BEGIN OF iTab_EKKO OCCURS 0. INCLUDE STRUCTURE BAPIEKKO. DATA : END OF iTab_EKKO. DATA : wa_group LIKE BAPIMMPARA-REL_GROUP, wa_code LIKE BAPIMMPARA-REL_CODE. DATA : wa_Qt(12) TYPE C. *** Structure BAPI pour BAPI_VENDOR_FIND DATA : BEGIN OF iTab_VENDOR_Sel OCCURS 0. INCLUDE STRUCTURE BAPIVENDOR_10. DATA : END OF iTab_VENDOR_Sel. DATA : wa_VENDOR_Sel LIKE iTab_VENDOR_Sel. DATA : BEGIN OF iTab_VENDOR_Res OCCURS 0. INCLUDE STRUCTURE BAPIVENDOR_11. DATA : END OF iTab_VENDOR_Res. *** Structure BAPI pour BAPI_VENDOR_GETDETAIL ( Table LFA1 Vendor Master ) DATA : wa_Vendor LIKE BAPIVENDOR_01-VENDOR_NO . DATA : BEGIN OF iTab_VENDOR OCCURS 0. INCLUDE STRUCTURE BAPIVENDOR_06. DATA : END OF iTab_VENDOR. *** Structure BAPI pour BAPI_PO_GETITEMS DATA : BEGIN OF iTab_EKPOC OCCURS 0. INCLUDE STRUCTURE BAPIEKPOC. DATA : END OF iTab_EKPOC. DATA : BEGIN OF iTab_EKKOL OCCURS 0. INCLUDE STRUCTURE BAPIEKKOL. DATA : END OF iTab_EKKOL. *** Structure Pour BAPI_PO_GETDETAIL DATA : BEGIN OF iTab_EKPO OCCURS 0. INCLUDE STRUCTURE BAPIEKPO. DATA : END OF iTab_EKPO. DATA : wa_EBELN LIKE EKKO-EBELN. DATA : BEGIN OF iTab_EKKN OCCURS 0. INCLUDE STRUCTURE BAPIEKKN. DATA : END OF iTab_EKKN. DATA ws_cmmda TYPE cmmda.

*------------------------------------------* Définition structure fichier texte TYPES : BEGIN OF sTab , Row(1000) TYPE C, END OF sTab. * Table Interne associées au fichiers texte DATA iTab_Down TYPE STANDARD TABLE OF sTab.

DATA wa_Tab TYPE sTab. *------------------------------------------* TRAITEMENT START-OF-SELECTION. * Récupération Liste EKKO et EKPO ( Ne récupère rien ) PERFORM GET_LIST. " BAPI_PO_GET_LIST "

PERFORM GET_VENDORS .

" " " "

BAPI_VENDOR_FIND puis BAPI_VENDOR_GETDETAIL " puis BAPI_PO_GETITEMS" puis GET_DETAIL "

*&---------------------------------------------------------------------* *& Form GET_VENDORS *&---------------------------------------------------------------------* FORM GET_VENDORS . * MISE EN PLACE CRITERE DE SELECTION wa_VENDOR_Sel-COMP_CODE = '1000'. * wa_VENDOR_Sel-COMP_CODE = '2200'. wa_VENDOR_Sel-TABNAME = 'LFB1'. wa_VENDOR_Sel-FIELDNAME = 'LIFNR'. wa_VENDOR_Sel-FIELDVALUE ='T-K515A01'. * wa_VENDOR_Sel-FIELDVALUE ='FCM1'. APPEND wa_VENDOR_Sel TO iTab_VENDOR_Sel. * Recheche des VENDORS Répondant au critères CALL FUNCTION 'BAPI_VENDOR_FIND' * EXPORTING * MAX_CNT = 0 * PL_HOLD = ' ' * IMPORTING * RETURN = TABLES SELOPT_TAB = iTab_VENDOR_Sel RESULT_TAB = iTab_VENDOR_Res . * BOUCLE de Lecture des VENDORS TROUVES LOOP AT iTab_VENDOR_Res. wa_vendor = iTab_VENDOR_Res-VENDOR_NO . CALL FUNCTION 'BAPI_VENDOR_GETDETAIL' EXPORTING VENDORNO = wa_vendor COMPANYCODE = IMPORTING GENERALDETAIL = COMPANYDETAIL = RETURN = TABLES BANKDETAIL = iTab_VENDOR .

* * * * *

" Test si table renseignée IF iTab_VENDOR IS NOT INITIAL . write : / 'Not init'. ENDIF . " Appel détail des Orders pour le Vendors PERFORM GET_ITEMS. " BAPI_PO_GETITEMS " ENDLOOP. ENDFORM. " GET_VENDORS *&---------------------------------------------------------------------* *& Form GET_ITEMS *&---------------------------------------------------------------------* FORM GET_ITEMS . REFRESH iTab_EKPOC. REFRESH iTab_EKKOL. CALL FUNCTION 'BAPI_PO_GETITEMS' EXPORTING * PURCHASEORDER = * DOC_TYPE = * DOC_DATE = * PUR_GROUP = * PURCH_ORG = VENDOR = wa_vendor * SUPPL_PLANT = * MATERIAL = * MAT_GRP = * ITEM_CAT = * ACCTASSCAT = * PLANT = * TRACKINGNO = * SHORT_TEXT = * CREATED_BY = * PREQ_NAME = ' ' * WITH_PO_HEADERS = ' ' * DELETED_ITEMS = ' ' * ITEMS_OPEN_FOR_RECEIPT = ' ' * PUR_MAT = ' ' * MATERIAL_EVG = * PUR_MAT_EVG = TABLES PO_HEADERS = iTab_EKKOL PO_ITEMS = iTab_EKPOC * RETURN = . LOOP AT iTab_EKPOC. IF iTab_EKPOC-PO_NUMBER = '4151508101'. " IF iTab_EKPOC-PO_NUMBER = '4500017051'. WRITE : / 'PO Number ' , iTab_EKPOC-PO_NUMBER COLOR COL_HEADING, 'Item ' , iTab_EKPOC-PO_ITEM, 'Matérial ' , iTab_EKPOC-MATERIAL. " Infos a partir du vendor PERFORM GET_INFORECORD. " BAPI_INFORECORD_GETLIST " PERFORM GET_DETAIL . ENDIF.

ENDLOOP. ENDFORM. " GET_ITEMS

*&---------------------------------------------------------------------* *& Form GET_DETAIL *&---------------------------------------------------------------------* FORM GET_DETAIL . DATA : BEGIN OF iTab_AdrDeliv OCCURS 0. include STRUCTURE BAPIMEPOADDRDELIVERY. DATA : END OF iTab_AdrDeliv . DATA : BEGIN OF iTab_Confirm OCCURS 0. include STRUCTURE BAPIEKES. DATA : END OF iTab_Confirm . DATA : BEGIN OF iTab_Text OCCURS 0. include STRUCTURE BAPIEKPOTX. DATA : END OF iTab_Text . DATA : BEGIN OF iTab_Histo OCCURS 0. include STRUCTURE BAPIEKBE. DATA : END OF iTab_Histo . DATA : wa_Header LIKE BAPIEKKOL , wa_Adresse LIKE BAPIADDRESS, wa_AdrDeliv LIKE BAPIMEPOADDRDELIVERY. CALL FUNCTION 'BAPI_PO_GETDETAIL1' EXPORTING PURCHASEORDER = iTab_EKPOC-PO_NUMBER * ACCOUNT_ASSIGNMENT = ' ' * ITEM_TEXT = ' ' * HEADER_TEXT = ' ' DELIVERY_ADDRESS = 'X' * VERSION = ' ' * SERVICES = ' ' * SERIALNUMBERS = ' ' * INVOICEPLAN = ' ' * IMPORTING * POHEADER = * POEXPIMPHEADER = TABLES * RETURN = * POITEM = POADDRDELIVERY = iTab_AdrDeliv * POSCHEDULE = * POACCOUNT = * POCONDHEADER = * POCOND = * POLIMITS = * POCONTRACTLIMITS = * POSERVICES = * POSRVACCESSVALUES = * POTEXTHEADER = * POTEXTITEM = * POEXPIMPITEM = * POCOMPONENTS = * POSHIPPINGEXP =

* * * * * * * * * *

POHISTORY POHISTORY_TOTALS POCONFIRMATION ALLVERSIONS POPARTNER EXTENSIONOUT SERIALNUMBER INVPLANHEADER INVPLANITEM POHISTORY_MA .

= = = = = = = = = =

** Récupération des Infos détail CALL FUNCTION 'BAPI_PO_GETDETAIL' EXPORTING PURCHASEORDER * ITEMS * ACCOUNT_ASSIGNMENT * SCHEDULES HISTORY ITEM_TEXTS * HEADER_TEXTS * SERVICES CONFIRMATIONS * SERVICE_TEXTS * EXTENSIONS IMPORTING PO_HEADER PO_ADDRESS TABLES * PO_HEADER_TEXTS PO_ITEMS PO_ITEM_ACCOUNT_ASSIGNMENT * PO_ITEM_SCHEDULES PO_ITEM_CONFIRMATIONS PO_ITEM_TEXTS PO_ITEM_HISTORY * PO_ITEM_HISTORY_TOTALS * PO_ITEM_LIMITS * PO_ITEM_CONTRACT_LIMITS * PO_ITEM_SERVICES * PO_ITEM_SRV_ACCASS_VALUES * RETURN * PO_SERVICES_TEXTS * EXTENSIONOUT .

= = = = = = = = = = =

iTab_EKPOC-PO_NUMBER 'X' ' ' ' ' 'X' 'X' ' ' ' ' 'X' ' ' ' '

= wa_Header = wa_Adresse = = = = = = = = = = = = = = = iTab_EKPO iTab_EKKN iTab_Confirm iTab_Text iTab_Histo

LOOP AT iTab_EKPO. " Adresse de Livraison DATA wa_AdrGet LIKE E1ORADR . CALL FUNCTION 'I_SMPM_ADDRESS_GET' EXPORTING ADRNR = iTab_EKPO-ADDRESS2 IMPORTING ADDRESS = wa_AdrGet . " Transformation Packet en C MOVE iTab_EKPO-QUANTITY TO wa_Qt . " Formatage ligne Enregistrement

CONCATENATE iTab_EKPO-PO_NUMBER ';' iTab_EKPO-PO_ITEM ';' iTab_EKPO-material ';' iTab_EKPO-SHORT_TEXT ';' iTab_EKPO-STATUS ';' iTab_EKPO-CHANGED_ON ';' iTab_EKPO-PUR_MAT ';' iTab_EKPO-CO_CODE ';' iTab_EKPO-PLANT ';' iTab_EKPO-STORE_LOC ';' iTab_EKPO-MAT_GRP ';' iTab_EKPO-INFO_REC ';' ""iTab_EKPO-QUANTITY ';' iTab_EKPO-UNIT ';' iTab_EKPO-ORDERPR_UN ';' ""iTab_EKPO-CONV_NUM1 ';' ""iTab_EKPO-CONV_DEN1 ';' ""iTab_EKPO-CONV_NUM2 ';' ""iTab_EKPO-CONV_DEN2 ';' ""iTab_EKPO-NET_PRICE ';' ""iTab_EKPO-PRICE_UNIT ';' ""iTab_EKPO-NET_VALUE ';' ""iTab_EKPO-GROS_VALUE ';' iTab_EKPO-INFO_UPD ';' iTab_EKPO-PRNT_PRICE ';' iTab_EKPO-ADDRESS2 ';' on INTO wa_Tab . APPEND wa_Tab TO iTab_Down . ENDLOOP.

" Adresse de Livrais

ENDFORM. " GET_DETAIL *&---------------------------------------------------------------------* *& Form GET_LIST ( ne fonctionne pas ) *&---------------------------------------------------------------------* FORM GET_LIST . DATA : BEGIN OF iTab_return OCCURS 0. include STRUCTURE BAPIRETURN. DATA : END OF iTab_return . wa_group = 100. wa_code = 01. ** Traitement entete Order CALL FUNCTION 'BAPI_PO_GET_LIST' * EXPORTING * REL_GROUP * REL_CODE * ITEMS_FOR_RELEASE TABLES PO_HEADERS * PO_ADDRESSES * PO_ADDRESSES_NEW PO_ITEMS RETURN EXCEPTIONS REL_CODE_MISSING REL_AUTHORITY_CHECK_FAILED OTHERS

= wa_group = wa_code = 'X' = iTab_EKKO = = = iTab_EKPO = iTab_return = 1 = 2 = 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. " GET_LIST

*&---------------------------------------------------------------------* *& Form BAPI_INFORECORD_GETLIST *&---------------------------------------------------------------------* FORM GET_INFORECORD . * TABLE retour erreur DATA : BEGIN OF iTab_return OCCURS 0. include STRUCTURE BAPIRETURN. DATA : END OF iTab_return . * TABLES pour BAPI_INFORECORD_GETLIST DATA : BEGIN OF iTab_PurchOrg OCCURS 0 . Include STRUCTURE BAPIEINE. DATA : END OF iTab_PurchOrg . * DATA : BEGIN OF iTab_General OCCURS 0 . Include STRUCTURE BAPIEINA. DATA : END OF iTab_General . REFRESH iTab_PurchOrg . REFRESH iTab_General . CALL FUNCTION 'BAPI_INFORECORD_GETLIST' EXPORTING VENDOR = wa_vendor * MATERIAL = * MAT_GRP = * VEND_MAT = * VEND_PART = * VEND_MATG = * PURCH_ORG = * INFO_TYPE = * PLANT = * PUR_GROUP = * PURCHASINGINFOREC = * DELETED_INFORECORDS = ' ' PURCHORG_DATA = 'X' * GENERAL_DATA = 'X' * MATERIAL_EVG = * PURCHORG_VEND = ' ' TABLES INFORECORD_GENERAL = iTab_General INFORECORD_PURCHORG = iTab_PurchOrg RETURN = iTab_return .

ENDFORM.

" GET_INFORECORD