matinal:SAP ABAP 在ALV列表中添加下拉框

2023-10-14 14:44:49 浏览数 (2)

直接上代码:

代码语言:javascript复制
REPORT ZTEST.
TYPE-POOLS: SLIS.

TYPES:
  BEGIN OF T_DATA,
    MATNR TYPE MAKT-MATNR,
    MAKTX TYPE MAKT-MAKTX,
    SPRAS TYPE MAKT-SPRAS,
  END   OF T_DATA,
  BEGIN OF T_ALV,
    MATNR     TYPE MAKT-MATNR,
    MAKTX     TYPE MAKT-MAKTX,
    SPRAS     TYPE MAKT-SPRAS,
    DD_HANDLE TYPE INT4,
  END   OF T_ALV.
DATA:
  GT_FIELDCATALOG TYPE LVC_T_FCAT,
  GW_FIELDCATALOG TYPE LVC_S_FCAT,
*定义存储下拉列表的数据
  GT_DDVAL        TYPE LVC_T_DROP,
  GW_DDVAL        TYPE LVC_S_DROP,

  GT_EVENTS       TYPE SLIS_T_EVENT,
  GW_EVENTS       TYPE SLIS_ALV_EVENT,
  GT_DATA         TYPE TABLE OF T_DATA,
  GW_DATA         TYPE          T_DATA,
  GT_ALV          TYPE TABLE OF T_ALV,
  GW_ALV          TYPE          T_ALV,
  G_REPID         TYPE SY-REPID VALUE SY-REPID.
************************************************************************
*                     SELECTION SCREEN                                 *
************************************************************************
SELECT-OPTIONS: S_MATNR FOR GW_DATA-MATNR .

************************************************************************
*                     START-OF-SELECTION                               *
************************************************************************
START-OF-SELECTION.
  SELECT MATNR MAKTX SPRAS
  INTO TABLE GT_DATA UP TO 50 ROWS
  FROM MAKT
  WHERE MATNR IN S_MATNR
      AND SPRAS = 'EN'.

  LOOP AT GT_DATA INTO GW_DATA.
    MOVE-CORRESPONDING GW_DATA TO GW_ALV.
    APPEND GW_ALV TO GT_ALV.
  ENDLOOP.

  PERFORM CREAT_FIELDCAT.
  PERFORM CREAT_DROPDOWN_VALUES.
  PERFORM CREAT_EVENT_EXITS.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM = G_REPID
      IT_FIELDCAT_LVC    = GT_FIELDCATALOG
      IT_EVENTS          = GT_EVENTS
    TABLES
      T_OUTTAB           = GT_ALV.
*---------------------------------------------------------------------*
* 设置输出字段的格式
*---------------------------------------------------------------------*
FORM CREAT_FIELDCAT.
  CLEAR GW_FIELDCATALOG.
  GW_FIELDCATALOG-FIELDNAME = 'MATNR'.
  GW_FIELDCATALOG-REF_FIELD = 'MATNR'.
  GW_FIELDCATALOG-REF_TABLE = 'MAKT'.
  APPEND GW_FIELDCATALOG TO GT_FIELDCATALOG.

  CLEAR GW_FIELDCATALOG.
  GW_FIELDCATALOG-FIELDNAME = 'MAKTX'.
  GW_FIELDCATALOG-REF_FIELD = 'MAKTX'.
  GW_FIELDCATALOG-REF_TABLE = 'MAKT'.
  APPEND GW_FIELDCATALOG TO GT_FIELDCATALOG.

  CLEAR GW_FIELDCATALOG.
  GW_FIELDCATALOG-FIELDNAME = 'SPRAS'.
  GW_FIELDCATALOG-OUTPUTLEN = '7'.
  GW_FIELDCATALOG-DD_OUTLEN = '7'.
  GW_FIELDCATALOG-INTLEN    = '2'.
  GW_FIELDCATALOG-INTTYPE   = 'C'.
  GW_FIELDCATALOG-COLTEXT   = 'Language'.
  GW_FIELDCATALOG-TOOLTIP   = 'Language'.
  GW_FIELDCATALOG-SELTEXT   = 'Language'.
  GW_FIELDCATALOG-DRDN_FIELD = 'DD_HANDLE'.
  GW_FIELDCATALOG-EDIT       = 'X'.
  APPEND GW_FIELDCATALOG TO GT_FIELDCATALOG.
ENDFORM.                    " creat_fieldcat
*---------------------------------------------------------------------*
*根据物料的所有的语言生成不同的生成下拉列表
*---------------------------------------------------------------------*
FORM CREAT_DROPDOWN_VALUES.
  DATA: L_SPRAS TYPE MAKT-SPRAS,
        L_COUNT TYPE I.
  LOOP AT GT_ALV INTO GW_ALV.
    ADD 1 TO L_COUNT.
    SELECT SPRAS
       INTO L_SPRAS
    FROM MAKT
    WHERE MATNR = GW_ALV-MATNR.
      CLEAR GW_DDVAL.
      GW_DDVAL-HANDLE = L_COUNT.
      GW_DDVAL-VALUE = L_SPRAS.
      APPEND GW_DDVAL TO GT_DDVAL.
    ENDSELECT.

    CLEAR GW_DDVAL.
    GW_DDVAL-HANDLE = L_COUNT.
    GW_DDVAL-VALUE = '                 '.
    APPEND GW_DDVAL TO GT_DDVAL.
*设置对应
    GW_ALV-DD_HANDLE = L_COUNT.
    MODIFY GT_ALV FROM GW_ALV.
  ENDLOOP.
ENDFORM.                    " creat_dropdown_values
*---------------------------------------------------------------------*
*      Form creat_event_exits
*---------------------------------------------------------------------*
FORM CREAT_EVENT_EXITS .
  GW_EVENTS-NAME = 'CALLER_EXIT'.
  GW_EVENTS-FORM = 'CALLER_EXIT'.
  APPEND GW_EVENTS TO GT_EVENTS.
ENDFORM.                    " creat_event_exits
*---------------------------------------------------------------------*
*设置下拉列表,使Grid和内表能链接上
*---------------------------------------------------------------------*
FORM CALLER_EXIT USING LS_DATA TYPE SLIS_DATA_CALLER_EXIT.
  DATA: L_REF_ALV TYPE REF TO CL_GUI_ALV_GRID.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = L_REF_ALV.
  CALL METHOD L_REF_ALV->SET_DROP_DOWN_TABLE
    EXPORTING
      IT_DROP_DOWN = GT_DDVAL.
ENDFORM.                    "CALLER_EXIT

另一个例子:

代码语言:javascript复制
**=====================================================================*
*& Report ZPS_FM_13
**=====================================================================*
REPORT zps_fm_13.

