Interactive report using GET CURSOR technique SAP ABAP

Developing interactive reports using GET CURSOR technique in SAP ABAP programming

+ -
Requirement:Develop a material master report, which displays a list of materials for a range of materials (select-options input).
  1. If the user double clicks on material number, it should display the details of that material in secondary list.
  2. If the use clicks on material type, it should display all the materials of that material type.

Requirement Analysis: To fulfill this requirement, we need to get material details from MARA for selection options input and need to get the click position of basic list(wether use clicked on material no or material type) and need to display data based on user click.

GET CURSOR is a key word, which is used to get cursor position with field name and value, by using this key work we can get value and field name at cursor .

SAP Tables to be used: for the above requirement, we are going to use MARA table.

For this requirement, everyting is same as previous program except some changes at line selection evet, at line selection we use key word GET CURSOR.

DATA : FNAM(30), FVAL(50).
  GET CURSOR FIELD FNAM VALUE FVAL.
  CONDENSE FNAM.
  CONDENSE FVAL.
  IF FNAM = 'WA_MARA-MATNR'.
    SELECT SINGLE * FROM MARA INTO WA_MARA WHERE MATNR = FVAL .
    WRITE:/ WA_MARA-MATNR, WA_MARA-MBRSH, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MEINS, WA_MARA-ERSDA, WA_MARA-ERNAM.
  ELSEIF FNAM = 'WA_MARA-MTART'.
    SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS WHERE MTART = FVAL.
    LOOP AT IT_MARA INTO WA_MARA.
      WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
    ENDLOOP.
  ENDIF.

Final code will be

REPORT ZSAPN_INTERACTIVE_GETCURSOR LINE-COUNT 30(3) NO STANDARD PAGE HEADING.
DATA : IT_MARA TYPE TABLE OF MARA,
       WA_MARA TYPE MARA,
       IT_MAKT TYPE TABLE OF MAKT,
       WA_MAKT TYPE MAKT.
DATA : FNAM(30), FVAL(50).

SELECT-OPTIONS : S_MATNR FOR WA_MARA-MATNR.

INITIALIZATION.

AT SELECTION-SCREEN.
  PERFORM VALIDATE_INPUT.

START-OF-SELECTION.
  PERFORM GET_DATA.
  PERFORM DISPLAY_DATA.

TOP-OF-PAGE.
  PERFORM DISPLAY_TOPOFPAGE.

AT LINE-SELECTION.
  PERFORM DISPLAY_SECONDARYLIST.

TOP-OF-PAGE DURING LINE-SELECTION.
  PERFORM LINE_TOPOFPAGE.
FORM VALIDATE_INPUT .
  IF S_MATNR IS INITIAL.
    MESSAGE 'Enter material input' TYPE 'E'.
  ENDIF.
ENDFORM.                    " VALIDATE_INPUT
FORM GET_DATA .
  SELECT * FROM MARA INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.
ENDFORM.                    " GET_DATA
FORM DISPLAY_DATA .
  LOOP AT IT_MARA INTO WA_MARA.
    WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MEINS.
  ENDLOOP.
ENDFORM.                    " DISPLAY_DATA
FORM DISPLAY_SECONDARYLIST .
  GET CURSOR FIELD FNAM VALUE FVAL.
  CONDENSE FNAM.
  CONDENSE FVAL.
  IF FNAM = 'WA_MARA-MATNR'.
    SELECT SINGLE * FROM MARA INTO WA_MARA WHERE MATNR = FVAL .
    WRITE:/ WA_MARA-MATNR, WA_MARA-MBRSH, WA_MARA-MTART, WA_MARA-MATKL, WA_MARA-MEINS, WA_MARA-ERSDA, WA_MARA-ERNAM.
  ELSEIF FNAM = 'WA_MARA-MTART'.
    SELECT * FROM MARA INTO TABLE IT_MARA UP TO 50 ROWS WHERE MTART = FVAL.
    LOOP AT IT_MARA INTO WA_MARA.
      WRITE:/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL.
    ENDLOOP.
  ENDIF.

ENDFORM.                    " DISPLAY_SECONDARYLIST
FORM DISPLAY_TOPOFPAGE .
  WRITE:/ 'Material Details' COLOR 3.
ENDFORM.                    " DISPLAY_TOPOFPAGE
FORM LINE_TOPOFPAGE .
  IF FNAM = 'WA_MARA-MATNR'.
    WRITE:/ 'Material details ', WA_MARA-MATNR COLOR 5.
  ELSEIF FNAM = 'WA_MARA-MTART'.
    WRITE:/ 'Material with material type ', WA_MARA-MTART COLOR 5.
  ENDIF.
ENDFORM.                    " LINE_TOPOFPAGE

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 42 People out of 43 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →