ABAP assigns a value to a dynamic variable

Source: Internet
Author: User

"Transfer from http://blog.csdn.net/forever_crazy/article/details/6544830"

Requirements: Sometimes write a program, you need to assign a dynamic variable operation, when the field is a long time, if the regular method of assigning value will appear to be very redundant code, in fact, can be assigned by the indirect address of the variable.

EX1:

Data c1 type CHAR10.

Data c2 type Char10.

Field-symbols <fs> Type any.

C1 = ' C2 '. Note: The variable "C2" to be assigned at this point must be capitalized, because in the ABAP internal variable names are saved in uppercase format.

C2 = ' test1 '.

Assign (C1) to <fs>.

<fs> = ' test2 '.

The contents of the variable C2 are then ' test2 ' by ' test1 '.

This method is suitable for use when multiple variables are to be dynamically assigned.

Here's an example: Click the button to set the button text to ' Test '.

Data ok_code type Sy-ucomm.

Data l_but type Char10.

Field-symbols <fs> Type any.

Parameters

Pushbutton 2 (Ten) PB1 User-command PB1,

Pushbutton (Ten) Pb2 User-command PB2,

Pushbutton (Ten) pb3 User-command pb3,

Pushbutton (Ten) pb4 User-command pb4.

At Selection-screen.

Ok_code = Sy-ucomm.

L_but = Ok_code.

Assign (l_but) to <fs>.

<fs> = ' Test '.

This method reduces the need to judge each button and assigns values, reducing the redundancy of the code.

ABAP assigns a value to a dynamic variable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.