首页 > 其他分享 >ABAP-CJ20N创建项目

ABAP-CJ20N创建项目

时间:2023-03-13 20:37:01浏览次数:40  
标签:GV ITAB GT GS PS CJ20N 创建 ABAP TYPE

   1 REPORT ZPSB_XM.
   2 
   3 *参考表
   4 TABLES:SSCRFIELDS.
   5 
   6 *定义结构
   7 TYPES:BEGIN OF TY_ITAB,
   8         PSPID           TYPE PS_PSPID, "项目ID
   9         POST1           TYPE PS_POST1, "项目描述
  10         VBUKR           TYPE PS_VBUKR, "公司代码
  11         WERKS           TYPE WERKS_D, "工厂代码
  12         PGSBR           TYPE PS_PGSBR, "业务范围编码
  13         PRCTR           TYPE PRCTR, "利润中心编码
  14         PROFL           TYPE PROFIDPROJ, "项目参数文件
  15         POSID           TYPE PS_POSID, "WBS编码
  16         POST2           TYPE PS_POST1, "WBS描述
  17         STUFE(3),                   "WBS层级
  18         UP_WBS          TYPE PS_POSID, "上级WBS编码
  19         UP_WBS_POST1    TYPE PS_POST1, "上级WBS描述
  20         WVBUKR          TYPE PS_VBUKR, "公司代码
  21         WWERKS          TYPE WERKS_D, "工厂代码
  22         WPGSBR          TYPE PS_PGSBR, "业务范围编码
  23         FUNC_AREA       TYPE FKBER,  "功能范围编码
  24         WPRCTR          TYPE PRCTR, "利润中心编码
  25         WFKSTL          TYPE PS_FKSTL, "成本中心编码
  26         PRART           TYPE PRART, "项目类型
  27         ZZTYPE          TYPE ZE_TYPE,               "项目类型
  28         ZZFUND_FILE     TYPE ZE_FUND_FILE,               "资金管理文件编码
  29         ZZFUND_VERSION  TYPE ZE_FUND_VERSION,               "版本编码
  30         ZZSIGN_RESEARCH TYPE ZE_SIGN_RESEARCH,               "是否为签合同科研项目
  31         PSTRT           TYPE PS_PSTRT,                 "项目计划开始日期
  32         PENDE           TYPE PS_PENDE,                 "项目计划完成日期
  33         VERNR           TYPE PS_VERNR,                 "BU项目经理
  34         ZZXSFR          TYPE C,        "项目销售负责人
  35         UP_WBS1         TYPE PS_POSID, "上级WBS编码
  36         VORNR           TYPE VORNR,    "活动编码
  37         LTXA1           TYPE LTXA1,    "工序短文本
  38         NTANF(8),                   "活动计划开始日期
  39         NTEND(8),                   "活动计划完成日期
  40         USR00           TYPE USRCHAR20, "任务负责人
  41         COFRM           TYPE C,        "报工标识
  42         MESSAGE(220)    TYPE C,
  43         ZTYPE(1)        TYPE C,
  44         ZCHECK          TYPE ICON-NAME,
  45         SEL             TYPE FLAG,
  46       END OF TY_ITAB.
  47 
  48 TYPES:BEGIN OF TY_PSPID,
  49         PSPID TYPE PS_PSPID, "项目ID
  50       END OF TY_PSPID.
  51 
  52 TYPES:BEGIN OF TY_UPSTUFE,
  53         POSID    TYPE PS_POSID,
  54         STUFE(3),
  55       END OF TY_UPSTUFE.
  56 
  57 *定义内表和工作区
  58 DATA:GT_ITAB  TYPE TABLE OF TY_ITAB,
  59      GS_ITAB  TYPE TY_ITAB,
  60      GT_PSPID TYPE STANDARD TABLE OF TY_PSPID WITH HEADER LINE.
  61 
  62 *定义指针
  63 FIELD-SYMBOLS <FS_ITAB> TYPE TY_ITAB.
  64 
  65 "ALV展示用的变量
  66 DATA: GT_FIELDCAT TYPE LVC_T_FCAT,        "存放字段目录的内表 Fieldcat
  67       GS_LAYOUT   TYPE LVC_S_LAYO,        "布局结构 layout
  68       GS_SETTING  TYPE LVC_S_GLAY,        "设置
  69       GT_EVENT    TYPE SLIS_T_EVENT.
  70 DATA: GO_GRID TYPE REF TO CL_GUI_ALV_GRID.
  71 DATA: GT_EXTAB TYPE TABLE OF SY-UCOMM WITH HEADER LINE.
  72 
  73 *项目定义
  74 DATA:GS_PROJECT TYPE BAPI_PROJECT_DEFINITION,
  75      GS_RETURN  TYPE BAPIRETURN1,
  76      GT_E_MSG   LIKE BAPI_METH_MESSAGE OCCURS 0 WITH HEADER LINE..
  77 
  78 *WBS元素
  79 DATA:GS_PRODEF    LIKE BAPI_PROJECT_DEFINITION,
  80      GS_PRODEF_UP LIKE BAPI_PROJECT_DEFINITION_UP,
  81      GT_METHOD    LIKE BAPI_METHOD_PROJECT OCCURS 0 WITH HEADER LINE,
  82      GT_MSGTAB    LIKE BAPI_METH_MESSAGE OCCURS 0 WITH HEADER LINE,
  83      GT_WBSELE    LIKE BAPI_WBS_ELEMENT  OCCURS 0 WITH HEADER LINE,
  84      GT_WBSELE_UP LIKE BAPI_WBS_ELEMENT_UPDATE  OCCURS 0 WITH HEADER LINE,
  85      GT_WBSHI_TAB LIKE BAPI_WBS_HIERARCHIE OCCURS 0 WITH HEADER LINE,
  86      GT_UPSTUFE   TYPE TY_UPSTUFE OCCURS 0 WITH HEADER LINE.
  87 
  88 *定义变量
  89 DATA:GV_MSG      TYPE CHAR200,
  90      GV_PSPNR    TYPE PROJ-PSPNR,
  91      GV_SUBRC    TYPE SY-SUBRC,
  92      GV_TABIX    TYPE SY-TABIX,
  93      GV_ZTYPE(1) TYPE C,
  94      GV_ZCHECK   TYPE ICON-NAME,
  95      GV_NUM      TYPE I,
  96      GV_LINES    TYPE CHAR6,
  97      GV_WBS      LIKE PRPS-POSID,
  98      GV_PSPID    TYPE PS_PSPID,
  99      GV_STUFE    LIKE PRPS-STUFE,
 100      GV_POSID    LIKE PRPS-POSID,
 101      GV_WBS_UP   LIKE GT_WBSHI_TAB-UP,
 102      GV_WBS_LEFT LIKE GT_WBSHI_TAB-LEFT.
 103 
 104 *选择屏幕
 105 SELECTION-SCREEN FUNCTION KEY 1.
 106 SELECTION-SCREEN BEGIN OF BLOCK DEMO1 WITH FRAME TITLE TEXT-001.
 107 
 108   PARAMETERS:P_FILE LIKE RLGRAP-FILENAME.           "EXCEL文件路径
 109 
 110 SELECTION-SCREEN END OF BLOCK DEMO1.
 111 
 112 *----------------------------------------------------------------------*
 113 *INITIALIZATION.
 114 *----------------------------------------------------------------------*
 115 INITIALIZATION.
 116 
 117   PERFORM FRM_INIT. "用于屏幕初始化,例如屏幕字段默认值的填充
 118 
 119 *----------------------------------------------------------------------*
 120 *AT SELECTION-SCREEN OUTPUT
 121 *----------------------------------------------------------------------*
 122 AT SELECTION-SCREEN OUTPUT.
 123 
 124 *----------------------------------------------------------------------*
 125 *AT SELECTION-SCREEN
 126 *----------------------------------------------------------------------*
 127 AT SELECTION-SCREEN.
 128 
 129   PERFORM FRM_SCREEN_COMMAND.
 130 
 131   IF SSCRFIELDS-UCOMM = 'ONLI'.
 132 
 133     CLEAR: GV_MSG.
 134     IF P_FILE IS INITIAL.
 135       GV_MSG = '导入文件路径必须填写!' .
 136     ENDIF.
 137     IF GV_MSG IS NOT INITIAL.
 138       MESSAGE S001(00) WITH  GV_MSG DISPLAY LIKE 'E'.
 139       LEAVE TO SCREEN 1000 .
 140     ENDIF.
 141 
 142   ENDIF.
 143 
 144 *----------------------------------------------------------------------*
 145 * AT SELECTION-SCREEN ON VALUE-REQUEST FOR
 146 *----------------------------------------------------------------------*
 147 AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.  "弹出文件选择框
 148 
 149   PERFORM FRM_GET_FILLPATH CHANGING P_FILE.
 150 
 151 *----------------------------------------------------------------------*
 152 *START-OF-SELECTION
 153 *----------------------------------------------------------------------*
 154 START-OF-SELECTION.
 155 
 156   PERFORM FRM_READ_EXCEL TABLES GT_ITAB[]
 157                             USING P_FILE 1 3 33 60001
 158                          CHANGING GS_ITAB.
 159 
 160   IF GT_ITAB[] IS NOT INITIAL.
 161 
 162     "数据校验
 163     PERFORM FRM_CHECK_DATA TABLES GT_ITAB[].
 164 
 165     "ALV显示
 166     PERFORM FRM_BUILD_FIELD CHANGING GT_FIELDCAT.             "定义列标题信息
 167     PERFORM FRM_BUILD_LAYOUT CHANGING GS_LAYOUT.              "定义ALV格式属性
 168     PERFORM FRM_DISPLAY_DATA_ALV TABLES GT_ITAB[]            "显示数据
 169                                  CHANGING GT_FIELDCAT
 170                                           GS_LAYOUT
 171                                           GT_EVENT
 172                                           GS_SETTING.
 173 
 174   ELSE.
 175 
 176     MESSAGE '读取EXCEL数据失败或EXCEL无数据!' TYPE 'S' DISPLAY LIKE 'E'.
 177     EXIT.
 178 
 179   ENDIF.
 180 
 181 *----------------------------------------------------------------------*
 182 *FORM
 183 *----------------------------------------------------------------------*
 184 
 185 *&---------------------------------------------------------------------*
 186 *& Form FRM_INIT
 187 *&---------------------------------------------------------------------*
 188 *& text
 189 *&---------------------------------------------------------------------*
 190 *& -->  p1        text
 191 *& <--  p2        text
 192 *&---------------------------------------------------------------------*
 193 FORM FRM_INIT .
 194 
 195   PERFORM FRM_CREATE_ICON USING 'ICON_SAVE_AS_TEMPLATE' '下载模板'
 196                        CHANGING SSCRFIELDS-FUNCTXT_01.
 197 
 198 ENDFORM.
 199 
 200 *&---------------------------------------------------------------------*
 201 *& Form FRM_CREATE_ICON
 202 *&---------------------------------------------------------------------*
 203 *& text
 204 *&---------------------------------------------------------------------*
 205 *&      --> P_
 206 *&      --> P_
 207 *&      <-- SSCRFIELDS_FUNCTXT_01
 208 *&---------------------------------------------------------------------*
 209 FORM FRM_CREATE_ICON USING VALUE(I_ICON_NAME) TYPE C
 210                            VALUE(I_TEXT) TYPE C
 211                   CHANGING VALUE(O_ICON) TYPE C.
 212 
 213   CLEAR O_ICON.
 214   CALL FUNCTION 'ICON_CREATE'
 215     EXPORTING
 216       NAME   = I_ICON_NAME
 217       TEXT   = I_TEXT
 218       INFO   = I_TEXT
 219     IMPORTING
 220       RESULT = O_ICON
 221     EXCEPTIONS
 222       OTHERS = 0.
 223 
 224 ENDFORM.
 225 
 226 *&---------------------------------------------------------------------*
 227 *& Form FRM_SCREEN_COMMAND
 228 *&---------------------------------------------------------------------*
 229 *& text
 230 *&---------------------------------------------------------------------*
 231 *& -->  p1        text
 232 *& <--  p2        text
 233 *&---------------------------------------------------------------------*
 234 FORM FRM_SCREEN_COMMAND .
 235 
 236   IF SY-UCOMM = 'FC01'.
 237 * 这里要利用SMW0 加载 EXCLE 模板 ,并调用响应的模板名称
 238     PERFORM FRM_DOWN_TEMPLATE USING 'ZPSB_XM_EXCEL' '项目批导入模板'.
 239   ENDIF.
 240 
 241 ENDFORM.
 242 
 243 *&---------------------------------------------------------------------*
 244 *& Form FRM_DOWN_TEMPLATE
 245 *&---------------------------------------------------------------------*
 246 *& text
 247 *&---------------------------------------------------------------------*
 248 *&      --> P_
 249 *&      --> P_
 250 *&---------------------------------------------------------------------*
 251 FORM FRM_DOWN_TEMPLATE USING VALUE(PV_OBJID) TYPE WWWDATA-OBJID
 252                              VALUE(PV_NAME) TYPE STRING.
 253 
 254   DATA : L_SUBRC    LIKE SY-SUBRC,
 255          L_FILENAME LIKE RLGRAP-FILENAME,
 256          LS_KEY     TYPE WWWDATATAB.
 257   PERFORM FRM_GET_FILENAME USING 'S' PV_NAME CHANGING L_FILENAME.
 258   CHECK L_FILENAME NE SPACE.
 259 
 260   CLEAR LS_KEY.
 261   SELECT SINGLE RELID OBJID
 262     FROM WWWDATA INTO CORRESPONDING FIELDS OF LS_KEY
 263    WHERE SRTF2 = 0
 264      AND RELID = 'MI'
 265   AND OBJID = PV_OBJID.
 266   IF SY-SUBRC = 0.
 267     CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
 268       EXPORTING
 269         KEY         = LS_KEY
 270         DESTINATION = L_FILENAME
 271       IMPORTING
 272         RC          = L_SUBRC.
 273   ELSE.
 274     MESSAGE S299(26).    "未找到模板
 275   ENDIF.
 276 
 277 ENDFORM.
 278 
 279 *&---------------------------------------------------------------------*
 280 *& Form FRM_GET_FILENAME
 281 *&---------------------------------------------------------------------*
 282 *& text
 283 *&---------------------------------------------------------------------*
 284 *&      --> P_
 285 *&      --> PV_NAME
 286 *&      <-- L_FILENAME
 287 *&---------------------------------------------------------------------*
 288 FORM FRM_GET_FILENAME USING VALUE(I_MODE) TYPE C
 289                             VALUE(I_NAME) TYPE STRING
 290                     CHANGING VALUE(O_FILENAME) TYPE C.
 291 
 292   CALL FUNCTION 'WS_FILENAME_GET'
 293     EXPORTING
 294       DEF_FILENAME     = I_NAME
 295       MASK             = ',EXCEL FILE,*.XLSX;'
 296       MODE             = I_MODE
 297     IMPORTING
 298       FILENAME         = O_FILENAME
 299     EXCEPTIONS
 300       INV_WINSYS       = 1
 301       NO_BATCH         = 2
 302       SELECTION_CANCEL = 3
 303       SELECTION_ERROR  = 4
 304       OTHERS           = 5.
 305 
 306 ENDFORM.
 307 
 308 *&---------------------------------------------------------------------*
 309 *& Form FRM_GET_FILLPATH
 310 *&---------------------------------------------------------------------*
 311 *& text
 312 *&---------------------------------------------------------------------*
 313 *&      <-- P_FILE
 314 *&---------------------------------------------------------------------*
 315 FORM FRM_GET_FILLPATH  CHANGING CV_PATH.
 316 
 317   DATA FILE_TABLE TYPE FILETABLE.
 318   DATA RC TYPE I.
 319 
 320   CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
 321     EXPORTING
 322       WINDOW_TITLE   = '请选择导入的文件路径'
 323       FILE_FILTER    = CL_GUI_FRONTEND_SERVICES=>FILETYPE_EXCEL
 324       MULTISELECTION = ''
 325     CHANGING
 326       FILE_TABLE     = FILE_TABLE
 327       RC             = RC.
 328 
 329   IF SY-SUBRC <> 0.
 330 
 331   ENDIF.
 332   READ TABLE FILE_TABLE INTO DATA(LS_FILE_TABLE) INDEX 1.
 333   CHECK SY-SUBRC = 0.
 334   CV_PATH = LS_FILE_TABLE-FILENAME.
 335 
 336 ENDFORM.
 337 
 338 FORM FRM_READ_EXCEL TABLES L_TAB
 339 USING PV_FILE TYPE RLGRAP-FILENAME
 340 LV_I_BEGIN_COL TYPE I
 341 LV_I_BEGIN_ROW TYPE I
 342 LV_I_END_COL TYPE I
 343 LV_I_END_ROW TYPE I
 344 CHANGING L_WA TYPE ANY.
 345 
 346 * DATA: lt_excel TYPE TABLE OF zsalsmex_tabline WITH HEADER LINE.
 347 
 348   CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
 349     EXPORTING
 350       FILENAME                = PV_FILE "文件路径
 351       I_BEGIN_COL             = LV_I_BEGIN_COL "开始列
 352       I_BEGIN_ROW             = LV_I_BEGIN_ROW "开始行
 353       I_END_COL               = LV_I_END_COL "结束列
 354       I_END_ROW               = LV_I_END_ROW "结束行
 355     TABLES
 356       INTERN                  = L_TAB
 357     EXCEPTIONS
 358       INCONSISTENT_PARAMETERS = 1
 359       UPLOAD_OLE              = 2
 360       OTHERS                  = 3.
 361   IF SY-SUBRC <> 0.
 362     MESSAGE S001(00) WITH '读取 EXCEL 文件失败' DISPLAY LIKE 'E'.
 363     STOP.
 364   ENDIF.
 365 
 366 ENDFORM.
 367 
 368 *&---------------------------------------------------------------------*
 369 *& Form FRM_CHECK_DATA
 370 *&---------------------------------------------------------------------*
 371 *& text
 372 *&---------------------------------------------------------------------*
 373 *&      --> GT_ITAB[]
 374 *&---------------------------------------------------------------------*
 375 FORM FRM_CHECK_DATA TABLES PT_ITAB STRUCTURE GS_ITAB.
 376 
 377   IF PT_ITAB[] IS NOT INITIAL.
 378 
 379     LOOP AT PT_ITAB ASSIGNING <FS_ITAB> WHERE ZTYPE <> 'S'.
 380 
 381       IF <FS_ITAB> IS INITIAL.
 382         DELETE PT_ITAB[].
 383       ELSE.
 384         "数据校验
 385         PERFORM FRM_CHECK_DATA_ITEM CHANGING <FS_ITAB>.
 386         APPEND <FS_ITAB>-PSPID TO GT_PSPID.
 387       ENDIF.
 388 
 389     ENDLOOP.
 390 
 391     SORT GT_PSPID BY PSPID.
 392     DELETE ADJACENT DUPLICATES FROM GT_PSPID COMPARING PSPID.
 393 
 394   ENDIF.
 395 
 396 ENDFORM.
 397 
 398 *&---------------------------------------------------------------------*
 399 *& Form FRM_CHECK_DATA_ITEM
 400 *&---------------------------------------------------------------------*
 401 *& text
 402 *&---------------------------------------------------------------------*
 403 *&      <-- <FS_ITAB>
 404 *&---------------------------------------------------------------------*
 405 FORM FRM_CHECK_DATA_ITEM CHANGING PS_ITAB STRUCTURE GS_ITAB.
 406 
 407   CLEAR:PS_ITAB-ZCHECK,PS_ITAB-MESSAGE.
 408 
 409   IF PS_ITAB-PSPID IS INITIAL.
 410     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }项目ID必输;|.
 411   ELSE.
 412 
 413     CLEAR GV_PSPNR.
 414     PERFORM FRM_TRANS_IPROJ USING PS_ITAB-PSPID
 415                             CHANGING GV_PSPNR
 416                                      GV_SUBRC.
 417     IF GV_SUBRC = 0.
 418 
 419       SELECT SINGLE PSPID
 420       FROM PROJ INTO @DATA(LV_PSPID)
 421       WHERE PSPNR = @GV_PSPNR.
 422       IF SY-SUBRC = 0.
 423         PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }项目ID已存在,不能重复创建;|.
 424       ENDIF.
 425 
 426     ENDIF.
 427 
 428   ENDIF.
 429 
 430   IF PS_ITAB-POST1 IS INITIAL.
 431     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }项目描述必输;|.
 432   ENDIF.
 433 
 434   IF PS_ITAB-WERKS IS INITIAL.
 435     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }工厂必输;|.
 436   ENDIF.
 437 
 438 *  IF PS_ITAB-PGSBR IS INITIAL.
 439 *    PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }业务范围必输;|.
 440 *  ENDIF.
 441 
 442   IF PS_ITAB-PROFL IS INITIAL.
 443     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }项目参数文件必输;|.
 444   ENDIF.
 445 
 446   IF PS_ITAB-POSID IS INITIAL.
 447     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }WBS行项目中WBS编码必输;|.
 448   ENDIF.
 449 
 450   IF PS_ITAB-STUFE IS INITIAL.
 451     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }上级WBS编码必输;|.
 452   ELSE.
 453     IF PS_ITAB-STUFE <> '1' AND PS_ITAB-UP_WBS IS INITIAL.
 454       PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }非首层WBS行项目上层WBS编码必输;|.
 455     ENDIF.
 456   ENDIF.
 457 
 458   IF PS_ITAB-WVBUKR IS INITIAL.
 459     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }WBS行项目中公司代码必输;|.
 460   ENDIF.
 461 
 462   IF PS_ITAB-WWERKS IS INITIAL.
 463     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }WBS行项目中工厂必输;|.
 464   ENDIF.
 465 
 466 *  IF PS_ITAB-PRART IS INITIAL.
 467 *    PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }WBS行项目中项目类型必输;|.
 468 *  ENDIF.
 469 
 470   IF PS_ITAB-VERNR IS INITIAL.
 471     PS_ITAB-MESSAGE = |{ PS_ITAB-MESSAGE }项目负责人必输;|.
 472   ENDIF.
 473 
 474   IF PS_ITAB-MESSAGE IS INITIAL.
 475     PS_ITAB-ZCHECK = ICON_LED_GREEN.
 476   ELSE.
 477     PS_ITAB-ZCHECK = ICON_LED_RED.
 478   ENDIF.
 479 
 480 ENDFORM.
 481 
 482 *定义一个实现类
 483 CLASS LCL_EVENT_RECEIVER DEFINITION.
 484   PUBLIC SECTION.
 485     METHODS HANDLE_MODIFY FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID
 486       IMPORTING E_MODIFIED ET_GOOD_CELLS.
 487 ENDCLASS.
 488 
 489 *&---------------------------------------------------------------------*
 490 *& Form FRM_BUILD_FIELD
 491 *&---------------------------------------------------------------------*
 492 *& text
 493 *&---------------------------------------------------------------------*
 494 *&      <-- GT_FIELDCAT
 495 *&---------------------------------------------------------------------*
 496 FORM FRM_BUILD_FIELD CHANGING VALUE(OT_FIELDCAT) TYPE LVC_T_FCAT.
 497   DATA: L_POS       TYPE I,
 498         LS_FIELDCAT TYPE LVC_S_FCAT.
 499   DEFINE ALV_APPEND_FIELD.
 500     CLEAR LS_FIELDCAT.
 501     LS_FIELDCAT-COL_POS  = L_POS.
 502     LS_FIELDCAT-FIELDNAME  = &1.
 503     LS_FIELDCAT-REPTEXT = &2.
 504     LS_FIELDCAT-SCRTEXT_L = &2.
 505     LS_FIELDCAT-SCRTEXT_M = &2.
 506     LS_FIELDCAT-SCRTEXT_S = &2.
 507     LS_FIELDCAT-KEY = &3.
 508     LS_FIELDCAT-REF_TABLE = &4.
 509     LS_FIELDCAT-REF_FIELD = &5.
 510     LS_FIELDCAT-HOTSPOT = &6.
 511     LS_FIELDCAT-EDIT = &7.
 512 
 513     APPEND LS_FIELDCAT TO OT_FIELDCAT.
 514     L_POS = L_POS + 1.
 515   END-OF-DEFINITION.
 516 
 517   REFRESH OT_FIELDCAT.
 518   L_POS = 1.
 519 
 520   ALV_APPEND_FIELD 'ZCHECK          '       '运行结果               ' '' ''     ''      ''   ''.
 521   ALV_APPEND_FIELD 'MESSAGE         '       '消息文本               ' '' ''     ''      ''   ''.
 522   ALV_APPEND_FIELD 'PSPID           '       '项目ID                 ' '' 'PROJ' 'PSPID' '' ''.
 523   ALV_APPEND_FIELD 'POST1           '       '项目描述               ' '' 'PROJ' 'PST1' '' ''.
 524   ALV_APPEND_FIELD 'VBUKR           '       '公司代码               ' '' '' '' '' ''.
 525   ALV_APPEND_FIELD 'WERKS           '       '工厂代码               ' '' '' '' '' ''.
 526   ALV_APPEND_FIELD 'PGSBR           '       '业务范围编码           ' '' '' '' '' ''.
 527   ALV_APPEND_FIELD 'PRCTR           '       '利润中心编码           ' '' '' '' '' ''.
 528   ALV_APPEND_FIELD 'PROFL           '       '项目参数文件           ' '' '' '' '' ''.
 529   ALV_APPEND_FIELD 'POSID           '       'WBS编码                ' '' 'PRPS' 'POSID' '' ''.
 530   ALV_APPEND_FIELD 'POST2           '       'WBS描述                ' '' 'PRPS' 'POST1' '' ''.
 531   ALV_APPEND_FIELD 'STUFE           '       'WBS层级                ' '' '' '' '' ''.
 532   ALV_APPEND_FIELD 'UP_WBS          '       '上级WBS编码            ' '' 'PRPS' 'POSID' '' ''.
 533   ALV_APPEND_FIELD 'UP_WBS_POST1    '       '上级WBS描述            ' '' 'PRPS' 'POST1' '' ''.
 534   ALV_APPEND_FIELD 'WVBUKR          '       '公司代码               ' '' '' '' '' ''.
 535   ALV_APPEND_FIELD 'WWERKS          '       '工厂代码               ' '' '' '' '' ''.
 536   ALV_APPEND_FIELD 'WPGSBR          '       '业务范围编码           ' '' '' '' '' ''.
 537   ALV_APPEND_FIELD 'FUNC_AREA       '       '功能范围编码           ' '' '' '' '' ''.
 538   ALV_APPEND_FIELD 'WPRCTR          '       '利润中心编码           ' '' '' '' '' ''.
 539   ALV_APPEND_FIELD 'WFKSTL          '       '成本中心编码           ' '' '' '' '' ''.
 540   ALV_APPEND_FIELD 'PRART           '       '项目类型               ' '' '' '' '' ''.
 541   ALV_APPEND_FIELD 'ZZTYPE          '       '项目类型               ' '' '' '' '' ''.
 542   ALV_APPEND_FIELD 'ZZFUND_FILE     '       '资金管理文件编码       ' '' '' '' '' ''.
 543   ALV_APPEND_FIELD 'ZZFUND_VERSION  '       '版本编码               ' '' '' '' '' ''.
 544   ALV_APPEND_FIELD 'ZZSIGN_RESEARCH '       '是否为有收入的科研项目 ' '' '' '' '' ''.
 545   ALV_APPEND_FIELD 'PSTRT           '       '项目计划开始日期       ' '' '' '' '' ''.
 546   ALV_APPEND_FIELD 'PENDE           '       '项目计划完成日期       ' '' '' '' '' ''.
 547   ALV_APPEND_FIELD 'VERNR           '       'BU项目经理             ' '' '' '' '' ''.
 548   ALV_APPEND_FIELD 'ZZXSFR          '       '项目销售负责人         ' '' '' '' '' ''.
 549   ALV_APPEND_FIELD 'UP_WBS1         '       '上级WBS编码            ' '' 'PRPS' 'POSID' '' ''.
 550   ALV_APPEND_FIELD 'VORNR           '       '活动编码               ' '' '' '' '' ''.
 551   ALV_APPEND_FIELD 'LTXA1           '       '工序短文本             ' '' '' '' '' ''.
 552   ALV_APPEND_FIELD 'NTANF           '       '活动计划开始日期       ' '' '' '' '' ''.
 553   ALV_APPEND_FIELD 'NTEND           '       '活动计划完成日期       ' '' '' '' '' ''.
 554   ALV_APPEND_FIELD 'USR00           '       '任务负责人             ' '' '' '' '' ''.
 555   ALV_APPEND_FIELD 'COFRM           '       '报工标识               ' '' '' '' '' ''.
 556 
 557 ENDFORM.
 558 
 559 *&---------------------------------------------------------------------*
 560 *& Form FRM_BUILD_LAYOUT
 561 *&---------------------------------------------------------------------*
 562 *& text
 563 *&---------------------------------------------------------------------*
 564 *&      <-- GS_LAYOUT
 565 *&---------------------------------------------------------------------*
 566 FORM FRM_BUILD_LAYOUT CHANGING VALUE(OS_LAYOUT) TYPE LVC_S_LAYO.
 567   CLEAR OS_LAYOUT.
 568   OS_LAYOUT-ZEBRA = 'X'.       "斑马线
 569   OS_LAYOUT-CWIDTH_OPT = 'X'.  "自动调整列宽
 570   OS_LAYOUT-BOX_FNAME = 'SEL'. "选择列
 571 ENDFORM.
 572 
 573 *&---------------------------------------------------------------------*
 574 *& Form FRM_DISPLAY_DATA_ALV
 575 *&---------------------------------------------------------------------*
 576 *& text
 577 *&---------------------------------------------------------------------*
 578 *&      --> GT_ITAB[]
 579 *&      <-- GT_FIELDCAT
 580 *&      <-- GS_LAYOUT
 581 *&      <-- GT_EVENT
 582 *&      <-- GS_SETTING
 583 *&---------------------------------------------------------------------*
 584 FORM FRM_DISPLAY_DATA_ALV TABLES PT_OTAB TYPE STANDARD TABLE
 585                           CHANGING PT_FIELDCAT TYPE LVC_T_FCAT
 586                                    PS_LAYOUT   TYPE LVC_S_LAYO
 587                                    PT_EVENTS   TYPE SLIS_T_EVENT
 588                                    PS_SETTING  TYPE LVC_S_GLAY.
 589 
 590   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 591     EXPORTING
 592       I_CALLBACK_PROGRAM       = SY-REPID
 593       I_CALLBACK_USER_COMMAND  = 'FRM_USER_COMMAND'
 594       I_CALLBACK_PF_STATUS_SET = 'FRM_SET_PF_STATUS'
 595       IS_LAYOUT_LVC            = PS_LAYOUT
 596       IT_FIELDCAT_LVC          = PT_FIELDCAT  "传入FIELDCAT
 597       IT_EVENTS                = PT_EVENTS
 598       I_GRID_SETTINGS          = PS_SETTING
 599       I_SAVE                   = 'A'         "STANDARD AND USER-SPECIFIC SAVING
 600     TABLES
 601       T_OUTTAB                 = PT_OTAB[]    "传入输出内表
 602     EXCEPTIONS
 603       PROGRAM_ERROR            = 1
 604       OTHERS                   = 2.
 605   IF SY-SUBRC NE 0.
 606     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
 607             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 608   ENDIF.
 609 
 610 ENDFORM.
 611 
 612 *&---------------------------------------------------------------------*
 613 *& Form FRM_USER_COMMAND
 614 *&---------------------------------------------------------------------*
 615 *& text
 616 *&---------------------------------------------------------------------*
 617 *& -->  p1        text
 618 *& <--  p2        text
 619 *&---------------------------------------------------------------------*
 620 FORM FRM_USER_COMMAND USING PV_UCOMM LIKE SY-UCOMM
 621                             PS_SELFIELD TYPE SLIS_SELFIELD.
 622 
 623   "刷新"ALV输出表"数据
 624   DATA: LO_GRID TYPE REF TO CL_GUI_ALV_GRID.
 625   CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' "获取ALV对象的函数
 626     IMPORTING
 627       E_GRID = LO_GRID.
 628   CALL METHOD LO_GRID->CHECK_CHANGED_DATA.
 629 
 630   "用户触发功能码响应逻辑
 631   CASE PV_UCOMM.
 632     WHEN '&IC1'.
 633     WHEN 'CREATE'. "执行导入
 634       "数据校验
 635       PERFORM FRM_CHECK_DATA TABLES GT_ITAB[].
 636       IF LINE_EXISTS( GT_ITAB[ ZCHECK = ICON_LED_RED ] ).
 637         MESSAGE '存在未通过操作数据!按钮无法启用!' TYPE 'S' DISPLAY LIKE 'E'.
 638       ELSE.
 639         PERFORM FRM_INTO_CREATE TABLES GT_ITAB[].
 640       ENDIF.
 641   ENDCASE.
 642 
 643   "获取ALV变化过后的布局参数
 644   CALL METHOD LO_GRID->GET_FRONTEND_LAYOUT
 645     IMPORTING
 646       ES_LAYOUT = GS_LAYOUT.
 647   "重新回写自适应宽度
 648   GS_LAYOUT-CWIDTH_OPT = 'X'.
 649   CALL METHOD LO_GRID->SET_FRONTEND_LAYOUT
 650     EXPORTING
 651       IS_LAYOUT = GS_LAYOUT.
 652   "稳定刷新ALV
 653   DATA:STBL TYPE LVC_S_STBL.
 654   STBL-ROW = 'X'." 基于行的稳定刷新
 655   STBL-COL = 'X'." 基于列稳定刷新
 656   CALL METHOD LO_GRID->REFRESH_TABLE_DISPLAY
 657     EXPORTING
 658       IS_STABLE = STBL.
 659 ENDFORM.                    "FRM_USER_COMMAND
 660 
 661 *&---------------------------------------------------------------------*
 662 *&
 663 *&---------------------------------------------------------------------*
 664 *      实现类方法
 665 *----------------------------------------------------------------------*
 666 CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
 667   METHOD HANDLE_MODIFY.
 668     LOOP AT ET_GOOD_CELLS INTO DATA(WA_MOD).
 669       "MOD_DATA-ROW_ID ——修改值所属的行号     MOD_DATA-FIELDNAME——修改值所属的字段名     MOD_DATA-VALUE——修改后的值
 670       READ TABLE GT_ITAB ASSIGNING <FS_ITAB> INDEX WA_MOD-ROW_ID.
 671       IF SY-SUBRC = 0.
 672         PERFORM FRM_CHECK_DATA_ITEM CHANGING <FS_ITAB>.
 673       ENDIF.
 674     ENDLOOP.
 675 
 676     IF E_MODIFIED = 'X'.
 677       "获取ALV变化过后的布局参数
 678       CALL METHOD GO_GRID->GET_FRONTEND_LAYOUT
 679         IMPORTING
 680           ES_LAYOUT = GS_LAYOUT.
 681       "重新回写自适应宽度
 682       GS_LAYOUT-CWIDTH_OPT = 'X'.
 683       CALL METHOD GO_GRID->SET_FRONTEND_LAYOUT
 684         EXPORTING
 685           IS_LAYOUT = GS_LAYOUT.
 686 
 687       CALL METHOD GO_GRID->REFRESH_TABLE_DISPLAY.
 688     ENDIF.
 689   ENDMETHOD.
 690 ENDCLASS.
 691 
 692 *&---------------------------------------------------------------------*
 693 *& Form FRM_BUILD_LAYOUT
 694 *&---------------------------------------------------------------------*
 695 *& text
 696 *&---------------------------------------------------------------------*
 697 FORM FRM_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
 698   SET PF-STATUS 'STANDARD' EXCLUDING RT_EXTAB."从标准拷出来并修改的STATUS
 699 ENDFORM.
 700 
 701 *&---------------------------------------------------------------------*
 702 *&      --> GS_PROJ_PSPID
 703 *&      <-- LV_PSPNR
 704 *&---------------------------------------------------------------------*
 705 FORM FRM_TRANS_IPROJ  USING LV_POSID CHANGING CV_POSID
 706                                               CV_SUBRC.
 707   CV_SUBRC = 0.
 708 
 709   CALL FUNCTION 'CONVERSION_EXIT_KONPD_INPUT'
 710     EXPORTING
 711       INPUT     = LV_POSID
 712     IMPORTING
 713       OUTPUT    = CV_POSID
 714 *     PROJWA    =
 715     EXCEPTIONS
 716       NOT_FOUND = 1
 717       OTHERS    = 2.
 718   IF SY-SUBRC <> 0.
 719 * Implement suitable error handling here
 720     CV_SUBRC = SY-SUBRC.
 721   ENDIF.
 722 
 723 ENDFORM.
 724 
 725 *&---------------------------------------------------------------------*
 726 *& Form FRM_INTO_CREATE
 727 *&---------------------------------------------------------------------*
 728 *& text
 729 *&---------------------------------------------------------------------*
 730 *&      --> GT_ITAB[]
 731 *&---------------------------------------------------------------------*
 732 FORM FRM_INTO_CREATE TABLES PT_ITAB STRUCTURE GS_ITAB.
 733 
 734   DATA:LT_ITAB TYPE TABLE OF TY_ITAB.
 735 
 736   SORT PT_ITAB BY PSPID.
 737   LOOP AT GT_PSPID.
 738 
 739     CLEAR GV_TABIX.
 740     READ TABLE PT_ITAB TRANSPORTING NO FIELDS WITH KEY PSPID = GT_PSPID-PSPID
 741                                                        BINARY SEARCH.
 742     IF SY-SUBRC = 0.
 743       GV_TABIX = SY-TABIX.
 744 
 745       REFRESH LT_ITAB.
 746       LOOP AT PT_ITAB INTO GS_ITAB FROM GV_TABIX.
 747 
 748         IF GS_ITAB-PSPID <> GT_PSPID-PSPID.
 749           EXIT.
 750         ENDIF.
 751 
 752         APPEND GS_ITAB TO LT_ITAB.
 753 
 754       ENDLOOP.
 755 
 756       IF LT_ITAB[] IS NOT INITIAL.
 757         PERFORM FRM_CREATE_DATA TABLES LT_ITAB[].
 758       ENDIF.
 759 
 760     ENDIF.
 761 
 762   ENDLOOP.
 763 
 764 ENDFORM.
 765 
 766 *&---------------------------------------------------------------------*
 767 *& Form FRM_CREATE_DATA
 768 *&---------------------------------------------------------------------*
 769 *& text
 770 *&---------------------------------------------------------------------*
 771 *&      <-- <FS_ITAB>
 772 *&---------------------------------------------------------------------*
 773 FORM FRM_CREATE_DATA TABLES PT_ITAB STRUCTURE GS_ITAB.
 774 
 775   READ TABLE PT_ITAB INTO GS_ITAB INDEX 1.
 776   IF SY-SUBRC = 0.
 777 
 778     "创建项目定义
 779     PERFORM FRM_CREATE_DATA_XMDY USING GS_ITAB
 780                                  CHANGING GV_ZTYPE
 781                                           GV_MSG
 782                                           GV_ZCHECK.
 783 
 784     IF GV_ZTYPE NE 'E'.
 785 
 786       "创建WBS元素
 787       PERFORM FRM_WBS_PROCESS TABLES PT_ITAB[]
 788                               CHANGING GV_ZTYPE
 789                                        GV_MSG
 790                                        GV_ZCHECK.
 791 
 792     ENDIF.
 793 
 794     CLEAR GV_TABIX.
 795     READ TABLE GT_ITAB TRANSPORTING NO FIELDS WITH KEY PSPID = GS_ITAB-PSPID
 796                                                        BINARY SEARCH.
 797     IF SY-SUBRC = 0.
 798 
 799       GV_TABIX = SY-TABIX.
 800 
 801       LOOP AT GT_ITAB ASSIGNING <FS_ITAB> FROM GV_TABIX.
 802         <FS_ITAB>-ZTYPE = GV_ZTYPE.
 803         <FS_ITAB>-MESSAGE = GV_MSG.
 804         <FS_ITAB>-ZCHECK = GV_ZCHECK.
 805       ENDLOOP.
 806 
 807     ENDIF.
 808 
 809     CLEAR GS_ITAB.
 810   ENDIF.
 811 
 812 ENDFORM.
 813 
 814 *&---------------------------------------------------------------------*
 815 *& Form FRM_CREATE_DATA_XMDY
 816 *&---------------------------------------------------------------------*
 817 *& text
 818 *&---------------------------------------------------------------------*
 819 *&      --> GS_ITAB
 820 *&      --> GV_ZTYPE
 821 *&      --> GV_MSG
 822 *&      --> GV_ZCHECK
 823 *&---------------------------------------------------------------------*
 824 FORM FRM_CREATE_DATA_XMDY USING PS_ITAB STRUCTURE GS_ITAB
 825                           CHANGING PV_ZTYPE
 826                                    PV_MSG
 827                                    PV_ZCHECK.
 828 
 829   CLEAR:GS_PROJECT,
 830         GS_RETURN,
 831         GT_E_MSG,
 832         PV_ZTYPE,
 833         PV_MSG.
 834   REFRESH:GT_E_MSG.
 835 
 836   GS_PROJECT-PROJECT_DEFINITION = PS_ITAB-PSPID.
 837   GS_PROJECT-DESCRIPTION = PS_ITAB-POST1.
 838   GS_PROJECT-PROJECT_PROFILE = PS_ITAB-PROFL.
 839   GS_PROJECT-FUNC_AREA = PS_ITAB-FUNC_AREA."功能范围
 840   GS_PROJECT-BUS_AREA = PS_ITAB-PGSBR."业务范围
 841   GS_PROJECT-COMP_CODE = PS_ITAB-VBUKR."公司
 842   GS_PROJECT-PLANT = PS_ITAB-WERKS."工厂
 843   GS_PROJECT-START = PS_ITAB-PSTRT."项目计划开始日期
 844   GS_PROJECT-FINISH = PS_ITAB-PENDE."项目计划完成日期
 845   GS_PROJECT-RESPONSIBLE_NO = PS_ITAB-VERNR."负责人编号(项目经理)
 846   GS_PROJECT-PROFIT_CTR = |{ PS_ITAB-PRCTR ALPHA = IN }|."利润中心
 847 
 848   WAIT UP TO '0.5' SECONDS.
 849   CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
 850   CALL FUNCTION 'BAPI_PROJECTDEF_CREATE'
 851     EXPORTING
 852       PROJECT_DEFINITION_STRU = GS_PROJECT
 853     IMPORTING
 854       RETURN                  = GS_RETURN
 855     TABLES
 856       E_MESSAGE_TABLE         = GT_E_MSG.
 857 
 858   IF GS_RETURN-TYPE EQ 'E'.
 859     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
 860     CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.
 861     CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
 862       EXPORTING
 863         I_PRECOMMIT_OK = 'Y'.
 864 
 865     PV_ZTYPE = 'E'.
 866     PV_ZCHECK = ICON_LED_RED.
 867     LOOP AT GT_E_MSG.
 868       CONCATENATE GT_E_MSG-MESSAGE_TEXT GV_MSG INTO GV_MSG SEPARATED BY '/'.
 869     ENDLOOP.
 870 
 871   ELSE.
 872     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 873       EXPORTING
 874         WAIT = 'X'.
 875 
 876     PV_ZTYPE = 'S'.
 877     PV_ZCHECK = ICON_LED_GREEN.
 878     CONCATENATE '项目定义' PS_ITAB-PSPID '创建成功' INTO GV_MSG.
 879 
 880     WAIT UP TO '0.5' SECONDS.
 881     SELECT SINGLE *
 882        INTO @DATA(LS_PROJ)
 883        FROM PROJ
 884        WHERE PSPID = @PS_ITAB-PSPID.
 885     UPDATE PROJ
 886     SET ZZTYPE = PS_ITAB-ZZTYPE
 887         ZZFUND_FILE = PS_ITAB-ZZFUND_FILE
 888         ZZFUND_VERSION = PS_ITAB-ZZFUND_VERSION
 889         ZZSIGN_RESEARCH = PS_ITAB-ZZSIGN_RESEARCH
 890     WHERE PSPNR = LS_PROJ-PSPNR.
 891     IF SY-SUBRC = 0.
 892       COMMIT WORK AND WAIT.
 893       CONCATENATE GV_MSG '更新定义字段成功!' INTO GV_MSG SEPARATED BY '/'.
 894     ELSE.
 895       ROLLBACK WORK.
 896       CONCATENATE GV_MSG '更新定义字段失败!' INTO GV_MSG SEPARATED BY '/'.
 897     ENDIF.
 898 
 899   ENDIF.
 900 
 901 ENDFORM.
 902 
 903 *&---------------------------------------------------------------------*
 904 *& Form FRM_WBS_PROCESS
 905 *&---------------------------------------------------------------------*
 906 *& text
 907 *&---------------------------------------------------------------------*
 908 *&      --> PT_ITAB[]
 909 *&      --> GV_ZTYPE
 910 *&      --> GV_MSG
 911 *&      --> GV_ZCHECK
 912 *&---------------------------------------------------------------------*
 913 FORM FRM_WBS_PROCESS TABLES PT_ITAB STRUCTURE GS_ITAB
 914                      CHANGING PV_ZTYPE
 915                               PV_MSG
 916                               PV_ZCHECK.
 917 
 918   CLEAR:GS_PRODEF,
 919         GS_PRODEF_UP,
 920         GS_RETURN,
 921         GT_METHOD,
 922         GT_WBSELE,
 923         GT_WBSELE_UP,
 924         GT_WBSHI_TAB,
 925         GT_MSGTAB,
 926         GV_NUM,
 927         GV_TABIX,
 928         GV_LINES,
 929         GT_UPSTUFE,
 930         GV_STUFE,
 931         GV_POSID,
 932         GV_WBS,
 933         GV_WBS_UP,
 934         GV_WBS_LEFT.
 935 
 936   REFRESH:GT_METHOD,
 937           GT_WBSELE,
 938           GT_WBSELE_UP,
 939           GT_WBSHI_TAB,
 940           GT_MSGTAB,
 941           GT_UPSTUFE.
 942 
 943   LOOP AT PT_ITAB INTO GS_ITAB.
 944 
 945     IF SY-TABIX = 1.
 946 
 947       GS_PRODEF-PROJECT_DEFINITION = GS_ITAB-PSPID. "项目定义
 948       GS_PRODEF-RESPONSIBLE_NO = GS_ITAB-VERNR. "负责人编号(项目经理)
 949       GS_PRODEF_UP-PROJECT_DEFINITION = 'X'. "项目定义.
 950       GS_PRODEF_UP-RESPONSIBLE_NO = 'X'. "负责人编号(项目经理)
 951 
 952     ENDIF.
 953 
 954     "wbs元素define
 955     GT_WBSELE-WBS_ELEMENT = GS_ITAB-POSID. "WBS元素
 956     GT_WBSELE-PROJECT_DEFINITION = GS_ITAB-PSPID. "项目ID
 957     GT_WBSELE-DESCRIPTION = GS_ITAB-POST2. "WBS元素描述
 958     GT_WBSELE-COMP_CODE = GS_ITAB-WVBUKR. "公司代码
 959     GT_WBSELE-BUS_AREA = GS_ITAB-WPGSBR.  "业务范围编码
 960     GT_WBSELE-PLANT = GS_ITAB-WWERKS.     "工厂代码
 961     GT_WBSELE-PROFIT_CTR = |{ GS_ITAB-WPRCTR ALPHA = IN }|. "利润中心编码
 962     GT_WBSELE-FUNC_AREA = GS_ITAB-FUNC_AREA.  "功能范围编码
 963     GT_WBSELE-PROJ_TYPE = GS_ITAB-PRART.    "项目类型
 964     GT_WBSELE-WBS_BASIC_START_DATE = GS_ITAB-PSTRT.  "基本开始日期
 965     GT_WBSELE-WBS_BASIC_FINISH_DATE = GS_ITAB-PENDE.  "基本结束日期
 966     GT_WBSELE-WBS_PLANNING_ELEMENT = 'X'.           "计划元素 默认为X
 967     GT_WBSELE-RESPSBL_CCTR = GS_ITAB-WFKSTL.         "负责成本中心
 968     GT_WBSELE-RESPONSIBLE_NO = GS_ITAB-VERNR.       "负责人编号(项目经理)
 969 
 970     "首层WBS元的科目分配元素PRPS-BELKZ需为空
 971     GV_LINES = STRLEN( GS_ITAB-POSID ) - 2.
 972     IF GS_ITAB-POSID+GV_LINES(2) <> '-B'.
 973       GT_WBSELE-WBS_ACCOUNT_ASSIGNMENT_ELEMENT = 'X'. "标志:科目分配元素
 974     ENDIF.
 975     GT_WBSELE-WBS_BILLING_ELEMENT = 'X'.  "标识符: 开票元素
 976 
 977     APPEND GT_WBSELE.
 978     CLEAR GT_WBSELE.
 979 
 980     "add end
 981     GV_NUM = GV_NUM + 1.
 982     IF GV_NUM = 1.
 983       GV_TABIX = SY-TABIX.
 984       MOVE: GS_ITAB-STUFE TO GT_UPSTUFE-STUFE,
 985             GS_ITAB-POSID TO GT_UPSTUFE-POSID.
 986       APPEND GT_UPSTUFE.
 987     ELSE.
 988       GV_TABIX = GV_TABIX + 1.
 989       DESCRIBE TABLE GT_UPSTUFE LINES GV_LINES.
 990       READ TABLE GT_UPSTUFE INDEX GV_LINES.
 991       GV_STUFE = GT_UPSTUFE-STUFE .
 992       GV_POSID = GT_UPSTUFE-POSID .
 993       READ TABLE GT_UPSTUFE WITH KEY STUFE = GS_ITAB-STUFE.
 994       IF SY-SUBRC NE 0.
 995         GV_STUFE = GV_STUFE + 1.
 996         IF GV_NUM = '2'.
 997           MOVE: GV_POSID TO GT_WBSHI_TAB-WBS_ELEMENT,
 998                 GS_ITAB-POSID TO GT_WBSHI_TAB-DOWN.
 999           APPEND GT_WBSHI_TAB.
