2019年12月19日星期四

PIR

report ZYPB840.

types:
  begin of TYP_PIR_KEY,
    MATNR type MATNR,
    PBDNR type PBIM-PBDNR,
  end of TYP_PIR_KEY,
  begin of TYP_FILE,
    ROW type STRING,
  end of TYP_FILE,
  I_TYP_FILE type standard table of TYP_FILE.

data:
  G_KUNNR type ZXP24-KUNNR,
  G_KBN   type ZXP24-ZZKUBUN,
  G_KDMAT type ZXP24-KDMAT,
  G_NOUKI type ZXP24-ZZNOUKI,
  GI_SYS  type I_TYP_FILE,
  GI_TRN  type I_TYP_FILE,
  GI_END  type I_TYP_FILE.


select-options:
  S_KUNNR for G_KUNNR,
  S_KBN   for G_KBN,
  S_KDMAT for G_KDMAT,
  S_NOUKI for G_NOUKI obligatory.

selection-screen:skip 2.

parameters:
  P_FOLD1 type  FILEPATH-PATHINTERN obligatory,
  P_FOLD2 type  FILEPATH-PATHINTERN obligatory,
  P_FOLD3 type  FILEPATH-PATHINTERN obligatory.

selection-screen:skip 1.

parameters:
  P_WAIT1 type I,
  P_WAIT2 type I.



initialization.
  S_NOUKI-SIGN 'I'.
  S_NOUKI-OPTION 'EQ'.
  S_NOUKI-LOW SY-DATUM 30.
  append S_NOUKI.
  P_WAIT1 60.
  P_WAIT2 300.


at selection-screen.

start-of-selection.
  perform F_MAIN.

end-of-selection.
  if GI_SYS is not initial.
    perform F_WRITE_LOG using '1' GI_SYS.
  endif.
  perform F_WRITE_LOG using '2' GI_TRN.
  perform F_WRITE_LOG using '3' GI_END.
  if GI_SYS is initial and LINESGI_TRN <= .
    message '正常終了' type 'S'.
  else.
    message 'エラー発生、ログ参照' type 'S' display like 'E'.
  endif.


*&---------------------------------------------------------------------*
*& Form f_main 主処理
*&---------------------------------------------------------------------*
form F_MAIN.
  data:
    LI_ZXP24   type standard table of ZXP24,
    LW_ZXP24   type ZXP24,
    LW_PIR_KEY type TYP_PIR_KEY,
    LI_PIR_KEY type standard table of TYP_PIR_KEY,
    LI_PBIM    type standard table of PBIM,
    LV_JOBNAME type TBTCO-JOBNAME,
    LW_PBIM    type PBIM,
    LW_TRN     type TYP_FILE,
    LW_SYS     type TYP_FILE,
    LV_FLG     type CHAR01,
    LV_INDEX   type I.

* mrp実行確認
  clearLV_FLG,
         GI_SYS,
         GI_TRN.

  do times.
    LV_INDEX SY-INDEX.
    select single JOBNAME into LV_JOBNAME
    from TBTCO where JOBNAME like '%MRP%'.
    if SY-SUBRC <> 0.
      LV_FLG ABAP_ON.
      exit.
    else.
      if LV_INDEX < 3.
        wait up to P_WAIT1 seconds.
      endif.
    endif.
  enddo.

  if LV_FLG is initial.
    LW_SYS-ROW 'MRP実行中。。。。。。'.
    append LW_SYS to GI_SYS.
    return.
  endif.




* テーブルロック処理
  do times.
    LV_INDEX SY-INDEX.
    call function 'ENQUEUE_E_TABLE'
      exporting
        MODE_RSTABLE   'E'
        TABNAME        'ZXP24'
      exceptions
        FOREIGN_LOCK   1
        SYSTEM_FAILURE 2
        others         3.
    if SY-SUBRC 0.
      LV_FLG ABAP_ON.
      exit.
    else.
      if LV_INDEX < 3.
        wait up to P_WAIT2 seconds.
      endif.
    endif.
  enddo.

  if LV_FLG is initial.
    LW_SYS-ROW 'ロックエラー。。。。。'.
    append LW_SYS to GI_SYS.
    return.
  endif.



