• ABAP语法


      新语法~*  可以用来取值一个表中的所有数据和一个表中的部分数据
        示例如下
    REPORT ZSQL.
    
    TYPES:
      BEGIN OF TY_VBAP,
        MATNR TYPE VBAP-MATNR,
        MAKTX TYPE MAKT-MAKTX.
            INCLUDE STRUCTURE VBAK.
    TYPES END OF TY_VBAP.
    DATA : GT_VBAP TYPE TABLE OF TY_VBAP,
           GW_VBAP TYPE TY_VBAP.
    SELECT VBAP~MATNR,
           MAKT~MAKTX,
           VBAK~*
          FROM VBAK
         INNER JOIN VBAP ON VBAK~VBELN = VBAP~VBELN
         INNER JOIN MAKT ON VBAP~MATNR = VBAP~MATNR AND SPRAS = @SY-LANGU
      UP TO 10 ROWS
      INTO CORRESPONDING FIELDS OF TABLE @GT_VBAP.
    
    LOOP AT GT_VBAP INTO GW_VBAP .
      WRITE: GW_VBAP-VBELN ,GW_VBAP-MATNR, GW_VBAP-MAKTX.
      SKIP 1 .
    ENDLOOP.

    2018.03.31  “取域值

      SELECT SINGLE ddtext INTO p_sczt FROM dd07t
         WHERE domname = p_domname
           AND domvalue_l = p_domvalue_l.

    2018.04.07 取值AL11 的文件目录

    DATA:FILE TYPE ESEFTAPPL VALUE 'gettabledata.txt'.
    
    CALL 'C_SAPGPARAM' ID 'NAME'  FIELD 'DIR_HOME'
                       ID 'VALUE' FIELD FILE.
      Append lines of itab1 [ from n1 ] [ to n2 ] to itab2.
    把内表 itab1 的 n1 到 n2 行内容附加到 itab2 内表中去.
    前提是 itab1 与 itab2 结构完成相同.
      LOOP AT  itab1 INTO DATA(WA).
         WRITE WA-MATNR .
      ENDLOOP.
      LOOP AT ITAB1 ASSIGNING FIELD-SYMBOL(<FS>).
        
      ENDLOOP.

     20180608

    根据一个内表的某个或某几个字段,取出其他内表的数据

    REPORT YTEST_FILTER.
    TYPES:BEGIN OF TY_SPFLI,
       CARRID TYPE spfli-CARRID,
       END OF TY_SPFLI.
    ****需要定义为排序表或者哈希表 因为需要主键
       DATA IT_TAB TYPE SORTED TABLE OF TY_SPFLI WITH UNIQUE KEY CARRID.
       DATA IT_SPLFI TYPE TABLE OF SPFLI .
       DATA IT_SPLF1 TYPE TABLE OF SPFLI .
       DATA IT_SPLF2 TYPE TABLE OF SPFLI .
    
    ****定义参考表的实际数据
       IT_TAB = VALUE #( ( CARRID = 'AA'  )  ( CARRID = 'UA'   ) ) .
    
       SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE IT_SPLFI.
    
    ****取到实际表中的数据
       IT_SPLF1 = FILTER #( IT_SPLFI IN IT_TAB WHERE CARRID = CARRID   )  .
    
    ****显示
      CL_DEMO_OUTPUT=>DISPLAY( IT_TAB ) .
    
       CL_DEMO_OUTPUT=>DISPLAY( IT_SPLFI ).
       CL_DEMO_OUTPUT=>DISPLAY( IT_SPLF1 ).

     ********ADD BY CHENHD 20180731  关于 WITH KEY 与 WITH TABLE KEY 的区别。
    对于标准表 两者是相同的,对于排序表,前者是线性查找,后者是二分法查找。

    1) READ TABLE <ITAB> WITH KEY
             This statement always search in linear fashion.
             You can use this syntax for any type of table(standard, sorted, hased)
    2) READ TABLE <ITAB> WITH TABLE KEY
             you can use this syntax only for internal table with primary keys defined
             For standard table - Linear search will be used
             For sorted table - Binary search will be used.
             For Hashed table - Hashing algorithm will be used.

    REPORT 1 .
    
    *TYPES:
    *    BEGIN OF TY_OUT_TAB,
    *      VBELN TYPE VBAP-VBELN,
    *      POSNR TYPE VBAP-POSNR,
    *      MATNR TYPE VBAP-MATNR,
    *     END OF  TY_OUT_TAB.
    * DATA :IT_TAB TYPE SORTED TABLE OF TY_OUT_TAB WITH UNIQUE  KEY  VBELN POSNR .
    *
    *  DATA WA_TAB TYPE TY_OUT_TAB.
    *
    * select vbeln posnr matnr FROM vbap into CORRESPONDING FIELDS OF TABLE IT_TAB UP TO 10 ROWS .
    *   IF sy-subrc = 0..
    *
    *   ENDIF.
    
    *
    *TYPES:
    *    BEGIN OF TY_OUT_TAB,
    *      COL1 TYPE char20,
    *      COL2 TYPE char20,
    *      matnr TYPE char20,
    *     END OF  ty_out_tab.
    * data :IT_TAB TYPE SORTED TABLE OF TY_OUT_TAB WITH UNIQUE  KEY  COL1 COL2 .
    *
    *  DATA WA_TAB TYPE TY_OUT_TAB.
    *
    *
    *
    *  wa_tab-COL1 = 'A2'.
    *  wa_tab-COL2 = 'AB'.
    *  wa_tab-matnr = 'AC'.
    *  APPEND WA_TAB TO IT_TAB.
    *
    *
    *
    *  wa_tab-COL1 = 'A1'.
    *  wa_tab-COL2 = 'AB'.
    *  wa_tab-matnr = 'AC'.
    *  APPEND WA_TAB TO IT_TAB.
    *
    *
    *  WA_TAB-COL1 = 'AA' .
    *  WA_TAB-COL2 = 'AB' .
    *  WA_TAB-MATNR = 'A1' .
    *
    *APPEND WA_TAB TO IT_TAB .
    *IF SY-SUBRC = 0..
    *
    *ENDIF.
    
    *  SELECT
    *         VBELN
    *         POSNR
    *         MATNR
    *     FROM VBAP
    *     INTO CORRESPONDING FIELDS OF TABLE
    *     IT_TAB UP TO 1000 ROWS .
    *
    *   IF SY-SUBRC = 0..
    *
    *   ENDIF.
    *
    *
    *
    *READ TABLE IT_TAB INTO WA_TAB  WITH KEY VBELN = '0001000021'.
    * IF SY-SUBRC = 0 .
    *
    * ENDIF.
    
    
    TYPES:
        BEGIN OF TY_OUT_TAB,
          VBELN TYPE CHAR20,
          POSNR TYPE CHAR20,
          MATNR TYPE CHAR20,
         END OF  TY_OUT_TAB.
     DATA :IT_TAB TYPE SORTED TABLE  OF TY_OUT_TAB  WITH UNIQUE KEY VBELN POSNR .
     DATA :GT_TAB TYPE TABLE OF TY_OUT_TAB  .
    
      DATA WA_TAB TYPE TY_OUT_TAB.
    
    
    
      WA_TAB-VBELN = 'B2'.
      WA_TAB-POSNR = 'AB'.
      WA_TAB-MATNR = 'AC'.
      APPEND WA_TAB TO IT_TAB.
    
    
      WA_TAB-VBELN = 'AA'.
      WA_TAB-POSNR = 'AD'.
      WA_TAB-MATNR = 'AC'.
    *  APPEND WA_TAB TO IT_TAB .
      INSERT WA_TAB INTO IT_TAB INDEX 1..
    
    
      WA_TAB-VBELN = 'A0' .
      WA_TAB-POSNR = 'AB' .
      WA_TAB-MATNR = 'A1' .
    
    *APPEND WA_TAB TO IT_TAB .
      INSERT WA_TAB INTO TABLE IT_TAB .
    
    * CL_DEMO_OUTPUT=>DISPLAY( IT_TAB ) .
    
    
    * SORT IT_TAB ASCENDING BY VBELN DESCENDING POSNR.
    * SORT IT_TAB BY VBELN POSNR.
     CHECK SY-SUBRC = 0.
    * SORT IT_TAB BY VBELN POSNR ASCENDING.
    * SORT IT_TAB ASCENDING BY VBELN DESCENDING POSNR.
    
    * CL_DEMO_OUTPUT=>DISPLAY( IT_TAB ) .
    
     INSERT WA_TAB INTO TABLE IT_TAB.
     IF SY-SUBRC = 0.
    
     ENDIF.
    
    READ TABLE IT_TAB INTO WA_TAB WITH TABLE KEY VBELN = 'A0' POSNR = 'AB'.
     IF SY-SUBRC = 0.
    
     ENDIF.
    
    
    * MOVE IT_TAB TO GT_TAB .
    *
    * INSERT LINES OF GT_TAB INTO IT_TAB INDEX 1..
    * IF SY-SUBRC = 0.
    *
    * ENDIF.
    
    
    
    
    
    
    *IF SY-SUBRC = 0..
    *
    *ENDIF.

    ***去除后置0

    REPORT TEST_STRING .

    DATA(LV_NUM'23.012000'.
     LV_NUM  = shift_right( val = LV_NUM sub = |0| ).
     WRITE LV_NUM.

     
  • 相关阅读:
    BZOJ2530 : [Poi2011]Party
    BZOJ3998 : [TJOI2015]弦论
    BZOJ3941 : [Usaco2015 Feb]Fencing the Herd
    BZOJ3939 : [Usaco2015 Feb]Cow Hopscotch
    搬家啦~
    BZOJ3837 : [Pa2013]Filary
    使用Privoxy做智能代理切换
    放弃iOS4,拥抱iOS5
    让Xcode的 stack trace信息可读
    改进iOS客户端的升级提醒功能
  • 原文地址:https://www.cnblogs.com/hdchen/p/8349994.html
Copyright © 2020-2023  润新知