‎2005 Jan 07 8:05 PM
In SAP BW, I have an internal table "COMM_STRUCTURE" composed of 52 columns, one for each week of the year.
Rather than appending 52 times to RESULT_TABLE, is there a way to do it in a loop, and traverse each column of a row programatically?
The codes looks like this. I want to eliminate the repeated lines. Thanks for any help.
FORM compute_data_field
TABLES MONITOR STRUCTURE RSMONITOR "user defined monitoring
RESULT_TABLE STRUCTURE /BIC/VIC_BUD_JCT
USING COMM_STRUCTURE LIKE /BIC/CSIS_MONBUD
RECORD_NO LIKE SY-TABIX
RECORD_ALL LIKE SY-TABIX
SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS
ICUBE_VALUES LIKE /BIC/VIC_BUD_JCT
CHANGING RETURNCODE LIKE SY-SUBRC
ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update
RESULT_TABLE = ICUBE_VALUES.
RESULT_TABLE-/BIC/IO_BUDINC = COMM_STRUCTURE-/BIC/IO_BAMT01.
RESULT_TABLE-CALMONTH = 200401.
APPEND RESULT_TABLE.
RESULT_TABLE-/BIC/IO_BUDINC = COMM_STRUCTURE-/BIC/IO_BAMT02.
RESULT_TABLE-CALMONTH = 200402.
APPEND RESULT_TABLE.
‎2005 Jan 07 8:26 PM
‎2005 Jan 07 9:47 PM
‎2005 Jan 10 2:34 PM
Thanks for the responses. I don't have much experience with ABAP, so I appreciate your patience. I still can't get it to work. The following, which is trying to turn the 52 week columns (ignoring the first column) into 52 rows, doesn't write anything.
Can someone see what my error is?
PROGRAM UPDATE_ROUTINE.
FIELD-SYMBOLS <FS> TYPE ANY.
FORM compute_data_field
TABLES MONITOR STRUCTURE RSMONITOR "user defined monitoring
RESULT_TABLE STRUCTURE /BIC/VIC_BUD_JCT
USING COMM_STRUCTURE LIKE /BIC/CSIS_MONBUD
RECORD_NO LIKE SY-TABIX
RECORD_ALL LIKE SY-TABIX
SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS
ICUBE_VALUES LIKE /BIC/VIC_BUD_JCT
CHANGING RETURNCODE LIKE SY-SUBRC
ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update
RESULT_TABLE = ICUBE_VALUES.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE COMM_STRUCTURE TO <FS>.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IF SY-INDEX > 1.
RESULT_TABLE-/BIC/IO_BUDAMT = <FS>.
RESULT_TABLE-CALMONTH = SY-INDEX.
APPEND RESULT_TABLE.
ENDIF.
ENDDO.
RETURNCODE = 0.
ABORT = 0.
ENDFORM.
‎2005 Jan 11 8:45 AM
Hi,
At first sight your code looks okay but I am doubting at the usage of sy-index as a counter ...
I would suggest making following changes:
- define a local counter
data: w_fieldindex type i value 1.
- use the counter in stead of sy-index and of course you need to increase the counter by hand
- you can get ridd of the test 'if sy-index > 1' ... Just give the counter already the default value for the second index lookup so you can ommit that if statement (should give some performance)
- Not sure but doesn't the index starts at 0 - so first field is index 0 (check that ... so then the default index to start can be set to 1)
Hope this helps,
Steven
‎2005 Jan 12 10:05 AM
Hello Jerry,
Sorry for the delayed response to this question.
You are using the <i>ASSIGN COMPONENT OF</i> option in your code here. Have you checked whether the fields -/BIC/IO_BAMT01 , -/BIC/IO_BAMT02....are consecutive and contiguous in the structure COMM_STRUCTURE (which is of type /BIC/CSIS_MONBUD) ? If not then you will have problems. Also, the statement
RESULT_TABLE-CALMONTH = SY-INDEX.seems to be incorrect. You want tthe CALMONTHs to be in the format 2004xx, right? If yes, then the above statement will not do. I have altered your code a little hwere necessary. Please see if it works. If you still find some problems, please give the structure of /BIC/CSIS_MONBUD.
Also please confirm whether your original program is working as intended.
====================================================================
PROGRAM UPDATE_ROUTINE.
FIELD-SYMBOLS <FS> TYPE ANY.
FORM compute_data_field TABLES MONITOR STRUCTURE RSMONITOR
RESULT_TABLE STRUCTURE /BIC/VIC_BUD_JCT
USING COMM_STRUCTURE LIKE /BIC/CSIS_MONBUD
RECORD_NO LIKE SY-TABIX
RECORD_ALL LIKE SY-TABIX
SOURCE_SYSTEM LIKE RSUPDSIMULH-LOGSYS
ICUBE_VALUES LIKE /BIC/VIC_BUD_JCT
CHANGING RETURNCODE LIKE SY-SUBRC
ABORT LIKE SY-SUBRC. "set ABORT <> 0 to cancel update"
DATA TEMP_CALMONTH(6) TYPE N.
TEMP_CALMONTH = '200401'.
RESULT_TABLE = ICUBE_VALUES.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE COMM_STRUCTURE TO <FS>.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IF SY-INDEX > 1.
RESULT_TABLE-/BIC/IO_BUDAMT = <FS>.
MOVE SY-INDEX TO TEMP_CALMONTH+4(2).
RESULT_TABLE-CALMONTH = TEMP_CALMONTH.
APPEND RESULT_TABLE.
ENDIF.
ENDDO.
RETURNCODE = 0.
ABORT = 0.
ENDFORM.
====================================================================
The DO..ENDDO loop above can also be coded in a different way -
DATA : TEMP_INDEX(2) TYPE N,
TEMP_MONBUD(29) TYPE C VALUE 'COMM_STRUCTURE-/BIC/IO_BAMT'.
DO.
MOVE SY-INDEX TO TEMP_INDEX.
CONCATENATE TEMP_MONBUD
TEMP_INDEX
INTO TEMP_MONBUD.
ASSIGN COMPONENT TEMP_MONBUD OF STRUCTURE COMM_SRTUCTURE TO <FS>.
* Rest of the code is same as above. Here, you do not have to know the actual structure of COMM_STRUCTURE,
so long as you know that there will be fields with the name /BIC/IO_BAMTxx.
ENDDO.
Hope to see your problem resolved ASAP. All the best,
Regards,
Anand Mandalika.
‎2005 Jan 12 3:53 PM
Thanks, Anand. I had multiple problems with my code, and your suggestions were on target for a lot of my problems. Thanks again.