Application Development and Automation 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: 
Read only

Append to only one field within a loop

Former Member
0 Likes
2,169

Hi guys,

This might be a very trivial question but i am unable to move ahead. I have an internal table(int_int_table) and actually i am looping this internal table within an external internal table(ext_int_table)loop with some keys to find a match. Now withing this internal loop i have an amount field that i have to update with the WRBTR in everyloop. So i do the following

int_int_table-Amount = int_int_table-Amount + ext_int_table-WRBTR, and then i do APPEND int_int_table. But it does not append this value as in the next loop i still see 0. Can anyone tell me what i am doing wrong here??..

Thanks,

David.

Hi guys,

This might be a very trivial question but i am unable to move ahead. I have an internal table(int_int_table) and actually i am looping this internal table within an external internal table(ext_int_table)loop with some keys to find a match. Now withing this internal loop i have an amount field that i have to update with the WRBTR in everyloop. So i do the following

int_int_table-Amount = int_int_table-Amount + ext_int_table-WRBTR, and then i do APPEND int_int_table. But it does not append this value as in the next loop i still see 0. Can anyone tell me what i am doing wrong here??..

Thanks,

David.

10 REPLIES 10
Read only

Former Member
0 Likes
2,008

Are you trying to update a field on a given record? If so, use the MODIFY statement.

Read only

Former Member
0 Likes
2,008

Hi David,

Use

modify int_int_table index sy-tabix

Regards,

Vivek

Read only

0 Likes
2,008

Hi Vivek,

I used your modify and it was working but it is appending a new record in the table, i do not want to append a new record within the same record i just want to modify this amount field in every loop. So plz all reply me ASAP as i am not able to move ahead.

Thanks,

David.

Read only

0 Likes
2,008

Can you post the code for the two loops(external and internal) so we can see what is going on.

Regards,

Rich Heilman

Read only

0 Likes
2,008

You have an extra append statement that needs to be removed.

Read only

0 Likes
2,008

Check this sample, notice that ITAB2 still only has 4 records and they all have been modified.



report zrich_0001.

data: begin of itab1 occurs 0,
      keyfld(5) type c,
      value type p decimals 2,
      end of itab1.

data: begin of itab2 occurs 0,
      keyfld(5) type c,
      value type p decimals 2,
      end of itab2.


itab1-keyfld = 'ABC'.
itab1-value  = '100.00'.
append itab1.

itab1-keyfld = 'DEF'.
itab1-value  = '200.00'.
append itab1.


itab2-keyfld = 'ABC'.
itab2-value  = '1.00'.
append itab2.

itab2-keyfld = 'ABC'.
itab2-value  = '2.00'.
append itab2.

itab2-keyfld = 'DEF'.
itab2-value  = '3.00'.
append itab2.

itab2-keyfld = 'DEF'.
itab2-value  = '4.00'.
append itab2.



loop at itab1.

  loop at itab2 where keyfld = itab1-keyfld.
    itab2-value = itab2-value + itab1-value.
    modify itab2.
  endloop.

endloop.



check sy-subrc  = 0.

Regards,

Rich Heilman

Read only

0 Likes
2,008

Hi Rich,

Here are the two loops

LOOP AT I_BSEG.

IF I_BSEG-BELNR = '5100000030' AND I_BSEG-BUKRS = 'AL00' .

MOVE-CORRESPONDING I_BSEG TO ITEM_TAB.

  • CLEAR WORK_TAB.

LOOP AT WORK_TAB WHERE BUKRS = I_BSEG-BUKRS

AND BELNR = I_BSEG-BELNR.

  • EXIT.

  • ENDLOOP.

  • READ TABLE WORK_TAB WITH KEY BUKRS = I_BSEG-BUKRS "added read instead of loop here

  • BELNR = I_BSEG-BELNR.

  • If sy-subrc eq 0.

**A check is made to determine whether the invoice has transportation costs

*and depending on the indicator processing is done.

If work_tab-rseg_ind = 'X'. " added the check to rseg_ind