* データ抽出処理
  select from ZXP24
  into table LI_ZXP24
  where KUNNR     in S_KUNNR  and
        ZZKUBUN   in S_KBN    and
        KDMAT     in S_KDMAT  and
        ZZNOUKI   in S_NOUKI  and
        ZZUPDDATE_FLG 'X'   and

        ZZDELETE_FLG SPACE.

  check LI_ZXP24 is not initial.

  loop at LI_ZXP24 into LW_ZXP24.
    LW_PIR_KEY-MATNR LW_ZXP24-MATNR.
    LW_PIR_KEY-PBDNR LW_ZXP24-KUNNR+5(5&& LW_ZXP24-ZZKUBUN.
    append LW_PIR_KEY to LI_PIR_KEY.
  endloop.
  sort LI_PIR_KEY by MATNR ascending
                     PBDNR ascending.

  delete adjacent duplicates from LI_PIR_KEY.

*(2)独立所要量データ
* 内示データに該当独立所要量データを取得する
  select from PBIM into table LI_PBIM
  for all entries in  LI_PIR_KEY
  where MATNR LI_PIR_KEY-MATNR and
        PBDNR LI_PIR_KEY-PBDNR.

  concatenate TEXT-H01
              TEXT-H02
              TEXT-H03
              TEXT-H04
              TEXT-H05
   into LW_TRN-ROW separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
  append LW_TRN to GI_TRN.

*(4) 独立所要量登録更新処理
  loop at LI_ZXP24 into LW_ZXP24.

    read table LI_PBIM into LW_PBIM
    with key MATNR LW_ZXP24-MATNR
             VERSB =  LW_ZXP24-KUNNR+5(5&& LW_ZXP24-ZZKUBUN.
    if SY-SUBRC <> 0.
      perform F_CREATE using LW_ZXP24.
    else.
      perform F_CHANGE using LW_ZXP24.
    endif.
  endloop.


* テーブルアンロック処理
  call function 'DEQUEUE_E_TABLE'
    exporting
      MODE_RSTABLE 'E'
      TABNAME      'ZXP24'.


endform.



*&---------------------------------------------------------------------*
*& Form CREATE 登録処理
*&---------------------------------------------------------------------*
form F_CREATE using UV_ZXP24 type ZXP24.

  data:
    LW_BAPISITEMR type BAPISITEMR,
    LI_SCHEDULE   type standard table of BAPISSHDIN,
    LW_SCHEDULE   type BAPISSHDIN,
    LI_RETURN     type standard table of BAPIRETURN1,
    LW_RETURN     type BAPIRETURN1,
    LW_ZXP24      type ZXP24,
    LV_ERRFLG     type CHAR01,
    LW_TRN        type TYP_FILE.

  "品目
  LW_BAPISITEMR-MATERIAL UV_ZXP24-MATNR.
  "プラント
  LW_BAPISITEMR-PLANT '1000'.
  "所要量タイプ
  LW_BAPISITEMR-REQU_TYPE 'LSF'.
  "所要量のバージョン番号
  LW_BAPISITEMR-VERSION '01'.
  "バージョン有効フラグ
  LW_BAPISITEMR-VERS_ACTIV 'X'.
  LW_BAPISITEMR-REQ_NUMBER UV_ZXP24-KUNNR+5(5&& UV_ZXP24-ZZKUBUN.


  clear LI_SCHEDULE.
  LW_SCHEDULE-DATE_TYPE '1'.   "day
  LW_SCHEDULE-REQ_DATE  UV_ZXP24-ZZNOUKI.
  LW_SCHEDULE-REQ_QTY   UV_ZXP24-ZZSUU.
*  LW_SCHEDULE-unit     = c_unit.
  append LW_SCHEDULE to LI_SCHEDULE.


  call function 'BAPI_REQUIREMENTS_CREATE' " Bapi to Create Planned Independent Reqmts
    exporting
      REQUIREMENTS_ITEM        LW_BAPISITEMR
      DO_COMMIT                'X'
      UPDATE_MODE              'X'
    tables
      REQUIREMENTS_SCHEDULE_IN LI_SCHEDULE
      RETURN                   LI_RETURN.

  loop at LI_RETURN into LW_RETURN
    where TYPE 'A' or
          TYPE 'E'.
    LV_ERRFLG 'X'.
  endloop.
  if LV_ERRFLG  is initial.
    LW_ZXP24 UV_ZXP24.
    clear LW_ZXP24-ZZUPDDATE_FLG.
    LW_ZXP24-AEDAT SY-DATUM.
    LW_ZXP24-AENAM SY-UNAME.
    LW_ZXP24-UDLTIME SY-UZEIT.
    modify ZXP24 from LW_ZXP24.
    commit work.
  else.
    concatenate UV_ZXP24-KUNNR
                UV_ZXP24-ZZKUBUN
                UV_ZXP24-KDMAT
                UV_ZXP24-ZZNOUKI
                LW_RETURN-MESSAGE
    into LW_TRN-ROW separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    append LW_TRN to GI_TRN.


  endif.

endform.



*&---------------------------------------------------------------------*
*& Form change 更新処理
*&---------------------------------------------------------------------*

form F_CHANGE using UV_ZXP24 type ZXP24.

  data:
    LW_BAPISITEMR type BAPISITEMR,
    LI_SCHEDULE   type standard table of BAPISSHDIN,
    LW_SCHEDULE   type BAPISSHDIN,
    LI_RETURN     type standard table of BAPIRETURN1,
    LW_RETURN     type BAPIRETURN1,
    LV_ERRFLG     type CHAR01,
    LW_ZXP24      type ZXP24,
    LW_TRN        type TYP_FILE.


  clear LI_SCHEDULE.
  LW_SCHEDULE-DATE_TYPE '1'.   "day
  LW_SCHEDULE-REQ_DATE  UV_ZXP24-ZZNOUKI.
  LW_SCHEDULE-REQ_QTY   UV_ZXP24-ZZSUU.
*  LW_SCHEDULE-unit     = c_unit.
  append LW_SCHEDULE to LI_SCHEDULE.


  call function 'BAPI_REQUIREMENTS_CHANGE'
    exporting
      MATERIAL                 UV_ZXP24-MATNR
      PLANT                    '1000'
      REQUIREMENTSTYPE         'LSF'
      VERSION                  UV_ZXP24-KUNNR+5(5&& UV_ZXP24-ZZKUBUN
      REQMTSPLANNUMBER         ''
      VERS_ACTIV               'X'
      DO_COMMIT                'X'
      UPDATE_MODE              'X'
    tables
      REQUIREMENTS_SCHEDULE_IN LI_SCHEDULE
      RETURN                   LI_RETURN.

  loop at LI_RETURN into LW_RETURN
     where TYPE 'A' or
           TYPE 'E'.
    LV_ERRFLG 'X'.
  endloop.
  if LV_ERRFLG  is initial.
    LW_ZXP24 UV_ZXP24.
    clear LW_ZXP24-ZZUPDDATE_FLG.
    LW_ZXP24-AEDAT SY-DATUM.
    LW_ZXP24-AENAM SY-UNAME.
    LW_ZXP24-UDLTIME SY-UZEIT.
    modify ZXP24 from LW_ZXP24.
    commit work.
  else.
    concatenate UV_ZXP24-KUNNR
          UV_ZXP24-ZZKUBUN
          UV_ZXP24-KDMAT
          UV_ZXP24-ZZNOUKI
          LW_RETURN-MESSAGE
    into LW_TRN-ROW separated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    append LW_TRN to GI_TRN.

  endif.

endform.
*&---------------------------------------------------------------------*
*& Form F_WRITE_LOG サーバ7ファイル作成処理
*&---------------------------------------------------------------------*
form F_WRITE_LOG using UV_TYPE type CHAR01
                       UI_CONTENTS type I_TYP_FILE.
  data:LV_PATH   type FILEPATH-PATHINTERN,
       LV_FILE   type STRING,
       LV_FILENM type STRING,
       LV_ROW    type TYP_FILE.

  if UV_TYPE 1.
    LV_PATH P_FOLD1.
    LV_FILE TEXT-T01 && SY-DATUM && SY-UZEIT && '.txt'.
  elseif UV_TYPE 2.

    LV_PATH P_FOLD2.
    LV_FILE TEXT-T02 && SY-DATUM && SY-UZEIT && '.txt'.
  else.
    LV_PATH P_FOLD3.
    LV_FILE TEXT-T03 && SY-DATUM && SY-UZEIT && '.txt'.
  endif.


  call function 'FILE_GET_NAME_USING_PATH'
    exporting
      LOGICAL_PATH               LV_PATH
      FILE_NAME                  LV_FILE
    importing
      FILE_NAME_WITH_PATH        LV_FILENM
    exceptions
      PATH_NOT_FOUND             1
      MISSING_PARAMETER          2
      OPERATING_SYSTEM_NOT_FOUND 3
      FILE_SYSTEM_NOT_FOUND      4
      others                     5.
  if SY-SUBRC <> 0.
* Implement suitable error handling here
  endif.

  open dataset LV_FILENM for output
    in legacy text mode  code page '8000'
     with windows linefeed .
  loop at UI_CONTENTS into LV_ROW.
    transfer LV_ROW-ROW to  LV_FILENM.
  endloop.
  close dataset  LV_FILENM.

endform.

2019年12月18日星期三

VA01 BAPI EXTENSIONS

FUNCTION:SD_SALESDOCUMENT_CREATE
Append fiels to Structure below.
BAPE_VBAP
BAPE_VBAPX
VBAPKOZ
VBAPKOZX
No need to append fields to Structure VBAPKOM and VBAPKOMX.
(VBAPKOM ----include VBAPKOZ 
 VBAPKOMX ---include VBAPKOZX) 


1) VBAP: In your append structure you specify your ZZFIELD with the data type as needed

2) BAPE_VBAP: In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters

3) BAPE_VBAPX: In the append structure add the field ZZFIELD of type BAPIUPDATE

(NOTE: (2) and (3) must have the same number of fields in the same order)

4) VBAPKOZ: In the append structure here also add the ZZFIELD with the data type as needed with limitations. No decimals. Try and stick to char characters

