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

Combining Logical Databases?

Former Member
0 Likes
1,095

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
932

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

8 REPLIES 8
Read only

Former Member
0 Likes
932

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.

Read only

Former Member
0 Likes
932

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.

Read only

0 Likes
932

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?

Read only

Former Member
0 Likes
933

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

Read only

Former Member
0 Likes
932

Hi,

Please check my reply..

Thanks,

Naren

Read only

RaymondGiuseppi
Active Contributor
0 Likes
932

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

Read only

0 Likes
932

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.

Read only

0 Likes
932

In logical database

- GET => read the data

- process lower level GET

- GET LATE => call after treatment of all lower level GET before reading next record of this level

process it like AT NEW / AT END

hoping to be understandable...