SAP获取CK13N全展开的成本核算数据

获取CK13N全展开数据,如下图所示
在这里插入图片描述
由于其背后逻辑复杂,此处使用增强+BDC调用CK13N获取数据。过程如下:
1.自定义程序调用时-全部展开增强。如果不是自定义程序,则按照系统默认方式-不展开
将MT_OUTPUT_TABLE(包含业务数据)放到meomory id里面
在这里插入图片描述
用完清空
在这里插入图片描述
2.将层级关系和描述信息内表lt_c_p_manager放到Memory id里面
在这里插入图片描述
types:BEGIN OF ty_c_p_manager,
node_key TYPE char12,
parent TYPE char12,
index TYPE numc10,
END OF ty_c_p_manager.
DATA:lt_c_p_manager TYPE TABLE OF ty_c_p_manager,
lw_c_p_manager TYPE ty_c_p_manager.

free MEMORY ID 'ZFIR28_2'.
CLear:lt_c_p_manager[].
LOOP AT mt_c_p_manager INTO DATA(lw_manager) .
   MOVE-CORRESPONDING lw_manager to lw_c_p_manager.
   append lw_c_p_manager to lt_c_p_manager.
ENDLOOP.
export output2 = lt_c_p_manager[] to MEMORY id 'ZFIR28_2'.

3.BDC获取数据
DATA:L_DATE TYPE CHAR50.
DATA:L_YEAR TYPE NUMC4,
L_MONTH TYPE NUMC2,
L_DAYS TYPE DATS.
DATA:LW_MANAGE LIKE LINE OF MT_C_P_MANAGER.

PERFORM BDC_DYNPRO USING ‘SAPLCKDI’ ‘4610’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
‘CKI64A-KLVAR’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘/00’.
PERFORM BDC_FIELD USING ‘CKI64A-KLVAR’
‘PPC1’.
PERFORM BDC_FIELD USING ‘CKI64A-TVERS’
‘1’.

"取会计年度变式期间表

  • L_YEAR = S_BDATJ-LOW.
  • L_MONTH = S_POPER-LOW.
  • L_DAYS = L_YEAR && L_MONTH && ‘01’.
    SELECT SINGLE * FROM T009B INTO @DATA(LW_T009B)
    WHERE PERIV = ‘Z1’ AND BDATJ IN @S_BDATJ
    AND POPER IN @S_POPER.

L_DAYS = LW_T009B-BDATJ && LW_T009B-BUMON && LW_T009B-BUTAG.

WRITE L_DAYS TO L_DATE.
CONDENSE L_DATE NO-GAPS.
PERFORM BDC_FIELD USING ‘CKI64A-AMDAT’
L_DATE.
PERFORM BDC_FIELD USING ‘CKI64A-MATNR’
S_MATNR-LOW.
PERFORM BDC_FIELD USING ‘CKI64A-WERKS’
S_WERKS-LOW.

PERFORM BDC_DYNPRO USING ‘SAPLCKDI’ ‘4610’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘/EBACK’.

  • BREAK CHUANGJW.
    "调用CK13N时,直接展开所有节点显示(增强实现)
    EXPORT PROGRAM = ‘ZFIR28’ TO MEMORY ID ‘ZFIR28_REPORT’.

CALL TRANSACTION ‘CK13N’ WITH AUTHORITY-CHECK USING BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO MESSTAB.

IMPORT OUTPUT = MT_OUTPUT_TABLE[] FROM MEMORY ID ‘ZFIR28’.

IMPORT OUTPUT2 = MT_C_P_MANAGER[] FROM MEMORY ID ‘ZFIR28_2’.

DELETE MT_C_P_MANAGER INDEX 1.

CLEAR:MESSTAB[],BDCDATA[].

FREE MEMORY ID ‘ZFIR28’.
FREE MEMORY ID ‘ZFIR28_2’.

附件:
工序配置表
在这里插入图片描述
报表效果
在这里插入图片描述
费用明细效果
在这里插入图片描述
工序成本报表

&---------------------------------------------------------------------
*& Report ZYS064
&---------------------------------------------------------------------
*&
&---------------------------------------------------------------------
REPORT ZYS064.
TABLES:KEKO,SSCRFIELDS.
TYPES:BEGIN OF TY_ALV,
MATNR TYPE CHAR50,
MAKTX TYPE MAKT-MAKTX,
MENGE TYPE MENGE_D,
MEINS TYPE MEINS,
VALUE1 TYPE DMBTR,
VALUE1_STR TYPE CHAR50,
VALUE2 TYPE DMBTR,
VALUE2_STR TYPE CHAR50,
VALUE3 TYPE DMBTR,
VALUE3_STR TYPE CHAR50,
VALUE4 TYPE DMBTR,
VALUE4_STR TYPE CHAR50,
OTHER TYPE DMBTR, "其他项
OTHER_STR TYPE CHAR50,
TOTAL TYPE DMBTR,
TOTAL_STR TYPE CHAR50,
RATE TYPE CHAR50,
VALUE TYPE DMBTR, "金额
DAIDING TYPE C, "待定项标记(匹配不到自建表数据)
ZERO_FLAG TYPE C, "上层物料金额为0标记
WERKS TYPE WERKS_D,
PARENT TYPE CHAR50, "父物料
END OF TY_ALV.

TYPES:BEGIN OF TY_FYMX, "费用明细
MATNR_TOP TYPE MARA-MATNR, "上层物料
KALNR TYPE KEKO-KALNR, "成本估算号
KSTAR TYPE KSTAR, "成本要素
MAKTX TYPE STRING, "成本要素名称
MENGE TYPE MENGE_D, "数量
LOSGR TYPE KEKO-LOSGR, "成本核算批量
RATE TYPE P DECIMALS 6 LENGTH 16, " 比例系数 = 数量 / 成本核算批量
WRTFW_POS TYPE CKIS-WRTFW_POS, "CKIS金额
VALUE TYPE CKIS-WRTFW_POS, "金额 = CKIS金额 * 比例系数
DAIDING TYPE C, "待定项标记(匹配不到自建表数据)
END OF TY_FYMX.

TYPES:BEGIN OF TY_C_P_MANAGER,
NODE_KEY TYPE CHAR12,
PARENT TYPE CHAR12,
INDEX TYPE NUMC10,
END OF TY_C_P_MANAGER.

TYPES:BEGIN OF TY_BOM.
TYPES:MATNR TYPE MARA-MATNR,
MAIN_FLAG TYPE C.
INCLUDE STRUCTURE STPOX.
TYPES:END OF TY_BOM.

DATA:GT_ALV TYPE TABLE OF TY_ALV,
GW_ALV TYPE TY_ALV.