5) VBAPKOZX: In the append structure add the field ZZFIELD of type BAPIUPDATE

(NOTE: (4) and (5) must have the same number of fields in the same order)

(Note: A great tip from Hendrik Maas: Use Data element CHAR1 instead of BAPIUPDATE as it will not work for BAPI_SALESDOCUMENT_CHANGE)

Similarly do for VBAK, BAPE_VBAK, BAPE_VBAKX, VBAKKOZ and VBAKKOZX.

Next we get to the code to fill in the structure EXTENSIONIN
I will demonstrate how to call the create sales order BAPI with custom fields.

* Local definitions
  DATA: wa_extensionin TYPE bapiparex,
        wa_bape_vbap   TYPE bape_vbap,
        wa_bape_vbapx  TYPE bape_vbapx,
        wa_bape_vbak   TYPE bape_vbak,
        wa_bape_vbakx  TYPE bape_vbakx,
        lv_posnr       TYPE posnr.

* Processing the header extension
  CLEAR wa_bape_vbak.
  wa_bape_vbak-ZZFIELD     = ‘HDRTEST’.
  wa_extensionin-structure = ‘BAPE_VBAK’.
  wa_extensionin+30(960)   = wa_bape_vbak.
  append wa_extensionin to lt_extensionin.
  clear wa_extensionin.

