Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

how do i get unique kunnr

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.

Former Member
replied

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question