1000           CLEAR GT_WBSHI_TAB.
1001         ELSE.
1002           READ TABLE GT_WBSHI_TAB INDEX GV_LINES.
1003           MOVE: GS_ITAB-POSID TO GT_WBSHI_TAB-DOWN.
1004           MODIFY GT_WBSHI_TAB INDEX GV_LINES.
1005           CLEAR GT_WBSHI_TAB.
1006         ENDIF.
1007 
1008         MOVE: GS_ITAB-POSID TO GT_WBSHI_TAB-WBS_ELEMENT,
1009               GV_POSID TO GT_WBSHI_TAB-UP.
1010         APPEND GT_WBSHI_TAB.
1011         CLEAR GT_WBSHI_TAB.
1012       ELSE.
1013         IF GS_ITAB-STUFE NE GV_STUFE.
1014           IF GS_ITAB-STUFE LE GV_STUFE.
1015             LOOP AT GT_UPSTUFE WHERE STUFE EQ GS_ITAB-STUFE.
1016               MOVE GT_UPSTUFE-POSID TO GV_WBS.
1017             ENDLOOP.
1018             READ TABLE GT_WBSHI_TAB WITH KEY WBS_ELEMENT = GV_WBS.
1019             MOVE: GT_WBSHI_TAB-UP TO GV_WBS_UP,
1020                   GT_WBSHI_TAB-WBS_ELEMENT TO GV_WBS_LEFT,
1021                   GS_ITAB-POSID TO GT_WBSHI_TAB-RIGHT.
1022             MODIFY GT_WBSHI_TAB INDEX SY-TABIX.
1023             CLEAR:GT_WBSHI_TAB.
1024 
1025             MOVE: GS_ITAB-POSID TO GT_WBSHI_TAB-WBS_ELEMENT,
1026                   GV_WBS_UP TO GT_WBSHI_TAB-UP,
1027                   GV_WBS_LEFT TO GT_WBSHI_TAB-LEFT.
1028             APPEND GT_WBSHI_TAB.
1029             CLEAR: GT_WBSHI_TAB,GV_WBS_UP,GV_WBS_LEFT.
1030           ELSE.
1031             READ TABLE GT_WBSHI_TAB INDEX GV_LINES.
1032             MOVE: GT_WBSHI_TAB-WBS_ELEMENT TO GV_WBS_UP,
1033                   GS_ITAB-POSID TO GT_WBSHI_TAB-DOWN.
1034             MODIFY GT_WBSHI_TAB INDEX GV_LINES.
1035             CLEAR:GT_WBSHI_TAB.
1036 
1037             MOVE: GS_ITAB-POSID TO GT_WBSHI_TAB-WBS_ELEMENT,
1038                   GV_WBS_UP TO GT_WBSHI_TAB-UP,
1039                   GV_WBS_LEFT TO GT_WBSHI_TAB-LEFT.
1040             APPEND GT_WBSHI_TAB.
1041             CLEAR: GT_WBSHI_TAB,GV_WBS_UP,GV_WBS_LEFT,GV_WBS.
1042           ENDIF.
1043         ELSE.
1044           READ TABLE GT_WBSHI_TAB INDEX GV_LINES.
1045           MOVE: GS_ITAB-POSID TO GT_WBSHI_TAB-RIGHT,
1046                 GT_WBSHI_TAB-UP TO GV_WBS_UP.
1047           MODIFY GT_WBSHI_TAB INDEX GV_LINES.
1048           CLEAR GT_WBSHI_TAB.
1049 
1050           MOVE: GS_ITAB-POSID TO GT_WBSHI_TAB-WBS_ELEMENT,
1051                 GV_WBS_UP TO GT_WBSHI_TAB-UP,
1052                 GV_POSID TO GT_WBSHI_TAB-LEFT.
1053           APPEND GT_WBSHI_TAB.
1054           CLEAR: GT_WBSHI_TAB,GV_WBS_UP.
1055         ENDIF.
1056       ENDIF.
1057 
1058       MOVE: GS_ITAB-STUFE TO GT_UPSTUFE-STUFE,
1059             GS_ITAB-POSID TO GT_UPSTUFE-POSID.
1060       APPEND GT_UPSTUFE.
1061     ENDIF.
1062 
1063     GT_METHOD-REFNUMBER  = SY-TABIX.
1064     GT_METHOD-OBJECTTYPE = 'WBS-Element'.
1065     GT_METHOD-METHOD     = 'Create'.
1066     GT_METHOD-OBJECTKEY  = GS_ITAB-POSID.
1067     APPEND GT_METHOD.
1068     CLEAR GT_METHOD.
1069 
1070     CLEAR GT_METHOD.
1071     GT_METHOD-OBJECTTYPE = 'WBS-Hierarchy'.
1072     GT_METHOD-METHOD     = 'Create'.
1073     APPEND GT_METHOD.
1074 
1075     CLEAR GT_METHOD.
1076     GT_METHOD-METHOD     = 'SAVE'.
1077     APPEND GT_METHOD.
1078     CLEAR GT_METHOD.
1079 
1080   ENDLOOP.
1081 
1082   WAIT UP TO '0.5' SECONDS.
1083   CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
1084   CALL FUNCTION 'BAPI_PROJECT_MAINTAIN'
1085     EXPORTING
1086       I_PROJECT_DEFINITION     = GS_PRODEF
1087       I_PROJECT_DEFINITION_UPD = GS_PRODEF_UP
1088     IMPORTING
1089       RETURN                   = GS_RETURN
1090     TABLES
1091       I_METHOD_PROJECT         = GT_METHOD
1092       I_WBS_ELEMENT_TABLE      = GT_WBSELE
1093       I_WBS_HIERARCHIE_TABLE   = GT_WBSHI_TAB
1094       E_MESSAGE_TABLE          = GT_MSGTAB.
1095 
1096   DELETE GT_MSGTAB WHERE MESSAGE_NUMBER = '719' OR MESSAGE_NUMBER = '036'.
1097   READ TABLE GT_MSGTAB WITH KEY MESSAGE_TYPE = 'E'.
1098   IF SY-SUBRC EQ 0.
1099     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
1100     CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.
1101     CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
1102       EXPORTING
1103         I_PRECOMMIT_OK = 'Y'.
1104 
1105     PV_ZTYPE = 'E'.
1106     PV_ZCHECK = ICON_LED_RED.
1107     LOOP AT GT_MSGTAB WHERE MESSAGE_TYPE CA 'AE'.
1108       CONCATENATE PV_MSG GT_MSGTAB-MESSAGE_TEXT INTO PV_MSG SEPARATED BY '/'.
1109     ENDLOOP.
1110 
1111   ELSE.
1112     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
1113       EXPORTING
1114         WAIT = 'X'.
1115 
1116     PV_ZTYPE = 'S'.
1117     PV_ZCHECK = ICON_LED_GREEN.
1118     CONCATENATE PV_MSG 'WBS元素创建成功' INTO PV_MSG SEPARATED BY '/'.
1119 
1120   ENDIF.
1121 
1122 ENDFORM.

 

