Search code examples
abapbapisap-erp

Usage of bapi_vendor_find


I'm quite new to ABAP world. I searched on the web over an hour but couldn't find an example of bapi_vendor_find function.

    CALL FUNCTION 'BAPI_VENDOR_FIND'
    *  EXPORTING
    *   MAX_CNT          = 0
    *   PL_HOLD          = ' '
    *  IMPORTING
    *  RETURN           =
      TABLES
      selopt_tab       = g_tab_selopt
      result_tab       = g_tab_result
                            .

How should I prepare the "g_tab_selopt" and "g_tab_selopt". Thanks in advance for any help...


Solution

  • After many tries and fails I've found out the solution.

        REPORT  zbss00_lieferant_anzeigen.
    
        PARAMETERS: p_ccode  TYPE bapivendor_10-comp_code.
    
        TYPES: tab1 TYPE TABLE OF BAPIVENDOR_10.
    
        Data:
              g_tab_selopt type table of BAPIVENDOR_10,
              g_tab_result type table of BAPIVENDOR_11,
              l_vendor_no type BAPIVENDOR_11,
              g_selopt type BAPIVENDOR_10.
    
    
              g_selopt-COMP_CODE = p_ccode.
              g_selopt-TABNAME = 'LFB1'.
              g_selopt-FIELDNAME = 'MANDT'.
              g_selopt-FIELDVALUE = '900'.
              APPEND g_selopt TO g_tab_selopt.
    
         CALL FUNCTION 'BAPI_VENDOR_FIND'
        *  EXPORTING
        *   MAX_CNT          = 0
        *   PL_HOLD          = ' '
        *  IMPORTING
        *  RETURN           =
          TABLES
          selopt_tab       = g_tab_selopt
          result_tab       = g_tab_result
                                .
    
        loop at g_tab_result into l_vendor_no.
          write: /, 'Vendor No: ', l_vendor_no-VENDOR_NO.
        endloop.
    

    In this example, I've searched for vendors by company code in the table "LFB1" where mandt is equal to 900. I set MANDT 900 because i needed to get all vendors and in my case all vendors have 900 in MANDT column.

    This may not be the proper way, but at least it works. If anyone knows a better way to do this, please feel free to write. I'll edit the answer according to that...