* Processing the line extension
LOOP AT line_items INTO wa_lineitems.

  ADD 10 TO lv_posnr.   
  CLEAR wa_bape_vbap.
  wa_bape_vbap-ZZFIELD     = ‘TEST’.
  wa_extensionin-structure = ‘BAPE_VBAP’.
  wa_bape_vbap-posnr       = lv_posnr.
  wa_extensionin+30(960)   = wa_bape_vbap.
  append wa_extensionin to lt_extensionin.
  clear wa_extensionin.

  CLEAR wa_bape_vbapx.
  wa_bape_vbapx-ZZFIELD    = ‘X’.
  wa_extensionin-structure = ‘BAPE_VBAPX’.
  wa_bape_vbapx-posnr      = lv_posnr.
  wa_extensionin+30(960)   = wa_bape_vbapx.
  append wa_extensionin to lt_extensionin.
  clear wa_extensionin.

ENDLOOP.

* Then the call to the BAPI
      CALL FUNCTION ‘BAPI_SALESORDER_CREATEFROMDAT2’
        EXPORTING
          order_header_in  = ls_order_header_in
          order_header_inx = ls_order_header_inx
        IMPORTING
          salesdocument    = lv_salesdocument
        TABLES
          return           = lt_ret2
          order_items_in   = lt_order_items_in
          order_items_inx  = lt_order_items_inx
          order_partners   = lt_order_partners
          order_keys       = lt_order_keys
          extensionin      = lt_extensionin.

Note: If you have a need to force a different Business Object type or wish to see the extension return fields then use the function SD_SALESDOCUMENT_CREATE instead.

      CALL FUNCTION ‘SD_SALESDOCUMENT_CREATE’
        EXPORTING
          sales_header_in     = ls_order_header_in
          sales_header_inx    = ls_order_header_inx
          business_object     = ‘BUS2032’
        IMPORTING
          salesdocument_ex    = lv_salesdocument
          sales_header_out    = lv_sales_header_out
          sales_header_status = lv_sales_header_status
        TABLES
          return              = lt_ret2
          sales_items_in      = lt_order_items_in
          sales_items_inx     = lt_order_items_inx
          sales_partners      = lt_order_partners
          sales_keys          = lt_order_keys
          extensionin         = lt_extensionin
          incomplete_log      = lt_incomplete_log
          extensionex         = lt_extensionex.


2019年12月5日星期四

SD Transport Route Determination

1. Get Shipping point from TVSTZ table by Shipping Cond. of Customer:Ship-to and Loading Group
of Material:Sales Data.

2.Get the country (ALAND) and Departure zone(AZONE) from TVST table  by Shippping point acquirred from step 1.

3.Get destination country(LLAND) and Transport.zone(LZONE) from  KNA1 by customer:ship-to.

4.Get Actual route(ROUTE) from TROLZ table by
①Country(ALAND) and Departure zone(AZONE) acquired in step 2,
②Shipping Cond (VSBED) of Customer:Ship-to,
③Trans. Group(TRAGR) of Material:Sales Data
destination country(LLAND) and Transport.zone(LZONE) of Ship-to acquired in step 3.

2019年11月15日星期五

Export License

Function:RV_EXPORT_CONTROL
Enhancement

Tr-code VX01n,VX22n

Customize: VE53,VE57,VE58
VE51:Legal control:License Types
VE52:Legal control:Departure country/Legal regulations 
VE53:Legal control:Control situation of Dest.country
VE57:Legal control:Country Classification by Destination Country
VE58:Legal control:Product Classification by Destination Country
VE60:Legal control:Export control classes
VE61:Legal control:Grouping Materials
VE62:Legal control:Export ontrol class / Grouping
   

Log display


https://answers.sap.com/questions/1515224/how-we-can-see-application-log.html

sap sample program:SBAL_DEMO_04


CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
      IMPORTING
        E_S_DISPLAY_PROFILE V_PROFILE
      EXCEPTIONS
        OTHERS              1.

 V_PROFILE-USE_GRID   'X'.     "Use grid control for output
 V_PROFILE-POP_ADJST  'X'.     "Adjust popup height
 V_PROFILE-CWIDTH_OPT 'X'.     "Optimize message list column width
 V_PROFILE-TITLE      TEXT-M01.
 V_PROFILE-END_COL    110. 

 LOOP AT V_PROFILE-MESS_FCAT ASSIGNING <LV_MESS_FCAT>
                                   WHERE REF_FIELD 'MSGTY'
                                      OR REF_FIELD 'MSGID'
                                      OR REF_FIELD 'MSGNO'.

    LV_CNT LV_CNT + 1.
    CLEAR:<LV_MESS_FCAT>-NO_OUT.
    <LV_MESS_FCAT>-COL_POS LV_CNT.

  ENDLOOP.

* Application Log: Log: Create with Header Data
  CALL FUNCTION 'BAL_LOG_CREATE'
    EXPORTING
      I_S_LOG                 V_LOG
    IMPORTING
      E_LOG_HANDLE            V_LOG_HANDLE
    EXCEPTIONS
      LOG_HEADER_INCONSISTENT 1
      OTHERS                  2.
 APPEND V_LOG_HANDLE TO I_LOG_HANDLE.


  LOOP AT I_ERRPARAM INTO WA_ERRPARAM.

    CALL FUNCTION 'BAL_LOG_MSG_ADD'
      EXPORTING
        I_LOG_HANDLE     V_LOG_HANDLE
        I_S_MSG          WA_ERRPARAM
      IMPORTING
        E_S_MSG_HANDLE   V_MSG_HANDLE
      EXCEPTIONS
        LOG_NOT_FOUND    1
        MSG_INCONSISTENT 2
        LOG_IS_FULL      3
        OTHERS           4.

    IF SY-SUBRC <> 0.
*     Create Application Log
      PERFORM SYSTEM_ERROR USING 'BAL_LOG_MSG_ADD'
                                  SY-SUBRC.

    ENDIF.
  ENDLOOP.

 CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
    EXPORTING
      I_T_LOG_HANDLE       I_LOG_HANDLE
      I_S_DISPLAY_PROFILE  V_PROFILE
      I_AMODAL             V_IM_NEW_SESSION
    IMPORTING
      E_S_EXIT_COMMAND     ST_EX_EXIT_COMMAND
    EXCEPTIONS
      PROFILE_INCONSISTENT 1
      INTERNAL_ERROR       2
      NO_DATA_AVAILABLE    3
      NO_AUTHORITY         4.

2019年11月12日星期二

Billing Consolidation (Multi Sales Order one billing)

Tr-code:VTFA

Chose Target and Source, For example: Target G2 and Source is CR

Header: Reference number  (A:Purchase Order number, B:Sales Order number...)

Item: Data VBRK/VBRP (For example 904.)


You can change consolidation conditions in Source below:

Include: RV60AFZC
Exit:   USEREXIT_FILL_VBRK_VBRP
change  the value of VBRK-XBLNR  and VBRK-BSTNK_VF.

   IF *TVCPF-XBLNR_FI 'A'.
       VBRK-XBLNR    VBAK-BSTNK.
       VBRK-BSTNK_VF VBAK-BSTNK.
    ENDIF.


Include: RV60C904
FORM DATEN_KOPIEREN_904.
" change value of vbrk-zukri  
ENDFORM.

           

2019年9月24日星期二

How to identify a country is EU country in sap

refer to T005  table.

F4 help Multi-fields

REPORT ZMULTIHELP.
PARAMETERS:
  P_EBELN TYPE LENGTH 20,
  P_EBELP TYPE LENGTH 10.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_EBELN.

  DATA:
        LT_EKPO TYPE STANDARD TABLE OF EKPO,
        LT_FIELDS TYPE STANDARD TABLE OF DFIES,
        LT_MAPPING TYPE STANDARD TABLE OF DSELC.

  "Fetching only 100 sales documents
  SELECT FROM EKPO
    INTO TABLE LT_EKPO
    UP TO 100 ROWS.

  "Adding the fields we need to be shown in the
  "search help
  PERFORM ADD_FIELD
    TABLES LT_FIELDS
    USING 'EKPO'
          'EBELN'.

  PERFORM ADD_FIELD
    TABLES LT_FIELDS
    USING 'EKPO'
          'EBELP'.



  "Adding fields that has to be mapped to
  "selection screen fields
  PERFORM APPEND_MAPPING
    TABLES LT_MAPPING
    USING 'EBELN' 'P_EBELN'.

    PERFORM APPEND_MAPPING
    TABLES LT_MAPPING
    USING 'EBELP' 'P_EBELP'.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
     RETFIELD               'EBELN'
     DYNPPROG               SY-REPID
     DYNPNR                 SY-DYNNR
     DYNPROFIELD            'P_EBELN'
     VALUE_ORG              'S'
    TABLES
     VALUE_TAB              LT_EKPO
     FIELD_TAB              LT_FIELDS
     DYNPFLD_MAPPING        LT_MAPPING
    EXCEPTIONS
     PARAMETER_ERROR        1
     NO_VALUES_FOUND        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.

