cancel
Showing results for 
Search instead for 
Did you mean: 

Bapi in alv

suryakumar1223
Explorer
0 Kudos

1. User will provide sales order on selection screen

2. The program should create delivery document for that sales order using BAPI-DELIVERYPROCESSING-EXEC.

3.Show the success or error log in ALV format

aoyang
Contributor

1. Define selection screen and sales order as the parameter.

2. In START-OF-SELECTION, select relevant data for that sales order and pass it to BAPI_DELIVERYPROCESSING_EXEC.

3. In the RETURN parameter of the BAPI, you will get the process log. Use function module REUSE_ALV_GRID_DISPLAY to display the content of RETURN as ALV.

I don't know what your question is but does this help?

NooruBohra
Participant
0 Kudos

Is this a question? It seems more like a requirement. Please provide where exactly you're getting an issue.

Accepted Solutions (0)

Answers (4)

Answers (4)

aoyang
Contributor

suryakumar1223 Fixed your code. Go ahead and run it and you will see return messages will display in ALV.

Personally I think user will appreciate more if message type is also displayed in the ALV. Does this answer your question?

TYPE-POOLS :slis.
TABLES : vbak,vbap.

TYPES:
BEGIN OF ty_vbap ,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
matnr LIKE vbap-matnr,
werks LIKE vbap-werks,
status type char200,
END OF ty_vbap,

BEGIN OF ty_message,
status type char200,
END OF ty_message.

DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_fieldcat TYPE slis_fieldcat_alv,
gs_layo TYPE slis_layout_alv.

DATA: gt_tab type table of ty_vbap with header line,
gv_tab type ty_vbap,
gt_message TYPE STANDARD TABLE OF ty_message,
gv_message TYPE ty_message.
DATA: gt_request TYPE STANDARD TABLE OF bapideliciousrequest WITH HEADER LINE.

DATA: gt_created TYPE STANDARD TABLE OF bapideliciouscreateditems WITH HEADER LINE.
DATA: gt_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
DATA : lv_text TYPE string.
DATA: wa_return type bapiret2.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_vbeln LIKE vbak-vbeln. SELECTION-SCREEN END OF BLOCK b1.

Start-of-selection.

SELECT vbeln posnr kwmeng matnr werks INTO TABLE gt_tab FROM vbap WHERE vbeln = p_vbeln.

gs_fieldcat-col_pos = '1'.
gs_fieldcat-fieldname = 'STATUS'.
gs_fieldcat-seltext_l = 'Status'.
gs_fieldcat-outputlen = '200'.
APPEND gs_fieldcat TO gt_fieldcat.

CLEAR gs_fieldcat.

LOOP AT gt_tab into gv_tab.
gt_request-document_numb = gv_tab-vbeln.
gt_request-document_item = gv_tab-posnr.
gt_request-quantity_sales_uom = gv_tab-kwmeng.
gt_request-id = 1.
gt_request-document_type = 'A'.
gt_request-delivery_date = sy-datum.
gt_request-material = gv_tab-matnr.
gt_request-plant = gv_tab-werks.
gt_request-date = sy-datum.
gt_request-goods_issue_date = sy-datum.
gt_request-goods_issue_time = sy-uzeit.
APPEND gt_request.

PERFORM delivery.
PERFORM message.
ENDLOOP.
FORM delivery .
CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
request = gt_request
createditems = gt_created
return = gt_return.
ENDFORM.
FORM message .
LOOP AT gt_return INTO wa_return.
clear:gv_message.

CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = wa_return-ID
lang = sy-langu
no = wa_return-number
v1 = wa_return-message_v1
v2 = wa_return-message_v2
v3 = wa_return-message_v3
v4 = wa_return-message_v4
IMPORTING
msg = lv_text
EXCEPTIONS
not_found = 1
OTHERS = 2.
gv_message-status = lv_text.

append gv_message to gt_message.
ENDLOOP.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = gs_layo
IT_FIELDCAT = gt_fieldcat
TABLES
T_OUTTAB = gt_message
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM.
NooruBohra
Participant
0 Kudos

aocheng Appreciate your effort.

suryakumar1223
Explorer
0 Kudos