**=====================================================================*
*  End Date               :
*======================================================================*
*                     Modify Log History.
*----------------------------------------------------------------------*
*
*No. Modified by    Date      Transport  Description
*--- -----------    ----      ---------  -----------
*M1

*======================================================================*
*                             Tables
*======================================================================*
TABLES:zps009.
*======================================================================*
*                             Constants
*======================================================================*

*======================================================================*
*                             Types
*======================================================================*
TYPE-POOLS : abap,slis,icon.
*======================================================================*
*                     Internal Tables/work areas
*======================================================================*
DATA:BEGIN OF gt_wd OCCURS 0,
  wdbh LIKE zps011-wdbh,    "文档编号
  wdmc LIKE zps011-wdmc,    "文档名称
  checkbox TYPE c,
  sel(1) TYPE c,
  END OF gt_wd.
DATA:BEGIN OF gt_out OCCURS 0,
  wdbh LIKE zps009-wdbh,    "文档编号
  wdmc LIKE zps009-wdmc,    "文档名称
  tjtime LIKE zps009-tjtime,    "提交时间
  tjry LIKE zps009-tjry,        "提交人员
  shry LIKE zps009-shry,        "审核人员
  shtime LIKE zps009-shtime,    "审核时间
  shqk LIKE zps009-shqk,        "审核情况
  bz LIKE zps009-bz,            "备注
  sel(1) TYPE c,
  dd_handle TYPE int4,
  END OF gt_out.
 DATA:BEGIN OF gt_zzhtbm OCCURS 0,
  zzhtbm TYPE zzhtbm,
  zzhtms TYPE zzhtms,
  END OF gt_zzhtbm.
DATA: fieldcat TYPE lvc_t_fcat WITH HEADER LINE.
DATA: fieldcat1 TYPE lvc_t_fcat WITH HEADER LINE.
*定义存储下拉列表的数据
DATA:gt_ddval TYPE lvc_t_drop,
     gw_ddval TYPE lvc_s_drop.
*======================================================================*
*                      Data declarations
*======================================================================*
DATA: wa_layout   TYPE lvc_s_layo,
      gt_events   TYPE slis_t_event,
      gs_event   LIKE LINE OF gt_events.
DATA: g_grid TYPE REF TO cl_gui_alv_grid.
DATA:is_variant LIKE  disvariant.
*======================================================================*
*                      Definition
*======================================================================*
DEFINE fill_field.
  CLEAR FIELDCAT.
  FIELDCAT-FIELDNAME     = &1.
  FIELDCAT-SCRTEXT_L     = &2.
  FIELDCAT-CFIELDNAME    = &3.
  FIELDCAT-OUTPUTLEN     = &4.
  FIELDCAT-EDIT          = &5.
  APPEND FIELDCAT.
END-OF-DEFINITION.
DEFINE fill_field1.
  CLEAR FIELDCAT1.
  FIELDCAT1-FIELDNAME     = &1.
  FIELDCAT1-SCRTEXT_L     = &2.
  FIELDCAT1-CFIELDNAME    = &3.
  FIELDCAT1-OUTPUTLEN     = &4.
  FIELDCAT1-EDIT          = &5.
  APPEND FIELDCAT1.
END-OF-DEFINITION.
*======================================================================*
*                       Range declarations
*======================================================================*

*======================================================================*
*                      Input Selection Screen
*======================================================================*
SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
  PARAMETERS:p_pspid LIKE proj-pspid OBLIGATORY.
  SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN:COMMENT 32(50) l_msl.                                     "项目定义描述
  SELECTION-SCREEN END OF LINE.
  SELECT-OPTIONS:s_zzhtbm FOR zps009-zzhtbm .
  PARAMETERS:p_r1 RADIOBUTTON GROUP r1 DEFAULT 'X',
             p_r2 RADIOBUTTON GROUP r1,
             p_r3 RADIOBUTTON GROUP r1.
SELECTION-SCREEN END OF BLOCK bl1.
*======================================================================*
*                          Initialization
*======================================================================*
INITIALIZATION.

*======================================================================*
*                        At Selection Screen
*======================================================================*
AT SELECTION-SCREEN ON p_pspid.
PERFORM frm_get_lms.
AT SELECTION-SCREEN ON s_zzhtbm.
PERFORM frm_zzhtbm.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_zzhtbm-low.
PERFORM frm_f4_zzhtbm.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_zzhtbm-high.
PERFORM frm_f4_zzhtbm.
*======================================================================*
*                        At Selection Screen Output
*======================================================================*
AT SELECTION-SCREEN OUTPUT .

*======================================================================*
*                        AT SELECTION-SCREEN ON VALUE-REQUEST
*======================================================================*

*======================================================================*
*                        Start of Selection
*======================================================================*
START-OF-SELECTION.

*======================================================================*
*                        End of Selection
*======================================================================*
END-OF-SELECTION.
IF p_r1 = 'X'.
   PERFORM frm_get_data.
   PERFORM frn_alv_display.
   ELSEIF p_r2 = 'X'.
     PERFORM frm_get_data1.
     PERFORM frm_alv_display.
     ELSEIF p_r3 = 'X'.
       PERFORM frm_get_data1.
       PERFORM frm_alv_display1.
ENDIF.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_LMS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_lms .
DATA:lv_msl TYPE char40.
CLEAR:l_msl.
IF p_pspid IS NOT INITIAL.
SELECT SINGLE post1
  INTO lv_msl
  FROM proj
  WHERE pspid = p_pspid.
 IF sy-subrc <> 0.
    MESSAGE '不存在此项目' TYPE 'E'.
    ELSE.
      l_msl = lv_msl.
      CLEAR lv_msl.
 ENDIF.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_ZZHTBM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_zzhtbm .
  IF s_zzhtbm[] IS INITIAL.
     MESSAGE '合同编号必输,请填写合同编号!' TYPE 'E'.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_F4_ZZHTBM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_f4_zzhtbm .
  SELECT zzhtbm zzhtms
    INTO CORRESPONDING FIELDS OF TABLE gt_zzhtbm
    FROM zhttz
    WHERE zzxmbm = p_pspid.
  DELETE ADJACENT DUPLICATES FROM gt_zzhtbm COMPARING zzhtbm.
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'ZZHTBM'
      dynpprog        = sy-repid
      dynpnr          = sy-dynnr
      dynprofield     = 'S_ZZHTBM'
      value_org       = 'S'
    TABLES
      value_tab       = gt_zzhtbm
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_data .
  SELECT wdbh wdmc
    INTO CORRESPONDING FIELDS OF TABLE gt_wd
    FROM zps011.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRN_ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frn_alv_display .
  CLEAR: wa_layout."它用来定义ALV报表的整体属性
    wa_layout-cwidth_opt    = 'X'."优化列宽选项是否设置
    wa_layout-box_fname = 'SEL'.
   REFRESH fieldcat.
  fill_field 'WDBH'      '文档编号' '' '20' 'X'.
  fill_field 'WDMC'      '文档名称' '' '20' 'X'.
  fieldcat-fieldname     = 'CHECKBOX'.
  fieldcat-scrtext_l     = '需要'.
  fieldcat-cfieldname    = ''.
  fieldcat-outputlen     = '5'.
  fieldcat-edit          = 'X'.
  fieldcat-checkbox      = 'X'.
  APPEND fieldcat.
  CLEAR fieldcat.

  is_variant-report = 'ZPS_FM_13'.
  is_variant-handle = '1'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_user_command  = 'USER_COMMAND'
      i_callback_pf_status_set = 'PF_STATUS'
      is_layout_lvc            = wa_layout
      it_fieldcat_lvc          = fieldcat[]
      i_default                = 'X'
      i_save                   = 'A'
     it_events                = gt_events[]
      is_variant               = is_variant
    TABLES
      t_outtab                 = gt_wd[]
    EXCEPTIONS
      OTHERS                   = 2.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.
