ABAP SYNTEAX FOR AUTHORITY-CHECK

Basic form

AUTHORITY-CHECK OBJECT object
ID name1 FIELD f1
ID name2 FIELD f2
...
ID name10 FIELD f10.

Effect

Explanation of IDs:
object Field which contains the name of the object for which the authorization is to be checked.
name1 ... Fields which contain the names of the name10 authorization fields defined in the object.
f1 ... Fields which contain the values for which the f10 authorization is to be checked.
AUTHORITY-CHECK checks for one object whether the user has an authorization that contains all values of f (see SAP authorization concept).
You must specify all authorizations for an object and a also a value for each ID (or DUMMY ).
The system checks the values for the ID s by AND-ing them together, i.e. all values must be part of an authorization assigned to the user.
If a user has several authorizations for an object, the values are OR-ed together. This means that if the CHECK finds all the specified values in one authorization, the user can proceed. Only if none of the authorizations for a user contains all the required values is the user rejected.
If the return code SY-SUBRC = 0, the user has the required authorization and may continue.

The return code is modified to suit the different error scenarios. The return code values have the following meaning:
4 User has no authorization in the SAP System for such an action. If necessary, change the user master record.
8 Too many parameters (fields, values). Maximum allowed is 10.
12 Specified object not maintained in the user master record.
16 No profile entered in the user master record.
24 The field names of the check call do not match those of an authorization. Either the authorization or the call is incorrect.
28 Incorrect structure for user master record.
32 Incorrect structure for user master record.
36 Incorrect structure for user master record.

If the return code value is 8 or possibly 24, inform the person responsible for the program. If the return code value is 4, 12, 15 or 24, consult your system administrator if you think you should have the relevant authorization. In the case of errors 28 to 36, contact SAP, since authorizations have probably been destroyed.
Individual authorizations are assigned to users in their respective user profiles, i.e. they are grouped together in profiles which are stored in the user master record.

Instead of ID name FIELD f , you can also write ID name DUMMY . This means that no check is performed for the field concerned.
The check can only be performed on CHAR fields. All other field types result in 'unauthorized'.

Example

Check whether the user is authorized for a particular plant. In this case, the following authorization object applies:

Table OBJ : Definition of authorization object

M_EINF_WRK
ACTVT
WERKS

Here, M_EINF_WRK is the object name, whilst ACTVT and WERKS are authorization fields. For example, a user with the authorizations

M_EINF_WRK_BERECH1
ACTVT 01-03
WERKS 0001-0003 .

can display and change plants within the Purchasing and Materials Management areas.

Such a user would thus pass the checks
 
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
    ID 'WERKS' FIELD '0002'
    ID 'ACTVT' FIELD '02'.
 
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
    ID 'WERKS' DUMMY
    ID 'ACTVT' FIELD '01':
but would fail the check
 
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
    ID 'WERKS' FIELD '0005'
    ID 'ACTVT' FIELD '04'.

To suppress unnecessary authorization checks or to carry out checks before the user has entered all the values, use DUMMY - as in this example. You can confirm the authorization later with another AUTHORITY-CHECK .


RELATED POST

AT EVENTS SYNTAX FOR ABAP
What is SAP and Why do we are in need of It
What is SAP Full form and its definition part one

AT Events on selection screen SAP ABAP SYNTAX PART TWO

Addition 6

... ON BLOCK block

Effect

This event is assigned to the blocks on the selection screen defined by SELECTION SCREEN BEGIN/END BLOCK .
If the report starts an error dialog at this point, precisely these fields of the block block become ready for input again.

In which sequence are the events AT SELECTION-SCREEN ON psel ... , AT SELECTION-SCREEN ON RADIOBUTTON GROUP ... , AT SELECTION-SCREEN ON BLOCK ... , AT SELECTION-SCREEN processed?
The AT SELECTION-SCREEN ON psel ... events assigned to the parameters or selection options are executed in the sequence they are declared in the program, i.e. in the sequence they appear on the selection screen.
The events assigned to the radio button groups are executed according to the first parameter of the radio button group.
The events assigned to the blocks are executed "from the inside to the outside".

