Application Development 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: 

clearing internal tables and work areas

Former Member
0 Kudos
476

hi this is my sample code can u tell me where and how to put my code for clearing and refresh work areas and internal table!! i have never used them before.

CLEAR gi_cstctr.

REFRESH gi_cstctr.

SELECT hkont

FROM bseg

INTO

TABLE gi_cstctr

WHERE

kostl = bseg-kostl AND prctr = bseg-prctr.

IF sy-subrc EQ 0. "if rows are returned

SORT gi_cstctr BY hkont. "sorting the internal table.

ENDIF.

*if cost centers are there in the internal table then loop the internal table into corresponding work area and if the G/L account matches any costcenter in the table

CLEAR gw_cstctr.

IF NOT gi_cstctr[] IS INITIAL.

LOOP AT gi_cstctr INTO gw_cstctr.

IF gw_cstctr-hkont EQ lv_hkont.

lv_flag = gc_x.

EXIT. "set the flag to x

ENDIF.

ENDLOOP.

ENDIF.

4 REPLIES 4

Former Member
0 Kudos
94

Hi..,

IF NOT gi_cstctr[] IS INITIAL.

LOOP AT gi_cstctr INTO gw_cstctr.

IF gw_cstctr-hkont EQ lv_hkont.

lv_flag = gc_x.

CLEAR gw_cstctr.

EXIT. "set the flag to x

ENDIF.

ENDLOOP.

ENDIF.

regards,

sai ramesh

Former Member
0 Kudos
94

1. You have to clear the workarea before the endloop.

2. Clear the internal table after the last use

CLEAR gi_cstctr.
REFRESH gi_cstctr.

SELECT hkont  FROM bseg
                       INTO TABLE gi_cstctr
                       WHERE  kostl = bseg-kostl 
                             AND prctr = bseg-prctr.

IF sy-subrc EQ 0. "if rows are returned
     SORT gi_cstctr BY hkont. "sorting the internal table.
ENDIF.

*if cost centers are there in the internal table then loop the internal table into corresponding work area and if the G/L account matches any costcenter in the table

CLEAR gw_cstctr.
IF NOT gi_cstctr[] IS INITIAL.

   LOOP AT gi_cstctr INTO gw_cstctr.

          IF gw_cstctr-hkont EQ lv_hkont.
               lv_flag = gc_x.
              EXIT. "set the flag to x
         ENDIF.
         Clear: gw_cstctr.
  ENDLOOP.
* if u are not using gi_cstctr farther
  clear: gi_cstctr. 
ENDIF.

0 Kudos
94

Sorry u have to clear clear: gi_cstctr after the endif. If you are not using the internal table farther.

Former Member
0 Kudos
94

Hi there

Please see the code below:

*CLEAR gi_cstctr.

*REFRESH gi_cstctr.

<b>CLEAR: gi_cstctr[],

gi_cstctr.</b>

SELECT hkont

FROM bseg

INTO TABLE gi_cstctr

WHERE

kostl = bseg-kostl

AND prctr = bseg-prctr.

IF sy-subrc EQ 0. "if rows are returned

SORT gi_cstctr BY hkont. "sorting the internal table.

ENDIF.

*if cost centers are there in the internal table then loop the internal table into *corresponding work area and if the G/L account matches any costcenter in the *table

CLEAR gw_cstctr.

IF NOT gi_cstctr[] IS INITIAL.

LOOP AT gi_cstctr INTO gw_cstctr.

IF gw_cstctr-hkont EQ lv_hkont.

lv_flag = gc_x.

EXIT. "set the flag to x

ENDIF.

<b>CLEAR gw_cstctr.</b>

ENDLOOP.

ENDIF.

<b>*If the data in table gi_cstctr is not needed further then you can clear this as well

CLEAR:gi_cstctr[].</b>

Please reward points if helpful.