Application Development 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: 

Interactive ALV Report that calls ME23N Transaction

masna_7
Explorer
0 Kudos
734

hi guyz,

consider the following code...

what I want to do here is to convert the following report into interactive report. I have to call the transaction 'ME23N' and display the respective data when double clicking on any row in my Output. It'll help a lot if the code is as simple as possible, tried many websites but cannot get the exact idea. Thanks in Advance.

REPORT Z_TESTPROGRAM.
TYPE-POOLS : SLIS.
TABLES : EKKO, EKPO.
TYPES : BEGIN OF TY_EKKO,
EBELN TYPE EKKO-EBELN,
AEDAT TYPE EKKO-AEDAT,
BUKRS TYPE EKKO-BUKRS,
BSTYP TYPE EKKO-BSTYP,
BSART TYPE EKKO-BSART,
EBELN1 TYPE EKPO-EBELN,
AEDAT1 TYPE EKPO-AEDAT,
BUKRS1 TYPE EKPO-BUKRS,
EBELP TYPE EKPO-EBELP,
END OF TY_EKKO.
DATA: IT_EKKO TYPE TABLE OF TY_EKKO,
WA_EKKO TYPE TY_EKKO.
DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FCAT LIKE LINE OF IT_FCAT.
PARAMETERS : P_EBELN TYPE EBELN OBLIGATORY,
P_AEDAT TYPE AEDAT OBLIGATORY,
P_BUKRS TYPE BUKRS OBLIGATORY,
P_BSTYP TYPE BSTYP,
P_BSART TYPE BSART.
START-OF-SELECTION.
SELECT A~EBELN A~AEDAT A~BUKRS A~BSTYP A~BSART B~EBELN B~AEDAT B~BUKRS B~EBELP
FROM EKKO AS A
INNER JOIN EKPO AS B
ON A~EBELN EQ B~EBELN
INTO TABLE IT_EKKO
WHERE A~EBELN = P_EBELN AND A~AEDAT = P_AEDAT AND A~BUKRS = P_BUKRS.
WA_FCAT-COL_POS = '1'.
WA_FCAT-FIELDNAME = 'EBELN'.
WA_FCAT-SELTEXT_L = 'Purchase Doc Num'.
WA_FCAT-KEY = 'X'.
WA_FCAT-HOTSPOT = 'X'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '2'.
WA_FCAT-FIELDNAME = 'AEDAT'.
WA_FCAT-SELTEXT_L = 'Record Creation Date'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '3'.
WA_FCAT-FIELDNAME = 'BUKRS'.
WA_FCAT-SELTEXT_L = 'Company Code'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '4'.
WA_FCAT-FIELDNAME = 'BSTYP'.
WA_FCAT-SELTEXT_L = 'Purchasing Doc Category'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '5'.
WA_FCAT-FIELDNAME = 'BSART'.
WA_FCAT-SELTEXT_L = 'Purchasing Doc Type'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '6'.
WA_FCAT-FIELDNAME = 'EBELN1'.
WA_FCAT-SELTEXT_L = 'Purchase Doc Num'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '7'.
WA_FCAT-FIELDNAME = 'AEDAT1'.
WA_FCAT-SELTEXT_L = 'Record Creation Date'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '8'.
WA_FCAT-FIELDNAME = 'BUKRS1'.
WA_FCAT-SELTEXT_L = 'Company Code'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
WA_FCAT-COL_POS = '9'.
WA_FCAT-FIELDNAME = 'EBELP'.
WA_FCAT-SELTEXT_L = 'Item Number of PO Doc'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = IT_FCAT
* IS_LAYOUT = GD_LAYOUT
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
TABLES
T_OUTTAB = IT_EKKO.
4 REPLIES 4

adityaIngale
Active Participant
0 Kudos
482

Hi masna_7,

Check this Existing Answer in Community.

https://answers.sap.com/questions/2118334/calling-a-transaction-from-an-interactive-alv-repo.html

Regards,

Aditya

raymond_giuseppi
Active Contributor
482

Why use an old FM REUSE, there are OO classes with many more options nowadays.

Basically, you need to handle the double_click event (or the associated function code in user_command if you stay with the old FMs)

In the event,

  • read the data from the clicked record,
  • map the value to the parameter-id handled by the transaction
  • call the transaction

What did you fail to code, there are indeed hundreds of examples in the forum?

Sandra_Rossi
Active Contributor
0 Kudos
482

Please edit your question, select your code and press the button [CODE], which makes the code appear colored/indented, it will be easier for people to look at it. Thank you!

Sandra_Rossi
Active Contributor
0 Kudos
482

CL_SALV_TABLE is much shorter. This short code compiles and is equivalent to yours:

REPORT z_testprogram.
PARAMETERS : p_ebeln TYPE ebeln OBLIGATORY,
             p_aedat TYPE aedat OBLIGATORY,
             p_bukrs TYPE bukrs OBLIGATORY,
             p_bstyp TYPE bstyp,
             p_bsart TYPE bsart.
START-OF-SELECTION.
  SELECT a~ebeln, a~aedat, a~bukrs, a~bstyp, a~bsart,
         b~ebeln AS ebeln1, b~aedat AS aedat1, b~bukrs AS bukrs1,
         b~ebelp
      FROM ekko AS a
      INNER JOIN ekpo AS b
      ON a~ebeln EQ b~ebeln
      WHERE a~ebeln = @p_ebeln AND a~aedat = @p_aedat AND a~bukrs = @p_bukrs
      INTO TABLE @DATA(it_ekko)
      UP TO 5 ROWS.
  cl_salv_table=>factory(
    IMPORTING
      r_salv_table = DATA(salv)
    CHANGING
      t_table      = it_ekko ).
  DATA(column) = salv->get_columns( )->get_column( 'BSTYP' ).
  column->set_fixed_header_text( 'L' ).
  column->set_long_text( 'Non-standard heading' ).
  salv->display( ).