DATA:GT_BOM TYPE TABLE OF TY_BOM,
GW_BOM TYPE TY_BOM.

DATA:GT_FYMX TYPE TABLE OF TY_FYMX,
GW_FYMX TYPE TY_FYMX.

DATA:GO_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA:GS_LAYOUT TYPE LVC_S_LAYO,
GT_FIELDCAT TYPE LVC_T_FCAT,
GT_FIELDCAT_MX TYPE LVC_T_FCAT,
GS_VARIANT TYPE DISVARIANT,
GS_FIELDCAT LIKE LINE OF GT_FIELDCAT,
GS_FIELDCAT_MX LIKE LINE OF GT_FIELDCAT,
GT_EXCLUDE TYPE SLIS_T_EXTAB,
GV_REPID TYPE SYREPID.

DATA:BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

  •   messages of call transaction
    

DATA:MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA:CTUMODE LIKE CTU_PARAMS-DISMODE VALUE ‘N’.

DATA:CUPDATE LIKE CTU_PARAMS-UPDMODE VALUE ‘L’.

DATA:MT_OUTPUT_TABLE TYPE TABLE OF KKB_CBL . "CK13前台数据

DATA:MT_C_P_MANAGER TYPE TABLE OF TY_C_P_MANAGER. "CK13前台数据

DATA:G_RATE TYPE P DECIMALS 6 LENGTH 16.

DATA:G_VALUE TYPE CKIS-WRTFW_POS. "费用项(人工、燃料等)金额
*&---------------------------------------------------------------------

    • 选择屏幕定义
      *&---------------------------------------------------------------------
      SELECTION-SCREEN FUNCTION KEY 1.
      SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
      SELECT-OPTIONS: S_WERKS FOR KEKO-WERKS NO-EXTENSION NO INTERVALS,
      S_MATNR FOR KEKO-MATNR NO-EXTENSION NO INTERVALS,
      S_BDATJ FOR KEKO-BDATJ NO-EXTENSION NO INTERVALS,
      S_POPER FOR KEKO-POPER NO-EXTENSION NO INTERVALS.
      SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.
SSCRFIELDS-FUNCTXT_01 = ‘维护工序成本对应表’.

AT SELECTION-SCREEN OUTPUT.

AT SELECTION-SCREEN.
IF SSCRFIELDS-UCOMM = ‘FC01’.
PERFORM FRM_CALL_SM30.
LEAVE LIST-PROCESSING.
ENDIF.

START-OF-SELECTION.

IF S_WERKS IS INITIAL OR
S_MATNR IS INITIAL OR
S_BDATJ IS INITIAL OR
S_POPER IS INITIAL.
MESSAGE ‘所有选项都必须输入’ TYPE ‘S’ DISPLAY LIKE ‘E’.
LEAVE LIST-PROCESSING.
ENDIF.

PERFORM FRM_DEAL_DATA.
PERFORM FRM_DISPLAY_DATA. "显示数据
&---------------------------------------------------------------------
*& Form FRM_DISPLAY_DATA
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM FRM_DISPLAY_DATA .

DATA:LT_EVENT TYPE SLIS_T_EVENT,
LS_EVENT LIKE LINE OF LT_EVENT.
DATA:L_SPACE TYPE CHAR30 VALUE ’  '.
DATA:L_TITLE TYPE LVC_TITLE.
DATA:L_MATNR TYPE MARA-MATNR.
DATA:L_MONTH TYPE NUMC2.

  • 给layout赋值
    GS_LAYOUT-CWIDTH_OPT = ABAP_TRUE.
    GS_LAYOUT-ZEBRA = ABAP_TRUE.
  • GS_LAYOUT-NO_ROWMARK = ABAP_TRUE.
    GS_LAYOUT-SEL_MODE = ‘D’.

CALL FUNCTION ‘CONVERSION_EXIT_MATN1_OUTPUT’
EXPORTING
INPUT = S_MATNR-LOW
IMPORTING
OUTPUT = L_MATNR.

L_MONTH = S_POPER-LOW.

L_TITLE = ‘工厂:’ && S_WERKS-LOW && L_SPACE &&
‘物料:’ && L_MATNR && L_SPACE &&
‘年份:’ && S_BDATJ-LOW && L_SPACE &&
‘月份:’ && L_MONTH.
.
GV_REPID = SY-REPID.

  • 载入需要显示的列
    PERFORM FRM_APPEND_COL .

  • 调用function module显示ALV
    CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
    EXPORTING
    I_CALLBACK_PROGRAM = GV_REPID
    IT_FIELDCAT_LVC = GT_FIELDCAT[]
    IS_LAYOUT_LVC = GS_LAYOUT
    I_GRID_TITLE = L_TITLE
    I_CALLBACK_PF_STATUS_SET = ‘FRM_SET_PF_STATUS’
    I_CALLBACK_USER_COMMAND = ‘FRM_USER_COMMAND’

  • I_CALLBACK_HTML_TOP_OF_PAGE = 'HTML_TOP_OF_PAGE'
    IT_EVENTS                = LT_EVENT[]
    I_SAVE                   = 'A'
    

    TABLES
    T_OUTTAB = GT_ALV
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.

ENDFORM.
&---------------------------------------------------------------------
*& FORM frm_set_alv_pf_status
&---------------------------------------------------------------------

  •   text:设置状态栏
    

----------------------------------------------------------------------
FORM FRM_SET_PF_STATUS USING U_EXTAB TYPE SLIS_T_EXTAB.

SET PF-STATUS ‘PF_1000’ EXCLUDING U_EXTAB.

ENDFORM. "FRM_SET_ALV_PF_STATUS
---------------------------------------------------------------------

  • FORM frm_user_command
    ---------------------------------------------------------------------

  • text: callback routine to execute user command
    ---------------------------------------------------------------------
    FORM FRM_USER_COMMAND USING U_UCOMM LIKE SY-UCOMM
    U_SELF TYPE SLIS_SELFIELD.

    DATA: LV_UCOMM LIKE SY-UCOMM,
    LV_FLAG.

    LV_UCOMM = U_UCOMM.

  • 获取alv屏幕对象
    CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
    IMPORTING
    E_GRID = GO_GRID.

  • 获取屏幕更新数据
    CALL METHOD GO_GRID->CHECK_CHANGED_DATA.

    CASE LV_UCOMM…
    WHEN ‘FYMX’."查看费用明细
    PERFORM FRM_DISPLAY_FYMX.
    WHEN OTHERS.

    ENDCASE.

ENDFORM. "FRM_USER_COMMAND
DEFINE MCR_FIELDCAT.