FORM pf_status USING lt_extab.
  SET PF-STATUS 'MENU'.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->UCOMM        text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM user_command USING ucomm  LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.     "#EC CALLED
  CASE ucomm.
    WHEN 'SAVE'.
      PERFORM frm_save_function.
    WHEN 'ONEKEY'.
      PERFORM frm_onekey_function.
    WHEN 'CREAT'.
      PERFORM frm_create_function.
    WHEN 'DELETE'.
      PERFORM frm_delete_function.
    WHEN 'OK'.
      PERFORM frm_ok_function.
  ENDCASE.
  rs_selfield-refresh    = 'X'.
  rs_selfield-col_stable = 'X'.
  rs_selfield-row_stable = 'X'.
ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
*&      Form  FRM_SAVE_FUNCTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_save_function .
  DATA: lv_valid  TYPE char01.
  DATA:lv_mes TYPE string.
  DATA lt_save TYPE TABLE OF zps011 WITH HEADER LINE.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = g_grid.
  CALL METHOD g_grid->check_changed_data
    IMPORTING
      e_valid = lv_valid.
  IF lv_valid IS INITIAL.
    EXIT.
  ENDIF.
  REFRESH lt_save.
  LOOP AT gt_wd.
     lt_save-wdbh = gt_wd-wdbh.
     lt_save-wdmc = gt_wd-wdmc.
      APPEND lt_save.
      CLEAR lt_save.
  ENDLOOP.
  MODIFY zps011 FROM TABLE lt_save.
  COMMIT WORK.
  IF sy-subrc = 0.
    MESSAGE '保存成功!' TYPE 'S'.
  ELSE.
    MESSAGE '保存失败!' TYPE 'E'.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_ONEKEY_FUNCTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_onekey_function .
      LOOP AT gt_wd.
          gt_wd-checkbox = 'X'.
          MODIFY gt_wd TRANSPORTING checkbox.
      ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_CREATE_FUNCTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_create_function .
  APPEND INITIAL LINE TO gt_wd.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_DELETE_FUNCTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_delete_function .
  DATA: l_answer(1) TYPE c.
  READ TABLE gt_wd WITH KEY sel = 'X'.
  IF sy-subrc <> 0.
    MESSAGE '请选择要删除的行!' TYPE 'E'.
    ELSE.
    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
       titlebar                    = '删除'
        text_question               = '是否要删除该内容?'
         default_button              = '2'
         display_cancel_button       = 'X'
     IMPORTING
       answer                      = l_answer
     EXCEPTIONS
       text_not_found              = 1
       OTHERS                      = 2.
    IF l_answer = '1'.
      LOOP AT gt_wd WHERE sel = 'X'.
        DELETE gt_wd.
        DELETE FROM zps011 WHERE wdbh = gt_wd-wdbh.
        IF sy-subrc = 0.
          MESSAGE '删除成功!' TYPE 'S'.
        ELSE.
          MESSAGE '删除失败!' TYPE 'E'.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_OK_FUNCTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_ok_function .
  DATA: l_valid  TYPE char01.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = g_grid.
  CALL METHOD g_grid->check_changed_data
    IMPORTING
      e_valid = l_valid.
  IF l_valid IS INITIAL.
    EXIT.
  ENDIF.
   PERFORM frm_get_wdbh.
   PERFORM frm_alv_display.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_WDBH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_wdbh .
  REFRESH gt_out.
  READ TABLE gt_wd WITH KEY checkbox = 'X'.
  IF sy-subrc = 0.
  LOOP AT gt_wd WHERE checkbox = 'X'.
      gt_out-wdbh = gt_wd-wdbh.
      gt_out-wdmc = gt_wd-wdmc.
      APPEND gt_out.
      CLEAR gt_out.
  ENDLOOP.
  ELSE.
    MESSAGE '请选择需要创建的文档!' TYPE 'E'.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_alv_display .
    DATA: l_count TYPE i.
  CLEAR: wa_layout."它用来定义ALV报表的整体属性
    wa_layout-box_fname = 'SEL'.

  REFRESH fieldcat1.
  fill_field1 'WDBH'      '文档编号' '' '20' ''.
  fill_field1 'WDMC'      '文档名称' '' '20' ''.
  fieldcat1-fieldname     = 'TJTIME'.
  fieldcat1-coltext     = '提交时间'.
  fieldcat1-cfieldname    = ''.
  fieldcat1-outputlen     = '15'.
  fieldcat1-edit          = 'X'.
  fieldcat1-ref_table   = 'BKPF'.
  fieldcat1-ref_field   = 'BUDAT'.
  fieldcat1-f4availabl    = 'X'.
  APPEND fieldcat1.
  CLEAR fieldcat1.
  fill_field1 'TJRY'      '提交人员' '' '20' 'X'.
  fill_field1 'SHRY'      '审核人员' '' '20' 'X'.
  fieldcat1-fieldname     = 'SHTIME'.
  fieldcat1-coltext     = '审核时间'.
  fieldcat1-cfieldname    = ''.
  fieldcat1-outputlen     = '15'.
  fieldcat1-edit          = 'X'.
  fieldcat1-ref_table   = 'BKPF'.
  fieldcat1-ref_field   = 'BUDAT'.
  fieldcat1-f4availabl    = 'X'.
  APPEND fieldcat1.
  CLEAR fieldcat1.
  fieldcat1-fieldname     = 'SHQK'.
  fieldcat1-coltext     = '审核情况'.
  fieldcat1-cfieldname    = ''.
  fieldcat1-outputlen     = '15'.
  fieldcat1-edit          = 'X'.
  fieldcat1-drdn_field    = 'DD_HANDLE'.
  APPEND fieldcat1.
  CLEAR fieldcat1.
  fill_field1 'BZ'      '备注' '' '40' 'X'.

  LOOP AT gt_out.
      ADD 1 TO l_count.
    gw_ddval-handle = l_count.
    gw_ddval-value = '未审核'.
    APPEND gw_ddval TO gt_ddval.
    CLEAR gw_ddval.
    gw_ddval-handle = l_count.
    gw_ddval-value = '审核中'.
    APPEND gw_ddval TO gt_ddval.
    CLEAR gw_ddval.
    gw_ddval-handle = l_count.
    gw_ddval-value = '审核完成'.
    APPEND gw_ddval TO gt_ddval.
    CLEAR gw_ddval.
