matinal:SAP ABAP 7.40及以上新语法全新总结

1.1 Inline declarations

Data Declarations

In ABAP you have many operand positions, where the value of the operand is changed by the statement. The most typical of these "write positions" is the left hand side lhs of an assignment.

lhs = rhs.

But of course there are more. The data objects you can use at these write positions are either writable formal parameters of the procedure you are working in or variables declared with DATA in front of the statement.

In many cases the variables filled by a statement are helper variables that you only need close to the statement. For each of  these helper variables you had to write a data declaration with the DATA statement and of course it was your task to give the variable an adequate type.

Well, the operand type of most write positions is statically fixed and well known to the compiler. And this is why ABAP can offer inline data declarations with Release 7.40. The ingredients are so called declaration positions (write positions with fully known operand type)  and the new declaration operator DATA(...).

Let's look at some examples.

Declaration of a lhs-variable for a simple assignment

Before 7.40

DATA text TYPE string.
text = `...`.

With 7.40

DATA(text) = `...`.

Declaration of table work areas

Before 7.40

DATA wa like LINE OF itab.
LOOP AT itab INTO wa.  
  ...
ENDLOOP.

With 7.40

LOOP AT itab INTO DATA(wa).  
  ...
ENDLOOP.

Declaration of a helper variable

Before 7.40

DATA cnt TYPE i.
FIND ... IN ... MATCH COUNT cnt.

With 7.40

FIND ... IN ... MATCH COUNT DATA(cnt).

Declaration of a result

Before 7.40

DATA xml TYPE xstring.
CALL TRANSFORMATION ... RESULT XML xml.

With 7.40

CALL TRANSFORMATION ... RESULT XML DATA(xml).

Declaration of actual parameters

Before 7.40

DATA a1 TYPE ...

DATA a2 TYPE ...

oref->meth( IMPORTING p1 = a1  IMPORTING p2 = a2  ... )

     

With 7.40

oref->meth( IMPORTING p1 = DATA(a1)  IMPORTING p2 = DATA(a2)  ... ).

Declaration of reference variables for factory methods

Before 7.40

DATA ixml           TYPE REF TO if_ixml.
DATA stream_factory TYPE REF TO if_ixml_stream_factory.
DATA document       TYPE REF TO if_ixml_document.

ixml           = cl_ixml=>create( ).
stream_factory = ixml->create_stream_factory( ).
document       = ixml->create_document( ).

With 7.40

DATA(ixml)           = cl_ixml=>create( ).
DATA(stream_factory) = ixml->create_stream_factory( ).
DATA(document)       = ixml->create_document( ).

Field Symbols

For field symbols there is the new declaration operator FIELD-SYMBOL(...) that you can use at exactly three declaration positions.

ASSIGN ... TO FIELD-SYMBOL(<fs>).

LOOP AT itab ASSIGNING FIELD-SYMBOL(<line>).
...
ENDLOOP.

READ TABLE itab ASSIGNING FIELD-SYMBOL(<line>) ...

I guess it is clear to you what happens here.

Outlook

In my upcoming blogs I will make use of inline declarations when introducing other new features. Be prepared for code like this:

TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.

DATA(itab) = VALUE t_itab( ( 1 ) ( 2 ) ( 3 ) ).

Yes, this is ABAP 7.40 ...

1.2 Constructor expression CORRESPONDING

MOVE-CORRESPONDING FOR Internal Tables

You can use MOVE-CORRESPONDING not only for structures but also for internal tables now. Components of the same name are are assigned row by row. New additions EXPANDING NESTED TABLES and KEEPING TARGET LINES allow to resolve tabular components of structures and to append lines instead of overwriting existing lines.

Example

MOVE-CORRESPONDING itab1 TO itab2 EXPANDING NESTED TABLES

KEEPING TARGET LINES.

More About

ABAP Keyword Documentation

Expressions and Functions

LET Expressions in Constructor Expressions

New LET expressions as sub expressions of constructor expressions allow you to define local variables or field symbols as auxiliary fields of constructor expressions.

Example

LET expression in a table construction using the VALUE operator.

