‎2018 Jun 19 10:11 AM
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
‎2018 Jun 19 10:33 AM
Of course, CLEAR tcurt would be better and working with TABLES should be avoided at all.
‎2018 Jun 19 10:32 AM
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.
‎2018 Jun 19 10:33 AM
Of course, CLEAR tcurt would be better and working with TABLES should be avoided at all.
‎2018 Jun 19 10:47 AM
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
‎2018 Jun 19 10:58 AM
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).
‎2018 Jun 19 11:04 AM
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
‎2018 Jun 19 11:53 AM
‎2018 Jun 19 1:45 PM
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?
‎2018 Jun 19 3:15 PM
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