SAP-Abap Learning Record (2)

2023-01-10   ES  

*&———————————————————————*
*& Report  ZTEST_ABAP_2
*&
*&———————————————————————*
*& String Treatment
*&
*&———————————————————————*
REPORT ztest_abap_2.

“Define a variable of a string type
DATA: test1(15) TYPE c VALUE ‘HELLO SEVEN’.
WRITE / test1.

“Define multiple variables at the same time
DATA: player(35)   TYPE c,
      nickname(35),
      points       TYPE i,
      games        TYPE i VALUE ’10’,
      averange(5)  TYPE p,
      acquired     TYPE d.

*Define reference variables
DATA: test2 LIKE test1.
test2 = test1.
WRITE / test2.

*Variable initialization
test1 = ‘SAP’.
CLEAR test1.
WRITE / test1.

*Definition constant
CONSTANTS: team1(20) TYPE c VALUE ’76ers’,
           team2     LIKE team1 VALUE ‘SAP’.
WRITE: / team1,team2.

*Copy between the structure and structure
DATA:BEGIN OF userinf,
       sid(10)  TYPE c,
       name(20) TYPE c,
       tel(20)  TYPE c,
     END OF userinf.

userinf-sid = ‘A0001’.
userinf-name = ‘SEVEN’.
userinf-tel = ‘010-123456’.

WRITE / userinf.

DATA:user2 LIKE userinf.
user2 = userinf.
WRITE / user2.

*Inheritance of the structure
DATA: BEGIN OF employee.
        INCLUDE STRUCTURE userinf.
DATA: birthday TYPE d,
      add(50)  TYPE c,
      END OF employee.

*Definition and use in the inner table
Tables: USR21. “Reference to a transparent table to reference

*
*below is the method of defining different types of internal tables
*
*TYPES: BEGIN OF EMP,
*      NAME LIKE USR21-BNAME,
*      TELNUM LIKE USR21-PERSNUMBER,
*      ADDR LIKE USR21-ADDRNUMBER,
*      END OF EMP.
*Refer to this structure to define an initialization size of 10, and there is an inner table of Header Line
*  DATA: EMPTAB TYPE STANDARD TABLE OF EMP INITIAL SIZE 10 WITH HEADER LINE.
*Refer to the inner table above, redefine the inner table of a size of a size 20 without the header line
*   DATA: EMPTAB2 LIKE STANDARD TABLE OF EMPTAB INITIAL SIZE 20.
*Another way to define the inner table, bring Header Line
*    DATA: EMPTAB3 LIKE EMPTAB OCCURS 10.
*Define a sort table, use name as the keyword, NAME does not repeat
*  DATA: EMPTAB4 LIKE SORTED TABLE OF EMPTAB WITH UNIQUE KEY NAME WITH HEADER LINE.
*Define a hash table with a initialization value 0
*          DATA: EMPTAB5 LIKE HASHED TABLE OF EMPTAB WITH UNIQUE KEY NAME WITH HEADER LINE.

*The assignment of the inner table
DATA: BEGIN OF emp OCCURS 0,
        name   LIKE usr21-bname,
        telnum LIKE usr21-persnumber,
        addr   LIKE usr21-addrnumber,
      END OF emp.

*DATA: lv_1 TYPE i VALUE 1,

emp-name = ‘SEVEN’.
emp-telnum = ‘010-111111’.
emp-addr = ‘DONGGUAN’.
APPEND emp.
WRITE / emp.

*Data from the inner table without Header Line: first encapsulate it outside

*TABLES: USR21.
*DATA: BEGIN OF EMPTAB,
*  NAME LIKE USR21-BNAME,
*  TELNUM LIKE USR21-PERSNUMBER,
*  ADDR LIKE USR21-ADDRNUMBER,
*  END OF EMPTAB.
* DATA: EMP LIKE STANDARD TABLE OF EMPTAB.
*    EMP-NAME = ‘SEVEN’.
*    EMP-TELNUM = ‘010-111111’.
*    EMP-ADDR = ‘DONGGUAN’.
*    APPEND EMPTAB TO EMP.

*Add data to the inner table through the database query
*    TABLES: USR21.
*    DATA: BEGIN OF EMP OCCURS 0,
*      NAME LIKE USR21-BNAME,
*      TELNUM LIKE USR21-PERSNUMBER,
*      ADDR LIKE USR21-ADDRNUMBER,
*      END OF EMP.
*
*      SELECT BNAME AS NAME PERSNUMBER AS NUMBER ADDRNUMBER AS ADDR
*        INTO TABLE EMP FROM USR21.

*Inner table management:
*Inner table is empty
*Refresh Emp FROM Table USR21. “Clear the storage space of EMP and find data from USR21 to fill in the inner table

*Inner table insert data
TYPES: BEGIN OF PERSON,
  NAME(30) TYPE C,
  END OF PERSON.

DATA: PERSONTAB TYPE STANDARD TABLE OF PERSON WITH HEADER LINE.

*Because there are Header Line, it also defines an object of the same name, so you can directly execute the following two codes, and the following loop code

PERSONTAB = ‘ABC’.
APPEND PERSONTAB.

DATA: PERSON1 LIKE PERSONTAB.
PERSON1 = ‘EFG’.
APPEND PERSON1 TO PERSONTAB.

DATA PERSON2 LIKE PERSONTAB.
PERSON2 = ‘HHH’.
INSERT PERSON2 INTO TABLE PERSONTAB.

LOOP AT PERSONTAB.
  WRITE: / PERSONTAB.
ENDLOOP.

LOOP AT PERSONTAB WHERE NAME = ‘HHH’.
  WRITE: / PERSONTAB.
ENDLOOP.

DELETE TABLE PERSONTAB WITH TABLE KEY NAME = ‘ABC’.
LOOP AT PERSONTAB.
  WRITE: / PERSONTAB.
ENDLOOP.

*No Header Line internal table operation
Types: Begin of Book, “Define a thing similar to a class
  NAME(30) TYPE C,
  PRICE TYPE I,
  END OF BOOK.

data book1 type book. “Define something similar to objects
data: Booktab type standing table of book.
  BOOK1-NAME = ‘AAA’.
  BOOK1-PRICE = 1.
  APPEND BOOK1 TO BOOKTAB.

*Data output without Header Line

*Date formatting
DATA: DATE TYPE D.
DATE = ‘20180718’.
WRITE / DATE MM/DD/YYYY.

*Common assignment method and pointer assignment
DATA: A TYPE C,
      B TYPE C,
      CC TYPE I.
A = ‘X’.
MOVE A TO B.
WRITE / B.
WRITE ‘Y’ TO B.
WRITE: / B ,CC.

DATA: NUM TYPE I VALUE 10.
FIELD-SYMBOLS: <F1>,
               <F2> TYPE I,
               <F3> LIKE NUM.
ASSIGN: NUM TO <F1>,
        <F1> TO <F2>.

<F2> = ( ( ( <F2> + 1 ) – 1 ) * 1 / 10 ) DIV 1 MOD 6 ** 1.
WRITE: / <F1> ,<F2>.

data: FIRST TYPE I VALUE 1,
      SEC TYPE I VALUE 2.

IF FIRST > SEC.
  WRITE: / ‘TRUE’.
  ELSE.
    WRITE: / ‘FALSE’.
ENDIF.

source

Random Posts

20 problems encountered in work in 2014: 161-180

TOMCAT Open JMX monitoring and common fault investigations

suffix expression

java Blue Bridge Cup Poisonette

jsp: usebean, jsp: setproperty Detailed explanation