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

How to declare local variable for table fields?

Former Member
0 Likes
4,775

Hi friends,

I have strucked with the local variable declaration.

Can anyone tell me how to declare local variables for table fields.

And this local variable must hold the data...

How this local variable can be used in select statement so tht when i click save in screen painter it has to store the value.

2 REPLIES 2
Read only

Former Member
0 Likes
1,527

Hi,

Jus for idea i am giving the following its not complete code

DATA:V_KNA1 TYPE KNA1,

V_FIELD(50) TYPE C,

V_VALUE1 TYPE KNA1-KUNNR ,

V_VALUE2 TYPE KNA1-KUNNR ,

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS:SO_CUST FOR V_KNA1-KUNNR OBLIGATORY.

SELECTION-SCREEN SKIP.

PARAMETER:P_HITS(10).

SELECTION-SCREEN END OF BLOCK B1.

SELECT KUNNR

NAME1

FROM KNA1 UP TO P_HITS ROWS

INTO TABLE IT_KNA1

WHERE KUNNR IN SO_CUST .

Regards,

kavitha.

Read only

Former Member
0 Likes
1,527

<REMOVED BY MODERATOR>

The scope where you declare the variable will determine whether the variable is local or global.

Global variable is declared at main program.

Local variable is declared at subroutines, functions.

I had found a keyword LOCAL. Herewith is some details on it.

The LOCAL statement can only be used after FORM and FUNCTION.

Saves the current value of the specified field f when you enter the routine and restores it when you leave the routine.

You should not regard the LOCAL statement as a declaration. It only saves the value of f at the point where the form was called.

You can also use LOCAL for field symbols and formal parameters. With field symbols, it not only saves and restores the field reference created using ASSIGN, but also the contents of the field referenced when you enter the routine.

With formal parameters, please note that although changing the value of the formal parameter does not affect the actual parameter after you leave the routine (if you specified the formal parameter after LOCAL), the values of the formal and actual parameter within the routine are always identical.

This contrasts with the VALUE specification (see FORM) where changing the passed field within the routine does not affect the value of the formal parameter.

Example

code

DATA text TYPE string VALUE `Global text`.

WRITE / text.

PERFORM subr1.

WRITE / text.

FORM subr1.

LOCAL text.

text = `Text in subr1`.

WRITE / text.

PERFORM subr2 USING text.

WRITE / text.

ENDFORM.

FORM subr2 USING para TYPE string.

LOCAL para.

para = `Text in subr2`.

WRITE / text.

ENDFORM.

[/code]

When the example is executed, the system temporarily (and seperately) stores the value of the global variant text twice. Once by specifying the name in subr1 and the second time by specifying the formal parameter para, which text is transferred to by reference. After its return from subr2, text has the value set in subr1 and after its return from subr1, text has the value set in the main program.

Note

You cannot use the LOCAL statement with internal tables if the code before and after the statement has been called within a LOOP performed on an internal table.

Within a loop performed on an internal table, the MOVE statement is carried out by the LOCAL statement and the table is then copied back. This destroys the LOOP administration for the table.

Regards

sas

Edited by: Alvaro Tejada Galindo on Apr 11, 2008 12:52 PM