*设置对应
    gt_out-dd_handle = l_count.
    MODIFY gt_out TRANSPORTING dd_handle.
  ENDLOOP.

  gs_event-name = 'CALLER_EXIT'.
  gs_event-form = 'CALLER_EXIT'.
  APPEND gs_event TO gt_events.

  is_variant-report = 'ZPS_FM_13'.
  is_variant-handle = '2'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_user_command  = 'USER_COMMAND1'
      i_callback_pf_status_set = 'PF_STATUS1'
      is_layout_lvc            = wa_layout
      it_fieldcat_lvc          = fieldcat1[]
      i_default                = 'X'
      i_save                   = 'A'
     it_events                = gt_events[]
      is_variant               = is_variant
    TABLES
      t_outtab                 = gt_out[]
    EXCEPTIONS
      OTHERS                   = 2.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*设置下拉列表,使Grid和内表能链接上
*---------------------------------------------------------------------*
FORM caller_exit USING ls_data TYPE slis_data_caller_exit.
  DATA: l_ref_alv TYPE REF TO cl_gui_alv_grid.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = l_ref_alv.
  CALL METHOD l_ref_alv->set_drop_down_table
    EXPORTING
      it_drop_down = gt_ddval.
ENDFORM.                    "CALLER_EXIT
FORM pf_status1 USING lt_extab.
  SET PF-STATUS 'MENU1'.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->UCOMM        text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM user_command1 USING ucomm  LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.     "#EC CALLED
  CASE ucomm.
    WHEN 'DELETE1'.
      PERFORM frm_delete1_function.
    WHEN 'SAVE1'.
      PERFORM frm_save1_function.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
  ENDCASE.
  rs_selfield-refresh    = 'X'.
  rs_selfield-col_stable = 'X'.
  rs_selfield-row_stable = 'X'.
ENDFORM.                    "user_command
*&---------------------------------------------------------------------*
*&      Form  FRM_DELETE1_FUNCTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_delete1_function .
  DATA: l_answer(1) TYPE c.
  READ TABLE gt_out WITH KEY sel = 'X'.
  IF sy-subrc <> 0.
    MESSAGE '请选择要删除的行!' TYPE 'E'.
    ELSE.
    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
       titlebar                    = '删除'
        text_question               = '是否要删除该内容?'
         default_button              = '2'
         display_cancel_button       = 'X'
     IMPORTING
       answer                      = l_answer
     EXCEPTIONS
       text_not_found              = 1
       OTHERS                      = 2.
    IF l_answer = '1'.
      LOOP AT gt_out WHERE sel = 'X'.
        DELETE gt_out.
        DELETE FROM zps009 WHERE pspid = p_pspid AND zzhtbm = s_zzhtbm-low AND wdbh = gt_out-wdbh AND wdmc = gt_out-wdmc.
        IF sy-subrc = 0.
          MESSAGE '删除成功!' TYPE 'S'.
        ELSE.
          MESSAGE '删除失败!' TYPE 'E'.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_SAVE1_FUNCTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_save1_function .
  DATA: lv_valid  TYPE char01.
  DATA:lv_mes TYPE string.
  DATA lt_save TYPE TABLE OF zps009 WITH HEADER LINE.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = g_grid.
  CALL METHOD g_grid->check_changed_data
    IMPORTING
      e_valid = lv_valid.
  IF lv_valid IS INITIAL.
    EXIT.
  ENDIF.
  REFRESH lt_save.
  LOOP AT gt_out.
     lt_save-pspid = p_pspid.
     lt_save-zzhtbm = s_zzhtbm-low.
     lt_save-wdbh = gt_out-wdbh.
     lt_save-wdmc = gt_out-wdmc.
     lt_save-tjtime = gt_out-tjtime.
     lt_save-tjry = gt_out-tjry.
     lt_save-shry = gt_out-shry.
     lt_save-shtime = gt_out-shtime.
     lt_save-shqk = gt_out-shqk.
     lt_save-bz = gt_out-bz.
      APPEND lt_save.
      CLEAR lt_save.
  ENDLOOP.
  MODIFY zps009 FROM TABLE lt_save.
  COMMIT WORK.
  IF sy-subrc = 0.
    MESSAGE '保存成功!' TYPE 'S'.
  ELSE.
    MESSAGE '保存失败!' TYPE 'E'.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_data1 .
     SELECT *
       INTO CORRESPONDING FIELDS OF TABLE gt_out
       FROM zps009
       WHERE pspid = p_pspid
         AND zzhtbm IN s_zzhtbm.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_DISPLAY1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_alv_display1 .
    DATA: l_count TYPE i.
  CLEAR: wa_layout."它用来定义ALV报表的整体属性
    wa_layout-box_fname = 'SEL'.

  REFRESH fieldcat1.
  fill_field1 'WDBH'      '文档编号' '' '20' ''.
  fill_field1 'WDMC'      '文档名称' '' '20' ''.
  fieldcat1-fieldname     = 'TJTIME'.
  fieldcat1-coltext     = '提交时间'.
  fieldcat1-cfieldname    = ''.
  fieldcat1-outputlen     = '15'.
  fieldcat1-edit          = ''.
  fieldcat1-ref_table   = 'BKPF'.
  fieldcat1-ref_field   = 'BUDAT'.
  fieldcat1-f4availabl    = 'X'.
  APPEND fieldcat1.
  CLEAR fieldcat1.
  fill_field1 'TJRY'      '提交人员' '' '20' ''.
  fill_field1 'SHRY'      '审核人员' '' '20' ''.
  fieldcat1-fieldname     = 'SHTIME'.
  fieldcat1-coltext     = '审核时间'.
  fieldcat1-cfieldname    = ''.
  fieldcat1-outputlen     = '15'.
  fieldcat1-edit          = ''.
  fieldcat1-ref_table   = 'BKPF'.
  fieldcat1-ref_field   = 'BUDAT'.
  fieldcat1-f4availabl    = ''.
  APPEND fieldcat1.
  CLEAR fieldcat1.
  fieldcat1-fieldname     = 'SHQK'.
  fieldcat1-coltext     = '审核情况'.
  fieldcat1-cfieldname    = ''.
  fieldcat1-outputlen     = '15'.
  fieldcat1-edit          = ''.
  fieldcat1-drdn_field    = 'DD_HANDLE'.
  APPEND fieldcat1.
  CLEAR fieldcat1.
  fill_field1 'BZ'      '备注' '' '40' ''.

  LOOP AT gt_out.
      ADD 1 TO l_count.
    gw_ddval-handle = l_count.
    gw_ddval-value = '未审核'.
    APPEND gw_ddval TO gt_ddval.
    CLEAR gw_ddval.
    gw_ddval-handle = l_count.
    gw_ddval-value = '审核中'.
    APPEND gw_ddval TO gt_ddval.
    CLEAR gw_ddval.
    gw_ddval-handle = l_count.
    gw_ddval-value = '审核完成'.
    APPEND gw_ddval TO gt_ddval.
    CLEAR gw_ddval.