Perform fetch_bseg_costs. "will get the corresponding match here

If item_tab2[] is initial.

Perform process_item_tab.

else.

loop at item_tab2.

perform process_rseg_item_tab.

endloop.

endif.

else.

perform process_item_tab.

Endif.

  • MODIFY WORK_TAB index sy-tabix.

APPEND WORK_TAB.

Clear: item_tab2,

TOT_TAX_AMT.

Refresh: item_tab2.

EXIT.

Endloop.

ENDIF.

ENDLOOP.

and within the perform routine i have to do the addition

IF ITEM_TAB-SHKZG = 'H'. "ECDK902223

ITEM_TAB-WRBTR = ITEM_TAB-WRBTR * -1.

ENDIF.

IF I_BSEG-BSCHL = '83'.

ITEM_TAB-MATNR = WORK_TAB-MATNR.

ITEM_TAB-WERKS = WORK_TAB-WERKS.

ENDIF.

IF ITEM_TAB-MATNR IS INITIAL.

EXIT.

ENDIF.

PERFORM FILL_MAKT.

PERFORM FILL_MIC.

WS-MATNR = ITEM_TAB-MATNR. "ECDK902000

WS-WERKS = ITEM_TAB-WERKS. "ECDK902000

PERFORM CHECK_T001K. "added code here

IF WS-BWMOD = '0004'.

ITEM_TAB-REFURB_IND = 'X'.

ENDIF.

IF ITEM_TAB-MWSKZ = 'ZB' AND ITEM_TAB-REFURB_IND = 'X'.

ITEM_TAB-TAX_IND = 'B'.

<b> WORK_TAB-TOT_TAX_AMT = WORK_TAB-TOT_TAX_AMT + ITEM_TAB-WRBTR.</b>

ELSEIF ITEM_TAB-MWSKZ = 'ZC' AND ITEM_TAB-REFURB_IND = 'X'.

ITEM_TAB-TAX_IND = 'C'.

ENDIF. "end of code

PERFORM FILL_MBEW.

ITEM_TAB-BKLAS = WS-BKLAS.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITEM_TAB-ADRN2 = WORK_TAB-ADRN2.

WS-BUKRS = ITEM_TAB-BUKRS.

WS-BUDAT = WORK_TAB-BUDAT.

PERFORM FILL_ACCOUNTING_TAB.

IF SY-SUBRC = 0.

ITEM_TAB-RCC = ZACCREF-INVRC.

ITEM_TAB-GEOLOC = ZACCREF-INVLOC.

ITEM_TAB-EXTC = ZACCREF-INVRCXC.

WRITE ITEM_TAB-HKONT TO WS-HKONT NO-ZERO.

CONCATENATE WS-HKONT(4) '.' WS-HKONT+4(6) INTO

ITEM_TAB-ACCOUNT.

ELSE.

CTR-ERROR_TOTAL = CTR-ERROR_TOTAL + 1.

WRITE: / 'Cannot find ZACCREF entry with: ',

WORK_TAB-AWKEY(10), ITEM_TAB-BUKRS, ITEM_TAB-BKLAS.

  • EXIT. "commented for testing purpose.

ENDIF.

APPEND ITEM_TAB.

  • APPEND WORK_TAB.

Clear item_tab.

ENDFORM. " process_item_tab

The field is work_tab-tot_tax_amt that i have to update for every line item.

Thanks,

David.

Read only

0 Likes
2,008

Where is the modify statement for WORK_TAB?

REgards,

Rich HEilman

Read only

0 Likes
2,008

Hi David,

It was hard to check the code for me but i think this is what you have to do.

<b>data: zzindex like sy-tabix.</b>

LOOP AT I_BSEG.

IF I_BSEG-BELNR = '5100000030' AND I_BSEG-BUKRS = 'AL00' .

MOVE-CORRESPONDING I_BSEG TO ITEM_TAB.

  • CLEAR WORK_TAB.

LOOP AT WORK_TAB WHERE BUKRS = I_BSEG-BUKRS