CLEAR gs_fieldcat.
gs_fieldcat-fieldname = &1.
gs_fieldcat-scrtext_s =
gs_fieldcat-scrtext_l =
gs_fieldcat-scrtext_m = &2.
gs_fieldcat-key = &3.
gs_fieldcat-checkbox = &4.
gs_fieldcat-edit = &5.
gs_fieldcat-hotspot = &6.
gs_fieldcat-ref_table = &7.
gs_fieldcat-ref_field = &8.
gs_fieldcat-icon = &9.
APPEND gs_fieldcat TO gt_fieldcat.

END-OF-DEFINITION.
DEFINE MCR_FIELDCAT_MX.

CLEAR gs_fieldcat_mx.
gs_fieldcat_mx-fieldname = &1.
gs_fieldcat_mx-scrtext_s =
gs_fieldcat_mx-scrtext_l =
gs_fieldcat_mx-scrtext_m = &2.
gs_fieldcat_mx-key = &3.
gs_fieldcat_mx-checkbox = &4.
gs_fieldcat_mx-edit = &5.
gs_fieldcat_mx-hotspot = &6.
gs_fieldcat_mx-ref_table = &7.
gs_fieldcat_mx-ref_field = &8.
gs_fieldcat_mx-icon = &9.
APPEND gs_fieldcat_mx TO gt_fieldcat_MX.

END-OF-DEFINITION.
&---------------------------------------------------------------------
*& Form FRM_APPEND_COL
&---------------------------------------------------------------------

  •   text:载入显示字段
    

----------------------------------------------------------------------
FORM FRM_APPEND_COL .

MCR_FIELDCAT ‘MATNR’ ‘物料编码’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘MAKTX’ ‘物料描述’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘MENGE’ ‘用量’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘MEINS’ ‘单位’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘VALUE1_STR’ ‘压延’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘VALUE2_STR’ ‘制胶’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘VALUE3_STR’ ‘涂布’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘VALUE4_STR’ ‘分切’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘OTHER_STR’ ‘其他’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘TOTAL_STR’ ‘合计’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘RATE’ ‘占比’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘VALUE’ ‘CK13N金额’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT ‘DAIDING’ ‘待定项’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.

READ TABLE GT_FIELDCAT ASSIGNING FIELD-SYMBOL(<FS_FIELDCAT>)
WITH KEY FIELDNAME = ‘MEINS’.
IF SY-SUBRC = 0.
<FS_FIELDCAT>-CONVEXIT = ‘CUNIT’.
ENDIF.

  • LOOP AT GT_FIELDCAT ASSIGNING <FS_FIELDCAT> WHERE FIELDNAME = ‘TOTAL_STR’.
  • <FS_FIELDCAT>-EMPHASIZE = ‘C510’.
  • ENDLOOP.
    ENDFORM.
    &---------------------------------------------------------------------
    *& Form FRM_APPEND_COL
    &---------------------------------------------------------------------
  •   text:载入显示字段
    

----------------------------------------------------------------------
FORM FRM_APPEND_COL_MX .
CLEAR:GT_FIELDCAT_MX[].

MCR_FIELDCAT_MX ‘MATNR_TOP’ ‘物料编码’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘KALNR’ ‘成本估算号’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘KSTAR’ ‘成本要素’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘MAKTX’ ‘成本要素名称’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘MENGE’ ‘数量’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘LOSGR’ ‘成本核算批量’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘RATE’ ‘比例系数’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘WRTFW_POS’ ‘CKIS金额’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘VALUE’ ‘最终金额’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.
MCR_FIELDCAT_MX ‘DAIDING’ ‘待定项’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’ ‘’.

  • LOOP AT GT_FIELDCAT_MX ASSIGNING FIELD-SYMBOL(<FS_FIELDCAT>) WHERE FIELDNAME = ‘VALUE’.
  • <FS_FIELDCAT>-EMPHASIZE = ‘C510’.
  • ENDLOOP.

ENDFORM.
&---------------------------------------------------------------------
*& Form FRM_CALL_SM30
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM FRM_CALL_SM30 .

CALL FUNCTION ‘VIEW_MAINTENANCE_CALL’
EXPORTING
ACTION = ‘U’
VIEW_NAME = ‘ZTFI028’
EXCEPTIONS
CLIENT_REFERENCE = 1
FOREIGN_LOCK = 2
INVALID_ACTION = 3
NO_CLIENTINDEPENDENT_AUTH = 4
NO_DATABASE_FUNCTION = 5
NO_EDITOR_FUNCTION = 6
NO_SHOW_AUTH = 7
NO_TVDIR_ENTRY = 8
NO_UPD_AUTH = 9
ONLY_SHOW_ALLOWED = 10
SYSTEM_FAILURE = 11
UNKNOWN_FIELD_IN_DBA_SELLIST = 12
VIEW_NOT_FOUND = 13
MAINTENANCE_PROHIBITED = 14
OTHERS = 15.
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.
&---------------------------------------------------------------------
*& Form FRM_DEAL_DATA
&---------------------------------------------------------------------
*& text
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM FRM_DEAL_DATA .
DATA:L_LOSGR TYPE KEKO-LOSGR.
DATA:L_KOSTL TYPE KOSTL.
DATA:L_VALUE_NAME TYPE STRING.
DATA:LW_KEKO TYPE KEKO.
DATA:LT_TAB TYPE TABLE OF STPOX.
DATA:L_BASIC_BOM TYPE STKO-BMENG.
DATA:L_INDEX TYPE I.
DATA:L_INDEX1 TYPE I,
L_INDEX_CHAR TYPE CHAR50.

CLEAR:GT_BOM,GT_ALV,GT_FYMX.
SELECT MATNR,WERKS FROM MARC INTO TABLE @DATA(LT_MARC)
WHERE MATNR IN @S_MATNR
AND WERKS IN @S_WERKS.
IF SY-SUBRC <> 0.
MESSAGE ‘找不到符合条件的数据’ TYPE ‘S’ DISPLAY LIKE ‘E’.
LEAVE LIST-PROCESSING.
ENDIF.

"获取CK13N前台数据
PERFORM FRM_GET_CK13N_DATA.

