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 and extracting1st line of table with no Keyother than name and last name

Former Member
0 Kudos

Hi Guys,

I need your help with something.

I am Looping a table and reading another so I can work on my conditions and display results.

The problem I have is that one of my conditions consists in the following logic:

If the employee is not found on the results table coming from an external application ( which happens a lot and btw, there is no kee for the employee other than name and last name ) I need to gather the 1st result ( 1st row of the results table ) and get all data but the employee's.

Any solution for this?

I have tried a coupe of things but do not want loop inside the loop for performance reasons.

Help highly appreciated.

Thank you,

F

19 REPLIES 19

Former Member
0 Kudos

hi Fafa,

can you please explain your requriement in other words. I suppose you have a system table and other ext app table. On comparision if system employee record is not found in ext app table then what exactly is req...?

Regards,

DN.

0 Kudos

When I compare SAPitab with ExTERNALitab results,   if I have a match with employee name, employee last name and employee address I populate the final results table.

Which is basically the results of employee address information being correct.

if I DO NOT have a match with employee name and employee last name BUT I still have the results table filled with other people with that particular street information I have searched for:   on the results table I only populate the street information.

Thing is: when that happens I have several people for the same street and I only one to get the first record on the table otherwise my results table and ALV gets incorrect information.

Thanks,  F

0 Kudos

Anyone to help out?

Highly appreciated ....

0 Kudos

Can you share the code. Just so that I can get a clear understanding of your problem.

Thanks and regards,

Rishav

0 Kudos

Hi Fafa,

I am still unclear of your req, still trying to share what i understand.

Loop at SAP_TAB into WA_SAP.

READ EXT_TAB into WA_EXT with key FNAME = wa_SAP-FNAME  LNAME=WA_SAP-LNAME ADD = WA_SAP-ADD.

IF sy-subrc eq 0.

          " if successful append record to IT_FINAL.

ELSE.

* if the first name last name and street comnination not found, check for streed in final table

read IT_FINAL into wa_temp with key add = WA_SAP-add.

if sy-subrc eq 0.        

* if employee with same street found use this in your new record directly as this would be the first record with that street in your table (depends on your SAP table sorting params)

*if you need the very first record of results/final table irrespective of street here then read index 1

* read it_final into wa_temp index 1.

* use wa_temp information to append new record.

endif.

ENDIF

ENDLOOP.

Please let me know your concern.

Regards,

DN.

0 Kudos

So lets your first read from External ITAB fails or does not match..

then you have in final table employee with same address.. You can use read statement to fetch only line for the same? Isnt it this way

0 Kudos

Solution Deepak gave me is partially working.

Problem is now that all the other employes  I had on the final, for example, 10 lines with 10 different employees are getting the same address, overwritting the old ones ...

0 Kudos

Please paste your sample code here

0 Kudos

I have given a sample/psuedo code.

Please check for proper clearing of variables. It will solve your this issue.

Regards,

DN.

0 Kudos

This is the crirteria if I find no match for employee and only a table full of other people and with the street I have searched for.  IF sy-subrc NE 0.  CLEAR wa_external_lista.        READ TABLE li_EXTERNAL_list INTO wa_2_list INDEX 1.        IF li_external_table[] IS NOT INITIAL and          wa_2_list-name NE ls_addr_list-nachn and          wa_2_list-vorname NE ls_addr_list-vorna.          wa_2_list-geburts_jahr NE ls_addr_list-gbjhr.           MOVE-CORRESPONDING:         wa_2_list TO ls_lista.            MOVE-CORRESPONDING:         ls_SAP_list TO ls_resultadofinal,         ls_external_table TO ls_resultadofinal.          resultadofinal-name = ''.         resultadofinal-vorname = ''.         resultadofinal = 'Address is correct.         APPEND ls_resultadofinal TO li_resultadofinal.        ENDIF.    ENDIF.

0 Kudos

This is the crirteria if I find no match for employee and only a table full of other people and with the street I have searched for. 

IF sy-subrc NE 0.  CLEAR wa_external_lista.     

  READ TABLE li_EXTERNAL_list INTO wa_2_list INDEX 1.     

IF li_external_table[] IS NOT INITIAL and       

wa_2_list-name NE ls_addr_list-nachn and       

wa_2_list-vorname NE ls_addr_list-vorna and       

wa_2_list-geburts_jahr NE ls_addr_list-gbjhr.         

MOVE-CORRESPONDING:         wa_2_list TO ls_lista.         

MOVE-CORRESPONDING:       

ls_SAP_list TO ls_resultadofinal,     

ls_external_table TO ls_resultadofinal.         

resultadofinal-name = ''.       

resultadofinal-vorname = ''.       

resultadofinal = 'Address is correct.       

APPEND ls_resultadofinal TO li_resultadofinal.       

ENDIF. 

ENDIF.

0 Kudos

Just debbuging I can see what is the issue.   As I have no keys realy for this, so I really need a condition when I read the table that:    IF Itab is not initial and have more than 1 record ...  I guess I can narrow it that way.   Can I do that with the READ .... ?

0 Kudos

My solution did not work either.   Anyone to help please?   Thanks  F

0 Kudos

Anyone to help please?

0 Kudos

Fafa what you can do in case no match happen use describe table to check if table has more than one line ifyes read index 1 and append data

0 Kudos

Use describe table and read combination

0 Kudos

I can find what I am looking for. The first record on the table only.   But when I have another employee, instead of getting the correct address of that employee, it overwrites with the address on this table.

0 Kudos

Hi Fafa,

I am not sure on how you have used the code that i had suggested, but i am pretty sure that it will work as per your requirement. I will request you to please check for clearing of variables and work areas thoroughly as overwirting previous values etc are minor issue which occur due to such things. Please debug your code and provide me specifically what is happening with your wrong street info record. check on how is the street for the second employee found and when the record is finally moving what is the value, if changed you will come to know which step exactly it is changing.

Regards,

DN.

venkat_aileni
Contributor
0 Kudos

Hi-

Follow below steps this will solve your problem:

*Create a new Internal table with only field Street.

SORT it_external BY street.

LOOP AT itab INTO wa.

   CLEAR: wa_external,

          wa_final.

   READ TABLE it_external INTO wa_external WITH KEY fname  = wa-fname

                                                    lname  = wa-lname

                                                    street = wa-street.

   IF sy-subrc = 0.

     MOVE-CORRESPONDING: wa_external TO wa_final.

     APPEND wa_final TO it_final.

   ELSE

     READ TABLE it_street INTO wa_street WITH KEY street = wa-street.

     IF sy-subrc NE 0.

       MOVE-CORRESPONDING wa_external TO wa_final.

       APPEND wa_final TO it_final.

       APPEND wa_final-street TO it_street.

     ENDIF.

   ENDIF.

   CLEAR: wa.

ENDLOOP.

-Venkat