cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ABAP Calling last calling program in the stack

saurabh_shukla4
Explorer
1,735

Hello experts,

  I have a program (dialog program - scr 400) screen and button on the screen. It's calling another program (+ transaction) having selection screen and after execution ALV grid displayed. After performing work it should back to original calling screen having dialog program screen (400).

ZPROGRAM1 (Screen 400) -> Call Transaction - ZPROGRAM2 (+selection screen) -> ALV screen and then back with same sequence.

We have tried with, AT SELECTION SCREEN EXIT-COMMAND and leave 0 or set screen 0 but somehow it is not working. CALL SCREEN will not work since it back button is in another program which is called.

How to call previous screens which are in call stack.

Regards,

PD

Accepted Solutions (0)

Answers (4)

Answers (4)

saurabh_shukla4
Explorer

Sorry for the wrong tag.

I want to leave selection screen and go back to the calling program screen (dialog programming). At present it is exiting the program.

ulrich_mhrke
Participant
Normally the calling program continues after "call transaction". Maybe you have some additional code there which stops the program. Let us know your code around this call.
Sandra_Rossi
Active Contributor
0 Kudos

Your issue is because you leave ZPROGRAM2 (which you call using Call Transaction) by using LEAVE TO CURRENT TRANSACTION. You don't return to ZPROGRAM1. It happens like if you had started only ZPROGRAM2 without using ZPROGRAM1.

So, in short, this is what happens after you call ZPROGRAM1 from the SAP menu (via a transaction code):

ZPROGRAM1

  1. ZPROGRAM1 (Screen 400)
  2. In PAI, a normal button does Call Transaction (which calls ZPROGRAM2). A breakpoint is defined after Call Transaction, you don't stop at it when leaving ZPROGRAM2 and your question is why?

ZPROGRAM2

  1. Selection screen. You press the standard Execute.
  2. In START-OF-SELECTION (or AT SELECTION-SCREEN?) there is a CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' which displays a screen with ALV.
  3. You press Back in the ALV Grid screen, it calls the subroutine defined for the USER_COMMAND event of the ALV Grid, you execute LEAVE TO CURRENT TRANSACTION, which makes you go back to the selection screen.
  4. NB: there is no stop at the breakpoint after REUSE_ALV_GRID_DISPLAY. LEAVE TO CURRENT TRANSACTION restarts the program ZPROGRAM2.
  5. You then press back in the selection screen, and you go back to the SAP menu instead of ZPROGRAM1.
  6. Why?

The ABAP documentation of LEAVE TO CURRENT TRANSACTION says:


If CURRENT TRANSACTION is specified, the current transaction is called using the transaction code that was used to call the transaction using CALL TRANSACTION [...] When the transaction is called, the ABAP program associated with the transaction code is loaded in a new internal session. All previous internal sessions are deleted from the stack.

If you read the chapter about internal sessions, you can see that there's a new internal session each time there is a Call Transaction or Submit And Return, so it means that both programs ZPROGRAM1 and ZPROGRAM2 are terminated, and then the transaction of ZPROGRAM2 is restarted.

Solution: instead of LEAVE TO CURRENT TRANSACTION, you have a parameter RS_SELFIELD in the subroutine of the ALV event USER_COMMAND, which you can change, it contains several possible actions like EXIT to exit the screen and go back to after REUSE_ALV_GRID_DISPLAY instead of restarting the whole program.

Your current code:

FORM user_command
      USING
        R_UCOMM     LIKE SY-UCOMM
        RS_SELFIELD TYPE SLIS_SELFIELD.
  CASE r_ucomm.
    WHEN 'EXIT'.
      LEAVE TO CURRENT TRANSACTION. " <====== Very bad idea
  ENDCASE.
ENDFORM.

Instead of LEAVE TO CURRENT TRANSACTION, just do:

  CASE r_ucomm.
    WHEN 'EXIT'.
      rs_selfield-exit = 'X'. " or use = abap_true
  ENDCASE.

You will see that you stop at the breakpoint after CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'.

PS: to better understand what was happening, you can see the effect of LEAVE TO CURRENT TRANSACTION on the call stack by activating the debug option "cross roll area stack". You will see in the call stack the numbers of the internal sessions, that the first time ZPROGRAM2 is at the level 2 (and ZPROGRAM1 is at the level 1), and after LEAVE TO CURRENT TRANSACTION you only see ZPROGRAM2 at the level 1. ZPROGRAM1 has vanished.

saurabh_shukla4
Explorer
0 Kudos

