-1

I'm new to SAP ABAP and want to achieve the following: I've my custom Z function module (SE37) which should have a table as import parameter. This table I want to read/loop in the code, parse the values and pass it back to an export parameter (which is also the [same] table). What I did so far:

  • In SE11 I've created a structure containing all required fields ZCOLLECTSTRUCT
  • Also in SE11 I've created a new table type ZCOLLECTTYPE which refers to this struct
  • In the function module for an import parameter I've entered TYPE ZCOLLECTTYPE.

Now I want to loop over the entries of this table (which will be passed by a RFC call to the function module). I thought I just need to declare an internal table and a workarea based on the table type. But the gap is still, how can I bring the data to the internal table?

DATA:  itabImport LIKE ZCOLLECTTYPE.
DATA:  itabExport LIKE ZCOLLECTTYPE.
DATA:  wa_itabImport TYPE ZCOLLECTTYPE.
DATA:  wa_itabExport TYPE ZCOLLECTTYPE.

loop at itabImport into wa_itabImport.
  MOVE-CORRESPONDING itabImport TO itabExport.
  APPEND wa_itabExport.
endloop.

Appreciate any insights.

Edit: I dont know how to get the data (values) from the import parameter table to the internal table.

enter image description here

enter image description here

to my itabImport?

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Schlager Bar
  • 31
  • 1
  • 6
  • Can you explain what you currently obtain, what you expect and what you don't understand? Please provide a minimal reproducible example (cf StackOverflow help). At the current point, the context of the function module is superfluous, your question is just pure ABAP transfer between internal tables. – Sandra Rossi Nov 25 '19 at 15:57
  • Yes, in the code above the part is missing which gets the data from the import parameter table (which will be filled by the user respectively the RFC call) to the internal table. – Schlager Bar Nov 25 '19 at 16:16
  • Added some more info above. – Schlager Bar Nov 25 '19 at 16:22
  • 1
    A parameter is to be handled like a variable : `LOOP AT import_batch ...` Is that the answer you're interested in? – Sandra Rossi Nov 25 '19 at 17:34

2 Answers2

1

Import parameters are just like variables. You can do

itabImport = import_batch.

Or avoid itabImport completely with

LOOP AT import_batch INTO wa_itabImport.

Note that your work areas need to be typed with the structure type, not with the table type:

DATA: wa_itabImport TYPE ZCOLLECTSTRUCT.
DATA: wa_itabExport TYPE ZCOLLECTSTRUCT.
Florian
  • 4,821
  • 2
  • 19
  • 44
  • Yes, thank you. Unfortunately, I get the following error if I use the LOOP statement: ```WA_ITABIMPORT cannot be converted to the row type of "IMPORT_BATCH". The reverse is also not possible.```. And also: ```WA_ITABIMPORT is a table without a header line and therefore does not have a component NODEREF.``` if I want to access a field of the workarea in the loop. – Schlager Bar Nov 26 '19 at 14:52
  • Included a comment in my answer. Your type definitions are wrong. Use `ZCOLLECTSTRUCT` to type the `wa_`s, not `ZCOLLECTTYPE`. – Florian Nov 26 '19 at 14:57
0

Use just like that in your function module

LOOP AT import_batch INTO DATA(wa_itab).

and don't bother about typing.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90