Application Development 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: 

Reading Tables with multiple keys

Former Member
0 Kudos

Hi Gurus,

I would appreciate your knowledge and input with this question of mine.

I have an extensive code, over 1600 lines now and all my validation are done and working 100 percent correctly.

I am doing 9 calls to a webservice and need now to compare the results of my results table to my sap results table.

I tried to use:

Loop table1 into wa

Read table2 into wa

With key ....,

BUT

I really cannot compare all the fields I need to compare because in each call I make to the webservice I use diferent keys.

What is the best way of doing this?

I have tried a couple of things but with no success.

I thought now reading tables 9 times separately, storing the result and after move all those results to a final structure and display.

Is there a better solution?

Please help.

Thank you

F

16 REPLIES 16

Former Member
0 Kudos

didnt completely understand your query...So Is This Like you have an an internal table with , say

field name: A     B      C

value       : a1    b1     c1     and you want to compare it with 9 internal tables with  same fields ?

0 Kudos

Hi Sooraj,

What I mean is ( as an example 😞

LOOP AT li_add1 INTO wa_add_1

    READ TABLE li_addr2 into wa_add_2

     WITH KEY name = ls_nachn strasse = ls_stras plz = ls_pstlz ort18 = ls_ort01.  "common field

Than I do my ifs in there.

Problem is for the next web services results I have different keys to compare to those same two tables.

I have 9 different key sets ...

That is my dilema. 

0 Kudos

Better example:

LOOP AT li_add1 INTO wa_add_1

    READ TABLE li_addr2 into wa_add_2

     WITH KEY name = ls_nachn strasse = ls_stras plz = ls_pstlz ort18 = ls_ort01.  "common field

All my ifs go here ....

Then I have another set of keys to compare

LOOP AT li_add1 INTO wa_add_1

    READ TABLE li_addr2 into wa_add_2

     WITH KEY str1 = ls_str3 birthday  = ls_birthday = ls_stras plz = ls_pstlz ort18 = ls_ort01.  "common field

All ifs

Than another read and compare table and so on ...

9 times ...

0 Kudos

Anyone to chime in?

0 Kudos

Hi Fafa,

If i understood your escenario...

You get data from web services and this data are store on iternal table. Now, your need compare this data with data from SAP tables.

Maby you can use:

if table_from_web_service[] = table_from_sap_table[].

     ..................

endif.

First, probably do you need fetch data from SAP Tables using any key.

Regards.

0 Kudos

Hi,

From the example you provided you have some common fields between 1st call and 2nd call.

Will it be an issue in terms of how much data in returned if you just call the web service with the common fields and then do a dynamic check on what you have with what is returned.

also, just for confirmation, is you goal to reduce the number of lines of code or to have a better performance in terms of making multiple web service calls

0 Kudos

Hi

try this

LOOP AT li_add1 INTO wa_add_1

    READ TABLE li_addr2 into wa_add_2

     WITH KEY name = ls_nachn strasse = ls_stras plz = ls_pstlz ort18 = ls_ort01.  "common

  IF     sy-subrc EQ 0.

"ur if logic........................

  ENDIF.

    READ TABLE li_addr2 into wa_add_2  WITH KEY str1 = wa_add_1-str3 birthday  = wa_add_1-birthdat ls_stras plz =wa_add_1-plz"""""""""""""common field.

IF     sy-subrc EQ 0.

ENDIF.

"""""""""""""""""""ur next 7 read statement

ENDLOOP.

U can use single loop for better performance.

0 Kudos

Not working that way. Besides of getting duplicates, the logic is not working properly ...

0 Kudos

Hi,

U want single Read statement is executed for each time. i m correct

0 Kudos

Correct.   In each case I will be populating a status collumn so I really need all those 9 KEY possibilites while comparing the tables.

0 Kudos

Try this,,

DATA l_flag TYPE c.

LOOP AT li_add1 INTO wa_add_1

    READ TABLE li_addr2 into wa_add_2

     WITH KEY name = ls_nachn strasse = ls_stras plz = ls_pstlz ort18 = ls_ort01.  "common

  IF     sy-subrc EQ 0.

l_flag = 'X'

"ur if logic........................

  ENDIF.

IF l_flag NE 'X'            "add this

    READ TABLE li_addr2 into wa_add_2  WITH KEY str1 = wa_add_1-str3 birthday  = wa_add_1-birthdat ls_stras plz =wa_add_1-plz"""""""""""""common field.

IF     sy-subrc EQ 0.

l_flag = 'X'.

ENDIF.

ENDIF.

"""""""""""""""""""ur next 7 read statement

Clear l_flag .

ENDLOOP.

Try to use l_flag  = 'X' after read statement sy-subrc EQ 0 .

0 Kudos

HI Fafa,

basically you need a Dynamic Condition on the read statement ... Check the below thread and implement the approach used in the program

http://scn.sap.com/thread/1570278

Regards,

Kapil.

0 Kudos

Thank you but dinamic condition will not work with the webservices response.

0 Kudos

Hi fafa,

Can you specify why dynamic condition will not work ? also provide format of webservice response which you are getting .

Regards,

Kapil.

Former Member
0 Kudos

Hi

Instead of looping it and comaring all the values which will affect the response time of your program just write one statement.

select fields from table into workarea

for all entries in (table you want to check)

where mentions the keys.

if sy-subrc = 0.

you have got all the values.

else.

no values.

Could you please post you query in a more understandable way.

With Regards

Suneesh

sascha_reissig
Participant
0 Kudos

Hi Fafa,

may be you can solve this in the following way:

regards, Sascha