AND BELNR = I_BSEG-BELNR.

<b>zzindex = sy-tabix.</b>

  • EXIT.

  • ENDLOOP.

  • READ TABLE WORK_TAB WITH KEY BUKRS = I_BSEG-BUKRS "added read instead of loop here

  • BELNR = I_BSEG-BELNR.

  • If sy-subrc eq 0.

**A check is made to determine whether the invoice has transportation costs

*and depending on the indicator processing is done.

If work_tab-rseg_ind = 'X'. " added the check to rseg_ind

Perform fetch_bseg_costs. "will get the corresponding match here

If item_tab2[] is initial.

Perform process_item_tab.

else.

loop at item_tab2.

perform process_rseg_item_tab.

endloop.

endif.

else.

perform process_item_tab.

Endif.

<b> MODIFY WORK_TAB index zzindex.</b>

<b>*APPEND WORK_TAB.</b>Clear: item_tab2,

TOT_TAX_AMT.

Refresh: item_tab2.

EXIT.

Endloop.

ENDIF.

ENDLOOP.

and within the perform routine i have to do the addition

IF ITEM_TAB-SHKZG = 'H'. "ECDK902223

ITEM_TAB-WRBTR = ITEM_TAB-WRBTR * -1.

ENDIF.

IF I_BSEG-BSCHL = '83'.

ITEM_TAB-MATNR = WORK_TAB-MATNR.

ITEM_TAB-WERKS = WORK_TAB-WERKS.

ENDIF.

IF ITEM_TAB-MATNR IS INITIAL.

EXIT.

ENDIF.

PERFORM FILL_MAKT.

PERFORM FILL_MIC.

WS-MATNR = ITEM_TAB-MATNR. "ECDK902000

WS-WERKS = ITEM_TAB-WERKS. "ECDK902000

PERFORM CHECK_T001K. "added code here

IF WS-BWMOD = '0004'.

ITEM_TAB-REFURB_IND = 'X'.

ENDIF.

IF ITEM_TAB-MWSKZ = 'ZB' AND ITEM_TAB-REFURB_IND = 'X'.

ITEM_TAB-TAX_IND = 'B'.

WORK_TAB-TOT_TAX_AMT = WORK_TAB-TOT_TAX_AMT + ITEM_TAB-WRBTR.

ELSEIF ITEM_TAB-MWSKZ = 'ZC' AND ITEM_TAB-REFURB_IND = 'X'.

ITEM_TAB-TAX_IND = 'C'.

ENDIF. "end of code

PERFORM FILL_MBEW.

ITEM_TAB-BKLAS = WS-BKLAS.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

ITEM_TAB-ADRN2 = WORK_TAB-ADRN2.

WS-BUKRS = ITEM_TAB-BUKRS.

WS-BUDAT = WORK_TAB-BUDAT.

PERFORM FILL_ACCOUNTING_TAB.

IF SY-SUBRC = 0.

ITEM_TAB-RCC = ZACCREF-INVRC.

ITEM_TAB-GEOLOC = ZACCREF-INVLOC.

ITEM_TAB-EXTC = ZACCREF-INVRCXC.

WRITE ITEM_TAB-HKONT TO WS-HKONT NO-ZERO.

CONCATENATE WS-HKONT(4) '.' WS-HKONT+4(6) INTO

ITEM_TAB-ACCOUNT.

ELSE.

CTR-ERROR_TOTAL = CTR-ERROR_TOTAL + 1.

WRITE: / 'Cannot find ZACCREF entry with: ',

WORK_TAB-AWKEY(10), ITEM_TAB-BUKRS, ITEM_TAB-BKLAS.

  • EXIT. "commented for testing purpose.

ENDIF.

APPEND ITEM_TAB.

  • APPEND WORK_TAB.

Clear item_tab.

ENDFORM. " process_item_tab

Regards,

Vivek

Read only

0 Likes
2,008

David - you don't appear to be within any loop at this point, and you haven't read a table, so there's no internal table you can modify.

Rob

Message was edited by: Rob Burbank