‎2007 Jan 11 3:01 PM
Hi all,
I am using the logical database ADA in a program that I am writing. I need to combine ANLAV, ANLCV, and ANEPV into one super structure that I've created with our necessary fields. The super structure is made up of 4 other structures -- a header structure and 3 custom structure versions of ANLAV, ANLCV, and ANEPV.
I've set up 3 different internal tables and work areas. I currently have the following code to get the data from those tables:
tables: anlav, anlcv, anepv.
initialization.
get anlav.
move-corresponding anlav to wa_anlav.
append wa_anlav to it_anlav.
get anlcv.
move-corresponding anlcv to wa_anlcv.
append wa_anlcv to it_anlcv.
get anepv.
move-corresponding anepv to wa_anepv.
append wa_anepv to it_anepv.
What would be the best way to join those three tables? I was considering the following (pseudocode):
loop at it_anlav into wa_ada.
read it_anlcv into wa_ada1.
read it_anepv into wa_ada2.
move-corresponding wa_ada1 to wa_ada.
move-corresponding wa_ada2 to wa_ada.
collect wa_ada to it_ada.
endloop.
My worry is that I will miss some data in the process. I don't know if it's plausible, but for example, if ANLAV returns 10 records, ANLCV returns only 5, but ANEPV returns 15, then I imagine I would lose the extra five records in ANEPV.
Any helpful suggestions will be awarded points. Thanks in advance.
‎2007 Jan 11 4:21 PM
Hi,
OK..Try this..
DATA: V_it_anlav TYPE XFELD.
DATA: V_it_anlcv TYPE XFELD.
DATA: V_it_anepv TYPE XFELD.
DO.
CLEAR: WA_IT_ANLAV,
WA_IT_ANLCV,
WA_IT_ANEPV.
READ TABLE IT_ANLAV INTO WA_IT_ANLAV
INDEX SY-INDEX.
IF SY-SUBRC <> 0.
V_IT_ANLAV = 'X'.
ENDIF.
READ TABLE IT_ANLCV INTO WA_IT_ANLCV
INDEX SY-INDEX.
IF SY-SUBRC <> 0.
V_IT_ANLCV = 'X'.
ENDIF.
READ TABLE IT_ANEPV INTO WA_IT_ANEPV
INDEX SY-INDEX.
IF SY-SUBRC <> 0.
V_IT_ANEPV = 'X'.
ENDIF.
Exit out of the loop if none of the three internal tables has records.
IF V_IT_ANLAV = 'X' AND
V_IT_ANLCV = 'X' AND
V_IT_ANEPV = 'X'.
EXIT.
ENDIF.
Move the records to the output internal table.
MOVE-CORRESPONDING WA_IT_ANLAV TO WA_ADA.
MOVE-CORRESPONDING WA_IT_ANLCV TO WA_ADA.
MOVE-CORRESPONDING WA_IT_ANEPV TO WA_ADA.
APPEND WA_ADA TO IT_ADA.
ENDDO.
Hope this works..
THanks,
Naren
‎2007 Jan 11 4:07 PM
Any help on this would be greatly appreciated.
Also, I am not very familiar with Logical Databases so if you have any other suggestions on the best way to do this, please let me know.
Thanks in advance.
‎2007 Jan 11 4:14 PM
LDB makes the join of the possible tables (Parent-Child realationship) with the common key by nested selects.So finally you will get the common data. There is no loss data here.
‎2007 Jan 11 4:17 PM
Thanks, Eswar. But how would you suggest that I combine those 3 tables (ANLAV, ANLCV, and ANEPV) into one super table? Would the pseudocode I wrote work?
‎2007 Jan 11 4:21 PM
Hi,
OK..Try this..
DATA: V_it_anlav TYPE XFELD.
DATA: V_it_anlcv TYPE XFELD.
DATA: V_it_anepv TYPE XFELD.
DO.
CLEAR: WA_IT_ANLAV,
WA_IT_ANLCV,
WA_IT_ANEPV.
READ TABLE IT_ANLAV INTO WA_IT_ANLAV
INDEX SY-INDEX.
IF SY-SUBRC <> 0.
V_IT_ANLAV = 'X'.
ENDIF.
READ TABLE IT_ANLCV INTO WA_IT_ANLCV
INDEX SY-INDEX.
IF SY-SUBRC <> 0.
V_IT_ANLCV = 'X'.
ENDIF.
READ TABLE IT_ANEPV INTO WA_IT_ANEPV
INDEX SY-INDEX.
IF SY-SUBRC <> 0.
V_IT_ANEPV = 'X'.
ENDIF.
Exit out of the loop if none of the three internal tables has records.
IF V_IT_ANLAV = 'X' AND
V_IT_ANLCV = 'X' AND
V_IT_ANEPV = 'X'.
EXIT.
ENDIF.
Move the records to the output internal table.
MOVE-CORRESPONDING WA_IT_ANLAV TO WA_ADA.
MOVE-CORRESPONDING WA_IT_ANLCV TO WA_ADA.
MOVE-CORRESPONDING WA_IT_ANEPV TO WA_ADA.
APPEND WA_ADA TO IT_ADA.
ENDDO.
Hope this works..
THanks,
Naren
‎2007 Jan 11 4:22 PM
‎2007 Jan 11 4:25 PM
Try something like
GET anlav.
CLEAR flag_anla.
GET anlcv.
CLEAR flag_anlc.
GET anepv.
CLEAR outtab.
MOVE-CORRESPONDING anepv TO outtab.
MOVE-CORRESPONDING anlcv TO outtab.
clear cumulative fields (amounts, qty) of anlcv
MOVE 'X' to flag_anlc
move-corresponding anlav TO outtab.
clear cumulative fields (amounts, qty) of anlav
MOVE 'X' TO flag_anla.
COLLECT outtab.
GET anlcv LATE.
CLEAR outtab.
IF flag_anlc IS INITIAL.
MOVE-CORRESPONDING anlcv TO outtab.
MOVE-CORRESPONDING anlav TO outtab.
clear cumulative fields (amounts, qty) of anlav
MOVE 'X' TO flag_anla.
COLLECT outtab.
ENDIF.
GET anlcv LATE.
CLEAR outtab.
IF flag_anla IS INITIAL.
MOVE-CORRESPONDING anlav TO outtab.
COLLECT outtab.
ENDIF.
ENDIF.
regards
‎2007 Jan 11 4:39 PM
Thanks, Naren. I rarely use "DO" so I didn't consider it.
Raymond, can you please explain in more detail how "LATE" works?
Thanks again, everyone.
‎2007 Jan 12 11:12 AM