SAP动态配置程序-Dialog-ALV-报表(下).docx
INCLUDEINCLUDEINCLUDEINCLUDEINCLUDESAP动态配置程序DialogALV报表(下)-AuthorzSUNZKQQ:1131341075WEIXIN:DreamSunlight88REPORTYMPSR9010MESSAGE-IDYMCANOSTANDARDPAGEHEADING.YMPSR9010_TOP.YMPSR9010_CLS.YMPSR9010_001.YMPSR9010_I01.YMPSR9010_F01.START-OF-SELECTION.CALLSCREEN1.00.DATA:ok_codesave_okg_errorTYPEsy-ucommzTYPEsy-ucomm,TYPEc,l_answer TYPE c,“弹框返回值,1创建、2、修改3、显示DATA:gt_cs009TYPETABLEOFympstcs009,gs_cs009TYPEympstcs009,gt.cs010TYPETABLEOFyrpstcs010,gs_cs010TYPEympstcs010.g_actionTYPEcVALUE'3'.DATA:gc_alvlOOTYPEREFTOcl_gui_alv_grid,"用户角色ALVgc_containerlOOTYPEREFTOcl_gui_custom_container,ALV容器gs_layoutlOOTYPElvc_s_layo,ZkLV布局结构gt_fieldcatlOOTYPElvc_t_fcat."标题头DATA:gc_alv200TYPEREFTOcl_gui_alv_grid,"用户角色ATNgc_container200TYPEREFTOcl_gui_custom_container,ALV容器gs_layout200TYPElvc_s_layo,"ALV布局结构gt_fieldcat200TYPElvc_t_fcat,”标题头gs_lvc_s_stblTYPElvc_s_stblVALUE,XX'.CLASSlcl_event_handlerDEFINITION.PUBLICSECTION.METHODS:handle_double_clickFOREVENTdouble_clickOFcl_gui_alv_gridIMPORTINGe_rowe_columnes_row_nosender.ENDCLASS.CLASSlcl_event_handlerIMPLEMENTATION.METHODhandle_double_click.*双击事务PERFORMhandle_double_clicklOOCHANGINGe_columnes_row_no.ENDMETHOD.ENDCLASS.MODULEstatus_0100OUTPUT.SETPF-STATUS,100,.SETTITLEBAR,100,.PERFORMfrm_disp_alvl00.ENDMODULE."STATUS_0100OUTPUTModuleSTATUS_0200OUTPUTtextMODULEstatus_0200OUTPUT.SETPF-STATUS,200'.SETTITLEBAR,200,.PERFORMfrm_disp_alv200.ENDMODULE.”STATUS_0200OUTPUTMODULEuser_command_0100INPUT.CALLMETHODgc_alvl00->check_changed_data.save_ok=ok_code.CLEARok_code.CASEsave_ok.WHEN,DISP,.g_action=,3,.WHEN'MODIFY,.g_action=,2'.WHEN,BACK,.1.EAVETOSCREEN0.WHEN,CREAT,.gaction=,1'.PERFORMfrm_create_datelOO.WHEN,DELE'.PERFORMfrm_delete_datelOO.WHEN,SAVE,.PERFORMfrm_save_datelOO.WHENOTHERS.ENDCASE.CALLMETHODgc_alvlOO->check_changed_data.CALLMETHODgc_aIvl00->refresh_table_displayEXPORTINGis_stable=gs_lvc_s_stbl.ENDMODULE."USER_COMMAND_01OOINPUTModuleUSER_COMMAND_0200INPUTtextMODULEuser_command_0200INPUT.CALLMETHODgc_alv200->check_changed_data.save_ok=ok_code.CLEARok_code.CASEsave_ok.WHEN'DISP'.g_action='3,.WHEN'MODIFY,.g_action='2'.WHEN,BACK,.g_action='3,.1.EAVETOSCREEN0.WHEN'CREAT,.g_action=,1,.PERFORMfrm_create_date200.WHEN,DELE'.PERFORMfrm_delete_date200.WHEN'SAVE,.PERFORMfrmsavedate200.WHENOTHERS.ENDCASE.CALLMETHODgc_alv200->check_changed_data.CALLMETHODgc_alv200->refresh_table_displayEXPORTINGis_stable=gs_lvc_s_stbl.ENDMODULE."USER_COMMAND_0200INPUT*&包含YMPSR9010_F01*力&FormFRM_DISP_ALV100*&*text->pltext<p2textFORMfrm_disp_alvlOO.DATA:l_event_receiverTYPEREFTOlcl_event_handler.gs_layoutlOO-sel_mode='A'.*gs_layoutlOO-zebra=abap_true.gs_layoutlOO-no_toolbar='X'.gs_layoutlOO-cwidth_opt='X,.IFgt_cs009ISINITIAL.PERFORMfrm_getdatalOO.ENDIF.IFgc_containerlOOISINITIAL,createacontainerforthesplittercontrolCREATEOBJECTgc_containerlOOEXPORTINGcontainer_name='ALVlOO'EXCEPTIONScntl_error=1cntl_system_error=2create_error=3lifetime_error=41ifetime_dynpro_dynpro_link=5OTHERS=6.IFsy-subrc<>0.-ExceptionhandlingMESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgvlsy-msgv2sy-msgv3sy-msgv4.ENDIF.createaninstanceofalvcontrolCREATEOBJECTgc_alvl00EXPORTINGi_parent=gc_containerlOO"gc_containerl00EXCEPTIONSerror_cntl_create=1error_cntl_init=2error_cntl_link=3error_dp_create=4OTHERS=5.IFsy-subrc<>0.MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgvlsy-msgv2sy-msgv3sy-msgv4.ENDIF.CLEARgt_fieldcatlOO.PERFORMfm_add_fieldcat_alvl00USING,SXFL,'项目属性分类编号I15IIIIIIIIPERFORMfm_add_fieldcat_alvlOOUSING,SXFLT,'项目属性分类描述,20PERFORMfm_add_fieldcat_alvl00USING,WBSCJ,'层级维护,20,YMPSTCS007,WBSCJ,=WBSCJ,.CALLMETHODgc_alvl00->register_edit_eventEXPORTINGi_event_id=cl_gui_alv_grid=>mc_evt_modifiedEXCEPTIONSerror=1OTHERS=2.CREATEOBJECTgceventlOO.SETHANDLERgc_eventlOO->handle_double_clickFORgc_alvlOO.CREATEOBJECTl_event_receiver.SETHANDLERl_event_receiver->handle_double_clickFORgc_alvl00.CALLMETHODgc_alvlOO->set_table_for_first_displayEXPORTINGis_layout=gs_layoutlOOit_toolbar_excluding=IJeXCIUdeCHANGINGit_outtab=gt_cs009it_fieldcatalog=gt_fieldcatlOO.ELSE.IFg_action=,3,.CLEARgt_fieldcatlOO.PERFORM fm_add_fieldcat_alvlOO 15PERFORM fm_add_fieldcat_alvlOO ,20PERFORM fm_add_fieldcat_alvlOOUSING 'SXFL,USING ,SXFLT,USING ,WBSCJ,20'' ' ,YMPSTCS007, 'WBSCJ, ,=WBSCJ,.ELSE.CLEAR gt_fieldcatlOO .PERFORM fm_add_fieldcat_alvlOO 15PERFORM fm_add_fieldcat_alvlOO ,20, ,XPERFORM fm add fieldcat alvlOOUSING 'SXFL,USING ,SXFLT,USING ,WBSCJ,,项目属性分类编号,项目属性分类描述,层级维护,项目属性分类编号,项目属性分类描述,层级维护,20,X,YMPSTCS007,'WBSCJ,=WBSCJ'ENDIF.CALLMETHODgc_alvlOO->set_frontend_fieldcatalogEXPORTINGit_fieldcatalog=gt_fieldcatlOO.CALLMETHODgc_alvlOO->refresh_table_displayEXPORTINGis_stable=gs_lvc_s_stbl.ENDIF.FormFMADDFIELDCATALVtext>P 0117text>P 0118text>P 0119text>P 0120textFORM fm_add_fieldcat_alvl00 USING pl p2 p3 p4 p5 p p7.DATA ls_fcat TYPE lvc_s_fcat.ls_fcat-fieIdname = pl. ls_fcat-scrtext_s = pl. ls_fcat-scrtext_m = pl. ls_fcat-scrtext_l = pl. ls_fcat-coltext = p2. ls_fcat-outputIen = p3. ls_fcat-edit = p4 . IF p5 IS NOT INITIAL.ls_fcat-ref_table = p5.ENDIF.IF p IS NOT INITIAL. ls_fcat-ref_field = p.ENDIF.ls_fcat-edit_mask = p7.APPEND ls_fcat TO gt_fieldcatlOO.ENDFORM.” FM_ADD_FIELDCAT_ALV1 OO*& Form FRM_DISP_ALV200text* 一 pltexttextFORMfrm_disp_alv200.gs_layout200-sel_mode=,A,.*gs_layout200-zebra=abap_true.gs_layout200-no_toolbar=,X,.gs_layout200-cwidth_opt=,X,.IFgc_container200ISINITIAL.*createacontainerforthesplittercontrolCREATEOBJECTgc_container200EXPORTINGcontainer_name=,ALV200,EXCEPTIONScntl_error=1cntl_system_error=2create_error=3lifetime_error=41ifetime_dynpro_dynpro_link=5OTHERS=6.IFsy-subrc<>0.*一ExceptionhandlingMESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgvlsy-msgv2sy-msgv3sy-msgv4.ENDIF.*createaninstanceofalvcontrolCREATEOBJECTgc_alv200EXPORTINGi_parent=gc_container200ugc_containerlOOEXCEPTIONSerror_cntl_create=1error_cntl_init=2error_cntl_link=3error_dp_create=4OTHERS=5.IFsy-subrc<>0.MESSAGEIDsy-msgidTYPEsy-msgtyNUMBERsy-msgnoWITHsy-msgvlsy-msgv2sy-msgv3sy-msgv4.ENDIF.CLEARgt_fieldcat200.项目属性编码项目属性描述PERFORMfm_add_fieldcat_alv200USING,XMSX',20,.PERFORMfmaddfieldcatalv200USING'XMSXT,'20'CALLMETHODgc_alv200->register_edit_eventEXPORTINGi_event_id=cl_gui_alv_grid=>mc_evt_modifiedEXCEPTIONSerror=1OTHERS=2.CALLMETHODgc_alv200->set_table_for_first_displayEXPORTINGis_layout=gs_layout200CHANGINGit_outtab=gt_cs010it_fieldcatalog=gt_fieldcat200.ELSE.IF g_action,3,.CLEAR gt_fieldcat200.PERFORM fm_add_fieldcat_alv200USING'XMSX'属性编码'20'PERFORM fm add fieldcat alv200USING,XMSXT'目属性描述'20'ELSE.CLEAR gt_fieldcat200.PERFORM fm add fieldcat alv200USING,XMSX'目属性编码'20'PERFORM fm add fieldcat alv200USING,XMSXT,,项目属性描述'20''X,.ENDIF.CALLMETHODgc_alv200->set_frontend_fieldcatalogEXPORTINGit_fieldcatalog=gt_fieldcat200.CALLMETHODgc_alv200->refresh_table_displayEXPORTINGis_stable=gs_lvc_s_stbl.ENDIF.ENDFORM."FRM_DISP_ALV2OOFormFM_ADD_FIELDCAT_ALV200text->P_0359text>P_0360text->P_0361text->P_0362textFORMfm_add_fieldcat_alv200USINGplp2p3p4.DATAls_fcatTYPElvc_s_fcat.ls_fcat-fieIdname=pl.ls_fcat-scrtext_s=pl.ls_fcat-scrtext_m=pl.ls_fcat-scrtext_l=pl.ls_fcat-coltext=p2.ls_fcat-outputIen=p3.ls_fcat-edit=p4.APPENDls_fcatTOgt_fieldcat200.ENDFORM.”FM_ADD_FIELDCAT_ALV200*&FormHANDLE_DOUBLE_CLICK100text<-P_E_COLUMNtext<-P_ES_ROW_NOtextFORMhandle_double_clicklOOCHANGINGis_columnTYPElvc_s_colis_row_noTYPElvc_s_roid.CLEAR:gs_cs009,gt_cs010.READTABLEgt_cs009INTOgs_cs009INDEXis_row_no-row_id.IFsy-subrc=0.”取得SELECT*INTOCORRESPONDINGFIELDSOFTABLEgt_cs010FROMympstcs010WHEREsxf1=gs_cs009-sxf1.g_action=,3'.CALLSCREEN0200.ENDIF.ENDFORM."HANDLE_DOUBLE_CLICK1OOFormFRM_GETDATA100text->pltext<-p2textFORMfrm_getdatal00.SELECT*INTOTABLEgt_cs009FROMympstcs009.SORTgt_cs009BYsxf1.DELETEADJACENTDUPLICATESFROMgt_cs009COMPARINGsxf1.ENDFORM."FRM_GETDATA100*&FormFRM_CREATE_DATE1OOtext->pltext<-p2textFORMfrm_create_date100.DO1TIMES.APPENDINITIALLINETOgt_cs009.ENDDO.ENDFORM.”FRMCREATEDATE100FormFRM_DELETE_DATE100text*->pltext*<-p2textFORMfrm_delete_datel00.DATA:lt_row_noTYPElvc_t_roid,ls_row_noTYPElvc_s_roid.DATA:lt_tjg005TYPETABLEOFympstjg005.PERFORMfrm_popup_messageUSINGtext-001text-002CHANGINGl_answer.CHECKl_answer=,J,.CALLMETHODgc_alvl00->get_selected_rowsIMPORTINGet_row_no=lt_row_no.IFlines(lt_row_no)=0.MESSAGEs000WITHtext-003DISPLAYLIKE'E,.RETURN.ENDIF.1.OOPATlt_row_noINTOls_row_no.READTABLEgt_cs009INTOgs_cs009INDEX1s_row_no-row_id.SELECT*INTOTABLEgt_cs010FROMympstcs010WHEREsxfl=gs_csO09-sxf1.* READTABLEgt_cs010INTOgs_cs010INDEX1.* IFgs_cs010-sxfl<>space.* MESSAGESOOOWITHte×t-OO4DISPLAYLIKE,E,.* EXIT.ENDIF.* CLEAR:gt_cs010fgs_cs010.IFgs_Cs009ISNOTINITIAL.SELECT*INTOTABLElt_tjg005FROMympstjg005WHEREsxfl=gs_cs009-sxf1.IFlt_tjg005ISNOTINITIAL.MESSAGEsll(ymca)WITHgs_cs009-sxf1DISPLAYLIKE,E,.RETURN.ENDIF.DELETEFROMympstcs009WHEREsxfl=gs_cs009-sxf1.MESSAGEs000WITHtext-005DISPLAYLIKE'S'.CLEARgs_cs009.ENDIF.ENDLOOP.PERFORMfrm_getdatal00.ENDFORM.“FRM_DELETE_DATE1OOFormFRM_SAVE_DATE1OOtext* -pltext* <-p2textFORMfrm_save_date100.DATA:lt_cs009TYPETABLEOFympstcs009,lt_cs009_iTYPETABLEOFympstcs009,ls_cs009TYPEympstcs009,ls_cs009_temTYPEympstcs009,lv_sxflTYPEiVALUE1.SELECT * FROM ympstcs009INTO TABLE lt_CsOO9.”自动编码1.OOPATgt_cs009INTOgs_cs009.IFgscs009-sxflISINITIAL.DO.READTABLElt_Cs009INTOls_Cs009WITHKEYsxfl=lv_sxf1.IFsy-subrc<>0.gs_cs009-sxf1=lv_sxf1.lv_sxf1=lv_sxf1+1.EXIT.ELSE.lv_sxf1=lv_sxf1+1.ENDIF.ENDDO.ENDIF.APPENDgs_cs009TOlt_cs009_i.ENDLOOP.CLEARlv_sxf1.IFlt_Cs009_iISINITIAL.MESSAGEsOOOWITHtext-006DISPLAYLIKE,E,.RETURN.ENDIF.>保存校验DATA:lt_009TYPETABLEOFympstcs009,ls_009TYPEympstcs009.REFRESHlt_009.1.OOPATlt_cs009_iINTOgs_cs009.1.OOPATlt_009INTOls_009.IFls_009-sxfIt=gs_cs009-sxfIt.MESSAGEeOOO(ymca)WITHls_009-sxflttext-007DISPLAYLIKE,ECLEARls_009.RETURN.ENDIF.ENDLOOP.APPENDgs_cs009TOlt_009.ENDLOOP.PERFORMfrm_popup_messageUSINGtext-008text-009CHANGINGl_answer.MODIFYympstcs009FROMTABLElt_cs009_i.MESSAGEs000WITHtext-010DISPLAYLIKE'S'.PERFORMfrm_getdatalOO.ENDFORM."FRM_SAVE_DATE1OOFormFRM_CREATE_DATE200text*->pltext*<-p2textFORMfrm_create_date200.APPENDINITIALLINETOgt_Cs010.ENDFORM."FRM_CREATE_DATE200*&FormFRM_DELETE_DATE200text*->pltext*<-p2textFORMfrm_delete_date200.DATA:lt_row_noTYPElvc_t_roid,ls_row_noTYPElvc_s_roid.DATA:lt_tjg005TYPETABLEOFympstjg005.PERFORMfrm_popup_messageUSINGtext-001text-002CHANGINGl_answer.CALLMETHODgc_alv200->get_selected_rowsIMPORTINGet_row_no=lt_row_no.IFlines(lt_row_no)=0.MESSAGEs000WITHtext-003DISPLAYLIKE,E,.RETURN.ENDIF.1.OOPATlt_row_noINTOls_row_no.READTABLEgt_cs010INTOgs_cs010INDEXls_row_no-row_id.IFgs-cslISNOTINITIAL.SELECT*INTOTABLElt_tjg005FROMympstjg005WHEREsxfl=gs_cs010-sxf1ANDxmsx=gs_cs010-xmsIFlt_tjg005ISNOTINITIAL.MESSAGEsll7(ymca)WITHgs_cs010-xmsxDISPLAYLIKE'E,.RETURN.ENDIF.DELETEFROMympstcs010WHEREsxfl=gs_cs010-sxf1.MESSAGEs000WITHtext-005DISPLAYLIKE,S,.CLEARgs_csOlO.ENDIF.ENDLOOP.PERFORMfrm_getdata200.MESSAGEs000WITHtext-005DISPLAYLIKE,S,.ENDFORM."FRM_DELETE_DATE200FormFRM_SAVE_DATE200texttext<-P2textFORMfrm_save_date200.DATA:lt-cslTYPETABLEOFympstcsl,lt_cs010_iTYPETABLEOFympstcs010,ls_cs010TYPEympstcs010,ls_cs010_temTYPEympstcs010,lv_xmsxTYPEiVALUE.SELECT*FROMympstcslINTOTABLElt_cs010WHEREsxf1=gs_cs009-sxf1.”自动编码1.OOPATgt_cs010INTOgs_cs010.lv_xmsx.IFgs_cs010-xmsxISINITIAL.DO.READTABLElt_Cs010INTOls_Cs010WITHKEYxmsxIFsy-subrc<>0.lv_xmsx=gs_cs009*IO+1.gs_cs010-xmsx=lv_xmsx.gs_cs010-sxf1=gs_cs009-sxf1.lv_xmsx=lv_xmsx+1.EXIT.ELSE.lv_xmsx=lv_xmsx+1gs_cs010-xmsx=lv_xmsx.gs_cs010-sxf1=gs_cs009-sxf1.ENDIF.ENDDO.ENDIF.APPENDgs_cs010TOlt_cs010_i.ENDLOOP.CLEARlv_xmsx.IFlt_Cs010_iISINITIAL.MESSAGEsOOOWITHtext-006DISPLAYLIKE,E,.RETURN.ENDIF.保存校验DATA:lt_010TYPETABLEOFympstcsl,ls_010TYPEympstcs010.REFRESHItOlO.1.OOPATlt_cs010_iINTOgs_cs010.1.OOPATlt_010INTOls_010.IFls_010-xmsxt=gs_cs010-xmsxt.MESSAGEe000(ymca)WITHls_010-xmsxttext-007DISPLAYLIKE'ECLEARls_010.RETURN.ENDIF.ENDLOOP.APPENDgs_cs010TOlt_010.ENDLOOP.PERFORMfrm_popup_messageUSINGtext-008text-009CHANGINGl_answer.CHECK1answerMODIFYympstcs010FROMTABLElt_Cs010_i.MESSAGEs000WITHtext-010DISPLAYLIKE'S'.PERFORMfrm_getdata200.ENDFORM."FRM_SAVE_DATE200FormFRM_POPUP_MESSAGEtext->P_TEXT_001text->P_TEXT_002text<P_L_ANSWERtextFORMfrm_popup_messageUSINGTYPEchar20l_textTYPEchar40CHANGINGl_answerTYPEc.CALLFUNCTION,POPUP_TO_CONFIRM_STEP,EXPORTINGtitel=1titeltextlinel=l_textdefaultoption=,N'CanCel.display=,start_column=16start_row=13IMPORTINGanswer=l_answer.ENDFORM."FRM_POPUP_MESSAGEFormFRM_GETDATA200text*->pltext*<-p2textFORMfrm_getdata200.SELECT*INTOCORRESPONDINGFIELDSOFTABLEgt_cs010FROMympstcs010WHEREsxf1=gs_cs009-sxf1.''FRM GETDATA200ENDFORM.