@Sandra_Rossi I tried this change. However, Getting back from ALV to Selection is not a problem. From Selection screen of (ZSOUPLOAD) program to back to calling program is main issue. From selection screen (ZSOUPLOAD -1000 screen no) back to calling program (screen 400) is not working.

Sandra_Rossi
Active Contributor
0 Kudos
You didn't understand. You have to fix the code when leaving the ALV (LEAVE TO CURRENT TRANSACTION), to solve the problem when you're leaving the selection screen. Please try the code and debug as I explained, you will understand.
saurabh_shukla4
Explorer
0 Kudos

@ulrich_mhrke

Yes you are right. I did check that and I have to add some code to come back to calling screen 400. Can you provide some tips/ help to go back to the screen? I have sequences of screens where output of the screen is based on selection of previous screen. So, It's challenging to jump directly on the screen. I do not want user to traverse again through screens 100, 200, 300 and again 400. I directly want user to land at screen 400 where he left off before.

Sandra_Rossi
Active Contributor
0 Kudos
You didn't give any debug details, did you? As I said, you can see by debug that after leaving the selection screen, you go back to ZPROGRAM1 directly after CALL TRANSACTION 'ZUPLOADRPA' in the PAI of the screen 400, and after the PAI of the screen 400 it goes to the PBO of the screen 400 and displays it. If not, please explain what you see during your debug.
saurabh_shukla4
Explorer
0 Kudos

@ulrich_mhrke 

Below is the code of PAI of ZPROG1 (Screen 400)

 

MODULE user_command_0400 INPUT.
 CASE sy-ucomm.
    WHEN 'NEWMAT'.
      "test run
      SET PARAMETER ID 'OPTION' FIELD 'MAT'.
      CALL TRANSACTION 'ZTRANS'.

 

This code is calling selection screen of ZTRANS transaction.

 

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS : cust  RADIOBUTTON GROUP g1 DEFAULT 'X'  USER-COMMAND cmd  MODIF ID upd,

 

and some more parameters at selection screen.
Once selection screen is executed it is calling ALV grid using REUSE_ALV_GRID_DISPLAY function. Once grid is displayed and back is pressed then it again comes back to selection screen of ZTRANS. From here, if we press back, then it exits the transaction and not going back to screen 400 of ZPROG1.
We have tried to use AT SELECTION-SCREEN ON EXIT-COMMAND. Also under ZTRANS program and in that we tried to use SET SCREEN 0 or CALL TRANSACTION (of 400 screen) but it's not going back to screen 400.

About your second question, attribute of screen 400 (next screen) is set to 400 and it is not empty.

 

Sandra_Rossi
Active Contributor
0 Kudos
Please don't post an answer for comments, additional details. Answer is reserved to propose a solution. Instead, use Replies > Comment (on the question or on a proposed answer).
ulrich_mhrke
Participant
0 Kudos
Please send the WHOLE flow logic of screen 400 of program ZPROG1 and the WHOLE PAI module where you call transaction ZTRANS. You will find the flow logic at screen definition. It should start with "PROCESS BEFORE OUTPUT". The code of the module starts with "MODULE ... INPUT." and ends with "ENDMODULE."
saurabh_shukla4
Explorer
0 Kudos

@ulrich_mhrke

This is screen flow logic:

PROCESS BEFORE OUTPUT.
  MODULE status_0400.

PROCESS AFTER INPUT.
  MODULE user_command_0400.


PROCESS ON VALUE-REQUEST.

And for Module user_command_400.

 CASE sy-ucomm.
    WHEN 'NEWMAT'.
      "test run
      SET PARAMETER ID 'OPTION' FIELD 'MAT'.
      CALL TRANSACTION 'ZTRANS'.

 NEWMAT is function key declared for the button on screen 400. 

ulrich_mhrke
Participant
For some reason you don't want to give us the whole code of module user_command_400. Maybe you can add an info message direct after the call screen (message 'Some text.' type 'I'.). Do you see this message after returning from the called transaction?
Sandra_Rossi
Active Contributor
0 Kudos
@saurabh_shukla4 A simple way to discuss efficiently is to create a small test program to reproduce the issue and post it (of course, sharing via a Git repository is the best way when it concerns non-ABAP objects like Dynpro, these objects can be uploaded/downloaded in an instant via abapGit).
saurabh_shukla4
Explorer
0 Kudos

@ulrich_mhrke

Please find screenshots of the development:

Screen 400: PAI

img1_400.png

PAI User-command:

400_attribute.png

Screen 400 Attribute

400_pai.png

Call Transaction (ZUPLOADRPA) - previously ZTRANS now name has changed.

 

