메뉴 건너뛰기

SAP 한국 커뮤니티



[PS-CJR2] BAPI_COSTACTPLN_POSTPRIMCOST

poce 2007.12.26 17:34 조회 수 : 6670

<P>* transaction code - cjr2에 대한 데이터 입력</P>
<P> </P>
<P>HTML로 보이시면 첨부파일을...</P>
<P>사용예를 두 가지 올림 비교하여 사용하시길...</P>
<P> </P>
<P>두번째 소스는 다른분의 소스라 그분께는 죄송하지만....도용했습니다. 넓은 아량을...</P>
<P> </P>
<P>ps모듈 플젝에서 사용했는 데 다른쪽에서 사용을 하는 지는 의문...</P>
<P> </P>
<P>1.-----------------------------------------------------------------------------</P>
<P>    CALL FUNCTION 'BAPI_COSTACTPLN_POSTPRIMCOST'<BR>    EXPORTING<BR>      HEADERINFO     = GS_HEADERINFO<BR>      DELTA          = ''  "C_X "Add Value<BR>    TABLES<BR>      INDEXSTRUCTURE = GT_INDEXSTRUCTURE<BR>      COOBJECT       = GT_COOBJECT<BR>      PERVALUE       = GT_PERVALUE<BR>      RETURN         = GT_RETURN. </P>
<P> </P>
<P>* start...................................................................................................</P>
<P><BR>  DATA: L_AMOUNT(18),<BR>        L_DIFF TYPE I,<BR>        L_CNT  TYPE I.</P>
<P>  DATA: LV_OBJ_INX        LIKE BAPIACISTRU-OBJECT_INDEX,<BR>        LV_VAL_INX        LIKE BAPIACISTRU-VALUE_INDEX.</P>
<P><BR>  DATA: LT_AMOUNT TYPE TABLE OF STRING,<BR>        LW_AMOUNT TYPE STRING.</P>
<P>*-----------------------------------------------------<BR>* Cost는 BAPI 수행<BR>*-----------------------------------------------------<BR>  GT_INDEXSTRUCTURE-OBJECT_INDEX = '1'.<BR>  GT_INDEXSTRUCTURE-VALUE_INDEX  = '1'.<BR>  APPEND GT_INDEXSTRUCTURE.</P>
<P>    LOOP AT GT_ITAB.<BR>      INIT: GT_COOBJECT, GT_PERVALUE,<BR>            GT_TOTVALUE, GT_RETURN.</P>
<P>*   Header<BR>      GS_HEADERINFO-CO_AREA     = GT_ITAB-KOKRS.     " Controlling area.<BR>      GS_HEADERINFO-VERSION     = GT_ITAB-VERSN.     " Version.<BR>      GS_HEADERINFO-FISC_YEAR   = GT_ITAB-MONTH(4).  " YYYY<BR>      GS_HEADERINFO-PERIOD_FROM = GT_ITAB-MONTH+4(2)." MM - START MONTH<BR>      GS_HEADERINFO-PERIOD_TO   = GT_ITAB-MONTH+4(2)." MM - END MONTH<BR>      GS_HEADERINFO-PLAN_CURRTYPE = 'T'. " or 'C'     플랜에 대한 CURRENCY(?)<BR>                                                     <BR>*   Item<BR>      GT_COOBJECT-OBJECT_INDEX = '1'.                 " INDEXSTRUCTURE의   </P>
<P>                                                        object index와 Match<BR>      GT_COOBJECT-WBS_ELEMENT  = GT_ITAB-POSID.       " WBS<BR>      APPEND GT_COOBJECT.</P>
<P>      GT_PERVALUE-VALUE_INDEX = '1'.                  " INDEXSTRUCTURE의 </P>
<P>                                                        value index와 Match   <BR>      GT_PERVALUE-COST_ELEM   = GT_ITAB-KSTAR.        " Cost element<BR>      GT_PERVALUE-TRANS_CURR  = GT_ITAB-WAERS.        " currency</P>
<P>*   금액에 Currency를 적용한 후 콤마 분리<BR>      WRITE GT_ITAB-AMOUNT TO L_AMOUNT LEFT-JUSTIFIED CURRENCY GT_ITAB-WAERS.</P>
<P>      " 금액을 char type으로 변환<BR>      SPLIT L_AMOUNT AT GC_COMMA INTO TABLE LT_AMOUNT.<BR>      CLEAR L_AMOUNT.<BR>      LOOP AT LT_AMOUNT INTO LW_AMOUNT.<BR>        CONCATENATE L_AMOUNT LW_AMOUNT INTO L_AMOUNT.<BR>      ENDLOOP.<BR>* 월별로 값을 저장<BR>      CASE GT_ITAB-MONTH+4(2).<BR>        WHEN '01'.  GT_PERVALUE-FIX_VAL_PER01 = L_AMOUNT.<BR>        WHEN '02'.  GT_PERVALUE-FIX_VAL_PER02 = L_AMOUNT.<BR>        WHEN '03'.  GT_PERVALUE-FIX_VAL_PER03 = L_AMOUNT.<BR>        WHEN '04'.  GT_PERVALUE-FIX_VAL_PER04 = L_AMOUNT.<BR>        WHEN '05'.  GT_PERVALUE-FIX_VAL_PER05 = L_AMOUNT.<BR>        WHEN '06'.  GT_PERVALUE-FIX_VAL_PER06 = L_AMOUNT.<BR>        WHEN '07'.  GT_PERVALUE-FIX_VAL_PER07 = L_AMOUNT.<BR>        WHEN '08'.  GT_PERVALUE-FIX_VAL_PER08 = L_AMOUNT.<BR>        WHEN '09'.  GT_PERVALUE-FIX_VAL_PER09 = L_AMOUNT.<BR>        WHEN '10'.  GT_PERVALUE-FIX_VAL_PER10 = L_AMOUNT.<BR>        WHEN '11'.  GT_PERVALUE-FIX_VAL_PER11 = L_AMOUNT.<BR>        WHEN '12'.  GT_PERVALUE-FIX_VAL_PER12 = L_AMOUNT.<BR>      ENDCASE.<BR>      APPEND GT_PERVALUE.</P>
<P>    CALL FUNCTION 'BAPI_COSTACTPLN_POSTPRIMCOST'<BR>    EXPORTING<BR>      HEADERINFO     = GS_HEADERINFO<BR>      DELTA          = ''  "C_X "Add Value<BR>    TABLES<BR>      INDEXSTRUCTURE = GT_INDEXSTRUCTURE<BR>      COOBJECT       = GT_COOBJECT<BR>      PERVALUE       = GT_PERVALUE<BR>      RETURN         = GT_RETURN.</P>
<P><BR> </P>
<P>* 수행후 아무런 메시지가 없으면 ok!<BR>  READ TABLE GT_RETURN INDEX 1.<BR>  IF SY-SUBRC NE 0.<BR>    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. </P>
<P>  ENDIF.</P>
<P> </P>
<P>2.-----------------------------------------------------------------------------</P>
<P>    DATA: LV_OBJ_INX        LIKE BAPIACISTRU-OBJECT_INDEX,<BR>        LV_VAL_INX        LIKE BAPIACISTRU-VALUE_INDEX,<BR>        LV_ERR_FLAG.</P>
<P>  REFRESH GT_1. CLEAR GT_1.<BR>  LOOP AT ITAB.<BR>    MOVE-CORRESPONDING ITAB TO GT_1.<BR>    APPEND GT_1. CLEAR GT_1.<BR>  ENDLOOP.</P>
<P>  SORT GT_1 BY YYYY MM KOSTL SAKNR.</P>
<P>  CLEAR LV_ERR_FLAG.<BR>  LOOP AT GT_1.<BR>    AT NEW MM.<BR>      REFRESH: GT_INDEXSTRUCTURE,GT_COOBJECT,GT_PERVALUE,<BR>               GT_TOTVALUE,GT_RETURN.<BR>      CLEAR  : GT_INDEXSTRUCTURE,GT_COOBJECT,GT_PERVALUE,<BR>               GT_TOTVALUE,GT_RETURN,GS_HEADERINFO,<BR>               LV_OBJ_INX ,LV_VAL_INX.</P>
<P>      PERFORM PUT_HEADERINFO.<BR>    ENDAT.</P>
<P>    AT NEW KOSTL.<BR>      LV_OBJ_INX = LV_OBJ_INX + 1.<BR>      PERFORM PUT_COOBJECT USING LV_OBJ_INX GT_1-KOSTL.<BR>    ENDAT.</P>
<P>    AT NEW SAKNR.<BR>      LV_VAL_INX = LV_VAL_INX + 1.<BR>      PERFORM PUT_INDEXSTRUCTURE USING LV_OBJ_INX LV_VAL_INX.<BR>      CLEAR GT_PERVALUE.<BR>    ENDAT.</P>
<P>    PERFORM PUT_PERVALUE USING<BR>            LV_VAL_INX GT_1-MM GT_1-SAKNR GT_1-AM_AMT.</P>
<P>    AT END OF SAKNR.<BR>      APPEND GT_PERVALUE.<BR>    ENDAT.</P>
<P>    AT END OF MM.<BR>      CALL FUNCTION 'BAPI_COSTACTPLN_POSTPRIMCOST'<BR>        EXPORTING<BR>          HEADERINFO     = GS_HEADERINFO<BR>        TABLES<BR>          INDEXSTRUCTURE = GT_INDEXSTRUCTURE<BR>          COOBJECT       = GT_COOBJECT<BR>          PERVALUE       = GT_PERVALUE<BR>          TOTVALUE       = GT_TOTVALUE<BR>          RETURN         = GT_RETURN.</P>
<P>      READ TABLE GT_RETURN INDEX 1.</P>
<P> </P>
<P>      IF SY-SUBRC EQ 0.<BR>        SET PF-STATUS '100' EXCLUDING 'EXECUTE'.</P>
<P>        LOOP AT GT_RETURN.<BR>          WRITE: / GT_RETURN-MESSAGE.<BR>        ENDLOOP.</P>
<P>        LV_ERR_FLAG  = 'X'.<BR>        EXIT.<BR>      ENDIF.<BR>    ENDAT.<BR>  ENDLOOP.</P>
<P>  CHECK LV_ERR_FLAG IS INITIAL.<BR>  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.<BR>  MESSAGE S355(00). </P>
<P> </P>
<P>*&---------------------------------------------------------------------*<BR>*&      Form  PUT_HEADERINFO<BR>*&---------------------------------------------------------------------*<BR>*       text<BR>*----------------------------------------------------------------------*<BR>FORM PUT_HEADERINFO.</P>
<P>  GS_HEADERINFO-CO_AREA       = P_KOKRS.<BR>  GS_HEADERINFO-VERSION       = P_VERSN.<BR>  GS_HEADERINFO-FISC_YEAR     = GT_1-YYYY.<BR>  GS_HEADERINFO-PERIOD_FROM   = GT_1-MM.<BR>  GS_HEADERINFO-PERIOD_TO     = GT_1-MM.<BR>  GS_HEADERINFO-PLAN_CURRTYPE = 'C'.</P>
<P>ENDFORM.                    " PUT_HEADERINFO </P>
<P>*&---------------------------------------------------------------------*<BR>*&      Form  PUT_COOBJECT<BR>*&---------------------------------------------------------------------*<BR>*       text<BR>*----------------------------------------------------------------------*<BR>FORM PUT_COOBJECT USING P_OBJ_INX P_KOSTL.</P>
<P>  GT_COOBJECT-OBJECT_INDEX = P_OBJ_INX.<BR>  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'<BR>    EXPORTING<BR>      INPUT  = P_KOSTL<BR>    IMPORTING<BR>      OUTPUT = GT_COOBJECT-COSTCENTER.</P>
<P>  APPEND GT_COOBJECT.</P>
<P>ENDFORM.                    " PUT_COOBJECT </P>
<P> </P>
<P>*&---------------------------------------------------------------------*<BR>*&      Form  PUT_INDEXSTRUCTURE<BR>*&---------------------------------------------------------------------*<BR>*       text<BR>*----------------------------------------------------------------------*<BR>FORM PUT_INDEXSTRUCTURE USING P_OBJ_INX P_VAL_INX.</P>
<P>  GT_INDEXSTRUCTURE-OBJECT_INDEX = P_OBJ_INX.<BR>  GT_INDEXSTRUCTURE-VALUE_INDEX  = P_VAL_INX.<BR>  APPEND GT_INDEXSTRUCTURE.</P>
<P>ENDFORM.                    " PUT_INDEXSTRUCTURE </P>
<P> </P>
<P>  *&---------------------------------------------------------------------*<BR>*&      Form  PUT_PERVALUE<BR>*&---------------------------------------------------------------------*<BR>*       text<BR>*----------------------------------------------------------------------*<BR>FORM PUT_PERVALUE USING P_VAL_INX P_MM P_SAKNR P_AM_AMT.</P>
<P>  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'<BR>    EXPORTING<BR>      INPUT  = P_SAKNR<BR>    IMPORTING<BR>      OUTPUT = GT_PERVALUE-COST_ELEM.</P>
<P>  GT_PERVALUE-VALUE_INDEX = P_VAL_INX.</P>
<P>  CASE P_MM.<BR>    WHEN '1'.  GT_PERVALUE-FIX_VAL_PER01 = P_AM_AMT.<BR>    WHEN '2'.  GT_PERVALUE-FIX_VAL_PER02 = P_AM_AMT.<BR>    WHEN '3'.  GT_PERVALUE-FIX_VAL_PER03 = P_AM_AMT.<BR>    WHEN '4'.  GT_PERVALUE-FIX_VAL_PER04 = P_AM_AMT.<BR>    WHEN '5'.  GT_PERVALUE-FIX_VAL_PER05 = P_AM_AMT.<BR>    WHEN '6'.  GT_PERVALUE-FIX_VAL_PER06 = P_AM_AMT.<BR>    WHEN '7'.  GT_PERVALUE-FIX_VAL_PER07 = P_AM_AMT.<BR>    WHEN '8'.  GT_PERVALUE-FIX_VAL_PER08 = P_AM_AMT.<BR>    WHEN '9'.  GT_PERVALUE-FIX_VAL_PER09 = P_AM_AMT.<BR>    WHEN '10'. GT_PERVALUE-FIX_VAL_PER10 = P_AM_AMT.<BR>    WHEN '11'. GT_PERVALUE-FIX_VAL_PER11 = P_AM_AMT.<BR>    WHEN '12'. GT_PERVALUE-FIX_VAL_PER12 = P_AM_AMT.<BR>  ENDCASE.</P>
<P>ENDFORM.                    " PUT_PERVALUE <BR></P>
<P> </P>