메뉴 건너뛰기

SAP 한국 커뮤니티



FUNCTION 모음

명신용 2007.04.03 19:56 조회 수 : 6209 추천:23

* E-OFFICE등에 넘기기 위해 수량을 기본단위로 변환시켜주는 함수.


 


* 청구예정량, 구매예정량 = pr 수량
* pr의 단위와 기본단위가 틀리면 기본단위로 conversion 한다


 



    IF ( MARA-MEINS NE P_EBAN-MEINS ) AND
       NOT MARA-MEINS IS INITIAL.


CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
        EXPORTING
          I_MATNR              = P_EBAN-MATNR
          I_IN_ME              = P_EBAN-MEINS
          I_OUT_ME             = MARA-MEINS
          I_MENGE              = P_EBAN-MENGE
        IMPORTING
          E_MENGE              = P_EBAN-MENGE
        EXCEPTIONS
          ERROR_IN_APPLICATION = 1
          ERROR                = 2
          OTHERS               = 3.


 



---------------------------------------------------------


 


* T-CODE /NMMBE에 대해서..


 



    CALL FUNCTION 'MB_ADD_RESERVATION_QUANTITIES'
      EXPORTING
        X_KZEAR       = SPACE
        X_MATNR       = P_EBAN-MATNR
        X_XLOEK       = SPACE
*   X_KZWSO       = ' '
      TABLES
        XBDART        = GR_XBDART
        XTAB1         = IT_XTAB1 "수량 들어옴.
        XWERKS        = GR_XWERKS.


    DELETE IT_XTAB1 WHERE WERKS NE P_EBAN-WERKS.
"해당 플랜트에 대해서만 SUM.
    LOOP AT IT_XTAB1.
      AT FIRST.
        SUM.
        GV_MENGE = IT_XTAB1-BDMNG.
      ENDAT.
    ENDLOOP.


    WRITE GV_MENGE TO IT_ITEM-BDMNG UNIT MARA-MEINS.


 


-------------------------------------------------------------


 


*롱텍스트 가져오는 함수.


 


FORM READ_LONG_TEXT USING P1 P2 P3.


  CLEAR : THEAD, IT_LINE, IT_LINE[].


  THEAD-TDID = P1.
  THEAD-TDSPRAS = SY-LANGU.
  THEAD-TDNAME = P2.
  THEAD-TDOBJECT = P3.


  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      CLIENT                        = SY-MANDT
      ID                            = THEAD-TDID
      LANGUAGE                      = THEAD-TDSPRAS
      NAME                          = THEAD-TDNAME
      OBJECT                        = THEAD-TDOBJECT
*   ARCHIVE_HANDLE                = 0
*   LOCAL_CAT                     = ' '
* IMPORTING
*   HEADER                        =
    TABLES
      LINES                         = IT_LINE
   EXCEPTIONS
     ID                            = 1
     LANGUAGE                      = 2
     NAME                          = 3
     NOT_FOUND                     = 4
     OBJECT                        = 5
     REFERENCE_CHECK               = 6
     WRONG_ACCESS_TO_ARCHIVE       = 7
     OTHERS                        = 8  .


  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


 


 



---------------------------------------------------------------------


 


*알파 컨버젼.... 0000001234 에서 0000빼는 함수.


 


FORM ALPHA_CONVERSION  USING  P_KIND  P_FIELD.


  IF P_KIND = '1'.                                          "0붙임
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  = P_FIELD
      IMPORTING
        OUTPUT = P_FIELD.


  ELSEIF P_KIND = '2'.                                      "0제거
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
      EXPORTING
        INPUT  = P_FIELD
      IMPORTING
        OUTPUT = P_FIELD.
  ENDIF.


 


------------------------------------------------------------------------


 


*BAPI 전송에 관련된 함수..


 



*&---------------------------------------------------------------------*
*&      Form  CHANGE_EKGRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CHANGE_EKGRP USING P_BANFN P_EKGRP P_TYPE P_MESSAGE.


  DATA : LT_BAPIEBAN LIKE BAPIEBAN  OCCURS 0 WITH HEADER LINE,
         LT_BAPIRETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE,
         LT_BAPI_OLD LIKE BAPIEBANV OCCURS 0 WITH HEADER LINE,
         LT_BAPI_NEW  LIKE BAPIEBANV OCCURS 0 WITH HEADER LINE.



* PR 값 읽어오기
  CLEAR : LT_BAPIEBAN, LT_BAPIEBAN[], LT_BAPIRETURN, LT_BAPIRETURN[],
          LT_BAPI_OLD, LT_BAPI_OLD[], LT_BAPI_NEW, LT_BAPI_NEW[].


  CALL FUNCTION 'BAPI_REQUISITION_GETDETAIL'
    EXPORTING
      NUMBER            = P_BANFN
    TABLES
      REQUISITION_ITEMS = LT_BAPIEBAN
      RETURN            = LT_BAPIRETURN
    EXCEPTIONS
      OTHERS            = 1.


 


* 구매그룹변경
  LOOP AT LT_BAPIEBAN .
    CLEAR : LT_BAPI_OLD, LT_BAPI_NEW.


    MOVE-CORRESPONDING LT_BAPIEBAN TO LT_BAPI_OLD.
    MOVE-CORRESPONDING LT_BAPIEBAN TO LT_BAPI_NEW.


    LT_BAPI_NEW-PUR_GROUP = P_EKGRP.


    APPEND LT_BAPI_OLD.
    APPEND LT_BAPI_NEW.
  ENDLOOP.



* PR 변경 BAPI 실행
  CALL FUNCTION 'BAPI_REQUISITION_CHANGE'
    EXPORTING
      NUMBER                = P_BANFN
    TABLES
      REQUISITION_ITEMS_OLD = LT_BAPI_OLD
      REQUISITION_ITEMS_NEW = LT_BAPI_NEW
      RETURN                = LT_BAPIRETURN
    EXCEPTIONS
      OTHERS                = 1.


  IF SY-SUBRC NE 0 OR SY-MSGNO NE '041'.
    P_TYPE = 'F'. "실패면 F


    CLEAR P_MESSAGE.
    CALL FUNCTION 'MESSAGE_TEXT_BUILD'
      EXPORTING
        MSGID               = SY-MSGID
        MSGNR               = SY-MSGNO
        MSGV1               = SY-MSGV1
        MSGV2               = SY-MSGV2
        MSGV3               = SY-MSGV3
        MSGV4               = SY-MSGV4
      IMPORTING
        MESSAGE_TEXT_OUTPUT = P_MESSAGE.


    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.



  ELSE.
    P_TYPE = 'S'. "성공이면 S


* BAPI 실행후에는 항상 COMMIT해줄것.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT = 'Y'.
  ENDIF.


ENDFORM.                    " CHANGE_EKGRP


* e-abap님에 의해서 게시물 이동되었습니다 (2007-11-05 12:45)