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

Looping a table declared as type any.

Former Member
0 Likes
5,428

Hi experts,

I have a form acting as a user exit, so i cannot change the declarations.

In my case in one of the parameters i have a table, such as this:

Form EXAMPLEFORM using tableparameter TYPE any.

I want to loop this table into a declared structure, but i cannot do this c'ause the program doesn't compile or gets a dump error.

I know wich is the table structure, is CE0ECHE.

I have read some examples here but are not the same case....

Can someone help me with this please?

Thanks!!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,758

hi Artur,

try using 'CHANGING  type any table',  like 'this:

data: BEGIN OF st_mara,
   matnr type mara-matnr,
  END OF st_mara,
  it_mara like STANDARD TABLE OF st_mara.

START-OF-SELECTION.
  st_mara-matnr = 'aaaa'.
  append st_mara to it_mara.

  st_mara-matnr = 'bbb'.
  append st_mara to it_mara.

  PERFORM show_itab CHANGING it_mara[].

FORM show_itab CHANGING p_itab type any table .
  loop at p_itab into st_mara.
    write:/, st_mara-matnr.
  ENDLOOP.
ENDFORM.

17 REPLIES 17
Read only

Former Member
0 Likes
3,758

Hi,

Declare local work area: ls_CE0ECHE type CE0ECHE.

LOOP AT <tableparameter>  into ls_CE0ECHE.

Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
3,758

You can do as follow

 

data

:lt_t001 type standard table of t001.
select * up to 100 rows from t001 into table lt_t001.

PERFORM get_directory_browse tables lt_t001.

*----------------------------------------------------------------------*
FORM get_directory_browse
tables pt_t001 .

data:lwa_t001 type t001,
lt_t001
type standard table of t001.
loop at pt_t001.
lwa_t001 = pt_t001.
append lwa_t001 to lt_t001..
endloop.
ENDFORM.

"get_directory_browse

Read only

0 Likes
3,758

hi nabheet, i cannot use tabless call c'ause i cannot change the call (is in a standard program) instead the form comes with the table in a using clause.

Read only

0 Likes
3,758

Hi Artur,

As i understood the situation, you need to write for subroutine which is used for multiple table types.

If i misunderstood it then please provide code to understand it better.

Regards,

Vishal Solanki

Read only

0 Likes
3,758

Hi Solanki,

I can only program the form, not the call, so i can only program the code inside the routine, as it is a user exit call called from a standard program.

The code is like i posted before:

Form EXAMPLEFORM using X_PAR TYPE any.

X_PAR is a table with structure CE0ECHE, but i have to work with it as it is called, a parameter type any from the using clause.

Read only

Former Member
0 Likes
3,758

Hello Artur,

instead of declaring it like a work area.

go with field symbols as below.

FIELD-SYMBOLS: <LFS_WA> TYPE CE0ECHE.

there after you can use that like this.

LOOP AT ITAB assigning <LFS_WA>.

     <your logic>

ENDLOOP.

let us know if you still facing issues with this.

Thanks,

bhaskar

Read only

0 Likes
3,758

The issue it that the program doesn't allow me doing the loop because the program does not recognise the parameter as a table c'ause it has been called with the using clause.

When you debig you can see that debugger let you see the table content with its fields.

Read only

0 Likes
3,758

Hi Arthur

There are several options as they stated:

is your table with header , better dont use header

like Data: lt_coeche type table of coeche with header lines. Dont use this

İts absolete use normal table like Data: lt_coeche type table of coeche

1- Work Area like ls_coeche

2- Field symbol <lfs_coeche>

3- Ref data lv_coeche

1-

Data ls_coeche type coeche.

loop at lt_coeche into ls_coeche.

*clear also

endloop.

2-

Field symbol which is much better like above ashkar posted that

Field symbols are more powerful and recommended by SAP

Read only

0 Likes
3,758