*&------------------------------------------------------*
*&      Form  add_field
*&------------------------------------------------------*
*  Add field info to fieldtab given its table name and
*  field name
*-------------------------------------------------------*
*      -->TABNAME    text
*      -->FIELDNAME  text
*-------------------------------------------------------*
FORM ADD_FIELD
  TABLES P_FIELDS
  USING TABNAME TYPE TABNAME
        FIELDNAME TYPE FIELDNAME.


  DATALS_FIELD TYPE DFIES,
       LT_FIELDS TYPE STANDARD TABLE OF DFIES.

  CALL FUNCTION 'DDIF_FIELDINFO_GET'
   EXPORTING
     TABNAME              TABNAME
     FIELDNAME            FIELDNAME
   TABLES
     DFIES_TAB            LT_FIELDS
   EXCEPTIONS
     NOT_FOUND            1
     INTERNAL_ERROR       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.

  APPEND LINES OF LT_FIELDS TO P_FIELDS.

ENDFORM.                    "add_field

*&------------------------------------------------------*
*&      Form  append_mapping
*&------------------------------------------------------*
*  Append field mapping to mapping table
*-------------------------------------------------------*
*      -->P_MAPPING       Mapping table
*      -->P_FIELD         Field in Itab
*      -->P_DYNPRO_FIELD  Field in screen
*-------------------------------------------------------*
FORM APPEND_MAPPING
  TABLES P_MAPPING
  USING P_FIELD
        P_DYNPRO_FIELD.

  DATA:
        LS_MAPPING TYPE DSELC.

  LS_MAPPING-FLDNAME P_FIELD.
  LS_MAPPING-DYFLDNAME P_DYNPRO_FIELD.
  APPEND LS_MAPPING TO P_MAPPING.

ENDFORM.                    "append_mapping

2019年9月4日星期三

BP Create Vendor

REPORT ZBPADD2.
DATA:L_PARTN_CAT       TYPE BAPIBUS1006_HEAD-PARTN_CAT,
     LS_CENTRAL        TYPE BAPIBUS1006_CENTRAL,
     LS_PARTN_GROUP    TYPE BAPIBUS1006_HEAD,
     LS_CENTRAL_PERSON TYPE BAPIBUS1006_CENTRAL_PERSON,
     LS_CENTRAL_ORGAN  TYPE BAPIBUS1006_CENTRAL_ORGAN,
     L_PARTN_GRP       TYPE BAPIBUS1006_HEAD-PARTN_GRP,
     LS_CENTRAL_GROUP  TYPE BAPIBUS1006_CENTRAL_GROUP,
     LS_ADDRESS        TYPE BAPIBUS1006_ADDRESS,
     L_BPARTNER        TYPE BAPIBUS1006_HEAD-BPARTNER,
     LT_BAPIADTEL      LIKE TABLE OF BAPIADTEL WITH HEADER LINE,
     LT_BAPIRET2       LIKE TABLE OF BAPIRET2 WITH HEADER LINE,
     LT_GUID           LIKE TABLE OF BUS000___I WITH HEADER LINE,
     LT_CUSTO          TYPE TABLE OF BUS000_EEW WITH HEADER LINE.

DATA:LS_BUT0BK TYPE BUT0BK,
     LV_BKVID  TYPE BUT0BK-BKVID,
     LV_TYPE   TYPE CHAR1,
     L_STR     TYPE STRING,
     L_ROLE    TYPE BAPIBUS1006_HEAD-PARTNERROLE VALUE 'FLVN00'.

DATA:LS_BANKDETAIL TYPE BAPIBUS1006_BANKDETAIL.
DATA:LS_BANKDETAIL_X TYPE BAPIBUS1006_BANKDETAIL_X.
DATA:LT_RETURN TYPE TABLE OF BAPIRET2.
DATA:LS_RETURN TYPE BAPIRET2.


L_PARTN_CAT                      '2'.
LS_CENTRAL_ORGAN-NAME1           'aaa'.
LS_CENTRAL-SEARCHTERM1           'aaa'.
LS_CENTRAL_ORGAN-FOUNDATIONDATE  '20190220'.
LS_ADDRESS-COUNTRY              'JP'.
LS_ADDRESS-CITY                 'TOKYO'.
LS_ADDRESS-POSTL_COD1           '270-2261'.
LS_ADDRESS-STREET               'aaa'.
L_PARTN_GRP 'Z001'.