*设置对应
    gt_out-dd_handle = l_count.
    MODIFY gt_out TRANSPORTING dd_handle.
  ENDLOOP.

  gs_event-name = 'CALLER_EXIT'.
  gs_event-form = 'CALLER_EXIT'.
  APPEND gs_event TO gt_events.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      is_layout_lvc            = wa_layout
      it_fieldcat_lvc          = fieldcat1[]
      i_default                = 'X'
      i_save                   = 'A'
     it_events                = gt_events[]
    TABLES
      t_outtab                 = gt_out[]
    EXCEPTIONS
      OTHERS                   = 2.
  IF sy-subrc <> 0.
  ENDIF.
ENDFORM.
代码语言:javascript复制
FORM FRM_VBELN_CS  USING    P_VBELN.
  "------------------------------------------
  DATA: I_ZSDT_SP03  TYPE TABLE OF ZSDT_SP03,
        WS_ZSDT_SP03 TYPE ZSDT_SP03.

  TYPES: BEGIN OF TY_VBKD,           "取项目名称
           BSTKD_E LIKE VBKD-BSTKD_E,
           VBELN   LIKE VBKD-VBELN,
           POSNR   LIKE VBKD-POSNR,
         END OF TY_VBKD.

  DATA: LT_VBKD TYPE TABLE OF TY_VBKD,
        WS_VBKD TYPE TY_VBKD.

  TYPES: BEGIN OF TY_MARM,
           MATNR LIKE MARM-MATNR,
           MEINH LIKE MARM-MEINH,
           UMREZ LIKE MARM-UMREZ,
           UMREN LIKE MARM-UMREN,
         END OF TY_MARM.

  DATA: I_MARM  TYPE TABLE OF TY_MARM,
        WS_MARM TYPE TY_MARM.

  DATA: L_COUNT TYPE I.
  DATA: L_COUNT1 TYPE I.
  "------------------------------------------
  SELECT
         A~VBELN    "销售凭证
         A~POSNR    "项目
         A~MATNR    "物料编码
         A~ARKTX    "物料描述
*
         A~KWMENG   "数量
         A~VRKME    "数量单位
         A~CMPRE    "单价
         A~KZWI1    "总价
         A~WERKS    "工厂
         A~PSTYV    "类别
         B~KNUMV    "单据条件号
         B~WAERK    "价格单位
         C~EDATU    "交货日期