"取物料的BOM数据
LOOP AT LT_MARC INTO DATA(LW_MARC).

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
  EXPORTING
    CAPID                 = 'PP01'
    DATUV                 = SY-DATUM
    MKTLS                 = 'X'
    MEHRS                 = 'X'
    MTNRV                 = LW_MARC-MATNR
    STPST                 = 0
    SVWVO                 = 'X'
    WERKS                 = S_WERKS-LOW
    VRSVO                 = 'X'
  TABLES
    STB                   = LT_TAB
  •   MATCAT                =
    EXCEPTIONS
      ALT_NOT_FOUND         = 1
      CALL_INVALID          = 2
      MATERIAL_NOT_FOUND    = 3
      MISSING_AUTHORIZATION = 4
      NO_BOM_FOUND          = 5
      NO_PLANT_DATA         = 6
      NO_SUITABLE_BOM_FOUND = 7
      CONVERSION_ERROR      = 8
      OTHERS                = 9.
    

    GW_BOM-MATNR = LW_MARC-MATNR.
    GW_BOM-IDNRK = LW_MARC-MATNR.
    GW_BOM-WERKS = LW_MARC-WERKS.
    GW_BOM-MAIN_FLAG = ‘X’.
    APPEND GW_BOM TO GT_BOM.
    CLEAR:GW_BOM.

    LOOP AT LT_TAB INTO DATA(LW_TAB).
    MOVE-CORRESPONDING LW_TAB TO GW_BOM.
    GW_BOM-MATNR = LW_MARC-MATNR.
    APPEND GW_BOM TO GT_BOM.
    CLEAR:GW_BOM,LW_TAB.
    ENDLOOP.

    ENDLOOP.

    CHECK GT_BOM IS NOT INITIAL.

计算金额******
"根据CK13N前台值给金额,用量,单位,描述赋值
"ALV顺序根据CK13N展开的顺序显示(即BOM展开顺序显示)
LOOP AT MT_C_P_MANAGER INTO DATA(LW_MANAGER) WHERE PARENT <> ‘&VIRTUALROOT’.

READ TABLE MT_OUTPUT_TABLE INTO DATA(LW_TABLE) INDEX LW_MANAGER-INDEX.
IF SY-SUBRC = 0.
  L_INDEX = SY-TABIX.

  GW_ALV-MATNR = LW_TABLE-MATNR.
  GW_ALV-MAKTX = LW_TABLE-LTEXT.
  GW_ALV-MENGE = LW_TABLE-MENGE.
  GW_ALV-MEINS = LW_TABLE-MEEHT.
  GW_ALV-VALUE = LW_TABLE-WERTB.  "金额
  GW_ALV-WERKS = LW_TABLE-WERKS.

  CLEAR:L_INDEX_CHAR,L_INDEX1.
  "求上层物料
  L_INDEX_CHAR = LW_MANAGER-PARENT.
  CONDENSE L_INDEX_CHAR NO-GAPS.
  L_INDEX1 = L_INDEX_CHAR.
  READ TABLE MT_OUTPUT_TABLE INTO DATA(LW_TABLE1) INDEX L_INDEX1.
  IF SY-SUBRC = 0.
    GW_ALV-PARENT = LW_TABLE1-MATNR.
  ENDIF.

  "判断该物料是否有下层BOM,如果有,则金额为0.
  READ TABLE MT_C_P_MANAGER INTO DATA(LW_MANAGER1) WITH KEY PARENT = LW_MANAGER-NODE_KEY.
  IF SY-SUBRC = 0.  "含有下层BOM,则该金额为0
    GW_ALV-ZERO_FLAG = 'X'.
  ENDIF.

  APPEND GW_ALV TO GT_ALV.

  CLEAR:GW_ALV,LW_TABLE,LW_MANAGER.
ENDIF.

ENDLOOP.

匹配工序分类******

"得到物料组和物料描述的逻辑
SELECT MARA~MATNR,MATKL,MAKTX,MEINS
INTO TABLE @DATA(LT_MARA)
FROM MARA
INNER JOIN MAKT
ON MARA~MATNR = MAKT~MATNR
AND MAKT~SPRAS = @SY-LANGU
FOR ALL ENTRIES IN @GT_BOM
WHERE MARA~MATNR = @GT_BOM-IDNRK.
SORT LT_MARA BY MATNR.

"得到评估类的逻辑
SELECT MATNR,BWKEY,BKLAS
FROM MBEW
INTO TABLE @DATA(LT_MBEW)
FOR ALL ENTRIES IN @GT_BOM
WHERE MATNR = @GT_BOM-IDNRK
AND BWKEY = @GT_BOM-WERKS.
SORT LT_MBEW BY MATNR BWKEY.

"得到成本中心的逻辑
SELECT MATNR,WERKS,PLNNR FROM MAPL
INTO TABLE @DATA(LT_MAPL)
FOR ALL ENTRIES IN @GT_BOM
WHERE MATNR = @GT_BOM-IDNRK
AND WERKS = @GT_BOM-WERKS.
IF SY-SUBRC = 0.
SORT LT_MAPL BY MATNR WERKS.

SELECT PLNNR,ARBID FROM PLPO INTO
  TABLE @DATA(LT_PLPO)
  FOR ALL ENTRIES IN @LT_MAPL
  WHERE PLNNR = @LT_MAPL-PLNNR.
IF SY-SUBRC = 0.
  SORT LT_PLPO BY PLNNR.

  SELECT OBJID,KOSTL FROM CRCO
    INTO TABLE @DATA(LT_CRCO)
    FOR ALL ENTRIES IN @LT_PLPO
    WHERE OBJID = @LT_PLPO-ARBID.
  SORT LT_CRCO BY OBJID.

ENDIF.

ENDIF.

SELECT * FROM ZTFI028
INTO TABLE @DATA(LT_028).
SORT LT_028.

"匹配工序成本配置表,找到对应的工序流程,找不到流程,则待定项为X,找到流程且有下层BOM,则该流程金额为0,
"找到流程且没有下层BOM,则该流程金额不为0
DATA:L_NUM TYPE I.
DATA:L_MATKL TYPE MARA-MATKL.
DATA:L_OK TYPE C."匹配到自建表标记
DATA:L_DATE TYPE DATS.
DATA:L_DATE1 TYPE DATS.
DATA:L_MONTH_DATA TYPE T009B-BUMON,
L_YEAR_DATA TYPE T009B-BDATJ,
L_DAYS_DATA TYPE T009B-BUTAG.
RANGES:R_DATE FOR BKPF-BUDAT.

L_MONTH_DATA = S_POPER-LOW.
L_YEAR_DATA = S_BDATJ-LOW.
CALL FUNCTION ‘NUMBER_OF_DAYS_PER_MONTH_GET’
EXPORTING
PAR_MONTH = L_MONTH_DATA
PAR_YEAR = L_YEAR_DATA
IMPORTING
PAR_DAYS = L_DAYS_DATA.

L_DATE = L_YEAR_DATA && L_MONTH_DATA && ‘01’.
L_DATE1 = L_YEAR_DATA && L_MONTH_DATA && L_DAYS_DATA.

