Application Development and Automation 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: 
Read only

ALV help required.

Former Member
0 Likes
698

Hi

I have to call : bapi_materialgroup_get_list in my report program & have to display the output into ALV format.

Please guide me how to proceed.

I am unable to reach out to a place to start.

Your help will be appriciated.

Vipin Sharma

5 REPLIES 5
Read only

gopi_narendra
Active Contributor
0 Likes
674

If you are talking about the BAPI, its a well documented BAPI.

If you are talking about ALV's follow this simple ALV List example

TYPE-POOLS: slis.

DATA : BEGIN OF xmara,
         matnr LIKE makt-matnr,
         spras LIKE makt-spras,
         maktx LIKE makt-maktx,
       END OF xmara.

DATA: imara LIKE STANDARD TABLE OF xmara WITH HEADER LINE.
DATA: fieldcat TYPE slis_t_fieldcat_alv.
DATA: repid TYPE syrepid.

repid = sy-repid.

SELECT matnr spras maktx
       FROM makt
       INTO TABLE imara
       UP TO 100 ROWS
       WHERE spras = sy-langu.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
          i_program_name     = repid
          i_internal_tabname = 'XMARA'
          i_inclname         = repid
          i_bypassing_buffer = 'X'
     CHANGING
          ct_fieldcat        = fieldcat.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
          it_fieldcat = fieldcat
     TABLES
          t_outtab    = imara.

Regards

Gopi

Read only

0 Likes
674

Hi Gopi,

He has asked about report program using BAPI not a simple ALV.

Read only

Former Member
0 Likes
674

Hi Vipin,

First you have to study about Bapi.

Check the following links:

http://www.sapbrainsonline.com/TUTORIALS/TECHNICAL/BAPI_tutorial.html

http://sap-img.com/bapi.htm

http://sapmaterial.com/bapi.html

using BAPI you can retrives the data's and then you can print the data's Using ALV.

Thanks,

Reward If Helpful.

Read only

Former Member
0 Likes
674

Hi,

This is a program using BAPI for creating sales order. Like this, u modify for Material Group.

REPORT zbapi_va01.

TYPES : BEGIN OF ty_so,

ind,

vkorg(4), "VBAK - Sales Organization

vtweg(2), "VBAK - Distribution Channel

spart(2), "VBAK - Division

vbeln(10), "VBAK - Sales Document

ketdat(8), "Requested delivery date of the document - Sales Order Data

vkbur(4), "VBAK - Sales office

kunnr1(10), "VBPA - Sold-to party

kunnr2(10), "VBPA - Ship-To Party

bstkd(35), "VBKD - Customer purchase order number

zterm(4), "VBKD - Terms of payment key

augru(3), "VBAK - Order reason

mabnr(18), "Material Number

kwmeng(15), "Cumulative order quantity in sales units

vrkme(3), "VBAP - Sales unit

werks(4), "VBAP - Plant (Own or External)

vstel(4), "VBAP - Shipping Point/Receiving Point

kbetr1(11), "KONV - Rate (condition amount or percentage)

kbetr2(11), "KONV - Rate (condition amount or percentage)

prctr(10), "Profit Center

END OF ty_so.

DATA : it_so TYPE STANDARD TABLE OF ty_so,

it_so1 TYPE STANDARD TABLE OF ty_so,

v_order_header_in LIKE bapisdhd1,

v_salesdocumentin LIKE bapivbeln-vbeln,

v_order_partners LIKE bapiparnr OCCURS 0 WITH HEADER LINE,

v_order_items_in LIKE bapisditm OCCURS 0,

v_order_conditions_in LIKE bapicond OCCURS 0,

v_order_schedules_in LIKE bapischdl OCCURS 0,

order_header_inx LIKE bapisdhd1x,

order_items_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE,

order_schedules_inx LIKE bapischdlx OCCURS 0 WITH HEADER LINE,

order_conditions_inx LIKE bapicondx OCCURS 0 WITH HEADER LINE,

it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

FIELD-SYMBOLS : <fs_so> TYPE ty_so, <fs_so1> LIKE LINE OF it_so.

DATA : wa_bapisditm LIKE bapisditm,

wa_bapicond LIKE bapicond,

wa_bapischdl LIKE bapischdl,

w_schditm LIKE bapischdl-sched_line,

w_itemno(6) TYPE n,

w_profit_ctr LIKE bapisditm-profit_ctr,

mesid(2) TYPE c.

PARAMETERS : testrun AS CHECKBOX DEFAULT 'X'.

START-OF-SELECTION.

CALL FUNCTION 'UPLOAD'

EXPORTING

filetype = 'DAT'

TABLES

data_tab = it_so

EXCEPTIONS

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

OTHERS = 7

.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

it_so1[] = it_so[].

