SAP MM Use ZBAPI_PO_CRATE to load open PO document

SAP MM
Use ZBAPI_PO_CRATE to load open PO document

http://www.erpgreat.com/abap/loading-purchase-orders-using-bapi-po-create.htm

 

Pls check if this code.  I used this to upload po.

*&---------------------------------------------------------------------*

*& Report  ZBAPI_PO_CRATE

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

 

REPORT  ZBAPI_PO_CRATE.

 

data : PO_HEADER like BAPIEKKOC.

data : PO_HEADER_ADD_DATA like BAPIEKKOA.

data : PO_ITEMS like BAPIEKPOC occurs 0 with header

line.

data : PO_ITEM_SCHEDULES like BAPIEKET occurs 0 with

header line.

data : RETURN like BAPIRETURN occurs 0 with header

line.

DATA : BEGIN OF TAB OCCURS 0,

       PO_NUMBER like
BAPIEKKOC-PO_NUMBER,

       DOC_DATE(10),

       DOC_TYPE like
BAPIEKKOC-DOC_TYPE,

       CO_CODE like
BAPIEKKOC-CO_CODE,

       PURCH_ORG like
BAPIEKKOC-PURCH_ORG,

       PUR_GROUP like
BAPIEKKOC-PUR_GROUP,

       VENDOR like
BAPIEKKOC-VENDOR,

       PMNTTRMS like
BAPIEKKOA-PMNTTRMS,

       INCOTERMS1 like
BAPIEKKOA-INCOTERMS1,

       INCOTERMS2 like
BAPIEKKOA-INCOTERMS2,

       PO_ITEM like 
BAPIEKPOC-PO_ITEM,

       MATERIAL like
BAPIEKPOC-MATERIAL,

       PUR_MAT like
BAPIEKPOC-PUR_MAT,

       ITEM_CAT like
BAPIEKPOC-ITEM_CAT,

       PLANT like
BAPIEKPOC-PLANT,

       NET_PRICE like
BAPIEKPOC-NET_PRICE,

       TAX_CODE like BAPIEKPOC-TAX_CODE,

       DELIV_DATE(10),

       QUANTITY like
BAPIEKET-QUANTITY,

     end of tab.

 

data: itab1 like alsmex_tabline occurs 0 with header

line.

DATA: gd_currentrow type i.

data : PURCHASEORDER like ekko-ebeln.

Data: tot_rec type i,     "Total
Records

     gd_update type i,  
"Main Table Increement

Counter

     gd_lines type
i,    "Success Table increement

Counter

     w_textout like t100-text.
"VARIABLE TO GET ERROR

LOG

 

data : begin of it_success occurs 0,

        PURCHASEORDER
LIKE ekko-ebeln,  "PROJECT

      end of it_success.

 

data : begin of it_error occurs 0,

        pono
like  ekko-ebeln,

        err_msg(73)
TYPE c,    "TO RETREIVE ERROR

MESSAGES

     end of it_error.

data : pono like  ekko-ebeln.

 

selection-screen begin of block b1 with frame.

skip 3.

parameter:p_infile like rlgrap-filename obligatory.

skip 3.

selection-screen end  of block b1.

 

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.

  PERFORM value_help.

 

start-of-selection.

 

  call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

    EXPORTING

     
filename               
= p_infile

     
i_begin_col            
= '1'

     
i_begin_row            
= '2' "Do not require

headings

     
i_end_col              
= '22'

     
i_end_row              
= '10000'

    TABLES

     
intern                 
= itab1

    EXCEPTIONS

      inconsistent_parameters =
1

     
upload_ole             
= 2

     
others                 
= 3.

  if sy-subrc <> 0.

    message e010(zz) with text-001.
"Problem uploading

Excel Spreadsheet

  endif.

 

*perform open_group.

 

  sort itab1 by row col.

 

* Get first row retrieved

  read table itab1 index 1.

 

* Set first row retrieved to current row

  gd_currentrow = itab1-row.

 

  loop at itab1.

 

* Reset values for next row

    if itab1-row ne gd_currentrow.

      append tab .

      clear tab.

      gd_currentrow = itab1-row.

    endif.

 

    case itab1-col.

 

      when '0001'. "PGNAM

        TAB-PO_NUMBER
= itab1-value.

      when '0002'. "RONAM

        TAB-DOC_DATE =
itab1-value.

      when '0003'. "JVLEVEL

        TAB-DOC_TYPE =
itab1-value.

      when '0004'. "FTTYPE

        TAB-CO_CODE =
itab1-value.

      when '0005'. "LANG

        TAB-PURCH_ORG
