2013年4月30日 星期二

ALV GRID report 儲存為檔案後部份欄位錯誤

例如物料號碼有前導0
儲存為檔案後,會少最後一碼
解決方法一:
增加參考欄位
gt_fieldcat-ref_tabname = 'MARA'.
gt_fieldcat-ref_fieldname = 'MATNR'.

解決方法二:
數量單位錯誤時(變成***):
gt_fieldcat-qtabname = 'MSEG'.
gt_fieldcat-qfieldname = 'MEINS'.
沒有作用的時候,請用方法一

2013年4月24日 星期三

排除不合的"狀態選擇設定檔"

  IF NOT selid IS INITIAL.
    LOOP AT objnr_tab.
      DATA flg_status_ok TYPE c.       "Statusprüfung OK
      CALL FUNCTION 'STATUS_CHECK_BY_SELSCHEM'
        EXPORTING
          objnr          = objnr_tab-objnr
          selid          = selid
        IMPORTING
          fullfill       = flg_status_ok
        EXCEPTIONS
          no_stat_scheme = 01
          no_stat_tab    = 02.
      IF  sy-subrc      IS INITIAL
      AND flg_status_ok IS INITIAL.
        DELETE objnr_tab.
      ENDIF.
    ENDLOOP.
  ENDIF.

2013年4月17日 星期三

SAP 確認小視窗

answer = 1確定,2否決,A取消

      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
*         TITLEBAR                    = ' '
*         DIAGNOSE_OBJECT             = ' '
          text_question               text-001
*         TEXT_BUTTON_1               = 'Ja'(001)
*         ICON_BUTTON_1               = ' '
*         TEXT_BUTTON_2               = 'Nein'(002)
*         ICON_BUTTON_2               = ' '
*         DEFAULT_BUTTON              = '1'
*         DISPLAY_CANCEL_BUTTON       = 'X'
*         USERDEFINED_F1_HELP         = ' '
*         START_COLUMN                = 25
*         START_ROW                   = 6
*         POPUP_TYPE                  =
*         IV_QUICKINFO_BUTTON_1       = ' '
*         IV_QUICKINFO_BUTTON_2       = ' '
       IMPORTING
         answer                      lv_ans
*       TABLES
*         PARAMETER                   =
*       EXCEPTIONS
*         TEXT_NOT_FOUND              = 1
*         OTHERS                      = 2
                .

2013年4月5日 星期五

BAPI commit and rollback

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
          .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
*   RETURN        =
          .

物料單位轉換

包含數量轉換
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
  EXPORTING
    i_matnr                    =
    i_in_me                    =
    i_out_me                   =
    i_menge                    =
* IMPORTING
*   E_MENGE                    =
* EXCEPTIONS
*   ERROR_IN_APPLICATION       = 1
*   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.


一般基礎單位轉換
  CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
  EXPORTING
*   INPUT                        = 0
*   KZMEINH                      = ' '
    matnr                        =
    meinh                        =
*   MEINS                        = ' '
*   EXTENDED_CONV                = ' '
*   TYPE_UMR                     = ' '
*   NO_OUTPUT                    = ' '
*   CHARGE                       =
*   CHARG_CUOBJ                  =
*   WERKS                        =
* IMPORTING
*   ADDKO                        =
*   MEINS                        =
*   OUTPUT                       =
*   UMREN                        =
*   UMREZ                        =
*   BATCH_CONVERSION_ERROR       =
*   KZWSO                        =
* EXCEPTIONS
*   CONVERSION_NOT_FOUND         = 1
*   INPUT_INVALID                = 2
*   MATERIAL_NOT_FOUND           = 3
*   MEINH_NOT_FOUND              = 4
*   MEINS_MISSING                = 5
*   NO_MEINH                     = 6
*   OUTPUT_INVALID               = 7
*   OVERFLOW                     = 8
*   OTHERS                       = 9
          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ALV列、行、單元格顏色設置

http://blog.csdn.net/zhongguomao/article/details/6719956

2013年4月1日 星期一

SAP指標與參考物件應用

1. 宣告參考物件:DATA dref TYPE REF TO DATA.(任意類型)
                        STANDARD TABLE.(Table類型的宣告)       
2. 建立參考物件的記憶體位址以及其資料結構:CREATE DATA dref {TYPE type}|{LIKE dobj}
3. dref->* :取得記體位址的資料結構
4. ASSIGN dref->* TO :將記憶體位址的資料結構指派給指標變數
5. Select ... INTO
   Loop at xxx INTO
   ASSIGN COMPONENT sy-index
         OF STRUCTURE TO .
   指派值到指標變數所指的位址
