SAPBRAINSONLINE.com
SAP Training, Tutorials, Certification and Jobs Materials
HOME TUTORIALS ARTICLES PROJECTS JOBS TOOLS REFERENCES CHAT FORUM GUESTS
Related 10 ABAP SyntaxTutorials
ENDWHILE (ABAP Keyword)
EXTRACT (ABAP Keyword)
COMMIT (ABAP Keyword)
STOP ( SAP ABAP Keyword)
CONTROLS (ABAP Keyword)
SYNTAX-TRACE ( SAP ABAP Keyword)
CONTINUE (ABAP Keyword)
SHIFT (ABAP Keyword)
WHILE ( SAP ABAP Keyword)
GENERATE (ABAP Keyword)

  ASSIGN (ABAP Keyword)

A D V E R T I S E M E N T
home--> ABAP --> ABAP Syntax
ASSIGN (ABAP Keyword) introduction & details

ASSIGN


Variants


1. ASSIGN f TO .
2. ASSIGN (f) TO .
3. ASSIGN TABLE FIELD (f) TO .
4. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .
5. ASSIGN COMPONENT idx OF STRUCTURE rec TO .
6. ASSIGN COMPONENT name OF STRUCTURE rec TO .

Variant 1
ASSIGN f TO .

Additions



1. ... TYPE typ
2. ... DECIMALS dec
3. ... LOCAL COPY OF ...

Effect
Assigns the field f to the field symbol . The field symbol "points to" the contents of the field f at runtime, i.e. every change to the contents of f is reflected in and vice versa. If the field symbol is not typed (see FIELD-SYMBOLS ), the field symbol adopts the type and atrributes of the field f at runtime, particularly the conversion exit. Otherwise, when the assignment is made, the system checks whether the type of the field f matches the type of the field symbol .

Note
With the ASSIGN statement, the offset and length specifications in field f (i.e. f+off , f+len or f+off(len) ) have a special meaning:

They may be variable and thus not evaluated until runtime.
The system does not check whether the selected area still lies within the field f .
If an offset is specified, but no length, for the field f , the field symbol adopts the length of the field f . Caution: also points to an area behind the field f . If you do not want this, the offset and length specifications can be in the form ASSIGN f+off(*) TO . . This means that the field symbol is set so that the field limits of f are not exceeded.
In the ASSIGN statement, you can also use offset and length specifications to access field symbols, FORM and function parameters.
Warning: If the effect of the ASSIGN statement is to assign parts of other fields beyond the limits of the field f , the changing of the contents via the field symbol may mean that the data written to these fields does not match the data type of these fields and thus later results in a runtime error.


Note
Since the ASSIGN statement does not set any return code value in the system field SY-SUBRC , subsequent program code should not read this field.

Example

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


Output: JOHN

Example

DATA: NAME(12) VALUE 'JACKJOHNCARL',
X(10) VALUE 'XXXXXXXXXX'.
FIELD-SYMBOLS .
ASSIGN NAME+4 TO .
WRITE .
ASSIGN NAME+4(*) TO .
WRITE .


Output: JOHNCARLXXXX JOHNCARL

Example

DATA: NAME(12) VALUE 'JACKJOHNCARL',
X(10) VALUE 'XXXXXXXXXX'.
FIELD-SYMBOLS .
ASSIGN NAME+4 TO .
WRITE .
ASSIGN NAME+4(*) TO .
WRITE .


Output: JOHNCARLXXXX JOHNCARL

Addition 1
... TYPE typ