Hi solen, i'm trying to solve this with field symbols, but as the table comes declared as using, the program does not allow me to do the loop.

My problem is more about the loop.

Read only

0 Likes
3,758

Artur,

declare a field symbol as type any table.

assing your formal parameter to it.

now you can loop on the field symbol which is declared as table.

Regards,

Bhaskar

Read only

Former Member
0 Likes
3,759

hi Artur,

try using 'CHANGING  type any table',  like 'this:

data: BEGIN OF st_mara,
   matnr type mara-matnr,
  END OF st_mara,
  it_mara like STANDARD TABLE OF st_mara.

START-OF-SELECTION.
  st_mara-matnr = 'aaaa'.
  append st_mara to it_mara.

  st_mara-matnr = 'bbb'.
  append st_mara to it_mara.

  PERFORM show_itab CHANGING it_mara[].

FORM show_itab CHANGING p_itab type any table .
  loop at p_itab into st_mara.
    write:/, st_mara-matnr.
  ENDLOOP.
ENDFORM.

Read only

0 Likes
3,758

Hi Dengyong, icannot use change as i cannot change the call, only the routine.

Read only

0 Likes
3,758

Do like this

   

data:lt_t001 type standard table of t001.
select * up to 100 rows from t001 into table lt_t001.

PERFORM get_directory_browse using lt_t001.

*----------------------------------------------------------------------*
FORM get_directory_browse
using pt_t001 type any .
data:lwa_t001 like line of t001,
lt_t001
type standard table of t001.
lt_t001[] = pt_t001.
loop at lt_t001 into lwa_t001.
endloop.
ENDFORM.

Read only

0 Likes
3,758

Hey Artur,

I have tried best to recreate your issue and have come up with a solution. It works for me and uses field symbols.

it is simple but hard the first time around.

Read only

0 Likes
3,758

It worked, thanks!!!!

Read only

hiriyappa_myageri
Participant
0 Likes
3,758

Hi Arthur,

You can declare Like this.

DATA BEGIN OF IT_CE0ECHE OCCURS 0.

   INCLUDE STRUCTURE CE0ECHE.

   DATA END OF IT_CE0ECHE.

Regards,

Hiriyappa

Read only

Former Member
0 Likes
3,758

Hi Arthur,

Please go through the below code and let me know if it works.

REPORT  Z08_SCN.

DATA: lt_table TYPE REF TO data,
       lx_line TYPE REF TO data,
       lt_fldcat TYPE lvc_t_fcat.

FIELD-SYMBOLS: <lt_table> TYPE STANDARD TABLE,
                <lx_line>,
                <lv_val>.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
*   I_BUFFER_ACTIVE              =
    I_STRUCTURE_NAME             = 'CE0ECHE'
*   I_CLIENT_NEVER_DISPLAY       = 'X'
*   I_BYPASSING_BUFFER           =
*   I_INTERNAL_TABNAME           =
   CHANGING
     ct_fieldcat                  = lt_fldcat
* EXCEPTIONS
*   INCONSISTENT_INTERFACE       = 1
*   PROGRAM_ERROR                = 2
*   OTHERS                       = 3
           .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

  CALL METHOD cl_alv_table_create=>create_dynamic_table

     EXPORTING

       it_fieldcatalog = lt_fldcat

     IMPORTING

       ep_table        = lt_table.

ASSIGN lt_table->* TO <lt_table>.

CREATE DATA lx_line LIKE LINE OF <lt_table>.
ASSIGN lx_line->* TO <lx_line>.


SELECT * FROM
   CE0ECHE INTO TABLE <lt_table>
   UP TO 10 ROWS.


   LOOP AT <lt_table> ASSIGNING <lx_line>.
    ASSIGN COMPONENT 1 OF STRUCTURE <lx_line> TO <lv_val>.
    WRITE: <lv_val>.
   ENDLOOP.

Thanks and Regards,

Ashish Kumar