*       TEXT1    "其他备注(行)
    INTO CORRESPONDING FIELDS OF TABLE I_ALV
    FROM VBAP AS A
    INNER JOIN VBAK AS B ON A~VBELN = B~VBELN
    INNER JOIN VBEP AS C ON A~VBELN = C~VBELN AND A~POSNR = C~POSNR
    WHERE A~ABGRU = ''
      AND B~VBELN = P_VBELN.

  SORT I_ALV BY  VBELN POSNR EDATU DESCENDING.
  DELETE ADJACENT DUPLICATES FROM I_ALV COMPARING VBELN POSNR."计划行日期 如果多条 取最后一条

  IF I_ALV[] IS NOT INITIAL. "取项目名称
    SELECT VBELN
           POSNR
           BSTKD_E
        INTO CORRESPONDING FIELDS OF TABLE LT_VBKD
      FROM VBKD
      FOR ALL ENTRIES IN I_ALV
      WHERE VBELN = I_ALV-VBELN.

    SELECT                               "取精确单价, (单位除以单价)
           KNUMV
           KPOSN
           STUNR
           ZAEHK
           KSCHL

           KBETR"金额
           KPEIN"单位
      INTO CORRESPONDING FIELDS OF TABLE I_KONV1
      FROM KONV
      FOR ALL ENTRIES IN I_ALV
      WHERE KNUMV = I_ALV-KNUMV
        AND KPOSN = I_ALV-POSNR
        AND KSCHL IN ( 'PR01','ZK01' ).
  ENDIF.

  IF I_ALV[] IS NOT INITIAL."单位换算
    SELECT MATNR
           MEINH
           UMREZ
           UMREN
      INTO CORRESPONDING FIELDS OF TABLE I_MARM
      FROM MARM
      FOR ALL ENTRIES IN I_ALV
      WHERE MATNR = I_ALV-MATNR
        AND MEINH = 'M'.
  ENDIF.

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE I_ZSDT_SP03
    FROM ZSDT_SP03
    WHERE VBELN = P_VBELN.

  LOOP AT I_ALV INTO WS_ALV .
    LOOP AT I_ZSDT_SP03 INTO WS_ZSDT_SP03 WHERE VBELN = WS_ALV-VBELN
                                             AND POSNR = WS_ALV-POSNR.

      CASE WS_ZSDT_SP03-ZTXBM.
        WHEN 'L01'.
          WS_ALV-ATWRT1 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L02'.
          WS_ALV-ATWRT2 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L03'.
          WS_ALV-ATWRT3 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L04'.
          WS_ALV-ATWRT4 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L05'.
          WS_ALV-ATWRT5 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L06'.
          WS_ALV-ATWRT6 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L07'.
          WS_ALV-ATWRT7 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L08'.
          WS_ALV-ATWRT8 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L09'.
          WS_ALV-ATWRT9 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L10'.
          WS_ALV-ATWRT10 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L11'.
          WS_ALV-ATWRT11 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L12'.
          WS_ALV-ATWRT12 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L13'.
          WS_ALV-ATWRT13 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L14'.
          WS_ALV-ATWRT14 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L15'.
          WS_ALV-ATWRT15 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L16'.
          WS_ALV-ATWRT16 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L17'.
          WS_ALV-ATWRT17 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L18'.
          WS_ALV-ATWRT18 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L19'.
          WS_ALV-ATWRT19 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L20'.
          WS_ALV-ATWRT20 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L21'.
          WS_ALV-ATWRT21 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L22'.
          WS_ALV-ATWRT22 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L23'.
          WS_ALV-ATWRT23 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L24'.
          WS_ALV-ATWRT24 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L25'.
          WS_ALV-ATWRT25 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L26'.
          WS_ALV-ATWRT26 = WS_ZSDT_SP03-ATWRT.
        WHEN 'L27'.
          WS_ALV-ATWRT27 = WS_ZSDT_SP03-ATWRT.
        WHEN OTHERS.
      ENDCASE.
    ENDLOOP.

    READ TABLE LT_VBKD INTO WS_VBKD WITH KEY VBELN = WS_ALV-VBELN  "VBKD-BSTKD_E
                                             POSNR = WS_ALV-POSNR.
    IF SY-SUBRC = 0 .
      WS_ALV-BSTKD_E = WS_VBKD-BSTKD_E.
    ELSE.
      READ TABLE LT_VBKD INTO WS_VBKD WITH KEY VBELN = WS_ALV-VBELN"如果没取到,放表头的项目名称
                                               POSNR = '000000'.      "VBKD-BSTKD_E
      IF SY-SUBRC = 0.
        WS_ALV-BSTKD_E = WS_VBKD-BSTKD_E.
      ENDIF.
    ENDIF.

    IF WS_ALV-VRKME = 'KG'.
      READ TABLE I_MARM INTO WS_MARM WITH KEY MATNR = WS_ALV-MATNR.
      IF SY-SUBRC = 0.
        WS_ALV-KWMENG1 = WS_ALV-KWMENG / WS_MARM-UMREZ * WS_MARM-UMREN."段长总长度 = 数量除以分子乘以分母。
      ENDIF.
    ELSE.
      WS_ALV-KWMENG1 = WS_ALV-KWMENG.
    ENDIF.

    READ TABLE I_KONV1 INTO WS_KONV1 WITH KEY KNUMV = WS_ALV-KNUMV
                                              KPOSN = WS_ALV-POSNR
                                              KSCHL = 'ZK01'.
    IF SY-SUBRC = 0.
      IF WS_KONV1-KBETR <> 0.
        WS_ALV-CMPRE1 = '0'.
        WS_ALV-CMPRE = '0'.
        WS_ALV-KZWI1 = '0'.
      ELSE.
        READ TABLE I_KONV1 INTO WS_KONV1 WITH KEY KNUMV = WS_ALV-KNUMV
                                            KPOSN = WS_ALV-POSNR
                                            KSCHL = 'PR01'.
        IF SY-SUBRC = 0.
          WS_ALV-CMPRE1 = WS_KONV1-KBETR /  WS_KONV1-KPEIN. "金额/单位 .
        ENDIF.
      ENDIF.
    ELSE.
      READ TABLE I_KONV1 INTO WS_KONV1 WITH KEY KNUMV = WS_ALV-KNUMV
                                        KPOSN = WS_ALV-POSNR
                                        KSCHL = 'PR01'.
      IF SY-SUBRC = 0.
        WS_ALV-CMPRE1 = WS_KONV1-KBETR /  WS_KONV1-KPEIN. "金额/单位 .
      ENDIF.
    ENDIF.



    PERFORM FRM_READ_TEXT USING WS_ALV-VBELN WS_ALV-POSNR CHANGING WS_ALV-TEXT1.     "读取物料销售文本

    MODIFY I_ALV FROM WS_ALV.
    CLEAR: WS_ALV,WS_ZSDT_SP03.
  ENDLOOP.
  "------------------------------------------
  CLEAR: GW_LAYOUT."它用来定义ALV报表的整体属性
  GW_LAYOUT-CWIDTH_OPT    = 'X'."优化列宽选项是否设置
  GW_LAYOUT-BOX_FNAME = 'SEL'.

  "------------------------------------------------
  L_COUNT = '1'.
  REFRESH GT_DDVAL.  "生产方式下拉框
  LOOP AT I_ALV INTO WS_ALV.
    ADD 2 TO L_COUNT.
    "------------------------------------------------
    CLEAR GW_DDVAL.
    GW_DDVAL-HANDLE = L_COUNT.
    GW_DDVAL-VALUE = '自制'.
    APPEND GW_DDVAL TO GT_DDVAL.

    CLEAR GW_DDVAL.
    GW_DDVAL-HANDLE = L_COUNT.
    GW_DDVAL-VALUE = '外协'.
    APPEND GW_DDVAL TO GT_DDVAL.

    CLEAR GW_DDVAL.
    GW_DDVAL-HANDLE = L_COUNT .
    GW_DDVAL-VALUE = '外购'.
    APPEND GW_DDVAL TO GT_DDVAL.

    CLEAR GW_DDVAL.
    GW_DDVAL-HANDLE = L_COUNT .
    GW_DDVAL-VALUE = '自制外协'.
    APPEND GW_DDVAL TO GT_DDVAL.

    CLEAR GW_DDVAL.
    GW_DDVAL-HANDLE = L_COUNT .
    GW_DDVAL-VALUE = '自制外购'.
    APPEND GW_DDVAL TO GT_DDVAL.
*设置对应
    WS_ALV-DD_HANDLE = L_COUNT."
    MODIFY I_ALV FROM WS_ALV.
  ENDLOOP.
  "------------------------------------------------
  "------------------------------------------------
