2017年7月24日 星期一

SAP_ABAP_邊學邊記錄_賦值(MOVE TO)

SAP_ABAP_邊學邊記錄_賦值(MOVE TO)

說明

相同的結構之間可以透過MOVE TO來做賦值,如存在結構差異的話,可以透過MOVE-CORRESPONDING TO來將相同字段給值。

MOVE TO範例

//定義結構
TYPES:BEGIN OF ADDS.
      FLAG, //沒指定會預設為C且長度為1
      ID LIKE AA-ID,
      NAME LIKE AA-NAME,
      CITY LIKE AA-CITY,
END OF ADDS.
//實作,產生WORD AREA
DATA ADDRESS TYPE ADDS.
//賦值
MOVE:'Y'      TO ADDRESS-FLAG,
     '0001'   TO ADDRESS-ID,
     'MARTY'  TO ADDRESS-NAME,
     'TAIWAN' TO ADDRESS-CITY.
//顯示
WRITE ADDRESS.

MOVE-CORRESPONDING TO範例

TABLES: EMPLOYEE.
 
DATA: BEGIN OF ADDS,
        FLAG,
        ID      LIKE EMPLOYEE-ID,
        NAME    LIKE EMPLOYEE-NAME1,
        CITY    LIKE EMPLOYEE-CITY,
      END OF ADDS.
 
SELECT * FROM EMPLOYEE.
 
     MOVE-CORRESPONDING EMPLOYEE TO ADDS.
     
     CLEAR ADDS.
ENDSELECT.

MOVE-CORRESPONDING TO說明

TABLE:EMPLYOEE
ID NAME1 CITY
0001 MARTY TAIWAN
ADDS
FLAG ID NAME CITY
透過MOVE-CORRESPONDING TO來賦值的話,只會針對欄位名稱相同的來賦值!
以案例來看,即ID與CITY在這個執行上會有值而以。

沒有留言:

張貼留言