SAP_ABAP_Basics of Programming_Modularization_Definition and calling of macros/Using included programs/Calling subprograms/Transmitting data through parameters/Defining local data types and objects in subprograms/Calling function modules

SAP ABAP consultant (development engineer) competency model_Terry talks about enterprise digitalization blog-CSDN blog article has been viewed 484 times. Goal: Based on the review of the SAP abap consultant competency model, provide super fuel for abaper with about one year of experience to quickly grow into three years of experience! https://blog.csdn.net/java_zhong1990/article/details/132469977


I usually work on 'moving bricks at the construction site' and rarely pay attention to basic skills. I have nothing to do, so I picked it up and reviewed it! 

It is actually used very rarely in the project, so when it comes to learning programming, you should first learn the framework and then learn the details! , because there are too many details to learn!


The word 'modularity' can be seen in almost all fields. Friends who like to read Autohome should be able to hear that a certain domestic automobile factory has become 'modularized' and its development efficiency has improved; in electronics, something happened This word can also be often heard in the field of equipment and architectural design.


What problem does 'modularity' solve?

1 Reusability , for example: design a common interface so that whoever wants to use it can use it

2Scalability , _

3. Can be developed in parallel , with multiple teams working at the same time.

4 Fault tolerance , if something goes wrong with one module, it will not affect the other module

5. Can be developed and tested independently , making it easier to find problems.

6Easy to understand and maintain , wait for it


Well, during interviews, we often encounter business line leaders who don’t understand technology and talk about a lot of awesome technologies. The other party may not know it. If the three words "modularity" are said, then to a certain extent, it is the same frequency. !


It can also be said that when we are working on solutions, we should put these three words on the PPT. If we brag about it, we will win the deal!


What is the content of modular design in the field of ABAP?


1 Definition and calling of macros

DEFINE <macro>.
<statements>
END-OF-DEFINITION.
<macro> [<p1><p2> ... <p9>].

The actual code looks like this:

 DATA:lv_position TYPE i VALUE 1.
  CLEAR: lv_position.
  lv_position = lv_position + 1.

  DEFINE df_fieldcat.
    CLEAR gs_fieldcat_lvc.
    gs_fieldcat_lvc-col_pos     = lv_position."ALV 控制: 输出列
    gs_fieldcat_lvc-scrtext_m   = &1."中字段标签
    gs_fieldcat_lvc-fieldname   = &2."ALV 控制: 内部表字段的字段名称
    gs_fieldcat_lvc-no_zero     = &3."ALV 控制: 为输出隐藏零
    gs_fieldcat_lvc-checkbox    = &4."ALV 控制: 作为复选框输出
    gs_fieldcat_lvc-edit        = &5."设置可编辑模式
    gs_fieldcat_lvc-outputlen   = &6."输出长度
    gs_fieldcat_lvc-ref_table   = &7.
    gs_fieldcat_lvc-ref_field   = &8.
    gs_fieldcat_lvc-datatype    = &9.
    APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.
    ADD 1 TO lv_position.
  END-OF-DEFINITION.

  df_fieldcat:

'物料编号' 'MATNR' 'X' '' '' '18' 'MARA' 'MATNR' '',
'物料描述' 'ZWLCMS' 'X' '' '' '40' '' '' '',

2 Use include programs

INCLUDE <incl>.

The code in the actual combat process looks like this: Friends who have done JAVA can understand it as: import java.util.List;, or introduce the concept of a package.

REPORT zmm029.

INCLUDE zmm029_top.
INCLUDE zmm029_sel.
INCLUDE zmm029_frm.
INCLUDE zmm029_pbo.
INCLUDE zmm029_pai.

3 Call subroutine

There are 4 types, and the first two are used in the project.

Call internal subroutine, PERFORM <subr> [<pass>].

Call external subroutine, PERFORM <subr>(<prog>) [<pass>] [IF FOUND].

Specify the subprogram name when running, PERFORM (<fsubr>) [IN PROGRAM (<fprog>)] [<pass>] [IF FOUND].

Call the subroutine from the list, PERFORM <idx> OF <form1><form2> ....<formn>.

PERFORM get_data.
PERFORM set_catalog.
PERFORM display_alv.