R_DATE[] = VALUE #( ( SIGN = ‘I’ OPTION = ‘BT’ LOW = L_DATE
HIGH = L_DATE1 ) ).

  • BREAK CHUANGJW.
    SELECT * FROM KEKO INTO TABLE @DATA(LT_KEKO)
    FOR ALL ENTRIES IN @MT_OUTPUT_TABLE
    WHERE MATNR = @MT_OUTPUT_TABLE-MATNR
    AND WERKS = @MT_OUTPUT_TABLE-WERKS
    AND POPER IN @S_POPER
    AND BDATJ IN @S_BDATJ
    AND KLVAR = ‘PPC1’.
    IF SY-SUBRC = 0.
    SELECT * FROM CKIS
    FOR ALL ENTRIES IN @LT_KEKO
    WHERE KALNR = @LT_KEKO-KALNR

  •  AND KADKY IN @R_DATE
    AND TYPPS = 'E'
    

    INTO TABLE @DATA(LT_CKIS_TEMP).

    SORT LT_CKIS_TEMP BY KALNR ELEMT.
    DELETE ADJACENT DUPLICATES FROM LT_CKIS_TEMP COMPARING KALNR ELEMT.
    ENDIF.

    LOOP AT GT_ALV INTO GW_ALV.

    "如果该物料下的费用含有人工,燃料等费用,则此步骤不计算
    READ TABLE LT_KEKO INTO LW_KEKO
    WITH KEY MATNR = GW_ALV-MATNR
    WERKS = GW_ALV-WERKS.
    IF SY-SUBRC = 0.
    READ TABLE LT_CKIS_TEMP INTO DATA(LW_CKIS_TEMP)
    WITH KEY KALNR = LW_KEKO-KALNR.
    IF SY-SUBRC = 0.
    CONTINUE.
    ENDIF.
    ENDIF.

    READ TABLE LT_MARA INTO DATA(LW_MARA)
    WITH KEY MATNR = GW_ALV-PARENT BINARY SEARCH.

    READ TABLE LT_MBEW INTO DATA(LW_MBEW)
    WITH KEY MATNR = GW_ALV-PARENT
    BWKEY = GW_ALV-WERKS BINARY SEARCH.

    CLEAR:L_KOSTL,L_OK.
    READ TABLE LT_MAPL INTO DATA(LW_MAPL)
    WITH KEY MATNR = GW_ALV-PARENT
    WERKS = GW_ALV-WERKS BINARY SEARCH.
    IF SY-SUBRC = 0.

    READ TABLE LT_PLPO INTO DATA(LW_PLPO)
    WITH KEY PLNNR = LW_MAPL-PLNNR BINARY SEARCH.
    IF SY-SUBRC = 0.
    
      READ TABLE LT_CRCO INTO DATA(LW_CRCO)
      WITH KEY OBJID = LW_PLPO-ARBID BINARY SEARCH.
      IF SY-SUBRC = 0.
        L_KOSTL = LW_CRCO-KOSTL.
      ENDIF.
    
    ENDIF.
    

    ENDIF.

    "先根据成本中心匹配自建表,如果存在1条记录,则取对应的工序
    "如果存在2条以上记录,则根据成本中心和物料组前缀匹配,如果存在1条记录
    "则取对应的工序,如果存在2条以上记录,则根据三个KEY匹配自建表
    CLEAR:L_NUM.
    LOOP AT LT_028 INTO DATA(LW_028) WHERE KOSTL = L_KOSTL AND MATKL IS INITIAL AND BKLAS IS INITIAL.
    ADD 1 TO L_NUM.
    IF L_NUM > 1.
    EXIT.
    ENDIF.
    ENDLOOP.
    IF L_NUM = 1.
    L_OK = ‘X’.
    PERFORM FRM_ASSIGN_ZGXFL USING LW_028 GW_ALV.
    ELSEIF L_NUM > 1.

    CLEAR:L_NUM,L_MATKL.
    LOOP AT LT_028 INTO LW_028 WHERE KOSTL = L_KOSTL AND  MATKL IS NOT INITIAL AND BKLAS IS INITIAL..
      L_MATKL = LW_028-MATKL.
      SHIFT L_MATKL RIGHT DELETING TRAILING '*'.
      DATA(L_LENGTH) = STRLEN( L_MATKL ).
      IF LW_MARA-MATKL+0(L_LENGTH) = L_MATKL.
        ADD 1 TO L_NUM.
      ENDIF.
    
      IF L_NUM > 1.
        EXIT.
      ENDIF.
    ENDLOOP.
    
    IF L_NUM = 1.
      L_OK = 'X'.
      PERFORM FRM_ASSIGN_ZGXFL USING LW_028 GW_ALV.
    ELSEIF L_NUM > 1.
    
      CLEAR:L_NUM.
      LOOP AT  LT_028 INTO LW_028 WHERE KOSTL = L_KOSTL
                                     AND BKLAS = LW_MBEW-BKLAS AND  MATKL IS NOT INITIAL..
        L_MATKL = LW_028-MATKL.
        SHIFT L_MATKL RIGHT DELETING TRAILING '*'.
        L_LENGTH = STRLEN( L_MATKL ).
        IF LW_MARA-MATKL+0(L_LENGTH) = L_MATKL.
          L_OK = 'X'.
          PERFORM FRM_ASSIGN_ZGXFL USING LW_028 GW_ALV.
          EXIT.
        ENDIF.
      ENDLOOP.
    
    ENDIF.
    

    ENDIF.

    IF L_OK IS INITIAL AND GW_ALV-ZERO_FLAG IS INITIAL.
    GW_ALV-DAIDING = ‘X’.
    "如果没有匹配上,则该行合计值等于CK13N值
    GW_ALV-TOTAL = GW_ALV-VALUE.
    GW_ALV-TOTAL_STR = GW_ALV-TOTAL.
    "其他值等于合计值
    GW_ALV-OTHER = GW_ALV-TOTAL.
    ENDIF.

    MODIFY GT_ALV FROM GW_ALV.

    CLEAR:LW_MARA,LW_MBEW,GW_ALV.
    ENDLOOP.

    "合并重复项
    DATA:LT_ALV_TEMP LIKE GT_ALV.
    LOOP AT GT_ALV INTO DATA(LW_ALV_TEMP).

    CLEAR:LW_ALV_TEMP-PARENT,LW_ALV_TEMP-ZERO_FLAG.
    COLLECT LW_ALV_TEMP INTO LT_ALV_TEMP.

    ENDLOOP.

    GT_ALV[] = LT_ALV_TEMP[].