=  itab1-value.

      when '0006'. "LTEXT

        TAB-PUR_GROUP
= itab1-value.

      when '0007'. "LTEXT

        TAB-VENDOR =
itab1-value.

      when '0008'. "LTEXT

        TAB-PMNTTRMS =
itab1-value.

      when '0009'. "LTEXT

        TAB-INCOTERMS1
= itab1-value.

      when '0010'. "FTTYPE

        TAB-INCOTERMS2
= itab1-value.

      when '0011'. "FTTYPE

        TAB-PO_ITEM =
itab1-value.

      when '0012'. "FTTYPE

        TAB-MATERIAL =
itab1-value.

      when '0013'. "FTTYPE

        TAB-PUR_MAT =
itab1-value.

      when '0014'. "FTTYPE

        TAB-ITEM_CAT =
itab1-value.

      when '0015'. "FTTYPE

        shift
itab1-value left deleting leading space.

        TAB-PLANT =
itab1-value.

      when '0016'. "FTTYPE

        TAB-NET_PRICE
= itab1-value.

      when '0017'. "FTTYPE

        TAB-TAX_CODE =
itab1-value.

      when '0018'. "FTTYPE

        TAB-DELIV_DATE
= itab1-value.

      when '0019'. "FTTYPE

        TAB-QUANTITY =
itab1-value.

    endcase.

  endloop.

  append tab.

  clear tab.

 

  sort tab by PO_NUMBER.

  DELETE TAB WHERE PO_NUMBER = SPACE.

  loop at tab.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        INPUT  =
tab-material

      IMPORTING

        OUTPUT =
tab-material.

 

    CALL FUNCTION
'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        INPUT  =
tab-PUR_MAT

      IMPORTING

        OUTPUT =
tab-PUR_MAT.

 

 

    CALL FUNCTION
'CONVERSION_EXIT_ALPHA_INPUT'

      EXPORTING

        INPUT  =
tab-vendor

      IMPORTING

        OUTPUT =
tab-vendor.

 

 

    concatenate tab-doc_DATE+4(4)
tab-doc_DATE+2(2)

tab-doc_DATE+0(2)

into tab-doc_DATE.

    concatenate tab-DELIV_DATE+4(4)

tab-DELIV_DATE+2(2)

tab-DELIV_DATE+0(2) into tab-DELIV_DATE.

 

    pono = tab-PO_NUMBER.

    if tab-po_number = pono.

      PO_HEADER-DOC_DATE =
tab-DOC_DATE.

      PO_HEADER-DOC_TYPE =
tab-DOC_TYPE.

      PO_HEADER-CO_CODE  =
tab-CO_CODE.

      PO_HEADER-PURCH_ORG =
tab-PURCH_ORG.

      PO_HEADER-PUR_GROUP =
tab-PUR_GROUP.

      PO_HEADER-VENDOR =
tab-VENDOR.

      PO_HEADER-PO_NUMBER =
tab-PO_NUMBER.

 

     
PO_HEADER_ADD_DATA-PMNTTRMS = tab-PMNTTRMS.

     
PO_HEADER_ADD_DATA-INCOTERMS1 = tab-INCOTERMS1.

     
PO_HEADER_ADD_DATA-INCOTERMS2 = tab-INCOTERMS2.

 

      PO_ITEMS-PO_ITEM =
tab-PO_ITEM.

      PO_ITEMS-MATERIAL =
tab-MATERIAL.

      PO_ITEMS-PUR_MAT =
tab-PUR_MAT.

      PO_ITEMS-ITEM_CAT =
tab-ITEM_CAT.

      PO_ITEMS-PLANT =
tab-PLANT.

      PO_ITEMS-NET_PRICE =
tab-NET_PRICE.

      PO_ITEMS-TAX_CODE =
tab-TAX_CODE.

      append po_items.

 

      PO_ITEM_SCHEDULES-PO_ITEM
= tab-PO_ITEM.

     
PO_ITEM_SCHEDULES-DELIV_DATE = tab-DELIV_DATE.

      PO_ITEM_SCHEDULES-QUANTITY
=  tab-QUANTITY.

      append PO_ITEM_SCHEDULES.

    endif.

    at end of PO_NUMBER.

      CALL FUNCTION
'BAPI_PO_CREATE'

        EXPORTING

         
PO_HEADER                       
= PO_HEADER

        
PO_HEADER_ADD_DATA              
=

PO_HEADER_ADD_DATA

*          
HEADER_ADD_DATA_RELEVANT         =

*          
PO_ADDRESS                      
=

