SAP SRM ABAP编程限制用户仅在字段中输入有效值

时间:2016-11-25 19:31:58

标签: sap abap

我编写了程序来显示SRM服务器中的购物车(SC)详细信息。 在我的程序中,我将验证放在select -options上。它工作正常,但是如果我为sc提供任何随机范围,例如9990000000到9999999999,则应该显示此范围之间的所有SC,但它会抛出错误消息,因为我在低值和高值上保持验证。因此,我的培训师表示,对选择选项进行验证并不可取。他给了我新的任务,除了做验证之外,我应该限制用户只输入输入字段的有效值。我怎样才能做到这一点?请给我完整的代码。

DATA : lv_shc TYPE crmd_orderadm_h-object_id .
*DATA : lv_shc TYPE z_obj_id.

SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-111.
*SELECT-OPTIONS : s_shc FOR crmd_orderadm_h-object_id VALUE-REQUEST.
SELECT-OPTIONS : s_shc FOR lv_shc .
SELECTION-SCREEN END OF BLOCK a1.

INCLUDE zsrmi_declarations1.

*validations.
AT SELECTION-SCREEN ON s_shc .


  IF s_shc IS NOT INITIAL.
    IF s_shc-low IS NOT INITIAL.
      SELECT SINGLE object_id FROM crmd_orderadm_h INTO lv_shc WHERE object_id = s_shc-low AND object_type = 'BUS2121'.
      IF sy-subrc <> 0.
        MESSAGE text-001 TYPE 'E'.
        EXIT.
      ENDIF.
    ENDIF.
    IF s_shc-high IS NOT INITIAL.
      SELECT SINGLE object_id FROM crmd_orderadm_h INTO lv_shc WHERE object_id = s_shc-high AND object_type = 'BUS2121'.
      IF sy-subrc <> 0.
        MESSAGE text-001 TYPE 'E'.
        EXIT.
      ENDIF.
    ENDIF.
  ENDIF.

1 个答案:

答案 0 :(得分:0)

您应该针对范围而不是谨慎的值进行验证:

AT SELECTION-SCREEN ON s_shc.

    IF s_shc[] IS NOT INITIAL.

        SELECT COUNT( * )
        FROM crmd_orderadm_h 
        WHERE object_id IN s_shc[] AND object_type = 'BUS2121'.

        IF SY-SUBRC NE 0.
            MESSAGE e000 WITH 'Enter Valid SC Number'.
            EXIT.
        ENDIF.

    ENDIF.

应该使用相同的查询来获取记录。