计算费用项(人工、燃料等费用)**********
DATA:LW_ALV LIKE GW_ALV.
DATA:LW_TMP LIKE GW_ALV.
DATA:LT_ALV LIKE GT_ALV.

"根据成本核算号算出该成本核算号下的所有人工,燃料等费用

  • BREAK CHUANGJW.
    IF LT_KEKO[] IS NOT INITIAL.
    SELECT * FROM CKIS INTO TABLE @DATA(LT_CKIS)
    FOR ALL ENTRIES IN @LT_KEKO
    WHERE KALNR = @LT_KEKO-KALNR
    AND TYPPS = ‘E’.
    IF SY-SUBRC = 0.
    SORT LT_CKIS BY KALNR ELEMT.
    DELETE ADJACENT DUPLICATES FROM LT_CKIS COMPARING KALNR ELEMT.
    ENDIF.
    ENDIF.

SELECT * FROM CSKU INTO TABLE @DATA(LT_CSKU)
WHERE KTOPL = ‘1000’
AND SPRAS = @SY-LANGU.
SORT LT_CSKU BY KSTAR.

CLEAR:GT_FYMX.
LOOP AT MT_OUTPUT_TABLE INTO LW_TABLE.

"比例系数 = 物料的数量 / 成本核算批量
CLEAR:G_VALUE.
G_RATE = LW_TABLE-MENGE / LW_TABLE-LOSGR.

"本层物料对应的成本核算号
CLEAR:LW_KEKO.
READ TABLE LT_KEKO INTO LW_KEKO WITH KEY MATNR = LW_TABLE-MATNR.

"本层物料下的所有费用
LOOP AT LT_CKIS INTO DATA(LW_CKIS) WHERE KALNR = LW_KEKO-KALNR.

  "每个费用需要匹配到对应的工序上,无论是否匹配到都需要加在合计中,同时显示该项费用的每一项
  CLEAR:LW_ALV,G_VALUE.
  LW_ALV-MATNR = LW_CKIS-KSTAR.

  READ TABLE LT_CSKU INTO DATA(LW_CSKU) WITH KEY KSTAR = LW_CKIS-KSTAR BINARY SEARCH.
  IF SY-SUBRC = 0.
    LW_ALV-MAKTX = LW_CSKU-KTEXT.
  ENDIF.

  "判断属于哪个工序流程
  READ TABLE LT_MARA INTO LW_MARA
  WITH KEY MATNR = LW_KEKO-MATNR BINARY SEARCH.

  READ TABLE LT_MBEW INTO LW_MBEW
  WITH KEY MATNR = LW_KEKO-MATNR
           BWKEY = LW_KEKO-WERKS BINARY SEARCH.

  CLEAR:L_KOSTL,L_OK.
  READ TABLE LT_MAPL INTO LW_MAPL
  WITH KEY MATNR = LW_KEKO-MATNR
           WERKS = LW_KEKO-WERKS BINARY SEARCH.
  IF SY-SUBRC = 0.

    READ TABLE LT_PLPO INTO LW_PLPO
    WITH KEY PLNNR = LW_MAPL-PLNNR BINARY SEARCH.
    IF SY-SUBRC = 0.

      READ TABLE LT_CRCO INTO LW_CRCO
      WITH KEY OBJID = LW_PLPO-ARBID BINARY SEARCH.
      IF SY-SUBRC = 0.
        L_KOSTL = LW_CRCO-KOSTL.
      ENDIF.

    ENDIF.
  ENDIF.

  "先根据成本中心匹配自建表,如果存在1条记录,则取对应的工序
  "如果存在2条以上记录,则根据成本中心和物料组前缀匹配,如果存在1条记录
  "则取对应的工序,如果存在2条以上记录,则根据三个KEY匹配自建表
  CLEAR:L_NUM.
  LOOP AT LT_028 INTO LW_028 WHERE KOSTL = L_KOSTL AND  MATKL IS INITIAL AND BKLAS IS INITIAL..
    ADD 1 TO L_NUM.
    IF L_NUM > 1.
      EXIT.
    ENDIF.
  ENDLOOP.
  IF L_NUM = 1.
    L_OK = 'X'.
    PERFORM FRM_ASSIGN_ZGXFL_OTHER USING LW_028 LW_CKIS LW_ALV.
  ELSEIF L_NUM > 1.

    CLEAR:L_NUM,L_MATKL.
    LOOP AT LT_028 INTO LW_028 WHERE KOSTL = L_KOSTL AND  MATKL IS NOT INITIAL AND BKLAS IS INITIAL..
      L_MATKL = LW_028-MATKL.
      SHIFT L_MATKL RIGHT DELETING TRAILING '*'.
      L_LENGTH = STRLEN( L_MATKL ).
      IF LW_MARA-MATKL+0(L_LENGTH) = L_MATKL.
        ADD 1 TO L_NUM.
      ENDIF.

      IF L_NUM > 1.
        EXIT.
      ENDIF.
    ENDLOOP.

    IF L_NUM = 1.
      L_OK = 'X'.
      PERFORM FRM_ASSIGN_ZGXFL_OTHER USING LW_028 LW_CKIS LW_ALV.
    ELSEIF L_NUM > 1.

      CLEAR:L_NUM.
      LOOP AT  LT_028 INTO LW_028 WHERE KOSTL = L_KOSTL
                                     AND BKLAS = LW_MBEW-BKLAS AND  MATKL IS NOT INITIAL..
        L_MATKL = LW_028-MATKL.
        SHIFT L_MATKL RIGHT DELETING TRAILING '*'.
        L_LENGTH = STRLEN( L_MATKL ).
        IF LW_MARA-MATKL+0(L_LENGTH) = L_MATKL.
          L_OK = 'X'.
          PERFORM FRM_ASSIGN_ZGXFL_OTHER USING LW_028 LW_CKIS LW_ALV.
          EXIT.
        ENDIF.
      ENDLOOP.

    ENDIF.

  ENDIF.

  G_VALUE = LW_CKIS-WRTFW_POS * G_RATE.

  "如果没有匹配到具体工序,也需要加到合计上
  IF L_OK IS INITIAL. "没取到
    LW_ALV-TOTAL = LW_ALV-TOTAL + G_VALUE.
    GW_FYMX-DAIDING = 'X'.
  ELSE. "取到
    LW_ALV-TOTAL = LW_ALV-VALUE1 + LW_ALV-VALUE2
                 + LW_ALV-VALUE3 + LW_ALV-VALUE4.
  ENDIF.

  "记录本次费用明细
  GW_FYMX-MATNR_TOP = LW_KEKO-MATNR.
  GW_FYMX-KALNR = LW_KEKO-KALNR.
  GW_FYMX-KSTAR = LW_ALV-MATNR.
  GW_FYMX-MAKTX = LW_ALV-MAKTX.
  GW_FYMX-MENGE = LW_TABLE-MENGE.   "数量
  GW_FYMX-LOSGR = LW_TABLE-LOSGR."成本核算批量
  GW_FYMX-RATE  = G_RATE.        " 比例系数 = 数量 / 成本核算批量
  GW_FYMX-WRTFW_POS = LW_CKIS-WRTFW_POS. "CKIS金额
  GW_FYMX-VALUE = G_VALUE.
  APPEND GW_FYMX TO GT_FYMX.
  CLEAR:GW_FYMX.

  COLLECT LW_ALV INTO LT_ALV.

  CLEAR:LW_ALV.
  CLEAR:LW_MBEW,LW_028,LW_MAPL,LW_PLPO,LW_CRCO,LW_MARA.

  CLEAR:LW_CKIS.
