• ASSIGN的用法


    *&---------------------------------------------------------------------*
    *& Report  ZASSIGN
    *& 作成者:張玉剛
    *&---------------------------------------------------------------------*
    *& 作成日  :2009/08/03
    *& 処理概要:ASSIGNの使い方
    *&---------------------------------------------------------------------*

    REPORT  ZASSIGN.

    *&---------------------------------------------------------------------*
    *& ASSIGN f TO <fs>
    *&---------------------------------------------------------------------*
    "ASSIGN f TO <fs>.

    DATA NAME(4) VALUE 'JOHN'.
    FIELD-SYMBOLS <F>.
    ASSIGN NAME TO <F>.
    WRITE <F>.

    "結果:JOHN

    DATA: NAME(12) VALUE 'JACKJOHNCARL',
          X(10)    VALUE 'XXXXXXXXXX'.
    FIELD-SYMBOLS <F>.
    ASSIGN NAME+4(*) TO <F>.
    "ASSIGN NAME+4(0) TO <F>. "0だめ
    WRITE <F>.

    "結果:JOHNCARL

    *&---------------------------------------------------------------------*
    *& ... TYPE typ
    *&---------------------------------------------------------------------*
    "... TYPE typ
    DATA LETTER TYPE C.
    FIELD-SYMBOLS <F>.
    ASSIGN LETTER TO <F>.

    ASSIGN LETTER TO <F> TYPE 'X'.

    *&---------------------------------------------------------------------*
    *& ... DECIMALS dec
    *&---------------------------------------------------------------------*
    "... DECIMALS dec
    DATA SALES_DEC2(10) TYPE P DECIMALS 2 VALUE 1234567.
    FIELD-SYMBOLS <SALES_DEC5>.

    ASSIGN SALES_DEC2 TO <SALES_DEC5> DECIMALS 5.
    WRITE: / SALES_DEC2,
           / <SALES_DEC5>.

    "結果:
         "1,234,567.00
         "1,234.56700

    *&---------------------------------------------------------------------*
    *& ... LOCAL COPY OF ...
    *&---------------------------------------------------------------------*

    DATA X(4) VALUE 'Carl'.
    PERFORM U.
    FORM U.
      FIELD-SYMBOLS <F>.
      ASSIGN LOCAL COPY OF X TO <F>.
      WRITE <F>.
      MOVE 'John' TO <F>.
      WRITE <F>.
      WRITE X.
    ENDFORM.

    "結果:Carl John Carl

    *&---------------------------------------------------------------------*
    *& ASSIGN (f) TO <fs>.
    *&---------------------------------------------------------------------*
    "ASSIGN (f) TO <fs>.
    "ASSIGN (f)+off(len) TO <fs> " is not allowed

    "SY-SUBRC = 0 The assignment was successful.
    "SY_SUBRC = 4 The field could not be assigned to the field symbol.

    DATA: NAME(4) VALUE 'XYZ',       XYZ VALUE '5'.
    FIELD-SYMBOLS <F>.
    ASSIGN (NAME) TO <F>.
    WRITE <F>.

    "結果:5

    *&---------------------------------------------------------------------*
    *& ASSIGN TABLE FIELD (f) TO <fs>.
    *&---------------------------------------------------------------------*
    "ASSIGN TABLE FIELD (f) TO <fs>.

    TABLES TRDIR.
    DATA NAME(10) VALUE 'TRDIR-NAME'.
    FIELD-SYMBOLS <F>.
    MOVE 'XYZ_PROG' TO TRDIR-NAME.
    ASSIGN TABLE FIELD (NAME) TO <F>.
    WRITE <F>.

    "結果:XYZ_PROG


    TABLES T100.
    T100-TEXT = 'Global'.
    PERFORM EXAMPLE.
    FORM EXAMPLE.
      DATA: BEGIN OF T100,
            TEXT(20) VALUE 'LOCAL',
            END OF T100,
            NAME(30) VALUE 'T100-TEXT'.
      FIELD-SYMBOLS <F>.
      ASSIGN (NAME) TO <F>.
      WRITE <F>.
    ENDFORM.

    "結果:LOCAL


    TABLES TRDIR.
    DATA: F(8) VALUE 'F_global',
          G(8) VALUE 'G_global'.
    MOVE 'XYZ_PROG' TO TRDIR-NAME.
    PERFORM U.
    FORM U.
      DATA: F(8)     VALUE 'F_local',
            NAME(30) VALUE 'F'.
      FIELD-SYMBOLS <F>.
      ASSIGN (NAME) TO <F>.
      WRITE <F>.
      MOVE 'G' TO NAME.
      ASSIGN (NAME) TO <F>.
      WRITE <F>.
      MOVE 'TRDIR-NAME' TO NAME.
      ASSIGN (NAME) TO <F>.
      WRITE <F>.
    ENDFORM.

    "結果:F_local  G_global  XYZ_PROG

    *&---------------------------------------------------------------------*
    *& ASSIGN COMPONENT idx OF STRUCTURE rec TO <fs>.
    *& ASSIGN COMPONENT name OF STRUCTURE rec TO <fs>.
    *&---------------------------------------------------------------------*
    "ASSIGN COMPONENT idx OF STRUCTURE rec TO <fs>.
    "ASSIGN COMPONENT name OF STRUCTURE rec TO <fs>.


    DATA: BEGIN OF REC,
              A VALUE 'a',
              B VALUE 'b',
              C VALUE 'c',
              D VALUE 'd',
            END OF REC,
            CN(5) VALUE 'D'.
      FIELD-SYMBOLS <FS>.
      DO 3 TIMES.
        ASSIGN COMPONENT SY-INDEX OF
               STRUCTURE REC TO <FS>.
        IF SY-SUBRC <> 0. EXIT. ENDIF.
        WRITE <FS>.
      ENDDO.
      ASSIGN COMPONENT CN OF STRUCTURE REC TO <FS>.
      WRITE <FS>.

    "結果:a b c d

  • 相关阅读:
    tomcat服务器宕机解决方案
    @SpringBootApplication无法被解析引入
    记一次ajax交互问题
    记一次js之button问题
    非常简单的部署脚本(JavaWeb项目)和部署项目教程
    Docker实战(十)之分布式处理与大数据平台
    Docker实战(九)之数据库应用
    Docker实战(八)之Web服务与应用
    DevExpress.Build
    批处理 批量删除当前目录及子目录下多个指定的扩展名文件
  • 原文地址:https://www.cnblogs.com/wequst/p/1538405.html
Copyright © 2020-2023  润新知