***------------------------------------------
  L_COUNT1 = '0'.
  REFRESH GT_DDVAL1.  "BOM类型下拉框
  LOOP AT I_ALV INTO WS_ALV.
    ADD 2 TO L_COUNT1.
    "------------------------------------------------
    CLEAR GW_DDVAL1.
    GW_DDVAL1-HANDLE = L_COUNT1.
    GW_DDVAL1-VALUE = '外购'.
    APPEND GW_DDVAL1 TO GT_DDVAL1.

    GW_DDVAL1-HANDLE = L_COUNT1.
    GW_DDVAL1-VALUE = '标准BOM'.
    APPEND GW_DDVAL1 TO GT_DDVAL1.

    CLEAR GW_DDVAL1.
    GW_DDVAL1-HANDLE = L_COUNT1.
    GW_DDVAL1-VALUE = '销售订单BOM'.
    APPEND GW_DDVAL1 TO GT_DDVAL1.

    WS_ALV-DD_HANDLE1 = L_COUNT1.
    MODIFY I_ALV FROM WS_ALV.
  ENDLOOP.
  "------------------------------------------------
  "------------------------------------------------


  REFRESH FIELDCAT.

  FILL_FIELD 'VBELN  '  '销售凭证'  '' '' '' '' '' ''."
  FILL_FIELD 'POSNR  '  '项目'  '' '' '' '' '' ''.
  FILL_FIELD 'MATNR  '  '物料编码'  '' '' ''  '' '' ''.
  FILL_FIELD 'ARKTX  '  '物料描述'  '' '' ''  '' '' ''.
  FILL_FIELD 'WERKS  '  '工厂'  '' '' ''  '' '' ''.
  IF SY-TCODE = 'ZSD027A' AND P_2 = 'X'.
    FILL_FIELD 'ATWRT26'  '生产方式'  '' '10' 'X'  'DD_HANDLE' '' ''."生产部门审批
  ELSE."
    FILL_FIELD 'ATWRT26'  '生产方式'  '' '10' ''  'DD_HANDLE' '' ''."生产部门审批
  ENDIF.
  FILL_FIELD 'BSTKD_E'  '项目名称'  '' '' ''  '' '' ''.
  FILL_FIELD 'KWMENG'  '数量'  '' '' ''  '' '' ''.
  FILL_FIELD 'VRKME'  '数量单位'  '' '' ''  '' '' ''.
  FILL_FIELD 'CMPRE'  '单价'  '' '' ''  '' '' ''.
  FILL_FIELD 'CMPRE1'  '精确单价'  '' '' ''  '' '' ''.
  FILL_FIELD 'KZWI1'  '总价'  '' '' ''  '' '' ''.
  FILL_FIELD 'WAERK'  '价格单位'  '' '' ''  '' '' ''.
  FILL_FIELD 'EDATU'  '交货日期'  '' '' ''  '' '' ''.
  FILL_FIELD 'TEXT1'  '其他备注(行)'  '' '' ''  '' '' ''.

  FILL_FIELD 'ATWRT2'  '型号'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT3'  '电压等级'  '' '' ''  '' '' '' .
  FILL_FIELD 'ATWRT4'  '导体类型'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT5'  '规格'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT6'  '温度等级'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT7'  '颜色'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT8'  '内护形式'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT9'  '结构'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT10'  '强度'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT11'  '锌层等级'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT12'  '执行标准'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT13'  '订单类型'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT14'  '绝缘标识'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT15'  '护套颜色'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT16'  '印字特殊内容'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT17'  '订单技术要求'  '' '' ''  '' '' ''.
  IF SY-TCODE = 'ZSD027B' AND P_2 = 'X'.
    FILL_FIELD 'ATWRT18'  '技术研发部要求'  '' '' 'X' '' 'ZSDT_SP03' 'ATWRT'."技术部门审批   ZSDT_SP03
  ELSE."
    FILL_FIELD 'ATWRT18'  '技术研发部要求'  '' '' '' '' 'ZSDT_SP03' 'ATWRT'."技术部门审批   "
  ENDIF.
*  FILL_FIELD 'ATWRT19'  '每米允许长度公差'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT19'  '客户型号'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT20'  '包装方式'  '' '' ''  '' '' '' .
  FILL_FIELD 'ATWRT21'  '盘具类型'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT22'  '提供资料'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT23'  '段长备注'  '' '' ''  '' '' ''.
  FILL_FIELD 'KWMENG1'  '段长总长度'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT24'  '备注'  '' '' ''  '' '' ''.
  FILL_FIELD 'ATWRT25'  '段总长度'  '' '' ''  '' '' ''.
  IF SY-TCODE = 'ZSD027B' AND P_2 = 'X'..
    FILL_FIELD 'ATWRT27'  'BOM     类 型'  '' '' 'X'  'DD_HANDLE1' '' ''.
  ELSE.
    FILL_FIELD 'ATWRT27'  'BOM     类 型'  '' '' ''  'DD_HANDLE1' '' '' .
  ENDIF.
  FILL_FIELD 'PSTYV'  '类别'  '' '' ''  '' '' ''.

  DATA: LS_EDIT TYPE LVC_S_STYL,
        LT_EDIT TYPE LVC_T_STYL.

  LOOP AT I_ALV INTO WS_ALV.
    IF WS_ALV-PSTYV EQ 'ZINN'."ZINN
      CLEAR:LS_EDIT.
      LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED."控制单行的style显示的
      LS_EDIT-FIELDNAME = 'PSTYV'.
      INSERT LS_EDIT INTO TABLE LT_EDIT.
      LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED."字段不可编辑
      LS_EDIT-FIELDNAME = 'ATWRT18'.
      INSERT LS_EDIT INTO TABLE LT_EDIT.
      LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED."字段不可编辑
      LS_EDIT-FIELDNAME = 'ATWRT27'.
      INSERT LS_EDIT INTO TABLE LT_EDIT.
      LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED."字段不可编辑
      LS_EDIT-FIELDNAME = 'ATWRT26'.
      INSERT LS_EDIT INTO TABLE LT_EDIT.
      INSERT LINES OF LT_EDIT INTO TABLE WS_ALV-STYLE.
      CLEAR:LT_EDIT.
      MODIFY TABLE I_ALV FROM WS_ALV.
    ENDIF.
  ENDLOOP.

  PERFORM CREAT_EVENT_EXITS.

  GW_LAYOUT-STYLEFNAME = 'STYLE'.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID    "SY-REPID  当前程序名
      I_CALLBACK_USER_COMMAND  = 'USER_COMMAND2'
      I_CALLBACK_PF_STATUS_SET = 'PF_STATUS2'
      IS_LAYOUT_LVC            = GW_LAYOUT
      IT_FIELDCAT_LVC          = FIELDCAT[]
      I_SAVE                   = 'A'
      IT_EVENTS                = GT_EVENTS
    TABLES
      T_OUTTAB                 = I_ALV
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  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  USER_COMMAND2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->UCOMM        text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM USER_COMMAND2 USING UCOMM  LIKE SY-UCOMM
                        RS_SELFIELD TYPE SLIS_SELFIELD.     "#EC CALLED
  DATA: L_VALID  TYPE CHAR01.
  DATA: LS_ZSDT_SP03 TYPE ZSDT_SP03.
  DATA: LT_ZSDT_SP05 TYPE TABLE OF ZSDT_SP05.
  DATA: LS_ZSDT_SP05 TYPE  ZSDT_SP05.
  REFRESH:LT_ZSDT_SP05.
  CLEAR:LS_ZSDT_SP05.
  SELECT * INTO TABLE LT_ZSDT_SP05 FROM ZSDT_SP05.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'  "刷新ALV
    IMPORTING
      E_GRID = G_GRID.
  CALL METHOD G_GRID->CHECK_CHANGED_DATA
    IMPORTING
      E_VALID = L_VALID.
  IF L_VALID IS INITIAL.
    EXIT.
  ENDIF.
  CASE UCOMM.
    WHEN 'SAVE'.
      IF SY-TCODE = 'ZSD027A'."生产审批
        LOOP AT I_ALV INTO WS_ALV.
          LS_ZSDT_SP03-VBELN = WS_ALV-VBELN.
          LS_ZSDT_SP03-POSNR = WS_ALV-POSNR.
          LS_ZSDT_SP03-ZTXBM = 'L26'.
          LS_ZSDT_SP03-ATWRT = WS_ALV-ATWRT26.
          READ TABLE LT_ZSDT_SP05 INTO LS_ZSDT_SP05 WITH KEY ZTXBM = LS_ZSDT_SP03-ZTXBM.
          IF SY-SUBRC = 0.
            LS_ZSDT_SP03-ATNAM = LS_ZSDT_SP05-ATNAM.
          ENDIF.
          MODIFY ZSDT_SP03 FROM LS_ZSDT_SP03.
          COMMIT WORK.
        ENDLOOP.
        MESSAGE '保存成功!' TYPE 'I'.
      ELSEIF SY-TCODE = 'ZSD027B'."技术审批
        LOOP AT I_ALV INTO WS_ALV."保存技术研发部要求

          LS_ZSDT_SP03-VBELN = WS_ALV-VBELN.
          LS_ZSDT_SP03-POSNR = WS_ALV-POSNR.
          LS_ZSDT_SP03-ZTXBM = 'L18'.
          LS_ZSDT_SP03-ATWRT = WS_ALV-ATWRT18.
          READ TABLE LT_ZSDT_SP05 INTO LS_ZSDT_SP05 WITH KEY ZTXBM = LS_ZSDT_SP03-ZTXBM.
          IF SY-SUBRC = 0.
            LS_ZSDT_SP03-ATNAM = LS_ZSDT_SP05-ATNAM.
          ENDIF.
          MODIFY ZSDT_SP03 FROM LS_ZSDT_SP03.
        ENDLOOP.

        LOOP AT I_ALV INTO WS_ALV."保存BOM类型
          IF WS_ALV-ATWRT26 = '自制' AND WS_ALV-ATWRT27 = '外购'.
            MESSAGE '保存数据有误' TYPE 'E'.
            RETURN.
          ELSE.
            LS_ZSDT_SP03-VBELN = WS_ALV-VBELN.
            LS_ZSDT_SP03-POSNR = WS_ALV-POSNR.
            LS_ZSDT_SP03-ZTXBM = 'L27'.
            LS_ZSDT_SP03-ATWRT = WS_ALV-ATWRT27.
            READ TABLE LT_ZSDT_SP05 INTO LS_ZSDT_SP05 WITH KEY ZTXBM = LS_ZSDT_SP03-ZTXBM.
            IF SY-SUBRC = 0.
              LS_ZSDT_SP03-ATNAM = LS_ZSDT_SP05-ATNAM.
            ENDIF.
            MODIFY ZSDT_SP03 FROM LS_ZSDT_SP03.
          ENDIF.
        ENDLOOP.

        MESSAGE '保存成功!' TYPE 'I'.
      ENDIF.