6. 參考物件無法直接使用,所以必須透過指標存取

REPORT z_barry_test                            .

TYPE-POOLS : abap.
FIELD-SYMBOLS: TYPE STANDARD TABLE,  "宣告指標變數
               ,
               .
DATA: dy_table TYPE REF TO data,  "宣告參考物件
      dy_line TYPE REF TO data,
      xfc TYPE lvc_s_fcat,
      ifc TYPE lvc_t_fcat.
DATA: itab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.

PARAMETERS p_file TYPE localfile.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM get_file_name USING p_file.


START-OF-SELECTION.
  PERFORM get_file_data.
  PERFORM get_structure.
  PERFORM create_dynamic_itab.
  PERFORM get_data.
  PERFORM write_out.
*---------------------------------------------------------------------*
*       FORM get_structure                                            *
*---------------------------------------------------------------------*
FORM get_structure.
  LOOP AT itab.
    CLEAR xfc.
    xfc-fieldname = itab-value .
    xfc-inttype = 'C'.
    xfc-intlen = 18.
*    xfc-decimals = 4.
    APPEND xfc TO ifc.
  ENDLOOP.
ENDFORM.                    "get_structure
*---------------------------------------------------------------------*
*       FORM create_dynamic_itab                                      *
*---------------------------------------------------------------------*
FORM create_dynamic_itab.

  CALL METHOD cl_alv_table_create=>create_dynamic_table "建立參考物件
    EXPORTING
      it_fieldcatalog = ifc
    IMPORTING
      ep_table        = dy_table.
  ASSIGN dy_table->* TO .   "指派參考物件記憶體位址連結到指標變數

  CREATE DATA dy_line LIKE LINE OF . "建立與指標變數所指的記憶體空間結構相同的參考物件
  ASSIGN dy_line->* TO .
ENDFORM.                    "create_dynamic_itab

*---------------------------------------------------------------------*
*       FORM get_data                                                 *
*---------------------------------------------------------------------*
FORM get_data.
  DATA: BEGIN OF itab OCCURS 0 .
          INCLUDE STRUCTURE eord.
  DATA: END OF itab.

  SELECT matnr  werks vdatu bdatu lifnr reswk ekorg flifn
      UP TO 10 ROWS
      INTO CORRESPONDING FIELDS OF TABLE
               FROM eord.
ENDFORM.                    "get_data
*---------------------------------------------------------------------*
*       FORM write_out                                                *
*---------------------------------------------------------------------*
FORM write_out.
  LOOP AT INTO .
    DO.
      ASSIGN COMPONENT sy-index
         OF STRUCTURE TO .
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      IF sy-index = 1.
        WRITE:/ .
      ELSE.
        WRITE: .
      ENDIF.
    ENDDO.
  ENDLOOP.
ENDFORM.                    "write_out
*&---------------------------------------------------------------------*
*&      Form  GET_FILE_NAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FILE  text
*----------------------------------------------------------------------*
FORM get_file_name  USING     p_file.
  CALL FUNCTION 'F4_FILENAME'
*   EXPORTING
*     PROGRAM_NAME        = SYST-CPROG
*     DYNPRO_NUMBER       = SYST-DYNNR
*     FIELD_NAME          = ' '
   IMPORTING
     file_name           = p_file
            .
ENDFORM.                    " GET_FILE_NAME
*&---------------------------------------------------------------------*
*&      Form  GET_FILE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <-- br="" nbsp="" p2="" text="">*----------------------------------------------------------------------*
FORM get_file_data .
  TYPE-POOLS : truxs.
  DATA: file_str TYPE rlgrap-filename.
  DATA: lv_werks1 TYPE string.
  DATA: lv_werks2 TYPE string.
  DATA: lv_lifnr LIKE eina-lifnr,
        lv_matnr LIKE eina-matnr.

  file_str = p_file.

  CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                      = file_str
      i_begin_col                   = '1'
      i_begin_row                   = '1'
      i_end_col                     = '255'
      i_end_row                     = '9999'
*   SHEET_NAME                    =
    TABLES
      intern                        = itab
* EXCEPTIONS
*   INCONSISTENT_PARAMETERS       = 1
*   UPLOAD_OLE                    = 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.


ENDFORM.                    " GET_FILE_DATA

SAP data Archiving

http://blog.csdn.net/jesson0083/article/details/5457234

SAP brtools

資料庫的備份與恢復可以用brtools設定
也可以用來設定自動擴展table space和增加data files
如果有安裝此工具的話必須登入OS進行操作
以下這兩篇可供參考
http://xjsunjie.blog.51cto.com/999372/849567
http://blog.csdn.net/bayaci/article/details/5212295