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

Initial Structure

Former Member
0 Likes
1,640

Hi all,

Can anyone please tell me what this particular line of code does in this program?

Tables TCURT.

DATA: CURR_TAB TYPE TABLE OF TCURT.
................
................
SELECT * FROM TCURT INTO TABLE CURR_TAB 
 WHERE ....

LOOP AT CURR_tAB INTO TCURT.
WRITE: /5 SY-TABIX, TCURT-WAERS,TCURT-LTEXT.
ENDLOOP.

TCURT = SPACE. "initial structure TCURT.
TCURT-WAERS = 'IJK'.
TCURT-LTEXT = 'DUMMY CURRENCY'.

INSERT TCURT INTO CURR_TAB INDEX REC_NO.

Now in the above program my doubt is with this line -

TCURT = SPACE. "initial structure TCURT.

What does this line do? And in the comment beside it is written "initial structure TCURT" !

Can anyone please tell me what it's use / purpose?

With Warm Regards,

Namrata

1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
1,515

https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenconversion_fla...

Of course, CLEAR tcurt would be better and working with TABLES should be avoided at all.

8 REPLIES 8
Read only

matt
Active Contributor
0 Likes
1,515

Why not run the program in debug and find out what the statement does?

Also, be aware that TABLES is an obsolete keyword and should not be used in new programs.

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
0 Likes
1,516

https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenconversion_fla...

Of course, CLEAR tcurt would be better and working with TABLES should be avoided at all.

Read only

0 Likes
1,515

Sir,

Thank you very much for the reply.

But it will be kind of you if you please tell me what is SPACE doing here ? I mean can you plz explain in a little details why TCURT is given the value 'space" instead of just avoiding it and directly inserting the values like

LOOP AT CURR_tAB INTO TCURT.
WRITE: /5 SY-TABIX, TCURT-WAERS,TCURT-LTEXT.
ENDLOOP.
"and completely avoiding the line TCURT = SPACE.
TCURT-WAERS ='IJK'.
TCURT-LTEXT ='DUMMY CURRENCY'.


Regards,

Namrata

Read only

1,515

I can't explain to you the bad programming style of someone else.

One has to ask the author of the program why he/she does not simply use CLEAR.

What's happening in that line, you can learn from the documentation (the structure is filled up with blanks).

Read only

1,515

Dear Namrata,

It is always considered as a good coding practice to initialize the structure (or variable) before using it and that is the purpose of this line of code. However as suggested by Horst, it would have been better if CLEAR statement was used instead of passing SPACE.

Please let me know if you need any further clarificaiton on this.

Best Regards,

Arpan Shukla

Read only

0 Likes
1,515

Hi Arpan,

Thanks for the reply.

Read only

Former Member
0 Likes
1,515

Hi Mathew and Horst,

Ok I got it. So do you think using "Data " keyword will be better to define a structured object like this below-

DATA: TCURT type TCURT

Will be better?

Read only

matt
Active Contributor
0 Likes
1,515

Yes. It's better. But it's still bad. Why not give it a meaningful name, like line_of_tcurt or tcurt_record or currency_code_name_record