selection_screen.png

Called transaction selection screen attribute.

As mentioned, the selection screen of another program ZUPLOADRPA (old name - ZTRANS) is getting called successfully and also ALV grid further. Back from ALV grid is also working to selection screen. But after selection screen the program is not returning to 400 transaction screen

 

ulrich_mhrke
Participant
0 Kudos
Why I asked for the whole code of the module?: Also in your picture we can not see if there is some more code between "ENDCASE." and "ENDMODULE."
saurabh_shukla4
Explorer
0 Kudos

@ulrich_mhrke

Hi, sorry for the late reply, I am not hesitating to share the code as only this much code is available. I will try more to add as below:
Screen 400 flow logic:

PROCESS BEFORE OUTPUT.
  MODULE status_0400.

PROCESS AFTER INPUT.
  MODULE user_command_0400.


PROCESS ON VALUE-REQUEST.
  "  FIELD SOLDTONEW MODULE SOLDTO_F4.
  " FIELD SHIPTONEW MODULE SHIPTO_F4.
  "  FIELD CURRENCYNEW MODULE CURRENCYNEW_F4.
  " FIELD MATNONEW MODULE MATNONEW_F4.
  " FIELD stprs MODULE unitc0st_f4.

Below is user-command module for screen 400:

MODULE user_command_0400 INPUT.

  SELECT SINGLE bezei INTO @DATA(wa_bezei) FROM tinct WHERE inco1 = @inco1 AND spras EQ @sy-langu.
  IF sy-subrc EQ 0.
    inco2 = wa_bezei.
  ENDIF.

  SELECT SINGLE name1 FROM kna1 INTO @DATA(name1) WHERE kunnr = @soldtonew.
  IF sy-subrc EQ 0.
    soldto = name1.
  ENDIF.
  CLEAR name1.
  SELECT SINGLE name1 FROM kna1 INTO @name1 WHERE kunnr = @shiptonew.
  IF sy-subrc EQ 0.
    shipto = name1.
    CLEAR name1.
  ENDIF.
  SELECT SINGLE maktg FROM makt INTO @DATA(maktg_v) WHERE matnr = @matnonew.
  IF sy-subrc EQ 0.
    maktg = maktg_v.
    CLEAR maktg_v.
  ENDIF.

  unit = unit.

  "SELECT SINGLE vkorg, vtweg, spart FROM knvv INTO @DATA(wa_knvv) WHERE kunnr = @soldtonew.
  "IF sy-subrc EQ 0.
  " vkorg = wa_knvv-vkorg.
  "vtweg = wa_knvv-vtweg.
  "spart = wa_knvv-spart.
  "CLEAR wa_knvv.
  "ENDIF.

