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

Display ALV after saving

Former Member
0 Likes
4,947

Hi Experts,

I have a ALV display in my report. What I need to do is to have another alv display after clicking save.

But when I've tried to do it. The previous structure in the first ALV still appears. How can I remove the first ALV after clicking save?

I have set this code in my save code:

         SET SCREEN 0.

         rs_selfield-refresh = 'X'.

         PERFORM display_result. <<< new ALV that needs to be shown


My ALV Display have different Structure/Fields

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,705

Hi,

I don't have any idea on how to create a new screen for the new ALV. Let me just google it first.

Thank you for the answers.

11 REPLIES 11
Read only

former_member355261
Participant
0 Likes
4,705

Hi,

Try using LEAVE TO SCREEN 0. instead,

Regards.

Read only

0 Likes
4,705

Hi,

I have used Leave to Screen 0 but after it leaves the screen it wont read the lines after it.

The result will just leave the screen and wont execute the other ALV.

Read only

0 Likes
4,705

You have created a separate screen for your second ALV right? Then do CALL SCREEN <SCREEN NUMBER> or LEAVE TO SCREEN <SCREEN NUMBER>

Read only

0 Likes
4,705

There is a method SET_DATA within the class CL_SALV_TABLE that allows you to change the DDIC structure for your ALV without creating another, Otherwise just create another screen with the second ALV and call it using CALL SCREEN ...

Read only

former_member185613
Contributor
0 Likes
4,705

Hi Jepoy,

Call ALV refresh after the second ALv call and see if it displays correctly.

Hope it helps,

~Athreya

Read only

0 Likes
4,705

still the same sir.

Read only

0 Likes
4,705

Hi,

Please check the field catalog for the second ALV display. Does it have the field entries that refer to the first ALV?

Regards,

~Athreya

Read only

former_member300076
Participant
0 Likes
4,705

Hi,

Why not create a new screen for this new ALV and call it after the SAVE method like this:

CALL METHOD cl_gui_cfw=>flush.

CALL SCREEN XXX.

Regards,

Sam,

Read only

Former Member
0 Likes
4,706

Hi,

I don't have any idea on how to create a new screen for the new ALV. Let me just google it first.

Thank you for the answers.

Read only

0 Likes
4,705

Hi Jepoy,

Here is a useful link you may use : https://abapjournal.wordpress.com/2011/08/22/alv-grid-report-template-using-dynpro-custom-container/

To create a new screen simply from the ABAP Editor :

First, from the left menu create a new screen by clicking with the left button of the mouse and then create.

Choose the type of the screen (Normal for you).

Give it a name.

Then click on the Layout button to edit your newly created screen.

Finally create a custom container on your screen (with other elements if you want).

This container will then contain your second ALV.

Read only

Former Member
0 Likes
4,705

Here is my code using SE38.

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

*& Report  ZPURGE_PO_ASC

*&

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

*&

*&

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

REPORT  ZPURGE_PO_ASC.

TABLES: ekko, ekbe, ekpo.

TYPE-POOLS: sdydo, icon, slis.

TYPES: BEGIN OF t_header,

        line01(555) TYPE c,

        line02(555) TYPE c,

        END OF t_header.

DATA: gw_header  TYPE t_header.

DATA: w_title     TYPE lvc_title,

       w_repid     TYPE sy-repid,

       w_comm      TYPE slis_formname,

       w_status    TYPE slis_formname,

       x_layout    TYPE slis_layout_alv,

       ls_events   TYPE LINE OF slis_t_event,

       t_events    TYPE slis_t_event,

       t_fieldcat  TYPE slis_t_fieldcat_alv,

       x_sort      type LINE OF slis_t_sortinfo_alv,

       t_sort      TYPE slis_t_sortinfo_alv,

       ls_heading  TYPE slis_listheader,

       t_heading   TYPE slis_t_listheader,

       ls_fieldcat TYPE slis_fieldcat_alv,

       gs_variant  LIKE disvariant.

