2018年12月19日星期三

copy customer fields from vbap to vbrp, lips to vbrp.

sap will automatically copy the append fields of vbap to vbrp.(assume the append fields name in vbap and vbrp are just the same ).
if you want to copy customer fields from lips to vbrp,
you should make change the userexit_fill_vbrk_vbrp. (LV60AA93 Line No.476 : the last line of LV60AA93)

add customer append items(BAPI_DELIVERYPROCESSING_EXEC)

1. Add append Items to structure (LESHP_DELIVERY_CREATE,SHP_VORGABE_DATEN)

2. BAPI_DELIVERYPROCESSING_EXEC (Line:186 OR Line:211)
  if not gi_bapi_dlvexec_ex is initial.

      call badi gi_bapi_dlvexec_ex->process_extensions
        exporting
          it_request            request[]
          it_partner_addr   partner_addr[]
          it_partner            partner[]
          it_bapiextc          extension1[]
          it_bapiext            extension2[]
          it_extensionin     extensionin[]
        changing
          ct_package_to_deliver lt_package_to_deliver
          ct_delivery_extend      ls_delivery_extend
          cs_control                    ls_control
          ct_interface_internal    lt_interface_internal.

    endif.

   perform userexit_prepare_001       tables     
                                                   request
                                                   extension1
                                                   extension2
                                          using    

                                               techn_control "n_711530
                                               delivery_extend
                                       changing 

                                                ls_delivery_extend
                                                ls_control
                                                lt_interface_internal
                                                lt_package_to_deliver
                                                lf_subrc.


USERExit Sample:
  userexit_prepare_001

  DATA:
  l_tbl_interface_internal TYPE STANDARD TABLE OF leshp_delivery_create,
  l_rec_extension2         LIKE LINE OF it_extension2,
  l_field                  TYPE string.

FIELD-SYMBOLS:
  <lfs_interface_internal> LIKE LINE OF ct_interface_internal,
  <lfs_field>              TYPE any.

APPEND LINES OF ct_interface_internal TO l_tbl_interface_internal.

LOOP AT it_extension2 INTO l_rec_extension2.

* READ Interface table
  READ TABLE l_tbl_interface_internal
    ASSIGNING <lfs_interface_internal>
    INDEX l_rec_extension2-row.

  IF sy-subrc IS INITIAL.