*  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*    EXPORTING
*      input  = matnonew
*    IMPORTING
*      output = matnonew.

  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = soldtonew
    IMPORTING
      output = soldtonew.

  REFRESH: t_a005[], lt_konp[].

  SELECT * FROM a005 INTO TABLE t_a005 WHERE kappl =  'V' AND kschl =  'ZPR1' AND vkorg = vkorg AND vtweg = vtweg AND kunnr = soldtonew AND matnr = matnonew  AND datbi >= sy-datum.
  IF sy-subrc = 0.
    SELECT knumh kopos kschl kbetr konwa kpein kmein krech loevm_ko mwsk1 kznep stfkz kzbzg
      FROM konp APPENDING TABLE lt_konp
      FOR ALL ENTRIES IN t_a005 WHERE
      knumh = t_a005-knumh AND
      kschl = t_a005-kschl.
    IF sy-subrc = 0.
      LOOP AT lt_konp INTO ls_konp.
        unit = ls_konp-kbetr.
        EXIT.
      ENDLOOP.
    ENDIF.
  ELSE.

    DATA matnonew_1 TYPE mara-matnr.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = matnonew
      IMPORTING
        output = matnonew_1.


    SELECT * FROM a005 INTO TABLE t_a005 WHERE kappl =  'V' AND kschl =  'ZPR1' AND vkorg = vkorg AND vtweg = vtweg AND kunnr = soldtonew AND matnr = matnonew_1  AND datbi >= sy-datum.
    IF sy-subrc = 0.
      SELECT knumh kopos kschl kbetr konwa kpein kmein krech loevm_ko mwsk1 kznep stfkz kzbzg
    FROM konp APPENDING TABLE lt_konp
    FOR ALL ENTRIES IN t_a005 WHERE
    knumh = t_a005-knumh AND
    kschl = t_a005-kschl.
      IF sy-subrc = 0.
        LOOP AT lt_konp INTO ls_konp.
          unit = ls_konp-kbetr.
          EXIT.
        ENDLOOP.
      ENDIF.
    ENDIF.
  ENDIF.


  CASE sy-ucomm.
    WHEN 'FNEXIT'.
      PERFORM exit_screen_400.
    WHEN 'FNADD'.
      add_btn_clicked_400 = 1.
      save_btn_clicked_400 = 0.
      change_btn_clicked_400 = 0.
      delete_btn_clicked_400 = 0.
      PERFORM add_item_400.
    WHEN 'FNCHANGE'.
      add_btn_clicked_400 = 0.
      change_btn_clicked_400 = 1.
      delete_btn_clicked_400 = 0.
      save_btn_clicked_400 = 0.
      PERFORM change_item_400.
    WHEN 'FNSAVE'.
      save_btn_clicked_400 = 1.
      add_btn_clicked_400 = 0.
      change_btn_clicked_400 = 0.
      delete_btn_clicked_400 = 0.
      PERFORM save_orders_so.
    WHEN 'FNACCEPT'.
      PERFORM accept_item_changes_400.
    WHEN 'FNDELETE'.
      save_btn_clicked_400 = 0.
      add_btn_clicked_400 = 0.
      change_btn_clicked_400 = 0.
      delete_btn_clicked_400 = 1.
      PERFORM delete_item_400.
    WHEN 'FNCALC'.
      PERFORM calculate_sub_total.
    WHEN 'FNVERIFY'.
      "test run
      wa_testrun = 'X'.
      PERFORM prepare_bapi_data.
    WHEN 'FNPOST'.
      "test run
      CLEAR wa_testrun.
      PERFORM prepare_bapi_data.
    WHEN 'NEWMAT'.
      "test run
      SET PARAMETER ID 'OPTION' FIELD 'MAT'.
      CALL TRANSACTION 'ZUPLOADRPA'.
    WHEN 'NEWCUST'.
      SET PARAMETER ID 'OPTION' FIELD 'CUST'.
      CALL TRANSACTION 'ZUPLOADRPA' AND SKIP FIRST SCREEN.
      "SUBMIT ZUPLOADRPA VIA SELECTION-SCREEN AND RETURN.
  ENDCASE.
ENDMODULE.

When NEWMAT is being clicked (which is button on screen 400) the transaction ZUPLOADRPA is called. The program and transaction names are same.

Now at ZUPLOADRPA below is the selection screen.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS : cust     RADIOBUTTON GROUP g1 DEFAULT 'X'  USER-COMMAND cmd  MODIF ID upd,
             vend     RADIOBUTTON GROUP g1 MODIF ID up1,
             mat      RADIOBUTTON GROUP g1 MODIF ID upm,
             raw      RADIOBUTTON GROUP g1 MODIF ID up1,
             halb     RADIOBUTTON GROUP g1 MODIF ID up1,

             bom      RADIOBUTTON GROUP g1  MODIF ID bom,
             altbom   RADIOBUTTON GROUP g1 MODIF ID bpd,
             exbom    RADIOBUTTON GROUP g1 MODIF ID bpd,
             moda     TYPE ctu_params-dismode OBLIGATORY DEFAULT 'A' MODIF ID bpd,

             routing  RADIOBUTTON GROUP g1 MODIF ID rot,
             altrot   RADIOBUTTON GROUP g1 MODIF ID rpd,
             exrot    RADIOBUTTON GROUP g1 MODIF ID rpd,


             hibe     RADIOBUTTON GROUP g1 MODIF ID up1,
             hawa     RADIOBUTTON GROUP g1 MODIF ID up1,
             vcust    RADIOBUTTON GROUP g1 MODIF ID up1,
             nlag     RADIOBUTTON GROUP g1 MODIF ID up1,
             rawext   RADIOBUTTON GROUP g1 MODIF ID up1,
             fertdesc TYPE zfertdesc MODIF ID upm.
*PARAMETERS : mod1 TYPE ctu_params-dismode DEFAULT 'A' OBLIGATORY  MODIF ID upd.
SELECTION-SCREEN END OF BLOCK b1.


AT SELECTION-SCREEN ON EXIT-COMMAND.

  "LEAVE to SCREEN 100.

The selection screen execution will display ALV grid as below:

 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        i_buffer_active          = space
        i_callback_program       = sy-repid
        i_callback_pf_status_set = 'SET_PF_STATUS'
        i_callback_user_command  = 'CUST_USER_COMMAND'
        it_fieldcat              = t_field[]
        is_layout                = gd_layout
        i_save                   = 'A'
        i_default                = 'X'
      TABLES
        t_outtab                 = it_cust
      EXCEPTIONS
        program_error            = 1
        OTHERS                   = 2.
  