DATA: is_print TYPE slis_print_alv,

       gset TYPE lvc_s_glay,

       %runmode TYPE aqlimode.

data: it_sortcat   type slis_sortinfo_alv occurs 1,

         wa_sort like line of it_sortcat.

DATA: BEGIN OF it_ekpo OCCURS 0,

     ebeln LIKE ekpo-ebeln,

     ebelp LIKE ekpo-ebelp,

     menge LIKE ekpo-menge,

     meins LIKE ekpo-meins,

     matnr LIKE ekpo-matnr,

     txz01 LIKE ekpo-txz01,

     werks LIKE ekpo-werks,

     banfn LIKE ekpo-banfn,

     netpr LIKE ekpo-netpr,

   END OF it_ekpo.

DATA: wa_ekpo LIKE  it_ekpo.

DATA: BEGIN OF it_ekbe OCCURS 0,

     ebeln LIKE ekbe-ebeln,

     ebelp LIKE ekbe-ebelp,

     menge LIKE ekbe-menge,

     dmbtr LIKE ekbe-dmbtr,

     wrbtr LIKE ekbe-wrbtr,

     vgabe LIKE ekbe-vgabe,

     shkzg LIKE ekbe-shkzg,

   END OF it_ekbe.

DATA: it_ekbe2 LIKE it_ekbe OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF it_ekbe3 OCCURS 0,

     ebeln LIKE ekbe-ebeln,

     ebelp LIKE ekbe-ebelp,

     menge LIKE ekbe-menge,

     dmbtr LIKE ekbe-dmbtr,

     wrbtr LIKE ekbe-wrbtr,

     vgabe LIKE ekbe-vgabe,

   END OF it_ekbe3.

DATA: BEGIN OF it_ekbe4 OCCURS 0,

     ebeln LIKE ekbe-ebeln,

     ebelp LIKE ekbe-ebelp,

     menge LIKE ekbe-menge,

     dmbtr LIKE ekbe-dmbtr,

   END OF it_ekbe4.

DATA: BEGIN OF it_ekbeNDSH OCCURS 0,

     ebeln LIKE ekbe-ebeln,

     ebelp LIKE ekbe-ebelp,

     menge LIKE ekbe-menge,

     dmbtr LIKE ekbe-dmbtr,

   END OF it_ekbeNDSH.

DATA: it_ekbeNDP2 LIKE it_ekbe OCCURS 0 WITH HEADER LINE, "No Down payment

       it_ekbeNDP LIKE it_ekbeNDSH OCCURS 0 WITH HEADER LINE, "No Down payment

       it_ekbeSH LIKE it_ekbe3 OCCURS 0 WITH HEADER LINE, "With downpayment

       it_ekbeWDP LIKE it_ekbe4 OCCURS 0 WITH HEADER LINE"With downpayment

       it_ekbeFINAL LIKE it_ekbe4 OCCURS 0 WITH HEADER LINE. "Final ITAB for it_ekbe

DATA: wa_ekbe LIKE it_ekbe,

       wa_ekbe2 LIKE it_ekbe2.

DATA: BEGIN OF it_final OCCURS 0,

     check(1) TYPE c,

     ebeln LIKE ekbe-ebeln,

     ebelp LIKE ekbe-ebelp,

     pomenge LIKE ekbe-menge,

     meins LIKE ekpo-meins,

     grmenge LIKE ekbe-menge,

     matnr LIKE ekpo-matnr,

     txz01 LIKE ekpo-txz01,

     werks LIKE ekpo-werks,

     banfn LIKE ekpo-banfn,

    dmbtr LIKE ekbe-dmbtr,

   END OF it_final.

DATA: wa_final LIKE it_final.

DATA: ans(1) TYPE c,

       lv_dmbtr  TYPE ekbe-dmbtr.

DATA: BEGIN OF it_msg  OCCURS 0,

   ponum LIKE ekbe-ebeln,

   polne LIKE ekbe-ebelp,

   type(1) TYPE c,

   message TYPE BAPI_MSG,

   END OF it_msg.

DATA: flg(1) TYPE c.

