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: 

How to append the data to hash internal table ?

carlos_zhang3
Participant
0 Kudos

Dear Guru ,

I am writing an abap program that using the hash internal table ?

but i don't know how to append data from one internal table to this hash internal table .

When i use "insert wa to itab" or "append hashitab" , the editor always told me :

"You cannot use explicit or implicit index operations on tables with

types "HASHED TABLE" or "ANY TABLE". "HASH_IBASE" has the type "HASHED

TABLE".

Can you give me a sample ? Thanks .

Best Regards,

Carlos

1 ACCEPTED SOLUTION

venkat_o
Active Contributor
0 Kudos

Hi Carlos, <li>First point INDEX access is not possible if you use hashed tables. <li>Define hashed internal table with header line like below


DATA: BEGIN OF wa_lst, "
        budat LIKE mkpf-budat,
        mblnr LIKE mseg-mblnr,
        lifnr LIKE mseg-lifnr,
        name1 LIKE lfa1-name1,
        xblnr LIKE mkpf-xblnr,
        zeile LIKE mseg-zeile,
        charg LIKE mseg-charg,
        matnr LIKE mseg-matnr,
        maktx LIKE makt-maktx,
        erfmg LIKE mseg-erfmg,
        erfme LIKE mseg-erfme,
        mjahr LIKE mseg-mjahr,
      END OF wa_lst.
DATA: ht_lst LIKE HASHED TABLE OF wa_lst WITH UNIQUE KEY mblnr mjahr zeile WITH HEADER LINE.
<li>As ht_lst table has header also, you can use below statement directly.
INSERT table ht_lst.
<li>Reference code

*&---------------------------------------------------------------------*
*&      Form  fill_ht_lst
*&---------------------------------------------------------------------*
FORM fill_ht_lst.
  REFRESH ht_lst.
  LOOP AT ht_mseg.
    CHECK ht_mseg-bwart = '101' OR ht_mseg-bwart = '901'.
    CHECK ht_mseg-matnr IN so_matnr.
    READ TABLE ht_mkpf WITH TABLE KEY mblnr = ht_mseg-mblnr
    mjahr = ht_mseg-mjahr.
    CLEAR ht_lst.
    MOVE-CORRESPONDING ht_mkpf TO ht_lst.
    MOVE-CORRESPONDING ht_mseg TO ht_lst.

    PERFORM read_lfa1 USING ht_mseg-lifnr CHANGING ht_lst-name1.
    PERFORM read_material USING ht_mseg-matnr CHANGING ht_lst-maktx.
    INSERT table ht_lst.
  ENDLOOP.
ENDFORM.                    "fill_ht_lst
Thanks Venkat.O

4 REPLIES 4

Former Member
0 Kudos

Hello Carlos,

You can append records to a hashed type internal table with the unique or the non-unique key addition to the internal table. Check the below threads for sample coding

Vikranth

Sandra_Rossi
Active Contributor

INSERT wa INTO TABLE hs_itab

INSERT LINES OF itab1 INTO TABLE hs_itab

Please read abap documentation

Former Member

type hashed , select the word, press F1.

venkat_o
Active Contributor
0 Kudos

Hi Carlos, <li>First point INDEX access is not possible if you use hashed tables. <li>Define hashed internal table with header line like below


DATA: BEGIN OF wa_lst, "
        budat LIKE mkpf-budat,
        mblnr LIKE mseg-mblnr,
        lifnr LIKE mseg-lifnr,
        name1 LIKE lfa1-name1,
        xblnr LIKE mkpf-xblnr,
        zeile LIKE mseg-zeile,
        charg LIKE mseg-charg,
        matnr LIKE mseg-matnr,
        maktx LIKE makt-maktx,
        erfmg LIKE mseg-erfmg,
        erfme LIKE mseg-erfme,
        mjahr LIKE mseg-mjahr,
      END OF wa_lst.
DATA: ht_lst LIKE HASHED TABLE OF wa_lst WITH UNIQUE KEY mblnr mjahr zeile WITH HEADER LINE.
<li>As ht_lst table has header also, you can use below statement directly.
INSERT table ht_lst.
<li>Reference code

*&---------------------------------------------------------------------*
*&      Form  fill_ht_lst
*&---------------------------------------------------------------------*
FORM fill_ht_lst.
  REFRESH ht_lst.
  LOOP AT ht_mseg.
    CHECK ht_mseg-bwart = '101' OR ht_mseg-bwart = '901'.
    CHECK ht_mseg-matnr IN so_matnr.
    READ TABLE ht_mkpf WITH TABLE KEY mblnr = ht_mseg-mblnr
    mjahr = ht_mseg-mjahr.
    CLEAR ht_lst.
    MOVE-CORRESPONDING ht_mkpf TO ht_lst.
    MOVE-CORRESPONDING ht_mseg TO ht_lst.

    PERFORM read_lfa1 USING ht_mseg-lifnr CHANGING ht_lst-name1.
    PERFORM read_material USING ht_mseg-matnr CHANGING ht_lst-maktx.
    INSERT table ht_lst.
  ENDLOOP.
ENDFORM.                    "fill_ht_lst
Thanks Venkat.O