*          
SKIP_ITEMS_WITH_ERROR           
= 'X'

*          
ITEM_ADD_DATA_RELEVANT          
=

*          
HEADER_TECH_FIELDS              
=

       IMPORTING

         PURCHASEORDER                   
=

PURCHASEORDER

        TABLES

         
PO_ITEMS                        
= PO_ITEMS

*          
PO_ITEM_ADD_DATA                
=

         
PO_ITEM_SCHEDULES               
=

PO_ITEM_SCHEDULES

*          
PO_ITEM_ACCOUNT_ASSIGNMENT       =

*          
PO_ITEM_TEXT                    
=

        
RETURN                           
= RETURN

*          
PO_LIMITS                       
=

*          
PO_CONTRACT_LIMITS              
=

*          
PO_SERVICES                     
=

*          
PO_SRV_ACCASS_VALUES            
=

*          
PO_SERVICES_TEXT                
=

*          
PO_BUSINESS_PARTNER             
=

*          
EXTENSIONIN                     
=

*          
POADDRDELIVERY                  
=

               
.

 

      if PURCHASEORDER <>
space.

.

        commit work.

        ADD 1 TO
gd_update.

       
it_success-PURCHASEORDER = PURCHASEORDER.

        append
it_success.

       

clear:PO_HEADER,PO_HEADER_ADD_DATA,PURCHASEORDER.

        refresh :
PO_ITEMS,PO_ITEM_SCHEDULES,RETURN.

      ELSE.

        loop at
return.

         
it_error-pono = tab-PO_NUMBER.

         
it_error-err_msg = return-MESSAGE .

         
Append it_error.

        ENDLOOP.

       

clear:PO_HEADER,PO_HEADER_ADD_DATA,PURCHASEORDER.

        refresh :
PO_ITEMS,PO_ITEM_SCHEDULES,RETURN.

      endif.

    endat.

  endloop.

  DESCRIBE TABLE it_success LINES gd_lines.

  IF gd_lines GT 0.

*     Display result report column
headings

    PERFORM display_column_headings.

*     Display result report

    PERFORM DISPLAY_SUCESS.

  ENDIF.

 

* IF SUCESS FAILS Display Error Report

  DESCRIBE TABLE it_error LINES gd_lines.

  IF gd_lines GT 0.

    PERFORM errorheadings.

    PERFORM errorreport.

  ENDIF.

*&---------------------------------------------------------------------*

*&      Form 
display_column_headings

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM display_column_headings.

  WRITE:2 ' Success Report '(014) COLOR
COL_POSITIVE.

  SKIP.

  WRITE:2 'The following records inserted

successfully:'(013).

  WRITE:/ sy-uline(15).

 

  FORMAT COLOR COL_HEADING.

  WRITE:/      sy-vline,

          
(10) 'Purchase order'(004), sy-vline.

 

  WRITE:/ sy-uline(15).

ENDFORM.                   
"display_column_headings

*Subroutine to display SUCESS REPORT

FORM DISPLAY_SUCESS.

  FORMAT COLOR COL_NORMAL.

  LOOP AT it_success.

    WRITE:/     
sy-vline,

        (10) 
it_success-PURCHASEORDER, sy-vline.

 

    CLEAR it_success.

  ENDLOOP.

  WRITE:/ sy-uline(15).

  REFRESH: it_success.

  FORMAT COLOR COL_BACKGROUND.

ENDFORM.                              
"

DISPLAY_REPORT

*&---------------------------------------------------------------------*

*&      Form 
errorreport

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM errorreport.

  LOOP AT it_error.

    WRITE:/     
sy-vline,

           
(10) it_error-pono, sy-vline,

            
(40) it_error-err_msg, sy-vline.

 

  ENDLOOP.

  WRITE:/ sy-uline(104).

  REFRESH: it_error.

 

endform.                   
"errorreport

 

*&---------------------------------------------------------------------*

*&      Form 
ERRORHEADINGS

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM ERRORHEADINGS.

  SKIP.

  WRITE:2 ' Error Report '(007) COLOR COL_NEGATIVE.

  SKIP.

  WRITE:2 'The following records failed during

update:'(008).

  WRITE:/ sy-uline(104).

  FORMAT COLOR COL_HEADING.

  WRITE:/      sy-vline,

         
(10) 'ERROR.'(009), sy-vline.

 

  WRITE:/ sy-uline(104).

  FORMAT COLOR COL_NORMAL.

ENDFORM.                   
"ERRORHEADINGS

**&---------------------------------------------------------------------

**

**&      Form 
value_help

**&---------------------------------------------------------------------