ENDLOOP.

CLEAR:LW_TABLE.

ENDLOOP.

  • break CHUANGJW.
    "根据该成本要素的明细数据是否有待定项决定最终汇总行是否有待定
    LOOP AT LT_ALV INTO LW_ALV.
    READ TABLE GT_FYMX INTO GW_FYMX WITH KEY KSTAR = LW_ALV-MATNR DAIDING = ‘X’.
    IF SY-SUBRC = 0.
    LW_ALV-DAIDING = ‘X’.

    "计算其他 = 合计 - 四项之和
    LW_ALV-OTHER = LW_ALV-TOTAL - LW_ALV-VALUE1 - LW_ALV-VALUE2 - LW_ALV-VALUE3 - LW_ALV-VALUE4.
    ENDIF.
    APPEND LW_ALV TO GT_ALV.
    CLEAR:LW_ALV.
    ENDLOOP.

  • break CHUANGJW.
    "计算汇总值
    CLEAR:LT_ALV.
    LOOP AT GT_ALV INTO GW_ALV.

    CLEAR:GW_ALV-MATNR,GW_ALV-MAKTX,GW_ALV-MEINS,GW_ALV-MENGE.
    CLEAR:GW_ALV-DAIDING,GW_ALV-VALUE,GW_ALV-ZERO_FLAG,GW_ALV-WERKS,GW_ALV-PARENT,GW_ALV-TOTAL_STR.
    MOVE-CORRESPONDING GW_ALV TO LW_ALV.
    COLLECT LW_ALV INTO LT_ALV.
    CLEAR:LW_ALV.

    ENDLOOP.

    "计算比例
    DATA:L_RATE TYPE P DECIMALS 4 LENGTH 10.
    DATA:L_RATE1 TYPE P DECIMALS 2 LENGTH 10.
    READ TABLE LT_ALV INTO LW_ALV INDEX 1.

  • BREAK CHUANGJW.
    LOOP AT GT_ALV ASSIGNING FIELD-SYMBOL(<FS_ALV>).

" 压延   制胶   涂布  分切
DO 4 TIMES.
  L_VALUE_NAME = 'VALUE' && SY-INDEX.
  ASSIGN COMPONENT L_VALUE_NAME OF STRUCTURE <FS_ALV>
  TO FIELD-SYMBOL(<FS_VALUE1>).
  IF <FS_VALUE1> IS ASSIGNED AND <FS_VALUE1> <> 0.
    L_VALUE_NAME = L_VALUE_NAME && '_STR'.
    ASSIGN COMPONENT L_VALUE_NAME OF STRUCTURE <FS_ALV>
    TO FIELD-SYMBOL(<FS_VALUE2>).
    IF <FS_VALUE2> IS ASSIGNED.
      <FS_VALUE2> = <FS_VALUE1>.
      UNASSIGN:<FS_VALUE2>.
    ENDIF.
    UNASSIGN:<FS_VALUE1>.
  ENDIF.
ENDDO.
<FS_ALV>-OTHER_STR = <FS_ALV>-OTHER.
<FS_ALV>-TOTAL_STR = <FS_ALV>-TOTAL.

"占比
IF LW_ALV-TOTAL <> 0.
  L_RATE = <FS_ALV>-TOTAL / LW_ALV-TOTAL.
  L_RATE1 = L_RATE * 100.
  <FS_ALV>-RATE = L_RATE1 && '%'.
ENDIF.

ENDLOOP.

最后2行*************
"金额汇总行
CLEAR:GW_ALV,LW_KEKO,LW_TMP.
READ TABLE MT_OUTPUT_TABLE INTO LW_TABLE WITH KEY MATNR = S_MATNR-LOW
WERKS = S_WERKS-LOW.
GW_ALV-MATNR = ‘每’ && LW_TABLE-LOSGR && ‘平米胶带的标准成本’.
DO 4 TIMES.
L_VALUE_NAME = ‘VALUE’ && SY-INDEX.
ASSIGN COMPONENT L_VALUE_NAME OF STRUCTURE LW_ALV
TO <FS_VALUE1>.
IF <FS_VALUE1> IS ASSIGNED AND <FS_VALUE1> <> 0.

  L_VALUE_NAME = L_VALUE_NAME && '_STR'.
  ASSIGN COMPONENT L_VALUE_NAME OF STRUCTURE GW_ALV
  TO <FS_VALUE2>.
  IF <FS_VALUE2> IS ASSIGNED.
    <FS_VALUE2> = <FS_VALUE1>.
    UNASSIGN:<FS_VALUE2>.
  ENDIF.

  "比例行
  IF LW_ALV-TOTAL <> 0.
    L_RATE = <FS_VALUE1> / LW_ALV-TOTAL.
    L_RATE1 = L_RATE * 100.
    ASSIGN COMPONENT L_VALUE_NAME OF STRUCTURE LW_TMP
    TO <FS_VALUE2>.
    IF <FS_VALUE2> IS ASSIGNED.
      <FS_VALUE2> = L_RATE1 && '%'.
      UNASSIGN:<FS_VALUE2>.
    ENDIF.
  ENDIF.

ENDIF.

ENDDO.

"汇总行
GW_ALV-OTHER_STR = LW_ALV-OTHER.
GW_ALV-TOTAL_STR = LW_ALV-TOTAL.
GW_ALV-RATE = ‘100%’.
APPEND GW_ALV TO GT_ALV.
CLEAR:GW_ALV.

"比例行
L_RATE = LW_ALV-OTHER / LW_ALV-TOTAL.
L_RATE1 = L_RATE * 100.
LW_TMP-OTHER_STR = L_RATE1 && ‘%’.
LW_TMP-TOTAL_STR = ‘100%’.
APPEND LW_TMP TO GT_ALV.

