REPORT Z_CO02 NO STANDARD PAGE HEADING.
TABLES: RESB ,AFPO.
PARAMETERS:P_FILE(128) DEFAULT ‘C:\Users\jax\Desktop\新建 Microsoft Excel 工作表.xlsx‘.
SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-001.
PARAMETERS R1 RADIOBUTTON GROUP GR1 DEFAULT ‘X‘.
PARAMETERS R2 RADIOBUTTON GROUP GR1.
PARAMETERS R3 RADIOBUTTON GROUP GR1.
SELECTION-SCREEN END OF BLOCK BK1.
PARAMETERS: NODATA DEFAULT ‘/‘ LOWER CASE NO-DISPLAY. "nodata
DATA: BEGIN OF GT_ZSTYPF OCCURS 0,
RSPOS TYPE RESB-RSPOS,
RSNUM TYPE RESB-RSNUM,
AUFNR TYPE RESB-AUFNR,
MATNR TYPE MARA-MATNR,
MEINS TYPE RESB-MEINS,
POTX1 TYPE RESB-POTX1,
XLOEK TYPE RESB-XLOEK,
BDMNG TYPE RESB-BDMNG,
POSNR TYPE RESB-POSNR,
VORNR TYPE RESB-VORNR,
PLNFL TYPE RESB-PLNFL,
END OF GT_ZSTYPF.
DATA GS_ZSTYPF LIKE LINE OF GT_ZSTYPF.
DATA GT_DATA LIKE GT_ZSTYPF[] WITH HEADER LINE.
DATA GT_DATA1 LIKE GT_ZSTYPF[] WITH HEADER LINE.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE .
PERFORM FRM_INPUT_HELP CHANGING P_FILE.
START-OF-SELECTION.
PERFORM GET_DATA USING P_FILE. "得到数据
PERFORM PRM_CHANGE_BOM .
FORM PRM_CHANGE_BOM .
DATA:GW_ZSTYPF LIKE LINE OF GT_ZSTYPF[].
DATA:LV_RSPOS TYPE RSPOS.
CLEAR:GW_ZSTYPF,LV_RSPOS.
MOVE-CORRESPONDING GT_DATA1[] TO GT_ZSTYPF[].
LOOP AT GT_ZSTYPF INTO GS_ZSTYPF WHERE RSNUM IS NOT INITIAL."修改原有组件
PERFORM prm_add_bom_line USING gs_zstypf.
* PERFORM PRM_CHANGE_BOM_LINE USING GS_ZSTYPF.
* PERFORM prm_delete_bom_line USING gs_zstypf.
IF SY-SUBRC = 0.
MESSAGE ‘修改组件成功!‘ TYPE ‘S‘.
ELSE.
MESSAGE ‘修改组件失败,请重新修改!‘ TYPE ‘E‘.
ENDIF.
ENDLOOP.
WAIT UP TO 1 SECONDS.
ENDFORM. " PRM_CHANGE_BOM
******************
FORM PRM_DELETE_BOM_LINE USING P_POSNR P_AUFNR.
DATA:LV_VALUE TYPE BDCDATA-FVAL.
DATA:LV_FNAME TYPE BDCDATA-FNAM.
REFRESH:MESSTAB,BDCDATA.
CLEAR:LV_VALUE,LV_FNAME.
CONCATENATE ‘RESBD-POSNR(‘ P_POSNR ‘)‘ INTO LV_VALUE.
CONCATENATE ‘RC27X-FLG_SEL(‘ P_POSNR ‘)‘ INTO LV_FNAME.
PERFORM BDC_DYNPRO USING ‘SAPLCOKO1‘ ‘0110‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
‘CAUFVD-AUFNR‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=KPU2‘.
PERFORM BDC_FIELD USING ‘CAUFVD-AUFNR‘
P_AUFNR.
* ‘100000043‘.
PERFORM BDC_FIELD USING ‘R62CLORD-FLG_OVIEW‘
‘X‘.
PERFORM BDC_DYNPRO USING ‘SAPLCOMK‘ ‘0120‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
LV_VALUE.
* ‘RESBD-POSNR(02)‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=DEL‘.
PERFORM BDC_FIELD USING ‘FILTER_BOX‘
‘NO_FIL‘.
PERFORM BDC_FIELD USING ‘SORT_BOX‘
‘ST_STA‘.
PERFORM BDC_FIELD USING LV_FNAME"‘RC27X-FLG_SEL(02)‘
‘X‘.
PERFORM BDC_DYNPRO USING ‘SAPLCOMK‘ ‘0120‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
‘RESBD-MATNR(01)‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=BU‘.
PERFORM BDC_FIELD USING ‘FILTER_BOX‘
‘NO_FIL‘.
PERFORM BDC_FIELD USING ‘SORT_BOX‘
‘ST_STA‘.
CALL TRANSACTION ‘CO02‘ USING BDCDATA
MODE ‘N‘
UPDATE ‘S‘
MESSAGES INTO MESSTAB.
*perform bdc_transaction using ‘CO02‘.
ENDFORM. " PRM_DELETE_BOM_LINE
***************************
FORM PRM_CHANGE_BOM_LINE USING P_GS_ZSTYPF STRUCTURE GS_ZSTYPF.
DATA:LV_VALUE TYPE BDCDATA-FVAL.
DATA:LV_DBMN TYPE BDCDATA-FVAL."数量
DATA:LV_FNAM1 TYPE BDCDATA-FNAM.
DATA:LV_FNAM2 TYPE BDCDATA-FNAM.
DATA:LV_FNAM3 TYPE BDCDATA-FNAM.
REFRESH:MESSTAB,BDCDATA.
CLEAR:LV_VALUE,LV_FNAM1,LV_FNAM2,LV_FNAM3.
CONCATENATE ‘RESBD-MATXT(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_VALUE. "这里需要注意,这样做是为了避开数据重复
CONCATENATE ‘RC27X-FLG_SEL(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM1.
CONCATENATE ‘RESBD-MATNR(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM2.
CONCATENATE ‘RESBD-MENGE(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM3.
PERFORM BDC_DYNPRO USING ‘SAPLCOKO1‘ ‘0110‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
‘CAUFVD-AUFNR‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=KPU2‘.
PERFORM BDC_FIELD USING ‘CAUFVD-AUFNR‘
P_GS_ZSTYPF-AUFNR.
PERFORM BDC_FIELD USING ‘R62CLORD-FLG_OVIEW‘
‘X‘.
PERFORM BDC_DYNPRO USING ‘SAPLCOMK‘ ‘0120‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
LV_VALUE.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=PICK‘.
PERFORM BDC_FIELD USING ‘FILTER_BOX‘
‘NO_FIL‘.
PERFORM BDC_FIELD USING ‘SORT_BOX‘
‘ST_STA‘.
PERFORM BDC_FIELD USING LV_FNAM1
‘X‘.
PERFORM BDC_FIELD USING LV_FNAM2
P_GS_ZSTYPF-MATNR.
MOVE P_GS_ZSTYPF-BDMNG TO LV_DBMN.
CONDENSE LV_DBMN NO-GAPS.
PERFORM BDC_FIELD USING LV_FNAM3
LV_DBMN.
PERFORM BDC_DYNPRO USING ‘SAPLCOMD‘ ‘0110‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=BU‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
‘RESBD-POTX1‘.
PERFORM BDC_FIELD USING ‘RESBD-MATNR‘
P_GS_ZSTYPF-MATNR.
PERFORM BDC_FIELD USING ‘RESBD-POSNR‘
P_GS_ZSTYPF-POSNR.
PERFORM BDC_FIELD USING ‘RESBD-POTX1‘
P_GS_ZSTYPF-POTX1.
PERFORM BDC_FIELD USING ‘RESBD-SANKA‘
‘X‘.
PERFORM BDC_DYNPRO USING ‘SAPLCOMD‘ ‘0110‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=BU‘.
PERFORM BDC_FIELD USING ‘RESBD-SANKA‘
‘X‘.
CALL TRANSACTION ‘CO02‘ USING BDCDATA
MODE ‘N‘
UPDATE ‘S‘
MESSAGES INTO MESSTAB.
ENDFORM. " PRM_CHANGE_BOM_LINE
FORM PRM_ADD_BOM_LINE USING P_GS_ZSTYPF STRUCTURE GS_ZSTYPF.
DATA:LV_VALUE TYPE BDCDATA-FVAL.
DATA:LV_DBMN TYPE BDCDATA-FVAL."数量
DATA:LV_FNAM1 TYPE BDCDATA-FNAM.
DATA:LV_FNAM2 TYPE BDCDATA-FNAM.
DATA:LV_FNAM3 TYPE BDCDATA-FNAM.
DATA:LV_FNAM4 TYPE BDCDATA-FNAM.
DATA:LV_FNAM5 TYPE BDCDATA-FNAM.
DATA:LV_FNAM6 TYPE BDCDATA-FNAM.
REFRESH:MESSTAB,BDCDATA.
CLEAR:LV_VALUE,LV_FNAM1,LV_FNAM2,LV_FNAM3,LV_FNAM4,LV_FNAM5,LV_FNAM6.
CONCATENATE ‘RESBD-MATXT(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_VALUE.
CONCATENATE ‘RESBD-MATNR(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM1.
CONCATENATE ‘RESBD-MENGE(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM2.
CONCATENATE ‘RESBD-EINHEIT(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM3.
CONCATENATE ‘RESBD-POSTP(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM4.
CONCATENATE ‘RESBD-VORNR(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM5.
CONCATENATE ‘RCOLS-APLFL(‘ P_GS_ZSTYPF-RSPOS ‘)‘ INTO LV_FNAM6.
PERFORM BDC_DYNPRO USING ‘SAPLCOKO1‘ ‘0110‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
‘CAUFVD-AUFNR‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=KPU2‘.
PERFORM BDC_FIELD USING ‘CAUFVD-AUFNR‘
P_GS_ZSTYPF-AUFNR.
PERFORM BDC_FIELD USING ‘R62CLORD-FLG_OVIEW‘
‘X‘.
PERFORM BDC_DYNPRO USING ‘SAPLCOMK‘ ‘0120‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
LV_VALUE.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=PICK‘.
PERFORM BDC_FIELD USING ‘FILTER_BOX‘
‘NO_FIL‘.
PERFORM BDC_FIELD USING ‘SORT_BOX‘
‘ST_STA‘.
PERFORM BDC_FIELD USING LV_FNAM1
P_GS_ZSTYPF-MATNR.
MOVE P_GS_ZSTYPF-BDMNG TO LV_DBMN.
CONDENSE LV_DBMN NO-GAPS.
PERFORM BDC_FIELD USING LV_FNAM2
LV_DBMN.
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_OUTPUT‘
EXPORTING
INPUT = P_GS_ZSTYPF-MEINS
LANGUAGE = SY-LANGU
IMPORTING
* LONG_TEXT =
OUTPUT = P_GS_ZSTYPF-MEINS
* SHORT_TEXT =
EXCEPTIONS
UNIT_NOT_FOUND = 1
OTHERS = 2.
PERFORM BDC_FIELD USING LV_FNAM3
P_GS_ZSTYPF-MEINS.
PERFORM BDC_FIELD USING LV_FNAM4
‘L‘.
PERFORM BDC_FIELD USING LV_FNAM5
P_GS_ZSTYPF-VORNR.
PERFORM BDC_FIELD USING LV_FNAM6
P_GS_ZSTYPF-PLNFL.
PERFORM BDC_DYNPRO USING ‘SAPLCOMD‘ ‘0110‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=BU‘.
PERFORM BDC_FIELD USING ‘BDC_CURSOR‘
‘RESBD-POTX1‘.
PERFORM BDC_FIELD USING ‘RESBD-POTX1‘
P_GS_ZSTYPF-POTX1.
PERFORM BDC_FIELD USING ‘RESBD-SANKA‘
‘X‘.
PERFORM BDC_DYNPRO USING ‘SAPLCOMD‘ ‘0110‘.
PERFORM BDC_FIELD USING ‘BDC_OKCODE‘
‘=BU‘.
CALL TRANSACTION ‘CO02‘ USING BDCDATA
MODE ‘N‘
UPDATE ‘S‘
MESSAGES INTO MESSTAB.
ENDFORM. " PRM_ADD_BOM_LINE
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = ‘X‘.
APPEND BDCDATA.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> NODATA.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
FORM FRM_INPUT_HELP CHANGING P_O_FILE.
DATA:
LTD_FILETABLE TYPE FILETABLE,
LTH_FILETABLE TYPE LINE OF FILETABLE,
LW_RC TYPE I,
LV_FILTER TYPE STRING.
LV_FILTER = ‘Excel文件(*.XLS)|*.XLS|Excel文件(*.XLSX)|*.XLSX|‘.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
EXPORTING
* FILE_FILTER = ‘*.*|Excel Files (*.xls)|*‘
FILE_FILTER = LV_FILTER
CHANGING
FILE_TABLE = LTD_FILETABLE
RC = LW_RC
EXCEPTIONS
FILE_OPEN_DIALOG_FAILED = 1
CNTL_ERROR = 2
ERROR_NO_GUI = 3
NOT_SUPPORTED_BY_GUI = 4
OTHERS = 5.
IF SY-SUBRC = 0.
READ TABLE LTD_FILETABLE INTO LTH_FILETABLE INDEX 1.
P_O_FILE = LTH_FILETABLE-FILENAME.
ELSE.
MESSAGE ID SY-MSGID TYPE ‘I‘ NUMBER SY-MSGNO
DISPLAY LIKE ‘E‘
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " FRM_INPUT_HELP
FORM GET_DATA USING P_I_FILE.
DATA: BEGIN OF IT_HEADER OCCURS 0,
COL LIKE ALSMEX_TABLINE-COL,
FIELD(20),
END OF IT_HEADER.
FIELD-SYMBOLS: <FS>.
DATA: L_INTERN TYPE ZALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA: C_ROW TYPE I VALUE 2, "读EXCEL第4行开始
C_COL TYPE I VALUE 1, "读EXCEL第1列开始
L_INDEX TYPE I,
L_MSG(60) TYPE C,
G_MOD TYPE D,
L_ROW(5) TYPE N,
LI_LEN TYPE SY-TABIX,
L_CSTR(4).
CALL FUNCTION ‘ZALSM_EXCEL_TO_INTERNAL_TABLE‘
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = C_COL
I_BEGIN_ROW = C_ROW
I_END_COL = 200
I_END_ROW = 50000
TABLES
INTERN = L_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
SORT L_INTERN BY ROW COL.
L_ROW = C_ROW.
LOOP AT L_INTERN.
IF L_INTERN-ROW = 1.
IT_HEADER-COL = L_INTERN-COL.
TRANSLATE L_INTERN-VALUE TO UPPER CASE.
CONDENSE L_INTERN-VALUE.
IT_HEADER-FIELD = L_INTERN-VALUE.
APPEND IT_HEADER.
ELSE.
MOVE L_INTERN-COL TO L_INDEX.
READ TABLE IT_HEADER WITH KEY COL = L_INDEX.
IF SY-SUBRC = 0.
ASSIGN COMPONENT IT_HEADER-FIELD OF STRUCTURE GT_DATA TO <FS>.
IF SY-SUBRC = 0.
MOVE L_INTERN-VALUE TO <FS>.
ENDIF.
ENDIF.
AT END OF ROW.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = GT_DATA-AUFNR
IMPORTING
OUTPUT = GT_DATA-AUFNR.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = GT_DATA-posnr
IMPORTING
OUTPUT = GT_DATA-posnr.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
INPUT = GT_DATA-VORNR
IMPORTING
OUTPUT = GT_DATA-VORNR.
SELECT SINGLE RSNUM FROM RESB INTO GT_DATA-RSNUM WHERE AUFNR = GT_DATA-aufnr.
SELECT MAX( RSPOS ) FROM resb INTO gt_DATA-rspos WHERE RSNUM = GT_DATA-rsnum.
GT_DATA-RSPOS = GT_DATA-RSPOS + 1 .
IF SY-SUBRC <> 0.
ENDIF.
MOVE-CORRESPONDING GT_DATA TO GT_DATA1.
APPEND GT_DATA1.
CLEAR: GT_DATA1, GT_DATA.
G_MOD = L_ROW MOD 100.
IF G_MOD = 0.
ENDIF.
L_ROW = L_ROW + 1.
ENDAT.
ENDIF.
ENDLOOP.
ENDFORM. "GET_DATA
工单预留增删改
Posted 追寻无限
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了工单预留增删改相关的知识,希望对你有一定的参考价值。
以上是关于工单预留增删改的主要内容,如果未能解决你的问题,请参考以下文章