SELECT-OPTIONS: s_ebeln FOR ekpo-ebeln,

                 s_ebelp FOR ekpo-ebelp,

                 s_werks FOR ekpo-werks.

START-OF-SELECTION.

PERFORM get_data.

PERFORM display_report.

FORM get_data.

   SELECT ebeln ebelp menge meins matnr txz01 werks banfn netpr

     INTO CORRESPONDING FIELDS OF TABLE it_ekpo

     FROM ekpo

     WHERE ebeln IN s_ebeln

     AND ebelp IN s_ebelp

     AND werks IN s_werks

     AND loekz NE 'L'. "Deleted PO Line Items

   "No Down Payment

   SELECT ebeln ebelp menge shkzg"dmbtr wrbtr shkzg vgabe

     INTO CORRESPONDING FIELDS OF TABLE it_ekbe

     FROM ekbe

     WHERE ebeln IN s_ebeln

     AND ebelp IN s_ebelp

     AND werks IN s_werks

     AND ( vgabe NE '4' OR vgabe NE 'C' )

     AND bwart NE ''. "asc check

     SORT it_ekbe BY ebeln ebelp.

     LOOP AT it_ekbe.

       IF it_ekbe-shkzg = 'S'. "positive

         it_ekbe-menge = it_ekbe-menge.

       ELSEIF it_ekbe-shkzg = 'H'. "negative

         it_ekbe-menge = it_ekbe-menge * -1.

       ENDIF.

       MODIFY it_ekbe.

     ENDLOOP.

     SORT it_ekbe BY ebeln ebelp shkzg.

     LOOP AT it_ekbe.

       COLLECT it_ekbe INTO it_ekbeNDP2.

     ENDLOOP.

     it_ekbeNDSH[] = it_ekbeNDP2[].

     LOOP AT it_ekbeNDSH.

       COLLECT it_ekbeNDSH INTO it_ekbeNDP.

     ENDLOOP.

   "With Downpayment

   SELECT ebeln ebelp menge dmbtr wrbtr vgabe shkzg

     INTO CORRESPONDING FIELDS OF TABLE it_ekbe2

     FROM ekbe

     WHERE ebeln IN s_ebeln

     AND ebelp IN s_ebelp

     AND werks IN s_werks

     AND ( vgabe EQ '4' OR vgabe EQ 'C' ).

     SORT it_ekbe2 BY ebeln ebelp.

     LOOP AT it_ekbe2.

       IF it_ekbe2-shkzg = 'S'. "positive

         it_ekbe2-dmbtr = it_ekbe2-dmbtr.

       ELSEIF it_ekbe2-shkzg = 'H'. "negative

         it_ekbe2-dmbtr = it_ekbe2-dmbtr * -1.

       ENDIF.

       MODIFY it_ekbe2.

     ENDLOOP.

     it_ekbe3[] = it_ekbe2[].

     SORT it_ekbe3 BY ebeln ebelp.

     LOOP AT it_ekbe3.

       COLLECT it_ekbe3 INTO it_ekbeSH.

     ENDLOOP.

     it_ekbe4[] = it_ekbeSH[].

     SORT it_ekbe4 BY ebeln ebelp.

     LOOP AT it_ekbe4.

       COLLECT it_ekbe4 INTO it_ekbeWDP.

     ENDLOOP.

   "check this if all ebeln have vgabe NE 4/c

   LOOP AT it_ekbeNDP.

     it_ekbefinal-ebeln = it_ekbeNDP-ebeln.

     it_ekbefinal-ebelp = it_ekbeNDP-ebelp.

     it_ekbefinal-menge = it_ekbeNDP-menge.

     READ TABLE it_ekbeWDP WITH KEY ebeln = it_ekbeNDP-ebeln

                                    ebelp = it_ekbeNDP-ebelp.

     IF sy-subrc EQ 0.

       it_ekbefinal-dmbtr = it_ekbeWDP-dmbtr.

     ENDIF.

     APPEND it_ekbefinal. CLEAR it_ekbefinal.

   ENDLOOP.

   LOOP AT it_ekpo INTO wa_ekpo.

     it_final-ebeln = wa_ekpo-ebeln.

     it_final-ebelp = wa_ekpo-ebelp.

     it_final-pomenge = wa_ekpo-menge.

     it_final-meins = wa_ekpo-meins.

     it_final-matnr = wa_ekpo-matnr.

     it_final-txz01 = wa_ekpo-txz01.

     it_final-werks = wa_ekpo-werks.

     it_final-banfn = wa_ekpo-banfn.

     READ TABLE it_ekbefinal WITH TABLE KEY ebeln = wa_ekpo-ebeln

                                            ebelp = wa_ekpo-ebelp.

     IF sy-subrc EQ 0.

       it_final-grmenge = it_ekbefinal-menge.

       it_final-dmbtr = it_ekbefinal-dmbtr.

     ENDIF.

     APPEND it_final. CLEAR it_final.

   ENDLOOP.