Example

 SELECT-OPTIONS SEL0 FOR SY-TVAR0.
 
SELECTION-SCREEN BEGIN OF BLOCK BL0.
  SELECT-OPTIONS SEL1 FOR SY-TVAR1.
 
  SELECTION-SCREEN BEGIN OF BLOCK BL1.
    PARAMETERS P0 RADIOBUTTON GROUP RADI.
    PARAMETERS P1 RADIOBUTTON GROUP RADI.
 
    SELECTION-SCREEN BEGIN OF BLOCK BL2.
      PARAMETERS P3.
    SELECTION-SCREEN END   OF BLOCK BL2.
 
    SELECT-OPTIONS SEL2 FOR SY-TVAR2.
 
  SELECTION-SCREEN END   OF BLOCK BL1.
 
SELECTION-SCREEN END   OF BLOCK BL0.

Sequence:

AT SELECTION-SCREEN ON...
SEL0
SEL1
RADIOBUTTON GROUP RADI
P3
BLOCK BL2
SEL2
BLOCK BL1
BLOCK BL0

AT SELECTION-SCREEN is executed at the very end.

Addition 7

... OUTPUT

Effect

This event is executed at PBO of the selection screen every time the user presses ENTER - in contrast to INITIALIZATION . Therefore, this event is not suitable for setting selection screen default values. Also, since AT SELECTION-SCREEN OUTPUT is first executed after the variant is imported (if a variant is used) and after adopting any values specified under SUBMIT in the WITH clause, changing the report parameters or the selection options in AT SELECTION-SCREEN OUTPUT would destroy the specified values.
Here, however, you can use LOOP AT SCREEN or MODIFY SCREEN to change the input/output attributes of selection screen fields.

Example

Output all fields of the SELECT-OPTION NAME highlighted:
 
SELECT-OPTIONS NAME FOR SY-REPID MODIF ID XYZ.
...
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    CHECK SCREEN-GROUP1 = 'XYZ'.
    SCREEN-INTENSIFIED = '1'.
    MODIFY SCREEN.
  ENDLOOP.
The addition MODIF ID XYZ to the key word SELECT-OPTIONS assigns all fields of the selection option NAME to a group you can read in the field SCREEN-GROUP1 . At PBO of the selection screen, all these fields are then set to highlighted.


RELATED POST

AT - Events on selection screens syntax for sap abap

Basic form

AT SELECTION-SCREEN.

Additions

1. ... ON psel
2. ... ON END OF sel
3. ... ON VALUE-REQUEST FOR psel_low_high .
4. ... ON HELP-REQUEST FOR psel_low_high
5. ... ON RADIOBUTTON GROUP radi
6. ... ON BLOCK block
7. ... OUTPUT

Effect

This event only makes sense in reports, i.e. in programs set to type 1 in the attributes. Type 1 programs are started via a logical database and always have a selection screen where the user can specify the database selections.
The event is processed when the selection screen has been
processed (at the end of PAI ).
If an error message ( MESSAGE Emnr ) is sent during the event, all fields on the selection screen become ready for input.
After further user input, AT SELECTION-SCREEN is executed again.
You should only perform very expensive checks with AT SELECTION-SCREEN if the program is then started (not every time the user presses ENTER). Here, you can read the system field SSCRFIELDS-UCOMM (provided a statement TABLES SSCRFIELDS exists). If the field has one of the values 'ONLI' (= Execute) or 'PRIN' (= Execute and Print), the report is then started, i.e. the selection screen is closed and the processing continues with START OF SELECTION . Remember that the selection screen (and thus also AT SELECTION-SCREE N ) is also processed in variant maintenance and with SUBMIT VIA JOB . You can determine which of these applies by calling the function module RS_SUBMIT_INFO .

Addition 1

... ON psel

Effect

This event is assigned to the selection screen fields corresponding to the report parameter or selection criterion psel .
If the report starts an error dialog at this point, precisely these fields become ready for input.

Addition 2

... ON END OF sel

Effect