CLEAR LT_BAPIADTEL.
LT_BAPIADTEL-COUNTRY 'JP'.
LT_BAPIADTEL-STD_NO 'X'.
"電話
LT_BAPIADTEL-TELEPHONE '010-84522355'.
APPEND LT_BAPIADTEL.
LS_ADDRESS-LANGU '1'.
LS_ADDRESS-STREET 'BACK STRET'.

CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
  EXPORTING
*   USINESSPARTNEREXTERN    =
    BUSINESSPARTNEREXTERN   '0000999962'
    PARTNERCATEGORY         L_PARTN_CAT
    PARTNERGROUP            L_PARTN_GRP
    CENTRALDATA             LS_CENTRAL
    CENTRALDATAPERSON       LS_CENTRAL_PERSON
    CENTRALDATAORGANIZATION LS_CENTRAL_ORGAN
    CENTRALDATAGROUP        LS_CENTRAL_GROUP
    ADDRESSDATA             LS_ADDRESS
*   UPLICATE_MESSAGE_TYPE   =
*   CCEPT_ERROR             = ' '
  IMPORTING
    BUSINESSPARTNER         L_BPARTNER
  TABLES
    TELEFONDATA             LT_BAPIADTEL
*   AXDATA                  =
*   ELETEXDATA              =
*   ELEXDATA                =
*   _MAILDATA               =
*   MLADDRESSDATA           =
*   400ADDRESSDATA          =
*   FCADDRESSDATA           =
*   RTADDRESSDATA           =
*   SFADDRESSDATA           =
*   RIADDRESSDATA           =
*   AGADDRESSDATA           =
*   DDRESSNOTES             =
*   OMMUNICATIONNOTES       =
*   OMMUNICATIONUSAGE       =
*   ELEFONDATANONADDRESS    =
*   AXDATANONADDRESS        =
*   ELETEXDATANONADDRESS    =
*   ELEXDATANONADDRESS      =
*   _MAILDATANONADDRESS     =
*   MLADDRESSDATANONADDRESS =
*   400ADDRESSDATANONADDRESS          =
*   FCADDRESSDATANONADDRESS =
*   RTADDRESSDATANONADDRESS =
*   SFADDRESSDATANONADDRESS =
*   RIADDRESSDATANONADDRESS =
*   AGADDRESSDATANONADDRESS =
*   OMMUNICATIONNOTESNONADDRESS       =
*   OMMUNICATIONUSAGENONADDRESS       =
    RETURN                  LT_BAPIRET2.
*   DDRESSDUPLICATES        =


IF LT_BAPIRET2[] IS INITIAL.
  CALL FUNCTION 'BUP_MEMORY_BUT000_GET'
    EXPORTING
      IV_PARTNER       L_BPARTNER
    IMPORTING
      ES_BUT000        LT_GUID
    EXCEPTIONS
      NOT_FOUND        1
      PARAMETER_ERROR  2
      BPEXT_NOT_UNIQUE 3
      OTHERS           4.
  READ TABLE LT_GUID INDEX 1.
  LT_CUSTO-PARTNR_GUID LT_GUID-PARTNER_GUID.
  APPEND LT_CUSTO.

  CALL FUNCTION 'BUPA_CENTRAL_CI_CHANGE'
    EXPORTING
      IS_BUS000_EEW LT_CUSTO.

  IF SY-SUBRC EQ 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT 'X'.
  ENDIF.

ELSE.
  CLEAR L_STR.
  LOOP AT LT_BAPIRET2 WHERE TYPE 'E'.
    IF L_STR IS INITIAL.
      L_STR LT_BAPIRET2-MESSAGE.
    ELSE.
      CONCATENATE L_STR LT_BAPIRET2-MESSAGE INTO L_STR.
    ENDIF.
  ENDLOOP.
ENDIF.

*->添加银行数据
IF L_BPARTNER IS NOT INITIAL.
*->添加业务角色
  CALL FUNCTION 'BAPI_BUPA_ROLE_ADD'
    EXPORTING
      BUSINESSPARTNER     L_BPARTNER
      BUSINESSPARTNERROLE L_ROLE
    TABLES
      RETURN              LT_RETURN.
  CALL FUNCTION 'BAPI_BUPA_ROLE_ADD'
    EXPORTING
      BUSINESSPARTNER     L_BPARTNER
      BUSINESSPARTNERROLE 'FLVN01'
    TABLES
      RETURN              LT_RETURN.

  LS_BANKDETAIL-BANK_CTRY       'JP'.
  LS_BANKDETAIL-BANK_KEY        '0001027'.
  LS_BANKDETAIL-BANK_ACCT       '100122'.
  LS_BANKDETAIL-BANKACCOUNTNAME 'aaaa'.
  LS_BANKDETAIL-CTRL_KEY        '01'.
  LS_BANKDETAIL-ACCOUNTHOLDER   'aa'.

  CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD'
    EXPORTING
      BUSINESSPARTNER L_BPARTNER
      BANKDETAILDATA  LS_BANKDETAIL
    TABLES
      RETURN          LT_RETURN.

  READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE 'E'.

  IF SY-SUBRC NE 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT 'X'.
  ENDIF.