DELETE it_so WHERE ind = 'D'.

DELETE it_so1 WHERE ind = 'H'.

order_header_inx-updateflag = 'I'.

order_header_inx-doc_type = 'X'.

order_header_inx-sales_org = 'X'.

order_header_inx-distr_chan = 'X'.

order_header_inx-division = 'X'.

order_header_inx-sales_off = 'X'.

order_header_inx-pmnttrms = 'X'.

order_header_inx-ord_reason = 'X'.

order_header_inx-purch_no_c = 'X'.

order_header_inx-req_date_h ='X'.

order_header_inx-date_type = 'X'.

LOOP AT it_so ASSIGNING <fs_so>.

CLEAR : v_order_header_in, v_salesdocumentin, v_order_partners[], v_order_items_in[], v_order_conditions_in[], v_order_conditions_in[],

order_items_inx[], order_conditions_inx[], v_order_schedules_in[], order_schedules_inx[].

v_order_header_in-doc_type = 'ZDEP'.

v_order_header_in-sales_org = <fs_so>-vkorg.

v_order_header_in-distr_chan = <fs_so>-vtweg.

v_order_header_in-division = <fs_so>-spart.

v_order_header_in-sales_off = <fs_so>-vkbur.

v_order_header_in-pmnttrms = <fs_so>-zterm.

v_order_header_in-ord_reason = <fs_so>-augru.

v_order_header_in-purch_no_c = <fs_so>-bstkd.

v_order_header_in-req_date_h = <fs_so>-ketdat.

v_order_header_in-date_type = '1'.

v_salesdocumentin = <fs_so>-vbeln.

w_itemno = 10.

CLEAR wa_bapisditm.

wa_bapisditm-itm_number = w_itemno.

wa_bapisditm-material = <fs_so>-mabnr.

wa_bapisditm-sales_unit = <fs_so>-vrkme.

wa_bapisditm-net_weight = <fs_so>-kwmeng.

wa_bapisditm-untof_wght = <fs_so>-vrkme.

wa_bapisditm-plant = <fs_so>-werks.

wa_bapisditm-ship_point = <fs_so>-vstel.

wa_bapisditm-profit_ctr = <fs_so>-prctr.

APPEND wa_bapisditm TO v_order_items_in.

order_items_inx-itm_number = w_itemno.

order_items_inx-updateflag = 'I'.

order_items_inx-material = 'X'.

order_items_inx-sales_unit = 'X'.

order_items_inx-net_weight = 'X'.

order_items_inx-untof_wght = 'X'.

order_items_inx-plant = 'X'.

order_items_inx-ship_point = 'X'.

order_items_inx-profit_ctr = 'X'.

APPEND order_items_inx.

v_order_partners-partn_role = 'AG'. "Sold-to-Party

v_order_partners-partn_numb = <fs_so>-kunnr1.

APPEND v_order_partners.

v_order_partners-partn_role = 'WE'. "Ship-to-Party

v_order_partners-partn_numb = <fs_so>-kunnr2.

APPEND v_order_partners.

CLEAR wa_bapischdl.

w_schditm = 1.

wa_bapischdl-itm_number = w_itemno.

wa_bapischdl-sched_line = w_schditm.

wa_bapischdl-req_date = <fs_so>-ketdat.

wa_bapischdl-date_type = '1'.

wa_bapischdl-req_qty = <fs_so>-kwmeng.

wa_bapischdl-sched_type = 'CP'.

wa_bapischdl-dlv_date = <fs_so>-ketdat.

APPEND wa_bapischdl TO v_order_schedules_in.

order_schedules_inx-itm_number = w_itemno.

order_schedules_inx-updateflag = 'I'.

order_schedules_inx-sched_line = 'X'.

order_schedules_inx-req_date = 'X'.

order_schedules_inx-date_type = 'X'.

order_schedules_inx-req_qty = 'X'.

order_schedules_inx-sched_type = 'X'.

order_schedules_inx-dlv_date = 'X'.

APPEND order_schedules_inx.

CLEAR wa_bapicond.

wa_bapicond-itm_number = w_itemno.

wa_bapicond-cond_type = 'ZDPR'.

wa_bapicond-cond_value = <fs_so>-kbetr1.

wa_bapicond-currency = 'INR'.

APPEND wa_bapicond TO v_order_conditions_in.

wa_bapicond-cond_type = 'ZDBV'.

wa_bapicond-cond_value = <fs_so>-kbetr2.

APPEND wa_bapicond TO v_order_conditions_in.

CLEAR order_conditions_inx.

order_conditions_inx-itm_number = w_itemno.

order_conditions_inx-cond_type = 'ZDPR'.

order_conditions_inx-updateflag = 'I'.

order_conditions_inx-cond_value = 'X'.

