ABAP SQL动态选择字段

话不多说,直接上码。有兴趣的同学可以自己试下

 

 

  TYPES:
    BEGIN OF typ_cossp,
      objnr  TYPE coss-objnr,
      kstar  TYPE coss-kstar,
      wkgxxx TYPE wkgxxx,
    END OF typ_cossp.

  DATA: BEGIN OF lt_fields OCCURS 0,
          fieldname(30) TYPE c,
        END OF lt_fields.
  DATA:
    lw_wkgxxx(6) TYPE c,
    lt_cossp     TYPE STANDARD TABLE OF typ_cossp.

  CONCATENATE 'WKG' p_perio INTO lw_wkgxxx.
  lt_fields-fieldname = 'OBJNR'.
  APPEND lt_fields.
  lt_fields-fieldname = 'KSTAR'.
  APPEND lt_fields.
  lt_fields-fieldname = lw_wkgxxx.
  APPEND lt_fields.

  SELECT (lt_fields)
    FROM coss
    INTO TABLE lt_cossp
   WHERE objnr IN rt_objnr        " 对象号
     AND gjahr = p_gjahr          " 财年
     AND wrttp =  '04'            " 值类型
     AND versn = '000'.            " 版本
  SELECT (lt_fields)
    FROM cosp
    APPENDING TABLE lt_cossp
   WHERE objnr IN rt_objnr        " 对象号
     AND gjahr = p_gjahr          " 财年
     AND wrttp =  '04'            " 值类型
     AND versn = '000'.            " 版本
*    %_HINTS HDB 'INDEX("COSP" "COSP~1")'.

 

posted @ 2018-08-23 19:06  陈一清  阅读(2453)  评论(0编辑  收藏  举报