That is the question only? I want to create delivery document for the sales order..i have to write code for delivery creation only and I want to display success or error log from the system in alv

suryakumar1223
Explorer
0 Kudos

Hi Aocheng yang,

I appreciate you, when I execute the code.. alv is not displaying.. could you check it once... only selection screen is displaying..alv is not displaying...please rectify it..and send the code... thank you

SimoneMilesi
Active Contributor

Shouldn't this be your work?
Aocheng gave you a base to start, almost complete even if with a couple of lacks: you can start debugging it and find where is the problem.

aoyang
Contributor

suryakumar1223 My code works fine. In the selection screen, you first must enter the sales order number from which you want create the delivery order. Then you execute the program, the program will create delivery order by calling the BAPI and then ALV will display the process log. Please try again.

Even though my code works, it is merely a base sample I gave you. You have to modify the program as your requirement(for example, add GUI status, change parameter to select options, and so on).

suryakumar1223
Explorer
0 Kudos

Hi experts,

Could please find the mistake in the program as I'm not getting output.

*&------------------------------------------------------------- *

*&---------------------------------------------------------------------* TYPE-POOLS :slis.
TABLES : vbak,vbap. TYPES: BEGIN OF ty_vbap ,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
matnr LIKE vbap-matnr,
werks LIKE vbap-werks,
END OF ty_vbap. TYPES: BEGIN OF ty_status,
status type char30,
END OF ty_status. DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
gs_fieldcat TYPE slis_fieldcat_alv,
gs_layo TYPE slis_layout_alv. DATA: gt_tab type table of ty_vbap with header line,
gv_tab type ty_vbap. DATA: gt_tab1 type table of ty_status with header line,
gv_tab1 type ty_status. DATA: gt_request TYPE STANDARD TABLE OF bapideliciousrequest WITH HEADER LINE. DATA: gt_created TYPE STANDARD TABLE OF bapideliciouscreateditems WITH HEADER LINE. DATA: gt_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE. DATA : lv_text TYPE string. DATA: wa_return type bapiret2. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001. PARAMETERS: p_vbeln LIKE vbak-vbeln. SELECTION-SCREEN END OF BLOCK b1.Start-of-selection.SELECT vbeln posnr kwmeng matnr werks INTO TABLE gt_tab FROM vbap WHERE vbeln = p_vbeln.gs_fieldcat-col_pos = '1'. gs_fieldcat-fieldname = 'STATUS'. gs_fieldcat-seltext_l = 'Status'. gs_fieldcat-outputlen = '30'. APPEND gs_fieldcat TO gt_fieldcat. CLEAR gs_fieldcat.LOOP AT gt_tab into gv_tab. gt_request-document_numb = gt_tab-vbeln. gt_request-document_item = gt_tab-posnr. gt_request-quantity_sales_uom = gt_tab-kwmeng. gt_request-id = 1. gt_request-document_type = 'A'. gt_request-delivery_date = sy-datum. gt_request-material = gt_tab-matnr. gt_request-plant = gt_tab-werks. gt_request-date = sy-datum. gt_request-goods_issue_date = sy-datum. gt_request-goods_issue_time = sy-uzeit. APPEND gt_request. PERFORM delivery. PERFORM message. endloop.FORM delivery . CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC' TABLES request = gt_request createditems = gt_created return = gt_return. ENDFORM.FORM message . LOOP AT gt_return INTO wa_return. CALL FUNCTION 'FORMAT_MESSAGE' EXPORTING id = wa_return-ID lang = sy-langu no = wa_return-number v1 = wa_return-message_v1 v2 = wa_return-message_v2 v3 = wa_return-message_v3 v4 = wa_return-message_v4 IMPORTING msg = lv_text EXCEPTIONS not_found = 1 OTHERS = 2. gv_tab-status = lv_text. MODIFY gt_tab from gv_tab. ENDLOOP. CLEAR:wa_return. CLEAR:gv_tab.CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING IS_LAYOUT = gs_layo IT_FIELDCAT = gt_fieldcat TABLES T_OUTTAB = gt_tab * EXCEPTIONS * PROGRAM_ERROR = 1 * OTHERS = 2 .Could please help me out where I'm getting wrong..... I'm not getting the status message.