首页 > 其他分享 >S4新语法汇总

S4新语法汇总

时间:2024-04-12 17:34:08浏览次数:21  
标签:GT 汇总 NUMBER S4 语法 LT MATNR DATA OUT

*&---------------------------------------------------------------------*
*& Report ZABAPS4
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZABAPS4.


TYPES: BEGIN OF TY_OUT,
         MATNR TYPE MARA-MATNR,
         MAKTX TYPE MAKT-MAKTX,
       END OF TY_OUT.

DATA: GT_OUT TYPE TABLE OF TY_OUT,
      GS_OUT TYPE TY_OUT,
      GT_TMP TYPE TABLE OF TY_OUT,
      GS_TMP TYPE TY_OUT.

**********************************内嵌声明

*构建工作区
GS_OUT = VALUE #( MATNR = '1000001'
                  MAKTX = '物料描述' ).

*构建内表
GT_OUT = VALUE #( ( MATNR = '1000001' MAKTX = '物料描述1'  )
                  ( MATNR = '1000002' MAKTX = '物料描述2'  ) ).

*内表追加数据
GT_OUT = VALUE #( BASE GT_OUT (  MATNR = '1000003' MAKTX = '物料描述3' ) ).

*定义变量
DATA(LV_DATUM) = SY-DATUM.

*定义内表和工作区
DATA(LS_OUT) = GS_OUT.
DATA(LT_OUT) = GT_OUT.





**********************************SELECT新特性

DATA LV_MATNR TYPE MARA-MATNR.

*直接取数定义局部内表
SELECT MATNR,ERSDA,ERNAM,MTART,MATKL
  FROM MARA
  INTO TABLE @DATA(LT_MARA)
 WHERE MATNR = @LV_MATNR.

IF LT_MARA IS NOT INITIAL.
  SELECT MATNR, MAKTX
    FROM MAKT
    INTO TABLE @DATA(LT_MAKT)
    FOR ALL ENTRIES IN @LT_MARA
    WHERE MATNR = @LT_MARA-MATNR.
ENDIF.



*WITH 替换 FOR ALL ENTRY IN
CLEAR LT_MAKT.
WITH +DATA AS ( SELECT FROM MARA AS A
                       FIELDS A~MATNR
                       WHERE MATNR = '000000000000000104' )
SELECT FROM +DATA INNER JOIN MAKT AS B
ON +DATA~MATNR = B~MATNR
FIELDS B~MATNR,B~MAKTX
INTO TABLE @LT_MAKT
.


*SUBSTRING  SQL中截取字段任意长度 注意某些情况INTO需要写在SQL最后面 否则会报错
CLEAR LT_MARA.
SELECT SUBSTRING( MATNR,1,5 ) AS MATNR,ERSDA,ERNAM,MTART
  FROM MARA
 WHERE MATNR = @LV_MATNR
    INTO TABLE @LT_MARA.

*SQL中默认值
CLEAR LT_MARA.
SELECT MATNR,
       ERSDA,
   'Yangchao'AS ERNAM,
       MTART,
       MATKL
  FROM MARA
  INTO TABLE @LT_MARA
 WHERE MATNR =  '000000000000000104' .





**********************************内表操作
*字段字段相同
GS_TMP = CORRESPONDING #( GS_OUT ).
GT_TMP = CORRESPONDING #( GT_OUT ).


*字段名相同赋值 并且指定字段复制到特定字段上
CLEAR GS_TMP.
GS_TMP = CORRESPONDING #( GS_OUT MAPPING MATNR = MAKTX ).


*EXCEPT时是将EXCEPT的字段置为空而不是不赋值
CLEAR GS_TMP.
GS_TMP = CORRESPONDING #( GS_OUT EXCEPT MAKTX ).

CLEAR GT_TMP.
GT_TMP = CORRESPONDING #( GT_OUT EXCEPT MAKTX ).


*找出满足条件的数据 使用操作符FILTER过滤
DATA  GT_FILTER TYPE HASHED TABLE OF TY_OUT
                  WITH UNIQUE KEY MATNR.
GT_FILTER = VALUE #( ( MATNR = '1000001' MAKTX = '物料描述1')
                     ( MATNR = '1000005' MAKTX = '物料描述5') ).

*找出GT_OUT在GT_FILTER里的
CLEAR GT_TMP.
GT_TMP = FILTER #( GT_OUT IN GT_FILTER WHERE MATNR = MATNR ) .


