Skip to Content

Help with routine!

Hi,

Need to use table in lookup for KUNNR.

SELECT * FROM HTABLE INTO temp FOR ALL ENTRIES IN SOURCE_PACKAGE WHERE customer = SOURCE_PACKAGE-KUNNR.

But issue is Table doesn't have customer directly and has name 0003DR0298730

Only value 98730 should be in customer.

Can't use name+8(5) directly in a select.

Any suggestions?

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 06, 2014 at 07:08 PM

    Hi,

    Yes Aditya we need another internal table here, and have to write two loop statements like below:-


    TYPES: BEGIN OF TY_HTABLE,

    KUNNR TYPE HTABLE-KUNNR,

    END OF TY_HTABLE.

    DATA: ITAB TYPE TABLE OF TY_HTABLE,

    WA TYPE TY_HTABLE,

    STR1 TYPE STRING LENGTH (XX), **what ever the length you need.

    N1 TYPE I.


    SELECT KUNNR FROM HTABLE INTO TABLE ITAB.

    LOOP AT ITAB INTO WA.

    STR1 = WA-KUNNR.

    N1 = STRLEN(STR1).

    N1 = N1 – 5.

    WA-KUNNR = STR1+N1(5).

    MODIFY ITAB FROM WA.

    END LOOP.


    LOOP AT SOURCE_PACKAGE ASSIGNING <SOURCE_FIELDS>.

    READ TABLE ITAB INTO WA WITH KEY KUNNR = <SOURCE_FIELDS> - CUSTOMER.

    END LOOP.

    The activity of first loop statement is not possible directly in select statement, to compare and get the corresponding records from HTABLE against source_package.

    Performance depends on no. of records in your HTABLE and source_package.

    EX:- Let’s assume that your source_package is holding 1000 records with different customers, and your HTABLE is containing 1 lakh records.

    In this case performance will degrade, because to compare 1000 records against HTABLE we are converting all the records(i.e., 1 lakh records) in HTABLE into format which we require. So for converting the other 99,000 records in HTABLE, is waste of time and space.

    I Hope it’s clear, if I am wrong please let know…😊

    Thanks & Regards,

    Upender reddy.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 04, 2014 at 07:49 AM

    Hi

    How can you use the KUNNR table in bi because KUNr table Is present in r/3 side not in bi side

    Please explain your requirement clearly

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 06, 2014 at 04:18 AM

    Hi Aditya,

    Open SQL is kind of limited in function specially with phase "FOR ALL ENTRIES", I am afraid you won't be able to do that by changing the SQL alone, but you may try your luck in the ABAP space as they may have more experience.

    Here some workaround come to my mind:

    1) Loop SOURCE_PACKAGE to create another itab with the correct format of customer (0003DR0298730), and replace SOURCE_PACKAGE with itab in the SQL

    2) Modify HTABLE and add a dummy field for customer ( 98730)

    3) Modify SOURCE_PACKAGE (i.e. the souce) so it contain a field in format "0003DR0298730"

    Wish it help

    Regards

    Bill

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Aditya,

      For workaround 1, I mean:

      * Please ignore any syntax error btw, am just showing the logic

      * Loop source and create a itab with list of customer in correct format
      LOOP AT SOURCE_PACKAGE INTO wa_src

      wa_itab-CUSTOMER = '0003DR02' + wa_src-KUNNR

      APPEND wa_itab TO itab.

      END LOOP


      * Use the new itab in SQL

      SELECT * FROM HTABLE INTO temp FOR ALL ENTRIES IN itab WHERE customer = itab-CUSTOMER.

      Performance depends on how many records you have in source.

      But anyway, I think you generally have 2 options:

      1) Like my workaround 1 or upender's code, add a few logic to further process the data, but performance really depends on how many data you have in HTABLE or SOURCE_PACKAGE

      2) Maintain a dummy field in HTABLE or SOURCE_PACKAGE

      Wish it help

      Regards

      Bill

  • Posted on Jan 04, 2014 at 12:50 PM

    Hi Aditya,

    You can create a variable. It consists of
    SOURCE_PACKAGE-KUNNR and concatenates 0003DR02.

    And that variable you can pass to where consist.

    Create this variable of same data type of CUSTOMER.

    Hope this helps you.

    Thanks & Regards,

    Vipin

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.