cl_demo_output=>new( )->write(

  VALUE text( LET it = `be` IN

                 ( |To { it } is to do|          )

                 ( |To { it }, or not to { it }| )

                 ( |To do is to { it }|          )

                 ( |Do { it } do { it } do|      ) ) )->display( ).

More About

ABAP Keyword Documentation

CORRESPONDING Operator

The new constructor operator CORRESPONDING allows to execute  a "MOVE-CORRESPONDING" for structures or internal tables at operand positions. Besides assigning components of the same name you can define your own mapping rules.

Example

struct2 = CORRESPONDING #( struct1 MAPPING b4 = a3 ).

More About

ABAP Keyword Documentation

Table Comprehensions

A new FOR sub expression for constructor expressions with operators NEW and VALUE allows to read existing internal tables and to construct new tabular contents from the lines read.

Example

Construction of an internal table itab2 from lines and columns of an internal table itab1. You can of course also use the CORRESPONDING operator to construct the lines.

DATA(itab2) = VALUE t_itab2( FOR wa IN itab1 WHERE ( col1 < 30 )

( col1 = wa-col2 col2 = wa-col3 ) ).

More About

ABAP Keyword Documentation

Meshes

This one is a little bit tricky. Meshes are special structures whose components are internal tables, which can be linked to each other using associations. Associations are evaluated by specifying mesh paths in suitable expressions and statements .The full power of meshes will become more clear in the moment when associations will be supported by Open SQL for database views (CDS views, see below) in the future.

Example

A mesh flights is declared from a mesh type T_FLIGHTS. In T_FLIGHTS you have tabular components as so called mesh nodes that are linked by associations. A structured data object root  is constructed to serve as the start line for the following LOOP over a mesh path. The results are lines from SFLIGHT that are found by following the mesh path evaluating the associations between its mesh nodes.

TYPES: t_scarr   TYPE SORTED TABLE OF scarr WITH UNIQUE KEY carrid,
       t_spfli   TYPE SORTED TABLE OF spfli WITH UNIQUE KEY carrid connid,
       t_sflight TYPE SORTED TABLE OF sflight WITH UNIQUE KEY carrid connid fldate.


TYPES: BEGIN OF MESH t_flights, 
           scarr  TYPE t_scarr ASSOCIATION to_spfli TO spfli ON carrid = carrid

USING KEY primary_key,
           spfli TYPE t_spfli ASSOCIATION to_sflight TO sflight ON carrid = carrid                                    
                                         AND connid = connid  USING KEY primary_key,
          sflight TYPE t_sflight,
         END OF MESH t_flights.                  

        

DATA: flights TYPE t_flights. 

... 

DATA(root) = flights-scarr[ carrname = 'United Airlines' ].

LOOP AT
  flights-scarr\to_spfli[ root ]\to_sflight[ ]
    INTO DATA(wa).
  ...
ENDLOOP.

More About

ABAP Keyword Documentation

Open SQL(New Syntax)

From 7.40, SP05

l   Lists in Open SQL statements can and should be separated by a comma.

l   Host variables in Open SQL statements can and should be escaped by a @.

You will be able to use other new functions that are based on a new SQL parser in the ABAP kernel.

Example

SELECT carrid, connid, fldate FROM sflight 

   INTO CORRESPONDING FIELDS OF TABLE @sflight_tab

      WHERE carrid = @carrier AND  connid = @connection      

         ORDER BY carrid, connid.

More About

ABAP Keyword Documentation

SQL Expressions

You can use SQL expressions in a column list behind SELECT. The result of such an expression is calculated on the database (code push down!) and written into the respective columns of the result set. Operands can be data base columns or host variables.

Possible expressions are

l   elementary values

l   arithmetic expressions

l   arithmetic functions abs, ceil, floor, div, mod

l   castings with cast

l   string concatenations with &&

l   coalesce

l   case

Expressions can be mixed and proritized with parentheses.

Examples

SELECT id, num1, num2, cast( num1 AS fltp ) / cast( num2 AS fltp ) AS ratio,

       div( num1, num2 ) AS div, mod( num1, num2 ) AS mod,

       @offset + abs( num1 - num2 ) AS sum

       FROM demo_expressions INTO CORRESPONDING FIELDS OF TABLE @results

       ORDER BY SUM DESCENDING.