"找出GT_OUT不在GT_FILTER里的
CLEAR GT_TMP.
GT_TMP = FILTER #(  GT_OUT EXCEPT IN GT_FILTER WHERE MATNR = MATNR ) .



*判断某一行数据是否存在
IF LINE_EXISTS( GT_OUT[ 2 ] ).
MESSAGE 'OK' TYPE 'S'.
ENDIF.

*获取第N行的记录
CLEAR GS_OUT.
GS_OUT = GT_OUT[ 2 ].

*互获取第N行的某个字段
DATA(LV_MAKTX) = GT_OUT[ 2 ]-MAKTX."标签类型

"内表中符合条件的数据有几条
DATA(LV_LINE) = REDUCE I( INIT X = 0
                             FOR  GS_LINES IN GT_OUT WHERE ( MATNR = '1000001' )
                          NEXT X = X + 1 ).



*计算内表行数
DATA(LV_LINES) = LINES( GT_OUT ).

*增加前导0  删除前导0
DATA LV_VBELN TYPE VBAK-VBELN VALUE '000010001'.

LV_VBELN = |{ LV_VBELN ALPHA = OUT }| .
LV_VBELN = |{ LV_VBELN ALPHA = IN }| .

*拼接
DATA LV_STR TYPE STRING.
LV_STR = |{ '系统日期'}{ SY-DATUM }{ '系统时间'}{ SY-UZEIT }| .

*通过REDUCE汇总
TYPES:BEGIN OF TY_DATA,
        NUMBER       TYPE C,
        PRICE        TYPE FINS_VOCUR12,
        CATEGORY(20) TYPE C,
      END OF TY_DATA.
DATA: LT_DATA TYPE TABLE OF TY_DATA,
      LT_SUM1 TYPE TABLE OF TY_DATA.

LT_DATA = VALUE #(
          ( NUMBER = 'a' PRICE = 2 CATEGORY = 'xxx')
          ( NUMBER = 'a' PRICE = 2 CATEGORY = 'xxx')
          ( NUMBER = 'a' PRICE = 2 CATEGORY = 'xxx')
          ( NUMBER = 'b' PRICE = 3 CATEGORY = 'xxx')
          ( NUMBER = 'b' PRICE = 3 CATEGORY = 'AAA')
          ( NUMBER = 'b' PRICE = 3 CATEGORY = 'AAA')
          ( NUMBER = 'b' PRICE = 3 CATEGORY = 'AAA')
          ( NUMBER = 'c' PRICE = 4 CATEGORY = 'AAA')
          ( NUMBER = 'c' PRICE = 4 CATEGORY = 'AAA')
          ( NUMBER = 'c' PRICE = 4 CATEGORY = 'AAA')
          ( NUMBER = 'c' PRICE = 4 CATEGORY = 'AAA')
          ).



SELECT NUMBER,SUM( PRICE ) AS PRICE
  FROM @LT_DATA AS A
  GROUP BY NUMBER
  ORDER BY NUMBER ASCENDING
  INTO TABLE @DATA(LT_SUM2).


LT_SUM2 = VALUE #(
( NUMBER = 'a')
( NUMBER = 'b' )
( NUMBER = 'c' ) ).


LOOP AT LT_SUM2  ASSIGNING FIELD-SYMBOL(<FS_SUM2>).

  <FS_SUM2>-PRICE = REDUCE #( INIT LV_PRICE TYPE FINS_VOCUR12
                         FOR LS_DATA IN LT_DATA
                         WHERE ( NUMBER = <FS_SUM2>-NUMBER )
                         NEXT LV_PRICE = LV_PRICE + LS_DATA-PRICE ).
ENDLOOP.


*LOOP AT GROUP替代AT NEW.
DATA: LT_COLLECT TYPE TABLE OF TY_DATA,
      LS_COLLECT TYPE TY_DATA.
*根据NUMBER分组跑逻辑
LOOP AT LT_DATA ASSIGNING FIELD-SYMBOL(<FS_DATA>) GROUP BY ( NUMBER = <FS_DATA>-NUMBER
*                                                              SIZE = GROUP SIZE"分组组数"
*                                                             INDEX = GROUP INDEX  "分组的组序号"
  )
  ASCENDING ASSIGNING FIELD-SYMBOL(<GROUP>).
  LOOP AT GROUP <GROUP> ASSIGNING FIELD-SYMBOL(<FS_GROUP>).


  ENDLOOP.