And at ALV grid user command module below is the code for back button PF1:

  ELSEIF ( ( sy-ucomm = 'PF1' ) OR ( sy-ucomm = 'PF2' ) OR ( sy-ucomm = 'PF3' ) ).
    LEAVE TO CURRENT TRANSACTION.
  ENDIF.

From here, back is pressed and the screen flow comes back to selection screen again.

But, after selection screen, and pressing back button at selection screen it is ending the transaction and not going back to the calling screen i.e. 400 PBO. Below is the 400 screen PBO:

ODULE status_0400 OUTPUT.
  SET PF-STATUS 'ZSCRPF_400'.
  SET TITLEBAR 'ZSCRT_400'.

  GET PARAMETER ID 'FILENAME' FIELD filename.

  PERFORM set_layout_list.
  IF initial_load = 'N'.
    PERFORM recalculate_overall_total.
  ENDIF.

  IF change_btn_clicked_400 EQ 0 AND add_btn_clicked_400 EQ 0
      AND delete_btn_clicked_400 EQ 0.
    IF initial_load EQ 'Y'.
      CLEAR: chkapplyall, chkdiscall, custmat, maktg,matnonew,qtynew, stprs, txtmsgs, sgstnew, cgstnew, igstnew, deldatenew, unit, basicamt, totalnew,kbetrnew, itemnobot, zzprdat,zzmfg_cdate ,zzrepeat, werks, lgort.
      initial_load = 'N'.
      PERFORM set_initial_values_of_header.
      PERFORM set_initial_values_of_items.
      PERFORM set_list_values.
    ENDIF.
    "PERFORM CLEAR_ITEM_VALUES.
  ENDIF.

  IF add_btn_clicked_400 EQ 1.
    "  PERFORM CLEAR_VALUES.
  ENDIF.

  IF save_btn_clicked_400 EQ 1.
    " PERFORM set_initial_values_400.
  ENDIF.

  IF change_btn_clicked_400 EQ 1.
    " PERFORM SET_VALUES_CHANGED_CLICKED.
  ENDIF.


  IF cust_items IS INITIAL.

    CREATE OBJECT cust_items
      EXPORTING
        container_name = 'CUST_ITEMS'.


    CREATE OBJECT grid_list
      EXPORTING
        i_parent = cust_items.


    CALL METHOD grid_list->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                     = is_layout_list
*       is_print                      =
*       it_special_groups             =
*       it_toolbar_excluding          =
*       it_hyperlink                  =
*       it_alv_graphics               =
*       it_except_qinfo               =
*       ir_salv_adapter               =
      CHANGING
        it_outtab                     = it_ybapi_item_rpa[]
        it_fieldcatalog               = it_fldcat_list[]
*       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.

    CALL METHOD grid_list->refresh_table_display.

  ELSE.
    CALL METHOD grid_list->refresh_table_display.
  ENDIF.
ENDMODULE.

Your help is appreciated in this.

Thanks,

Regards,

PD

saurabh_shukla4
Explorer
0 Kudos

@ulrich_mhrke 

Our code in ZPROG1 (having total 4 screens 100->200->300->400) from calling dialog programming module (at Screen no.400) on button click sy-ucomm case:

PAI module:

 

CALL TRANSACTION 'ZTRANS'  "AND SKIP FIRST SCREEN. "same is the program name ZTRANS

 

In ZTRANS program, there is selection screen and after executing selection screen thee is ALV display. This is working fine. After back from ALV, it is again coming back to Selection screen of ZTRANS. After this if we back to ZTRANS.

 

AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'PF01'.  "back or exit button FCODE
  SET SCREEN 0.

 

It is exiting from ZTRANS program (transaction) totally and not coming back to original calling screen of ZPROG1 (400). 

If we use, leave to screen 400, it will not find screen since both are different programs. If we do call transaction ZPROG1 then it is calling transaction 100 screen no which is starting. But, we want to come back to 400 (screen).

Any help appreciated.

PD

 

 

ulrich_mhrke
Participant
0 Kudos
Please send the whole flow logic of screen 400 of program ZPROG1 and the whole PAI module where you call transaction ZTRANS.
ulrich_mhrke
Participant
0 Kudos
Look at the Attributes of screen 400 of program ZPROG1. Maybe the "Next Screen" is set to 0 (empty in change mode).
Sandra_Rossi
Active Contributor
0 Kudos

deleted