SELECT id, CASE char1

             WHEN 'aaaaa' THEN ( char1 && char2 )

             WHEN 'xxxxx' THEN ( char2 && char1 )

             ELSE @else

           END AS text

       FROM demo_expressions INTO CORRESPONDING FIELDS OF TABLE @results.

 More About

ABAP Keyword Documentation

CDS Views     

The new CDS (Core Data Services) enable you to define Views of the ABAP Dictionary with a DDL (Data Definition Language) in ADT. This DDL encompasses the DDL of SQL and enhances it with the possibility to define annotations and associations. CDS-Views in the Dictionary are not bound to a specific database platform. They provide another way of database independent code push down .You can access CDS-Views with Open SQL.

Example

Definitiion of a simple view based on only one database table. Of course, you can join as you like ...

@AbapCatalog.sqlViewName: 'BPA_VW'

define view business_partner as

     select from snwd_bpa { key bp_id, company_name, bp_role }

You can access the view in ABAP programs e.g. as follows:

SELECT * FROM business_partner INTO TABLE itab ...

More About

ABAP Keyword Documentation

See also the dedicated blog:

New Data Modeling Features in SAP NW ABAP 7.4 SP5 | SAP Blogs

ABAP Managed Database Procedures

ABAP Managed Database Procedures (AMDP) are a class based framework for maintaining and calling stored procedures as so called AMDP procedures from ABAP. An AMDP procedure is implemented in its native DB-language in an AMDP method of an AMDP class. Currently, the only database that supports AMDP is SAP's HANA database.

An AMDP class must implement a specific tag interface. Currently, there is only one namely IF_AMDP_MARKER_HDB. An AMDP class can be maintained in ADT only. An AMDP method looks from its declaration like a normal ABAP method and can be used like that. Only when implementing the method, you denote the database and the DB language. You also must denote the entities to be used. The following is an example for using the language SQLScript of the HANA database:

CLASS cl_demo_amdp DEFINITION PUBLIC.
  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb .
    METHODS increase_price
      IMPORTING
        VALUE(clnt) TYPE sy-mandt
        VALUE(inc)  TYPE sflight-price .
ENDCLASS.

CLASS cl_demo_amdp IMPLEMENTATION.
  METHOD increase_price BY DATABASE PROCEDURE FOR HDB
                        LANGUAGE SQLSCRIPT
                        USING sflight.
    update sflight set price = price + :inc
                   where mandt = :clnt;
  ENDMETHOD.
ENDCLASS.

Please note that a simple example as the above one is only to show the syntax. Implementing functionality in an AMDP method means the usage of Native SQL. And for the usage of Native SQL the same holds as before: Stay open as long as possible! It makes absolutely no sense to push down statements to the database that you can also express in Open SQL, because those are pushed down by the Native SQL Interface in exactly the same way or even better!

You use AMDP as a convenient way of programming and handling Native SQL in ABAP only if you really gain something from it. And for that, simple examples are not too easy to find, especially since Open SQL is empowered by new features now (see above).

Example

A simple example of a database functionality that is not readily available in Open SQL is the predefined currency conversion of HANA. An AMDP method that uses this conversion might look as follows:

METHOD convert BY DATABASE PROCEDURE FOR HDB

                           LANGUAGE SQLSCRIPT

                           USING demo_prices.

  PRICES = select * from DEMO_PRICES;

  PRICES =

    CE_CONVERSION (

      :PRICES,

      [ family             = 'currency',

        method             = 'ERP',

        steps              = 'shift,convert,shift_back',

        target_unit        = :TO_CURRENCY,

        client             = :MANDT,

        source_unit_column = "CURRENCY",

        reference_date     = :DATE,

        output_unit_column = "CURRENCY",

        error_handling     = 'keep unconverted' ],

      [ amount AS amount ] );

   replace DEMO_PRICES select * from :PRICES;

ENDMETHOD.

An alternative implementation for databases other than the SAP HANA database must then be provided, e.g. as follows:

