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: 

how do i get unique kunnr

Former Member
0 Kudos

Hi All,

i want to fetch the KUNNR from BSEG table based on the BELNR. But if we see the BSEG table same same BELNR is having different KUNNR.

based on the KUNNR i want to dislpay the Customer name from KNA1.

so, how do proceed ?.

thanks in advance

manjusha.

1 ACCEPTED SOLUTION

GauthamV
Active Contributor
0 Kudos

You have to select data based on document ,year and item in order

to get unique record.

I.e use these fields - BUKRS,BELNR,GJAHR,BUZEI.

Now based on that kunnr get from KNA1.

6 REPLIES 6

GauthamV
Active Contributor
0 Kudos

You have to select data based on document ,year and item in order

to get unique record.

I.e use these fields - BUKRS,BELNR,GJAHR,BUZEI.

Now based on that kunnr get from KNA1.

Former Member
0 Kudos

bseg-bukrs, "Company Code

bseg-belnr, "Accounting Document Number

bseg-gjahr, "Fiscal Year

Use above fields to fetch the unique record

For Example.

SELECT belnr
               augbl
               wrbtr
               shkzg
               rebzg
               rebzj
               rebzz
          FROM bseg
          INTO TABLE t_partial_cleared
          WHERE
          bukrs = '1000' AND
          belnr =  bsad-augbl AND
          gjahr =  fiscal_year.

Former Member
0 Kudos

Hi All,

actually i am using the FEBEP table to fetch other reuired fields including BELNR.

so, i am checking the FEBEP-BELNR with BSEG-BELNR.

and for that BSEG-BELNR and BSEG-KUNNR i am fetching name1 rom KNA1 .

0 Kudos

From FEBEP, read FEBKO with FEBEP-KUKEY, then read BSEG with FEBKO-BUKRS, FEBEP-GJAHR and FEBEP-BELNR

Regards

Former Member
0 Kudos

Lets say u get entries for BSEG in GT_BSEG with "FEBEP-BELNR with BSEG-BELNR." condition.

then 1 simple and effective way is.

sort gt_bseg by kunnr.
loop at gt_bseg into gs_bseg.
 at new kunnr.
    gs_kunnr-kunnr = gs_bseg-kunnr .   "this gs_kunnr work areahas one field only as kunnr
    append gs_kunnr to gt_kunnr.  " gt_kunnr is table similar to gs_kunnr 
    clear: gs_kunnr.
endloop.

select kunnr
          name1
         from KNA1 into table gt_kna1
         for all entries in gt_kunnr
         where kunnr = gt_kunnr-kunnr.

or


loop at gt_bseg into gs_bseg.
    gs_kunnr-kunnr = gs_bseg-kunnr .   "this gs_kunnr work areahas one field only as kunnr
    collect gs_kunnr to gt_kunnr.  " gt_kunnr is table similar to gs_kunnr 
    clear: gs_kunnr.
endloop.

select kunnr
          name1
         from KNA1 into table gt_kna1
         for all entries in gt_kunnr
         where kunnr = gt_kunnr-kunnr.

Former Member
0 Kudos

Hi

select name1, name2 into table TB_NAME from KNA1

join BSEG on BSEGKUNNR = KNA1KUNNR

where BUKRS = WF_BUKRS and

BELNR = WF_BELNR and

GJAHR = WF_GJAHR and

BUZEI = WF_BUZEI.