4 Data transfer through parameters

Statement, method of passing parameters in 3:

FORM <subr> [TABLES <formal  table list>]
[USING <formal  input list>]          
[CHANGING <formal output list>]....

PERFORM <subr>[(<prog>)] [TABLES <actual  table list>]
[USING <actual  input list>]                       
[CHANGING <actual output list>]....

Passed by reference:

Data transfer between caller and subroutine via reference value

PERFORM... [USING <ai1> ... <ain>] [CHANGING <ao1> ... <aon>] ...

FORM ..... [USING <fi1> ... <fin>] [CHANGING <fo1> ... <fon>] ...

That is to say PERFORM --> FORM

PERFORM get_data.
FORM get_data .

  SELECT
        mara~zwlcms,
        mara~matnr, "物料描述
        mara~mtart, "物料类型
        mara~meins, "单位
        marc~werks,

        marc~ekgrp,
        marc~dismm,
        marc~dispo,
        marc~sfcpf,
        marc~fevor,

        mvke~vkorg,  "销售组织
        mbew~vprsv,  "价格控制
        mbew~mlast   "物料价格确定: 控制

    INTO CORRESPONDING FIELDS OF TABLE @gt_data
    FROM mara
    LEFT JOIN marc ON marc~matnr = mara~matnr
    LEFT JOIN mvke ON mvke~matnr = mara~matnr AND mvke~dwerk = marc~werks
    LEFT JOIN mbew ON mbew~matnr = mara~matnr AND mbew~bwkey = marc~werks

    WHERE

    mara~matnr     IN @so_matnr
    AND marc~werks IN @so_werks

    .
ENDFORM.

Pass by value:

PERFORM... USING .......<aii> ..

FORM ..... USING ...VALUE(<fii>) ..

Passing by value and result:

PERFORM... CHANGING .......<aii> ..

FORM ..... CHANGING ...VALUE(<fii>) ..

5 Define local data types and objects in subroutines

Define dynamic local data types and objects:

You can create local data types and data objects within a subroutine using the TYPES and DATA statements, as described in Creating Data Objects and Data Types

Define static local data types and objects:

If you want to retain the value of a local data object after exiting the subroutine, you must use the STATICS  statement instead of the DATA statement to declare it.

Explicitly define global data objects:

LOCAL <f>. Prevent global data object values ​​from being changed within subroutines

6 Call function module

CALL FUNCTION <module>
[EXPORTING  f1 = a1 .... fn = an]
[IMPORTING  f1 = a1 .... fn = an]
[CHANGING   f1 = a1 .... fn = an]
[TABLES     f1 = a1 .... fn = an]
[EXCEPTIONS e1 = r1 .... en = rn [OTHERS = ro]].

(1) The EXPORTING  option allows the real parameter ai to be passed to the formal input parameter fi. In function modules, formal parameters must be declared as input parameters .

(2) The IMPORTING  option allows the formal output parameter fi to be passed to the real parameter ai. In function modules, formal parameters must be declared as output parameters .

(3) The CHANGING option allows the real parameter ai to be passed to the formal parameter fi, and after processing the function module, the system will pass the (changed) formal parameter fi back to the real parameter ai. In function modules, formal parameters must be declared as change parameters.

(4) The TABLES option allows tables to be passed between actual parameters and formal parameters. With this option, the internal table is always passed by reference value.

EXPORTING  : is the input parameter, IMPORTING: is the output parameter; it must be understood in reverse, it is said to be the communication between engineers in the modularization process, one party quarrels but does not win!   EXPORTING  : is the input parameter, that is, the input of the dropped function parameter

example:

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
      EXPORTING
        i_callback_program       = sy-repid "这里是调用这个ALV的程序名
        i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
        i_callback_user_command  = 'USER_COMMAND' "获取用户事件的函数
        is_layout_lvc            = ls_layout "显示的布局
        it_fieldcat_lvc          = gt_fieldcat_lvc "设置显示的字段以及字段的功能
        i_save                   = 'A'
      TABLES
        t_outtab                 = gt_data
      EXCEPTIONS
        program_error            = 1.

 


Guess you like

Origin blog.csdn.net/java_zhong1990/article/details/134725992