‎2008 Mar 26 12:28 PM
hey there,
im new to abap and i have the following problem:
zps_s_mass is the structure which i need it later to show in an ALV. the program searches the table it_nexceltab for an identical entry in the table it_XXX1. if it finds an itendic entry it mutates the entry in the table it_XXX1 (it_nexceltab-instrneu).
but then, i want to write the data in a structure with a bonus field "status" in this field i write if the mutation was a success, if it found a identical entry. i need the structure later to show in an ALV.
the problem is, that it always overwrites my data in the structure, with every loop. but i need all entries...
thx for any help.
code:
LOOP AT it_XXX1 INTO wa_XXX1.
success = ''.
zusatz = ''.
name = wa_XXX1-verna.
FIND '@' IN wa_XXX1-verna.
IF sy-subrc = 0.
REPLACE '@ ' IN wa_XXX1-verna WITH ''.
zusatz = '@ '.
ENDIF.
LOOP AT it_nexceltab INTO wa_nexceltab.
IF wa_XXX1-verna EQ wa_nexceltab-instralt.
name = wa_nexceltab-instrneu.
success = 'X'.
ENDIF.
ENDLOOP.
IF zusatz EQ '@ '.
CONCATENATE zusatz name INTO name.
zusatz = ''.
ENDIF.
wa_XXX1-verna = name.
zps_s_mass-persnr = wa_XXX1-vernr.
zps_s_mass-nameinstr = wa_XXX1-verna.
zps_s_mass-tabelle = 'XXX1'.
IF success EQ 'X'.
zps_s_mass-status = 'Mutation Erfolgreich'.
ELSE.
zps_s_mass-status = 'Mutation Fehlgeschlagen'.
ENDIF.
MODIFY it_XXX1 FROM wa_XXX1.
ENDLOOP.
Edited by: rafe b. on Mar 26, 2008 1:34 PM
‎2008 Mar 27 12:54 AM
Rafe,
A structure is basically a single set of different fields grouped using a single name - it can therefore only hold a single set of values.
For your requirement you need to define an internal table with a layout that matches your structure:
DATA: zpt_s_mass LIKE STANDARD TABLE OF zps_s_mass.Then, in each pass of the loop, after you have set the sructure values, you need to append them to the internal table.
IF success EQ 'X'.
zps_s_mass-status = 'Mutation Erfolgreich'.
ELSE.
zps_s_mass-status = 'Mutation Fehlgeschlagen'.
ENDIF.
APPEND zps_s_mass TO zpt_s_mass. "<<<<<<<<<<<<<<
MODIFY it_XXX1 FROM wa_XXX1.Later on, you can get the values back one at a time by looping through the internal table.
LOOP AT zpt_s_mass INTO zps_s_mass.
...code to process
ENDLOOP.Andrew
‎2008 Mar 26 10:10 PM
Hi Rafe,
I guess I know were your conflict is caused by. It's not a structural discrepancy, but a LOOP in the LOOP problem. The inner LOOP is running always till the end, i.e. there is always information captured from the last occurence when wa_XXX1-verna equals wa_nexceltab-instralt. When the if-statement is true, there has to be an EXIT-statement, i.e. the LOOP will be exited.
Another recommendation: It's faster an securer to use the clear-statement for to initialize a field (not <field> = '').
I marked the critical loop in bold and added the EXIT-statement.
LOOP AT it_XXX1 INTO wa_XXX1.
success = ''.
zusatz = ''.
name = wa_XXX1-verna.
FIND '@' IN wa_XXX1-verna.
IF sy-subrc = 0.
REPLACE '@ ' IN wa_XXX1-verna WITH ''.
zusatz = '@ '.
ENDIF.
LOOP AT it_nexceltab INTO wa_nexceltab.
IF wa_XXX1-verna EQ wa_nexceltab-instralt.
name = wa_nexceltab-instrneu.
success = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF zusatz EQ '@ '.
CONCATENATE zusatz name INTO name.
zusatz = ''.
ENDIF.
wa_XXX1-verna = name.
zps_s_mass-persnr = wa_XXX1-vernr.
zps_s_mass-nameinstr = wa_XXX1-verna.
zps_s_mass-tabelle = 'XXX1'.
IF success EQ 'X'.
zps_s_mass-status = 'Mutation Erfolgreich'.
ELSE.
zps_s_mass-status = 'Mutation Fehlgeschlagen'.
ENDIF.
MODIFY it_XXX1 FROM wa_XXX1.
ENDLOOP.
Have success and fun,
Heinz
PS: Ich spreche auch Deutsch; bin aus Muenchen.
‎2008 Mar 27 12:54 AM
Rafe,
A structure is basically a single set of different fields grouped using a single name - it can therefore only hold a single set of values.
For your requirement you need to define an internal table with a layout that matches your structure:
DATA: zpt_s_mass LIKE STANDARD TABLE OF zps_s_mass.Then, in each pass of the loop, after you have set the sructure values, you need to append them to the internal table.
IF success EQ 'X'.
zps_s_mass-status = 'Mutation Erfolgreich'.
ELSE.
zps_s_mass-status = 'Mutation Fehlgeschlagen'.
ENDIF.
APPEND zps_s_mass TO zpt_s_mass. "<<<<<<<<<<<<<<
MODIFY it_XXX1 FROM wa_XXX1.Later on, you can get the values back one at a time by looping through the internal table.
LOOP AT zpt_s_mass INTO zps_s_mass.
...code to process
ENDLOOP.Andrew
‎2008 Mar 27 7:47 AM
defining an internal table with a layout that matches my structure solved the problem!
thx for all your help 😃
regards
‎2008 Mar 27 3:44 AM
hi rafe,
see this code.
data:it2_xx1 like wa_xx1 occurs 0 with header line.
LOOP AT it_XXX1 INTO wa_XXX1.
success = ''.
zusatz = ''.
name = wa_XXX1-verna.
FIND '@' IN wa_XXX1-verna.
IF sy-subrc = 0.
REPLACE '@ ' IN wa_XXX1-verna WITH ''.
zusatz = '@ '.
ENDIF.
LOOP AT it_nexceltab INTO wa_nexceltab.
IF wa_XXX1-verna EQ wa_nexceltab-instralt.
name = wa_nexceltab-instrneu.
success = 'X'.
ENDIF.
ENDLOOP.
IF zusatz EQ '@ '.
CONCATENATE zusatz name INTO name.
zusatz = ''.
ENDIF.
wa_XXX1-verna = name.
zps_s_mass-persnr = wa_XXX1-vernr.
zps_s_mass-nameinstr = wa_XXX1-verna.
zps_s_mass-tabelle = 'XXX1'.
IF success EQ 'X'.
zps_s_mass-status = 'Mutation Erfolgreich'.
ELSE.
zps_s_mass-status = 'Mutation Fehlgeschlagen'.
ENDIF.
move-corresponding wa_XXX1 to it2_xx1.
append it2_xx1.
clear it2_xx1.
ENDLOOP.