Dear Guys,
From Here, I would to share one of my “genius” (the way of my calling that) solutions, which is in the case of when you want to display the feedback (return) messages from BAPI, or you are in the loop, there are some processes going on inside of it, and they will throw exception to you (eg. sy-subrc NE 0). What happen is that if you just use “MESSAGE” statement to display one by one, would be really frustrated that you won’t see full details from those messages (because there are whole bunch of them) and so on, whereby you looking for a system function that can be collecting themselves and display them in a particular of time. Trust me, those functions is not as abatable as mine.
1. First of all you create a function group. [ I called that ZMESSAGES_DISPLAY]
2. Create a screen as a dialog type, because I'm using ALV to display, from here I won't to give any details about it.
Here is the main program:
*&Developed by Hai Wang 2013-10-23 last modification
*&+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*******************************************************************
* System-defined Include-files. *
*******************************************************************
INCLUDE LZMESSAGES_DISPLAYTOP. " Global Data
INCLUDE LZMESSAGES_DISPLAYUXX. " Function Modules
*******************************************************************
* User-defined Include-files (if necessary). *
*******************************************************************
* INCLUDE LZMESSAGES_DISPLAYF... " Subprograms
* INCLUDE LZMESSAGES_DISPLAYO... " PBO-Modules
* INCLUDE LZMESSAGES_DISPLAYI... " PAI-Modules
INCLUDE LZMESSAGES_DISPLAYO01.
INCLUDE LZMESSAGES_DISPLAYI01.
INCLUDE LZMESSAGES_DISPLAYF01.
3. Lets view the Includes:
*&Developed by Hai Wang 2013-10-23 last modification
*&+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
FUNCTION-POOL ZMESSAGES_DISPLAY. "MESSAGE-ID ..
TYPES: BEGIN OF t_message,
object TYPE string,
operate TYPE string,
message(220) TYPE c,
type TYPE c,
col(4) TYPE c,
END OF t_message.
DATA: fm_g_alv TYPE REF TO cl_gui_alv_grid,
fm_g_con TYPE REF TO cl_gui_custom_container,
fm_layout TYPE lvc_s_layo,
fm_fcat TYPE lvc_t_fcat WITH HEADER LINE.
DATA: messages_list TYPE TABLE OF t_message. "Container of the messages
DATA: title TYPE string. "this surposse to be for displaying the title for the dialog windows, but it doesn't work
DATA: clear_flag TYPE i. "a control flag, to tell funcation to clear the list.
The view of INCLUDE LZMESSAGES_DISPLAYF01.
*----------------------------------------------------------------------*
***INCLUDE LZMESSAGES_DISPLAYF01 .
*----------------------------------------------------------------------*
*&Developed by Hai Wang 2013-10-23 last modification
*&+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*&---------------------------------------------------------------------*
*& Form SETLAYO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LAYOUT text
*----------------------------------------------------------------------*
form SETLAYO.
fm_layout-no_toolbar = 'X'.
fm_layout-INFO_FNAME = 'COL'.
endform. " SETLAYO
*&---------------------------------------------------------------------*
*& Form SETFCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FCAT text
*----------------------------------------------------------------------*
form SETFCAT.
PERFORM fcat USING: 'OBJECT' 1 '对象',
'OPERATE' 2 '操作',
'MESSAGE' 3 '消息',
'TYPE' 4 '类型'.
endform. " SETFCAT
*&---------------------------------------------------------------------*
*& Form FCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form FCAT using fname TYPE LVC_FNAME
col TYPE LVC_COLPOS
seltext TYPE LVC_TXT .
fm_fcat-FIELDNAME = fname.
fm_fcat-COL_POS = col.
fm_fcat-SELTEXT = seltext.
fm_fcat-COLTEXT = seltext.
IF seltext = 'MESSAGE'.
fm_fcat-outputlen = '100'.
ENDIF.
APPEND fm_fcat.
endform. " FCAT
The view of INCLUDE LZMESSAGES_DISPLAYO01.
*----------------------------------------------------------------------*
***INCLUDE LZMESSAGES_DISPLAYO01 .
*----------------------------------------------------------------------*
*&Developed by Hai Wang 2013-10-23 last modification
*&+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*&---------------------------------------------------------------------*
*& Module STATUS_1000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module STATUS_1000 output.
SET PF-STATUS 'T_000'.
SET TITLEBAR title.
endmodule. " STATUS_1000 OUTPUT
*&---------------------------------------------------------------------*
*& Module ALV_OUTPUT OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module ALV_OUTPUT output.
CREATE OBJECT fm_g_con
EXPORTING
container_name = 'LIST'
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT fm_g_alv
EXPORTING
i_parent = fm_g_con
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF fm_g_alv IS BOUND.
IF fm_layout IS INITIAL AND fm_fcat IS INITIAL.
PERFORM setlayo .
PERFORM setfcat .
ENDIF.
CALL METHOD fm_g_alv->set_table_for_first_display
EXPORTING
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
* i_structure_name =
* is_variant =
* i_save =
* i_default = 'X'
is_layout = fm_layout
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = messages_list
it_fieldcatalog = fm_fcat[]
* it_sort =
* it_filter =
* EXCEPTIONS
* invalid_parameter_combination = 1
* program_error = 2
* too_many_lines = 3
* others = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
endmodule. " ALV_OUTPUT OUTPUT
The view of INCLUDE LZMESSAGES_DISPLAYI01.
*----------------------------------------------------------------------*
***INCLUDE LZMESSAGES_DISPLAYI01 .
*----------------------------------------------------------------------*
*&Developed by Hai Wang 2013-10-23 last modification
*&+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*&---------------------------------------------------------------------*
*& Module EXIT INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module EXIT input.
CALL METHOD fm_g_alv->free.
CALL METHOD fm_g_con->free.
LEAVE TO SCREEN 0.
endmodule. " EXIT INPUT
4. There are two funcation model, one is for collecting messages, another is to display , the following is the code of these two.
For collection:
FUNCTION ZFM_MESSAGE_APPEND.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(MSGID) TYPE SYMSGID OPTIONAL
*" VALUE(MSGNO) TYPE SYMSGNO OPTIONAL
*" VALUE(MSGTY) TYPE SYMSGTY
*" VALUE(MSGV1) TYPE SYMSGV OPTIONAL
*" VALUE(MSGV2) TYPE SYMSGV OPTIONAL
*" VALUE(MSGV3) TYPE SYMSGV OPTIONAL
*" VALUE(MSGV4) TYPE SYMSGV OPTIONAL
*" VALUE(MESSAGE) TYPE BAPI_MSG OPTIONAL
*" VALUE(OBJ) TYPE CHAR10
*" VALUE(OPERATE) TYPE CHAR10
*"----------------------------------------------------------------------
*&Developed by Hai Wang 2013-10-23 last modification
*&+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DATA: wa_message TYPE t_message,
buff TYPE string.
wa_message-type = msgty.
IF clear_flag = 1.
CLEAR: messages_list[],
clear_flag.
ENDIF.
IF MESSAGE IS INITIAL.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = MSGID
msgnr = MSGNO
MSGV1 = MSGV1
MSGV2 = MSGV2
MSGV3 = MSGV3
MSGV4 = MSGV4
IMPORTING
MESSAGE_TEXT_OUTPUT = buff
.
wa_message-message = buff.
ELSE.
wa_message-message = message.
ENDIF.
CASE msgty.
WHEN 'S'. wa_message-col = 'C510'.
WHEN 'W'OR 'A'. wa_message-col = 'C310'.
WHEN 'E'. wa_message-col = 'C610'.
WHEN OTHERS.
wa_message-col = 'C601'.
ENDCASE.
wa_message-object = obj.
wa_message-operate = operate.
APPEND wa_message TO messages_list.
DELETE ADJACENT DUPLICATES FROM messages_list COMPARING ALL FIELDS.
ENDFUNCTION.
For Display:
FUNCTION ZFM_MESSAGE_DISPLAY_SETUP.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(P_TITLE) TYPE STRING
*"----------------------------------------------------------------------
*&Developed by Hai Wang 2013-10-23 last modification
*&+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DATA: line TYPE i.
DESCRIBE TABLE messages_list LINES line.
IF line NE 0.
TITLE = P_TITLE.
clear_flag = 1.
CALL SCREEN 1000 STARTING AT 20 30.
ENDIF.
ENDFUNCTION.
SAMPLE PROGRAM.
form set_bapi_data.
LOOP AT it_output WHERE flag = 'C510'.
bapi_vbeln = it_output-vbeln.
CLEAR ls_ord_header-DLV_BLOCK.
ls_ord_header_inx-UPDATEFLAG = 'U'.
ls_ord_header_inx-DLV_BLOCK = 'X'.
PERFORM uploaddata.
ENDLOOP.
IF sy-subrc NE 0.
MESSAGE w000(z_1) WITH '操作失误,' '请选定有效订单后,再按' 'RELEASE(释放)' '!'.
ELSE.
* alv_flag = 1 .
DATA: buff TYPE string.
* LOOP AT lt_return WHERE TYPE NE 'S'. " Replaced for "LOOP AT lt_return." Hai Wang 2013-10-21
**& Replace by Hai Wang 2013-10-18
** APPEND lt_return-message TO logs.
**
**& AS the following
** MESSAGE ID lt_return-id TYPE 'I' NUMBER lt_return-number
** WITH lt_return-MESSAGE_V1 lt_return-MESSAGE_V2 lt_return-MESSAGE_V3 lt_return-MESSAGE_V4.
* CONCATENATE buff lt_return-message INTO buff.
* MESSAGE buff TYPE 'I'.
* ENDLOOP.
* IF buff is not INITIAL.
* MESSAGE buff TYPE 'I'.
* ENDIF.
*
* "Added by Hai Wang 2013-10-21
* IF sy-subrc NE 0.
* MESSAGE S000(z_1) WITH '所选并已释放的订单,' '已成功解锁!' '' ''.
* ENDIF.
CALL FUNCTION 'ZFM_MESSAGE_DISPLAY_SETUP'
EXPORTING
p_title = '订单解锁操作'
.
CLEAR lt_return[].
ENDIF.
ENDFORM.
form uploadData.
DATA: it_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = bapi_vbeln
ORDER_HEADER_IN = ls_ord_header
order_header_inx = ls_ord_header_inx
tables
return = it_return
.
READ TABLE it_output WITH KEY vbeln = bapi_vbeln.
* APPEND LINES OF it_return TO lt_return.
LOOP AT it_return.
CALL FUNCTION 'ZFM_MESSAGE_APPEND'
EXPORTING
* MSGID =
* MSGNO =
msgty = it_return-type
* MSGV1 =
* MSGV2 =
* MSGV3 =
* MSGV4 =
MESSAGE = it_return-message
obj = bapi_vbeln
operate = '上传'
.
ENDLOOP.
READ TABLE it_return WITH KEY type = 'S' TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
it_output-flag = 'C601'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'x'
IMPORTING
return = it_return.
* APPEND LINES OF it_return TO lt_return.
LOOP AT it_return.
CALL FUNCTION 'ZFM_MESSAGE_APPEND'
EXPORTING
* MSGID =
* MSGNO =
msgty = it_return-type
* MSGV1 =
* MSGV2 =
* MSGV3 =
* MSGV4 =
MESSAGE = it_return-message
obj = bapi_vbeln
operate = '数据库操作'
.
ENDLOOP.
READ TABLE it_return WITH KEY type = 'S' TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
it_output-flag = 'C501'.
ELSE.
it_output-flag = 'C301'.
ENDIF.
ENDIF.
MODIFY TABLE it_output.
endform.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 |