Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Get/Set Parameter

Former Member
0 Likes
1,817

Hi,

What is GET/SET Parameter?

Regards,

Luke

6 REPLIES 6
Read only

Former Member
0 Likes
1,412
Read only

Former Member
0 Likes
1,412

Hi

To fill the input fields of a called transaction with data from the calling program, you can use the SPA/GPA technique. SPA/GPA parameters are values that the system stores in the global, user-specific SAP memory. SAP memory allows you to pass values between programs. A user can access the values stored in the SAP memory during one terminal session for all parallel sessions. Each SPA/GPA parameter is identified by a 20-character code. You can maintain them in the Repository Browser in the ABAP Workbench. The values in SPA/GPA parameters are user-specific.

ABAP programs can access the parameters using the SET PARAMETER and GET PARAMETER statements.

To fill one, use:

SET PARAMETER ID <pid> FIELD <f>.

This statement saves the contents of field <f> under the ID <pid> in the SAP memory. The code <pid> can be up to 20 characters long. If there was already a value stored under <pid>, this statement overwrites it. If the ID <pid> does not exist, double-click <pid> in the ABAP Editor to create a new parameter object.

To read an SPA/GPA parameter, use:

GET PARAMETER ID <pid> FIELD <f>.

This statement fills the value stored under the ID <pid> into the variable <f>. If the system does not find a value for <pid> in the SAP memory, it sets SY-SUBRC to 4, otherwise to 0.

To fill the initial screen of a program using SPA/GPA parameters, you normally only need the SET PARAMETER statement.

The relevant fields must each be linked to an SPA/GPA parameter.

On a selection screen, you link fields to parameters using the MEMORY ID addition in the PARAMETERS or SELECT-OPTIONS statement. If you specify an SPA/GPA parameter ID when you declare a parameter or selection option, the corresponding input field is linked to that input field.

On a screen, you link fields to parameters in the Screen Painter. When you define the field attributes of an input field, you can enter the name of an SPA/GPA parameter in the Parameter ID field in the screen attributes. The SET parameter and GET parameter checkboxes allow you to specify whether the field should be filled from the corresponding SPA/GPA parameter in the PBO event, and whether the SPA/GPA parameter should be filled with the value from the screen in the PAI event.

When an input field is linked to an SPA/GPA parameter, it is initialized with the current value of the parameter each time the screen is displayed. This is the reason why fields on screens in the R/3 System often already contain values when you call them more than once.

When you call programs, you can use SPA/GPA parameters with no additional programming overhead if, for example, you need to fill obligatory fields on the initial screen of the called program. The system simply transfers the values from the parameters into the input fields of the called program.

However, you can control the contents of the parameters from your program by using the SET PARAMETER statement before the actual program call. This technique is particularly useful if you want to skip the initial screen of the called program and that screen contains obligatory fields.

If you want to set SPA/GPA parameters before a program call, you need to know which parameters are linked to which fields on the initial screen. A simple way of doing this is to start the program that you want to call, place the cursor on the input fields, and choose F1 followed by Technical info. The Parameter ID field contains the name of the corresponding SPA/GPA parameter. Alternatively, you can look at the screen definition in the Screen Painter.

http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9e0435c111d1829f0000e829fbfe/content.htm

A parameter id allows you to store and retrieve values for a specific user, see below for syntax on how to perform these operations.

The program displays a report containing what the value of the parameter id is before you run the SAP program and what it is after wards. Before will contain blank or what ever you entered last time the program was executed, and the after value will be the value you entered onto the ABAP selection screen this time.

Example program,:

REPORT PARAMID .

data: gd_valuein(10) type c,

gd_valueout(10) type c.

PARAMETERS: p_value(10) type c.

********************

*start-of-selection.

start-of-selection.

get parameter ID 'ZMESS' field gd_valuein.

set parameter ID 'ZMESS' field p_value.

get parameter ID 'ZMESS' field gd_valueout.

******************

*end-of-selection.

end-of-selection.

write:/ 'value at start of program:', gd_valuein,

/ 'value at end of program:', gd_valueout.

Read only

0 Likes
1,412

Thanks, Naresh Nelapatla.

I want to ask another question about memory id.

For example, I wrote a report like this:

REPORT ZTEST.

PARAMETERS P_TEST TYPE C LENGTH 10 MEMORY ID AAAA.

When I first run this program, in selection screen, I inputed 'test'; then I back to the editor, then run this program again, in the input field, the value is 'test'! But I didn't input that, the field is filled automaticly.

Can you explain this?

Regard,

feng.

Read only

former_member188829
Active Contributor
0 Likes
1,412

Hi,

Check this thread..

Read only

Former Member
0 Likes
1,412

Hi,

I will try to explain in an easy language.

Say whenever you open any transaction,

it has many input screen fields.

In many case you might have seen that some

of them contains some default values.

These default values are not input directly but

are input in a fields called parameter ID which

are nothing but memory cache which is active till

you are logged in.

Now using SET parameter ID <PID>.

we set the parameter ID to some field where we

want some default value.

By GET parameter ID<PID>.

we can get the value that has been set into

a particular parameter ID (memory cache) for

our own processing in our program.

Read only

Former Member
0 Likes
1,412

thank you

Regards,

Luke