METHOD abap_convert.

  DATA prices TYPE STANDARD TABLE OF demo_prices.

  SELECT *

&nb

<think>好的,我现在需要处理用户关于SAP系统中车间和仓库盘盈盘亏处理方式及差异的问题。首先,我要回忆之前用户提到的内容,用户之前问过车间库负库存的设置,引用了matinalSAP FICO的资料。现在用户进一步询问盘盈盘亏的具体处理方和区别,需要结合之前的引用信息,同时可能需要补充其他相关知识。 首先,盘盈盘亏通常涉及库存差异的处理,这在SAP中可能通过不同的移动类型和会计科目来体现。根据引用[1],车间库是虚拟库,允许负库存,而实体仓库不允许。这可能影响盘点的处理方式。例如,车间库的差异可能通过生产订单调整,而实体仓库的差异可能直接通过库存调整科目处理。 然后,引用[2]提到KO88结算生产订单时产生的会计凭证,涉及生产成本和材料成本差异科目。这说明生产相关的差异可能通过生产订单结算流程处理,而仓库的差异可能直接调整库存科目。 接下来,我需要区分车间和实体仓库的处理步骤。车间库作为虚拟库,可能与生产订单相关,盘盈盘亏可能通过调整生产订单的投入或产出来处理,使用特定的移动类型如701/702。而实体仓库的差异可能使用移动类型701/702,并直接过账到差异科目,影响库存价值。 另外,会计处理方面,车间库的差异可能关联到生产成本科目,而实体仓库差异可能对应库存调整科目。需要注意系统配置中是否允许负库存对处理方式的影响,车间库允许负库存可能意味着差异处理更灵活,而实体仓库需要及时调整避免负库存。 用户可能还想知道具体的操作事务代码,比如MI07用于库存盘点,MI20查看差异,以及KO88结算生产订单。同时,需要说明两者的核心区别在于库存类型、会计科目和处理流程。 最后,生成相关问题需要考虑用户可能进一步的问题,比如配置步骤、会计凭证差异、生产订单影响等。确保问题覆盖用户可能的兴趣点,帮助他们深入理解处理机制。</think>### SAP车间与仓库盘盈盘亏处理方及区别 #### 一、车间库(虚拟库)盘盈盘亏处理 1. **业务背景** 车间库作为配合生产回冲扣料的虚拟库,允许负库存[^1],其差异通常与生产订单执行相关。例如:生产投料未完全消耗或退库未及时记录。 2. **处理步骤** - **差异确认**:通过事务代码`MI07`进行库存盘点,系统生成差异清单。 - **调整方式**: - 盘盈:使用移动类型`701`(库存增加)关联生产订单,冲减生产成本。 - 盘亏:使用移动类型`702`(库存减少)关联生产订单,增加生产成本。 - **会计处理**:差异通过生产订单结算(事务代码`KO88`)转入成本中心或差异科目,例如: ``` 借:生产成本-差异调整 贷:库存-车间库 ``` [^2] #### 二、实体仓库盘盈盘亏处理 1. **业务限制** 实体仓库禁止负库存[^1],差异需立即处理,通常由物料管理模块触发。 2. **处理步骤** - **差异过账**:使用移动类型`701`/`702`直接调整库存,系统自动生成会计凭证: ``` 借/贷:库存商品 贷/借:库存盘盈盘亏科目 ``` - **权限控制**:需审批流程(通过审批码或电子工作流)。 #### 三、核心区别对比 | **维度** | **车间库** | **实体仓库** | |----------------|-----------------------------------|--------------------------------| | **库存类型** | 虚拟库(允许负库存)[^1] | 实物库(禁止负库存) | | **差异来源** | 生产订单执行偏差 | 收发存操作误差 | | **会计科目** | 关联生产成本科目[^2] | 直接使用库存调整科目 | | **处理流程** | 需结合生产订单结算(KO88)[^2] | 独立过账,无需关联订单 | #### 四、配置要点 1. **车间库**:在物料主数据中设置“特殊库存标识”(如生产库存),并配置移动类型与生产订单的关联。 2. **实体库**:在物料管理(MM)模块定义库存调整科目,并设置审批策略。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值