ENDFORM.

FORM user_command USING r_ucomm LIKE sy-ucomm

                   rs_selfield TYPE slis_selfield.

CASE r_ucomm.

   WHEN '&DATA_SAVE'.

     "Validation

     READ TABLE it_final WITH KEY check = 'X'.

     IF sy-subrc NE 0 .

       MESSAGE 'No Item(s) Selected' TYPE 'E'.

         LEAVE LIST-PROCESSING.

     ENDIF.

     LOOP AT it_final INTO wa_final WHERE check EQ 'X'.

       IF wa_final-pomenge EQ wa_final-grmenge.

         MESSAGE 'PO Item(s) have Equal Quantity' TYPE 'E'.

         LEAVE LIST-PROCESSING.

       ENDIF.

       IF wa_final-dmbtr IS NOT INITIAL.

         MESSAGE 'PO Item(s) have Downpayment' TYPE 'E'.

         LEAVE LIST-PROCESSING.

       ENDIF.

     ENDLOOP.

     CALL FUNCTION 'POPUP_TO_CONFIRM'

       EXPORTING

         TITLEBAR              = 'Confirmation'

         TEXT_QUESTION         = 'Are you sure you want to proceed in purging the PO item(s)?'

         TEXT_BUTTON_1         = 'Yes'

         ICON_BUTTON_1         = 'ICON_CHECKED'

         TEXT_BUTTON_2         = 'No'

         ICON_BUTTON_2         = 'ICON_CANCEL'

         DISPLAY_CANCEL_BUTTON = ' '

         POPUP_TYPE            = 'ICON_MESSAGE_WARNING'

       IMPORTING

         ANSWER                = ANS.

       IF ANS = 2.

         EXIT.

       ELSE.

         LOOP AT it_final INTO wa_final WHERE check EQ 'X'.

           DATA: t_return LIKE bapiret2      OCCURS 0 WITH HEADER LINE.

           DATA: t_item   LIKE bapimepoitem  OCCURS 0 WITH HEADER LINE.

           DATA: t_itemx  LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE.

           DATA: ponumber LIKE BAPIMEPOHEADER-PO_NUMBER.

           DATA: c_err like t_return-type.

           IF wa_final-grmenge IS NOT INITIAL.

             ponumber = wa_final-ebeln.

             t_item-po_item = wa_final-ebelp.

             t_item-quantity = wa_final-grmenge.

*            t_item-net_price = '2000'.

             APPEND t_item.

             t_itemx-po_item = wa_final-ebelp.

             t_itemx-po_itemx = 'X'.

             t_itemx-quantity = 'X'.

*            t_itemx-net_price = 'X'.

             APPEND t_itemx.

           ELSE.

             ponumber = wa_final-ebeln.

             t_item-po_item = wa_final-ebelp.

             t_item-delete_ind = 'X'.

             APPEND t_item.

             t_itemx-po_item = wa_final-ebelp.

             t_itemx-po_itemx = 'X'.

             t_itemx-delete_ind = 'X'.

             APPEND t_itemx.

           ENDIF.

           CALL FUNCTION 'BAPI_PO_CHANGE'

           EXPORTING

             PURCHASEORDER = ponumber

           TABLES

             RETURN        = t_return

             POITEM        = t_item

             POITEMX       = t_itemx.

           READ TABLE t_return WITH KEY type = 'E' TRANSPORTING NO FIELDS.

           IF sy-subrc NE 0.

             CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

               EXPORTING

                 wait = 'X'.