Effect
With untyped field symbols, allows you to change the current type of the field symbol to the type typ. The output length of the field symbol is corrected according to its type.
With typed field symbols, this addition should only be used if the type of the field f does not match the type of the field symbol . The specified type type must be compatible with the type of the field symbol. Since no conversion can be performed (as with MOVE , the system must be able to interpret f as a field with this type type .
The type specification is in the form of a literal or a field. At present, only system types ( C, D, T, P, X, N, F, I or W ) are allowed; you can also specify type 's' for 2-byte integer fields with a sign and type 'b' for 1-byte integer fields without a sign (see also DESCRIBE FIELD ).

Note
This statement results in a runtime error if the specified type is unknown or does not match the field to be assigned (due to a missing alignment or an inappropriate length).

Example

DATA LETTER TYPE C.
FIELD-SYMBOLS .
ASSIGN LETTER TO .


The field symbol has the type C and the output length 1.


ASSIGN LETTER TO TYPE 'X'.


The field symbol has the type X and the output length 2.

Addition 2
... DECIMALS dec

Effect
This addition only makes sense when used with type P. The field symbol contains dec decimal places.

Example
Output sales in thousands:


DATA SALES_DEC2(10) TYPE P DECIMALS 2 VALUE 1234567.
FIELD-SYMBOLS .

ASSIGN SALES_DEC2 TO DECIMALS 5.
WRITE: / SALES_DEC2,
/ .


Output:
1,234,567.00
1,234.56700

Note
This statement results in a runtime error if the field symbol has a type other than P at runtime or the specified number of decimal places is not in the range 0 to 14.

Addition 3
... LOCAL COPY OF ...

Effect
With LOCAL COPY OF , the ASSIGN statement can only be used in subroutines. This creates a copy of f which points to the field symbol.

Note
The field symbol must also be defined locally in the subroutine.

Example

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


Output: Carl John Carl

Variant 2
ASSIGN (f) TO .

Additions



1. ... TYPE typ
2. ... DECIMALS dec
3. ... LOCAL COPY OF ...

Effect
Assigns the field whose name is stored in the field f to the field symbol.
The statement " ASSIGN (f)+off(len) TO " is not allowed.

Notes
The search for the field to be assigned is performed as follows:

If the statement is in a subroutine or function module, the system first searches in this modularization unit. If the statement lies outside any such modularization units or if the field is not found there, the system searches for the field in the global data of the program. If the field is not found there, the system searches in the table work areas of the main program of the current program group declared with TABLES

The name of the field to be assigned can also be the name of a field symbol or formal parameter (or even a component of one of these, if the field symbol or the parameter has a structure).
If the name of the field to be assigned is of the form "(program name)field name", the system searches in the global fields of the program with the name "Program name" for the field with the name "Field name". However,it is only found if the program has already been loaded.
Warning: This option is for internal use by specialists only. Incompatible changes or developments may occur at any time without warning or prior notice.


The return code value is set as follows:

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

Example

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


Output: 5

Addition 1
... TYPE typ
Addition 2
... DECIMALS dec
Addition 3
... LOCAL COPY OF ...

Effect
See similar additions of variant 1.

Variant 3
ASSIGN TABLE FIELD (f) TO .

Effect
Identical to variant 2, except that the system searches for the field f only in the data in the current program group declared with TABLES .

The return code value is set as follows:


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

Example

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


Output: XYZ_PROG

Example

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 .
ASSIGN (NAME) TO .
WRITE .
ENDFORM.


Output: Local - although the global table field T100-TEXT has "global" contents. (This kind of name assignment of work fields is, of course, not recommended.)

Example

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 .
ASSIGN (NAME) TO .
WRITE .
MOVE 'G' TO NAME.
ASSIGN (NAME) TO .
WRITE .
MOVE 'TRDIR-NAME' TO NAME.
ASSIGN (NAME) TO .
WRITE .
ENDFORM.


Output: F_local G_global XYZ_PROG

Example

PROGRAM P1MAIN.
TABLES TRDIR.
DATA NAME(30) VALUE 'TFDIR-PNAME'.
FIELD-SYMBOLS .
MOVE 'XYZ_PROG' TO TRDIR-NAME.
PERFORM U(P1SUB).
ASSIGN (NAME) TO .
WRITE .
CALL FUNCTION 'EXAMPLE'.




PROGRAM P1SUB.
TABLES TFDIR.
...
FORM U.
FIELD-SYMBOLS .
DATA NAME(30) VALUE 'TRDIR-NAME'.
ASSIGN TABLE FIELD (NAME) TO .
WRITE .
MOVE 'FCT_PROG' TO TFDIR-PNAME.
ENDFORM.




FUNCTION-POOL FUN1.
FUNCTION EXAMPLE.
DATA NAME(30) VALUE 'TRDIR-NAME'.
FIELD-SYMBOLS .
ASSIGN (NAME) TO .
IF SY-SUBRC = 0.
WRITE .
ELSE.
WRITE / 'TRDIR-NAME cannot be accessed'.
ENDIF.
ENDFUNCTION.


Output: XYZ_PROG FCT_PROG
TRDIR-NAME cannot be accessed

Example

TABLES TRDIR.
MOVE 'XYZ_PROG' to TRDIR-NAME.
PERFORM U USING TRDIR.
FORM U USING X STRUCTURE TRDIR.
FIELD-SYMBOLS .
DATA NAME(30) VALUE 'X-NAME'.
ASSIGN (NAME) TO .
WRITE .
ENDFORM.


Output: XYZ_PROG

Variant 4
ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .

Additions



1. ... TYPE typ
2. ... DECIMALS dec


Effect
Identical to variant 3, except that the system searches for the field whose name is in f steht only in the data in the program group of the main program declared with TABLES . However, the field symbol then points not directly to the found field, but to a copy of this field on theq value stack.
This variant therefore ensures that any access to Dictionary fields of an external program group is read only and no changes are made.

Example



PROGRAM P1MAIN.
TABLES TRDIR.
DATA NAME(30) VALUE 'TFDIR-PNAME'.
FIELD-SYMBOLS .
MOVE 'XYZ_PROG' TO TRDIR-NAME.
CALL FUNCTION 'EXAMPLE'.




FUNCTION-POOL FUN1.
FUNCTION EXAMPLE.
DATA NAME(30) VALUE 'TRDIR-NAME'.
FIELD-SYMBOLS .
ASSIGN LOCAL COPY OF MAIN
TABLE FIELD (NAME) TO .
IF SY-SUBRC = 0.
WRITE .
ELSE.
WRITE / 'TRDIR-NAME cannot be accessed'.
ENDIF.
ENDFUNCTION.


Output: XYZ_PROG

Addition 1
... TYPE typ
Addition 2
... DECIMALS dec

Effect
See similar additions to variant 1.

Variant 5
ASSIGN COMPONENT idx OF STRUCTURE rec TO .
Variant 6
ASSIGN COMPONENT name OF STRUCTURE rec TO .

Additions



1. ... TYPE typ
2. ... DECIMALS dec

Effect
If the field name or idx has the type C or if it is a field string with no internal table, it is treated as a component name. Otherwise, it is considered as a component number. The corresponding component of the field string rec is assigned to the field symbol .

The return code value is set as follows:


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

Note
If idx has the value 0, the entire field string is assigned to the field symbol.

Example

PROGRAM P1MAIN.
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 .
DO 3 TIMES.
ASSIGN COMPONENT SY-INDEX OF
STRUCTURE REC TO .
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE .
ENDDO.
ASSIGN COMPONENT CN OF STRUCTURE REC TO .
WRITE .


Output: a b c d

Addition 1
... TYPE typ
Addition 2
... DECIMALS dec

Effect
See similar additions to variant 1.

Note
Runtime errors

Depending on the operands, the ASSIGN statement can cause runtime errors .

Note
Performance

For performance reasons, you are recommended to use typed field symbols. The runtime for a typed ASSIGN statement amounts to approx. 9 msn (standardized microseconds) against approx. 13 msn for an untyped ASSIGN statement.


Email this Tutorial to my friend
Your Mail ID :
Friend mail ID:
Also send to me

Latest Added Tutorials

SAP PRE-SALE(very urgent requirement) - SAP JOBS INDIA
SAP PRE-SALE(very urgent requirement) - SAP JOBS INDIA
Experiense Required for this job: 6-9 years exp
Job Locations: Mumbai
Apply for this SAP Job in INDIA
SAP ABAP Professionals - SAP JOBS INDIA
SAP ABAP Professionals - SAP JOBS INDIA
Experiense Required for this job: 5 - 7 years exp
Job Locations: Bengaluru / Bangalore, Chennai, Others
Apply for this SAP Job in INDIA
Junior SAP Consultants - SAP JOBS INDIA
Junior SAP Consultants - SAP JOBS INDIA
Experiense Required for this job: 0-5 years exp
Job Locations: Bengaluru/Bangalore
Apply for this SAP Job in INDIA
SAP Plant Maintanence with ETM module - SAP JOBS INDIA
SAP Plant Maintanence with ETM module - SAP JOBS INDIA
Experiense Required for this job: 2-7 years exp
Job Locations: Pune
Apply for this SAP Job in INDIA
SAP Plant Maintainence /PM Consultant/Sr.consultant/TL - SAP JOBS INDIA
SAP Plant Maintainence /PM Consultant/Sr.consultant/TL - SAP JOBS INDIA
Experiense Required for this job: 3-8 years exp
Job Locations: Gurgaon, Kolkata
Apply for this SAP Job in INDIA
Immediate position for SAP ABAP Professionals. - SAP JOBS INDIA
Immediate position for SAP ABAP Professionals. - SAP JOBS INDIA
Experiense Required for this job: 5-9 years exp
Job Locations: Bengaluru/Bangalore, Chennai, Gurgaon
Apply for this SAP Job in INDIA
SAP - IS Retail (SRS) Consultant - SAP JOBS INDIA
SAP - IS Retail (SRS) Consultant - SAP JOBS INDIA
Experiense Required for this job: 5-8 years exp
Job Locations: Bengaluru/Bangalore
Apply for this SAP Job in INDIA
SAP BPC/EPM - SAP JOBS INDIA
SAP BPC/EPM - SAP JOBS INDIA
Experiense Required for this job: 4-9 years exp
Job Locations: Bengaluru/Bangalore, Hyderabad / Secunderabad, Pune
Apply for this SAP Job in INDIA
LOOKING FOR TECHNICAL AND FUNCTIONAL LEADS AND MANAGERS(SAP) - SAP JOBS INDIA
LOOKING FOR TECHNICAL AND FUNCTIONAL LEADS AND MANAGERS(SAP) - SAP JOBS INDIA
Experiense Required for this job: 3-8 years exp
Job Locations: Bengaluru/Bangalore, Chennai
Apply for this SAP Job in INDIA
SAP FICO Consultant - SAP JOBS INDIA
SAP FICO Consultant - SAP JOBS INDIA
Experiense Required for this job: 5-10 years exp
Job Locations: Hyderabad / Secunderabad
Apply for this SAP Job in INDIA

Most readed 5 Tutorials

List of SAP MM Transaction codes
This documentation covers the details of SAP MM Transaction codes
WRITE - Output to a list ( SAP ABAP Keyword)
WRITE ( Output to a list ) is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.
FI Accounts Receivable and Accounts Payable | SAP FI PDF manual
The following topics are an introduction to the Accounts Receivable and Accounts Payable application components.
List of SAP HR TABLES and Infotypes tables
Detailed full list of tables and infotypes used in SAP HR module.
Report Programming in HR | SAP PDF study material )
This document is intended for all persons who would like to program their own reports in SAP HR or customize standard ones. The documentation is not intended to be an introduction to programming. It contains just the special features that form part of programming in SAP HR.A general knowledge of ABAP programming and HR applications is a prerequisite. This can be acquired by reading the relevant documentation and attending the courses.This document provides information which enables programmers to become acquainted with the special features of programming in HR.
  

