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

Assign value to global variables in a different function group

Former Member
0 Likes
3,163

Hi all,

What's the best way of assigning values in the caller program to some global variables defined in the TOP include of a different function group? The one way I know of, which is to create a new function module in the target function group and pass the data via import parameters is not feasible for our development because that would be considered a standard code modification.

The problem can be described as follows:

Caller Function Group : A

Program: caller_program

Pseudo code:

gv_var_1 = 'A'

call function 'USE_GV_VAR'

Called (Target) Function group : B

Top include : LBTOP

LBTOP Code: Data: gv_var_1(1).

Function Module: USE_GV_VAR

USE_GV_VAR Code: if gv_var_1 == 'A'

....

Thanks!!

Jay

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,050

Hi Jay,

One idea could be:

1. Create a new Z-Function group.

2. copy your two function modules from Group A and group B to the Z-group under the name with prefix Z.

3. both TOP-includes have to be combined properly (I guess you can't use both TOP include together. This caused naming problems - probably?!)

Then you have access to all the TOP-fields.

Think about it. May be it works; or it gives you another idea for a solution.

Have luck,

Heinz

Hi all,

What's the best way of assigning values in the caller program to some global variables defined in the TOP include of a different function group? The one way I know of, which is to create a new function module in the target function group and pass the data via import parameters is not feasible for our development because that would be considered a standard code modification.

The problem can be described as follows:

Caller Function Group : A

Program: caller_program

Pseudo code:

gv_var_1 = 'A'

call function 'USE_GV_VAR'

Called (Target) Function group : B

Top include : LBTOP

LBTOP Code: Data: gv_var_1(1).

Function Module: USE_GV_VAR

USE_GV_VAR Code: if gv_var_1 == 'A'

....

Thanks!!

Jay

5 REPLIES 5
Read only

Former Member
0 Likes
2,051

Hi Jay,

One idea could be:

1. Create a new Z-Function group.

2. copy your two function modules from Group A and group B to the Z-group under the name with prefix Z.

3. both TOP-includes have to be combined properly (I guess you can't use both TOP include together. This caused naming problems - probably?!)

Then you have access to all the TOP-fields.

Think about it. May be it works; or it gives you another idea for a solution.

Have luck,

Heinz

Read only

0 Likes
2,050

Hello Heinz,

Accessing the variable by name is not the concern, but to access and assign value to the variable that is in the roll area of Function Group of B. Even Function Group A can make use of a variable named gv_var_1, it is in the roll area of A, not B. Hence when the function module in B is called, the variable gv_var_1 there is still initial.

Jay

Read only

0 Likes
2,050

You need to have some function module in function group B to modify that variable of function group B.

You can not alter its value from different function group. However you can access its value by using calling stack . For example:

DATA: GW_FIELD(60) TYPE C,

L_WBSTK TYPE VBUK-WBSTK.

FIELD-SYMBOLS: <GW_WBSTK_VAL> TYPE VBUK-WBSTK.

CLEAR: GW_FIELD, L_WBSTK.

MOVE '(SAPMV50A)XVBUK-WBSTK' TO GW_FIELD.

ASSIGN (GW_FIELD) TO <GW_WBSTK_VAL>.

IF <GW_WBSTK_VAL> IS ASSIGNED.

L_WBSTK = <GW_WBSTK_VAL>.

ENDIF.

G@urav.

Read only

0 Likes
2,050

Thank you, Gaurav. I needed this hint just today. Saved me from making a modification.

Frank

Read only

0 Likes
2,050

Thank you Gaurav