标签:GV,ITAB,GT,GS,PS,CJ20N,创建,ABAP,TYPE
From: https://www.cnblogs.com/TigerMan/p/17212746.html

相关文章

  • lvm分区创建和扩容
    lvm分区创建parted/dev/vdbmklabelgptparted/dev/vdbmkpartprimary1100%pvcreate/dev/vdb1vgcreatevg-data/dev/vdb1lvcreate-l100%VG-nlv-datavg-d......
  • 创建.NET程序Dump的几种姿势
    https://blog.csdn.net/mzl87/article/details/127670331创建.NET程序Dump的几种姿势  Windows平台dotnet-dump(Windows)Windows任务管理器SysInternals-Pro......
  • Series的对象创建
    1.索引从0开始计数: 2.修改索引从1开始计数:  3.自定以索引和数据的对应: ......
  • angular利用FormArray创建动态响应式表单
    FormArray 是 FormGroup 之外的另一个选择,用于管理任意数量的匿名控件。像 FormGroup 实例一样,你也可以往 FormArray 中动态插入和移除控件,并且 FormArray 实例的......
  • SpringCloud-创建服务消费者-Feign方式(附代码下载)
    场景在上面已经实现服务注册中心、服务提供者和以Ribbon方式实现服务消费者的前提下,使用另一种Feign方式实现服务消费者。FeignFeign是一个声明式的伪Http客户端,它使得写......
  • SpringCloud -创建统一的依赖管理
    场景SpringCloud为开发者提供了在分布式系统(配置管理,服务发现,熔断,路由,微代理,控制总线,一次性Token,全居琐,Leader选举,分布式Session,集群状态)中快速构建的工具,使用Spring......
  • platform_device 的创建
    platform_device 的创建主要有两种方式(1)在内核初始化时通过device_node转换为platform_device,这种是最新的实现方式,基于设备树,在内核初始化时将设备树中的节点转化为plat......
  • 3、IOC创建对象的方法
    目录3、IOC创建对象的方法4、Spring配置4.1、别名4.2、Bean的配置4.3、import5、依赖注入5.1、构造器注入5.2、Set方式注入【重点】5.3、扩展方式注入5.4、bean的作用域6、......
  • Python创建虚拟环境
    1、什么是虚拟环境虚拟环境的意义,就如同虚拟机一样,它可以实现不同环境中Python依赖包相互独立,互不干扰。 example:假设我们服务器中有两个项目,都是用到了一个第三方......
  • 为application.yml创建自定义配置并进行自动提示
    第一步:导入依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId></dependency>......