order_conditions_inx-currency = 'X'.

APPEND order_conditions_inx.

order_conditions_inx-cond_type = 'ZDBV'.

APPEND order_conditions_inx.

LOOP AT it_so1 ASSIGNING <fs_so1> WHERE vbeln = <fs_so>-vbeln.

CLEAR wa_bapisditm.

ADD 10 TO w_itemno.

wa_bapisditm-itm_number = w_itemno.

wa_bapisditm-material = <fs_so1>-mabnr.

wa_bapisditm-sales_unit = <fs_so1>-vrkme.

wa_bapisditm-net_weight = <fs_so1>-kwmeng.

wa_bapisditm-untof_wght = <fs_so1>-vrkme.

wa_bapisditm-plant = <fs_so1>-werks.

wa_bapisditm-ship_point = <fs_so1>-vstel.

wa_bapisditm-profit_ctr = <fs_so1>-prctr.

APPEND wa_bapisditm TO v_order_items_in.

order_items_inx-itm_number = w_itemno.

order_items_inx-updateflag = 'I'.

order_items_inx-material = 'X'.

order_items_inx-sales_unit = 'X'.

order_items_inx-net_weight = 'X'.

order_items_inx-untof_wght = 'X'.

order_items_inx-plant = 'X'.

order_items_inx-ship_point = 'X'.

order_items_inx-profit_ctr = 'X'.

APPEND order_items_inx.

CLEAR wa_bapischdl.

ADD 1 TO w_schditm.

wa_bapischdl-itm_number = w_itemno.

wa_bapischdl-sched_line = w_schditm.

wa_bapischdl-req_date = <fs_so1>-ketdat.

wa_bapischdl-date_type = '1'.

wa_bapischdl-req_qty = <fs_so1>-kwmeng.

wa_bapischdl-sched_type = 'CP'.

wa_bapischdl-dlv_date = <fs_so1>-ketdat.

APPEND wa_bapischdl TO v_order_schedules_in.

order_schedules_inx-itm_number = w_itemno.

order_schedules_inx-updateflag = 'I'.

order_schedules_inx-sched_line = 'X'.

order_schedules_inx-req_date = 'X'.

order_schedules_inx-date_type = 'X'.

order_schedules_inx-req_qty = 'X'.

order_schedules_inx-sched_type = 'X'.

order_schedules_inx-dlv_date = 'X'.

APPEND order_schedules_inx.

CLEAR wa_bapicond.

wa_bapicond-itm_number = w_itemno.

wa_bapicond-cond_type = 'ZDPR'.

wa_bapicond-cond_value = <fs_so1>-kbetr1.

wa_bapicond-currency = 'INR'.

APPEND wa_bapicond TO v_order_conditions_in.

wa_bapicond-cond_type = 'ZDBV'.

wa_bapicond-cond_value = <fs_so1>-kbetr2.

APPEND wa_bapicond TO v_order_conditions_in.

order_conditions_inx-itm_number = w_itemno.

order_conditions_inx-cond_type = 'ZDPR'.

order_conditions_inx-updateflag = 'I'.

order_conditions_inx-cond_value = 'X'.

order_conditions_inx-currency = 'X'.

APPEND order_conditions_inx.

order_conditions_inx-cond_type = 'ZDBV'.

APPEND order_conditions_inx.

ENDLOOP.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

salesdocumentin = v_salesdocumentin

order_header_in = v_order_header_in

order_header_inx = order_header_inx

testrun = testrun

TABLES

return = it_return

order_items_in = v_order_items_in

order_items_inx = order_items_inx

order_partners = v_order_partners

order_conditions_in = v_order_conditions_in

order_conditions_inx = order_conditions_inx

order_schedules_in = v_order_schedules_in

order_schedules_inx = order_schedules_inx.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

LOOP AT it_return.

mesid = it_return-id+0(2).

CONDENSE mesid.

WRITE 😕 it_return-type, mesid, it_return-number, it_return-message+0(80).

ENDLOOP.

ENDLOOP.

Reward if useful.

Read only

kiran_k8
Active Contributor
0 Likes
674

Vipin,

after that bapi's execution check for sy-subrc and then pass the tables in the BAPI to ALV or pass these tables into one more internal table and use this internal table to display in ALV.

CALL FUNCTION 'BAPI_MATERIAL_GETLIST'

EXPORTING

MAXROWS = 0

<b>TABLES</b>

MATNRSELECTION =

MATERIALSHORTDESCSEL =

  • MANUFACTURERPARTNUMB =

  • PLANTSELECTION =

  • STORAGELOCATIONSELECT =

  • SALESORGANISATIONSELECTION =

  • DISTRIBUTIONCHANNELSELECTION =

  • MATNRLIST =

  • RETURN

K.Kiran.