For each selection criterion sel on the selection screen, you can call a further screen by pressing a pushbutton. On this screen, you can enter any number of single values and ranges for the selection criterion sel .
When this screen has been processed (i.e. at the end of PAI for this screen), the event AT SELECTION-SCREEN ON END OF sel is executed.
At this point, all the values entered are available in the internal table sel .

Addition 3

... ON VALUE-REQUEST FOR psel_low_high

Effect

With this addition, the field psel_low_high is either the name of a report parameter or of the form sel-LOW or sel-HIGH , where sel is the name of a selection criterion. The effect of this is twofold:

The pushbutton for F4 (Possible entries) appears beside the appropriate field.

When the user selects this pushbutton or presses F4 for the field, the event is executed. You can thus implement a self-programmed possible entries routine for the input/output fields of the selection screen. If the program contains such an event and the user presses F4 , the system processes this rather than displaying the check table or the fixed values of the Dictionary field - even if the report parameter or the selection option with LIKE or FOR points to a Dictionary field. You can, for example, use the CALL SCREEN statement to display a selection list of possible values. The contents of the field psel_low_high at the end of this processing block are copied to the appropriate input/output field.

This addition is only allowed with report-specific parameters (PARAMETERS ) or selection options ( SELECT OPTIONS ). For database-specific parameters or selection options, you can achieve the same effect by using the addition VALUE-REQUEST FOR ... with the key word PARAMETERS or SELECT-OPTIONS in the include DBxyzSEL (where xyz = name of logical database). In this case, you must program the value help in the database program SAPDBxyz .

Addition 4

... ON HELP-REQUEST FOR psel_low_high

Effect

As with the addition ON VALUE-REQUEST the field psel_low_high is either the name of a report parameter or of the form sel-LOW or sel-HIGH , where sel is the name of a selection criterion. When the user presses F1 on the relevant field, the subsequent processing block is executed. You can thus implement a self-programmed help for the input/output fields of the selection screen. If the program contains such an event and the user presses F1 , the system processes this rather than displaying the documentation of the Dictionary field - even if the report parameter or the selection option with LIKE or FOR points to a Dictionary field.
This addition is only allowed with report-specific parameters (PARAMETERS ) or selection options (SELECT-OPTIONS ). For database-specific parameters or selection options, you can achieve the same effect by using the addition HELP-REQUEST FOR ... with the key word PARAMETERS or SELECT-OPTIONS in the include DBxyzSEL (where xyz = name of logical database). In this case, you must program the help in the database program SAPDBxyz .

Addition 5

... ON RADIOBUTTON GROUP radi

Effect

This event is assigned to the radio button groups on the selection screen defined by PARAMETERS PAR RADIO BUTTON GROUP RADI.
If the report starts an error dialog at this point, precisely these fields of the radio button group radi become ready for input again.

Addition 6

... ON BLOCK block

Effect

This event is assigned to the blocks on the selection screen defined by BEGIN/END OF SELECTION SCREEN.
If the report starts an error dialog at this point, precisely these fields of the block block become ready for input again.

RELATED POST

AT Events in lists in abap part two

Variant 2

AT USER-COMMAND.

Effect

Event in interactive reporting

This event is executed whenever the user presses a function key in the list or makes an entry in the command field .

Some functions are executed directly by the system and thus cannot be processed by programs. These include:
PICK See variant AT LINE-SELECTION PFn See variant AT PFn /... System command %... System command PRI Print BACK Back RW Cancel P... Scroll function (e.g.: P+ , P- , PP+3 , PS-- etc.)

Instead of this functions, you can use the scroll statement in programs.

Since many of these system functions begin with "P", you should avoid using this letter to start your own function codes.

Otherwise, the effect is as for AT LINE-SELECTION ; also, the current function code is stored in the system field SY-UCOMM .

Example

 
DATA: NUMBER1 TYPE I VALUE 20,
      NUMBER2 TYPE I VALUE  5,
      RESULT  TYPE I.
 
START-OF-SELECTION.
  WRITE: / NUMBER1, '?', NUMBER2.
 
AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'ADD'.
      RESULT = NUMBER1 + NUMBER2.
    WHEN 'SUBT'.
      RESULT = NUMBER1 - NUMBER2.
    WHEN 'MULT'.
      RESULT = NUMBER1 * NUMBER2.
    WHEN 'DIVI'.
      RESULT = NUMBER1 / NUMBER2.
    WHEN OTHERS.
      WRITE 'Unknown function code'.
      EXIT.
  ENDCASE.
  WRITE: / 'Result:', RESULT.

After entry of a function code, the appropriate processing is performed under the event AT USER-COMMAND and the result is displayed in the details list.

Variant 3

AT PFn.

Effect

Event in interactive reporting

Here, n stands for a numeric value between 0 and 99.
This event is executed whenever the user presses a function key that contains the function code PFn in the interface definition. The default status for lists contains some of these functions.

Otherwise, the effect is as for the variant AT LINE-SELECTION . The cursor can be on any line.
To ensure that the chosen function is executed only for valid lines, you can check the current HIDE information. This variant should be used only for test or prototyping purposes, since the default status is not normally used. Instead, you should set a program-specific status with SET PF-STATUS . This should not contain any function codes beginning with " PF ".

Example

 
DATA NUMBER LIKE SY-INDEX.
 
START-OF-SELECTION.
  DO 9 TIMES.
    WRITE: / 'Row', (2) SY-INDEX.
    NUMBER = SY-INDEX.
    HIDE NUMBER.
  ENDDO.
 
AT PF8.
  CHECK NOT NUMBER IS INITIAL.
  WRITE: / 'Cursor was in row', (2) NUMBER.
  CLEAR NUMBER.


RELATED POST

AT EVENTS IN LISTS PART ONE

What is SAP and Why do we are in need of It

AT Events in lists in abap

Variants

1. AT LINE-SELECTION.
2. AT USER-COMMAND.
3. AT PFn.

Variant 1

AT LINE-SELECTION.

Effect

Event in interactive reporting This event is processed whenever the user chooses a valid line in the list (i.e. a line generated by statements such as WRITE , ULINE or SKIP ) with the cursor and presses the function key which has the function PICK in the interface definition. This should normally be the function key F2 , because it has the same effect as double-clicking the mouse, or single-clicking in the case of a HOTSPOT .
The processing for the event AT LINE-SELECTION usually generates further list output (the details list) which completely covers the current list display. If the latter is still visible (to aid user orientation), this may be due to the key word WINDOW .
In most cases, the information is from the selected line is used
to retrieve more comprehensive information by direct reading. When displaying the original list, you store the key terms needed for this in the HIDE area of the output line.
You can choose a line and start new processing even in the details lists.
The following system fields are useful for orientation purposes, since their values change with each interactive event executed.
SY-LSIND Index of list created by current event (basic list = 0, 1st details list = 1, ...) SY-PFKEY Status of displayed list ( SET PF STATUS ) SY-LISEL Contents of selected line SY-LILLI Absolute number of this line in the displayed list SY-LISTI Index of this list - usually SY-LSIND - 1 ( READ LINE ) SY-CUROW Last cursor position: Line in window SY-CUCOL Last cursor position: Column in window ( GET CURSOR) SY-CPAGE 1st displayed page of displayed list SY-STARO 1st displayed line of this page of displayed list SY-STACO 1st displayed column of displayed list ( SCROLL LIST )
The system field SY-LSIND defines the line selection level (basic list: SY-LSIND = 0).

Example

 
DATA TEXT(20).
 
START-OF-SELECTION.
  PERFORM WRITE_AND_HIDE USING SPACE SPACE.
 
AT LINE-SELECTION.
  CASE TEXT.
    WHEN 'List index'.
      PERFORM WRITE_AND_HIDE USING 'X' SPACE.
    WHEN 'User command'.
      PERFORM WRITE_AND_HIDE USING SPACE 'X'.
    WHEN OTHERS.
      SUBTRACT 2 FROM SY-LSIND.
      PERFORM WRITE_AND_HIDE USING SPACE SPACE.
  ENDCASE.
  CLEAR TEXT.
 
