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: 

Append field into internal table

ratana_pouy
Participant
0 Kudos
419

Hi,

i am trying to build a new internal table by adding new field into it because standard table doesn't exist.

SELECT * FROM aufm INTO TABLE @DATA(it_aufm) WHERE aufnr = @wa_mseg-aufnr AND werks = @wa_mseg-werks.

TYPES: BEGIN OF zitab_aufm,
include TYPE aufm,
zperiod TYPE mseg-gjahr.
TYPES END OF zitab_aufm.

DATA: final_it_aufm TYPE STANDARD TABLE OF zitab_aufm, " Goods movements for order
temp_it_aufm TYPE zitab_aufm, " Goods movements for order
wa_it_aufm TYPE zitab_aufm.

"Built internal table
LOOP AT it_aufm into wa_it_aufm.
CASE wa_it_aufm-shkzg.
WHEN 'H'.
wa_it_aufm-dmbtr = wa_it_aufm-dmbtr * -1.
wa_it_aufm-menge = wa_it_aufm-menge * -1.
wa_it_aufm-erfmg = wa_it_aufm-erfmg * -1.
ENDCASE.
MOVE-CORRESPONDING wa_it_aufm TO temp_it_aufm.
APPEND temp_it_aufm TO final_it_aufm.

ENDLOOP.

but work area wa_it_aufm doesn't recognize these fields.

Please help.

Regards,

RTN

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; }.L0S31 { font-style: italic; color: #808080; }.L0S32 { color: #3399FF; }.L0S33 { color: #4DA619; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }.L0S70 { color: #808080; }

1 ACCEPTED SOLUTION

thkolz
Contributor
349
TYPES:
  BEGIN OF zitab_aufm,  
    aufm  TYPE aufm,
    zperiod TYPE mseg-gjahr,  
  END OF zitab_aufm.

DATA: s_itab_aufm TYPE zitab_aufm.
WRITE s_itab_aufm-aufm-shkzg.
4 REPLIES 4

Bohdan
Active Contributor
0 Kudos
349

Hi ratana.pouy,

There is an issue with the way you defined the complex type. Try to define it this way:

types: begin of zitab_aufm.
   include type aufm.
   types: zperiod type mseg-gjahr.
types end of zitab_aufm.<br>

To access the variant SHKZG in your current code, you need to reference it as wa_it_aufm-include-shkzg (because of the way you defined the complex type).

Regards,

Bohdan

thkolz
Contributor
350
TYPES:
  BEGIN OF zitab_aufm,  
    aufm  TYPE aufm,
    zperiod TYPE mseg-gjahr,  
  END OF zitab_aufm.

DATA: s_itab_aufm TYPE zitab_aufm.
WRITE s_itab_aufm-aufm-shkzg.

Sandra_Rossi
Active Contributor
349

See the color of "include" which is black instead of blue.

black means a component named "include". Blue would mean that it's the ABAP statement INCLUDE TYPE.

Obviously, the comma above must be replaced with a dot.

Avoid using INCLUDE TYPE wherever possible (see Thorsten solution).

matt
Active Contributor
349

Do use the CODE button in the editor, it makes things so much easier for everyone else.

SELECT * FROM aufm INTO TABLE @DATA(it_aufm) WHERE aufnr = @wa_mseg-aufnr AND werks = @wa_mseg-werks.

TYPES: BEGIN OF zitab_aufm,
  include TYPE aufm,
  zperiod TYPE mseg-gjahr.
TYPES END OF zitab_aufm.

DATA: final_it_aufm TYPE STANDARD TABLE OF zitab_aufm, " Goods movements for order
      temp_it_aufm TYPE zitab_aufm, " Goods movements for order
      wa_it_aufm TYPE zitab_aufm.

"Built internal table
LOOP AT it_aufm into wa_it_aufm.
  CASE wa_it_aufm-shkzg.
    WHEN 'H'.
      wa_it_aufm-dmbtr = wa_it_aufm-dmbtr * -1.
      wa_it_aufm-menge = wa_it_aufm-menge * -1.
      wa_it_aufm-erfmg = wa_it_aufm-erfmg * -1.
  ENDCASE.
  MOVE-CORRESPONDING wa_it_aufm TO temp_it_aufm.
  APPEND temp_it_aufm TO final_it_aufm.
ENDLOOP.

See?

You've defined a field in your type with the name "INCLUDE" which has as its components the fields of AUFM.

You've clearly done a pretty print, and include is lower case. That should be a clue that you've done something wrong.