*              MESSAGE 'PO Successfully Changed' TYPE 'S'.

               LOOP AT t_return.

                 it_msg-ponum = wa_final-ebeln.

                 it_msg-polne = wa_final-ebelp.

                 it_msg-type = t_return-type.

                 it_msg-message = t_return-message.

                 APPEND it_msg. CLEAR it_msg.

                 DELETE it_msg WHERE type = 'W' OR type = 'I'.

               ENDLOOP.

           ELSE.

*             MESSAGE 'There was an Error in changing PO' TYPE 'S'.

              LOOP AT t_return.

                it_msg-ponum = wa_final-ebeln.

                it_msg-polne = wa_final-ebelp.

                it_msg-type = t_return-type.

                it_msg-message = t_return-message.

                APPEND it_msg. CLEAR it_msg.

                DELETE it_msg WHERE type = 'W' OR type = 'I'.

              ENDLOOP.

           ENDIF.

         ENDLOOP.

         SET SCREEN 0.

         rs_selfield-refresh = 'X'.

         PERFORM display_result.

       ENDIF.

ENDCASE.

ENDFORM.

FORM display_report.

   is_print-no_print_selinfos = 'X'.

   is_print-no_print_listinfos = 'X'.

   is_print-print_ctrl = 'X'.

   PERFORM pf_write_fieldcat USING:

   'CHECK'               'IT_FINAL' ''                           ' ' 'X' 'X',

   'EBELN'               'IT_FINAL' 'Purchase Order'             ' ' ' ' ' ',

   'EBELP'               'IT_FINAL' 'Item'                       ' ' ' ' ' ',

   'BANFN'               'IT_FINAL' 'Purchase Requisition'       ' ' ' ' ' ',

   'MATNR'               'IT_FINAL' 'Material'                   ' ' ' ' ' ',

   'TXZ01'               'IT_FINAL' 'Short Text'                 ' ' ' ' ' ',

   'WERKS'               'IT_FINAL' 'Plant'                      ' ' ' ' ' ',

   'POMENGE'             'IT_FINAL' 'PO Quantity'                ' ' ' ' ' ',

   'MEINS'               'IT_FINAL' 'Order Unit'                 ' ' ' ' ' ',

   'GRMENGE'             'IT_FINAL' 'GR Quantity'                ' ' ' ' ' ',

   'DMBTR'               'IT_FINAL' 'Balance'                    ' ' ' ' ' '.

* Layout

   x_layout-zebra = 'X'.

   x_layout-no_keyfix = ' '.

   x_layout-colwidth_optimize = 'X'.

* GUI Status

   w_status = 'SET_PF_STATUS'.

   w_repid = sy-repid.

* User commands

   w_comm = 'USER_COMMAND'.

   gs_variant-report  = sy-repid.

   gs_variant-username = sy-uname.

   gset-no_colwopt = 'X'.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

     EXPORTING

       i_callback_program = sy-repid

       it_fieldcat        = t_fieldcat

       is_layout          = x_layout

       it_sort            = it_sortcat

       is_variant         = gs_variant

       i_save             = 'A'

       is_print           = is_print

       i_callback_pf_status_set = w_status

       i_callback_user_command  = w_comm

*      i_callback_top_of_page  = 'TOP-OF-PAGE'

     TABLES

       t_outtab           = it_final

     EXCEPTIONS

       program_error      = 1

       OTHERS             = 2.

ENDFORM.                    " display_report