FORM WRITE_AND_HIDE USING P_FLAG_LSIND P_FLAG_UCOMM.
  WRITE / 'SY-LSIND:'.
  PERFORM WRITE_WITH_COLOR USING SY-LSIND P_FLAG_LSIND.
  TEXT = 'List index'.
  HIDE TEXT.
  WRITE / 'SY-UCOMM:'.
  PERFORM WRITE_WITH_COLOR USING SY-UCOMM P_FLAG_UCOMM.
  TEXT = 'User command'.
  HIDE TEXT.
  IF SY-LSIND > 0.
    WRITE / 'PICK here to go back one list level'.
  ENDIF.
ENDFORM.
 
FORM WRITE_WITH_COLOR USING P_VALUE
                            P_FLAG_POSITIVE.
  IF P_FLAG_POSITIVE = SPACE.
    WRITE P_VALUE COLOR COL_NORMAL.
  ELSE.

Depending on whether you choose the line at SY-LSIND or SY-UCOMM , the next details list
contains the corresponding value with the color "positive". If the line is chosen without HIDE
information, the list level is reduced.

RELATED POST

SYNTAX FOR CONTROL BREAK IN SAP ABAP

SAP architecture,its full form of working and enjoy sap products
SAP journey from R/3 towards MySAP.com

sap abap syntax for Control break with internal tables

Variants

1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.

Effect

In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with END AT . The sequence of statements which lies between them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was SORTED .

At the start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:
  • All default key fields (on the right) are filled with "*" after the current control level key.
  • All other fields (on the right) are set to their initial values after the current control level key.
Between AT and ENDAT , you can use SUM to insert the appropriate control totals in the number fields (see also ABAP/4 number types ) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level ( AT FIRST , AT NEW f ) and also the end of a control level ( AT END OF f , AT LAST ).

At the end of the control level processing (i.e. after ENDAT ), the old contents of the LOOP output area are restored.
When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.
If an internal table is processed only in a restricted form (using the additions FROM , TO and/or WHERE with the LOOPS statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.

With LOOP s on extracts, there are also special control breaks and strectures you can use.
Runtime errors
  • SUM_OVERFLOW : Overflow when calculating totals with SUM .

Variant 1

AT NEW f.

Variant 2

AT END OF f.

Effect

f is a sub-field of an internal table processed with LOOP . The sequence of statements which follow it is executed if the sub-field f or a sub-field in the current LOOP line defined (on the
left) before f has a differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.

Example

DATA: BEGIN OF COMPANIES OCCURS 20,
        NAME(30),
        PRODUCT(20),
        SALES TYPE I,
      END   OF COMPANIES.
...
LOOP AT COMPANIES.
  AT NEW NAME.
    NEW-PAGE.
    WRITE / COMPANIES-NAME.
  ENDAT.
  WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
  AT END OF NAME.
    SUM.
    WRITE: / COMPANIES-NAME, COMPANIES-SALES.
  ENDAT.
ENDLOOP.

The AT statements refer to the field COMPANIES-NAME .

If a control break criterion is not known until runtime, you can use AT NEW (name) or AT END OF (name) to specify it dynamically as the contents of the field name . If name is blank at runtime, the control break criterion is ignored and the sequence of statements is not executed. If name contains an invalid component name, a runtime error occurs.
By defining an offset and/or length, you can further restrict control break criteria - regardless of whether they are specified statically or dynamically.
A field symbol pointing to the LOOP output area can also be used as a dynamic control break criterion. If the field symbol does not point to the LOOP output area, a runtime error occurs.

Runtime errors
  • AT_BAD_PARTIAL_FIELD_ACCESS : Invalid sub-field access when dynamically specifying the control break criterion.
  • AT_ITAB_FIELD_INVALID : When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.
ITAB_ILLEGAL_COMPONENT : When dynamically specifying the control break criterion via (name) the field name does not contain a valid sub-field name.

RELATED POST
What is SAP and Why do we are in need of It
SAP architecture,its full form of working and enjoy sap products
SAP journey from R/3 towards MySAP.com


SAP ABAP SYNTAX FOR ASSIGN PART TWO

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.

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

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.

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.

SAP ABAP SYNTAX FOR ASSIGN


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 run time, i.e. every change to the contents of f is reflected in and vice versa. If the field symbol is not typed 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 .
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.

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.

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.

RELATED POST