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

Value of OK-CODE outside the TCode

Former Member
0 Likes
1,937

Hello All:

I need to call a transaction from within a function module.

When the user finishes with the Transaction, control returns to the function. At this point of time I need to know the last button pressed (OK-CODE) in the transaction screen, (Save, Exit, Back, Quit, Enter or something else)

What is the best way to code this?

Thank you,

Fred.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,467

Thank you Amar.

Friends, I need some more help.

Based upon our higher-up instructions, we need to accomplish this (info transfer in-out of dialog programs) using messages (like in BAPIs) rather than memory ids.

I have pasted a sample code from SAPs BAPI.

CALL TRANSACTION 'PR05' 
     USING  BDCDATA
     OPTIONS FROM OPTIONS.
IF SY-MSGTY IS INITIAL.
*   execution was canceled by the user
    PERFORM SET_RETURN USING 'S' '00' 359
                             SPACE SPACE SPACE SPACE
                             RETURN.
  ELSE.
 IF ( SY-MSGTY EQ 'S' )
       AND ( SY-MSGID EQ '56' )
       AND ( SY-MSGNO EQ 185 ).
* trip sucessful created, tripnumber is in sy-msgv1
      TRIPNUMBER = SY-MSGV1.
    ELSE.
      CLEAR TRIPNUMBER.
    ENDIF. 

As you can notice, the BAPI accesses the message created in the TCode PR05 thro SYST.

I tried very similar, called a (Z)Tcode from a (Z)function and tried to access the messages from the transaction in the function module thro SYST.

MSGTY, MSGID, MSGNO have values but MSGV1->4 values get cleared out in the function.

What am I doing wrong or missing?

Thanks again,

Fred.

9 REPLIES 9
Read only

Former Member
0 Likes
1,467

Hi Fred,

I assume that transaction you call is a Z program, so you can add some code.

I think you can save OK-CODE value to memory.

Add this code at your User_Command:


export OK_CODE TO MEMORY ID 'OK_CODE_ZXX'.

Add this code at your FM to get ok_code value:


import OK_CODE from memory id 'OK_CODE_ZXX'.

Note:

ZXX is your tcode.

Regards,

Read only

former_member787646
Contributor
0 Likes
1,467

Hi

You can use either ABAP memory or SAP memory for this.

ABAP MEMORY: EXPORT OK_CODE TO MEMORY ID 'XYZ'.

SAP MEMORY: SET PARAMETER ID 'XYZ' FIELD <field_name>

GET PARAMETER ID 'XYZ' FIELD <field_name>

Hope this would help you.

Murthy

Read only

Former Member
0 Likes
1,467

Thank you Jatra, Murthy. (Yes, it is a Z transaction)

I am wondering if using a memory id is the best/only way to do it.

How consistent can the memory ids be? Supposing there are multiple users looking at the same transaction, will there be separate and independent memory ids? Are the memory ids created per session, per user?

Thank you,

Fred.

Read only

0 Likes
1,467

that depends on the memory u use.

if u use SAP memory then per user

if ABAP memory then per internal session

with call transaction u have one more internal session, so u can use abap memory with out any prob.

Best regards

Amar

Read only

Former Member
0 Likes
1,467

If you absolutely will not use ABAP memory, you may encapsulate your inner z transaction in a Function Module that has a return code [1], [2], [3] etc according as what OK_code was pressed. I, probably would not sweat it.

Read only

Former Member
0 Likes
1,468

Thank you Amar.

Friends, I need some more help.

Based upon our higher-up instructions, we need to accomplish this (info transfer in-out of dialog programs) using messages (like in BAPIs) rather than memory ids.

I have pasted a sample code from SAPs BAPI.

CALL TRANSACTION 'PR05' 
     USING  BDCDATA
     OPTIONS FROM OPTIONS.
IF SY-MSGTY IS INITIAL.
*   execution was canceled by the user
    PERFORM SET_RETURN USING 'S' '00' 359
                             SPACE SPACE SPACE SPACE
                             RETURN.
  ELSE.
 IF ( SY-MSGTY EQ 'S' )
       AND ( SY-MSGID EQ '56' )
       AND ( SY-MSGNO EQ 185 ).
* trip sucessful created, tripnumber is in sy-msgv1
      TRIPNUMBER = SY-MSGV1.
    ELSE.
      CLEAR TRIPNUMBER.
    ENDIF. 

As you can notice, the BAPI accesses the message created in the TCode PR05 thro SYST.

I tried very similar, called a (Z)Tcode from a (Z)function and tried to access the messages from the transaction in the function module thro SYST.

MSGTY, MSGID, MSGNO have values but MSGV1->4 values get cleared out in the function.

What am I doing wrong or missing?

Thanks again,

Fred.

Read only

0 Likes
1,467

Try this way



CALL TRANSACTION 'PR05' USING BDCDATA 
                                       OPTIONS FROM OPTIONS
                                        MESSAGES INTO MESSTAB.

a®

Read only

0 Likes
1,467

Well, duh! Thanks a®s pointing that for me.

After checking some more I realize that the MSGV1->4 variables were missing bocs the first variable was initial while rest had values. If the first message variable wasnt empty SYST gets filled.

Thanks again,

Fred.

Read only

Former Member
0 Likes
1,467

I would like to hear more reg the last reply I have posted