*    WHEN '&IC1'.
*      IF RS_SELFIELD-FIELDNAME = 'ATWRT18'."双击全部填充
*        READ TABLE I_ALV INTO WS_ALV INDEX RS_SELFIELD-TABINDEX.
**        READ TABLE I_ALV INTO WS_ALV INDEX RS_SELFIELD-VALUE.      "双击单元格的值(内容)
*        CHECK WS_ALV-ATWRT18 IS NOT INITIAL.
*
*        LOOP AT I_ALV INTO WS_ALV.
*          WS_ALV-ATWRT18 = RS_SELFIELD-VALUE.
*          MODIFY I_ALV FROM WS_ALV.
*        ENDLOOP.
*      ENDIF.
  ENDCASE.
  CLEAR:UCOMM.

  RS_SELFIELD-REFRESH    = 'X'.
  RS_SELFIELD-COL_STABLE = 'X'.
  RS_SELFIELD-ROW_STABLE = 'X'.
ENDFORM.                    "USER_COMMAND2
*&---------------------------------------------------------------------*
*&      Form  PF_STATUS2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM PF_STATUS2 USING LT_EXTAB.
  IF P_1 = 'X'.
    SET PF-STATUS 'MENU7'.
  ELSE.
    SET PF-STATUS 'MENU6'.
  ENDIF.
ENDFORM.                    " PF_STATUS2
*&---------------------------------------------------------------------*
*&      Form  FRM_READ_TEXT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_READ_TEXT   USING    P_ALV_VBELN
                              P_ALV_POSNR CHANGING P_ALV_TEXT1.
  DATA: LINES TYPE STANDARD TABLE OF TLINE WITH HEADER LINE.
  DATA:LV_NAME  TYPE C LENGTH 70.

  CONCATENATE P_ALV_VBELN  P_ALV_POSNR INTO LV_NAME.
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      ID                      = 'Z153'
      LANGUAGE                = SY-LANGU
      NAME                    = LV_NAME
      OBJECT                  = 'VBBP'
    TABLES
      LINES                   = LINES
    EXCEPTIONS
      ID                      = 1
      LANGUAGE                = 2
      NAME                    = 3
      NOT_FOUND               = 4
      OBJECT                  = 5
      REFERENCE_CHECK         = 6
      WRONG_ACCESS_TO_ARCHIVE = 7
      OTHERS                  = 8.
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

  IF SY-SUBRC EQ 0.
    LOOP AT  LINES.
      CONCATENATE P_ALV_TEXT1 LINES-TDLINE INTO LINES-TDLINE.
      P_ALV_TEXT1 = LINES-TDLINE.
      CLEAR:LINES-TDLINE.
    ENDLOOP.
    "ELSE.
    " MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  CREAT_EVENT_EXITS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CREAT_EVENT_EXITS .
  GW_EVENTS-NAME = 'CALLER_EXIT'.
  GW_EVENTS-FORM = 'CALLER_EXIT'.
  APPEND GW_EVENTS TO GT_EVENTS.
*  GW_EVENTS-NAME = 'CALLER_EXIT1'.
*  GW_EVENTS-FORM = 'CALLER_EXIT1'.
*  APPEND GW_EVENTS TO GT_EVENTS.
ENDFORM.
*---------------------------------------------------------------------*
*设置下拉列表,使Grid和内表能链接上
*---------------------------------------------------------------------*
FORM CALLER_EXIT USING LS_DATA TYPE SLIS_DATA_CALLER_EXIT.
  DATA: L_REF_ALV TYPE REF TO CL_GUI_ALV_GRID.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = L_REF_ALV.
  CALL METHOD L_REF_ALV->SET_DROP_DOWN_TABLE
    EXPORTING
      IT_DROP_DOWN = GT_DDVAL.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = L_REF_ALV.
  CALL METHOD L_REF_ALV->SET_DROP_DOWN_TABLE
    EXPORTING
      IT_DROP_DOWN = GT_DDVAL1.
ENDFORM.                    "CALLER_EXIT1

0 人点赞