cancel
Showing results for 
Search instead for 
Did you mean: 

help me

Former Member
0 Kudos

i am not understanding the output how does it work

REPORT demo_mod_tech_data_types .

TYPES word(10) TYPE c.

DATA text TYPE word.

text = '1234567890'. WRITE / text.

PERFORM datatest.

WRITE / text.

FORM datatest.

TYPES word(5) TYPE c.

DATA text TYPE word.

text = 'ABCDEFGHJK'. WRITE / text.

ENDFORM.

output:-

1234567890

ABCDE

1234567890

Accepted Solutions (1)

Accepted Solutions (1)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

If Types is used,then we can refer the other data type through it.

So they have declared word as character of length 10 which is user defined type.So while we use

data text type word.

text refers to data type character of length 10.

They are just writting the text.So '1234567890' is coming as output in the first line.

After that they are calling the subroutine dataset.

There word is declared as user defined type of length 5.Since it is declared locally,it takes precedence inside the subroutine.

So write statement inside the subroutine truncates the lenght to 5 character and writes 'ABCDE'.

After the perform,they are again writting the text globally.

So again '1234567890' is the output.

Hope it helps.If so,Kindly reward points by clicking the star on the left of reply,if it helps.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi sanjeev,

1. The output is perfectly allright, as it should be.

2. I think u are expecting the output to be :

1234567890

ABCDEFGHJK

ABCDEFGHJK

3. If this is so,

make your form like this (just comment two lines of declaration)

FORM datatest.

  • TYPES word(5) TYPE c.

  • DATA text TYPE word.

text = 'ABCDEFGHJK'. WRITE / text.

ENDFORM. "datatest

4. In the above case, the ORIGINAL VARIABLE

TEXT is modified.

5. Whereas in your program,

the FORM

creates ANOTHER VARIABLE, (of the same name)

and modifies this EXTRA Variable.

(not the original one)

regards,

amit m.

Message was edited by: Amit Mittal

Former Member
0 Kudos

variables used inside subroutine are local variables,the exists only in the subroutines.

if u want the value of text to be changed after PERFORM dataset.

u can write like this

PERFORM DATASET changing text.

u can change the value of text inside the subroutine now.

Former Member
0 Kudos

Hi Sanjeev,

Here are the details...

TYPES word(10) TYPE c.
<i>Globally you are declaring a variable word of length 10 charecters long. 
i.e The variable life is time is with in the report.</i>

<b>At this step the system check first checks for the type word whether 
it is declared inside 
the report. 
If it is declared it takes that type. 
In this case YES. 
So it assigns the 
text with data type : charecter and length = 10.</b>

DATA text TYPE word.

<i>Globally you are declaring a variable text of type word.i.e
The variable life is time is with in the report.</i>

text = '1234567890'. WRITE / text.

<i>Initialize the text variable with a value '1234567890'.

Write the text value in the output list.</i>

PERFORM datatest.
<i>Call the function datatest.</i>

<b>***</b>
WRITE / text.

<i>write it after the function call. This variable corresponds to the text 
variable that you have declared in the top.</i>

Fuction dataset.
FORM datatest.

<b>At this step the system check first checks for the type word whether 
it is declared inside the function. 
If it is declared it takes that type. 
In this case YES. So it assigns the text with 
data type : charecter and length = 5.</b>

TYPES word(5) TYPE c.
DATA text TYPE word.
<i>word is a string with 5 charecters. Text is of type word.

This both variables life time is only with in this function. 
Once it comes out of the function it's life time ends.</i>

text = 'ABCDEFGHJK'. WRITE / text.
<i>Initialize the text variable with a value '1234567890'.

Write the text value in the output list.</i>

ENDFORM.

<i>return to this place</i><b>***</b>.

Hope it helps.

Reward points for useful answers by clicking the star on the left hand side of the screen.

Regards,

Maheswaran.B

Message was edited by: Maheswaran B

Former Member
0 Kudos

The type declaration <b>word(5)</b> in the form dataset is local to the form. So, it is given precedence over the global declaration!

Former Member
0 Kudos

Change the type declaration inside the form as:

types word<b>2</b>(5) type c.

Don't make any other change! Now, if you run your program you will find the difference.