1

I'm new to SAP/ABAP programming. I'm really having trouble displaying a simple table control out of my internal table. Could you please help? Currently, if I search for the course by entering a course ID - 10001, it displays a blank table control. It should display the content which i've already populated. I followed exactly from this source: http://sapabap-4.blogspot.sg/2013/06/simple-table-control.html.

The only difference is that I've placed everything in a report program instead of module program as my lecturer asked me to. Also do note that there's absolutely no errors, the table control just doesn't show.

*-------Declaration of tables for screen fields------------------------*
TABLES: zcms_courses.

*------Declaration of required structures------------------------------*
TYPES: BEGIN OF ty_zcms_courses,
         course_id      TYPE zcms_courses-course_id,
         course_content TYPE zcms_courses-course_content,
         music_genre    TYPE zcms_courses-music_genre,
         options        TYPE zcms_courses-options,
         course_name    TYPE zcms_courses-course_name,
       END OF ty_zcms_courses.

*-----Declaration of user command variables----------------------------*
DATA: OK_CODE TYPE sy-ucomm,
      OK_CODE1 TYPE sy-ucomm.

*-----Declaration of work area & table---------------------------------*
DATA: wa_zcms_courses      TYPE          ty_zcms_courses,
      itab_zcms_courses_hd TYPE TABLE OF ty_zcms_courses.

*---------Declaration of Table Control---------------------------------*
CONTROLS: zcms_courses_tc TYPE TABLEVIEW USING SCREEN 9002.


MODULE status_9001 OUTPUT.
  SET PF-STATUS 'PF_PO_INP'.
  SET TITLEBAR 'PO_TITLE'.

ENDMODULE.                 " status_9001  OUTPUT


MODULE user_command_9001 INPUT.
  "Call screen 9001.
  CASE OK_CODE.
    WHEN 'DISP'.     "Display button
      CALL SCREEN 9002.
      "PERFORM get_po.

    WHEN 'CLR'.      "Clear button
      CLEAR zcms_courses-course_id.

    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.

  ENDCASE.

ENDMODULE.

MODULE status_9003 OUTPUT.
  SET PF-STATUS 'PF_PO_INN'.
  SET TITLEBAR 'PO_TITLE1'.

ENDMODULE.

module user_command_9003 input.
  CASE OK_CODE1.
  WHEN 'ADD'.
      CALL SCREEN 9003.                               endcase.
endmodule.

FORM get_po .

  IF zcms_courses-course_id IS NOT INITIAL.
    REFRESH: itab_zcms_courses_hd .

    SELECT SINGLE course_id course_content music_genre options  course_name
      FROM zcms_courses  INTO wa_zcms_courses
      WHERE course_id = zcms_courses-course_id.

    IF sy-subrc = 0.
      SELECT course_id course_content music_genre options  course_name
        FROM zcms_courses INTO TABLE itab_zcms_courses_hd
        WHERE course_id = wa_zcms_courses-course_id.


      IF sy-subrc = 0.
        SORT itab_zcms_courses_hd.

        "Refreshing the table control to have updated data
        REFRESH CONTROL 'ZCMS_COURSES_TC' FROM SCREEN 9002.
        CALL SCREEN 9002.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.



MODULE STATUS_9002 OUTPUT.
  SET PF-STATUS 'PF_PO_INP'.
  SET TITLEBAR 'PO_TITLE'.
ENDMODULE.

MODULE table_control OUTPUT.
  DESCRIBE TABLE itab_zcms_courses_hd LINES sy-dbcnt.

  zcms_courses_tc-current_line = sy-loopc.

  zcms_courses_tc-lines = sy-dbcnt.

  zcms_courses-course_id = wa_zcms_courses-course_id.
  zcms_courses-course_content = wa_zcms_courses-course_content.
    zcms_courses-music_genre = wa_zcms_courses-music_genre.
  zcms_courses-options = wa_zcms_courses-options.
  zcms_courses-course_name = wa_zcms_courses-course_name.

  CLEAR wa_zcms_courses.

ENDMODULE.



MODULE user_command_9002 INPUT.
  CASE ok_code.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.

      CLEAR ok_code.

      LEAVE LIST-PROCESSING.
      LEAVE TO SCREEN 9001.
  ENDCASE.
ENDMODULE.



MODULE modify_table_control INPUT.

  READ TABLE itab_zcms_courses_hd INTO wa_zcms_courses INDEX
zcms_courses_tc-current_line.

  IF sy-subrc = 0.

    MODIFY itab_zcms_courses_hd FROM wa_zcms_courses INDEX
zcms_courses_tc-current_line.
  ENDIF.
ENDMODULE.


__________________________________________________________________________________

FLOW LOGIC of screen 9002:
PROCESS BEFORE OUTPUT.
  MODULE status_9002.

  LOOP AT itab_zcms_courses_hd INTO wa_zcms_courses WITH CONTROL
zcms_courses_tc.
    MODULE table_control.
  ENDLOOP.

PROCESS AFTER INPUT.

  LOOP AT itab_zcms_courses_hd.
    MODULE modify_table_control.
  ENDLOOP.

  MODULE user_command_9002.

__________________________________________________________________________________
FLOW LOGIC of screen 9001
PROCESS BEFORE OUTPUT.
MODULE STATUS_9001.

PROCESS AFTER INPUT.
MODULE USER_COMMAND_9001.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Nisha Nisha
  • 11
  • 1
  • 4
  • Why don't you use an ALV for table display? – Rene MF Jan 25 '18 at 19:05
  • Have you accidentally omitted the part of the code that calls the screen that contains the table control by accident or is it missing in your code? – vwegert Jan 28 '18 at 12:54
  • I don't see where you call screen 9001, which calls all subsequent screens. `LEAVE TO SCREEN 9001` is placed in 9002 PAI and will never be executed. – Suncatcher Feb 04 '18 at 12:56

3 Answers3

2

If your program is a report, you can use ALV functions.

This is a simple tutorial. https://wiki.scn.sap.com/wiki/display/ABAP/ALV+easy+tutorial

Or, if you need more help, I can pass some code from my programs.

Rene MF
  • 157
  • 1
  • 12
1

The reason you're not seeing errors is basically because those are all valid ABAP commands.

However, the PAI/PBO logic you're using (e.g. MODULE user_command_9001 INPUT) should be tied to SCREEN objects and not directly inside a REPORT object.

Think of it in this way: REPORTs can display data (e.g. an ALV) without you having to explicitly create a SCREEN object. The problem here is that a table control needs to be tied to a SCREEN to be properly displayed, so it's best to use an ALV to display data inside a REPORT.

I know this might be confusing at first, but usually you would use a MODULE POOLwhen a lot of interaction between the user and the screen is needed and that's exactly the case with a table control.

maurcz
  • 341
  • 3
  • 11
1

You can find a modern ALV example here: ALV Grid for In-Line Declaration

And additional examples in package SALV_OM_OBJECTS.

Brian
  • 385
  • 2
  • 12