ENDFORM.
FORM FRM_GET_CK13N_DATA.
DATA:L_DATE TYPE CHAR50.
DATA:L_YEAR TYPE NUMC4,
L_MONTH TYPE NUMC2,
L_DAYS TYPE DATS.
DATA:LW_MANAGE LIKE LINE OF MT_C_P_MANAGER.

PERFORM BDC_DYNPRO USING ‘SAPLCKDI’ ‘4610’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
‘CKI64A-KLVAR’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘/00’.
PERFORM BDC_FIELD USING ‘CKI64A-KLVAR’
‘PPC1’.
PERFORM BDC_FIELD USING ‘CKI64A-TVERS’
‘1’.

"取会计年度变式期间表

  • L_YEAR = S_BDATJ-LOW.
  • L_MONTH = S_POPER-LOW.
  • L_DAYS = L_YEAR && L_MONTH && ‘01’.
    SELECT SINGLE * FROM T009B INTO @DATA(LW_T009B)
    WHERE PERIV = ‘Z1’ AND BDATJ IN @S_BDATJ
    AND POPER IN @S_POPER.

L_DAYS = LW_T009B-BDATJ && LW_T009B-BUMON && LW_T009B-BUTAG.

WRITE L_DAYS TO L_DATE.
CONDENSE L_DATE NO-GAPS.
PERFORM BDC_FIELD USING ‘CKI64A-AMDAT’
L_DATE.
PERFORM BDC_FIELD USING ‘CKI64A-MATNR’
S_MATNR-LOW.
PERFORM BDC_FIELD USING ‘CKI64A-WERKS’
S_WERKS-LOW.

PERFORM BDC_DYNPRO USING ‘SAPLCKDI’ ‘4610’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘/EBACK’.

  • BREAK CHUANGJW.
    "调用CK13N时,直接展开所有节点显示(增强实现)
    EXPORT PROGRAM = ‘ZFIR28’ TO MEMORY ID ‘ZFIR28_REPORT’.

CALL TRANSACTION ‘CK13N’ WITH AUTHORITY-CHECK USING BDCDATA
MODE CTUMODE
UPDATE CUPDATE
MESSAGES INTO MESSTAB.

IMPORT OUTPUT = MT_OUTPUT_TABLE[] FROM MEMORY ID ‘ZFIR28’.

IMPORT OUTPUT2 = MT_C_P_MANAGER[] FROM MEMORY ID ‘ZFIR28_2’.

DELETE MT_C_P_MANAGER INDEX 1.

CLEAR:MESSTAB[],BDCDATA[].

FREE MEMORY ID ‘ZFIR28’.
FREE MEMORY ID ‘ZFIR28_2’.

IF MT_OUTPUT_TABLE[] IS INITIAL OR MT_C_P_MANAGER[] IS INITIAL.
MESSAGE ‘找不到符合条件的数据’ TYPE ‘S’ DISPLAY LIKE ‘E’.
LEAVE LIST-PROCESSING.
ENDIF.

ENDFORM.
----------------------------------------------------------------------

  •    Insert field                                                  *
    

----------------------------------------------------------------------
FORM BDC_FIELD USING FNAM FVAL.

  • IF FVAL <> NODATA.
    CLEAR BDCDATA.
    BDCDATA-FNAM = FNAM.
    BDCDATA-FVAL = FVAL.
    APPEND BDCDATA.
  • ENDIF.
    ENDFORM.
    ----------------------------------------------------------------------
  •    Start new screen                                              *
    

----------------------------------------------------------------------
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = ‘X’.
APPEND BDCDATA.
ENDFORM.
FORM FRM_ASSIGN_ZGXFL USING FU_028 TYPE ZTFI028 FU_ALV TYPE TY_ALV.
DATA:L_VALUE_NAME TYPE STRING.

L_VALUE_NAME = ‘VALUE’ && FU_028-ZGXFL.
ASSIGN COMPONENT L_VALUE_NAME
OF STRUCTURE FU_ALV TO FIELD-SYMBOL(<FS_VALUE>).
IF <FS_VALUE> IS ASSIGNED AND FU_ALV-ZERO_FLAG IS INITIAL.
<FS_VALUE> = FU_ALV-VALUE.
FU_ALV-TOTAL = FU_ALV-VALUE.
FU_ALV-DAIDING = ‘’.
UNASSIGN:<FS_VALUE>.
ENDIF.

ENDFORM.
FORM FRM_ASSIGN_ZGXFL_OTHER USING FU_028 TYPE ZTFI028 FU_CKIS TYPE CKIS FU_ALV TYPE TY_ALV.
DATA:L_VALUE_NAME TYPE STRING.

L_VALUE_NAME = ‘VALUE’ && FU_028-ZGXFL.
ASSIGN COMPONENT L_VALUE_NAME
OF STRUCTURE FU_ALV TO FIELD-SYMBOL(<FS_VALUE>).
IF <FS_VALUE> IS ASSIGNED.
<FS_VALUE> = FU_CKIS-WRTFW_POS * G_RATE.
UNASSIGN:<FS_VALUE>.
ENDIF.

ENDFORM.
&---------------------------------------------------------------------
*& Form FRM_DISPLAY_FYMX
&---------------------------------------------------------------------
*& text 显示人工等费用明细
&---------------------------------------------------------------------
*& --> p1 text
*& <-- p2 text
&---------------------------------------------------------------------
FORM FRM_DISPLAY_FYMX .
DATA:L_TITLE TYPE LVC_TITLE.
DATA:L_MATNR TYPE MARA-MATNR.
DATA:L_MONTH TYPE NUMC2.
DATA:LS_LAYOUT TYPE LVC_S_LAYO,
LS_VARIANT TYPE DISVARIANT,
LV_REPID TYPE SYREPID.

  • 给layout赋值
    LS_LAYOUT-CWIDTH_OPT = ABAP_TRUE.
    LS_LAYOUT-ZEBRA = ABAP_TRUE.
    LS_LAYOUT-SEL_MODE = ‘D’.
    L_TITLE = ‘费用明细’.
    LV_REPID = SY-REPID.

  • 载入需要显示的列
    PERFORM FRM_APPEND_COL_MX.

  • 调用function module显示ALV
    CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
    EXPORTING
    I_CALLBACK_PROGRAM = LV_REPID
    IT_FIELDCAT_LVC = GT_FIELDCAT_MX[]
    IS_LAYOUT_LVC = LS_LAYOUT
    I_GRID_TITLE = L_TITLE
    I_SAVE = ‘A’
    TABLES
    T_OUTTAB = GT_FYMX
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.

ENDFORM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值