**

**       text

**----------------------------------------------------------------------

**

**  --> 
p1        text

**  <-- 
p2        text

**----------------------------------------------------------------------

**

FORM value_help .

  CALL FUNCTION 'DSVAS_DOC_WS_FILENAME_GET_50'

    EXPORTING

     
DEF_FILENAME     = ' '

     
DEF_PATH         = ' '

     
MASK             =
',*.*,*.*.'

     
MODE             =
'O'

     
TITLE            = ' '

    IMPORTING

     
FILENAME         = p_infile

    EXCEPTIONS

     
INV_WINSYS       = 1

     
NO_BATCH         = 2

      SELECTION_CANCEL = 3

      SELECTION_ERROR  = 4

     
OTHERS           = 5.

  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.                   
"value_help

 

时间: 2024-11-10 12:15:10

SAP MM Use ZBAPI_PO_CRATE to load open PO document的相关文章

SAP MM PO上不勾选‘Origin Accept.’也能用107 + 109 组合移动类型收货

SAP MM PO上不勾选'Origin Accept.'也能用107 + 109 组合移动类型收货 [2016原创字-2016002] 如下PO的item 20没有勾选'Origin Accept.'选项,   却依旧能使用107+109 组合移动类型对其执行收货:        

SAP MM PO Item Category 内部code的用处?

SAP MM PO Item Category 内部code的用处? 这个内部号码在Classification里会使用到.如果你想启用审批策略,并且依赖ITEM CATEGORY,你就必须在特征值里使用ITEM CATEGORY的内部表示值了.  

SAP MM 包含多个Account Assignment Object的PO收货金额自动为0

SAP MM 包含多个Account Assignment Object的PO收货金额自动为0 1>PO# 8500010329, see the  PO history, the 101 GR history, the amount is 0.00, 2>The root cause is  that  the check box 'GR Non-Valuated' was selected, 3>There are multiple account assignment object

SAP MM 为FO类型的采购订单做MIRO时候PO Amount不自动带出来问题之对策

SAP MM 为FO类型的采购订单做MIRO时候PO Amount不自动带出来问题之对策 如下Framework 类型的采购订单,   Account Assignment Category为K, Item category 为B (limit).   此种类型的采购订单可以用于一定的时间段范围内定期向供应商付款的服务采购业务场景.它不用做收货,直接去做Invoice校验.   MIRO的时候,PO金额带不出来,如下展示:     回车,   Amount为0, 不能自动带出PO里的金额.为什么

SAP MM PO 使用了107收货之后还能用101收货?

SAP MM PO 使用了107收货之后还能用101收货? [2016原创字-2016001] SA Document Number:5500019529 Inbound Delivery :181125425 已经针对这个Inbound delivery完成107 收货:       MIGO,试图使用101针对该Inbound Delivery 做收货,   结论是:做了107收货之后,不能再做101收货.

SAP MM PO中’Origin Accept.’选项被勾选,就不能再用101移动类型执行收货了.

SAP MM PO中'Origin Accept.'选项被勾选,就不能再用101移动类型执行收货了. [2016原创字-2016003] 这个PO ITEM 30里勾选了'Origin Accept.'选项.      试图使用MIGO+101执行收货,   系统报错,不让执行101收货!

SAP MM PO没有完全收货,为什么ME2N报表里显示’To be del.’数量为0?

SAP MM PO没有完全收货,为什么ME2N报表里显示'To be del.'数量为0?   [Issue] Some data is not exact in the report run by using ME2N. Do you know why? eg. PO8500014845 The total GR quantity is 1860 not 2000, why the 'to be delivered' value is 0 in this report?       [Anal

SAP MM 如果是参考PO来创建发票,系统会将PO中的付款条件自动带入MIRO界面

SAP MM MIRO的时候,如果是参考PO来创建的话,系统会将PO中的付款条件自动带入MIRO界面   如果是同时参考多个PO来创建IV的话,系统会将第一个PO中的付款条件自动带入MIRO的界面里.经过测试,确实如此.测试效果如下.   1>2个PO,已经GR.付款条件各不相同: 和   2>MIRO的时候,先输入4500017648,再输入4500017649   3> MIRO的时候,先输入4500017649,再输入4500017648        

SAP MM PO 如果有了Confirmation记录就不能修改 Confirmation Control Key.

SAP MM PO 如果有了Confirmation记录就不能修改 Confirmation Control Key. PO number 8500010073, the confirmation control key is Z001, ME22N try to change the confirmation key from Z001 to 0001, The value of the field 'Conf.Control' cannot be changed. How to do? Cl