Skip to Content

How to concat 2 fields in database view for creating generic datasource

Hi

How to concat 2 fields in database view for creating generic datasource?

I need to create a database view between RSEG and BKPF for creating generic datasource i.e.

RSEG's two fields BELNR &GJAHR are concat value is equal to BKPF's AWKEY value. 

so I define following in Table/join Condition tab in SE11:

RSEG - MANDT = BKPF - MANDT

RSEG - BELNR & GJAHR = BKPF - AWKEY  (Error: Field RSEG-BELNR&GJAHR does not belong to a base table)

How to resolve it?

Thanks

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Oct 16, 2015 at 11:53 AM

    not possible in a view. you need to create a datasource based on a function module and use abap to link both tables.

    M.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2015 at 05:31 AM

    Hi,

    I don't think it's possible to specify this join condition in se11.

    You can think of wriitng a code to accomplish the requirement.

    Something like below -

    select belnr gjahr from RSEG into table <internal table 1> <where = "filter condition" if any>


    loop at <internal table 1> into <work area>.

    concatenate <work area-beln> <work area-gjahr> into <work area-zfield>.

    endloop.


    select * from BKPF into table <internal table 2> for all entries in <internal table 1> where awkey = <internal table 1>-zfield.


    Regards,

    Amit



    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2015 at 09:57 AM

    Hi Imran,

    Both fields BELNR(doc number) & GJAHR(fisc year) exists in both tables RSEG & BKPF, you can use these two fields in your view join conditions? then why do you need to concatenate BELNR and GJAHR to join with AWKEY? 

    you can simply use the common fields (doc number, fisc year and comp code) to join and create a view.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 16, 2015 at 11:52 AM

    Hi Imran,

    The data base view will work when the table has common Key fields. You cannot join the fields like that. the system knows to identify one to one mapping.

    Regards,

    M Priya

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 20, 2015 at 05:24 AM

    Hi

    I try to write a FM code please check it and correct it if any thing is wrong:

    TABLES: ZNADFLDGL14.

    DATA: L_S_SELECT TYPE SRSC_S_SELECT.

    STATICS: S_S_IF TYPE SRSC_S_IF_SIMPLE,

                   S_COUNTER_DATAPAKID LIKE SY-TABIX,

                   S_CURSOR TYPE CURSOR.

    RANGES: SDNO FOR ZNADFLDGL14-AWKEY.

                    SDNO FORZNADFLDGL14-BELNR.          

                   SDNO FORZNADFLDGL14-GJAHR.

    IF I_INITFLAG = SBIWA_C_FLAG_ON.

    CASE I_DSOURCE.

    WHEN 'ZFMADFLDGL14'.

    WHEN OTHERS.

         IF 1 = 2. MESSAGE E009(R3). ENDIF.

         LOG_WRITE 'E'           "message type

                             'R3'         "message class

                             '009'        "message number

                             I_DSOURCE "message variable 1

                             ' '.           "message variable 2

         RAISE ERROR_PASSED_TO_MESS_HANDLER.

    ENDCASE.

    APPEND LINES OF I_T_SELECT TO S_S_IF-T_SELECT.

    S_S_IF-REQUNR = I_REQUNR.

    S_S_IF-DSOURCE = I_DSOURCE.

    S_S_IF-MAXSIZE = I_MAXSIZE.

    APPEND LINES OF I_T_FIELDS TO S_S_IF-T_FIELDS.

    ELSE.

    IF S_COUNTER_DATAPAKID = 0.

    LOOP AT S_S_IF-T_SELECT INTO L_S_SELECT WHERE

         FIELDNM = 'AWKEY'

         FIELDNM = 'BELNR'

         FIELDNM = 'GJHAR'.

         MOVE-CORRESPONDING L_S_SELECT TO SDNO.

         APPEND SDNO.

    ENDLOOP.

    SELECT

         RSEG~BELNR RSEG~GJAHR

         BKPF~BELNR BKPF~GJAHR BKPF~AWKEY

    FROM RSEG, BKPF

         INNER JOIN RSEG on EKPO~EBELN = RSEG~EBELN

         INNER JOIN BKPF on CONCATENATE RSEG~BELNR RSEG~GJAHR =  BKPF~AWKEY

    WHERE

         RSEG~EBELN IN SDNO

         BKPF~AWKEY IN SDNO

    ENDIF.

    FETCH NEXT CURSOR S_CURSOR

    APPENDING CORRESPONDING FIELDS

    OF TABLE E_T_DATA

    PACKAGE SIZE S_S_IF-MAXSIZE.

    IF SY-SUBRC <> 0.

         CLOSE CURSOR S_CURSOR.

         RAISE NO_MORE_DATA.

    ENDIF.

         S_COUNTER_DATAPAKID = S_COUNTER_DATAPAKID + 1.

    ENDIF.

    ENDFUNCTION.

    Thanks

    Add comment
    10|10000 characters needed characters exceeded

    • I found 7 DS when I combine them then 10 fields from 11 required fields are available but what will I do the 1 field which is not available in any data source?

      Is it good practice that use Data source for 2/3 fields and 7/8 DS's uses to fulfill requirement instead of 1 generic data source?