FORM pf_write_fieldcat  USING fname

                               tname

                               text

                               len

                               chk

                               edt.

   ls_fieldcat-fieldname     = fname.

   ls_fieldcat-tabname       = tname.

   ls_fieldcat-seltext_l     = text.

   ls_fieldcat-outputlen     = len.

   ls_fieldcat-checkbox      = chk.

   ls_fieldcat-edit          = edt.

   IF len = '0'.

     ls_fieldcat-outputlen     = '1'.

     ls_fieldcat-no_out = 'X'.

   ENDIF.

   APPEND ls_fieldcat TO t_fieldcat.

   CLEAR ls_fieldcat.

ENDFORM.

FORM set_pf_status USING rt_extab TYPE slis_t_extab.      

SET PF-STATUS 'ZSTANDARD'.

ENDFORM. "Set_pf_status

FORM display_result.

   is_print-no_print_selinfos = 'X'.

   is_print-no_print_listinfos = 'X'.

   is_print-print_ctrl = 'X'.

   PERFORM pf_write_fieldcat USING:

   'PONUM'               'IT_MSG' 'PO Number'                           ' ' ' ' ' ',

   'POLNE'               'IT_MSG' 'Item'             ' ' ' ' ' ',

   'TYPE'                'IT_MSG' 'Type'                       ' ' ' ' ' ',

   'MESSAGE'             'IT_MSG' 'Message'       ' ' ' ' ' '.

* Layout

   x_layout-zebra = 'X'.

   x_layout-no_keyfix = ' '.

   x_layout-colwidth_optimize = 'X'.

* GUI Status

   w_status = 'SET_PF_STATUS'.

   w_repid = sy-repid.

* User commands

   w_comm = 'USER_COMMAND'.

   gs_variant-report  = sy-repid.

   gs_variant-username = sy-uname.

   gset-no_colwopt = 'X'.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

     EXPORTING

       i_callback_program = sy-repid

       it_fieldcat        = t_fieldcat

       is_layout          = x_layout

       it_sort            = it_sortcat

       is_variant         = gs_variant

       i_save             = 'A'

       is_print           = is_print

       i_callback_pf_status_set = w_status

       i_callback_user_command  = w_comm

*      i_callback_top_of_page  = 'TOP-OF-PAGE'

     TABLES

       t_outtab           = it_msg

     EXCEPTIONS

       program_error      = 1

       OTHERS             = 2.

ENDFORM.                    " display_report

*FORM top-of-page.

**ALV Header declarations

*  DATA: t_header TYPE slis_t_listheader,

*        wa_header TYPE slis_listheader,

*        t_line LIKE wa_header-info,

*        ld_lines TYPE i,

*        ld_linesc(10) TYPE c.

*  DATA: text TYPE sdydo_text_element,

*        a_right   TYPE REF TO cl_dd_area.

*

*

**  text = 'Request Date:'.

**  wa_header-typ  = 'S'.

**  wa_header-info = text.

**  APPEND wa_header TO t_header.

**  CLEAR: wa_header.

**  gw_header-line01 = text.

*

*  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

*    EXPORTING

*      it_list_commentary = t_header.

*

*ENDFORM.                    "top-of-page

FORM reuse_alv_get_variant

   USING    value(iv_repid)   TYPE  sy-repid

            value(iv_handleTYPE  slis_handl

   CHANGING iv_variant        TYPE  disvariant-variant.

   DATA: lv_exit(1) TYPE c,

         ls_variant TYPE disvariant.   " Structure for Variant

   MOVE: iv_variant TO ls_variant-variant,

         iv_handle  TO ls_variant-handle,

         iv_repid   TO ls_variant-report.

   CALL FUNCTION 'REUSE_ALV_VARIANT_F4'

     EXPORTING

       is_variant    = ls_variant

       i_save        = 'A'

     IMPORTING

       e_exit        = lv_exit

       es_variant    = ls_variant

     EXCEPTIONS

       not_found     = 1

       program_error = 2

       OTHERS        = 3.

   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 lv_exit = space.

     MOVE ls_variant-variant TO iv_variant.

   ENDIF.

ENDFORM.                    " REUSE_ALV_GET_VARIANT                 "