‎2006 Aug 17 10:12 PM
Hi, I have a small table of about 10 materials and I'd like to create 10 abap objects with the names that are stored in the table. I'm not sure how to do this..
Thanks for any help...
‎2006 Aug 17 10:48 PM
Hello Kenneth
You could use class CL_IBASE_R3_MATERIAL to generate your material objects.
Sample coding could look like:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_CREATE_MATERIAL *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT zus_sdn_create_material .
TYPES: BEGIN OF ty_s_material.
TYPES: matnr TYPE matnr.
TYPES: obj TYPE REF TO cl_ibase_r3_material.
TYPES: END OF ty_s_material.
TYPES: ty_t_material TYPE STANDARD TABLE OF ty_s_material
WITH KEY matnr.
DATA:
gs_material TYPE ty_s_material,
gto_material TYPE ty_t_material.
START-OF-SELECTION.
* Your itab containing the materials
LOOP AT itab INTO struc.
CLEAR: gs_material.
gs_material-matnr = struc-matnr.
* Create object instances for each material
CREATE OBJECT gs_material-obj
EXPORTING
i_matnr = struc-matnr.
APPEND gs_material TO gto_material.
ENDLOOP.
END-OF-SELECTION.This class has some interesting methods:
- GET_BUSINESS_KEY
- GET_ICON
- GET_MAKT
- GET_MARA
- GET_STANDARD_TEXT
and many others.
Regards
Uwe
‎2006 Aug 17 11:32 PM
If you don't have that class in your system, you can always use a local class.
report zrich_0001 .
*---------------------------------------------------------------------*
* CLASS lcl_materials DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_materials definition.
public section.
data: matnr type mara-matnr.
methods: constructor importing im_matnr type mara-matnr.
endclass.
*---------------------------------------------------------------------*
* CLASS lcl_materials IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class lcl_materials implementation.
method constructor.
matnr = im_matnr.
endmethod.
endclass.
data: a_material type ref to lcl_materials.
data: a_material_list type table of ref to lcl_materials.
start-of-selection.
create object a_material
exporting im_matnr = 'ABCD'.
append a_material to a_material_list.
create object a_material
exporting im_matnr = 'WXYZ'.
append a_material to a_material_list.
loop at a_material_list into a_material.
write:/ a_material->matnr.
endloop.
Regards,
RIch Heilman
‎2007 Feb 28 11:51 PM