ENDIF.

CLEAR LT_RETURN[].
DATALS_MASTER_DATA           TYPE VMDS_EI_MAIN,
      LS_MASTER_DATA_CORRECT   TYPE VMDS_EI_MAIN,
      LS_MESSAGE_CORRECT       TYPE CVIS_MESSAGE,
      LS_MASTER_DATA_DEFECTIVE TYPE VMDS_EI_MAIN,
      LS_MESSAGE_DEFECTIVE     TYPE CVIS_MESSAGE.

DATALT_VENDOR        TYPE VMDS_EI_EXTERN_T,
      LS_VENDOR        TYPE VMDS_EI_EXTERN,
      LS_PURCHASE_DATA TYPE VMDS_EI_VMD_PURCHASING,
      LT_PURCHASE      TYPE VMDS_EI_PURCHASING_T,
      LS_PURCHASE      TYPE VMDS_EI_PURCHASING,
      LS_COMPANY       TYPE VMDS_EI_COMPANY,
      LT_FUNCTIONS     TYPE STANDARD TABLE OF VMDS_EI_FUNCTIONS,
      LS_FUNCTION      TYPE VMDS_EI_FUNCTIONS.

REFRESH LT_FUNCTIONSLT_VENDOR.
CLEARLS_VENDORLS_PURCHASE_DATA.
LS_VENDOR-HEADER-OBJECT_INSTANCE-LIFNR L_BPARTNER.
LS_VENDOR-HEADER-OBJECT_TASK  'U'" I/U/D
LS_PURCHASE_DATA-CURRENT_STATE SPACE.
LS_VENDOR-CENTRAL_DATA-CENTRAL-DATA-KTOKK 'SUPL'.
LS_VENDOR-CENTRAL_DATA-CENTRAL-DATAX-KTOKK 'X'.

LS_COMPANY-TASK                                'I'.
LS_COMPANY-DATA_KEY-BUKRS                      '1000'.
LS_COMPANY-DATA-AKONT                          =  '0004142000'.
LS_COMPANY-DATAX-AKONT                         =  'X'.
APPEND LS_COMPANY TO LS_VENDOR-COMPANY_DATA-COMPANY.
LS_PURCHASE-TASK 'I' .
LS_PURCHASE-DATA_KEY-EKORG '1000'.
LS_PURCHASE-FUNCTIONS-CURRENT_STATE SPACE.
LS_PURCHASE-DATA-WAERS 'JPY'.
LS_PURCHASE-DATAX-WAERS 'X'.
CLEAR LS_FUNCTION.
LS_FUNCTION-TASK  'I'.
LS_FUNCTION-DATA_KEY-PARVW 'LF'.
LS_FUNCTION-DATA-PARTNER   L_BPARTNER.
*ls_function-datax-partner  = 'X'.
APPEND LS_FUNCTION TO LT_FUNCTIONS.
LS_FUNCTION-TASK  'I'.
LS_FUNCTION-DATA_KEY-PARVW 'RS'.
LS_FUNCTION-DATA-PARTNER   L_BPARTNER.
*ls_function-datax-partner  = 'X'.
APPEND LS_FUNCTION TO LT_FUNCTIONS.
LS_PURCHASE-FUNCTIONS-FUNCTIONS LT_FUNCTIONS[].
APPEND LS_PURCHASE TO LT_PURCHASE.

LS_PURCHASE_DATA-PURCHASING[]  LT_PURCHASE[].
LS_VENDOR-PURCHASING_DATA LS_PURCHASE_DATA.
APPEND LS_VENDOR TO LT_VENDOR.
LS_MASTER_DATA-VENDORS LT_VENDOR[].

VMD_EI_API=>INITIALIZE).
VMD_EI_API=>LOCKIV_LIFNR LS_VENDOR-HEADER-OBJECT_INSTANCE-LIFNR ).

CALL METHOD VMD_EI_API=>MAINTAIN_BAPI
  EXPORTING
    IV_TEST_RUN              SPACE
*   IV_COLLECT_MESSAGES      = SPACE
    IS_MASTER_DATA           LS_MASTER_DATA
  IMPORTING
    ES_MASTER_DATA_CORRECT   LS_MASTER_DATA_CORRECT
    ES_MESSAGE_CORRECT       LS_MESSAGE_CORRECT
    ES_MASTER_DATA_DEFECTIVE LS_MASTER_DATA_DEFECTIVE
    ES_MESSAGE_DEFECTIVE     LS_MESSAGE_DEFECTIVE.



IF LS_MESSAGE_DEFECTIVE IS INITIAL.
  BREAK-POINT.
  COMMIT WORK.
ELSE.
  BREAK-POINT.
ENDIF.

VMD_EI_API=>UNLOCKIV_LIFNR LS_VENDOR-HEADER-OBJECT_INSTANCE-LIFNR ).

Customer Characteristic

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