10-25-2009 11:47 AM
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
10-26-2009 3:05 AM
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
<li>As ht_lst table has header also, you can use below statement directly.
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>Reference code
INSERT table ht_lst.
Thanks
Venkat.O
*&---------------------------------------------------------------------*
*& 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
10-25-2009 12:09 PM
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
10-25-2009 1:18 PM
INSERT wa INTO TABLE hs_itab
INSERT LINES OF itab1 INTO TABLE hs_itab
Please read abap documentation
10-25-2009 2:43 PM
10-26-2009 3:05 AM
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
<li>As ht_lst table has header also, you can use below statement directly.
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>Reference code
INSERT table ht_lst.
Thanks
Venkat.O
*&---------------------------------------------------------------------*
*& 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