CATEGORIES

  ABAP
  Advanced ABAP
  SAP JOBS
  SAP Functional Modules
  SAP R/3
  SAP NetWeaver
   
SAP Technical PDF Tutorials

ABAP
DICTIONARY
INTERNAL TABLES
ALV Reports
SAPSCRIPTS
SMARTFORMS
LSMW
BDC
ALE
IDOC
USER EXITS
TRANSPORTING
ITS


SAP Functional PDF  Tutorials

FI (Financial)
CO (Controlling)
HR (Human Resource)
LO (Logistics)
MM (Materials Management)
PP (Production Planning)
QM (Quality Management)
SD (Sales and Distribution)
TR (Treasury and cash)
WM (Warehouse Management)
PS (project Systems)
PM (plant Maintenance)
CA (Cross Application)


SAP References

transaction codes
System Fields
Function Modules
SAP TABLES
code optimization


TOOLS

SQL Trace tool
Runtime Analysis
LSMW
ABAP Query
CTS


SAP Emerging Technologies

SAP Advanced Planner and Optimizer (APO)
SAP Business Information Warehouse
(BW)

SAP Business Intelligence
(BI)

SAP Customer Relationship Management
(CRM)
SAP Enterprise Portal (EP)
SAP Exchange Infrastructure
(XI)

Human Resource Management Systems
(HRMS)
SAP Manufacturing
SAP Master Data Management
(MDM)

SAP Knowledge Warehouse
(KW)

SAP Product Lifecycle Management
(PLM)

SAP Service and Asset Management

SAP Strategic Enterprise Management
(SEM)

SAP Solutions for mobile business

SAP Solution Manager

SAP Training and Event Management
(TEM)
SAP Web Application Server
(Web AS)
SAP xApps



Jobs in Kerala

 
Custom Search
  site contact sapbrain.support@gmail.com All of the product names here are trademarks of their respective companies. The site www.sapbrainsonline.com no way affiliated with SAP AG. Use information on this site at your own risk. Information furnished in the site is collected from various sites and posts from users. This site does not host any files on its server. If any compliants about the posts please contact us at sapbrain.support@gmail.com, we are ready to move the posts.
Complete SAP Study materials | SAP JOBS | PDF Tutorials web counter