G-YWWN0NYSS1 NEW Operator – Structures and Internal Tables - TECHNICAL GYAN GURU NEW Operator – Structures and Internal Tables - TECHNICAL GYAN GURU

NEW Operator – Structures and Internal Tables

Can we declare NEW # as shown above for d_ref_struct? (NEW Operator – Structures and Internal Tables)
Since, d_ref_struct is anonymous data object, it would not recognize matnr and werks. The error is: No type can be derived from the context for the operator “NEW”.

ABAP for SAP HANA. ALV Report On SAP HANA – Opportunities And Challenges

The right way is to define d_ref_struct as structured object as shown below. NEW Operator – Structures and Internal Tables

1. For Structures
i) Anonymous data object

* Example 1
TYPES: BEGIN OF ty_marc,
  matnr TYPE matnr,
  werks TYPE werks_d,
END OF ty_marc.
 
DATA: d_ref_struct TYPE REF TO data.      " Anonymous data object
 
d_ref_struct = new ty_marc( matnr = '165251' werks = '4030' ).
* Example 2
d_ref_struct = NEW #( matnr = '165251' werks = '4030' ).

Might we at any point proclaim NEW # as displayed above for d_ref_struct?
Since, d_ref_struct is mysterious information object, it wouldn’t perceive matnr and werks. The blunder is: No sort can be gotten from the setting for the administrator “NEW”.

The correct way is to characterize d_ref_struct as organized object as displayed underneath.

ii) Structured data object

* Example 2
TYPES: 
BEGIN OF ty_marc,
  matnr TYPE matnr,
  werks TYPE werks_d,
END OF ty_marc.

DATA: d_ref_struct TYPE REF TO ty_marc. " Structured data object

d_ref_struct = NEW #( matnr = '165251' werks = '4030' ).

When “#” succeeds NEW, it means the object ref in the Left Hand Side determines the type.

2. For Internal Tables
i) Anonymous data object

* Example 1
TYPES: 
BEGIN OF ty_marc,
  matnr TYPE matnr,
  werks TYPE werks_d,
END OF ty_marc.

DATA: d_ref_tab TYPE REF TO data. " Anonymous data object

d_ref_tab = NEW ty_marc( ( matnr = '165251' werks = '4030')
                         ( matnr = '165251' werks = '5172') ).

Going by the case of designs displayed above before inside table, this model 1 of inward table looks right. In any case, SAP could do without it..

What turned out badly?
NEW ty_marc( ) is pertinent for structure. In this way, can’t switch over completely to interior table.

Lets attempt once more by proclaiming a table kind.

* Example 1 -- first retry
TYPES: 
BEGIN OF ty_marc,
  matnr TYPE matnr,
  werks TYPE werks_d,
END OF ty_marc.

TYPES: tt_marc TYPE TABLE OF ty_marc.

DATA: d_ref_tab TYPE REF TO data. " Anonymous data object

d_ref_tab = NEW tt_marc( ( matnr = '165251' werks = '4030')
                         ( matnr = '165251' werks = '5172') ).

Here we rolled out two improvements.
I) Table Sort tt_marc is characterized.
ii) NEW tt_marc is utilized rather than NEW ty_marc

Yet, still the framework gives mistake “A worth of the nonexclusive kind “TT_MARC” can’t be built”.

How about we offer another chance.
Here we will add only 3 watchwords “WITH DEFAULT KEY” in Table Kind announcement.

* Example 1 -- second retry
TYPES: 
BEGIN OF ty_marc,
  matnr TYPE matnr,
  werks TYPE werks_d,
END OF ty_marc.

TYPES: tt_marc TYPE TABLE OF ty_marc WITH DEFAULT KEY.

DATA: d_ref_tab TYPE REF TO data. " Anonymous data object

d_ref_tab = NEW tt_marc( ( matnr = '165251' werks = '4030')
                         ( matnr = '165251' werks = '5172') ).

Bingooo!!!! WITH DEFAULT KEY got the job done. Unknown information object is currently an inner table.

The following is one more guide to characterize and populate inward table with mysterious item.

* Example 2
TYPES:
begin of ty_marc,
  matnr type matnr,
  werks type werks_d,
end of ty_marc.

DATA: d_ref_tab TYPE TABLE OF REF TO DATA, " Anonymous data object
      wa_marc   TYPE ty_marc.

 SELECT matnr werks UP TO 10 ROWS FROM marc INTO wa_marc.
  APPEND NEW ty_marc( wa_marc ) to d_ref_tab. " Object is created here

The substance of the line is alloted to the information object. The item is made at the assertion Add and the NEW information reference is affixed straightforwardly to an inward table with the suitable line type. The outcome is a table that references generally new unknown information objects of 10 lines.

ii) Structured data object

* Example 3
 TYPES:
 BEGIN OF ty_marc,
   matnr TYPE matnr,
   werks TYPE werks_d,
 END OF ty_marc.

 DATA: d_ref_tab TYPE STANDARD TABLE OF REF TO ty_marc, "Structured object
       wa_marc   TYPE ty_marc.

 SELECT matnr werks UP TO 10 ROWS FROM marc INTO wa_marc.
   APPEND NEW #( wa_marc ) TO d_ref_tab.
 ENDSELECT.

Trust with the above models and pieces, you would be in the situation to mess with NEW Administrator. In our next post we would investigate the Worth Administrator.

YOU MAY LIKE THIS

SAP MM Salary Guide: What You Need to Know

abap ale idoc rfc step by step

What is the demand for the SAP PP module?

  • Related Posts

    You’hv got an IDoc !!

    Assuming you google IDoc, you would be overwhelmed with large number of pages. Here, I have attempted to gather just those part which are essentially utilized continuously projects. You’hv got…

    *.IDO file for IDocs

    In the event that your heritage group or outsider group or EDI group or non-SAP group asks you for a *.IDO file for IDocs type, don’t scratch your head. Ido…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    You’hv got an IDoc !!

    • By Varad
    • June 2, 2025
    • 12 views
    You’hv got an IDoc !!

    *.IDO file for IDocs

    • By Varad
    • June 1, 2025
    • 27 views
    *.IDO file for IDocs

    A to Z of Custom Change Pointer

    • By Varad
    • May 31, 2025
    • 20 views
    A to Z of Custom Change Pointer

    IDoc Tips – Change Pointers and Reprocessing IDocs

    • By Varad
    • May 30, 2025
    • 32 views
    IDoc Tips – Change Pointers and Reprocessing IDocs

    Tool for GOS attachment from one SAP system to another SAP system

    • By Varad
    • May 29, 2025
    • 32 views
    Tool for GOS attachment from one SAP system to another SAP system

    Sample program to attach any file from application server to any Business Object

    • By Varad
    • May 28, 2025
    • 38 views
    Sample program to attach any file from application server to any Business Object