ENDLOOP.








**********************************指针
*循环中直接定义工作区/指针
LOOP AT GT_OUT INTO DATA(LW_OUT).

ENDLOOP.

LOOP AT GT_OUT ASSIGNING FIELD-SYMBOL(<FS_OUT>).

ENDLOOP.


READ TABLE GT_OUT INTO DATA(LW_OUT1) INDEX 1.

READ TABLE GT_OUT ASSIGNING FIELD-SYMBOL(<FS_OUT1>) INDEX 1.



BREAK-POINT.

 

标签:GT,汇总,NUMBER,S4,语法,LT,MATNR,DATA,OUT
From: https://www.cnblogs.com/Anyohh233/p/18131759

相关文章

  • uniapp做微信小程序遇到的一些问题汇总
    1.当我写完代码想手机预览的时候,小程序的启用组件按需注入显示未通过 加一句搞定//启用组件按需注入问题  "lazyCodeLoading":"requiredComponents", 2.微信开发者工具-右上角-详情-基本信息-代码依赖分析-可以看哪些文件比较大(如static下不超过200K,一般情况图片都......
  • 02 Vue3核心语法
    选项式APIOptionsAPI和组合式APICompositionAPIVue2的API设计是Options(配置)风格的,就是选项式APIVue3的API设计是Composition(组合)风格的,就是组合式API选项式API的弊端Options类型的API,数据、方法、计算属性等,是分散在:data、methods、computed中的,若想新增或者修改一个需......
  • Vue卡壳问题汇总
    上传文件问题(特别注意同步和异步请求)-手动构造'数组对象'发送给后端,后端可以正常接收-选取excel文件并读取,构造'数组对象'发送给后端,后端只收到一个空list -原因如下:读取excel函数的逻辑是异步请求,还没等数据处理完,请求就发给后端了,造成以上结果uploadHttpReq......
  • LaTeX语法入门
    引言TeX是由DonaldKnuth创造的基于底层编程语言的电子排版系统(TEX是Honeywell公司在1980年为其TextExecutive文本处理系统注册的商标,它与TeX是两回事)。使用TeX可以对版面做精细的操作,生成精美的文档。TeX提供版面编辑的底层命令,但是使用时操作复杂,工作效率不高.TeX允许用这......
  • Markdown常用语法
    常用语法Markdown语法详解快捷键效果*斜体*无Ctrl/⌘+I斜体粗体无Ctrl/⌘+B粗体#一级标题"#"后需加空格无无##二级标题以此类推三级标题为三个“#”无无[链接](http://a)“[]”间为显示的超文本Ctrl/⌘+K链接![图片](http://url/a.png)“[]”间为图片名Ctrl/⌘+......
  • 【Shell】if选择结构语法实例
    if结构用于在Shell脚本中进行判定。如果指定的条件为真,则执行指定的命令。if和then若写在同一行,then与语句之间要使用分号“;”隔开。if语句结构一定要以“fi”结尾。1.单分支结构语法格式ifconditionthencommand1command2...commandNfi......
  • 第二节:C#12新语法(主构造函数、集合表达式、默认Lambda参数)
    一.        二.        三.         !作       者:Yaopengfei(姚鹏飞)博客地址:http://www.cnblogs.com/yaopengfei/声     明1:如有错误,欢迎讨论,请勿谩骂^_^。声     明2:原创博客请在转载......
  • JavaScript Array方法汇总
    函数名定义返回值是否改变原数组是否生成新数组push向数组的末尾添加一个或多个元素返回新的数组长度是否pop删除并返回数组的最后一个元素返回数组的最后一个元素是否unshift向数组的开头添加一个或多个元素返回新的数组长度是否shift删除数组的第一项返回第一个元素的值。若......
  • JavaScript String方法汇总
    方法名定义返回值是否改变原字符串是否生成新字符串charAt()查找指定位置的元素返回元素否否concat()连接两个或多个字符串返回连接后的字符串否是indexOf()indexOf()方法可返回某个指定的字符串值在字符串中首次出现的位置。如果没有找到匹配的字符串则返回-1。返回查找到的......
  • Python基础语法
    1.常用数据类型2.注释单行注释#需要注释的内容多行注释"""需要注释的内容"""3.变量定义变量名=变量值type()查看数据类型type(需查看类型的数据)4.类型转换类型转换代码int(x)#将x转换成整型float(x)#将x转换成浮点型str(x)#将x转换成字......