*   Field assign
    CONCATENATE '<lfs_interface_internal>-'
                l_rec_extension2-field
           INTO l_field.
    ASSIGN (l_fieldTO <lfs_field>.

    IF sy-subrc IS INITIAL.

      MOVE:
        l_rec_extension2-value TO <lfs_field>.

    ENDIF.

  ENDIF.

ENDLOOP.

CLEAR ct_interface_internal.

INSERT LINES OF l_tbl_interface_internal INTO TABLE ct_interface_internal.



3.LV50R_CREAF34 (Line.13)
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  userexit_prepare_002
*&---------------------------------------------------------------------*
FORM userexit_prepare_002
     USING    is_create_interface   TYPE leshp_delivery_create
     CHANGING cs_vorgabe_daten      TYPE shp_vorgabe_daten.



  CALL CUSTOMER-FUNCTION '002'
       EXPORTING is_interface_internal is_create_interface
       CHANGING  cs_vorgabe_daten      cs_vorgabe_daten.



ENDFORM.                    " userexit_prepare_002



For Example:

MOVE:
  is_interface_internal-yyXXX  TO cs_vorgabe_daten-yyXXX,
  is_interface_internal-yyXXX2 TO cs_vorgabe_daten-yyXXXX2,
  is_interface_internal-yyXXXX TO cs_vorgabe_daten-yyXXXX.



4.LV50R_CREAF34 (Line.33)


*&---------------------------------------------------------------------*
*&      Form  userexit_prepare_003
*&---------------------------------------------------------------------*
FORM userexit_prepare_003
     USING    is_create_interface TYPE leshp_delivery_create
     CHANGING cs_komdlgn          TYPE komdlgn.


  CALL CUSTOMER-FUNCTION '003'
       EXPORTING is_interface_internal is_create_interface
       CHANGING  cs_komdlgn            cs_komdlgn.



ENDFORM.                    " userexit_prepare_003

For Example:
MOVE:
  is_interface_internal-yyXXX  TO cs_komdlgn-yyXXXX,
  is_interface_internal-yyXXXX2 TO cs_komdlgn-yyXXXX2,
  is_interface_internal-yyXXXX TO cs_komdlgn-yyXXXX.


5.MV50AFZ1 (Line77)
FORM USEREXIT_MOVE_FIELD_TO_LIPS.

*  LIPS-zzfield = xxxx-zzfield2.
*{   INSERT         FFDK905325                                        1
DATA:
  l_rec_cvbap LIKE LINE OF CVBAP.

* SD Create Delivery
  IF gs_vorgabe_daten IS NOT INITIAL.

*   Read CVBAP
    READ TABLE cvbap INTO l_rec_cvbap
      WITH KEY vbeln lips-vgbel
               posnr lips-vgpos.

    IF SY-SUBRC IS INITIAL.

*     Field Copy
      MOVE:
        l_rec_cvbap-yyXXXX  TO lips-yyXXXX,
        l_rec_cvbap-yyXXXX2 TO lips-yyXXXX2.

    ENDIF.

*   Field Copy
    MOVE:
      gs_vorgabe_daten-yyXXXXX TO lips-yyXXXX.

  ENDIF.

* MM Create Delivery
  IF gs_komdlgn IS NOT INITIAL.

*   Field Copy
    MOVE:
      gs_komdlgn-yyXXXX  TO lips-yyXXX,
      gs_komdlgn-yyXXXX2 TO lips-yyXXXX2,
      gs_komdlgn-yyXXXXX TO lips-yyXXXX.

  ENDIF.
*}   INSERT

ENDFORM.






 

BAPI_GOODSMVT_CREATE(ADD CUSTOMER FIELD )

HEADER: ADD Customer Fields to structure of  IMKPF and BAPI_TE_XMKPF.
Items:  ADD Customer Fields to structure of  IMSEG and BAPI_TE_XMSEG.

Implements the Badi:

Line 417 of Function BAPI_GOODSMVT_CREATE .

    TRY.

        call badi lo_mb_bapi_goodsmvt_create->extensionin_to_matdoc
          EXPORTING
            EXTENSION_IN EXTENSIONIN[]
          CHANGING
            CS_IMKPF     S_IMKPF
            CT_IMSEG     T_IMSEG[]
            CT_RETURN    return.
      CATCH cx_badi_initial_reference.                  "#EC NO_HANDLER

    ENDTRY.



METHOD IF_EX_MB_BAPI_GOODSMVT_CREATE~EXTENSIONIN_TO_MATDOC.

  DATA:
    c_lenstruc          TYPE VALUE 30,
    wa_bapi_mb_header   TYPE bapi_te_xmkpf,
    wa_bapi_mb_item     TYPE bapi_te_xmseg,
    wa_extension_in     TYPE bapiparex.

  FIELD-SYMBOLS:
    <fs_imseg>          TYPE imseg.

  CHECK NOT extension_in[] IS INITIAL.

* Analyze IMSEG for document structure and assign LINE_IDs if necessary
  CALL METHOD cl_mmim_line_id_manager=>analyze_mb_create
    CHANGING
      ct_imseg          ct_imseg[]
    EXCEPTIONS
      duplicate_line_id 1
      OTHERS            2.

  LOOP AT extension_in INTO wa_extension_in.
    CASE wa_extension_in-structure.
* extension of MKPF
      WHEN 'BAPI_TE_XMKPF'.
        MOVE wa_extension_in+c_lenstruc TO wa_bapi_mb_header.
        MOVE-CORRESPONDING wa_bapi_mb_header TO cs_imkpf.
* extension of MSEG
      WHEN 'BAPI_TE_XMSEG'.
        MOVE wa_extension_in+c_lenstruc TO wa_bapi_mb_item.
        READ TABLE ct_imseg
          WITH KEY line_id wa_bapi_mb_item-matdoc_itm
          ASSIGNING <fs_imseg>.
        IF sy-subrc EQ 0.
          MOVE-CORRESPONDING wa_bapi_mb_item TO <fs_imseg>.
        ENDIF.
    ENDCASE.
  ENDLOOP.

ENDMETHOD.



2018年11月13日星期二

MD81 bapi

 DATAITEM_DATA TYPE VBAPKOM OCCURS WITH HEADER LINE,
       ITEM_DATA_OUT TYPE VBAP OCCURS WITH HEADER LINE,
       ITEM_DATAX TYPE VBAPKOMX OCCURS WITH HEADER LINE,
       PARTNER_DATA TYPE VBPAKOM OCCURS WITH HEADER LINE,
       RETURN_DATA TYPE BAPIRET2 OCCURS WITH HEADER LINE,
       SCHEDULE_DATA TYPE VBEPKOM OCCURS WITH HEADER LINE,
       SCHEDULE_DATAX TYPE VBEPKOMX OCCURS WITH HEADER LINE.
MD81作成:
 *----Header data(追加)   
  
 HEADER_DATA-AUART '01'. 
 HEADER_DATAX-AUART 'X'. 
 HEADER_DATAX-UPDKZ 'I'.  "更新区分 
  
  
  
 *----Item data 
  
 ITEM_DATA-POSNR '000010'. 
 ITEM_DATA-MATNR 'ZTST23'. 
 ITEM_DATA-WERKS 'A501'. 
 ITEM_DATA-ZIEME 'PC'. 
 ITEM_DATA-BEDAE 'KEV'. 
 APPEND ITEM_DATA. 
  
  
 ITEM_DATAX-POSNR '000010'. 
 ITEM_DATAX-UPDKZ 'I'. 
 ITEM_DATAX-MATNR 'X'. 
 ITEM_DATAX-ZIEME 'X'. 
 ITEM_DATAX-WERKS 'X'. 
 ITEM_DATAX-BEDAE 'X'. 
 APPEND ITEM_DATAX. 
  
  
 SCHEDULE_DATA-POSNR '000010'. 
 SCHEDULE_DATA-WMENG 10. 
 APPEND SCHEDULE_DATA. 
  
 SCHEDULE_DATAX-POSNR '000010'. 
 SCHEDULE_DATAX-WMENG 'X'. 
 APPEND SCHEDULE_DATAX.   
MD82:受注数量更新
 HEADER_DATA-AUART '01'.   
 HEADER_DATA-VBELN '0050000133'. 
 HEADER_DATAX-UPDKZ 'U'.  "更新区分 
  
 SCHEDULE_DATA-POSNR '000010'. 
 SCHEDULE_DATA-ETENR '0001'. 
 SCHEDULE_DATA-WMENG 30. 
 APPEND SCHEDULE_DATA. 
  
 SCHEDULE_DATAX-POSNR '000010'. 
 SCHEDULE_DATAX-ETENR '0001'. 
 SCHEDULE_DATAX-UPDKZ 'U'. 
 SCHEDULE_DATAX-WMENG 'X'. 
 APPEND SCHEDULE_DATAX.   
MD82:拒否理由更新
 HEADER_DATA-AUART '01'.   
 HEADER_DATA-VBELN '0050000133'. 
 HEADER_DATAX-UPDKZ 'U'.  "更新区分 
  
 ITEM_DATA-POSNR '000010'. 
 ITEM_DATA-ABGRU '00'. 
 APPEND ITEM_DATA. 
 * 
 * 
 ITEM_DATAX-POSNR '000010'. 
 ITEM_DATAX-UPDKZ 'U'. 
 ITEM_DATAX-ABGRU 'X'. 
 APPEND ITEM_DATAX.    
 CALL FUNCTION 'SD_SALES_DOCU_MAINTAIN'  
   EXPORTING 
     I_VBAKKOM                 HEADER_DATA 
     I_VBAKKOMX                HEADER_DATAX 
     WITH_COMMIT               'X' 
     I_CALL_BAPI               'X' 
     SUPPRESS_AVAILIBILITY_DIA 'X' 
     STATUS_BUFFER_REFRESH     'X' 
   IMPORTING 
     E_VBAK                    HEADER_OUT 
   TABLES 
     IX_VBAPKOM                ITEM_DATA 
     IX_VBAPKOMX               ITEM_DATAX 
     IX_VBEPKOM                SCHEDULE_DATA 
     IX_VBEPKOMX               SCHEDULE_DATAX 
     RETURN                    RETURN_DATA. 

Customer Characteristic

  Characteristic Descriptions are stored in the table - CABNT - Language - SPRAS - Characteristic description - ATBEZ Characteristic Values ...